require("include/top.php");
unset($submitok);
// check the submitted data
//if($sshotfile&&($sshotfile!="none"))
if(is_uploaded_file($sshotfile))
{
// check user account
if(!$_SESSION["SESSION"]||!$_SESSION["SCENEID"])
$errormessage[]="you need to be logged in first.";
// check if this prod exists
$query = "SELECT count(0) FROM prods WHERE id=".$which;
$result = mysql_query($query);
if(!mysql_result($result,0))
$errormessage[] = "I can't find this prod o_O";
$fileinfo = GetImageSize($sshotfile);
switch($fileinfo[2]) {
case 1:$mytype=".gif";break;
case 2:$mytype=".jpg";break;
case 3:$mytype=".png";break;
default: $errormessage[]="the screenshot is not a valid .gif/jpg or .png file"; break;
}
if($fileinfo[0]>400) {
$errormessage[]="the width of the screenshot must not be greater than 400 pixels";
}
if($fileinfo[1]>300) {
$errormessage[]="the height of the screenshot must not be greater than 300 pixels";
}
if(filesize($sshotfile)>65536) {
$errormessage[]="the size of the screenshot must not be greater than 64Kb";
}
// check if there is already a sshot for this prod
if(file_exists("screenshots/".$which.".gif")||file_exists("screenshots/".$which.".jpg")||file_exists("screenshots/".$which.".png"))
{
if($SESSION_LEVEL=='administrator' || $SESSION_LEVEL=='moderator' || $SESSION_LEVEL=='gloperator')
{
unlink("screenshots/".$which.".jpg");
unlink("screenshots/".$which.".gif");
unlink("screenshots/".$which.".png");
copy($sshotfile,"screenshots/".$which.$mytype);
unlink($sshotfile);
$errormessage[]="there was already a screenshot for this prod but since you're so leet and sexy i allowed you to lick my claw and replace it.";
} else {
$errormessage[]="there is already a screenshot for this prod";
}
}
// if everything is ok
if(!$errormessage)
$submitok=true;
}
// move the submitted sshot to the appropriate location
if(!$submitok&&file_exists($sshotfile)){
unlink($sshotfile);
// move_uploaded_file($sshotfile,"screenshots/".$which.$mytype);
// copy($sshotfile, "screenshots/".$which.$mytype);
// unlink($sshotfile);
}
if($submitok) {
copy($sshotfile,"screenshots/".$which.$mytype);
unlink($sshotfile);
// reward the user
$query ="INSERT INTO screenshots SET ";
$query.="prod=".$which.",";
$query.="user=".$_SESSION["SCENEID_ID"].",";
$query.="added=NOW()";
mysql_query($query);
}
?>