<?php
///////////////////////////////////////////////////////////////////////////////////////
// PHPizabi 0.848b C1 [ALICIA]                               http://www.phpizabi.net //
///////////////////////////////////////////////////////////////////////////////////////
// Please read the license.txt file before using / modifying this software           //
// Original author:         Claude Desjardins, R - feedback@realitymedias.com        //
// Last modification date:  August 13th 2006                                         //
// Version:                 PHPizabi 0.848b C1                                       //
//                                                                                   //
// (C) 2005, 2006 Real!ty Medias / PHPizabi - All rights reserved                    //
///////////////////////////////////////////////////////////////////////////////////////

	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");

	$tpl = new template;
	$tpl -> Load("remove");
	$tpl -> AssignUser($_GET["id"]);
	
	
	if (isset($_GET["id"])) {
		
		if (!isset($_POST["remove"]) and !isset($_POST["noremove"])) {
			$tpl -> Zone("remove", "question");
		}
		
		/*
			The user answered the question!
		*/
		elseif (isset($_POST["remove"])) {
			
			/*
				Load the contacts array
			*/
			if (!is_array($myContacts = unpk(me("contacts")))) $myContacts = array();
			
			foreach ($myContacts as $groupName => $groupArray) {
				if (is_array($groupArray)) foreach($groupArray as $userEntryKey => $userId) {
					if ($userId == $_GET["id"]) unset($myContacts[$groupName][$userEntryKey]);
				}
			}
			myQ("UPDATE `[x]users` SET `contacts`='".pk($myContacts)."' WHERE `id`='".me('id')."'");
			
			_fnc("reload", 3, "?L=contacts.contacts");
			$tpl -> Zone("remove", "removed");
		}
		
		else _fnc("reload", 0, "?L=contacts.contacts");
		
	} 
	
	/*
		No user ID specified
	*/
	else $tpl -> Zone("remove", "nouser");
	
	$tpl -> CleanZones();
	$tpl -> Flush();
	
?>