<?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['top_man'] == 1){ }else{
	show("no_permission.php");
	down();
	die();
}
if(empty($_GET['step'])){
	redirect('admin.php',0);
	die();
}





if($_GET['step'] == 'add'){
	$what						= 'add';
	show('language_add.php');
}


if($_GET['step'] == 'insert'){
	$what	= 'add';
	
	$posted['language'] 	= $_POST['language'];
	$posted['file'] 		= $_POST['file'];
	$posted['style_dir'] 	= $_POST['style_dir'];
	
	

	if(empty($posted['language']) OR empty($posted['file']) OR empty($posted['style_dir'])){
	$rows	= $posted;
	show('language_add.php');
	down(); die();
	}
	
	$insert	= mysql_query("INSERT INTO `languages` (`language`,`file`,`style_dir`) VALUES ('".$posted['language']."','".$posted['file']."','".$posted['style_dir']."')");
	
	if($insert){
		ok('languages.php?step=control',2);
	}else{
		echo mysql_error();
	}
}


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





if($_GET['step'] == 'update'){
	$id	= $_GET['id'];
	$what	= 'edit';
	
	if(! id_check($id,'languages')){
		echo '<div class="error">'.$language['lang1'].'</div>';
		down();
		die();
	}
	
	$posted['language'] 	= $_POST['language'];
	$posted['file'] 		= $_POST['file'];
	$posted['style_dir'] 	= $_POST['style_dir'];
	
	

	if(empty($posted['language']) OR empty($posted['file']) OR empty($posted['style_dir'])){
	$rows	= $posted;
	show('language_add.php');
	down(); die();
	}
	
	$update	= mysql_query("UPDATE `languages` SET `language`='".$posted['language']."',
	`file`='".$posted['file']."',`style_dir`='".$posted['style_dir']."'
	WHERE `id`='".$id."'");

	if($update){
		ok('languages.php?step=control',2);
	}else{
		echo mysql_error();
	}
}






if($_GET['step'] == 'control'){
	$query	= mysql_query("SELECT * FROM `languages` ORDER BY `id` DESC");
	show('language_control.php');
}


if($_GET['step'] == 'delete'){
	$id	= $_GET['id'];
	
	if(! id_check($id,'languages')){
		echo '<div class="error">'.$language['lang1'].'</div>';
		down();
		die();
	}

	$delete	= mysql_query("DELETE FROM `languages` WHERE `id`='".$id."'");
	
	if($delete){
		ok('languages.php?step=control',2);
	}else{
		echo mysql_error();
	}
}
down();
?>