<?php

session_start();
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");



$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}
$Manifest_Auto=$_GET['Manifest_Auto'];

$query="select stamp1_id,stamp2_id,stamp3_id,
stamp4_id,stamp5_id,stamp6_id
 from manifest inner join stamp on stamp.code=manifest.stamp1_id where manifest_auto='$Manifest_Auto'";
 
 //echo $query;
 $queryres=mysql_query($query,$connection) or die(mysql_error());
while($row=mysql_fetch_array($queryres)){
	
	$stamp1_id=$row[0];
	$stamp2_id=$row[1];
	$stamp3_id=$row[2];
	$stamp4_id=$row[3];
	$stamp5_id=$row[4];
	$stamp6_id=$row[5];
}
$query="select stampdescstatus
 from manifest  where manifest_auto='$Manifest_Auto'";
 
 //echo $query;
 $queryres=mysql_query($query,$connection) or die(mysql_error());
while($row=mysql_fetch_array($queryres)){
	
	$stampdescstatus=$row[0];
	
}
ECHO "<html>";
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<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">

<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>

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


function changestamp(str){
	if(str==1){document.getElementById('stamp_1').innerHTML=document.Stamp.stamp1.value;}
	if(str==2){document.getElementById('stamp_2').innerHTML=document.Stamp.stamp2.value;}
	if(str==3){document.getElementById('stamp_3').innerHTML=document.Stamp.stamp3.value;}
	if(str==4){document.getElementById('stamp_4').innerHTML=document.Stamp.stamp4.value;}
	if(str==5){document.getElementById('stamp_5').innerHTML=document.Stamp.stamp5.value;}
	if(str==6){document.getElementById('stamp_6').innerHTML=document.Stamp.stamp6.value;}
	//alert(str);
}
function openstamp(str){
	win = window.open('List_stamp.php?str='+str, 'Form_ManifestsSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=400,top=100');		
	win.creator = self;
	win.focus();
}
function addstampvalue(){
	x=document.Stamp;
	var Manifest_Auto=x.Manifest_Auto.value;
	
		opener.document.Manifest.stamp1.value=x.stamp1.value;
		opener.document.Manifest.stamp2.value=x.stamp2.value;
		opener.document.Manifest.stamp3.value=x.stamp3.value;
		opener.document.Manifest.stamp4.value=x.stamp4.value;
		opener.document.Manifest.stamp5.value=x.stamp5.value;
		opener.document.Manifest.stamp6.value=x.stamp6.value;
	
	if(Manifest_Auto!='')
	{
		//alert('not');

	document.Stamp.action='Form_Manifests_Action.php?Manifest_Auto='+Manifest_Auto+'&mode=updatestamp';
	document.Stamp.submit();

	x.mode.value='updatestamp';

	 //window.close();
	}
	else {
	
		
		document.Stamp.action='Form_Manifests_Action.php?Manifest_Auto='+Manifest_Auto;
	document.Stamp.submit();

	x.mode.value='insertstamp';
//alert('d');
	 //window.close();
	}
}


function addmanieststamp(){
	x=document.Stamp;
	var Manifest_Auto=x.Manifest_Auto.value;
	document.Stamp.action='Form_Manifests_Action.php?Manifest_Auto='+Manifest_Auto+'&mode=updatemanifeststamp';
	document.Stamp.submit();

	x.mode.value='updatemanifeststamp';
}

</script>
HERE;
echo "</head>
<body>
<form name='Stamp' method='post' action=''>
<input type='hidden' name='Manifest_Auto' value='$Manifest_Auto'>
<input type='hidden' name='mode' value='$mode'>
<input type='hidden' name='selectstamp' value='$selectstamp'>
";





echo "<table border=0 width=100%>
<col width=100px>
<col width=200px>
<col width=100px>
<col width=200px>
<col width=100px>
<col width=200px>




<tr colspan=6>
<td colspan=6><b>Stamp</b></td></tr>

<tr ><td colspan=6><input type='checkbox' name='stampdescstatus' id='stampdescstatus' "; if ($stampdescstatus==1)echo "checked";

echo ">with stamp status</td></tr>
<tr>


</tr>
<tr>
<td align=right ><div id='stamp_1'>$stamp1_id</div></td><td>
";



