<?php

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

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

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

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

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

							switch($action){

								case 'profiles':
									manage_profiles();
									break;

								case 'approve_profile':
									approve_profile();
									break;

								case 'approve_all':
									approve_all_profiles();
									break;

								case 'delete_all':
									delete_all_profiles();
									break;

							}//switch

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

function manage_profiles(){

	admin_validate();

	$data["section"] = "manage";
	$data["subsection"] = 12;
	$data["title_id"] = "33";
	$p = $GLOBALS["Get"]->val("p");

	$sql_query_total = "SELECT COUNT(members.mem_id) ";
	$sql_query_result = "SELECT members.mem_id ";

	$sql_query="FROM members,profiles,network
				WHERE members.mem_id=profiles.mem_id
				AND members.mem_id=network.mem_id
				AND profiles.approved='0'
				AND members.verified='1'
				AND members.mem_id > 100000
				ORDER BY profiles.updated DESC";

	$start = $p*30;

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

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


	$data["cards"] = admin_build_cards($result,"index.php?section=manage_profiles&action=profiles&p=".$p);
	$data["cards_total"] = count($result);

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

	$data["link"] = "index.php?section=manage_profiles&action=profiles&p=".$p;

	$data["onload"] = "";

	$layout[0] = "profiles_list";

	admin_output($layout,$data);

}//manage_profiles

function approve_profile(){

	admin_validate();

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

	include_once(DOC_ROOT."/classes/Mail.class.php");

	if(is_array($mem_id)){
		$sql_query="UPDATE profiles
					SET approved='1'
					WHERE mem_id IN (".implode(",",$mem_id).")";

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

		if($GLOBALS["settings"]["limit_unapproved"]){
		$mail_details = array (
			"mes_id" => 44,
			"notifications" => 1
		);
		foreach($mem_id as $id){
			$GLOBALS["Mail"]->details = $mail_details;
			$GLOBALS["Mail"]->details["recipient"] = $id;
			$GLOBALS["Mail"]->send_mass();
		}//foreach
		}//if
	}//if
	elseif(!empty($mem_id)){
		$sql_query="UPDATE profiles
					SET approved='1'
					WHERE mem_id=".$mem_id;

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

		if($GLOBALS["settings"]["limit_unapproved"]){
		$mail_details = array (
			"mes_id" => 44,
			"notifications" => 1
		);
		$GLOBALS["Mail"]->details = $mail_details;
		$GLOBALS["Mail"]->details["recipient"] = $mem_id;
		$GLOBALS["Mail"]->send_mass();
		}//if
	}//elseif

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

}//approve_profile

function approve_all_profiles(){

	admin_validate();

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

	if($GLOBALS["settings"]["limit_unapproved"]){
	$mail_details = array (
		"mes_id" => 44,
		"notifications" => 1
	);

	include_once(DOC_ROOT."/classes/Mail.class.php");

	$sql_query = "SELECT m.mem_id FROM members AS m,profiles AS p WHERE m.mem_id=p.mem_id AND p.approved='0' AND m.verified='1'";
	$result = $GLOBALS["DB"]->execute($sql_query);
	while($res = mysql_fetch_assoc($result)){
		$GLOBALS["Mail"]->details = $mail_details;
		$GLOBALS["Mail"]->details["recipient"] = $res["mem_id"];
		$GLOBALS["Mail"]->send_mass();
	}//while
	}//if

	$sql_query="UPDATE members AS m,profiles AS p
				SET p.approved='1' WHERE m.mem_id=p.mem_id AND m.verified='1' AND p.approved='0'";

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

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

}//approve_all_profiles

function delete_all_profiles(){

	admin_validate();

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

	$sql_query = "SELECT m.mem_id FROM members AS m,profiles AS p WHERE m.mem_id=p.mem_id AND p.approved='0' AND m.member_type != 'a'";
	$result = $GLOBALS["DB"]->result($sql_query);

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

	foreach($result as $res){
		delete_member($res["mem_id"]);
	}//foreach

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

}//delete_all_profiles

?>