<?php

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);
}




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

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<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">


<title>Demarage Setup</title>
<script>

function submitRecord(){
	var demsetupid = document.demsetup.demsetupid.value;
	if (demsetupid == '')
		var mode = 'insert';
	else var mode = 'edit';
	
	if (document.demsetup.cntr_type.value == ''){
		alert('Container Type is Empty!');
		return 0;
	}
	else if (document.demsetup.fromday.value == ''){
		alert('From Day is Empty!');
		return 0;
	}
	else if (document.demsetup.demval.value == '' && document.demsetup.freeday.checked == 0){
		alert('Demarage Value is Empty!');
		return 0;
	}
	else {
		document.demsetup.action = "Form_Demarage_Action.php?mode="+mode+"&demsetupid="+demsetupid;
		document.demsetup.submit();
	}
}

function editRec(demsetupid){
	document.demsetup.demsetupid.value = demsetupid;
	document.demsetup.submit();
}

function deleteRec(demsetupid){
	document.demsetup.action = "Form_Demarage_Action.php?mode=delete&demsetupid="+demsetupid;
	document.demsetup.submit();
}

function ClearPage(){
	var x = document.demsetup;
	x.message.value 	= '';
	x.demsetupid.value 	= '';
	x.cntr_type.value 	= '';
	x.fromday.value 	= '';
	x.today.value 		= '';
	x.demval.value 		= '';
	x.action = 'Form_Demarage.php';
	x.submit();
}

function setDay(){
	if (document.getElementById('freeday').checked){
		document.getElementById('freeday').value   = 1;
		document.getElementById('today').disabled  = true;
		document.getElementById('demval').disabled = true;
	} else {
		document.getElementById('freeday').value   = 0;
		document.getElementById('today').disabled  = false;
		document.getElementById('demval').disabled = false;
	}
}
</script>
<style type="text/css">
.styledt{
    font-size: 13px;
}

.dem {
	font-size: 16px;
    font-family: sans-serif;
    font-weight: bold;
}
.dem {
	font-size: 14px;
    font-family: sans-serif;
    font-weight: bold;
}
</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>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
</head>
<body >
<form name='demsetup' id='formcr' method='post' >
<input type=hidden name='mode' value='$mode'>
<input type='hidden' name='message' value='$message'>
<input type=hidden name='demsetupid' value='$demsetupid'>
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>";


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'>Demarage Setup</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='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px'>
					<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='btnSubmit' name='btnSubmit' onclick=\"submitRecord(); return false;\" title='Save' ><span><span>Save</span></span></button>&nbsp;";
				echo"</td>
				<td align='left' width='250px'>
					</td>
				<td align='left'></td>
			</tr>
		</table>
	</td>
</tr>
<tr>
	<td id='content-body'>
		<table border='0'  align='center' valign='top'  class='tablecontent' >
				<col width=65%>
				<tr bgcolor='#F7F7F7' >
					<td valign='top' align='left'>
						<table border='0' style='table-layout:fixed' align='left'  cellpadding='0' cellspacing='0' valign='top' width='1100px'>
						<col width='120px'><col width='160px'><col width='120px'><col width='120px'>
						<col width='120px'><col width='120px'><col width='140px'><col width='180px'>";
						
if ($demsetupid != ''){
	$queryedit = "select container_type, fromday, today, demarage_val, ifnull(free_days,0) from demarage_setup where demsetup_id = $demsetupid ";
	$resedit = mysql_query($queryedit, $connection);
	$rowedit = mysql_fetch_row($resedit);
	$cntr_type 	= $rowedit[0];
	$fromday 	= $rowedit[1];
	$today 		= $rowedit[2];
	$demval 	= $rowedit[3];
	$freeday 	= $rowedit[4];
}	
$querycntr = "select type_code from containertype order by type_code";						
$rescntr = mysql_query($querycntr, $connection);

