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

require("includes/global.php");

// work out the album id
$albumid = intval($_GET["albumid"]);

// check for actions - admins
if ($usr->Access > 1){
	if ($_POST["do"] == "createalbum"){
		$errormsg = createalbum($_POST["title"], $albumid);
	} elseif ($_POST["do"] == "editalbum"){
		$errormsg = editalbum($albumid, $_POST["title"], $_POST["parent"], $_POST["visible"], $_POST["status"], $_POST["priority"], $_POST["actasalbum"], $_POST["description"]);
	} elseif ($_POST["do"] == "deletealbum"){
		$errormsg = deletealbum($_POST["albumid"], $_POST["confirm"]);
	} elseif ($_POST["do"] == "moderateimages"){
		$errormsg = moderateimages(2, $_POST["ids"], $_POST["decision"], $_POST["allids"]);
	}
}

// check for actions - upload
if ($usr->Access > 0){
	if ($_POST["do"] == "uploadimages"){
		$errormsg = uploadimages($albumid, $_FILES["files"], $_POST["titles"]);
	} elseif ($_POST["do"] == "deleteimage"){
		$errormsg = deleteimage($_POST["imageid"], $_POST["confirm"]);
	}
}

// get album recorset
$sql = "SELECT * FROM " . $dbprefix . "albums WHERE albumid = " . dbSecure($albumid);
$rec = $db->execute($sql);
if ($rec->rows < 1){ notfound(); }

// work out visibility
$vis = ($usr->Access > 1) ? 0 : 1;

// get list of sub-albums
$sql = "SELECT * FROM " . $dbprefix . "albums WHERE parent = " . $rec->fields["albumid"] . " AND visible >= " . $vis . " ORDER BY priority DESC, title ASC";
$alb = $db->execute($sql);
if ($alb->rows > 0){ $subalbums = 1; }

// work out how to sort
if ($_GET["sortby"] == "oldest"){
	$sortby = "oldest first";
	$sortco = "postdate ASC";
} elseif ($_GET["sortby"] == "views"){
	$sortby = "by popularity";
	$sortco = "views DESC";
} elseif ($_GET["sortby"] == "title"){
	$sortby = "by title";
	$sortco = "title ASC";
} else {
	$sortby = "newest first";
	$sortco = "postdate DESC";
}

// get list of images
$sql = "SELECT * FROM " . $dbprefix . "images WHERE albumid = " . $rec->fields["albumid"] . " AND visible = 1 ORDER BY " . $sortco . ", imageid ASC";
$mex = $db->execute($sql);

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = intval($_GET['page']);
    $page = ($page < 1) ? 1 : $page;
}

$maxitems = intval($config["imagesperpage"]);
$maxitems = ($maxitems < 1) ? 1 : $maxitems;
$from = (($page * $maxitems) - $maxitems);
$total_pages = ceil($mex->rows / $maxitems);

$sql .= " LIMIT " . $from . ", " . $maxitems;
$img  = $db->execute($sql);

// work out breadcrumbs
$bread = breadcrumbs("album", $rec->fields["albumid"]);

$pagetitle = "Album: " . $rec->fields["title"];
include("includes/page_header.php");

// set up some base values
$t->set_file("spacer", "spacer");
$t->set_var("FORM_LINK", "viewalbum.php?albumid=" . $albumid);
$t->set_var("ALBUMID", $albumid);
$t->set_var("IMAGE_SIZE", $config["thumbnailsize"]);

if ($alb->rows > 0){
	$t->set_file("subalbums", "viewalbum_subalbums");
	$t->set_file("albumrow", "albumbit");
	
	do {
		$stack = fetchstack($alb->fields["albumid"]);
		$scan  = process_stack($stack);
		
		if ($alb->fields["visible"] == 0 && $alb->fields["status"] == 0){
			$t->set_var("ALBUM_FOLDER", "inactive");
		} elseif ($alb->fields["visible"] == 0){
			$t->set_var("ALBUM_FOLDER", "hidden");
		} elseif ($alb->fields["status"] == 0){
			$t->set_var("ALBUM_FOLDER", "locked");
		} else {
			$t->set_var("ALBUM_FOLDER", "open");
		}
		
		$t->set_var("ALBUM_ALBUMS", number_format(fetchalbumnum($scan, $alb->fields["albumid"])));
		$t->set_var("ALBUM_IMAGES", number_format(fetchimagenum($scan)));
		$t->set_var("ALBUM_LATEST", fetchlatestaddition($scan));
		
		$t->set_var("ALBUM_LINK", "viewalbum.php?albumid=" . $alb->fields["albumid"]);
		$t->set_var("ALBUM_TITLE", $alb->fields["title"]);
		$t->set_var("ALBUM_DESCRIPTION", $alb->fields["description"]);
		$t->parse("ALBUMS", "albumrow", true);
	} while ($alb->loop());
	
	$t->parse("CHILD_ALBUMS", "subalbums");
	$t->set_var("ALBUM_IMAGES", "");
}

