<?php


session_start();


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


$service='delivery';


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



print <<<HERE

<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
HERE;

if($cashreg_colortheme=='red'){
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-red.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-red.css" />';
}	
else if($cashreg_colortheme=='' || $cashreg_colortheme=='default')	{
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-default.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-default.css" />';
}


print <<<HERE
<link rel="stylesheet" href="Style.css" type="text/css" />

<script type="text/javascript">

function assigndriver(vdeldriver_id,vsaleid){

document.selectdriver.deldriver_id.value=vdeldriver_id;
document.selectdriver.saleid.value=vsaleid;
selectdriver.submit();

}
function opendrivers(){

var Win_Employee = window.open('List_Drivers.php','List_Drivers', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=760,height=520,left=250,top=200');		
}

function SelectRecord(value1,value2,value3){

		value2 = value2.replace(/%20/g, ' ');

		document.selectdriver.driver_Code.value = value1;
		opener.document.retail.txtRetDriverCode.value = value1;
		opener.document.retail.txtRetDriverName.value = replaceAll(value3, "<br>", "\\n");
		//opener.document.retail.txtRetDriverName.focus();
		
		opener.document.retail.submit();
		document.selectdriver.submit();
}

function replaceAll(txt, replace, with_this) {   return txt.replace(new RegExp(replace, 'g'),with_this); }
</script>
<style type="text/css">
img:hover {
    opacity: 0.5;
    filter: alpha(opacity=50);
}
</style>
</head>
<body leftmargin="0px" topmargin="0px" marginwidth="0px" marginheight="0px"> 
<form method="GET" name='selectdriver' action=''>
<input type='hidden' name='deldriver_id' value='$deldriver_id'>
<input type='hidden' name='driver_Code' value='$driver_Code'>
<input type='hidden' name='saleid' value='$saleid'>

HERE;


echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' ><br>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:650px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Select Driver
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr><tr height = 400 valign = top><td id='search-content1'></td><td>
	
";


 
print <<<HERE


<table width='650' border=0>
<tr><td ></td><td ></td></tr>
<tr><td >
<table width='650' border=0>

HERE;

	$query="select ledger_number, ledger_name, Concat(ledger_name, if(ifnull(Client_Telephone1,'') != '', concat('<br>Tel#: ', Client_Telephone1), '')) as DriverRemark from clients where  client_type = 'driver'  ";
	$result=mysql_query($query,$connection) or die(mysql_error());
	
	$j=1;
	while($row=mysql_fetch_array($result)){
	
	$lname = ereg_replace(" ", "%20", trim($row[1]));
	$DriverRemark=ereg_replace("'","%27",trim($row[2]));
	
	if ($j%5==0)
	echo"</tr><tr>";
	echo"<td  width='15'>
	<button type='button' onMouseOver=style.cursor='pointer' onclick=\"SelectRecord('$row[0]','$lname','$DriverRemark');\" style='border:0px;width:167px;height:70px;color:black;font-weight:bold;font-size:20px'  ><span><span>".$row[1]."</span></span></button></td>";
	
	$j+=1;
	}
	
	echo"<td></td>";

	echo"</tR>";
	
	echo"<tr>";
	
	echo"<td><button type='button' onMouseOver=style.cursor='pointer'  onclick=opendrivers() style='border:0px;width:167px;height:70px;color:red;font-weight:bold;font-size:20px'  ><span><span>List Drivers</span></span></button></td>";
	echo"</td>";
	
	echo"</tr>";
	
	echo"<tr><td colspan=10 height='20'></td></tr>";
echo"</table>";	
 


if($saleid!='' and $driver_Code!=''){
$query = "update temp_retail set driver_Code = '$driver_Code' where sale_id = $saleid ;";
//echo $query;
$result = mysql_query($query,$connection);
}

if($driver_Code!=''){
print <<<HERE
<script type="text/javascript" language="javascript">
self.close();
</script>

HERE;

}
 


print <<<HERE
  </table></td><td id='search-content3' ></td></tr>
  <tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:600px;' valign='top'>
HERE;
	 
		echo"</td>
		<td id='search-bottom3' style='height:34px; width:31px;'>";

 
	
print <<<HERE
&nbsp;</td></tr>
		
   </table>
</form>
</body>
</html>

HERE;


?>