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

// ########################## INCLUDE BACK-END ###########################
include_once (dirname(dirname(__FILE__)).'/config.php');
include_once (dirname(dirname(__FILE__)).'/cache/data_admin_options.php');
include_once (dirname(__FILE__).'/functions_receive.php');
include_once (dirname(__FILE__).'/functions_php.php');
include_once (dirname(dirname(__FILE__)).'/language/'.$language.'/'.$language.'.php');


// ############################ INITILIZATION ############################
$settings 		= '';
$popout			= '99';
$hide_bar		= '0';
$play_sound		= '1';
$window_open	= '0';
$only_names		= '0';
$unfocus_chat	= '0';
$focus_chat		= '0';

// ############################ GET USER DATA ############################
$userid = getUserID();

// Get the user's settings
if ($userid != 0) {

	$sql = "SELECT theme, status, popout, hash_id, hide_bar, play_sound, window_open, only_names, unfocus_chat, focus_chat 
		FROM arrowchat_status 
		WHERE userid = '".mysql_real_escape_string($userid)."'";
	$result = mysql_query($sql);
	if ($result && mysql_num_rows($result) > 0) {
		$user_settings 	= mysql_fetch_array($result);
		if (isset($user_settings['theme']))
			$theme 	= $user_settings['theme'];
		if (isset($user_settings['popout']))
			$popout = $user_settings['popout'];
		if (isset($user_settings['hide_bar']))
			$hide_bar = $user_settings['hide_bar'];
		if (isset($user_settings['play_sound']))
			$play_sound = $user_settings['play_sound'];
		if (isset($user_settings['window_open']))
			$window_open = $user_settings['window_open'];
		if (isset($user_settings['only_names']))
			$only_names = $user_settings['only_names'];
		if (!empty($user_settings['unfocus_chat'])) {
			$unfocus_chat = $user_settings['unfocus_chat'];
			$unfocus_chat = explode(":", $unfocus_chat);
		}
		if (!empty($user_settings['hash_id'])) {
			$hash_id = $user_settings['hash_id'];
		} else {
			$hash_id = genRandomString();
			$sql = "UPDATE arrowchat_status SET hash_id='".$hash_id."' WHERE userid = '".mysql_real_escape_string($userid)."'";
			mysql_query($sql);
		}
		if (!empty($user_settings['focus_chat']))
			$focus_chat = $user_settings['focus_chat'];
		if (!empty($user_settings['status']))
			$status = $user_settings['status'];
	} else {
		$hash_id = genRandomString();
		$sql = "INSERT INTO arrowchat_status (userid, hash_id, session_time) 
			VALUES ('".mysql_real_escape_string($userid)."', '".$hash_id."', '".time()."')";
		mysql_query($sql);
	}
	
}

/**
 * Gets a random hash combination if the user does not have a hash 
 *
 * @return a random letter and number combination
 */
function genRandomString() {
    $length = 20;
    $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    $string ='';    
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}

define('BASE_URL',$base_url);

?>