<?php

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


include("config.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");

$query_navigator = "SELECT LANGUAGE,
       ClearPage,
       Excel,
       Save,
       Print,
       Addd,
       SEARCH,
       Pending,
       CopyJV,
       PaymentRequests,
       ExportExcel
FROM ".$_SESSION['dbLabel'].".mainform_label
WHERE LANGUAGE = '".$Language."'";
$result_navigator = mysql_query($query_navigator, $connection);
$row_navigator    = mysql_fetch_array($result_navigator);
extract($row_navigator);

	
//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	

if($mainmode=='') $mainmode='insert';
if ($tpShowCount=='') $tpShowCount = 0;
if ($tpNoSLAhrs=='') $tpNoSLAhrs = 0;
if ($startrange=='') $startrange = 0;
if ($perpage == '' ) $perpage = $config['trowlimit'][0];
print <<<HERE

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

<script type="text/javascript" language="javascript">

function SubmitRecord(){
	var x = document.ticketprob;
	x.action = 'Form_TicketProblem_Action.php';
	x.submit();
}

function editRecord(probid){
	var x = document.ticketprob;
	x.tpId.value = probid;
	x.mainmode.value = 'edit';
	x.submit();
}

function deleteRecord(probid){
	var x = document.ticketprob;
	x.tpId.value = probid;
	x.mainmode.value = 'delete';
	x.action = 'Form_TicketProblem_Action.php';
	x.submit();
}

function ClearPage(){
	var x = document.ticketprob;
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		x.mainmode.value 		= '';		
		x.message.value 		= '';		
		x.tpId.value 			= '';		
		x.tpProblemType.value 	= '';		
		x.tpSLAH.value 			= '';		
		x.tpShowCount.value 	= '';		
		x.action='Form_TicketProblem.php';
		x.submit();
	}	
}

function SetNextPage(startrange,perpage){
	document.ticketprob.action='Form_TicketProblem.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.ticketprob.submit();
}

function SetPrvPage(startrange,perpage){
	document.ticketprob.action='Form_TicketProblem.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.ticketprob.submit();
}

function SearchForCur(){
	x = document.ticketprob;
	document.ticketprob.action='Form_TicketProblem.php?startrange=0';
	document.ticketprob.submit();
}

function ClearKeyword(){
	x = document.ticketprob;
	x.txtKeyword.value='';
	document.ticketprob.submit();
}

function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   	document.ticketprob.action='Form_TicketProblem.php?startrange=0';
	document.ticketprob.submit();
  
   return false;
   }
else
   return true;
}

function set_limit(){

	perpage=document.ticketprob.perpage.value;
	document.ticketprob.action='Form_TicketProblem.php?perpage='+perpage+'&startrange=0';
	document.ticketprob.submit();
}

function setCheked(vField, vDisabledField){
	if (document.getElementById(vField).checked){
		document.getElementById(vField).value = 1;
		if (vDisabledField != '')
			document.getElementById(vDisabledField).disabled = true;
	}
	else {
		document.getElementById(vField).value = 0;
		if (vDisabledField != '')
			document.getElementById(vDisabledField).disabled = false;
	}
	
}
</script>

<title>Ticket Problem</title>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style1 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
</head>
<body >
<form name='ticketprob' method='post' >
<input type='hidden' name='mainmode' value='$mainmode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='tpId' value='$tpId'>

HERE;

if ($mainmode == 'edit' && $tpId != ''){
	$queryEdit = "select ticketProblem_type, ticketProblem_SLAHours, ifnull(ticketProblem_showCounter,0), ifnull(ticketProblem_NoSLAHours,0) from ticket_problem where ticketProblem_id = $tpId ";
	$resEdit = mysql_query($queryEdit, $connection);
	$rowEdit = mysql_fetch_row($resEdit);
	$tpProblemType 	= $rowEdit[0];
	$tpSLAH 		= $rowEdit[1];
	$tpShowCount 	= $rowEdit[2];
	$tpNoSLAhrs 	= $rowEdit[3];
}

echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title' style='text-transform: uppercase'>Ticket Problem</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";


echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px'>";
echo"		<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>$ClearPage</span></span></button>";


echo"		<button type='button' id='btnPost' name='btnPost' onclick=\"SubmitRecord();return false;\" title='Save Changes' $Insmode><span><span>$Save</span></span></button>";
	
echo"   </td><td align='left' width='240px'>
			<input type='text' name='txtKeyword' value='$txtKeyword' style='width:105px;' onKeyPress='return submitenter(this,event)'>
			<button type='button' id='btnSearch' name='btnSearch' onclick='SearchForCur(); return false;' title='Search'><span><span>Find</span></span></button>
			<button type='button' id='btnClear' name='btnClear' onclick='ClearKeyword(); return false;' title='Clear Keyword'><span><span>Clear</span></span></button>
		</td><td align='left'>
	 <span class='style1'><b>".$ResultsPage1."</b></span>
	 <span class='style1'><select name='perpage' id='perpage'  onchange=set_limit();>";
	 
			
	foreach ($config['trowlimit'] as $value) {
		echo "<option value='$value' ".($value==$perpage?'selected':'')."  >$value</option>";
	}
		
	 
	 echo"</td></tr>";
echo"	</table>";
echo"</td></tr>";

