include("path.php");
require(BASE."include/"."incl.php");
require(BASE."include/"."application.php");
global $current;
/*=========================================================================
*
* this script expects appId and versionId as arguments
*
* OR
*
* cmd and imageId
*/
if($cmd)
{
if(havepriv("admin") || isMaintainer($appId, $versionId))
{
//process screenshot upload
if($cmd == "screenshot_upload")
{
if(!copy($imagefile, "data/screenshots/".$appId."-".$versionId."-".basename($imagefile_name)))
{
// whoops, copy failed. do something
errorpage('debug: copy failed; $imagefile; $imagefile_name');
exit;
}
$query = "INSERT INTO appData VALUES (null, $appId, $versionId, 'image', ".
"'".addslashes($screenshot_desc)."', '".$appId."-".$versionId."-".basename($imagefile_name)."')";
if(debugging()) { addmsg("
query: $query
",green); }
if (mysql_query($query))
{
//success
$email = getNotifyEmailAddressList($appId, $versionId);
if($email)
{
$fullAppName = "Application: ".lookupAppName($appId)." Version: ".lookupVersionName($appId, $versionId);
$ms .= APPDB_ROOT."screenshots.php?appId=$appId&versionId=$versionId"."\n";
$ms .= "\n";
$ms .= ($current->username ? $current->username : "Anonymous")." added screenshot ".$screenshot_desc." to ".$fullAppName."\n";
$ms .= "\n";
$ms .= STANDARD_NOTIFY_FOOTER;
mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
} else
{
$email = "no one";
}
addmsg("mesage sent to: ".$email, green);
addmsg("The image was successfully added into the database", "green");
redirect(apidb_fullurl("screenshots.php?appId=$appId&versionId=$versionId"));
}
else
{
//error
$statusMessage = "Database Error!
".mysql_error()."
\n";
addmsg($statusMessage, "red");
}
} else
{
if($cmd == "delete")
{
$result = mysql_query("DELETE FROM appData WHERE id = $imageId");
if($result)
{
$email = getNotifyEmailAddressList($appId, $versionId);
if($email)
{
$fullAppName = "Application: ".lookupAppName($appId)." Version: ".lookupVersionName($appId, $versionId);
$ms .= APPDB_ROOT."screenshots.php?appId=$appId&versionId=$versionId"."\n";
$ms .= "\n";
$ms .= ($current->username ? $current->username : "Anonymous")." deleted screenshot from ".$fullAppName."\n";
$ms .= "\n";
$ms .= STANDARD_NOTIFY_FOOTER;
mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
} else
{
$email = "no one";
}
addmsg("mesage sent to: ".$email, green);
addmsg("Image deleted", "green");
redirect(apidb_fullurl("screenshots.php?appId=$appId&versionId=$versionId"));
} else
{
addmsg("Failed to delete image: ".mysql_error(), "red");
redirect(apidb_fullurl("screenshots.php?appId=$appId&versionId=$versionId"));
}
}
}
}
exit;
}
$result = mysql_query("SELECT * FROM appData WHERE type = 'image' AND appId = $appId AND versionId = $versionId");
if((!$result || !mysql_num_rows($result)) && (!havepriv("admin") && !isMaintainer($appId, $versionId)))
{
errorpage("No Screenshots Found","There are no screenshots currently linked to this application.");
exit;
}
else
{
apidb_header("Screenshots");
if($result && mysql_num_rows($result))
{
echo html_frame_start("Screenshot Gallery",500);
// display thumbnails
$c = 1;
echo "\n";
while($ob = mysql_fetch_object($result))
{
//set img tag
$imgSRC = '
';
//get image size
$size = getimagesize("data/screenshots/".$ob->url);
//generate random tag for popup window
$randName = generate_passwd(5);
//set image link based on user pref
$img = ''.$imgSRC.'';
if (loggedin())
{
if ($current->getpref("window:screenshot") == "no")
{
$img = ''.$imgSRC.'';
}
}
//display image
echo "\n";
echo html_frame_start(substr(stripslashes($ob->description),0,20),128,"",0);
echo $img;
//show admin delete link
if(loggedin() && (havepriv("admin") || isMaintainer($appId, $versionId)))
{
echo "";
}
echo html_frame_end(" ");
echo " | \n";
//end row if counter of 3
if ($c % 3 == 0) { echo "
\n"; }
$c++;
}
echo "
\n";
echo html_frame_end("Click thumbnail to view image in new window.");
}
if(havepriv("admin") || isMaintainer($appId, $versionId))
{
//image upload box
echo '',"\n";
}
echo html_back_link(1);
apidb_footer();
}
?>