\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; //print "\n"; print "
Remove a ".strtolower($singular)." from the Database*
$singular to Delete: \n"; print "\n"; print "

*note: this will also delete the $singular from the server to free up space for more $mediaType
\n"; print "
\n"; } // end deleteMediaForm(...) //// // Displays a form to start editing of an object of the given media type. //// function editMediaForm($mediaType){ $db = dil_connect(); $action = ""; $singular = ucfirst(getSingular($mediaType)); print "
\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; //print "\n"; print "
Edit a ".strtolower($singular)."*
$singular to edit: \n"; print "\n"; print "

*note: unless you are an admin, you are only allowed to edit the $mediaType that you submitted
\n"; print "

\n"; } // end editMediaForm(...) //// // Processes the post made by deleteMediaForm(...) //// function processDeleteMedia($mediaType){ if(isset($_POST['deleteMe'])){ $deleteMe = $_POST['deleteMe']; $db = dil_connect(); $queryString = "SELECT url,thumbUrl,title FROM $mediaType WHERE id=$deleteMe"; if($result = mysql_query($queryString,$db)){ if(($numRows = mysql_num_rows($result)) && ($numRows > 0)){ $cnt=0; $url = mysql_result($result,$cnt, "url_orig"); $title = mysql_result($result,$cnt, "title"); $thumbUrl = mysql_result($result, $cnt, "url_thumb"); if(unlink($url)){ if(($thumbUrl != "") && (false == unlink($thumbUrl))){ dispError("Couldn't unlink thumbnail: $thumbUrl"); logEvent("Couldn't unlink thumbnail: $thumbUrl"); } $queryString = "DELETE FROM $mediaType WHERE id=$deleteMe"; if(mysql_query($queryString,$db)){ dispSuccess("$title deleted."); } } else { dispError("Could not delete $title from the server."); } } else { dispError("Mo results for $queryString"); } } else { dispError(mysql_error()."

