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


//Access Mode On Insert/Edit/Delete
$InsMode = '';

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



if($mode=='editmode' or $mode=='view'){

	$query_edit="select  type_id, cntr_code, cntr_designation, cntr_barcode,cntr_tues
						from container 
						where Cntr_Auto='".$Cntr_Auto."'";
//echo $query_edit;
	 $resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){

	
	$type_id=$row[0];
	$cntr_code=$row[1];
	$Cntr_designation=$row[2];
	$Cntr_barcode=$row[3];
	$tues=$row[4];
	

	}
	$mode='edit';
}

if($mode=='') $mode='insert';



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

<script type="text/javascript" language="javascript">


function editmode () {

	document.Container.action="Form_Container.php?mode=edit";
	document.Container.submit();
}





function SubmitRecord() {
var perpage=document.Container.perpage.value; 
if (document.Container.cntr_code.value=='' )
		{alert('Unable to save : check missing field Size ');
		document.Container.cntr_code.focus();
	}
		

		else  if (document.Container.type_id.value=='' )
		{alert('Unable to save : check missing field type ');
		document.Container.type_id.focus();
		}
		
		else {
		
		document.Container.action="Form_Container_Actions.php?&perpage='+perpage";
				document.Container.submit();
		
		}


}


function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		
		x.mode.value='';
		x.message.value='';
		x.action='Form_Container.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.Container;
	x.cntr_code.value='';
	x.Cntr_designation.value='';
	x.Cntr_Auto.value='';
	x.Cntr_barcode.value='';
	x.type_id.value='';
	

}



   function PrintPreview() {
	var str = '';
	
	str = 'Form_ContainerPreview.php';
	window.open(str);

}



function ExportExcel() {
	var str = 'Form_ContainerExcel.php';
	window.open(str);
}


function PrintPreview() {
	var str = 'Form_ContainerPreview.php';
	window.open(str);
}

function setContainer(Cntr_Auto){
	
	document.Container.Cntr_Auto.value=Cntr_Auto;
	document.Container.message.value='';
	document.Container.mode.value='editmode';
	document.Container.submit();
}

function SetNextPage(startrange,perpage){
	document.Container.action='Form_Container.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.Container.submit();
}

function SetPrvPage(startrange,perpage){
	document.Container.action='Form_Container.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.Container.submit();
}

function SearchForContainer(){
	x = document.Container;
	document.Container.action='Form_Container.php?startrange=0';
	document.Container.submit();
}

function ClearKeyword(){
	x = document.Container;
	x.txtKeyword.value='';
	document.Container.submit();
}

function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   	document.Container.action='Form_Container.php?startrange=0';
	document.Container.submit();
  
   return false;
   }
else
   return true;
}

function confirm_delete(Code) {
	
				
	if (confirm ( "Are you sure you want to Delete this Record " + "?")) {
		
		document.Container.mode.value='delete';	
		
		document.Container.action='Form_Container_Actions.php?Cntr_Auto='+Code;
		document.Container.submit();
		
	}
					
}

function set_limit(){

	perpage=document.Container.perpage.value;
	document.Container.action='Form_Container.php?perpage='+perpage+'&startrange=0';
	document.Container.submit();
}

