Location: PHPKode > scripts > picKLE > PNpicKLE-1.0beta/index.php
<?php
// ----------------------------------------------------------------------
// Module: PNpicKLE 1.0 beta
// Author: Lance Hart
// ----------------------------------------------------------------------
// This module is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
// ----------------------------------------------------------------------
//
// SETTINGS
//
// Gallery name
$galleryname="PNpicKLE Galleries";
// ID of the admin
$setadmin=2;
// Number of cols
$numcols=6;
// Absolute path to upload dir
$uploaddir="/home/frc/www/modules/PNpicKLE/uploads/";
// Website addy for forum links 
$websiteaddy="http://freeridersclub.com";
// Number of pics members can have in their own albums
$memberpics="50";
//
//
// SETTINGS END
//

if (!defined("LOADED_AS_MODULE")) {
	die ("You can't access this file directly...");
}
$ModName = basename( dirname( __FILE__ ) );
modules_get_language();
// Security check
if (!pnSecAuthAction(0, 'PNpicKLE:PNpicKLE:', '::', ACCESS_READ))
{
	include 'header.php';
	echo _BADAUTHKEY;
	include 'footer.php';
	return;
}
include("header.php");

// Function file
require_once("functions.php");
// Get userid and username
$uid = pnSessionGetVar('uid');
$uname = pnUserGetVar('uname');
// If user is logged in allow them to upload
if($uid and $uname){
	$up_pics='1';
}
/*
echo "<form enctype=\"multipart/form-data\" method=post><br>Select the album to view pics.<br>
<select name=aid><option value=\"\">My member gallery";
$r2=mysql_query("select * from PNpicKLE_albums order by timestamp desc");
while($row2=mysql_fetch_array($r2)){
	$aid=$row2[aid];
	$aname=$row2[aname];
	echo "<option value=\"$aid\">$aname";
}
echo "</select><br><input type=hidden name=go value=1><input name=trac type=submit class=button value=\"go\"></form>";
*/
// Main nav header
echo "<table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3><a href=\"modules.php?op=modload&name=PNpicKLE&file=index\">Gallery Home</a> | <a 
href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=3\">$galleryname</a> |
<a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=2\">Member Galleries</a>";


if($up_pics=='1'){
	echo " | <a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=0\">Upload pics</a>";
}

echo "<br><br><font color=red>For $galleryname or member galleries please click the links above.</font>";

echo "</td></tr></table></h3>";
if($up_pics != '1'){
	echo " (you must login to upload pics)";
}


