<?php

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

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

						admin_validate_section("manage",19);
						$action = $GLOBALS["Get"]->val("action");
								
							switch($action){								
										
								case '':									
									manage_recordings();
									break;
									
								case 'approve':
									approve_recordings();
									break;
								
								case 'approve_all':
									approve_all_recordings();
									break;

								case 'delete':
									delete_recordings();
									break;
																			
								case 'delete_all':
									delete_all_recordings();
									break;
									
								case 'view':
									view_recording();
									break;
																		
							}//switch
							
						///////////////////////////////////////
						
function manage_recordings(){
	
	$admin = admin_validate();
	$p = $GLOBALS["Get"]->val("p");
	
	$data["section"] = "manage";
	$data["subsection"] = 19;
	$data["title_id"] = 62;	
	$start = $p*30;
	
	$ret_link = "index.php?section=manage_recordings&p=".$p;	
	$data["link"] = stripslashes(html_entity_decode($ret_link));
	
	$sql_query_total = "SELECT COUNT(*) ";
	$sql_query_result = "SELECT * ";
	
	$sql_query="FROM streams
				WHERE approved='0' and posted not like 'mailbox_message|%'	
				ORDER BY mem_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_recordings",30);	
	
	$data["recordings"] = array();
	foreach($results as $result){
		
		$recording = array();
		$stream = explode("|",$result["posted"]);
		$msg_type = $stream[0];
		$type_id = $stream[1];
		
		$recording["msg_type"]	      = ucwords(str_replace("_"," ",$msg_type));
		$recording["type"] 	      = ucwords($result["type"]);
		$recording["mem_id"]	      = $result["mem_id"];
		$recording["view"]	      = "javascript:HS_Popup('index.php?section=manage_recordings&action=view&mem_id=".$result["mem_id"]."&hash=".$result["hash"]."','width=335,height=275,scrollbars=no,menubar=no,resizable=no,location=no');";
		$recording["hash"]	      = $result["hash"];
		$recording["author"]          = $GLOBALS["Network"]->card($result["mem_id"]);
		$recording["delete"]          = "index.php?section=manage_recordings&action=delete&hash=".$result["hash"]."&ret_link=".urlencode($data["link"]);
		$recording["approve"]         = "index.php?section=manage_recordings&action=approve&hash=".$result["hash"]."&ret_link=".urlencode($data["link"]);
		
		$data["recordings"][] = $recording;
		
	}//foreach
	
	$layout[0] = "unapproved_recordings_list";
	admin_output($layout,$data);
	
}//manage_recordings

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

function delete_recordings(){
	
	$admin = admin_validate();
	$hash = $GLOBALS["Get"]->val("hash");
	$ret_link = $GLOBALS["Get"]->val("ret_link");
	
	include_once(DOC_ROOT."/functions/delete_functions.php");
	
	if(is_array($hash) && count($hash)){
		foreach($hash as $hash_id){
			$sql_query = "SELECT posted FROM streams WHERE hash ='".$hash_id."'";
			$posted = $GLOBALS["DB"]->single($sql_query);
			$arr = explode("|",$posted);
			switch ($arr[0]){
				case 'testimonial':
					//REMOVE TESTIMONIAL (CHECK BOTH TABLES)
					$sql_query = "DELETE FROM testimonials WHERE hash = '".$hash_id."'";
					$GLOBALS["DB"]->execute($sql_query);
					$sql_query = "DELETE FROM internal_mail WHERE message = '".$hash_id."'";
					$GLOBALS["DB"]->execute($sql_query);
					break;
				case 'blog_comment':
					//REMOVE BLOG COMMENT
					$sql_query = "DELETE FROM blogs_comments WHERE hash = '".$hash_id."'";
					$GLOBALS["DB"]->execute($sql_query);
					break;
				case 'blog_post':
					//REMOVE BLOG POST
					$sql_query = "DELETE FROM blogs_posts WHERE hash = '".$hash_id."'";
					$GLOBALS["DB"]->execute($sql_query);
					break;
				case 'video_comment':
					//REMOVE VIDEO COMMENT
					$sql_query = "DELETE FROM video_comments WHERE hash = '".$hash_id."'";
					$GLOBALS["DB"]->execute($sql_query);
					break;
				case 'music_comment':
					//REMOVE MUSIC COMMENT
					$sql_query = "DELETE FROM music_comments WHERE hash = '".$hash_id."'";
					$GLOBALS["DB"]->execute($sql_query);
					break;
			}//switch
			delete_stream($hash_id);
		}//foreach
	}//if
	elseif(!empty($hash)){
		$sql_query = "SELECT posted FROM streams WHERE hash ='".$hash."'";
		$posted = $GLOBALS["DB"]->single($sql_query);
		$arr = explode("|",$posted);
		switch ($arr[0]){
			case 'testimonial':
				//REMOVE TESTIMONIAL (CHECK BOTH TABLES)
				$sql_query = "DELETE FROM testimonials WHERE hash = '".$hash."'";
				$GLOBALS["DB"]->execute($sql_query);
				$sql_query = "DELETE FROM internal_mail WHERE message = '".$hash."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'blog_comment':
				//REMOVE BLOG COMMENT
				$sql_query = "DELETE FROM blogs_comments WHERE hash = '".$hash."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'blog_post':
				//REMOVE BLOG POST
				$sql_query = "DELETE FROM blogs_posts WHERE hash = '".$hash."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'video_comment':
				//REMOVE VIDEO COMMENT
				$sql_query = "DELETE FROM video_comments WHERE hash = '".$hash."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'music_comment':
				//REMOVE MUSIC COMMENT
				$sql_query = "DELETE FROM music_comments WHERE hash = '".$hash."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
		}//switch
		delete_stream($hash);
	}//if
	
	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);	
	load_page($ret_link);
	
}//delete_recordings

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

