<?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_TicketProblemApp 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'];
$tpId 			= $_POST['tpId'];
$tpProblemType 	= $_POST['tpProblemType'];
$tpSLAH 		= $_POST['tpSLAH'];
$tpShowCount 	= $_POST['tpShowCount'];
$tpNoSLAhrs 	= $_POST['tpNoSLAhrs'];

$message = '';

if ($tpShowCount == '') $tpShowCount = 0;
if ($tpNoSLAhrs == '') $tpNoSLAhrs = 0;

if ($mainmode == 'insert' && $tpId == ''){
	$queryins 	= "insert into ticket_problem (ticketProblem_type, ticketProblem_SLAHours, ticketProblem_showCounter, ticketProblem_NoSLAHours) 
					values 
				   (".GetSQLValueString($tpProblemType,'text').", ".GetSQLValueString($tpSLAH,'double').", $tpShowCount, $tpNoSLAhrs)";
	$resins 	= mysql_query($queryins, $connection);
	$message = mysql_error();
	$tpId	= '';
}
else if ($mainmode == 'edit' && $tpId != ''){
	$queryup 	= "update ticket_problem set ticketProblem_type = ".GetSQLValueString($tpProblemType,'text').", ticketProblem_SLAHours = ".GetSQLValueString($tpSLAH,'text').", 
					ticketProblem_showCounter = $tpShowCount, ticketProblem_NoSLAHours = $tpNoSLAhrs
					where ticketProblem_id = $tpId ";
	$resup 		= mysql_query($queryup, $connection);
	$message 	= mysql_error();	
	$mainmode 	= '';
	$tpId	= '';
}
else if ($mainmode == 'delete' && $tpId != ''){
	$querydel 	= "delete from ticket_problem where ticketProblem_id = $tpId ";
	$resdel		= mysql_query($querydel, $connection);
	$message 	= mysql_error();
	$mainmode 	= '';
	$tpId	= '';
}
 
echo "<form name='ticketprobAction' method='POST' action='Form_TicketProblem.php'>
	<input type='hidden' name='mainmode' value='$mainmode'>
	<input type=hidden name='message' value='$message'>
	<input type=hidden name='tpId' value='$tpId'>
	</form>";
echo "<script> 
		document.ticketprobAction.submit();
	 </script>";
		
?>