if ($img->rows < 1){
	$t->set_file("albumimages", "viewalbum_noimages");
	$t->parse("ALBUM_IMAGES", "albumimages");
} else {
	// album sorting
	$t->set_file("albumsorting", "viewalbum_sorting");
	$t->set_var("CURRENT_SORTING", $sortby);
	
	$t->set_var("SORTLINK_NEW", "viewalbum.php?albumid=" . $albumid . "&amp;sortby=newest");
	$t->set_var("SORTLINK_OLD", "viewalbum.php?albumid=" . $albumid . "&amp;sortby=oldest");
	$t->set_var("SORTLINK_VIEWS", "viewalbum.php?albumid=" . $albumid . "&amp;sortby=views");
	$t->set_var("SORTLINK_TITLE", "viewalbum.php?albumid=" . $albumid . "&amp;sortby=title");
	
	$t->parse("ALBUM_IMAGES", "albumsorting");
	
	// insert paging
	$t->set_file("albumpaging", "viewalbum_paging");
	$t->set_var("PAGING", dopaging($total_pages, $page, "viewalbum.php?albumid=" . $albumid . "&amp;sortby=" . $_GET["sortby"]));
	$t->parse("ALBUM_IMAGES", "albumpaging", true);
	
	// loop through images
	$t->set_file("imgbit_container", "imagebit_container");
	
	if ($config["thumbnailswithoutgd"] == "true"){
		$t->set_file("imgbit", "imagebit_size");
	} else {
		$t->set_file("imgbit", "imagebit");
	}
	
	$row = 0;
	$imagesperrow = intval($config["imagesperrow"]);
	$imagesperrow = ($imagesperrow < 1) ? 1 : $imagesperrow;
	
	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"]);
		}
		
		$t->set_var("IMAGE_LINK", "viewimage.php?imageid=" . $img->fields["imageid"]);
		$t->set_var("IMAGE_CAPTION", $img->fields["title"]);
		$t->parse("IMAGEBIT", "imgbit");
		
		if ($row == $imagesperrow){
			$row = 0;
			$t->set_var("ROW_CODE", "</tr><tr>");
		} else {
			$t->set_var("ROW_CODE", "");
		}
		
		$t->parse("IMAGES", "imgbit_container", true);
		$row++;
	
	} while ($img->loop());
	
	// parse it in
	$t->set_file("imagesholder", "viewalbum_images");
	$t->parse("ALBUM_IMAGES", "imagesholder", true);
	
	// insert paging again
	$t->parse("ALBUM_IMAGES", "albumpaging", true);
}

if ($img->rows > 0 || !($subalbums == 1)){
	// parse in album images container
	$t->set_file("albumimagescontainer", "viewalbum_imagescontainer");
	$t->parse("ALBUM_IMAGES_CONTAINER", "albumimagescontainer");
}

if ($img->rows > 0 && $subalbums == 1){
	// parse in spacer
	$t->parse("SPACER_1", "spacer");
}

// parse in upload tools?
if ($usr->Access > 1 || ($usr->Access > 0 && $rec->fields["status"] == 1 && $config["useruploading"] == "true")){
	$t->set_file("uploadtools", "viewalbum_upload");
	$t->set_file("uploadrow", "viewalbum_upload_row");
	
	if ($_POST["uploadfields"] <> ""){
		$uploadfields = intval($_POST["uploadfields"]);
		if ($uploadfields < 1 || $uploadfields > 25){ $uploadfields = 5; }
	} else {
		$uploadfields = 5;
	}
	
	$t->set_var("UPLOAD_FIELDS_COUNT", $uploadfields);
	
	while ($uploadfields > 0){
		$t->parse("UPLOAD_ROWS", "uploadrow", true);
		$uploadfields = ($uploadfields - 1);
	}
	
	$t->parse("UPLOAD_TOOLS", "uploadtools");
}

