<?php

session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");



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

if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;
	
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<title>Search Templates</title>
<script type="text/javascript" language="javascript">

function DeleteRecord(TempId){

	if (TempId != '') {
		if (confirm ( "Are you sure you want to Delete this record ?") )
		{
			document.search.action="Form_ReportsOptions_Actions.php?SMode=delete&STempId="+TempId;
			document.search.submit();
		}
	}
	
}

function UpdateRecord(TempId){
		
	opener.document.form1.templateid.value=TempId;
	opener.document.form1.mainaction.value='edit';
	
	opener.document.form1.action='Form_ReportsOptions.php';
	opener.document.form1.submit();
	
	
	self.close();
	

}




</script>

<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;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.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: #000000 ;font-size: 10px;}

</style>

</head>
<body >
<form name='search' method='post' action="">
HERE;

echo "<input type='hidden' name='message' value='".htmlspecialchars($message, ENT_QUOTES)."'>";

echo"<table border='0' cellspacing='1' style='table-layout:fixed'>
	  <col width=20>
	  <col width=20>
	  <col width=120>
	  <col width=80>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
	  <col width=70>
		     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='30'><span class='style16'>List of Templates</span></td></tr>
	  <tr bgcolor='#DDDDDD'>
		<td height='15' align='center' colspan='30'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr bgcolor='#CCD8E6' height='20' >
		<td  align='center'><span class='style25'>&nbsp;</span></td>
		<td  align='center'><span class='style25'>&nbsp;</span></td>
		<td  align='center'><span class='style25'>&nbsp;</span></td>
		<td  align='center'><span class='style25'>&nbsp;</span></td>
		<td  align='center' colspan='2'><span class='style25'>Ledger </span></td>
		<td  align='center' colspan='2'><span class='style25'>Client </span></td>
		<td  align='center' colspan='2'><span class='style25'>Supplier </span></td>
		<td  align='center' colspan='2'><span class='style25'>Salesman</span></td>
		<td  align='center' colspan='2'><span class='style25'>Item</span></td>
		<td  align='center' colspan='2'><span class='style25'>Warehouse</span></td>
		<td  align='center' colspan='2'><span class='style25'>Group</span></td>
		<td  align='center' colspan='2'><span class='style25'>Subgroup</span></td>
		<td  align='center' colspan='2'><span class='style25'>Project</span></td>
		<td  align='center' colspan='2'><span class='style25'>Costcenter</span></td>
		<td  align='center' colspan='2'><span class='style25'>Master Project</span></td>
		<td  align='center' colspan='2'><span class='style25'>Master Costcenter</span></td>
		<td  align='center' colspan='2'><span class='style25'>Area</span></td>
	  </tr>
	  <tr bgcolor='#CCD8E6' height='20' >
		<td  align='center'><span class='style25'>&nbsp;</span></td>
		<td  align='center'><span class='style25'>&nbsp;</span></td>
		<td  align='left'><span class='style25'>Template Name </span></td>
		<td  align='left'><span class='style25'>Report Name </span></td>
		<td  align='center'><span class='style25'>From </span></td>
		<td  align='center'><span class='style25'>To </span></td>
		<td  align='center'><span class='style25'>From </span></td>
		<td  align='center'><span class='style25'>To </span></td>
		<td  align='center'><span class='style25'>From </span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
		<td  align='center'><span class='style25'>From</span></td>
		<td  align='center'><span class='style25'>To</span></td>
	  </tr>";
		

	

	