// If allowed to upload pics
if($up_pics=='1' and $_GET[go]=='0'){
	// Generate form
	echo "<br>As soon as you upload a pic, your gallery will automatically be created.<h3>Please make sure pics are smaller than 150 KB.</h3>Resolution doesn't matter, only size of the file matters.
	In windows right click on the file you are about to upload and click properties.  If \"Size on disk:\" is less than 150 KB, your image will upload with no problems.
	If it's greater than 150 KB you need to resample/resize your image to make it smaller.<br><br>  If you do not know how to resample/resize your images you can download and install:
	<a href=\"http://software.macek.cc/files/JpegResampler.exe\">http://software.macek.cc/files/JpegResampler.exe</a>.
	<br><br>It's a very small and easy to use image resampler. It will batch resample which means it will take a whole directory of images and resample/resize
	them and output them to another directory. Much easier than doing each 1 at a time.
	<br><br>Our image gallery likes images 150 KB or smaller. In the JpegResampler, if you click on the radio button \"Filesize of\" and keep the default
	settings or up to 150 you should be able to upload the \"target directory\" images to free riders without any problems.
	<form enctype=\"multipart/form-data\" action=\"modules.php?op=modload&name=PNpicKLE&file=index&go=0\" method=post>
	<br><font color=red>KEEP IT DECENT - Thanks.</font>";
	
	// CHeck to see if they have more than 50 pics in their member gallery
	$r2=mysql_query("select count(pid) as count from PNpicKLE_pics where aid=\"0\" and oid=\"$uid\"");
	while($row2=mysql_fetch_array($r2)){
		$countpics=$row2[count];
	}
	if($countpics > $memberpics){
		echo "<br><br><b>font color=red>You've reached your limit of $memberpics pics to your member directory.  Please upload to a $galleryname
		(related to THAT gallery) or delete from your member gallery to make room.  Thanks.</font></b><br><br>";
	}
	
	echo "<br><b>Select an album to upload to:</b><br><select name=aid>";
	
	if($countpics >= $memberpics){}else{
		
		echo "<option value=\"\">";
		$memname = pnUserGetVar('uname', $uid);
		echo "$memname's member gallery";
		
	}
	
	$r2=mysql_query("select * from PNpicKLE_albums order by timestamp desc");
	while($row2=mysql_fetch_array($r2)){
		$aid=$row2[aid];
		$aname=$row2[aname];
		echo "<option value=\"$aid\">$aname";
	}
	echo "</select>
	<br><b>Name of pic: <font color=red>(required)</font></b><br><input type=text name=picname size=20 maxlength=20>
	<br><b>Description of pic: </b><br><input type=text name=desc size=42 maxlength=255>
	<br><b>Please select a JPG or GIF to upload:</b><br><input name=\"userfile\" type=\"file\" size=42><br>
	<input type=hidden name=\"MAX_FILE_SIZE\" value=\"150000\"><input name=trac type=submit class=button value=\"Upload\"></form>";
	
	
	// If a file has been uploaded
	if ($_FILES['userfile']['name']) {
		if(!$_POST[picname]){
			echo "<b>ERROR:</b> You must enter a name for the pic.";
			include("footer.php");
			exit;
		}
		// Set upload dir
		// Get image details
		$image_details = getimagesize($_FILES['userfile']['tmp_name']);
		// Check file types and only allow what we want image/jpeg'
		if($_FILES['userfile']['type'] != "image/pjpeg" and $_FILES['userfile']['type'] != "image/jfif" and $_FILES['userfile']['type'] != "image/gif" and $_FILES['userfile']['type'] != "image/jpeg"){
			echo "<b>ERROR:</b> You are trying to upload a file other than a JPG or GIF";
			unset($_FILES['userfile']['tmp_name']);
			include("footer.php");
			exit;
		}
		// Check file size and only allow 150K
		$filesize=$_FILES['userfile']['size'];
		if($filesize > 186000){
			$filesize = round($filesize/1024);
			echo "<b>ERROR:</b> Your file is $filesize KB please make sure the size is smaller than 150 KB.";
			unset($_FILES['userfile']['tmp_name']);
			include("footer.php");
			exit;
		}
		// generate random filename
		$getFileExt=explode(".",$_FILES['userfile']['name']);
		$numDot=count($getFileExt);
		$filename = substr(md5(uniqid(mktime())),0,15);
		$uploadname = $filename.".".$getFileExt[($numDot-1)];
		$uploadthumb = $filename."_thumb.".$getFileExt[($numDot-1)];
		// Set upload filename and path
		$uploadfile = $uploaddir . $uploadname;
		$uploadfilethumb = $uploaddir . $uploadthumb;
		// Move tmp file to real location
		if  (move_uploaded_file($_FILES['userfile']['tmp_name'], "$uploadfile")) {
			$uploaddirthumb="$uploaddir/thumbs/";
			$orig_x=$image_details[0]; $orig_y=$image_details[1]; $tmax_x=100; $tmax_y=100; $max_x=640; $max_y=640;
			$type=$_FILES['userfile']['type'];
			$newthumb = thumbnail($uploaddir,$uploaddirthumb,$uploadname,$orig_x,$orig_y,$tmax_x,$tmax_y);
			$newresize = resize($uploaddir,$uploadname,$orig_x,$orig_y,$max_x,$max_y);
			$ip=$_SERVER[REMOTE_ADDR];
			$filesize=filesize($uploadfile);
			$result = mysql_query("insert PNpicKLE_pics set oid=\"$uid\", file=\"$uploadname\", ip=\"$ip\",
			filesize=\"$filesize\", description=\"$_POST[desc]\", aid=\"$_POST[aid]\", picname=\"$_POST[picname]\"")
			or die("Invalid query: " . mysql_error());
			echo "<b>Upload complete:</b><br><img src=\"modules/PNpicKLE/uploads/thumbs/$uploadname\">";
			// Delete temp file
			//unset($_FILES['userfile']['tmp_name']);
		} else {
			echo "<b>ERROR:</b> Something went wrong, we'll blame it on Sinsee!";
			include("footer.php");
			exit;
		}
	}
}

