<?php
/* MyTickets [   by = www.phpx3.com   ]
* Faha1ad2@hotmail.com
* Writed By : Fahad S. Al-ghudaier
* All Right Reseved (C) 2010
*/
session_start();
include("Admin_Function.php");
head('rtl','','');
includes();
check_session();

$language			= array();
$language['lang1']	= 'المعذرة ... يوجد خطأ بالمعطيات !!!';


if($permission['allow_control'] == 1 OR $permission['top_man'] == 1){ }else{
	show("no_permission.php");
	down();
	die();
}
if(empty($_GET['step'])){
	redirect('admin.php',0);
	die();
}




if($_GET['step'] == 'edit'){
	$id	= $_GET['id'];
	if(! id_check($id,'reply')){
		echo '<div class="error">'.$language['lang1'].'</div>';
		down();
		die();
	}
	
	$query		= mysql_query("SELECT * FROM `reply` WHERE `id`='".$id."'");
	$rows		= mysql_fetch_array($query);
	$ticket		= mysql_fetch_array(mysql_query("SELECT `id`,`subject` FROM `tickets` WHERE `id`='".$rows['ticket_id']."'"));
	
	show('reply_edit.php');
}


if($_GET['step'] == 'update'){

	$id	= $_GET['id'];
	if(! id_check($id,'reply')){
		echo '<div class="error">'.$language['lang1'].'</div>';
		down();
		die();
	}
	
	$subject	= $_POST['subject'];
	$text		= text_handler($_POST['text']);
	if($_POST['change_name'] == 1){
	$name		= $_POST['name'];
	$email		= $_POST['email'];
	$MORE		= ",`name`='".$name."',`email`='".$email."'";
	}

	$to = $_GET['to'];
	if(!isset($to)){
		$to = 'tickets.php?step=control';
	}else{
		$to	= replace_to($to);
	}
	
	$update	= mysql_query("UPDATE `reply` SET `subject`='".$subject."',
	`text`='".$text."'".$MORE."
	WHERE `id`='".$id."'");
	
	if($update){
		ok($to,2);
	}else{
		echo mysql_error();
	}
}


if($_GET['step'] == 'delete'){
	$id	= $_GET['id'];
	if(! id_check($id,'reply')){
		echo '<div class="error">'.$language['lang1'].'</div>';
		down();
		die();
	}
	$to = $_GET['to'];
	if(!isset($to)){
		$to = 'tickets.php?step=control';
	}else{
		$to	= replace_to($to);
	}
	
	$delete	= mysql_query("DELETE FROM `reply` WHERE `id`='".$id."'");
	if($delete){
		ok($to,2);
	}else{
		echo mysql_error();
	}
}



down();
?>