<!DOCTYPE>
<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}



print <<< HERE
<HTML>
<HEAD>
<TITLE> Ticket Support Report </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style type="text/css" >
table.params td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }

table.master th { font-size: 14px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                      }				 
table.master td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }
table.group td { font-size: 12px; 
                 font-weight: bold;
                 font-family:Times-New-Roman;
               }				 
				 
table.detail td { font-size: 10px; 
                  font-family:Times-New-Roman;
                 }				 
table.headerdetail td { font-size: 10px; 
                        font-weight: bold;
                        font-family:Times-New-Roman;
                      }				 
table.totals td { font-size: 12px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                 }					  

.header1 {
	font-size: 26px;
	font-weight: bold;
}
.header2 {
	font-size: 20px;
	font-weight: bold;
}
.header3 {
	font-size: 13px;
	font-weight: bold;
}	

.detail1 {
	font-size: 12px;
	font-weight: bold;
}

</style>
</HEAD>

HERE;



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

set_time_limit(0);

$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");

$querylog="SELECT print as printaccess 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 ($printaccess==0 or $printaccess=='')
echo'<BODY oncontextmenu="return false;">';
else
echo'<BODY>';


$querysetup="select grid_color1,grid_color2, DecimalBase, DecimalBase1, DecimalBase2, report_color1, report_color2, base1, base2, Company_Name As CompanyName from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultsetup)){
  extract($rows);
}



$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);

$title = 'Ticket Support Report';

echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'>
	<col width='85%'><col width='15%'>";
echo "<tr height='30px'><td ><span class='header2'>$CompanyName</span></td><td><span class='header3'>Print Date: $printdate[2]-$printdate[1]-$printdate[0]<br>Print Time: $dt[1]</span></td></tr>";
echo "<tr height='30px'><td colspan='2'></td></tr>";
echo "<tr height='30px'><td colspan='2' align='center'><span class='header1'>$title</span></td></tr>";
echo "<tr height='30px'><td colspan='2'> </td></tr>";
echo "</table>";	

if ($tsProbTypeId != ''){
	$queryType 	 = "select ticketProblem_type from ticket_problem where ticketProblem_id = $tsProbTypeId";
	$resType 	 = mysql_query($queryType, $connection);
	$rowType 	 = mysql_fetch_row($resType);
	$problemType = $rowType[0];
	
}

if ($tsSupTeamId != ''){
	$queryTeam 	 = "select username from user_support where user_id = $tsSupTeamId";
	$resTeam 	 = mysql_query($queryTeam, $connection);
	$rowTeam 	 = mysql_fetch_row($resTeam);
	$Team		 = $rowTeam[0];
	
}

$SelectedOptions = "Filter by: <br>";
if ($fromdate != '')      $SelectedOptions .= "-> Date From: ". $fromdate . "  To: ". $todate ."<br>";	
if ($PProjectCode != '')  $SelectedOptions .= "-> Branch: ". $PProjectCode ."<br>";	
if ($tsProbTypeId != '')  $SelectedOptions .= "-> Ticket Problem Type: ". $problemType."<br>";
if ($tsSupTeamId != '')   $SelectedOptions .= "-> Team: ". $Team ."<br>";
if ($tsStatus != '')   	  $SelectedOptions .= "-> Status: ". $tsStatus ."<br>";


if (!empty($fromdate))   $fromdate = explodeword($fromdate);
if (!empty($todate))     $todate = explodeword($todate);  

$fromdate	   = GetSQLValueString($fromdate, 'date');
$todate        = GetSQLValueString($todate, 'date');   

  
  
print <<<HERE
<table width="100%" border="0" align="left" >
<tr><td>
<table class="report-master" width="100%" border="0" align="center" style='table-layout:fixed'>
<col width=100>
<tr><td>&nbsp;</td>
  <td  valign='top' width=100%><span class='header3'><b>$SelectedOptions</b></span></td>
</tr>
<tr height='5'><td><h5></td></tr>
</table></td></tr>
</table>
HERE;


 $wdt = "1180px";



echo "<table width='$wdt' cellspacing='4' cellpadding='0' border='0'>";