function delete_all_recordings(){
	
	$admin = admin_validate();
	$ret_link = $GLOBALS["Get"]->val("ret_link");
	
	$sql_query = "SELECT hash FROM streams WHERE approved='0'";
	$result = $GLOBALS["DB"]->result($sql_query);
	
	include_once(DOC_ROOT."/functions/delete_functions.php");
	
	foreach($result as $res){
		$sql_query = "SELECT posted FROM streams WHERE hash ='".$res["hash"]."'";
		$posted = $GLOBALS["DB"]->single($sql_query);
		$arr = explode("|",$posted);
		switch ($arr[0]){
			case 'testimonial':
				//REMOVE TESTIMONIAL (CHECK BOTH TABLES)
				$sql_query = "DELETE FROM testimonials WHERE hash = '".$res["hash"]."'";
				$GLOBALS["DB"]->execute($sql_query);
				$sql_query = "DELETE FROM internal_mail WHERE message = '".$res["hash"]."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'blog_comment':
				//REMOVE BLOG COMMENT
				$sql_query = "DELETE FROM blogs_comments WHERE hash = '".$res["hash"]."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'blog_post':
				//REMOVE BLOG POST
				$sql_query = "DELETE FROM blogs_posts WHERE hash = '".$res["hash"]."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'video_comment':
				//REMOVE VIDEO COMMENT
				$sql_query = "DELETE FROM video_comments WHERE hash = '".$res["hash"]."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
			case 'music_comment':
				//REMOVE MUSIC COMMENT
				$sql_query = "DELETE FROM music_comments WHERE hash = '".$res["hash"]."'";
				$GLOBALS["DB"]->execute($sql_query);
				break;
		}//switch
		delete_stream($res["hash"]);
	}//foreach
	
	$ret_link = html_entity_decode($ret_link);
	$ret_link = stripslashes($ret_link);	
	load_page($ret_link);
	
}//delete_all_recordings

function view_recording(){
	
	admin_validate();
	
	$hash = $GLOBALS["Get"]->val("hash");
	$mem_id = $GLOBALS["Get"]->type_val("mem_id","integer");
	
	$data["title_id"] = "manage_recording";	
	$data["javascript"] = <<<HTMLTEXT
<script language="JavaScript">
	function HS_ResizeWindow(){
		var DocWidth = document.body.scrollWidth;
		var DocHeight = document.body.scrollHeight;
		window.resizeTo(DocWidth + 20, DocHeight + 60);
	}//HS_ResizeWindow
</script>
HTMLTEXT;
	$data["display"] = '<script type="text/javascript">
				AC_FL_RunContent( "codebase","http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0",
						"width","330",
						"height","271",
						"src","/swf/player",
						"quality","high",
						"allowScriptAccess","always",
						"bgcolor","#ffffff",
						"FlashVars","mem_id='.$mem_id.'&MainURL='.extract_mainurl().'&hash='.$hash.'",
						"pluginspage","http://www.macromedia.com/go/getflashplayer",
						"movie","/swf/player" );
				</script>';
	$data["onload"] = "HS_ResizeWindow()";
	
	$layout[0] = "recording_view";
	
	admin_popup_output($layout,$data);
	
}//view_ecard
?>