echo"<tr><td id='content-body'>";		
echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=65%>";
		
	echo"   <tr bgcolor='#F7F7F7'><td valign='top'  align='left'>";	  
echo"<table border='0' style='table-layout:fixed' align='left' valign='top' width='700px'>
      <col width=130><col width=250><col width=130>";
	  
echo"<tr bgcolor='#F7F7F7' height='25'>
     <td valign='center' align='left' ><span class='style1'>Problem Type <span class='style26'>*</span></span>";
	echo"</td>";
	echo"<td ><input type='text' name='tpProblemType' id='tpProblemType' value='".htmlspecialchars($tpProblemType, ENT_QUOTES)."' style='font-size:12px; width:250px; height:18px;' maxlength='50' /> ";
	
echo" </td><td><span class='style1'>Show Counter Number <input type='checkbox' name='tpShowCount' id='tpShowCount' value='$tpShowCount' onclick=\"setCheked('tpShowCount','');\" ".($tpShowCount=='1'?'checked':'')."></span></td></tr>";

if ($tpNoSLAhrs == 1) $dis = "disabled";
echo"<tr bgcolor='#F7F7F7'  height='25'><td valign='center' align='left' ><span class='style1'>SLA Hours </span></td>";
echo"	  <td valign='center' align='left' ><input type='text' name='tpSLAH' id='tpSLAH' value='".htmlspecialchars($tpSLAH, ENT_QUOTES)."' $dis style='font-size:12px; width:200px; height:18px;' maxlength='100' />  </td>
	<td><span class='style1'>No SLA Hours <input type='checkbox' name='tpNoSLAhrs' id='tpNoSLAhrs' value='$tpNoSLAhrs' onclick=\"setCheked('tpNoSLAhrs','tpSLAH');\" ".($tpNoSLAhrs=='1'?'checked':'')."></span></td>
	</tr> ";
	
echo"<tr height='20'><td>&nbsp;</td></tr>";


	
echo"</table></td></tr><tr><td  valign='top'>";

echo"<table width=1050px border='0' cellspacing=0><col width=1050>";				
echo"<tr><td  style='width:1050px;height:15px;' colspan='4'></td>
	</tr>
	 <tr><td  valign='top' colspan=3  style='width:1050px;'>";

echo"<table width=1050px style='position:relative; left:15px;' border='0' cellspacing=0>
	<col width=50>
	<col width=400>
	<col width=300>
	<col width=300>
	
	 <tr height='30px' style='background-color:darkgray;'>
	 <td>&nbsp;</td>
	 <td align='center' ><span class='style1'><b>Problem Type</b></span></td>
	 <td align='center' ><span class='style1'><b>SLA Hours</b></span></td>
	 <td align='center' ><div style='width:45%;float:left;'><span class='style1'><b>Show Counter Number</b></span></div><div style='width:45%;float:right;'><span class='style1'><b>No SLA Hours</b></span></div></td></tr>";
	
	 
	echo"<tr><td  colspan=4 id=''><div style='overflow-x: hidden;overflow-y:scroll;height:250px;width:1060px;border:0px solid #000000;'>
	<table  border='0' width='1050px'>
	<col width=25>
	<col width=25>
	<col width=400>
	<col width=300>
	<col width=150>
	<col width=150>";
	
	$querysearch  = " select ticketProblem_id, ticketProblem_type, ticketProblem_SLAHours,if(ticketProblem_showCounter=1,'&#10004;','&cross;'), if(ticketProblem_NoSLAHours=1, '&#10004;','&cross;') from ticket_problem ";
	$querysearch .= " where (ticketProblem_type like"."('%".$txtKeyword."%') or ticketProblem_SLAHours like"."('%".$txtKeyword."%')) ";
	$querysearch .= " order by ticketProblem_type ";
	
	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
	
		
	$querysearch = $querysearch." limit ".$startrange.",".$perpage;
	

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
	while($rows=mysql_fetch_array($resultsearch)){
		$ct+=1;
		$stylefont='style15';
		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
				
		if($tpId==$rows[0]){
			
			$Color="style='background-color:#1e87a5'";
			$stylefont='style28';
		}	
		
	echo'<tr '.$Color.' height="20px" >';
	echo "<td align=center ><img border='0' src='img/button_edit.png' width='9' height='10' title='Edit Detail' onmouseover=\"this.style.cursor='pointer'\" OnClick=\"editRecord('$rows[0]')\"></td>";	
	echo "<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover=\"this.style.cursor='pointer'\" OnClick=\"deleteRecord('$rows[0]')\"></td>";	
	echo"<td><span class='$stylefont' >$rows[1]</span></td>
		<td><span class='$stylefont'>$rows[2]</span></td>
		<td><span class='$stylefont'>$rows[3]</span></td>
		<td><span class='$stylefont'>$rows[4]</span></td>";
	echo"	</tr>";
}		
	
echo"</table></div></td></tr>";

echo"<tr><td >&nbsp;</td><td align='center'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td></tr>";

echo"</table></td></tr><tr>
					<td id='' style='width:1050px;height:20px;' colspan='4'></td>
				</tr></table></td></tr></table></td></tr>";		


	  
 echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	

print <<< HERE
      
	  </table>
HERE;


print <<<HERE
</form>
</body>

HERE;

?>