$query="select code,description from stamp ";
//where code='$stamp1_id'";
//echo $query;
$queryres=mysql_query($query,$connection) or die(mysql_error());
echo "<select name=stamp1 style='width:200px' onChange='changestamp(1)'>";
echo "<option value=''></option>";
while($row=mysql_fetch_array($queryres)){
	echo "<option value=$row[0]";
	if ($row[0]==$stamp1_id){
		echo " selected ";	}
		echo ">$row[0] &nbsp;&nbsp;&nbsp;&nbsp; $row[1]</option>";
		
}
echo "</select>";
//echo "&#9679;<input type='text' id='stamp1' ".$KeyDown."  name='stamp1'  
//value='".htmlspecialchars($stamp1_id, ENT_QUOTES)."'    style='width:100;border:none;'/>";
//echo "<input type='image' src='img/btnopen.jpg' title='Select Area ' width='15' height='17 border='0' onmouseover='style.cursor=hand' onclick='openstamp(1); return false' style='cursor: pointer;'>";
//echo "<input type=text name=stamp1 value='$stamp1_id'>";
echo "</td>

";
//<tr>";
//echo "<tr>
echo "


<td  align=right><div id='stamp_2'>$stamp2_id</div></td>
<td>";
//echo "&#9679;<input type='text' id='stamp2' ".$KeyDown."  name='stamp2'  
//value='".htmlspecialchars($stamp2_id, ENT_QUOTES)."'    style='width:100;border:none;'/>";
$query="select code,description from stamp ";
//where code='$stamp2_id'";
//echo $query;
$queryres=mysql_query($query,$connection) or die(mysql_error());
echo "<select name=stamp2 style='width:200px' onChange='changestamp(2)'>";
echo "<option value=''></option>";
while($row=mysql_fetch_array($queryres)){
	echo "<option value=$row[0]";
	if ($row[0]==$stamp2_id){
		echo " selected ";	}
		echo ">$row[0] &nbsp;&nbsp;&nbsp;&nbsp; $row[1]</option>";
		
}
echo "</select>";
//echo "<input type=text name=stamp2 value='$stamp2_id'>";
echo "</td>";
//</tr>";

//echo "<tr>
echo "
<td  align=right><div id='stamp_3'>$stamp3_id</div></td>
<td>";





//echo "&#9679;<input type='text' id='stamp3' ".$KeyDown."  name='stamp3'  
//value='".htmlspecialchars($stamp3_id, ENT_QUOTES)."'    style='width:100;border:none;'/>";
$query="select code,description from stamp ";
//where code='$stamp3_id'";
//echo $query;
$queryres=mysql_query($query,$connection) or die(mysql_error());
echo "<select name=stamp3 style='width:200px' onChange='changestamp(3)'>";
echo "<option value=''></option>";
while($row=mysql_fetch_array($queryres)){
	echo "<option value=$row[0]";
	if ($row[0]==$stamp3_id){
		echo " selected ";	}
		echo ">$row[0] &nbsp;&nbsp;&nbsp;&nbsp; $row[1]</option>";
		
}
echo "</select>";
//echo "<input type=text name=stamp3 value='$stamp3_id'>";
echo "</td></tr>";
//</tr>";

//echo "
//<tr>
echo "<tr><td  align=right><div id='stamp_4'>$stamp4_id</div></td>
<td>";

//echo "<input type=text name=stamp4 value='$stamp4_id'>";
//echo "&#9679;<input type='text' id='stamp4' ".$KeyDown."  name='stamp4'  
//value='".htmlspecialchars($stamp4_id, ENT_QUOTES)."'    style='width:100;border:none;'/>";
$query="select code,description from stamp ";
//where code='$stamp4_id'";
//echo $query;
$queryres=mysql_query($query,$connection) or die(mysql_error());
echo "<select name=stamp4 style='width:200px' onChange='changestamp(4)'>";
echo "<option value=''></option>";
while($row=mysql_fetch_array($queryres)){
	echo "<option value=$row[0]";
	if ($row[0]==$stamp4_id){
		echo " selected ";	}
		echo ">$row[0] &nbsp;&nbsp;&nbsp;&nbsp; $row[1]</option>";
		
}
echo "</select>";


echo "</td>


";
//</tr>";
//echo "<tr>
echo "
<td  align=right><div id='stamp_5'>$stamp5_id</div></td>

<td>";

//echo "&#9679;<input type='text' id='stamp5' ".$KeyDown."  name='stamp5'  
//value='".htmlspecialchars($stamp5_id, ENT_QUOTES)."'    style='width:100;border:none;'/>";

