<?php
/*
 * Copyright (c) 2004-2009 Luiz Otavio O Souza <loos.br@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* 
 * $Id: save_contact_op.php 102 2009-02-05 18:37:40Z loos-br $
 */

    require('default.array.option.inc.php');
    require('default.array.cmd.inc.php');
    require('class.ctl.php');
    require('mysql.inc.php');

    // Date in the past
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    // always modified
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

    // HTTP/1.1
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);

    // HTTP/1.0
    header("Pragma: no-cache");

    header("Content-Type: text/html; charset=iso-8859-1");

    $sql = "UPDATE contacts ";
    switch ($_REQUEST['name']) {
	case "deny";
	    $sql .= "SET contact_deny = ";
	    if ($_REQUEST['value'] == "yes")
		$sql .= "contact_deny & ~". $arrayCMD["CONTACT_DENY"];
	    else
		$sql .= "contact_deny | ". $arrayCMD["CONTACT_DENY"];
	    break;
    }

    $sql .= " WHERE contact_email = '". $_REQUEST['contact'] ."' AND ";
    $sql .= "email = '". $_REQUEST['user'] ."'";

    if (!mysql_query($sql, $mysql))
	echo "fail";

    $ctl = new ctl;    
    $ctl->connect(1);

    $xml  = "<msn-proxy><command type=\"loaduser\">";
    $xml .= "<user>". $_REQUEST["user"] ."</user>";
    $xml .= "<contact>". $_REQUEST["contact"] ."</contact>";
    $xml .= "</command></msn-proxy>\0\0";

    $ctl->write($xml);
    $ctl->close();
    echo "ok";
?>
