Location: PHPKode > scripts > Particle Gallery > moderate.php
<?php
define("IN_SCRIPT", true);

require("includes/global.php");
$pagetitle = "Moderation Panel";

// authorise the user
$usr->Auth(2);

// check for actions
if ($_GET["move"] <> ""){
	$errormsg = reorderalbums($_GET["albumid"], $_GET["move"]);
} elseif ($_POST["do"] == "deletecomment"){
	$errormsg = deletecomments($_POST["commentid"]);
} elseif ($_POST["action"] == "Delete Selected"){
	$errormsg = massdeleteimages($_POST["ids"]);
} elseif ($_POST["action"] == "Move Selected"){
	$errormsg = massmoveimages($_POST["destination"], $_POST["ids"]);
}

// work out breadcrumbs
$bread = breadcrumbs("moderate");

include("includes/page_header.php");

// work out the page
if ($_GET["page"] == "reorder"){
	$t->set_file("page_content", "moderate_reorder");
	$t->set_file("albumrow", "moderate_reorder_row");
	$core = "moderate.php?page=reorder";
	$deep = 0;
	$cur  = 0;
	
	// sub-function for getting lower beings
	function modcp_child_albums($cur){
		global $db, $dbprefix, $t, $deep, $core;
		
		$layer = $deep;
		$pretitle = "";
		while ($layer > 0){
			$pretitle .= "---- ";
			$layer = ($layer - 1);
		} $deep++;
		
		$sql = "SELECT * FROM " . $dbprefix . "albums WHERE parent = " . $cur . " ORDER BY priority DESC, title ASC";
		$erk = $db->execute($sql);
		if ($erk->rows > 0){ do {
				// parse in new template code
				$icore = $core . "&amp;albumid=" . $erk->fields["albumid"] . "&amp;move=";
				$t->set_var("ALBUM_NAME", $pretitle . $erk->fields["title"]);
				$t->set_var("ALBUM_UP", $icore . "up");
				$t->set_var("ALBUM_DOWN", $icore . "down");
				$t->set_var("ALBUM_VIEW", "viewalbum.php?albumid=" . $erk->fields["albumid"]);
				$t->parse("ALBUMROWS", "albumrow", true);
				
				// get children of this one
				$code = modcp_child_albums($erk->fields["albumid"]);
		} while ($erk->loop()); }
		
		$deep--;
	}
	
	// call the function from root
	modcp_child_albums($cur);
	
} elseif ($_GET["page"] == "albums"){
	$t->set_var("ALBUM_OPTIONS", fetchoptions(intval($_GET["albumid"]), 0));
	
	// set info for items amount drop down
	if ($_GET["show"] <> ""){
		$show = intval($_GET["show"]);
		$t->set_var("PS_" . $show, " selected");
		if ($show < 1){ $show = 15; }
	} else {
		$t->set_var("PS_15", " selected");
		$show = 15;
	}
	
	// check for moderating an album
	if (isset($_GET["albumid"])){
		$albumid = intval($_GET["albumid"]);
		
		$sql = "SELECT * FROM " . $dbprefix . "albums WHERE albumid = " . dbSecure($albumid);
		$alb = $db->execute($sql);
		if ($alb->rows < 1){ die("The album could not be found"); }
		
		// build core
		$core = "moderate.php?page=albums&amp;albumid=" . $alb->fields["albumid"] . "&amp;show=" . $_GET["show"] . "&amp;mode=" . $_GET["mode"];
		
		// lets get the images then
		$sql = "SELECT * FROM " . $dbprefix . "images WHERE visible = 1 AND albumid = " . $alb->fields["albumid"] . " ORDER BY postdate DESC, imageid ASC";
		$mex = $db->execute($sql);
		
		if(!isset($_GET["pn"])){
		    $page = 1;
		} else {
		    $page = intval($_GET["pn"]);
		    $page = ($page < 1) ? 1 : $page;
		}
		
		$maxitems = intval($show);
		if ($maxitems < 0 || $maxitems > 1000){ $maxitems = 15; }
		$from = (($page * $maxitems) - $maxitems);
		$total_pages = ceil($mex->rows / $maxitems);
		
		// get page recordset
		$sql .= " LIMIT " . $from . ", " . $maxitems;
		$img  = $db->execute($sql);
		
		// work out mode
		if ($_GET["mode"] == "list"){
			$mode = 2;
			$t->set_var("MODE_2", "selected");
			$t->set_file("itembit", "moderate_albums_row_list");
		} else {
			$mode = 1;
			$t->set_var("MODE_1", "selected");
			
			$t->set_file("imgbit_container", "imagebit_container");
			
			if ($config["thumbnailswithoutgd"] == "true"){
				$t->set_file("itembit", "imagebit_size");
			} else {
				$t->set_file("itembit", "imagebit");
			}
		}
		
		$row = 0;
		$imagesperrow = intval($config["imagesperrow"]);
		$imagesperrow = ($imagesperrow < 1) ? 1 : $imagesperrow;
		$t->set_var("IMAGE_SIZE", $config["thumbnailsize"]);
		
		// loop through rows
		if ($img->rows > 0){ do {
			if ($config["thumbnailswithoutgd"] == "true"){
				$t->set_var("IMAGE_WIDTH", $config["thumbnailsize"]);
				$t->set_var("IMAGE_HEIGHT", $config["thumbnailsize"]);
				$t->set_var("IMAGE_PATH", "generators/original.php?imageid=" . $img->fields["imageid"]);
			} else {
				$t->set_var("IMAGE_PATH", "generators/thumbnail.php?imageid=" . $img->fields["imageid"]);
			}
			
			$capt = ($img->fields["title"] <> "") ? $img->fields["title"] : "Untitled";
			$t->set_var("IMAGE_CAPTION", $capt);
			$t->set_var("IMAGE_ID", $img->fields["imageid"]);
			$t->set_var("IMAGE_UPLOADER", fetchusername($img->fields["userid"]));
			$t->set_var("IMAGE_FORMAT", strtoupper($img->fields["extention"]));
			$t->set_var("IMAGE_DATE", date($config["dateformat"], $img->fields["postdate"]));
			$t->set_var("IMAGE_LINK", "viewimage.php?imageid=" . $img->fields["imageid"]);
			
			if ($mode == 1){
				$t->set_file("imageextra", "moderate_albums_row_thumbs");
				$t->parse("IMAGE_EXTRA", "imageextra");
				
				$t->parse("IMAGEBIT", "itembit");
			} else {
				$t->parse("IMAGES", "itembit", true);
			}
			
			if ($row == $imagesperrow){
				$row = 0;
				$t->set_var("ROW_CODE", "</tr><tr>");
			} else {
				$t->set_var("ROW_CODE", "");
			}
			
			if ($mode == 1){
				$t->parse("IMAGES", "imgbit_container", true);
			}
			$row++;
		} while ($img->loop()); }
		
		// contain the things
		if ($mode == 1){
			$t->set_file("imagescontainer", "viewalbum_images");
		} else {
			$t->set_file("imagescontainer", "moderate_albums_list");
		}
		
		$t->parse("TO_MODERATE", "imagescontainer");
		$t->set_var("ALBUM_PAGING", dopaging($total_pages, $page, $core, "pn"));
		$t->set_file("container", "moderate_albums_album");
		$t->parse("MODERATE_ALBUM", "container");
	}
	
	$t->set_var("MODERATE_FORM_LINK", "moderate.php?page=albums&amp;albumid=" . $alb->fields["albumid"] . "&amp;mode=" . $_GET["mode"] . "&amp;show=" . $show);
	$t->set_var("FORM_LINK", "moderate.php?page=albums");
	$t->set_file("page_content", "moderate_albums");
	
} elseif ($_GET["page"] == "comments"){
	$sql = "SELECT * FROM " . $dbprefix . "comments ORDER BY postdate DESC";
	$mex = $db->execute($sql);
	
	if(!isset($_GET["pn"])){
	    $page = 1;
	} else {
	    $page = intval($_GET["pn"]);
	    $page = ($page < 1) ? 1 : $page;
	}
	
	$maxitems = intval($config["commentsperpage"]);
	$from = (($page * $maxitems) - $maxitems);
	$total_pages = ceil($mex->rows / $maxitems);
	
	$sql .= " LIMIT " . $from . ", " . $maxitems;
	$com = $db->execute($sql);
	$t->set_file("commentrow", "moderate_comments_row");
	
	if ($com->rows > 0){ do {
		$t->set_var("COMMENT_DATE", date($config["dateformat"], $com->fields["postdate"]));
		$t->set_var("COMMENT_ID", $com->fields["commentid"]);
		$t->set_var("COMMENT_USER", fetchusername($com->fields["userid"]));
		$t->set_var("COMMENT_BODY", bbcode($com->fields["comments"]));
		$t->set_var("COMMENT_IMAGE", $com->fields["imageid"]);
		$t->set_var("COMMENT_L_IMAGE", "viewimage.php?imageid=" . $com->fields["imageid"]);
		$t->parse("COMMENT_ROWS", "commentrow", true);
	} while ($com->loop()); }
	
	$t->set_var("COMMENTS_PAGING", dopaging($total_pages, $page, "moderate.php?page=comments", "pn"));
	$t->set_file("page_content", "moderate_comments");
	
} else {
	// get list of albums in need of moderation
	$sql = "SELECT DISTINCT albumid FROM " . $dbprefix . "images WHERE visible = 0 ORDER BY postdate ASC LIMIT 0, 20";
	$als = $db->execute($sql);
	$t->set_file("listbit", "listbit");
	if ($als->rows < 1){
		$t->set_file("listbit", "listbit_nolink");
		$t->set_var("LIST_TEXT", "None");
		$t->parse("ALBUM_ITEMS", "listbit");
	} else { do {
		$t->set_var("LIST_LINK", "viewalbum.php?albumid=" . $als->fields["albumid"]);
		$t->set_var("LIST_TEXT", fetchalbum($als->fields["albumid"], 1));
		$t->parse("ALBUM_ITEMS", "listbit", true);
	} while ($als->loop()); }
	
	// get list of images in need of moderation
	$sql = "SELECT * FROM " . $dbprefix . "reported ORDER BY postdate ASC LIMIT 0, 20";
	$rep = $db->execute($sql);
	$t->set_file("listbit", "listbit");
	if ($rep->rows < 1){
		$t->set_file("listbit", "listbit_nolink");
		$t->set_var("LIST_TEXT", "None");
		$t->parse("IMAGE_ITEMS", "listbit");
	} else { do {
		$t->set_var("LIST_LINK", "viewimage.php?imageid=" . $rep->fields["imageid"]);
		$t->set_var("LIST_TEXT", "#" . $rep->fields["imageid"] . " \"" . $rep->fields["reason"] . "\"");
		$t->parse("IMAGE_ITEMS", "listbit", true);
	} while ($rep->loop()); }
	
	$t->set_file("moderatepanel", "auth_cp_moderate");
	$t->parse("MODERATION_INFO", "moderatepanel");
	
	$t->set_file("page_content", "moderate_mainpage");
}

// parse admin menu
$t->set_file("modcpmenu", "moderate_menu");
$t->set_var("MODCP_L_HOME", "moderate.php");
$t->set_var("MODCP_L_REORDER", "moderate.php?page=reorder");
$t->set_var("MODCP_L_ALBUMS", "moderate.php?page=albums");
$t->set_var("MODCP_L_COMMENTS", "moderate.php?page=comments");
$t->parse("MODERATION_MENU", "modcpmenu");

// parse in error message?
if ($errormsg <> ""){
	$t->set_file("noticebox", "errorbox");
	$t->set_var("MESSAGE", $errormsg);
	$t->parse("ERRORMSG", "noticebox");
}

// parse it in
$t->parse("page_all", "page_content", true);

include("includes/page_footer.php");
?>
Return current item: Particle Gallery