</script>
<title>Add Container</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;
}
.style1 {color: #999999; font-weight: bold; }
.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>

<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='Container' method='post' onKeyPress="return submitenter(this,event)">
<input type=hidden name='mode' value='$mode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='Cntr_Auto' value='$Cntr_Auto'>
HERE;



if($mode==''){
$status='disabled';
$dis='disabled';

}

if($mode=='view'){

$status='readonly';
$dis='disabled';

}

if($mode=='insert')
$status='';

//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

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'>Container</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>
									<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(); return false;' title='Save Changes' $Insmode><span><span>Save</span></span></button>&nbsp;";
									
									echo "<button type='button' id='btnPrint' name='btnPrint' onclick='PrintPreview(); return false;' title='Print' $Insmode><span><span>Print</span></span></button>&nbsp;";
									
									echo "<button type='button' id='btnExcel' name='btnExcel' onclick='ExportExcel(); return false;' title='Export Excel' ><span><span>Excel</span></span></button>";
								echo"</td>
								<td align='left' width='250px'>
									<input type='text' name='txtKeyword' value='$txtKeyword' style='width:105px;' onKeyPress='return submitenter(this,event)'>
									<button type='button' id='btnSearch' name='btnSearch' onclick='SearchForContainer(); return false;' title='Search Container'><span><span>Find</span></span></button>
									<button type='button' id='btnClear' name='btnClear' onclick='ClearKeyword(); return false;' title='Clear Keyword'><span><span>Clear</span></span></button>
								</td>
								<td align='left'>
									<span class='style1'><b>".$ResultsPage1."</b></span>
									<span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
									if ($startrange=='')
										$startrange = 0;
									if ($perpage=='')
										$perpage = 50;
									//row limit loop
									foreach ($config['trowlimit'] as $value) {
										echo "<option value='$value' ";
										if($value==$perpage) echo "selected";
										echo " >$value</option>";
									}
echo"							</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td id='content-body'>";
					
				
echo "			<table border='0'  align='center' valign='top'  class='tablecontent' >
							<col width=100%>
							<tr bgcolor='#F7F7F7' >
								<td valign='top' align='left'>";
								
echo "									<table border='0' style='table-layout:fixed' align='left' valign='top'>
										<col width=100>
										<col width=200>
										<col width=100>
										<col width=200>
										<col width=100>
										<col width=200>
										
										";
					echo "
										<tr bgcolor='#F7F7F7' height='25'>
											<td valign='center' align='left' ><span class='style1'>Code&nbsp;<span class='style26'>*</span></span>
											<td align='left'><input type='text' name='cntr_code'  value='".htmlspecialchars($cntr_code, ENT_QUOTES)."' style='font-size:12px; width:100px; height:18px;'  $status maxlength='20' /></td>
										
											<td valign='center' align='left' ><span class='style1'> Designation &nbsp;<span class='style26'></span></span>
											<td><input type='text' name='Cntr_designation' value='".htmlspecialchars($Cntr_designation, ENT_QUOTES)."' style='font-size:12px; width:200px; height:18px;'  $status maxlength='100' /></td>
										
											<td valign='center' align='right' ><span class='style1'> Barcode &nbsp;</span>
											<td><input type='text' name='Cntr_barcode' value='".htmlspecialchars($Cntr_barcode, ENT_QUOTES)."' style='font-size:12px; width:200px; height:18px;'  $status maxlength='100' /></td>
										</tr>";
										echo "<tr bgcolor='#F7F7F7' height='25'>
											
											<td valign='center' align='left' ><span class='style1'> Type &nbsp;<span class='style26'>*</span></span>
											<td><input type='text' name='type_id' value='".htmlspecialchars($type_id, ENT_QUOTES)."' style='font-size:12px; width:100px; height:18px;'  $status maxlength='100' /></td>
											<td valign='center' align='left' ><span class='style1'> Nb Tues &nbsp;<span class='style26'></span></span>
											<td><input type='text' name='tues' value='".htmlspecialchars($tues, ENT_QUOTES)."' style='font-size:12px; width:100px; height:18px;'  $status maxlength='100' /></td>
										
										
										
										</tr>";
										

									echo "
									</table>
								</td>
							</tr>
							<tr>
								<td  valign='top'style='width:1100px;'>
									<table style='width:1100px;' border='0' cellspacing=0>
										<col width=30>
										<col width=100>
										<col width=400>
										<col width=100>";
										
										echo "<tr style='background-color:darkgray;'>";
									
											echo "<td align='left' ></td>
											<td align='center' ><span class='style1'><b>Code</b></td>
											<td align='center' ><span class='style1'><b>description</b></td>
											<td align='center' ><span class='style1'><b>Type</b></td>
										</tr>";
										
									echo "</table>
								</td>
							
										<tr>
											<td>";
											
echo"											<table  border='0' width='1100px;'>
													<col width=30>
													<col width=100>
													<col width=400>
													<col width=100>";

													$querysearch="select Cntr_Auto,cntr_code,Cntr_designation,type_id from container ";
													$querysearch=$querysearch." where (cntr_code like"."('%".$txtKeyword."%') or Cntr_designation like"."('%".$txtKeyword."%')) ";
														
													$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
													$totalrows = mysql_num_rows($resultsearch);

													if ($startrange=='')
														$startrange = 0;
													if ($perpage=='')
														$perpage = 50;

													$querysearch = $querysearch." limit ".$startrange.",".$perpage;

													$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
														while($rows=mysql_fetch_array($resultsearch)){
															$ct+=1;
															$stylefont='style15';
															if($ct%2==0)
																$Color="style='background-color:".$grid_color1."'";
															else			
																$Color="style='background-color:".$grid_color2."'";	
																	
															if($mode=='edit' && $Cntr_Auto==$rows[0]){
																
																$Color="style='background-color:#1e87a5'";
																$stylefont='style28';
														}	
																		
													echo'<tr '.$Color.' height="20px" >';
print<<<HERE
															<td align=center >
															<img border='0' src='img/c_delete.png' width='9' height='10'
															title='Delete Detail' onmouseover="this.style.cursor='pointer'" 
															OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;



echo"														<td style='cursor:pointer;' "; echo " onclick=setContainer('$rows[0]');";echo"><span class='$stylefont' >$rows[1]&nbsp;</span></font></td>
															<td style='cursor:pointer;' "; echo " onclick=setContainer('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[2]&nbsp;</span></font></td>
															<td style='cursor:pointer;' "; echo " onclick=setContainer('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[3]&nbsp;</span></font></td>";
echo"													</tr>";
}		
echo"												</table>";
												//	</div>
echo "											</td>
											</tr>
										<tr>
											
											<td align='center'>";
											echo "<table><tr><td>";
												$diff= $startrange - $perpage;
												
												if (($diff) >= 0 ){
													
													$prvstartrange = $startrange - $perpage;
													echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
												}
												else
													echo "&nbsp;";
													
echo"										 </td><td>";
												if ($startrange <= $totalrows){
													$startrange = $startrange + $perpage;
													if  ($startrange <= $totalrows)
														echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
												} else
													echo "&nbsp;";																
echo"										</td></tr></table></td>
										</tr>";

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

?>