$querysearch = " SELECT Template_Id, Template_Name, Report_Name, Groupby_Level1Value, Groupby_Level2Value, Groupby_Level3Value, Groupby_Level1Name, ".
			   " Groupby_Level2Name, Groupby_Level3Name, JournalType_alltypes, JournalType_exclude, JournalType_types,  FromLedger_Number, ".
			   " ToLedger_Number, FromClient_Code, ToClient_Code, FromSupplier_Code, ToSupplier_Code, FromSalesman_Code, ToSalesman_Code, ".
			   " FromItem_Code, ToItem_Code, FromWarehouse_Code, ToWarehouse_Code, FromGroup_Code, ToGroup_Code, FromSubgroup_Code, ToSubgroup_Code, ".
			   " FromProject_Code, ToProject_Code, FromMasterProject_Code, ToMasterProject_Code, FromCostcent_Code, ToCostcent_Code, FromMasterCostcent_Code, ".
			   " ToMasterCostcent_Code, FromArea_Code, ToArea_Code  ".
			   " FROM ReportsOptions_Templates ".
			   " WHERE User_Account = '".$HTTP_SESSION_VARS['useraccount']."'";
 
//echo $querysearch;			 

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

$i = 0;
while($rows=mysql_fetch_array($resultsearch)){
		
	extract($rows);
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
		
		
		   
	echo'<tr '.$Color.'>
	        <td align="center"><span class="style15"><img src="img/button_edit.png" onMouseOver="style.cursor=\'hand\'" onclick="UpdateRecord('.$Template_Id.');" title="Edit Record"  ></span></td>
			<td align="center"><span class="style15"><img src="img/c_delete.png" onMouseOver="style.cursor=\'hand\'" onclick="DeleteRecord('.$Template_Id.');" title="Delete Record"  ></span></td>';
		
	echo'	<td align="left"><span class="style15">'.$Template_Name.'</span></td>
			<td align="left"><span class="style15">'.$Report_Name.'</span></td>
			<td align="center"><span class="style15">'.$FromLedger_Number.'</span></td>
			<td align="left"><span class="style15">'.$ToLedger_Number.'</span></td>
			<td align="left"><span class="style15">'.$FromClient_Code.'</span></td>
			<td align="center"><span class="style15">'.$ToClient_Code.'</span></td>
			<td align="center"><span class="style15">'.$FromSupplier_Code.'</span></td>
			<td align="center"><span class="style15">'.$ToSupplier_Code.'</span></td>
			<td align="left"><span class="style15">'.$FromSalesman_Code.'</span></td>
			<td align="left"><span class="style15">'.$ToSalesman_Code.'</span></td>
			<td align="left"><span class="style15">'.$FromItem_Code.'</span></td>
			<td align="left"><span class="style15">'.$ToItem_Code.'</span></td>
			<td align="center"><span class="style15">'.$FromWarehouse_Code.'</span></td>
			<td align="right"><span class="style15">'.$ToWarehouse_Code.'</span></td>
			<td align="center"><span class="style15">'.$FromGroup_Code.'</span></td>
			<td align="right"><span class="style15">'.$ToGroup_Code.'</span></td>
			<td align="center"><span class="style15">'.$FromSubgroup_Code.'</span></td>
			<td align="right"><span class="style15">'.$ToSubgroup_Code.'</span></td>
			<td align="left"><span class="style15">'.$FromProject_Code.'</span></td>
			<td align="left"><span class="style15">'.$ToProject_Code.'</span></td>
			<td align="left"><span class="style15">'.$FromCostcent_Code.'</span></td>
			<td align="left"><span class="style15">'.$ToCostcent_Code.'</span></td>
			<td align="left"><span class="style15">'.$FromMasterProject_Code.'</span></td>
			<td align="left"><span class="style15">'.$ToMasterProject_Code.'</span></td>
			<td align="left"><span class="style15">'.$FromMasterCostcent_Code.'</span></td>
			<td align="left"><span class="style15">'.$ToMasterCostcent_Code.'</span></td>
			<td align="left"><span class="style15">'.$FromArea_Code.'</span></td>
			<td align="left"><span class="style15">'.$ToArea_Code.'</span></td>
		</tr>';
}
							

			
		
echo"   <tr><td colspan='30'>&nbsp;</td></tr>";
echo"</table>";
	


          

		  

print <<<HERE

</form>
</body>

HERE;

?>