<?php
ob_start();
/* All Right Reserved (C) 2010;
  MyTickets;
  Writed By Fahad S. Al-ghudaier;
  faha1ad2@hotmail.com;
  www.phpx3.com;
*/
	include('start.php');
	
	

	
	$page['title']			= $language['lang_10'];
	$page['allow_metas']	= 2;
	$page['show_header']	= 1;
	include('content_head.php');

	$dos	= array('in','login','out');
	$do		= $_GET['do'];
	if(! in_array($do,$dos)){
		$do	= 'login';
	}
	
	switch($do){
	case 'login':
		$smarty->display('login.htm');
	break;
	case 'in':
		
	$posted['username']	= input_handler($_POST['username']);
	$posted['password']	= input_handler($_POST['password']);
	

	if(empty($posted['username']) OR empty($posted['password'])){
		$error['error']	= 1;
		$error['msg']	= $language['lang_11'];
		$smarty->assign('error',$error);
		$smarty->display('login.htm');
		include('content_foot.php');
		die();
	}
	
	$check	= mysql_query("SELECT `id`,`username`,`password`,`language` FROM `members` WHERE `username`='".$posted['username']."' AND `password`='".md5($posted['password'])."'");
	if(@mysql_num_rows($check) == 0){
		$error['error']	= 1;
		$error['msg']	= $language['lang_12'];
		$smarty->assign('error',$error);
		$smarty->display('login.htm');
		include('content_foot.php');
		die();
	}
	
	$user	= mysql_fetch_array($check);
	
	$Set1 = setcookie('MyTickets_username',$user['username'],time()+86400,"/");
	$Set2 = setcookie('MyTickets_password',$user['password'],time()+86400,"/");
	$Set3 = setcookie('MyTickets_id',$user['id'],time()+86400,"/");
	$Set4 = setcookie('MyTickets_language',$user['language'],time()+86400,"/");
	
	$smarty->assign('msg',$language['lang_13']);
	$smarty->display('ok_msg.htm');
	redirect('tickets.php?do=control');

	break;
	case 'out':
		$Set1 = setcookie('MyTickets_username','',time()+86400,"/");
		$Set2 = setcookie('MyTickets_password','',time()+86400,"/");
		$Set3 = setcookie('MyTickets_id','',time()+86400,"/");
		$Set4 = setcookie('MyTickets_language','',time()+86400,"/");
		
	$smarty->assign('msg',$language['lang_14']);
	$smarty->display('ok_msg.htm');
	redirect('index.php');
	break;
	}
	
	include('content_foot.php');
?>