//echo "<input type=text name=stamp5 value='$stamp5_id'>";
$query="select code,description from stamp ";
//where code='$stamp5_id'";
//echo $query;
$queryres=mysql_query($query,$connection) or die(mysql_error());
echo "<select name=stamp5 style='width:200px' onChange='changestamp(5)'>";
echo "<option value=''></option>";
while($row=mysql_fetch_array($queryres)){
	echo "<option value=$row[0]";
	if ($row[0]==$stamp5_id){
		echo " selected ";	}
		echo ">$row[0] &nbsp;&nbsp;&nbsp;&nbsp; $row[1]</option>";
		
}
echo "</select>";
echo "</td>";
//</tr>";

//echo "<tr>
echo "

<td  align=right><div id='stamp_6'>$stamp6_id</div></td>
<td>";
//echo "&#9679;<input type='text' id='stamp6' ".$KeyDown."  name='stamp6'  
///value='".htmlspecialchars($stamp6_id, ENT_QUOTES)."'    style='width:100;border:none;'/>";

$query="select code,description from stamp ";
//where code='$stamp6_id'";
//echo $query;
$queryres=mysql_query($query,$connection) or die(mysql_error());
echo "<select name=stamp6 style='width:200px' onChange='changestamp(6)'>";
echo "<option value=''></option>";
while($row=mysql_fetch_array($queryres)){
	echo "<option value=$row[0]";
	if ($row[0]==$stamp6_id){
		echo " selected ";	}
		echo ">$row[0] &nbsp;&nbsp;&nbsp;&nbsp; $row[1]</option>";
		
}
echo "</select>";
//echo "<input type=text name=stamp6 value='$stamp6_id'>";
echo "</td>";
echo "</tr>";
echo "<tr height=5></tr><tr><td>

<button type='button' id='btnPost' name='btnPost' onclick='addstampvalue(); return false;' title='Save Changes' $Insmode><span><span>select</span></span></button>
<button type='button' id='btnPost' name='btnPost' onclick='addmanieststamp(); return false;' title='Save Changes' $Insmode><span><span>save</span></span></button>
									
</td><tr>";

