<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("function.inc.php");



$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}


$querylog="SELECT FS_TypeSetupApp as loginaccess, user_account, Language from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");

$mainmode 		= $_POST['mainmode'];
$message 		= $_POST['message'];
$csOldCode 		= $_POST['csOldCode'];
$csCode 		= $_POST['csCode'];
$csDescription 	= $_POST['csDescription'];
$csfromtime 	= $_POST['csfromtime'];
$cstotime 		= $_POST['cstotime'];

$message = '';

if ($mainmode == 'insert' && $csOldCode == ''){
	$queryins 	= "insert into Ticket_ColorSetup (color_code, setup_description, setup_fromTime, setup_toTime) 
					values (".GetSQLValueString($csCode,'text').", ".GetSQLValueString($csDescription,'text').", ".GetSQLValueString($csfromtime,'int').",".GetSQLValueString($cstotime,'int').")";
					//echo $queryins;exit;
	$resins 	= mysql_query($queryins, $connection);
	$message = mysql_error();
	$csOldCode	= '';
}
else if ($mainmode == 'edit' && $csOldCode != ''){
	$queryup 	= "update Ticket_ColorSetup set color_code = ".GetSQLValueString($csCode,'text').", setup_description = ".GetSQLValueString($csDescription,'text').",
						setup_fromTime = ".GetSQLValueString($csfromtime,'int').", setup_toTime = ".GetSQLValueString($cstotime,'int')."
					where color_code = ".GetSQLValueString($csOldCode,'text')." ";
	$resup 		= mysql_query($queryup, $connection);
	$message 	= mysql_error();	
	$mainmode 	= '';
	$csOldCode	= '';
}
else if ($mainmode == 'delete' && $csOldCode != ''){
	$querydel 	= "delete from Ticket_ColorSetup where color_code = ".GetSQLValueString($csOldCode,'text')." ";
	$resdel		= mysql_query($querydel, $connection);
	$message 	= mysql_error();
	$mainmode 	= '';
	$csOldCode	= '';
}

echo "<form name='csAction' method='POST' action='Form_TicketColorSetup.php'>
	<input type='hidden' name='mainmode' value='$mainmode'>
	<input type=hidden name='message' value='$message'>
	<input type=hidden name='csOldCode' value='$csOldCode'>
	</form>";
echo "<script> 
		document.csAction.submit();
	 </script>";
		
?>