$queryString"); } } else { dispError("Id to delete was not set."); } } // end processDeleteMedia(...) //// // Displays a form to add or edit flash media (games or flash media). //// function dispFlashMediaForm($mediaType){ $singular = getSingular($mediaType); $singularCaps = ucfirst($singular); $action = ""; $db = dil_connect(); GLOBAL $init; $thisForm = "add"; if(isset($init['id']) && ($init['id'] != "")){ $thisForm = "edit"; } print "
\n"; print "\n"; if($thisForm == "edit"){ print "\n"; } print "
\n"; if($thisForm == "add"){ print "\n"; } else { print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $queryString = "SELECT category FROM categories WHERE mediaType='$mediaType'"; if($result = mysql_query($queryString,$db)){ if(($numRows = mysql_num_rows($result)) && ($numRows > 0)){ print "\n"; } } print "\n"; print "
Add a $singular to the database
Edit $singular
".(($mediaType!="movies")?"Flash f":"F")."ile: "; if($thisForm == "edit"){ print "
(leave blank to
keep same $singular)"; } print "
Thumbnail: "; if($thisForm == "edit"){ print "
(leave blank to
keep same thumbnail)
"; } print "(scales automatically)
(optional)
Name of $singularCaps:
Tags: (comma separated)
Caption:
Categories: "; print "
\n"; print "
\n"; } // end dispFlashMediaForm(...) //// // Processes any adds or updates for flash media (flash movies or games). //// function processFlashMediaForm($mediaType){ profiler_beginSection(__METHOD__); $db = dil_connect(); $singular = getSingular($mediaType); $singularCaps = ucfirst($singular); GLOBAL $init; $initOrig = array( "id" => "", "title" => "", "caption" => "", "tags" => "", "categories" => "", "url_thumb" => "", // only used in editing existing entries "fileUrl" => "" // only used in editing existing entries ); $init = $initOrig; $formName = ""; if(isset($_POST['formName']) && $_POST['formName'] != ""){ $formName = $_POST['formName']; } if($formName == "startEdit$singularCaps"){ if(isset($_POST['editMe']) && $_POST['editMe']){ $id = $_POST['editMe']; $queryString = "SELECT * FROM $mediaType WHERE id=$id"; if($result = mysql_query($queryString,$db)){ if(($numRows = mysql_num_rows($result)) && ($numRows > 0)){ $cnt = 0; $init['id'] = $id; $init['title'] = mysql_result($result, $cnt, "title"); $init['caption'] = mysql_result($result, $cnt, "caption"); $init['tags'] = stringFromTags(getTags($mediaType, $id)); $init['categories'] = mysql_result($result, $cnt, "categories"); $init['thumbUrl'] = mysql_result($result, $cnt, "url_thumb"); $init['fileUrl'] = mysql_result($result, $cnt, "url_orig"); } } } } else if(($formName == "add$singularCaps") || ($formName == "edit$singularCaps")){ grabVal("id"); grabVal("title"); grabVal("caption"); grabVal("tags"); grabVal("categories"); $editMode = false; if($init['id'] != ""){ $editMode = true; $queryString = "SELECT * FROM $mediaType WHERE id=".$init['id']; if($result = mysql_query($queryString,$db)){ if(($numRows = mysql_num_rows($result)) && ($numRows > 0)){ $cnt = 0; $prevData['id'] = mysql_result($result, $cnt, "id"); $prevData['title'] = mysql_result($result, $cnt, "title"); $prevData['caption'] = mysql_result($result, $cnt, "caption"); $prevData['tags'] = stringFromTags(getTags($mediaType, $id)); $prevData['categories'] = mysql_result($result, $cnt, "categories"); $prevData['thumbUrl'] = mysql_result($result, $cnt, "url_thumb"); $prevData['fileUrl'] = mysql_result($result, $cnt, "url_orig"); } } } include 'fileupload-class.php'; $contentDirectory = "./content/$mediaType/"; $acceptable_file_types = ""; $default_extension = ""; $mode = 2; $postIndex = "fileName"; // the name used in the form $errString = ""; if($init['title'] == ""){ $errString.= "Please enter the name of the $singular.
\n"; dispError($errString); } else { include_once 'fileupload-class.php'; $my_uploader = new uploader(); //$my_uploader->max_filesize(1594967295); //$my_uploader->max_image_size(2000, 2000); $fileName = ""; if ($my_uploader->upload("fileName", $acceptable_file_types, $default_extension)){ $my_uploader->save_file($contentDirectory, $mode); } if($my_uploader->error != ""){ if($editMode){ $fileName = $prevData['fileUrl']; } else { dispError("Error uploading: ".$my_uploader->error); } } else { $fileName = $contentDirectory.$my_uploader->file['name']; if($editMode && ($fileName != $prevData['fileUrl'])){ if(false === unlink($prevData['fileUrl'])){ logEvent("When editing $singular ".$init['id']." (".$init['title'].") could not delete file".$prevData['fileUrl']); dispMsg("Unable to delete the old $singular from the server. This problem has been logged."); } } } if($fileName != ""){ // Format the tags $tags = $init['tags']; if(strlen($tags) > 0){ /*if(substr($tags, 0, 1) != ","){ // Old system (when tags were strings) $tags = ",$tags"; } if(substr($tags, -1, 1) != ","){ $tags .= ","; }*/ $tags = preg_replace("/\s*,\s*/", ",", $tags); $tags = preg_replace("/,,/", ",", $tags); } $init['tags'] = $tags; // Format the categories $cats = $init['categories']; $categoryString = ","; for($cnt=0; $cnterror = ""; if ($my_uploader->upload("thumbName", $acceptable_file_types, $default_extension)){ $my_uploader->save_file($contentDirectory, $mode); if($my_uploader->error != ""){ if($editMode){ $thumbName = $prevData['thumbUrl']; } else { dispError("Error uploading: ".$my_uploader->error); } } else { $thumbName = $contentDirectory.$my_uploader->file['name']; $THUMB_WIDTH = 100; $THUMB_HEIGHT = 100; exec("mogrify -scale $THUMB_WIDTH"."x$THUMB_HEIGHT $thumbName $thumbName"); // scales thumbnail if($editMode && ($thumbName != $prevData['thumbUrl'])){ if(($prevData['thumbUrl'] != "") && (false === unlink($prevData['thumbUrl']))){ logEvent("When editing $singular ".$init['id']." (".$init['title'].") could not delete file".$prevData['thumbUrl']); dispMsg("Unable to delete the old $singular thumbnail from the server. This problem has been logged."); } } } } // If this is a normal movie (not flash or a still image), use getId3 to determine the dimensions $movieWidth = $movieHeight = 0; // if this doesn't change then it won't be updated in database if(($mediaType == "movies") && (($formName == "add$singularCaps") || ($fileName != $prevData['fileUrl']))){ include_once './getid3/getid3.php'; $getID3 = new getID3; $fileinfo = $getID3->analyze($fileName); getid3_lib::CopyTagsToComments($fileinfo); if(isset($fileInfo['video']['resolution_x'])){ $movieWidth = $fileInfo['video']['resolution_x']; } if(isset($fileInfo['video']['resolution_y'])){ $movieHeight= $fileInfo['video']['resolution_y']; } } $db = dil_connect(); $user = getUser(); $username = $user->getUsername(); $userId = $user->getId(); if($editMode){ $queryString = "UPDATE $mediaType SET url='$fileName', thumbUrl='$thumbName', "; $queryString.= "title='".$init['title']."', caption='".$init['caption']."', "; $queryString.= "categories='$categoryString'"; if(($mediaType == "movies") && ($movieWidth != 0)){ $queryString.= ", width=$movieWidth, height=$movieHeight"; } $queryString.= " WHERE id=".$prevData['id']; $tagId = $prevData['id']; } else { $queryString = "INSERT INTO $mediaType (submittedBy_username,submittedBy_id,url,thumbUrl,title,caption,categories,submittedOn"; if($mediaType == "movies"){ $queryString.= ",width,height"; } $queryString.= ") VALUES "; $queryString.= "('$username', '$userId', '$fileName', '$thumbName', '".$init['title']."','".$init['caption']; $queryString.= "', '$categoryString', NOW()"; if($mediaType == "movies"){ $queryString.= ", $movieWidth, $movieHeight"; } $queryString.= ")"; $tagId = -1; // get the id from the insert } if(mysql_query($queryString,$db)){ if($tagId == -1){ $tagId = mysql_insert_id($db); } setTags($mediaType, $tagId, tagsFromString($init['tags'])); if($editMode){ dispSuccess("".$init['title']." updated."); } else { dispSuccess("".$init['title']." added to database."); // TODO: REFACTOR TO USE "userStats" INSTEAD OF DEPRECATED "members" table. if(false===mysql_query("UPDATE members SET $mediaType"."Posted=$mediaType"."Posted+1 WHERE username='$username'", $db)){ logEvent("Couldn't log the addition of a $singular by $username

".mysql_error()); } } $init = $initOrig; } else { dispError(mysql_error()."

Query:
\n".$queryString); logEvent(mysql_error()."

Query:
\n".$queryString); } } } } else if($formName == "delete$singularCaps"){ $user = getUser(); if($user->isAdmin()){ processDeleteMedia("$mediaType"); } } profiler_endSection(__METHOD__); } // end processFlashMediaForm(...) ?>