//if($_GET[go]=='3' or !$_GET[go] and $_GET[go] <> '0'){
	if($_GET[go]=='3'){
		echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3>$galleryname</h3></td></tr></table>";
		$r2=mysql_query("select * from PNpicKLE_albums");
		$i=0;
		while($row2=mysql_fetch_array($r2)){
			$aid=$row2[aid];
			$aname=$row2[aname];
			$r4=mysql_query("select timestamp, DATE_FORMAT(timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_pics where aid = '$aid' order by timestamp desc limit 1");
			while($row4=mysql_fetch_array($r4)){
				$timestamp=$row4[timestamp];
				$timestamp2=$row4[timestamp2];
			}
			$r3=mysql_query("select count(pid) as count from PNpicKLE_pics where aid = '$aid' limit 1");
			while($row3=mysql_fetch_array($r3)){
				$piccount=$row3[count];
			}
			if(!$timestamp2){
				$timestamp2="No pics yet.";
			}
			// lower so it sorts correctly
			$anamesort=strtolower($aname);
			$PNpicKLE_galleries[$i] = array('aid' => $aid, 'anamesort' => $anamesort, 'aname' => $aname, 'timestamp' => $timestamp, 'timestamp2' => $timestamp2, 'piccount' => $piccount);
			$i++;
			$timestamp=NULL;
			$timestamp2=NULL;
			$piccount=NULL;
			$aname=NULL;
			$aid=NULL;
		}
		array_qsort2($PNpicKLE_galleries, "anamesort");
		echo "<table width=100% cellpadding=2>";
		$count=0;
		for ($x=0; $x < count($PNpicKLE_galleries); $x++) {
			$count++;
			if($count=='0'){ echo "<tr>"; }
			echo "<td align=middle><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=1&a=".$PNpicKLE_galleries[$x][aid]."\"><img src=\"modules/PNpicKLE/folder.png\" 
			border=\"0\"></a><br><b>".$PNpicKLE_galleries[$x][aname]."</b><br>Last updated:<br> ".$PNpicKLE_galleries[$x][timestamp2]."<br>Number of pics: ".$PNpicKLE_galleries[$x][piccount]."</td>";
			if($count==$numcols){ echo "</tr>"; $count=0; }
		}
		echo "</table>";
	}
	
	//if($_GET[go]=='2' or !$_GET[go] and $_GET[go] <> '0'){
		if($_GET[go]=='2'){
			echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3>Member Galleries</h3></td></tr></table>";
			$r2=mysql_query("select DISTINCT oid from PNpicKLE_pics where aid = '0'");
			$i=0;
			while($row2=mysql_fetch_array($r2)){
				$oid=$row2[oid];
				$picuname = pnUserGetVar('uname', $oid);
				$r4=mysql_query("select timestamp, DATE_FORMAT(timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_pics where aid = '0' and oid = '$oid' order by timestamp desc limit 1");
				while($row4=mysql_fetch_array($r4)){
					$timestamp=$row4[timestamp];
					$timestamp2=$row4[timestamp2];
				}
				$r3=mysql_query("select count(pid) as count from PNpicKLE_pics where aid = '0' and oid = '$oid' limit 1");
				while($row3=mysql_fetch_array($r3)){
					$piccount=$row3[count];
				}
				//lower so it sorts correctly
				$picunamesort=strtolower($picuname);
				$member_galleries[$i] = array('oid' => $oid, 'usernamesort' => $picunamesort, 'username' => $picuname, 'timestamp' => $timestamp, 'timestamp2' => $timestamp2, 'piccount' => $piccount);
				$i++;
			}
			//array_qsort2($member_galleries, "timestamp", SORT_DESC);
			array_qsort2($member_galleries, "usernamesort");
			echo "<table width=100% cellpadding=2>";
			$count=0;
			for ($x=0; $x < count($member_galleries); $x++) {
				$count++;
				if($count=='0'){ echo "<tr>"; }
				echo "<td align=middle><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=1&u=".$member_galleries[$x][oid]."\">
				<img src=\"modules/PNpicKLE/folder.png\" border=\"0\"></a><br><b>".$member_galleries[$x][username]."</b><br>Last updated:<br>
				".$member_galleries[$x][timestamp2]."<br>Number of pics: ".$member_galleries[$x][piccount]."</td>";
				if($count==$numcols){ echo "</tr>"; $count=0; }
			}
			echo "</table>";
		}
		if($_GET[go]=='1'){
			if(!$_GET[a]){
				$where="where oid=\"$_GET[u]\" and aid=\"0\"";
			} else {
				$where="where aid=\"$_GET[a]\"";
			}
			// List all pics in PNpicKLE_pics
			$picuname = pnUserGetVar('uname', $u);
			if(!$_GET[a]){
				echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3>$picuname's Gallery</h3>
				</td></tr></table>";
			}else{
				$r2=mysql_query("select aname from PNpicKLE_albums where aid=\"$a\"");
				while($row2=mysql_fetch_array($r2)){
					$aname=$row2[aname];
				}
				echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3>$aname Gallery</h3></td></tr></table>";
			}
			echo "<table width=100% cellpadding=2>";
			$r2=mysql_query("select picname, pid, file, oid, description, filesize, DATE_FORMAT(timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_pics $where order by timestamp desc");
			while($row2=mysql_fetch_array($r2)){
				$file=$row2[file];
				$oid=$row2[oid];
				$pid=$row2[pid];
				$description=$row2[description];
				$picname=$row2[picname];
				$filesize=$row2[filesize];
				$timestamp2=$row2[timestamp2];
				$picuname = pnUserGetVar('uname', $oid);
				$count++;
				if($count=='0'){ echo "<tr>"; }
				echo "<td align=middle><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=4&p=$pid\"><img src=\"modules/PNpicKLE/uploads/thumbs/$file\" border=\"1\"></a>
				<br>$picname<br>$timestamp2";
				if($oid==$uid or $uid==$setadmin and $uid <> ''){
					echo "<br><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=5&p=$pid&u=$oid\">Delete</a> -
					<a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=6&p=$pid\">Edit</a>";
				}
				echo "</td>";
				if($count==$numcols){ echo "</tr>"; $count=0; }
			}
			if(!$picname){ echo "<tr><td>No pics yet.</td></tr>"; }
			echo "</table>";
		}
		if($_GET[go]=='4' and $_GET[p]){
			// Hits counter
			// put hits in own table PNpicKLE_stats
			$r2=mysql_query("select pid from PNpicKLE_stats where pid=\"$p\" limit 1");
			while($row2=mysql_fetch_array($r2)){
				$pidtest2=$row2[pid];
			}
			if(!$pidtest2){
				mysql_query("insert PNpicKLE_stats set hits = '1', pid=\"$p\"") or die(mysql_error());
			} else {
				mysql_query("update PNpicKLE_stats set hits = hits + 1 where pid=\"$p\"") or die(mysql_error());
			}
			$r2=mysql_query("select hits from PNpicKLE_stats where pid=\"$p\" limit 1");
			while($row2=mysql_fetch_array($r2)){
				$hits=$row2[hits];
			}
			$r2=mysql_query("select aid, picname, pid, file, oid, description, filesize, DATE_FORMAT(timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_pics where pid=\"$p\" limit 1");
			while($row2=mysql_fetch_array($r2)){
				$file=$row2[file];
				$oid=$row2[oid];
				$pid=$row2[pid];
				$aid=$row2[aid];
				$description=$row2[description];
				$picname=$row2[picname];
				$filesize=$row2[filesize];
				$timestamp2=$row2[timestamp2];
				$picuname = pnUserGetVar('uname', $oid);
				$pidtest=$pid;
				echo "<h3><br>";
				if($aid=='0'){
					echo "$picuname's Gallery<br>
					<a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=1&u=$oid\">See all the pics in 
					$picuname's gallery</a>";
					
				} else {
					$r2=mysql_query("select * from PNpicKLE_pics,PNpicKLE_albums where PNpicKLE_pics.aid=PNpicKLE_albums.aid and PNpicKLE_pics.pid=\"$p\"");
					while($row2=mysql_fetch_array($r2)){
						$aname=$row2[aname];
						$aid=$row2[aid];
					}
					echo "$aname Gallery<br>
					<a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=1&a=$aid\">See all the pics the $aname 
					gallery</a>";
				}
				echo "</h3>";
				echo "<table width=650 align=center><tr>";
				$filesize = round($filesize / 1024);
				if(!$description){ $description="No description added."; }
				echo "<td align=center>$nopicsyet<b>&nbsp  Pic Name:</b> $picname<br><b>Description:</b> $description<br>
				<img src=\"modules/PNpicKLE/uploads/$file\" border=\"1\"><br>
				<b>Copy and paste into a FRC forum post:</b><br> [img]$websiteaddy/modules/PNpicKLE/uploads/".$file."[/img]<br>
				<b>&nbsp  Picture owner:</b> <a href=\"/index.php?name=PNphpBB2&file=profile&mode=viewprofile&u=$oid\"><b>$picuname</b></a><br><b>&nbsp Pic uploaded:</b> $timestamp2<br>
				<b>&nbsp Hits:</b> $hits<br><b>&nbsp Size:</b> $filesize KB";
				if($oid==$uid or $uid==$setadmin and $uid <> ''){
					echo "<br><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=5&p=$pid&u=$oid\">Delete</a> -
					<a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=6&p=$pid\">Edit</a>";
				}
				echo "</td></tr></table>";
				
				if($aid=='0'){
					$where="where oid=\"$oid\" and aid=\"0\"";
				} else {
					$where="where aid=\"$aid\"";
				}
				$j=0;
				$r3=mysql_query("select * from PNpicKLE_pics $where order by timestamp desc");
				while($row3=mysql_fetch_array($r3)){
					$file=$row3[file];
					$pid=$row3[pid];
					$pics[$j]=array('file' => $file, 'pid' => $pid);
					$j++;
				}
				$countarray=count($pics);
				for ($x=0; $x < count($pics); $x++) {
					if($pidtest==$pics[$x][pid]){
						$before=$x-1;
						$after=$x+1;
						
						$beforeid=$pics[$before][pid];
						$beforefile=$pics[$before][file];
						$afterid=$pics[$after][pid];
						$afterfile=$pics[$after][file];
						
						if($before >= '0'){
							echo "<table width=650 align=center><tr><td align=left width=216><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=4&p=$beforeid\">
							<img src=\"modules/PNpicKLE/uploads/thumbs/$beforefile\" border=\"1\"><br><---Previous</a></td>";
						}else{
							echo "<table width=650 align=center><tr><td align=left width=216><img src=\"modules/PNpicKLE/blank.gif\"></td>";
						}
						
						echo "<td align=center width=217><h3>$after of $countarray</h3></td>";
						
						if($after < count($pics)){
							echo "<td align=right width=200><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=4&p=$afterid\">
							<img src=\"modules/PNpicKLE/uploads/thumbs/$afterfile\" border=\"1\"><br>Next---></a></td>";
						}else{
							echo "<td align=right width=><img src=\"modules/PNpicKLE/blank.gif\"></td>";
						}
						
						echo "</tr></table>";
						
						if($_POST[addcomment]=='1' and $_POST[comment]){
							
							$r4=mysql_query("select cid, comment from PNpicKLE_comments where pid=\"$pidtest\"");
							while($row4=mysql_fetch_array($r4)){
								$cidtest=$row4[cid];
								$commenttest=$row4[comment];
							}
							// check for dupe
							if($cidtest==$uid and $commenttest==$_POST[comment]){
							} else {
								mysql_query("insert PNpicKLE_comments set cid=\"$uid\", pid=\"$pidtest\", comment=\"$_POST[comment]\" ") or die(mysql_error());
							}
						}
						
						echo "<table width=500 align=center><tr><td colspan=3>";
						
						if($up_pics=='1'){
							echo "<form method=POST action=".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."><b>
							Comments:<br></b> <input type=text name=comment size=50 maxlength=150>
							<input type=hidden name=addcomment value=1><INPUT TYPE=submit NAME=submit VALUE='add'></form>";
						} else {
							echo "<b>Comments:</b> (you must login to post comments)<br><br>";
						}
						
						
						if($_POST[addcomment]=='1' and !$_POST[comment]){
							echo "ERROR: you have to type in a comment silly.<br><br>";
						}
						
						echo "</td></tr>";
						
						$r4=mysql_query("select cid, comment, DATE_FORMAT(timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_comments where pid=\"$pidtest\" order by timestamp desc");
						while($row4=mysql_fetch_array($r4)){
							$cid=$row4[cid];
							$comment=$row4[comment];
							$timestamp2=$row4[timestamp2];
							$cuname = pnUserGetVar('uname', $cid);
							echo "<tr><td width=130 valign=top>$timestamp2</td><td width=120 valign=top><b>$cuname said:</b></td><td width=250>$comment</td></tr>";
						}
						if(!$comment){
							echo "<tr><td colspan=3>No comments yet.</td></tr>";
						}
						
						echo "</table>";
						
					}
				}
			}
		}
		if($_GET[go]=='5' and $_GET[p] <> ''){
			$r2=mysql_query("select file,oid from PNpicKLE_pics where pid=\"$_GET[p]\" limit 1");
			while($row2=mysql_fetch_array($r2)){
				$file=$row2[file];
				$oid=$row2[oid];
			}
			if($uid==$oid or $uid==$setadmin and $uid <> ''){
				if($doit=='1'){
					mysql_query("delete from PNpicKLE_pics where pid=\"$_GET[p]\"") or die(mysql_error());
					mysql_query("delete from PNpicKLE_stats where pid=\"$_GET[p]\"") or die(mysql_error());
					mysql_query("delete from PNpicKLE_comments where pid=\"$_GET[p]\"") or die(mysql_error());
					$pic="$uploaddir/$file";
					$picthumb="$uploaddir/thumbs/$file";
					unlink($pic);
					unlink($picthumb);
					echo "<h3>Done deal, image has been destroyed like the death star.</h3>";
				}else{
					$u=$_GET[u];
					$p=$_GET[p];
					echo "<h2>Are you sure you want to delete this picture?
					<a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=5&p=$p&doit=1&u=$u\">YES</a> -
					<a href=\"javascript:history.go(-1)\">NO</a></h2>";
					echo "<br><img src=\"modules/PNpicKLE/uploads/$file\">";
				}
			} else {
				echo "<h3>I think you're trying to do something shady or you hit refresh after you deleted a pic.  Who knows, either/or you may still be shady.  Haha, just kidding.  ;)</h3>";
			}
		}
		if($_GET[go]=='6' and $_GET[p] <> ''){
			$p=$_GET[p];
			$r2=mysql_query("select timestamp,aid,file,picname,description,oid from PNpicKLE_pics where pid=\"$_GET[p]\" limit 1");
			while($row2=mysql_fetch_array($r2)){
				$picname=$row2[picname];
				$oid=$row2[oid];
				$aid=$row2[aid];
				$file=$row2[file];
				$ptimestamp=$row2[timestamp];
				$description=$row2[description];
			}
			if($_GET[e]=='1' and $oid==$uid or $_GET[e]=='1' and $uid==$setadmin){
				if(!$_POST[picname]){
					echo "<b>ERROR:</b> You must enter a name for the pic.";
					include("footer.php");
					exit;
				}
				mysql_query("update PNpicKLE_pics set aid=\"$_POST[aid]\", picname=\"$_POST[picname]\", description=\"$_POST[desc]\", timestamp=\"$ptimestamp\" where pid=\"$_GET[p]\"") or die(mysql_error());
				echo "<h3>Your picture has been updated.</h3>";
			} else {
				if($uid==$oid or $uid==$setadmin){
					echo "<form action=\"modules.php?op=modload&name=PNpicKLE&file=index&go=6&p=$p&e=1\" method=post><br><b>Select an album to upload to:</b><br>
					<select name=aid>";
					// This is so you can change which album it goes to
					if(!$aid){
						echo "<option value=\"\">My member gallery";
					} else {
						$r2=mysql_query("select * from PNpicKLE_albums where aid=\"$aid\" limit 1");
						while($row2=mysql_fetch_array($r2)){
							$aid=$row2[aid];
							$aname=$row2[aname];
							echo "<option value=\"$aid\">$aname";
						}
					}
					echo "<option value=\"\">My member gallery";
					$r2=mysql_query("select * from PNpicKLE_albums order by timestamp desc");
					while($row2=mysql_fetch_array($r2)){
						$aid=$row2[aid];
						$aname=$row2[aname];
						echo "<option value=\"$aid\">$aname";
					}
					echo "</select><br>
					<b>Name of pic: <font color=red>(required)</font></b><br><input type=text name=picname size=20 maxlength=20 value=\"$picname\">
					<br><b>Description of pic: </b><br><input type=text name=desc size=75 maxlength=255 value=\"$description\"><br><input name=trac type=submit class=button value=\"Edit\"></form>
					<img src=\"modules/PNpicKLE/uploads/$file\">";
				} else {
					echo "<h3>I think you're trying to do something shady.  ;)</h3>";
				}
			}
		}
		
		// Most recent
		if(!$_GET[go] and $_GET[go] <> '0'){
			echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3>Most Recent</h3></td></tr></table>";
			echo "<table width=100% cellpadding=2>";
			$numget=$numcols*4;
			$count=0;
			$r2=mysql_query("select picname, pid, file, DATE_FORMAT(timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_pics order by timestamp desc limit $numget");
			while($row2=mysql_fetch_array($r2)){
				$file=$row2[file];
				$pid=$row2[pid];
				$picname=$row2[picname];
				$timestamp2=$row2[timestamp2];
				if($count=='0'){ echo "<tr>"; }
				$count++;
				echo "<td align=middle><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=4&p=$pid\">
				<img src=\"modules/PNpicKLE/uploads/thumbs/$file\" border=1></a><br>$picname<br>$timestamp2</td>";
				if($count==$numcols){ echo "</tr>"; $count=0; }
			}
			echo "</table>";
		}
		// Most popular
		if(!$_GET[go] and $_GET[go] <> '0'){
			echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3>Most Popular</h3></td></tr></table>";
			echo "<table width=100% cellpadding=2>";
			$numget=$numcols*2;
			$count=0;
			$r2=mysql_query("select PNpicKLE_pics.picname, PNpicKLE_pics.pid, PNpicKLE_pics.file, DATE_FORMAT(PNpicKLE_pics.timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_stats,PNpicKLE_pics where PNpicKLE_pics.pid=PNpicKLE_stats.pid order by hits desc limit $numget");
			while($row2=mysql_fetch_array($r2)){
				$file=$row2[file];
				$pid=$row2[pid];
				$picname=$row2[picname];
				$timestamp2=$row2[timestamp2];
				if($count=='0'){ echo "<tr>"; }
				$count++;
				echo "<td align=middle><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=4&p=$pid\">
				<img src=\"modules/PNpicKLE/uploads/thumbs/$file\" border=1></a><br>$picname<br>$timestamp2</td>";
				if($count==$numcols){ echo "</tr>"; $count=0; }
			}
			echo "</table>";
		}
		// Most recent comments
		if(!$_GET[go] and $_GET[go] <> '0'){
			echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><h3>Recent Comments</h3></td></tr></table>";
			echo "<table width=100% cellpadding=2>";
			$numget=$numcols*2;
			$count=0;
			
			$r2=mysql_query("select * from PNpicKLE_comments order by timestamp desc limit $numget");
			while($row2=mysql_fetch_array($r2)){
				$pid=$row2[pid];
				
				$r3=mysql_query("select PNpicKLE_pics.picname, PNpicKLE_pics.pid, PNpicKLE_pics.file, DATE_FORMAT(PNpicKLE_pics.timestamp,'%m/%d/%y %r') as timestamp2 from PNpicKLE_pics where pid=\"$pid\"");
				while($row3=mysql_fetch_array($r3)){
					$file=$row3[file];
					$pid=$row3[pid];
					$picname=$row3[picname];
					$timestamp2=$row3[timestamp2];
					if($count=='0'){ echo "<tr>"; }
					$count++;
					echo "<td align=middle><a href=\"modules.php?op=modload&name=PNpicKLE&file=index&go=4&p=$pid\">
					<img src=\"modules/PNpicKLE/uploads/thumbs/$file\" border=1></a><br>$picname<br>$timestamp2</td>";
					if($count==$numcols){ echo "</tr>"; $count=0; }
				}
			}
			
			echo "</table>";
		}
		
		echo "<br><table width=100%><tr bgcolor=\"#D3D3D3\"><td><center>Indexed by PNpicKLE 1.0 beta ©2005</center></td></tr></table>";
		include("footer.php");
		?>
Return current item: picKLE