<?php
/* Nulled by Wizzywig */
/***********تعريب***********/
/**          saher        **/
/**  منتديات شباب وصبايا  **/
/**   www.shababtop.com   **/
/**  saher1986@live.com   **/
/***************************/

// ########################## INCLUDE BACK-END ###########################
include ("../config.php");

// ########################### GET POST DATA #############################
$userid 		= $_POST['userid'];
$hide 			= $_POST['hide'];
$sound 			= $_POST['sound'];
$window 		= $_POST['window'];
$name 			= $_POST['name'];
$focus_chat 	= $_POST['focus_chat'];
$unfocus_chat 	= $_POST['unfocus_chat'];
$close_chat 	= $_POST['close_chat'];
$clear_user		= $_POST['clear_chat'];
$tab_alert		= $_POST['tab_alert'];

// ######################## START POST HIDE BAR ##########################
if (!empty($_POST['hide'])) {

	if ($hide == "-1")
		$hide = 0;
	
	$sql = ("INSERT INTO arrowchat_status (userid,hide_bar) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($hide)."') 
		ON DUPLICATE KEY 
			UPDATE hide_bar = '".mysql_real_escape_string($hide)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ####################### START POST POPOUT CHAT ########################
if (!empty($_POST['popoutchat'])) {
	if ($_POST['popoutchat'] == "99") {
		$time = 99;
	} else {
		$time = time();
	}
	
	$sql = ("INSERT INTO arrowchat_status (userid,popout) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($time)."') 
		ON DUPLICATE KEY 
			UPDATE popout = '".mysql_real_escape_string($time)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ######################### START POST SOUND ############################
if (!empty($_POST['sound'])) {
	if ($sound == "-1")
		$sound = 0;
	
	$sql = ("INSERT INTO arrowchat_status (userid, play_sound) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($sound)."') 
		ON DUPLICATE KEY 
			UPDATE play_sound = '".mysql_real_escape_string($sound)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ##################### START POST KEEP WINDOW OPEN #####################
if (!empty($_POST['window'])) {
	if ($window == "-1")
		$window = 0;
	
	$sql = ("INSERT INTO arrowchat_status (userid, window_open) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($window)."') 
		ON DUPLICATE KEY 
			UPDATE window_open = '".mysql_real_escape_string($window)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ##################### START POST SHOW ONLY NAMES ######################

if (!empty($_POST['name'])) {
	if ($name == "-1")
		$name = 0;
	
	$sql = ("INSERT INTO arrowchat_status (userid, only_names) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($name)."') 
		ON DUPLICATE KEY 
			UPDATE only_names = '".mysql_real_escape_string($name)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ######################## START POST FOCUS CHAT ########################
if (!empty($_POST['focus_chat'])) {

	if ($tab_alert == "1") {
		$sql = "UPDATE arrowchat 
			SET arrowchat.user_read='1' 
			WHERE arrowchat.from='".mysql_real_escape_string($focus_chat)."' 
				AND arrowchat.to='".mysql_real_escape_string($userid)."' 
				AND arrowchat.user_read='0'";
		mysql_query($sql);
	}
	
	$sql =("SELECT unfocus_chat, focus_chat 
		FROM arrowchat_status 
		WHERE userid='".mysql_real_escape_string($userid)."'");
	$result = mysql_query($sql);
	
	if ($result && mysql_num_rows($result)) {
		$row = mysql_fetch_assoc($result);
		$unfocus_chat = $row['unfocus_chat'];
		$unfocus_chat = str_replace($focus_chat.":", "", $unfocus_chat);
		if (!empty($row['focus_chat']) && $row['focus_chat'] != $focus_chat) {
			$unfocus_chat .= $row['focus_chat'].":";
		}
	}
	
	$sql = ("INSERT INTO arrowchat_status (userid, unfocus_chat, focus_chat) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($unfocus_chat)."', '".mysql_real_escape_string($focus_chat)."') 
		ON DUPLICATE KEY 
			UPDATE focus_chat = '".mysql_real_escape_string($focus_chat)."', unfocus_chat = '".mysql_real_escape_string($unfocus_chat)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ###################### START POST UNFOCUS CHAT ########################
if (!empty($_POST['unfocus_chat'])) {

	if ($tab_alert == "1") {
		$sql = "UPDATE arrowchat 
			SET arrowchat.user_read='1' 
			WHERE arrowchat.from='".mysql_real_escape_string($unfocus_chat)."' 
				AND arrowchat.to='".mysql_real_escape_string($userid)."' 
				AND arrowchat.user_read='0'";
		mysql_query($sql);
	}
	
	$sql =("SELECT unfocus_chat 
		FROM arrowchat_status 
		WHERE userid='".mysql_real_escape_string($userid)."'");
	$result = mysql_query($sql);
	
	if ($result && mysql_num_rows($result)) {
		$row = mysql_fetch_assoc($result);
		$unfocus_chat = $row['unfocus_chat'];
		$unfocus_chat .= $_POST['unfocus_chat'].":";
		$focus_chat = "";
	}
	
	$sql = ("INSERT INTO arrowchat_status (userid, unfocus_chat, focus_chat) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($unfocus_chat)."', '".mysql_real_escape_string($focus_chat)."') 
		ON DUPLICATE KEY 
			UPDATE focus_chat = '".mysql_real_escape_string($focus_chat)."', unfocus_chat = '".mysql_real_escape_string($unfocus_chat)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ######################## START POST CLOSE CHAT ########################
if (!empty($_POST['close_chat'])) {

	if ($tab_alert == "1") {
		$sql = "UPDATE arrowchat 
			SET arrowchat.user_read='1' 
			WHERE arrowchat.from='".mysql_real_escape_string($close_chat)."' 
				AND arrowchat.to='".mysql_real_escape_string($userid)."' 
				AND arrowchat.user_read='0'";
		mysql_query($sql);
	}
	
	$sql =("SELECT unfocus_chat, focus_chat 
		FROM arrowchat_status 
		WHERE userid='".mysql_real_escape_string($userid)."'");
	$result = mysql_query($sql);
	
	if ($result && mysql_num_rows($result)) {
		$row = mysql_fetch_assoc($result);
		$unfocus_chat = $row['unfocus_chat'];
		$focus_chat = $row['focus_chat'];
		$focus_chat = str_replace($close_chat, "", $focus_chat);
		$unfocus_chat = str_replace($close_chat.":", "", $unfocus_chat);
	}
	
	$sql = ("INSERT INTO arrowchat_status (userid, unfocus_chat, focus_chat) 
		VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($unfocus_chat)."', '".mysql_real_escape_string($focus_chat)."') 
		ON DUPLICATE KEY 
			UPDATE focus_chat = '".mysql_real_escape_string($focus_chat)."', unfocus_chat = '".mysql_real_escape_string($unfocus_chat)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

// ######################## START POST CLEAR CHAT ########################
if (!empty($_POST['clear_chat'])) {
	
	$sql =("SELECT last_message 
		FROM arrowchat_status 
		WHERE userid='".mysql_real_escape_string($userid)."'");
	$result = mysql_query($sql);
	
	if ($result && mysql_num_rows($result)) {
		$row = mysql_fetch_assoc($result);
		$last_message = $row['last_message'];
		$new_time = time() + 3600;
		if (empty($last_message)) {
			$last_message = ":".$clear_user."/".$new_time;
		} else {
			$old_data = $last_message;
			if (preg_match("#:$clear_user/[0-9]+#", $old_data, $matches)) {
				$last_message = str_replace($matches[0], ":".$clear_user."/".$new_time."", $old_data);
			} else {
				$last_message .= ":".$clear_user."/".$new_time;
			}
		}
	}
	
	$sql = ("INSERT INTO arrowchat_status (userid, last_message) 
		VALUES ('".mysql_real_escape_string($userid)."', '".mysql_real_escape_string($last_message)."') 
		ON DUPLICATE KEY 
			UPDATE last_message = '".mysql_real_escape_string($last_message)."'");
	mysql_query($sql);

	echo "1";
	exit(0);
}

?>