//header
echo "<tr bgcolor='#F7F7F7' height='25'>
			<td valign='center' align='left' ><span class='style1'>Container Type</span></td>
			<td align='left'><select name='cntr_type' id='cntr_type' style='font-size:12px; width:100px;'>
				<option value='' ".($cntr_type==''?'selected':'')."></option>";
	while ($row = mysql_fetch_array($rescntr)){
		echo "<option value='".htmlentities($row[0],ENT_QUOTES)."' ".($cntr_type==$row[0]?'selected':'').">$row[0]</option>";
	}	
echo "		</select></td>
			<td valign='center' align='left' ><span class='style1'>From Day</span></td>
			<td align='left'><input typ='text' name='fromday' id='fromday' value='$fromday' style='font-size:12px; width:40px;'></td>
			<td valign='center' align='left' ><span class='style1'>To Day</span></td>
			<td align='left'><input typ='text' name='today' id='today' value='$today' style='font-size:12px; width:40px;'></td>
			<td valign='center' align='left' ><span class='style1'>Demarage Value</span></td>
			<td align='left'><input typ='text' name='demval' id='demval' value='$demval' style='font-size:12px; width:60px;'></td>
		</tr>";
if ($freeday == '') $freeday = 0;		
echo "<tr height='25'><td colspan='8'><input type='checkbox' name='freeday' id='freeday' value='$freeday' onclick=\"setDay();\" ".($freeday=='1'?'checked':'')."><span class='style1'>Set From Day as Free Day</span></td></tr>";	
echo "<tr height='15'><td colspan='8'></td></tr>";		
$bottom = "border-bottom: 1px solid black";
echo "<tr height='25'><td colspan='8'>";
echo "<table cellpadding='0' cellspacing='0' width='1100px'>
	<col width='30px'><col width='30px'><col width='260px'><col width='260px'><col width='260px'><col width='260px'>";
echo "<tr height='30px' bgcolor='#a9a9a9'>
		<td align='center' style='$bottom;'></td><td align='center' style='$bottom;'></td>
		<td align='center' style='$bottom;'><span class='style1'>Type</span></td>
		<td align='center' style='$bottom;'><span class='style1'>From Day</span></td>
		<td align='center' style='$bottom;'><span class='style1'>To Day</span></td>
		<td align='center' style='$bottom;'><span class='style1'>Demarage Value</span></td>
	</tr>";
echo "</table>";
echo "</td></tr>";	

echo "<tr height='25'><td colspan='8'>";
echo "<div style='width:1100px;height:500px;overflow-y:scroll;overflow:hidden;'>
	<table cellpadding='0' cellspacing='0' width='1100px'>
	<col width='30px'><col width='30px'><col width='260px'><col width='260px'><col width='260px'><col width='260px'>";
$query = "select demsetup_id, container_type, fromday, today, demarage_val from demarage_setup order by container_type, fromday, today ";	
$result = mysql_query($query, $connection);

while ($row = mysql_fetch_array($result)){
	if ($ct%2) 
		$bgcolor = "bgcolor='#e6e6e6'";
	else 
		$bgcolor = "bgcolor='#F7F7F7'";
	
	echo "<tr height='20px' $bgcolor>
			<td align='center' ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Record' onmouseover=\"this.style.cursor='pointer'\" onclick=\"deleteRec('$row[0]');\" style='cursor: pointer;'></td>
			<td align='center'><img border='0' src='img/edit.png' width='16' height='16' title='Edit Record' onmouseover=\"this.style.cursor='pointer'\" onclick=\"editRec('$row[0]');\" style='cursor: pointer;'></td>
			<td align='center' ><span class='styledt'>$row[1]</span></td>
			<td align='center' ><span class='styledt'>$row[2]</span></td>
			<td align='center' ><span class='styledt'>$row[3]</span></td>
			<td align='center' ><span class='styledt'>$row[4]</span></td>
		</tr>";
	$ct++;
}
echo "</table></div>";
echo "</td></tr>";

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

echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
echo" </table>  ";//end of last table menu		 



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

HERE;

?>