// parse in admin tools?
if ($usr->Access > 1){
	// first lets do the moderation stuff
	$sql = "SELECT * FROM " . $dbprefix . "images WHERE albumid = " . dbSecure($albumid) . " AND visible = 0 ORDER BY postdate ASC LIMIT 0, 10";
	$tom = $db->execute($sql);
	if ($tom->rows > 0){
		// parse in images to moderate
		$t->set_file("moderate_row", "viewalbum_moderate_row");
		$t->set_file("imagestomoderate", "viewalbum_moderate");
		$allids = "";
		
		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=" . $tom->fields["imageid"]);
			} else {
				$t->set_var("IMAGE_PATH", "generators/thumbnail.php?imageid=" . $tom->fields["imageid"]);
			}
			
			$t->set_var("IMAGE_ID", $tom->fields["imageid"]);
			$t->set_var("IMAGE_LINK", "viewimage.php?imageid=" . $tom->fields["imageid"]);
			$t->set_var("IMAGE_CAPTION", $tom->fields["title"]);
			$t->parse("IMAGEBIT", "imgbit");
			
			if ($tom->fields["title"] <> ""){
				$t->set_var("IMAGE_NAME", $tom->fields["title"]);
			} else {
				$t->set_var("IMAGE_NAME", "Untitled");
			}
			
			$t->set_var("IMAGE_DATE", date($config["dateformat"], $tom->fields["postdate"]));
			$t->set_var("IMAGE_USER", fetchusername($tom->fields["userid"]));
			$t->parse("MODERATEROWS", "moderate_row", true);
			$allids .= $tom->fields["imageid"] . ",";
		} while ($tom->loop());
		
		$allids = substr($allids, 0, -1);
		$t->set_var("MODERATE_ALLIDS", $allids);
		$t->set_var("MODERATE_COLWIDTH", $config["thumbnailsize"]);
		$t->parse("IMAGES_TO_MODERATE", "imagestomoderate");
	}
	
	// now lets do the real admin tools
	$t->set_var("MODERATE_LINK", "moderate.php?page=albums&amp;albumid=" . $rec->fields["albumid"]);
	
	$t->set_var("ADMIN_TITLE", htmlspecialchars($rec->fields["title"]));
	$t->set_var("ADMIN_DESCRIPTION", htmlspecialchars($rec->fields["description"]));
	$t->set_var("ADMIN_PRIORITY", $rec->fields["priority"]);
	
	// album visibility
	if ($rec->fields["visible"] == 1){
		$vis1 = " selected"; $vis2 = "";
	} else{
		$vis1 = ""; $vis2 = " selected";
	}
	
	$t->set_var("ADMIN_VIS1", $vis1);
	$t->set_var("ADMIN_VIS2", $vis2);
	
	// album status
	if ($rec->fields["status"] == 1){
		$vis1 = " selected"; $vis2 = "";
	} else{
		$vis1 = ""; $vis2 = " selected";
	}
	
	$t->set_var("ADMIN_STATUS_1", $vis1);
	$t->set_var("ADMIN_STATUS_2", $vis2);
	
	// act as album
	if ($rec->fields["actasalbum"] == 1){
		$vis1 = " selected"; $vis2 = "";
	} else{
		$vis1 = ""; $vis2 = " selected";
	}
	
	$t->set_var("ADMIN_ACT_1", $vis1);
	$t->set_var("ADMIN_ACT_2", $vis2);
	
	// parent options
	$t->set_var("ADMIN_PARENT_OPTIONS", fetchoptions($rec->fields["parent"], $rec->fields["albumid"]));
	
	// work out form link for deleting album
	if ($rec->fields["parent"] == 0){
		$t->set_var("FORM_LINK_UP", "index.php");
	} else {
		$t->set_var("FORM_LINK_UP", "viewalbum.php?albumid=" . $rec->fields["parent"]);
	}
	
	$t->set_var("RESORT_LINK", "moderate.php?page=reorder");
	$t->set_file("admintools", "viewalbum_admin");
	$t->parse("ADMIN_TOOLS", "admintools");
}

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

$t->set_file("page_content", "viewalbum");
$t->parse("page_all", "page_content", true);

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