<?php
/**
	List of Tenders Preview / Excel
**/

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

include("config.inc.php");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


$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 FI_Tender as loginaccess, print as printaccess, ExporttoExcel 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");

$querysetup ="select base1, base2, if(DefaultBase=1, base1, base2) as defaultcurr from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);
$defaultcurr = $rowsetup[2];

$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
extract($rows);

}

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(loginstk.project_code,'%') ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
			  
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectrows   = mysql_num_rows($projectresult);
if ($projectrows == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";			  
$resultproject=mysql_query($queryproject,$connection) or die(mysql_error());


if (empty($fromdate)) $fromdate = displayToday();
if (empty($todate))   $todate   = displayToday();

print <<< HERE


<!DOCTYPE>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<title>List of Tenders</title>
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style1 {
	color: #FF0000;
	font-family: "Times New Roman", Times, serif;
	font-size: 20px;
}
.style8 {font-size: 11px; color: #999999; font-weight: bold; }
.style11 {font-size: 11px}
body {
	margin-top: 0px;
}

</style>
<script>
function showlistClient(str){
	window.open('List_SorClient.php?frm='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function showlistProject(item){
	window.open('List_SorProject.php?frm=38&item='+item,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function PrintPrev(exp){
	var str;
	var x = document.form1;
	
	if (exp == 0)
		str = 'Rep_ListofTenders.php';
	else
		str = 'Exp_ListofTenders.php';
	
	var fromdate 	= x.fromdate.value;
	var todate 		= x.todate.value;
	
	var fromclient 	= x.fromclient.value;
	var toclient 	= x.toclient.value;
	
	var fromproject = x.fromproject.value;
	var toproject 	= x.toproject.value;
	
	
	str = str+'?fromdate='+fromdate+'&todate='+todate+'&fromclient='+fromclient+'&toclient='+toclient+'&fromproject='+fromproject+'&toproject='+toproject;
	window.open(str, 'List of Tenders');
}
</script>


<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20101112" media="screen"></link>
<script type="text/javascript" src="dhtmlgoodies_calendar.js?random=20100118"></script>

</head>
<body>
HERE;

echo "<form id='form1' name='form1' method='post' action='$_SERVER[PHP_SELF]'>";

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'>  Transfer List</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='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";
				
echo" <button type='button' id='btnClear' name='btnClear'  title='Clear Page' onClick=\"clearPage()\"><span><span>Clear</span></span></button>";
     

	 echo" <button type='button' id='preview' name='preview' onClick=\"PrintPrev('0')\"; title='Preview'><span><span>Preview</span></span></button>";
	

if ($ExporttoExcel==1){
	 echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"PrintPrev('1')\"; title='Export Excel'><span><span>Export Excel</span></span></button>";

}	
	

echo"	</td></tr></table>";
echo"</td></tr>";				

		
echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";		
   
echo "  <table border='0' align='center' width='1100px'>
	<col width=120px><col width=160px><col width=200px><col width=140px><col width=120px><col width=160px><col width=200px>";

//Date
echo "<tr><td><span class='style8'>Date</span></td></tr>";
echo "<tr>
		<td><span class='style8'>From</span></td>
		<td><input type='text' name='fromdate' id='fromdate' value='$fromdate' style='width:90px;' maxlength='10'>
			<a href='#' onclick=\"displayCalendar(document.form1.fromdate,'dd/mm/yyyy',this);return false;\" id='anchor1' name='anchor1'>
			<img src='./img/cal.gif' border='0' align='center'>
		</td>
		<td colspan='5'></td>
	</tr>";
echo "<tr>
		<td><span class='style8'>To</span></td>
		<td><input type='text' name='todate' id='todate' value='$todate' style='width:90px;' maxlength='10'>
			<a href='#' onclick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this);return false;\" id='anchor1' name='anchor1'>
			<img src='./img/cal.gif' border='0' align='center'>
		</td>
		<td colspan='5'></td>
	</tr>";

echo "<tr height='20px'><td colspan='7'></td></tr>";	

// Client Code/Description 	// Project Code/Description	
echo "<tr >
		<td colspan='3'><span class='style8'>Client Code / Description</span></td>
		<td></td>
		<td colspan='3'><span class='style8'>Project Code / Description</span></td>
	 </tr>";

// From Client 	// From Project 
echo "<tr>
		<td><span class='style8'>From</span></td>
		<td colspan='2'><input type='text' name='fromclient' id='fromclient' value='' style='width:120px;'>
			<input type='text' name='fromclientname' id='fromclientname' value='' style='width:180px;'>
			<label><span class='style1'><img src='img/btnopen.jpg' title='Select Client' id='lstClientCodeH' width='15' height='20' border='0' onmouseover=\"style.cursor='hand'\"
					onclick=\"showlistClient('18');\" > </span></label>
		</td>
		<td></td>
		<td><span class='style8'>From</span></td>
		<td colspan='2'><input type='text' name='fromproject' id='fromproject' value='' style='width:120px;'>
			<input type='text' name='fromprojectname' id='fromprojectname' value='' style='width:180px;'>
			<label><span class='style1'><img src='img/btnopen.jpg' title='Select Client' id='lstClientCodeH' width='15' height='20' border='0' onmouseover=\"style.cursor='hand'\"
					onclick=\"showlistProject('1');\" > </span></label>
		</td>
	 </tr>";

// To Client 	// To Project 
echo "<tr>
		<td><span class='style8'>To</span></td>
		<td colspan='2'><input type='text' name='toclient' id='toclient' value='' style='width:120px;'>
			<input type='text' name='toclientname' id='toclientname' value='' style='width:180px;'>
			<label><span class='style1'><img src='img/btnopen.jpg' title='Select Client' id='lstClientCodeH' width='15' height='20' border='0' onmouseover=\"style.cursor='hand'\"
					onclick=\"showlistClient('19');\" > </span></label>
		</td>
		<td></td>
		<td><span class='style8'>To</span></td>
		<td colspan='2'><input type='text' name='toproject' id='toproject' value='' style='width:120px;'>
			<input type='text' name='toprojectname' id='toprojectname' value='' style='width:180px;'>
			<label><span class='style1'><img src='img/btnopen.jpg' title='Select Client' id='lstClientCodeH' width='15' height='20' border='0' onmouseover=\"style.cursor='hand'\"
					onclick=\"showlistProject('2');\" > </span></label>
		</td>
	 </tr>";
echo "<tr height='20px'><td colspan='7'></td></tr>";	 
echo"   </table></td></tr>"; 
 echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
 echo" </table>
 
</form>
</body>
</html>";

function displayFromDate($data){
	return "01/01/".substr($data, 6, 4);		
}
//Return Today's Date in DD/MM/YYYY format
function displayToday(){
	return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
}

?>
