<?php
session_start();

if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$item_code    = $_GET['item_code'];
$item_barcode = $_GET['item_barcode'];
$barcode      = $_GET['barcode'];

if($barcode == 1){
$query_update  = "update items set item_barcode = '$item_barcode'
                  where item_code = '$item_code'";
}
else
	if($barcode == 2){
		$query_update  = "update items set item_barcode2 = '$item_barcode'
                          where item_code = '$item_code'";
	}
else
	if($barcode == 3){
		$query_update  = "update items set item_barcode3 = '$item_barcode'
                          where item_code = '$item_code'";
	}
$result_update = mysql_query($query_update, $connection);

echo"<html>
<head>
<title>Generating Barcode</title>
<script>
function fillListCost(costcenter_code){
	if(document.getElementById('costcenter_'+costcenter_code).checked){
		document.getElementById('list_of_costcent').value = document.getElementById('list_of_costcent').value + costcenter_code + ',';
	}
	else{
		document.getElementById('list_of_costcent').value = document.getElementById('list_of_costcent').value.replace((costcenter_code+',') , '')
	}
}
function Generate(){
	var item_code        = document.getElementById('item_code').value;
	var item_barcode     = document.getElementById('item_barcode').value;
	var list_of_costcent = document.getElementById('list_of_costcent').value;
	var projects         = document.generatebarocdes.projects.value;
	var quantity_needed  = document.getElementById('quantity_needed').value;
	
	if(projects == ''){
		alert('Please choose a project!');
	}
	else
		if(list_of_costcent == ''){
			alert('Please choose one or more costcenters!');
		}
		else{
			//alert('You choose '+projects+' as a project');
			//alert('you choose '+list_of_costcent+'as costcenters');
			var str = 'GenerateBarcode1Proj_Cost_Report.php?actionmode=generatebarcode1&item_barcode='+item_barcode+'&projects='+projects+'&list_of_costcent='+list_of_costcent+'&quantity_needed='+quantity_needed+'&item_code=$item_code&barcode=$barcode';
		    document.location.href = str;
  
}
//window.print();
	
}
</script>
</head>
<body>
<form name='generatebarocdes'>
<input type='hidden' name='item_code' id='item_code' value='".$_GET['item_code']."' />
<input type='hidden' name='item_barcode' id='item_barcode' value='".$_GET['item_barcode']."' />
<div style='width: 100%; font-size: 16px; font-weight: bold' id='barcodes'>
<table width=750 style='border-collapse: collapse'>
<tr>
<th width=50% style='border: solid 1px #000000'>Size</th>
<th width=50% style='border: solid 1px #000000'>Color</th>
</tr>
<tr>
<td style='border: solid 1px #000000; font-size: 18px; font-weight: bold; vertical-align: top;'>";
$query_projects  = "select Project_Code, Project_Name 
                    from project";
$result_projects = mysql_query($query_projects, $connection);
while($row_projects = mysql_fetch_array($result_projects)){
	extract($row_projects);
	echo "<input type='radio' name='projects' id='projects' value='$Project_Code'> $Project_Name <br>";
}
echo"</td>
<td style='border: solid 1px #000000; font-size: 18px; font-weight: bold; vertical-align: top;'>";
$query_costcenter  = "select Costcent_code, Costcent_name
                      from costcent";
$result_costcenter = mysql_query($query_costcenter, $connection);
while($row_costcenter = mysql_fetch_array($result_costcenter)){
	extract($row_costcenter);
	echo "<input type='checkbox' name='costcenter' id='costcenter_$Costcent_code' value='$Costcent_code' onclick=\"fillListCost('$Costcent_code')\"> $Costcent_name <br>";
}
echo"</td>
<input type='hidden' name='list_of_costcent' id='list_of_costcent' value='' />
</tr>
</table>
<div style='height: 15px'></div>
<div>Quantity Needed: <input type='number' id='quantity_needed' name='quantity_needed' value=1></div>
<div style='height: 15px'></div>
<div style='text-align: center'><input type='button' onclick='Generate()' value='Print' /></div>
</div>

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