<?php
/**
	Tenders Form
**/
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);
}

if(!isset($actionmode))
$actionmode='';

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

// User Access 
$querylog=" SELECT FI_Tender as loginaccess, login_belongstogrp, ifNull(FI_TenderDel,0) as FI_TenderDel, ifNull(FI_TenderMod,0) as FI_TenderMod, ifNull(FI_TenderApp,0) as FI_TenderApp, 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");

// Labels
$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);

$saveEnabled = 0;
if ( ($FI_TenderMod == 1 && $actionmode=='editmode') || ($FI_TenderApp == 1))
	$saveEnabled = 1;

// Initial Values
if($actionmode=='')	 		$actionmode		= 'insert';
if ($txtReviewReady == '')  $txtReviewReady = 0;
if ($txtAwardStat == '')	$txtAwardStat 	= 0;

if ($txtRcvdDate == '')		$txtRcvdDate 	= date('d/m/Y');;

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"> 
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<title>Tenders</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;
}

.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>
<script>

function setChkBox(valid){
	if(document.getElementById(valid).checked)
		document.getElementById(valid).value = 1;
	else
		document.getElementById(valid).value = 0;		
}

function returnMsg(){
	alert('Access Denied!');
	return 0;
}

function showlistClient(){
	var vdate, vcode;
	vdate = document.tender.txtRcvdDate.value;
	vcode = encodeURIComponent(document.tender.txtClientCode.value);
	vname = encodeURIComponent(document.tender.txtClientName.value);
  
	window.open('List_SorClient.php?frm=17&item=&PLedger_name='+vname+'&PLedger_number='+vcode+'&TransDate='+vdate,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistProject(){

	vProjectCode = encodeURIComponent(document.getElementById('txtProjectCode').value);
	window.open('List_SorProject.php?frm=42&item&PProject_Code='+vProjectCode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function SubmitRecord(){
	var x = document.tender;
	if(x.txtClientCode.value == ''){
		alert('Client should not be Empty!');
		x.txtClientCode.focus();
		showlistClient();
		return 0;
	} else if(x.txtProjectCode.value == ''){
		alert('Project should not be Empty!');
		x.txtProjectCode.focus();
		showlistProject();
		return 0;
	} else {
		if(confirm('Are you sure You want to save?')){
			x.action = "Form_Tenders_Action.php";
			x.submit();
		}
	}
}

function openSearch(){
	window.open('Form_TenderSearch.php','Search Tender','width=950,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function ClearPage(){
	var x = document.tender;
	
	x.tenderid.value		= '';
	x.txtRcvdDate.value		= '';
	x.txtDueDate.value		= '';
	x.txtSubmitDate.value	= '';
	x.txtClientCode.value	= '';
	x.txtClientName.value	= '';
	x.txtProjectCode.value	= '';
	x.txtProjectDesc.value	= '';
	x.txtAvaDocs.value		= '';
	x.txtScope.value		= '';
	x.txtActionReq.value	= '';
	x.txtStatusAt.value		= '';
	x.txtAmount.value		= '';
	x.txtDirCost.value		= '';
	x.txtMargin.value		= '';
	x.txtMarginPer.value	= '';
	x.txtAwardStat.value	= '';
	x.txtReviewReady.value	= '';
	
	x.action = 'Form_Tenders.php';
	x.submit();
}
</script>
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body >
<form name='tender' method='post' >
<input type='hidden' name='actionmode' value='$actionmode'>
<input type=hidden name='message' value='$message'>
HERE;

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

if ($tenderid != '' && $actionmode == 'editmode'){
	$queryEdit = " select tender_reference, tenders.project_code, project_name, client_code, ledger_name, date_format(tender_receivedDate,'%d/%m/%Y'), tender_documents, tender_scope, date_format(tender_dueDate,'%d/%m/%Y'),   ".
				 " ifnull(tender_reviewReady,0), tender_actionReq, tender_statusAt, date_format(tender_submitDate,'%d/%m/%Y'), tender_amount, tender_directCost, tender_margin, tender_marginPer, ifnull(tender_awardStatus,0) ".
				 " from tenders ".
				 " inner join clients on Ledger_number = client_code ".
				 " inner join project on project.Project_Code = tenders.project_code ".
				 " where tender_id = $tenderid "; 
	$resEdit = mysql_query($queryEdit, $connection);			 
	$rowEdit = mysql_fetch_row($resEdit);
	
	$ref			= $rowEdit[0];
	$txtClientCode 	= $rowEdit[3];
	$txtClientName	= $rowEdit[4];
	$txtProjectCode = $rowEdit[1];
	$txtProjectDesc = $rowEdit[2];
	$txtRcvdDate 	= $rowEdit[5];
	$txtDueDate 	= $rowEdit[8];
	$txtSubmitDate 	= $rowEdit[12];

	$txtScope 		= $rowEdit[7];
	$txtAvaDocs 	= $rowEdit[6];
	$txtActionReq 	= $rowEdit[10];
	$txtStatusAt 	= $rowEdit[11];
	$txtAmount 		= $rowEdit[13];

	$txtDirCost 	= $rowEdit[14];
	$txtMargin 		= $rowEdit[15];
	$txtMarginPer 	= $rowEdit[16];
	$txtAwardStat 	= $rowEdit[17];
	$txtReviewReady = $rowEdit[9];
}

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'>Tender</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";
// Buttons
echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width' width='1100px'>
				<col width='450'>
				<col width='120'>
				<col width='150'>
				<col width='250'>
				<col width='200'>
				<col width='200'>
				<tr>
					<td valign='middle' height='34' style='padding-left:40px'>";
	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='btnSearch' name='btnSearch' onclick='openSearch(); return false;' title='Search Record'><span><span>$SEARCH</span></span></button>";
	echo"				<button type='button' id='btnPost' name='btnPost' onclick=\"";
	if ($saveEnabled == 1)
		echo "SubmitRecord(); ";
	else
		echo "returnMsg(); ";	
	echo "return false;\" title='Save Changes' ><span><span>$Save</span></span></button>";
	echo "</td>";
	echo"<td align='center'>";
	echo"</td><td  align='center'>";
	echo"	</td>
			<td align='left' width='263px'></td>
			<td colspan=2 align='left'></td>
				</tr>
			</table>
		</td>
	</tr>";

	// Main Part
	echo"<tr><td id='content-body'>";		
	echo"<table border='0'  align='center' valign='top' width=1100px class='tablecontent'>";
	echo"<tr bgcolor='#F7F7F7'><td valign='top'>";
	echo "<table style='table-layout:fixed' align='left' valign='top' width='1100px' border=0>
		<col width=130px><col width=190px><col width=220px><col width=130px><col width=150px><col width=130px><col width=150px>";
	
	
	//Row 1
	echo "<tr height='30px'>
			<td><span class='style1'>Reference</span></td>
			<td><span class='style1'>$ref</span></td>
			<td><input type='hidden' name='tenderid' id='tenderid' value='$tenderid'></td>
			<td><span class='style1'>Date Received</span></td>
			<td><input type='text' name='txtRcvdDate' id='txtRcvdDate' value='$txtRcvdDate' style='width:80px;'>
				<a href='#' onclick=\"displayCalendar(document.tender.txtRcvdDate,'dd/mm/yyyy',this);  return false;\" name='anchor1' id='anchor1'><img src='./img/cal.gif' border='0' align='center'></a>
			</td>
			<td><span class='style1'>Submission Due Date</span></td>
			<td><input type='text' name='txtDueDate' id='txtDueDate' value='$txtDueDate' style='width:80px;'>
				<a href='#' onclick=\"displayCalendar(document.tender.txtDueDate,'dd/mm/yyyy',this);  return false;\" name='anchor1' id='anchor1'><img src='./img/cal.gif' border='0' align='center'></a>
			</td>
		 </tr>";
	
	//Row 2
	echo "<tr height='30px'>
			<td><span class='style1'>Client</span></td>
			<td colspan='2'>
				<input type='text' name='txtClientCode' id='txtClientCode' value='$txtClientCode' style='width:120px;'>
				<input type='text' name='txtClientName' id='txtClientName' value='$txtClientName' style='width:200px;'>	
				<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();\" > </span></label>
			</td>
			<td><span class='style1'>Date Submitted</span></td>
			<td><input type='text' name='txtSubmitDate' id='txtSubmitDate' value='$txtSubmitDate' style='width:80px;'>
				<a href='#' onclick=\"displayCalendar(document.tender.txtSubmitDate,'dd/mm/yyyy',this);  return false;\" name='anchor1' id='anchor1'><img src='./img/cal.gif' border='0' align='center'></a>
			</td>
			<td colspan='2'></td>			
		 </tr>";
	
	//Row 3	
	echo "<tr height='30px'>
			<td><span class='style1'>Project</span></td>
			<td colspan='2'>
				<input type='text' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' style='width:120px;'>
				<input type='text' name='txtProjectDesc' id='txtProjectDesc' value='$txtProjectDesc' style='width:200px;'>	
				<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();\" > </span></label>
			</td>
			<td><span class='style1'>Available Documents</span></td>
			<td colspan='3'><textarea name='txtAvaDocs' id='txtAvaDocs' cols='50' rows='2'>".htmlentities($txtAvaDocs,ENT_QUOTES)."</textarea></td>
		 </tr>";	

	//Row 4	
	echo "<tr height='30px'>
			<td><span class='style1'>Scope of Works</span></td>
			<td colspan='2'>
				<textarea name='txtScope' id='txtScope' cols='40' rows='2'>".htmlentities($txtScope,ENT_QUOTES)."</textarea>
			</td>
			<td><span class='style1'>Urgent Action Requested</span></td>
			<td colspan='3'><input type='text' name='txtActionReq' id='txtActionReq' value='".htmlentities($txtActionReq,ENT_QUOTES)."' style='width:370px;'></td>
		 </tr>";	
	
	echo "<tr height='30px'>
			<td><span class='style1'>Status At</span></td>
			<td colspan='2'>
				<input type='text' name='txtStatusAt' id='txtStatusAt' value='".htmlentities($txtStatusAt,ENT_QUOTES)."' style='width:300px;'>
			</td>
			<td><span class='style1'>Tender Amount</span></td>
			<td><input type='text' name='txtAmount' id='txtAmount' value='$txtAmount' style='width:120px;'></td>
			<td><span class='style1'>Direct Cost</span></td>
			<td><input type='text' name='txtDirCost' id='txtDirCost' value='$txtDirCost' style='width:120px;'></td>
		 </tr>";	
	echo "<tr height='30px'>
			<td><span class='style1'>Margin</span></td>
			<td colspan='2'>
				<input type='text' name='txtMargin' id='txtMargin' value='$txtMargin' style='width:120px;'>&nbsp;&nbsp;
				<input type='text' name='txtMarginPer' id='txtMarginPer' value='$txtMarginPer' style='width:120px;'> <span class='style1'>%</span>
			</td>
			<td colspan='2'><input type='checkbox' name='txtAwardStat' id='txtAwardStat' value='$txtAwardStat' onclick=\"setChkBox('txtAwardStat');\" ".($txtAwardStat=='1'?'checked':'')."><span class='style1'>Award Status</span></td>
			<td colspan='2'><input type='checkbox' name='txtReviewReady' id='txtReviewReady' value='$txtReviewReady' onclick=\"setChkBox('txtReviewReady');\" ".($txtReviewReady=='1'?'checked':'')."><span class='style1'>To Be Ready For Review</span></td>
		</tr>";		 
	echo "</table>";	  
	echo "</td></tr>";
	echo "</table>";
	echo "</td></tr>";
 echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
print <<< HERE
			</td>
		</tr>
	</table>
HERE;

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

HERE;

?>
