<?php

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

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

						admin_validate_section("manage",16);
						$action = $GLOBALS["Get"]->val("action");
								
							switch($action){								
										
								case '':									
									manage_videos();
									break;
									
								case 'approve':
									approve_videos();
									break;
									
								case 'approve_all':
									approve_all_videos();
									break;
									
								case 'delete_all':
									delete_all_videos();
									break;
									
							}//switch
							
						///////////////////////////////////////
						
function manage_videos(){
	
	$admin = admin_validate();
	$p = $GLOBALS["Get"]->val("p");
	
	$data["section"] = "manage";
	$data["subsection"] = 16;
	$data["title_id"] = "56";	
	$start = $p*30;
	
	$ret_link = "index.php?section=manage_videos&p=".$p;	
	$data["link"] = stripslashes(html_entity_decode($ret_link));
	
	$sql_query_total = "SELECT COUNT(vid_id) ";
	$sql_query_result = "SELECT * ";
	
	$sql_query="FROM videos
				WHERE approved='0'	
				ORDER BY vid_id DESC ";
	
	$total = $GLOBALS["DB"]->single($sql_query_total.$sql_query);
				
	$sql_query.= "LIMIT ".$start.",30";
	
	$results = $GLOBALS["DB"]->result($sql_query_result.$sql_query);
	
	$data["pages"] = handle_multipages($p,$total,"index.php?section=manage_videos",30);	
	
	$data["videos"] = array();
	foreach($results as $result){
		if(hs_strlen($result["title"] > 30))
			$result["title"] = hs_substr($result["title"],0,27)."...";
			
		$media["id"]              = $result["vid_id"];
		$media["title"]           = $result["title"];
		$media["author"]          = $GLOBALS["Network"]->card($result["mem_id"]);
		$media["date"]            = extract_date($result["posted"]);
		$media["view"]            = URL."/index.php?page=videos&section=view&vid_id=".$result["vid_id"];
		$media["approve"]         = "index.php?section=manage_videos&action=approve&vid_id=".$result["vid_id"]."&ret_link=".urlencode($data["link"]);
		$media["edit"]            = "index.php?section=videos&action=edit&vid_id=".$result["vid_id"]."&ret_link=".urlencode($data["link"]);
		$media["delete"]          = "index.php?section=videos&action=delete&vid_id=".$result["vid_id"]."&ret_link=".urlencode($data["link"]);
		$media["featured"]        = $result["featured"];
		$media["featured_add"]    = "index.php?section=videos&action=featured_add&vid_id=".$result["vid_id"]."&ret_link=".urlencode($data["link"]);
		$media["featured_remove"] = "index.php?section=videos&action=featured_remove&vid_id=".$result["vid_id"]."&ret_link=".urlencode($data["link"]);
		
		$data["videos"][] = $media;
	}//foreach
	
	$layout[0] = "unapproved_videos_list";
	admin_output($layout,$data);
	
}//manage_videos

function approve_videos(){
	
	$admin = admin_validate();
	$vid_id = $GLOBALS["Get"]->val("vid_id");
	$ret_link = $GLOBALS["Get"]->val("ret_link");
	
	if(is_array($vid_id) && count($vid_id)){
		$sql_query = "UPDATE videos
					  SET approved='1'
					  WHERE vid_id IN (".implode(",",$vid_id).")";
		$GLOBALS["DB"]->execute($sql_query);
	}//if
	elseif(!empty($vid_id)){
		$sql_query="UPDATE videos
					SET approved='1'
					WHERE vid_id=".$vid_id;	
		$GLOBALS["DB"]->execute($sql_query);
	}//if
	
	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);	
	load_page($ret_link);
	
}//approve_musto

function delete_videos(){
	
	$admin = admin_validate();
	$vid_id = $GLOBALS["Get"]->val("vid_id");
	$ret_link = $GLOBALS["Get"]->val("ret_link");
	
	include_once(DOC_ROOT."/functions/delete_functions.php");
	
	if(is_array($vid_id) && count($vid_id)){
		foreach($vid_id as $id){
			delete_video($id);
		}//foreach
	}//if
	elseif(!empty($vid_id))
		delete_video($vid_id);
	
	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);	
	load_page($ret_link);
	
}//delete_videos

function approve_all_videos(){
	
	$admin = admin_validate();
	$ret_link = $GLOBALS["Get"]->val("ret_link");
	
	$sql_query="UPDATE videos
				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_videos

function delete_all_videos(){
	
	$admin = admin_validate();
	$ret_link = $GLOBALS["Get"]->val("ret_link");
	
	$sql_query = "SELECT vid_id FROM videos WHERE approved='0' AND vid_id > 100000";
	$result = $GLOBALS["DB"]->result($sql_query);
	
	include_once(DOC_ROOT."/functions/delete_functions.php");
	
	foreach($result as $res){
		delete_video($res["vid_id"]);
	}//foreach
	
	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);	
	load_page($ret_link);
	
}//delete_all_videos

?>