<?php
/* All Right Reserved (C) 2010;
  MyTickets;
  Writed By Fahad S. Al-ghudaier;
  faha1ad2@hotmail.com;
  www.phpx3.com;
*/
	$cookies['username'] 	= $_COOKIE['MyTickets_username'];
	$cookies['password'] 	= $_COOKIE['MyTickets_password'];
	$cookies['id']		 	= $_COOKIE['MyTickets_id'];
	$cookies['language']	= $_COOKIE['MyTickets_language'];
	
	$member	= array();

	if(empty($cookies['username']) OR empty($cookies['password']) OR empty($cookies['id']) ){
		$member['member'] = 2;
	}else{
		$username 		= $cookies['username'];
		$password 		= $cookies['password'];
		$user_id 		= $cookies['id'];
		if(! is_numeric($user_id)){
			$member['member'] = 2; 
		}else{
			$Check = mysql_num_rows(mysql_query("SELECT `id` FROM `members` WHERE `username`='".mysql_real_escape_string($username)."' AND `password`='".mysql_real_escape_string($password)."' AND `id`='".intval($user_id)."' "));
			if($Check == 1){ 
				$member['member'] = 1;
			}else{
				$member['member'] = 2;
			}
		}
	}
	
	if($member['member'] == 1){
		
		$member_q			= mysql_query("SELECT * FROM `members` WHERE `id`='".$cookies['id']."'");
		$member				= mysql_fetch_array($member_q);
		$member['member']	= 1;
		$premission_q		= mysql_query("SELECT * FROM `groups` WHERE `id`='".$member['group_id']."'");
		$permission			= mysql_fetch_array($premission_q);
	}else{
		$premission_q		= mysql_query("SELECT * FROM `groups` WHERE `id`='".$options['main_group']."'");
		$permission			= mysql_fetch_array($premission_q);
	}
	
	if(empty($cookies['language'])){
		setcookie('language',$options['main_language'],time()+86400,"/");
		$language	= $options['main_language'];
	}else{
		if(mysql_num_rows(mysql_query("SELECT `id` FROM `languages` WHERE `id`='".$cookies['language']."'")) == 0){
			$language	= $options['main_language'];
		}
		$language	= $cookies['language'];
	}
	
	
	$language	= mysql_fetch_array(mysql_query("SELECT * FROM `languages` WHERE `id`='".$language."'"));
?>