if($selectstamp==1){

$query="select description
 from manifest inner join stamp on stamp.code=manifest.stamp1_id where manifest_auto='$Manifest_Auto'";
 
 //echo $query;
 $i=0;

 $queryres=mysql_query($query,$connection) or die(mysql_error());
while($row=mysql_fetch_array($queryres)){
	 $j=$i+1;
if ($i%2==0)	echo "<tr>";
echo "<td colspan=3 >";
echo "<input type='text' size='64' name=stampdesc$j  value='".htmlspecialchars($row[0], ENT_QUOTES)."'> ";
//	echo " value='".$row[0].'">';
//echo $row[0];

	echo "</td>";


if ($i%2!=0) echo "</tr>";
$i++;
}
//if ($i%2==0){
	//echo "</tr>";
//}

$query="select description
 from manifest inner join stamp on stamp.code=manifest.stamp2_id where manifest_auto='$Manifest_Auto'";
 
 //echo $query;
 //$i=0;
 $queryres=mysql_query($query,$connection) or die(mysql_error());
while($row=mysql_fetch_array($queryres)){
	 $j=$i+1;
if ($i%2==0)	echo "<tr>";
echo "<td colspan=3>";
	echo "<input type='text' size='64' name='stampdesc$j'  value='".htmlspecialchars($row[0], ENT_QUOTES)."'> ";
	echo "</td>";


if ($i%2!=0) echo "</tr>";
$i++;
}
//if ($i%2==0){
	//echo "</tr>";
//}
$query="select description
 from manifest inner join stamp on stamp.code=manifest.stamp3_id where manifest_auto='$Manifest_Auto'";
 
 //echo $query;
 //$i=0;
 
 $queryres=mysql_query($query,$connection) or die(mysql_error());
while($row=mysql_fetch_array($queryres)){
	
	 $j=$i+1;
if ($i%2==0)	echo "<tr>";
echo "<td colspan=3>";
	echo "<input type='text' size='64' name='stampdesc$j'  value='".htmlspecialchars($row[0], ENT_QUOTES)."'  > ";
	echo "</td>";


if ($i%2!=0) echo "</tr>";
$i++;
}
//if ($i%2==0){
	//echo "</tr>";
//}
$query="select description
 from manifest inner join stamp on stamp.code=manifest.stamp4_id where manifest_auto='$Manifest_Auto'";
 
 //echo $query;
 //$i=0;
 $queryres=mysql_query($query,$connection) or die(mysql_error());
while($row=mysql_fetch_array($queryres)){
	 $j=$i+1;
if ($i%2==0)	echo "<tr>";
echo "<td colspan=3>";
	echo "<input type='text' size='64' name='stampdesc$j'  value='".htmlspecialchars($row[0], ENT_QUOTES)."' > ";
	echo "</td>";


if ($i%2!=0) echo "</tr>";
$i++;
}
//if ($i%2==0){
	//echo "</tr>";
//}
$query="select description
 from manifest inner join stamp on stamp.code=manifest.stamp5_id where manifest_auto='$Manifest_Auto'";
 
 //echo $query;
 //$i=0;
 $queryres=mysql_query($query,$connection) or die(mysql_error());
while($row=mysql_fetch_array($queryres)){
	 $j=$i+1;
if ($i%2==0)	echo "<tr>";
echo "<td colspan=3>";
	echo "<input type='text' size='64' name='stampdesc$j'  value='".htmlspecialchars($row[0], ENT_QUOTES)."'  > ";
	echo "</td>";


if ($i%2!=0) echo "</tr>";
$i++;
}
//if ($i%2==0){
	//echo "</tr>";
//}

}
else{

$manifeststamp="
SELECT stampdesc1, stampdesc2, stampdesc3, stampdesc4, stampdesc5, stampdesc6, stampdesc7, stampdesc8, stampdesc9, stampdesc10, stampdesc11,
stampdesc12, stampdesc13, stampdesc14, stampdesc15, stampdesc16, stampdesc17, stampdesc18, stampdesc19, stampdesc20, stampdesc21,
stampdesc22 FROM MANIFESTSTAMP WHERE manifest_manifestauto='$Manifest_Auto'";
//echo $manifeststamp;
$j=1;
 $queryres=mysql_query($manifeststamp,$connection) or die(mysql_error());
if($row=mysql_fetch_array($queryres)){
	$stampdesc1=$row[0];
	$stampdesc2=$row[1];
	$stampdesc3=$row[2];
	$stampdesc4=$row[3];
	$stampdesc5=$row[4];
	$stampdesc6=$row[5];
	$stampdesc7=$row[6];
	$stampdesc8=$row[7];
	$stampdesc9=$row[8];
	$stampdesc10=$row[9];
	$stampdesc11=$row[10];
	$stampdesc12=$row[11];
	$stampdesc13=$row[12];
	$stampdesc14=$row[13];
	$stampdesc15=$row[14];
	$stampdesc16=$row[15];
	$stampdesc17=$row[16];
	$stampdesc18=$row[17];
	$stampdesc19=$row[18];
	$stampdesc20=$row[19];
	$stampdesc21=$row[20];
	$stampdesc22=$row[21];
	
	


echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc1'  value='".htmlspecialchars($stampdesc1, ENT_QUOTES)."'  > </td>
<td colspan=3><input type='text' size='64' name='stampdesc2'  value='".htmlspecialchars($stampdesc2, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc3'  value='".htmlspecialchars($stampdesc3, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc4'  value='".htmlspecialchars($stampdesc4, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc5'  value='".htmlspecialchars($stampdesc5, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc6'  value='".htmlspecialchars($stampdesc6, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc7'  value='".htmlspecialchars($stampdesc7, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc8'  value='".htmlspecialchars($stampdesc8, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc9'  value='".htmlspecialchars($stampdesc9, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc10'  value='".htmlspecialchars($stampdesc10, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc11'  value='".htmlspecialchars($stampdesc11, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc12'  value='".htmlspecialchars($stampdesc12, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc13'  value='".htmlspecialchars($stampdesc13, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc14'  value='".htmlspecialchars($stampdesc14, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc15'  value='".htmlspecialchars($stampdesc15, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc16'  value='".htmlspecialchars($stampdesc16, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc17'  value='".htmlspecialchars($stampdesc17, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc18'  value='".htmlspecialchars($stampdesc18, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc19'  value='".htmlspecialchars($stampdesc19, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc20'  value='".htmlspecialchars($stampdesc20, ENT_QUOTES)."'  ></td>
</tr>";
echo "<tr>
<td colspan=3><input type='text' size='64' name='stampdesc21'  value='".htmlspecialchars($stampdesc21, ENT_QUOTES)."'  ></td>
<td colspan=3><input type='text' size='64' name='stampdesc22'  value='".htmlspecialchars($stampdesc22, ENT_QUOTES)."'  ></td>
</tr>";

}
}

echo "</form>";
echo "</body>";

?>