<?php

						/*************************************\

						    Handshakes Professional (3.0)
						            by DZOIC LTD
						       Copyright(c) 2005-2006
						        http://www.dzoic.com

						\*************************************/

						///////////////////////////////////////

						admin_validate_section("manage",13);
						$action = $GLOBALS["Get"]->val("action");

							switch($action){

								case 'photos':
									manage_photos();
									break;

								case 'approve':
									approve_photos();
									break;

								case 'delete':
									delete_photos();
									break;

								case 'approve_all':
									approve_all_photos();
									break;

								case 'delete_all':
									delete_all_photos();
									break;

							}//switch

						///////////////////////////////////////

function manage_photos(){

	$admin = admin_validate();
	$p = $GLOBALS["Get"]->val("p");

	$data["section"] = "manage";
	$data["subsection"] = 13;
	$data["title_id"] = "32";
	$start = $p*30;

	$ret_link = "index.php?section=manage_photos&action=photos&p=".$p;

	$sql_query_total = "SELECT COUNT(pho_id) ";
	$sql_query_result = "SELECT * ";

	$sql_query="FROM photos
				WHERE approved='0'
				ORDER BY pho_id DESC ";

	$total = $GLOBALS["DB"]->single($sql_query_total.$sql_query);

	$sql_query.= "LIMIT ".$start.",30";

	$result = $GLOBALS["DB"]->result($sql_query_result.$sql_query);

	$data["pages"] = handle_multipages($p,$total,"index.php?section=manage_photos&action=photos",30);

	$photos = array();
	foreach($result as $res){
		$photo["photo"]   = $res["photo_small"];
		$photo["caption"] = hs_wordwrap($res["caption"],50);
		$photo["pho_id"]  = $res["pho_id"];
		$photo["mem_id"]  = $res["mem_id"];
		$photo["delete"]  = "index.php?section=manage_photos&action=delete&pho_id=".$res["pho_id"]."&ret_link=".urlencode($ret_link);
		$photo["edit"]    = "javascript:HS_Popup('index.php?section=manage_members&action=edit_photo&pho_id=".$res["pho_id"]."','width=400,height=400,scrollbars=no,menubar=no,resizable=no,location=no')";
		$photo["approve"] = "index.php?section=manage_photos&action=approve&pho_id=".$res["pho_id"]."&ret_link=".urlencode($ret_link);
		$photos[] = $photo;
	}//foreach

	$data["photos"] = $photos;

	$data["link"] = stripslashes(html_entity_decode($ret_link));

	$layout[0] = "photos_list";
	admin_output($layout,$data);

}//manage_photos

function approve_photos(){

	$admin = admin_validate();
	$pho_id = $GLOBALS["Get"]->val("pho_id");
	$ret_link = $GLOBALS["Get"]->val("ret_link");

	if(is_array($pho_id) && count($pho_id)){
		$sql_query = "UPDATE photos
					  SET approved='1'
					  WHERE pho_id IN (".implode(",",$pho_id).")";
		$GLOBALS["DB"]->execute($sql_query);
	}//if
	elseif(!empty($pho_id)){
		$sql_query="UPDATE photos
					SET approved='1'
					WHERE pho_id=".$pho_id;
		$GLOBALS["DB"]->execute($sql_query);
	}//if

	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);
	load_page($ret_link);

}//approve_photo

function delete_photos(){

	$admin = admin_validate();
	$pho_id = $GLOBALS["Get"]->val("pho_id");
	$ret_link = $GLOBALS["Get"]->val("ret_link");

	include_once(DOC_ROOT."/functions/delete_functions.php");

	if(is_array($pho_id) && count($pho_id)){
		foreach($pho_id as $id){
			delete_photo($id);
		}//foreach
	}//if
	elseif(!empty($pho_id))
		delete_photo($pho_id);

	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);
	load_page($ret_link);

}//delete_photos

function approve_all_photos(){

	$admin = admin_validate();
	$ret_link = $GLOBALS["Get"]->val("ret_link");

	$sql_query="UPDATE photos
				SET approved='1'";

	$GLOBALS["DB"]->execute($sql_query);

	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);
	load_page($ret_link);

}//approve_all_photos

function delete_all_photos(){

	$admin = admin_validate();
	$ret_link = $GLOBALS["Get"]->val("ret_link");

	$sql_query = "SELECT pho_id FROM photos WHERE approved='0' AND pho_id > 100000";
	$result = $GLOBALS["DB"]->result($sql_query);

	include_once(DOC_ROOT."/functions/delete_functions.php");

	foreach($result as $res){
		delete_photo($res["pho_id"]);
	}//foreach

	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);
	load_page($ret_link);

}//delete_all_photos

?>