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


$querylog="SELECT RI_ListofProduction as loginaccess, print as printaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['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");


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

HERE;

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter ".
             " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


$querylog=" select ifNull(FI_RepRestrictProject,0) As FI_RepRestrictProject, ifNull(FI_RepRestrictCostcenter,0) As FI_RepRestrictCostcenter, ".
		  " ifNull(FI_RepRestrictWarehouse,0) As FI_RepRestrictWarehouse, ifNull(FI_ShowCostPrice,0) As FI_ShowCostPrice  ".
          " from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."') ";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$querysetup ="select base1, base2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);

//Projects List
$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%') ".
			  " where user_account='".$HTTP_SESSION_VARS['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());
$projectexist  = mysql_num_rows($projectresult);	
if ($projectexist == 0 || $FI_RepRestrictProject == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";	  

$resultfromproject=mysql_query($queryproject,$connection) or die(mysql_error());
$resulttoproject  =mysql_query($queryproject,$connection) or die(mysql_error());


//Costcenter List
$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$HTTP_SESSION_VARS['dbLabel'].".loginstk on costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%') ".
			   " where user_account='".$HTTP_SESSION_VARS['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);		  
if ($costcentexist == 0 || $FI_RepRestrictCostcenter == 0)
    $querycostcent=" select distinct costcent_code, costcent_name from costcent order by costcent_code ";			  
	
$resultfromcostcent=mysql_query($querycostcent,$connection) or die(mysql_error());
$resulttocostcent  =mysql_query($querycostcent,$connection) or die(mysql_error());


//Get Default Project
$querydflproject="select project_code as defaultproject from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}





if ((!isset($fromproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1)
	$fromproject = $defaultproject;
if ((!isset($toproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1)
	$toproject = $defaultproject;
if ((!isset($fromcostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	$fromcostcent = $defaultcostcent;	
if ((!isset($tocostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	$tocostcent = $defaultcostcent;	

if (empty($fromdate))	
	$fromdate = displayFromDate(displayToday());
if (empty($todate))	
	$todate = displayToday();
	
$ShowCostMode  = '';
$ShowCostCheck = 'checked';
if($FI_ShowCostPrice == 0)  {
	$ShowCostMode  = 'disabled';	
	$ShowCostCheck = 'unchecked';	
}	
	
print <<< HERE

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />

<script language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->
<script type="text/javascript" language="javascript">
<!--


all = 0;  // 0 means 'no', 1 means 'yes'

function openvehicle(){
	win = window.open('Form_VehicleListReport.php?str=vehiclemovement', 'Form_VehicleSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
}


function printPrev(printaccess)
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
		
	
	varfromdate   = document.form1.fromdate.value;
	vartodate     = document.form1.todate.value;
	varfromemployee   = document.form1.fromemployee.value;
	varvehicleid    = document.form1.vehicle_id.value;
	varplaceid    = document.form1.place_id.value;
	
	varfromref    = document.form1.fromreference.value;
	vartoref    = document.form1.toreference.value;
	
 for (var i=0; i < document.form1.date.length; i++)
  {
    if (document.form1.date[i].checked)
    {
      var vardate = document.form1.date[i].value;
    }
  }	 

  
	str =  'Rep_VehicleMovement.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromemployee='+varfromemployee
		   +'&vehicleid='+varvehicleid+'&placeid='+varplaceid+'&vdate='+vardate+'&fromreference='+varfromref+'&toreference='+vartoref;
		   
			   
	if (printaccess==1)
		window.open(str);
	else
		window.open(str,"Report", "width=900,height=600,screenX=0,left=50,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
		
		
}


function SelectReport(option){
	var x = document.form1;
	
	if (option == 1) {
		for (var i=0; i < x.listby.length; i++)
		{
			x.listby[i].disabled = true;
		}
		
		x.showidealqty.disabled = true;
		x.showidealqty.checked  = false;
		
	}
	else if (option == 2) {
		for (var i=0; i < x.listby.length; i++)
		{
			x.listby[i].disabled = false;
		}
		
	}
}

function SelectListBy(option){
	var x = document.form1;
	
	if (option == 1) {
		x.showidealqty.disabled = true;
		x.showidealqty.checked  = false;
	}
	else if (option == 2) {
		x.showidealqty.disabled = false;
		
	}
}

function showlistemployee(str){
	win = window.open('Form_EmployeeListReport.php?str='+str, 'Form_EmployeeSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
}

-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>List of Vehicle Movements</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>

<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>
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'>Vehicle Movement Report</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

	 
	
echo"<tr>
		<td  height='18'  valign='top' id='content-top2'>";
			
			
echo"</td></tr>";
 
echo '  <tr><td colspan="9" id="content-body" align="left" >';

 echo"<table border=0 align=center width=900><td width=3%></td><td>";
 




echo" <tr height=30 >";
echo"<td bgcolor='#F5F5F5' colspan=2> <span class='style4'>";
    echo "<input name='date' id='date' type='radio' checked value='date' />";
	
echo"</label> ";
echo"Date</span></td>";
echo"<td width='18%' height='19' colspan='5' align='left' bgcolor='#F5F5F5'><span class='style4'>";
echo"<label>";

	
   echo "<input name='date' id='date' type='radio' value='reference' />";				

echo"</label>";
echo"Reference</span></td>";

echo" </tr>";

echo" <tr height=30 >";	  
echo"   <td width='5%'  valign='middle' bgcolor='#F5F5F5' ><span class='style4'>From</span></td>";
echo"   <td width='15%'  valign='middle' bgcolor='#F5F5F5' ><span class='style4'>";
echo"      <input type='text' name='fromdate' value='$fromdate' maxlength='10' size='10'>";
echo"      <A HREF=\"#\" onClick=\"displayCalendar(document.form1.fromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>";

echo"   <td width='10%' valign='top' bgcolor='#F5F5F5'><span class='style4'>From<label></td>";

echo"   <td width='15%'  colspan=5 valign='middle' bgcolor='#F5F5F5' ><span class='style4'>";
echo"      <input type='text' name='fromreference' value='$fromreference' size='20'></td>";
  

		

echo" </tr>";

echo" <tr height=30 >";
echo"   <td width='5%' valign='top' bgcolor='#F5F5F5'><span class='style4'>To</span></td>";
echo"   <td width='15%' valign='top' bgcolor='#F5F5F5'><span class='style4'>";
echo"      <input type='text' name='todate' value='$todate'  maxlength='10' size='10'>";
echo"      <A HREF=\"#\" onClick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>";
 echo" <td bgcolor='#F5F5F5'><span class='style4'>To<label></td>";
echo"   <td width='15%' colspan=5 valign='middle' bgcolor='#F5F5F5' ><span class='style4'>";
echo"      <input type='text' name='toreference' value='$toreference' size='20'></td>";
echo" </tr>";

echo" <tr height=30 >";
echo"   <td colspan='7' bgcolor='#F5F5F5'><span class='style4'>&nbsp;</span></td>";
echo" </tr>";



echo" <tr height=30 >";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style4'>Employee</span></td>";
echo"   <td width='30%'  colspan='2' valign='middle' bgcolor='#F5F5F5' ><span class='style4'>";
echo"   <label>
        
        <input name='fromemployee' type='text' id='fromemployee' size='45' value='".$fromemployee."' style='width:316.37px' />
        </label>
      </span>
      
	  <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Employee From ' 
             onClick='showlistemployee(1); '>
			 <img src='img/scroll-down-1.png' width='20' height='20' border='0' /></a> </span></label>      ";

echo"   <td width='5%'  align='right' bgcolor='#F5F5F5' ><span class='style4'>Vehicle</span></td>";			 		
		echo"<td colspan=5  bgcolor='#F5F5F5' ></span>&nbsp;
				<input type='text' name='vehicle_name' style='width:250px'  value='$vehicle_name'>
				<input type='hidden' name='vehicle_id' $status  style='border:0px;width:150px' readonly value='$vehicle_id'>
				
				<label><span class='style1'><img src='img/scroll-down-1.png' title=' Select Vehicle ' id='btnvehicle' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\"  onclick=\"openvehicle()\"  /></span></label>
				</td>
				
				";
echo" </tr>";
   
echo" <tr height=30 >";	  
 
echo"   <td width='5%'  align='right' bgcolor='#F5F5F5' ><span class='style4'>Place</span></td>";			 		
		echo"<td colspan=5  bgcolor='#F5F5F5' align='left'></span>&nbsp;
			<select   name='place_id' onchange=dosubmit(); value='".htmlspecialchars($place_id, ENT_QUOTES)."'  style='width:320px; position:relative; left:33px;' />";
	
	$queryplace="select place_id,fromplace_name,toplace_name from place order by fromplace_name
				 ";
	$resultplace = mysql_query($queryplace, $connection);
	echo"<option value=''></option>";
	while($rowplace=mysql_fetch_array($resultplace)){
	echo"<option value='$rowplace[0]' ";
		if ($rowplace[0]==$place_id)
			echo " selected ";
	echo">$rowplace[1] -----> $rowplace[2]</option>";
	
	}
echo"</select >
				</td>
				
				";		 
echo" </tr>";



echo" <tr><td bgcolor='#F5F5F5' colspan=10>&nbsp;</td></tr>
		<tr>
      <td colspan='9' align='center' bgcolor='#F5F5F5'>
	  <button type='reset'  name='clearbtn' value='Clear'  /><span><span>Clear</span></span></button>
	  <button type='button' name='preview' id='Preview' value='Preview'   onClick=\"printPrev('".$printaccess."')\"; /><span><span>Preview</span></span></button>
	  
      </td>
    </tr>
	<tr>
	  <td colspan='9' height='100'>&nbsp;</td>
    </tr>
  </table>
 </td></tr> 
 
 

      
       <tr height='30'><td align='center' id='content-bottom' ></td></tr>
	  </table>

</form>
</body>
</html>";


//Return Date in DD/MM/YYYY format
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");
}
	  
?>