<?php
	/* $Id: sub_viewdetails.php,v 1.10 2005/12/16 10:54:46 gizmola Exp $ */
    /*********************************************\
    **   PonyGallery 1.1.2
    **   By: Danial Taherzadeh
    **   http://www.taher-zadeh.com
    **   Based on : Akogallery 2.1 by Arthur Konze
    **   Released Under GNU GPL Public License
    \*********************************************/

	## Original Copyright ####################
    #                                        # 
    # AkoGallery - A Mambo Gallery Component #
    # Copyright (C) 2003  by  Arthur Konze   #
    # Homepage   : www.mamboportal.com       #
    # Version    : 2.1 beta 1                #
    # License    : GNU GPL Public License    #
    ##########################################

    # Don't allow direct linking

    defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

    # Don't allow passed settings

    if ($_REQUEST['is_editor']) {
    	echo "<SCRIPT>document.location.href='../../index.php'</SCRIPT>\n";
        exit();
    }
    // list of common inclusions:
    if (file_exists($mosConfig_absolute_path . '/components/com_ponygallery/language/' . $mosConfig_lang . '.php')) { 
	    include($mosConfig_absolute_path . '/components/com_ponygallery/language/' . $mosConfig_lang . '.php');
    } else { 
		include($mosConfig_absolute_path . '/components/com_ponygallery/language/english.php');
    }
    # Show gallery header
    GalleryHeader();

    # Javascript for SmilieInsert and Form Check
    echo "<script language=\"Javascript\">";
    echo "  function validatecomment(){";
    echo "    if ((document.commentform.cmtname.value=='') || (document.commentform.cmttext.value=='')){";
    echo "      alert(\""._PONYGALLERY_ENTER_NAME_COMMENT."\");";
    echo "    } else {";
    echo "      document.commentform.action = 'index.php';";
    echo "      document.commentform.submit();";
    echo "    }";
    echo "  }";
    echo "</SCRIPT>";
    echo "<script language=\"Javascript\">";
    echo "  function validatesend2friend(){";
    echo "    if ((document.send2friend.send2friendname.value=='') || (document.send2friend.send2friendemail.value=='')){";
    echo "      alert(\""._PONYGALLERY_ENTER_NAME_EMAIL."\");";
    echo "    } else {";
    echo "      document.send2friend.action = 'index.php';";
    echo "      document.send2friend.submit();";
    echo "    }";
    echo "  }";
    echo "</SCRIPT>";

    # Database Query

    $database->setQuery("SELECT c.access 
						FROM #__ponygallery_catg as c 
						LEFT JOIN #__ponygallery as a ON a.catid = c.cid
						WHERE a.id= '$id'");

    $c_access=$database->loadResult();

    if ( $gid < $c_access ) {
        mosRedirect("index.php?option=com_ponygallery", _PONYGALLERY_NOT_ALLOWED_VIEW_PIC );
    }

    $database->setQuery("SELECT a.id, a.catid, a.imgtitle, a.imgauthor, 
						a.imgtext, a.imgdate, a.imgcounter, a.imgvotes, 
						a.imgvotesum, a.published, a.imgfilename, a.imgthumbname, 
						a.ordering, a.owner, u.id 
						FROM #__ponygallery as a 
						LEFT JOIN #__users as u ON u.username = a.owner
						WHERE a.id = '$id' AND a.approved=1");

    $result1=$database->query();

    if ( count( $database->loadObjectList() ) < 1 ) {
        mosRedirect( "index.php?option=com_ponygallery&func=userpannel", _PONYGALLERY_PICSLAD );
    }

    list( $id, $catid, $imgtitle, $imgauthor, 
    		$imgtext, $imgdate, $imgcounter, $imgvotes, 
    		$imgvotesum, $published, $imgfilename, $imgthumbname, $ordering, 
    		$imgowner,  $imgownerid ) = mysql_fetch_row( $result1 );

    # Paging through category

    $id_cache=array();

    $database->setQuery( "SELECT id, ordering, imgfilename FROM #__ponygallery WHERE catid=$catid ORDER BY ordering ASC" );

    $result1=$database->query();

    while ( $row1=@mysql_fetch_object( $result1 ) ) {
            $id_cache[]=$row1->id;
            $fn_cache[]=$picturepath . $row1->imgfilename;
    }

    $act_key=array_search( $id, $id_cache );
    $nid=(isset( $id_cache[$act_key + 1] )) ? $id_cache[$act_key + 1] : 0;
    $pid=(isset( $id_cache[$act_key - 1] )) ? $id_cache[$act_key - 1] : 0;

    unset($id_cache);
    if ($ag_slideshow)
        include "$mosConfig_absolute_path/components/com_ponygallery/slideshow.ponygallery.php";

    echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
    echo "<tr><td width='100'>";
    if ( $pid > 0 )
        echo "<a href='index.php?option=com_ponygallery&Itemid=$Itemid&func=detail&id=$pid'>" . _PONYGALLERY_LAST_IMAGE . '</a>';
    echo "</td><td align='center'>";
    if ( $ag_slideshow )
        echo _PONYGALLERY_SLIDESHOW .": <a href='javascript:stopstatus=0;runSlideShow()'>" . _PONYGALLERY_START . "</a> - <a href='javascript:endSlideShow()'>"._PONYGALLERY_STOP."</a>";
    echo "</td><td align='right' width='100'>";
    if ( $nid > 0 )
        echo "<a href='index.php?option=com_ponygallery&Itemid=$Itemid&func=detail&id=$nid'>"._PONYGALLERY_NEXT_IMAGE."</a>";
    echo "</td></tr></table><p />";

    # Update View counter

    $imgcounter++;
    $database->setQuery("UPDATE #__ponygallery SET imgcounter='$imgcounter' WHERE id=$id");
    $database->query();
    # show picture

	$imgfilename_ori = 'originals/' . $imgfilename;
	$imginfo = getimagesize($mosConfig_absolute_path . $ag_pathimages . '/' . $imgfilename_ori);
	
	if ($imginfo == null) 
		die(_PONYGALLERY_FOUR_ERR);
	
	// height/width
	$srcWidth = $imginfo[0];
	$srcHeight = $imginfo[1];
	
	echo '<center>'; 
	if ($ag_resizetomaxwidth) {
		echo "<a href=\"javascript:void makepopup('$picturepath$imgfilename_ori', 'PonyGallery', $srcWidth, $srcHeight)\">";				
	} 
	echo "<img src='$picturepath$imgfilename' border='1' name='". _PONYGALLERY_SLIDESHOW."'>";
	if ($ag_resizetomaxwidth) {
		echo '</a>';		
	} 
	echo '</center>';
    # show picture data

    if ( $ag_showdetail ) {
            $fimgdate=strftime( "%c", $imgdate );
            $imgsize=filesize( "$mosConfig_absolute_path$ag_pathimages/$imgfilename" );
            $fimgsize=number_format( $imgsize / 1024, 2, ",", "." );

            if ( $imgvotes > 0 ) {
                    $fimgvotesum=number_format( $imgvotesum / $imgvotes, 2, ",", "." );
                    $frating="$fimgvotesum ($imgvotes "._PONYGALLERY_VOTES.")";
            } else {
            	$frating=_PONYGALLERY_NO_VOTES;
            }

            echo "<p /><table width='100%' border='0' cellspacing='1' cellpadding='3'>";
            echo "<tr><td colspan='2' class='sectiontableheader'><b>$imgtitle</b></td></tr>";
            echo "<tr class='sectiontableentry1'><td width='30%' valign='top'><b>". _PONYGALLERY_DESCRIPTION.":</b></td><td width='70%' valign='top'>$imgtext</td></tr>";
            echo "<tr class='sectiontableentry2'><td width='30%' valign='top'><b>". _PONYGALLERY_DATUM.":</b></td><td width='70%' valign='top'>$fimgdate</td></tr>";
            echo "<tr class='sectiontableentry1'><td width='30%' valign='top'><b>". _PONYGALLERY_HITS.":</b></td><td width='70%' valign='top'>$imgcounter</td></tr>";
            echo "<tr class='sectiontableentry2'><td width='30%' valign='top'><b>". _PONYGALLERY_RATING.":</b></td><td width='70%' valign='top'>$frating</td></tr>";
            echo "<tr class='sectiontableentry1'><td width='30%' valign='top'><b>"._PONYGALLERY_FILESIZE.":</b></td><td width='70%' valign='top'>$fimgsize KB</td></tr>";
			$cbauthor = ($ag_combuild == true) ? "<a href='index.php?option=com_comprofiler&task=userProfile&user=$imgownerid'><b>$imgowner</b></a>" : "<b>$imgowner</b>";
            echo "<tr class='sectiontableentry2'><td width='30%' valign='top'><b>"._PONYGALLERY_AUTHOR.":</b></td><td width='70%' valign='top'>$cbauthor</td></tr>";
			echo "</table>";
    }

    # show voting area

    if ( $ag_showrating ) {
            echo "<p /><form name='ratingform' action='index.php' target=_top method='post'>";
            echo "<INPUT TYPE='hidden' NAME='option' value='com_ponygallery'>";
            echo "<INPUT TYPE='hidden' NAME='Itemid' value='$Itemid'>";
            echo "<INPUT TYPE='hidden' NAME='func' value='votepic'>";
            echo "<INPUT TYPE='hidden' NAME='id' value='$id'>";
            echo "<table width='100%' border='0' cellspacing='1' cellpadding='3'>";
            echo "<tr><td class='sectiontableheader'><b>". _PONYGALLERY_PICTURE_RATING."</b></td></tr>";
            echo "<tr><td class='sectiontableentry1' align='center'>";
            echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'>1 ("._PONYGALLERY_BAD.")</td>";

            $selitem=floor( $ag_maxvoting / 2 ) + 1;
            for ( $i=1; $i <= $ag_maxvoting; $i++ ) {
                    echo "<td align='center'><input type='radio' value='$i' name='imgvote'";
                    if ( $i == $selitem )
                        echo " checked";
                    echo "></td>";
            }

            $i--;
            echo "<td align='center'>$i ("._PONYGALLERY_GOOD.")</td><td align='center'><input class='button' type='submit' value='" . _PONYGALLERY_VOTE . "' name='" . _PONYGALLERY_VOTE . "'></td></tr></table>";
            echo "</td></tr>";
            echo "</table></form>";
	}

    if ( $ag_anoncomment ) {
        $allowcomment=1;
    } else if ( $my->username ) {
        $allowcomment=1;
    }  else {
    	$allowcomment=0;
    }

    # show comments area

    echo "<p />";

    if ( $ag_showcomment ) {
            if ( $allowcomment ) {
                    echo "<FORM NAME='commentform' ACTION='index.php' TARGET=_top METHOD='POST'>";
                    echo "<INPUT TYPE='hidden' NAME='option' value='com_ponygallery'>";
                    echo "<INPUT TYPE='hidden' NAME='Itemid' value='$Itemid'>";
                    echo "<INPUT TYPE='hidden' NAME='func' value='commentpic'>";
                    echo "<INPUT TYPE='hidden' NAME='id' value='$id'>";
                    if ( !$my->username ) {
                            $ip = $_SERVER['REMOTE_ADDR'];
                            echo "<INPUT TYPE='hidden' NAME='cmtname' value='$ip'>";
                        }
                }

            echo "<table width='100%' border='0' cellspacing='1' cellpadding='4'>";
            echo "<tr><td width='30%' height='20' class='sectiontableheader'>"._PONYGALLERY_AUTHOR."</td>";
            echo "<td width='70%' height='20' class='sectiontableheader'>". _PONYGALLERY_COMMENT."</td></tr>";
            $line=2;
            $database->setQuery( "SELECT cmtid, cmtip, cmtname, cmttext, cmtdate FROM #__ponygallery_comments WHERE cmtpic = '$id' ORDER BY cmtid ASC" );
            $result1=$database->query();

            while ( $row1=mysql_fetch_object( $result1 ) ) {
                    $linecolor=($line % 2) + 1;
                    $database->setQuery( "select id from #__users where username='$row1->cmtname'" );
                    $userid=$database->loadResult();
										if ( $ag_combuild )
											{
                    	echo "<tr class='sectiontableentry" . $linecolor . "'><td width='30%' valign='top'><a href='index.php?option=com_comprofiler&task=userProfile&user=" . $userid . "'><b>" . $row1->cmtname . "</b></a>";
											}
            				else
            					{
            					echo "<tr class='sectiontableentry" . $linecolor . "'><td width='30%' valign='top'><b>" . $row1->cmtname . "</b>";
											}
                    if ( $is_editor ) {
                    	echo "<br><img src='components/com_ponygallery/images/ip.gif' alt='$row1->cmtip' hspace='3' border='0'>";
                        echo "<a href='index.php?option=com_ponygallery&Itemid=$Itemid&func=deletecomment&cmtid=$row1->cmtid'><img src='components/com_ponygallery/images/del.gif' alt='Delete Comment' hspace='3' border='0'></a>";
                    }

                    echo "</td>";
                    $signtime=strftime( "%c", $row1->cmtdate );
                    $origtext=$row1->cmttext;

                    if ( $ag_bbcodesupport )
                        $origtext=bb_decode( $origtext );

                    echo "<td width='70%' valign='top'><span class='small'>"._PONYGALLERY_COMM_ADDED.": $signtime<hr></span>$origtext</td></tr>";
                    $line++;
                }

            # Build up comments form
            $linecolor=($line % 2) + 1;
            $bbcodestatus=array(_PONYGALLERY_BB_OFF, _PONYGALLERY_BB_ON);

            if ($allowcomment) {
            	if ($_COOKIE['sessioncookie'] <> '' ) {
                	$cryptSessionID = md5($_COOKIE['sessioncookie']);
                    $database->setQuery("SELECT username FROM #__session WHERE session_ID='$cryptSessionID'");
                    $result2 = $database->query();
                    list($cmtname) = mysql_fetch_row($result2);
                }
                echo "<tr class='sectiontableentry" . $linecolor . "'><td width='30%' valign='top'><b>" . $my->username . "</b><INPUT TYPE='hidden' NAME='cmtname' VALUE='$my->username'>";
                echo "<p><font class='small'>" . _PONYGALLERY_BBCOD . " <b>$bbcodestatus[$ag_bbcodesupport]</b>.</font></p></td>";
                echo "<TD width='70%' valign='top'><TEXTAREA cols='40' ROWS='4' NAME='cmttext' class='inputbox' wrap='VIRTUAL'></TEXTAREA></TD></TR>";
                echo "<TR class='sectiontableentry" . $linecolor . "'><TD WIDTH='130'></TD>";
                echo "<TD align='right'><br /><INPUT TYPE='button' NAME='send' VALUE= "._PONYGALLERY_SEND." class='button' onClick='validatecomment()'>&nbsp;<input type='reset' value="._PONYGALLERY_DELETE." name='reset' class='button'></TD></TR></TABLE><br /></FORM>";
			} else {
            	echo "<tr class='sectiontableentry" . $linecolor . "'><td width='30%' valign='top'> </td>";
                echo "<TD width='70%' valign='top'>" . _PONYGALLERY_PLEASE_REGISTER . '</TD></TR></TABLE></FORM>';
            }
        }

    //  \/\/\/  Danial was here :)  \/\/\/
    # show send 2 friend area

    if ( !$ag_send2friend ) {
            if ( $my->username ) {
            	$sql = $database->setQuery( "select name,email from #__users where username='$my->username'" );
                $s2y = $database->loadObjectList();
                echo "<p /><form name='send2friend' action='index.php' target=_top method='post'>";
                echo "<INPUT TYPE='hidden' NAME='option' value='com_ponygallery'>";
                echo "<INPUT TYPE='hidden' NAME='func' value='send2friend'>";
                echo "<INPUT TYPE='hidden' NAME='from2friendname' value='" . $s2y[0]->name . "'>";
                echo "<INPUT TYPE='hidden' NAME='from2friendemail' value='" . $s2y[0]->email . "'>";
                echo "<INPUT TYPE='hidden' NAME='id' value='$id'>";
                echo "<table width='100%' border='0' cellspacing='1' cellpadding='3'>";
                echo "<tr><td class='sectiontableheader' colspan=2><b>". _PONYGALLERY_SEND_FRIEND."</b></td></tr>";
                echo "<tr class='sectiontableentry1'><td width='30%' valign='top'><b>". _PONYGALLERY_YOUR_NAME.":</b></td><td width='70%' valign='top'>" . $s2y[0]->name . "</td></tr>";
                echo "<tr class='sectiontableentry2'><td width='30%' valign='top'><b>". _PONYGALLERY_YOUR_MAIL.":</b></td><td width='70%' valign='top'>" . $s2y[0]->email . "</td></tr>";
                echo "<tr class='sectiontableentry2'><td width='30%' valign='top'><b>". _PONYGALLERY_FRIENDS_NAME."</b></td><td width='70%' valign='top'>
    <input type='text' name='send2friendname' size='15' class='inputbox'>
    </td></tr>";
                echo "<tr class='sectiontableentry2'><td width='30%' valign='top'><b>". _PONYGALLERY_FRIENDS_MAIL."</b></td><td width='70%' valign='top'>
    <input type='text' name='send2friendemail' size='15' class='inputbox'>
    </td></tr>";
                echo "<tr class='sectiontableentry1'><td width='30%' valign='top'>&nbsp;</td>
                    <td><br /><INPUT TYPE='button' NAME='send' VALUE='"._PONYGALLERY_SEND."' class='button' onClick='validatesend2friend()'>
    </td></tr>";
                echo "</table>    
    </form>";
            } else {
            	echo "<table width='100%' border='0' cellspacing='1' cellpadding='3'>";
                echo "<tr><td class='sectiontableheader' colspan=2><b>". _PONYGALLERY_SEND_FRIEND."</b></td></tr>";
                echo "<tr class='sectiontableentry1'><td width='70%' valign='top'>". _PONYGALLERY_LOGIN_FIRST."</td></tr>";
                echo "</table><br />";
            }
        }
?>
