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

	if($member['member'] == 1){
		header("Location: index.php");
		die();
	}
	
	$dos	= array('main','check');
	
	$do		= $_GET['do'];
	if(! in_array($do,$dos)){
		$do	= 'main';
	}
	
	if(empty($_GET['pagen']) OR ! is_numeric($_GET['pagen'])){ $pagen = 1; }else{ $pagen = $_GET['pagen']; }
	switch($do){
	case 'main': $page['title']	= $language['lang_41']; break;
	case 'check': 	$page['title']	= $language['lang_41']; break;
	}
	
	$page['allow_metas']	= 2;
	$page['show_header']	= 1;
	include('content_head.php');


	
	switch($do){
	case 'main':
		$smarty->display('forget.htm');
	break;
	
	/* ============ new do ========= */
	case 'check':
	$posted['email']		= $_POST['email'];
	
	
		if(empty($posted['email'])){
			$error['error']	= 1;
			$error['msg']	= $language['lang_38'];
			$smarty->assign('error',$error);
			$smarty->display('forget.htm');
			include('content_foot.php');
			die();
		}
		if(check($posted['email'],'email') == false){
			$error['error']	= 1;
			$error['msg']	= $language['lang_38'];
			$smarty->assign('error',$error);
			$smarty->display('forget.htm');
			include('content_foot.php');
			die();
		}

	
		$check	= mysql_query("SELECT `id`,`username`,`email` FROM `members` WHERE `email`='".$posted['email']."'");
		
		if(mysql_num_rows($check) == 0){
			$error['error']	= 1;
			$error['msg']	= $language['lang_38'];
			$smarty->assign('error',$error);
			$smarty->display('forget.htm');
			include('content_foot.php');
			die();
		}
		
		$pass	= rand(000,999);
		$update	= mysql_query("UPDATE `members` SET `new_password`='1' AND `password`='".md5($pass)."' WHERE `email`='".$posted['email']."'");
			
		
			
		mytickets_mail($options['site_name'],$AdminEmail,$posted['name'],$posted['email'],$language['email2s'],str_replace('[new_password]',$pass,$language['email2']));
		if(! isset($SENT)){ $SENT	= $GLOBALS['sent']; }
		
		if($SENT == 1){
			$smarty->assign('msg',$language['lang_39']);
			$smarty->display('ok_msg.htm');
		}else{
			$error['error']	= 1;
			$error['msg']	= $language['lang_40'];
			$smarty->assign('error',$error);
			$smarty->display('forget.htm');
			include('content_foot.php');
			die();
		}
		
	
	
	break;
	}
	
	
	include('content_foot.php');
?>