echo "<col width=100><col width=100><col width=150>
      <col width=100><col width=150><col width=200>
      <col width=100><col width=100><col width=120>
	  <col width=100><col width=100><col width=120><col width=200>";

 echo"<tr height='25px'>
		 <td align='left' ><span class='header3'>Date</td>
		 <td align='left' ><span class='header3'>Time</td>
		 <td align='left' ><span class='header3'>Branch</td>
		 <td align='left' ><span class='header3'>Status</td>
		 <td align='left' ><span class='header3'>Problem Type</td>
		 <td align='left' ><span class='header3'>Problem Description</td>
		 <td align='left' ><span class='header3'>Max Date	</td>
		 <td align='left' ><span class='header3'>Max Time	</td>
		 <td align='left' ><span class='header3'>Support Team</td>
		 <td align='left' ><span class='header3'>Counter No</td>
		 <td align='left' ><span class='header3'>SLA Hour</td>
		 <td align='left' ><span class='header3'>Engineer</td>
		 <td align='left' ><span class='header3'>Solution</td>
 </tr>"; 

 $querysearch = "select date_format(ticketSupport_date,'%d/%m/%Y') as ticketDate, date_format(ticketSupport_date,'%H:%i %p') as ticketTime, ticket_support.project_code as branch, project_name,
		ticketProblem_type, ticketSupport_ProblemDesc, ticketProblem_SLAHours, date_format(ticketSupport_MaxDate,'%d/%m/%Y') as MaxDate, date_format(ticketSupport_MaxDate,'%H:%i %p') as MaxTime,
		username as TeamName, ticketSupport_CounterNo, ticketSupport_SolutionDesc, ticketVisit_Engineer, ticketSupport_status
		from ticket_support
		left join ticket_problem on ticket_problem.ticketProblem_id = ticket_support.ticketProblem_id
		left join user_support on user_id = ticket_support.ticketSupport_userId 
		left join project on project.project_code = ticket_support.project_code 
		where date_format(ticketSupport_date,'%Y-%m-%d') between $fromdate and $todate
			and if('$PProjectCode'='', 1=1, ticket_support.project_code = '$PProjectCode') 
			and if('$tsProbTypeId' = '', 1=1, ticket_support.ticketProblem_id = '$tsProbTypeId')	
			and if('$tsSupTeamId' = '', 1=1, ticketSupport_userId = '$tsSupTeamId')	
			and if('$tsStatus' = '', 1=1, ticketSupport_status = '$tsStatus')	
		order by date_format(ticketSupport_date,'%Y-%m-%d %H:%i') desc ";
	
$result = mysql_query($querysearch, $connection);

while($rows = mysql_fetch_array($result)){
	extract($rows);
	if (!($ct%2))
			$bgcolor = "bgcolor='#ABD4F1'";
		else 
			$bgcolor = "bgcolor='#EFF1F3'";
	
	echo"<tr $bgcolor>
			<td align='left'><span class='detail1'>$ticketDate</span></td>
			<td align='left'><span class='detail1'>$ticketTime</span></td>	
			<td align='left'><span class='detail1'>$branch</span></td>	
			<td align='left'><span class='detail1'>$ticketSupport_status</span></td>	
			<td align='left'><span class='detail1'>$ticketProblem_type</span></td>	
			<td align='left'><span class='detail1'>$ticketSupport_ProblemDesc</span></td>	
			<td align='right'><span class='detail1'>$MaxDate</span></td>	
			<td align='right'><span class='detail1'>$MaxTime</span></td>	
			<td align='left'><span class='detail1'>$TeamName</span></td>	
			<td align='right'><span class='detail1'>$ticketSupport_CounterNo</span></td>	
			<td align='right'><span class='detail1'>$ticketProblem_SLAHours</span></td>	
			<td align='left'><span class='detail1'>$ticketVisit_Engineer</span></td>	
			<td align='left'><span class='detail1'>$ticketSupport_SolutionDesc</span></td>	
		</tr>";
	
	
	
	$ct++;
}
 
echo "</table>";



function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}

function explodeword($date)
{

$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}




if ($printaccess==1)
print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
