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


<?php
include('../include/session.php');
$today = date("Y-m-d");
?>

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
</head>
<?php

$page = $_GET['page'];
	
if ($page=='store item') {
$reference='store_item_edit.php?edit=&error=0&store_item_id=';	
$page_name='Edit store item.';
$line_name='store item';
$page_caption = 'Edit store item details.';
$table_name = $_SESSION['db_prefix']."_store_items";
$storeQuery = "SELECT subCategory, store_item_id, item_name FROM $table_name  ORDER BY item_name ASC";
$storeResult = execsql($storeQuery);
$storeNum = mysql_num_rows($storeResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $storeNum) {
		$subCategory = mysql_result($storeResult, $w, 'subCategory');
		if ($subCategory=='Old') {
			  $old = '(Old)';
		}
		else {
			$old= '';
		}
		$arrId4[$w] = mysql_result($storeResult, $w, 'store_item_id');
		$arrName4[$w] = mysql_result($storeResult, $w, 'item_name').'&nbsp;&nbsp;&nbsp;'.$old;
		$w++;
	}
}

if ($page=='supplier') {
$reference='supplier_details_edit.php?supplier_id=';
$page_name='Supplier details';
$line_name='supplier';
$page_caption = 'Edit supplier details.';
$table_name = $_SESSION['db_prefix']."_suppliers";
$supplier_query = "SELECT account_name, supplier_id FROM $table_name ORDER BY account_name ASC";
$supplier_result = mySQL_query($supplier_query);
$supplier_num = mysql_num_rows($supplier_result);
$supplier_id = mysql_result($supplier_result, 0, "supplier_id"); 	

	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $supplier_num) {
		$arrId4[$w] = mysql_result($supplier_result, $w, 'supplier_id');
		$arrName4[$w] = mysql_result($supplier_result, $w, 'account_name');
		$w++;
	}
}

if ($page=='purchase') {
$reference='edit_purchase_order.php?purchase_id=';
$page_name='Purchase order';
$line_name='purchase order';
$page_caption = 'Edit purchase order.';
$table_name = $_SESSION['db_prefix']."_purchase";
$purchase_query = "SELECT purchase_id, purchase_order, supplier_id FROM $table_name WHERE authorised = 'no' ORDER BY purchase_order DESC";
$purchase_result = mySQL_query($purchase_query);
$purchase_num = mysql_num_rows($purchase_result);
if ($purchase_num>0) {
$purchase_id = mysql_result($purchase_result, 0, "purchase_id"); 

}	

	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $purchase_num) {
		
		$supplier_id = mysql_result($purchase_result, $w, "supplier_id"); 		
		$table_name2 = $_SESSION['db_prefix']."_suppliers";
		$account_name_query = "SELECT account_name FROM $table_name2 WHERE supplier_id ='".$supplier_id."' ";
		$account_name_result = mySQL_query($account_name_query);
		$account_name_num = mysql_num_rows($account_name_result);	
		$account_name = mysql_result($account_name_result, 0, "account_name"); 
		
		
		$arrId4[$w] = mysql_result($purchase_result, $w, 'purchase_id');
		$arrName4[$w] = mysql_result($purchase_result, $w, 'purchase_order').' for '.$account_name;
		$w++;
	}
}

if ($page=='receive') {
$reference='edit_receive_note.php?receive_id=';
$page_name='Receive note';
$line_name='receive note';
$page_caption = 'Edit receive note.';
$receive_date = date('Y-m-d', strtotime(date("Y-m-d", strtotime($today))." -5 day"));
$table_name = $_SESSION['db_prefix']."_receive_store";
$receive_query = "SELECT receive_id, delivery_note, purchase_order, supplier_id FROM $table_name WHERE receive_date > '".$receive_date."' ORDER BY delivery_note DESC";
echo '<br>*****'.$receive_query;
$receive_result = mySQL_query($receive_query);
$receive_num = mysql_num_rows($receive_result);
if ($receive_num>0) {
$receive_id = mysql_result($receive_result, 0, "receive_id"); 
}	

	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $receive_num) {
		
		$supplier_id = mysql_result($receive_result, $w, "supplier_id"); 
			
		$table_name2 = $_SESSION['db_prefix']."_suppliers";
		$account_name_query = "SELECT account_name FROM $table_name2 WHERE supplier_id ='".$supplier_id."' GROUP BY supplier_id";
		
		$account_name_result = mySQL_query($account_name_query);
		$account_name_num = mysql_num_rows($account_name_result);	
		$account_name = mysql_result($account_name_result, 0, "account_name"); 
		
		
		$arrId4[$w] = mysql_result($receive_result, $w, 'receive_id');
		$arrName4[$w] = mysql_result($receive_result, $w, 'delivery_note').' for '.$account_name;
		$w++;
	}
}


?>
<body>
<?php
include ("../navigation/header.php");
$page_name = "Stores-edit";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");

?>
<div class="main_frame">
<table width="630" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="52" colspan="4" align="left" valign="top"><div class="page_head_frame">
        <table width="630" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="385"><label class="label_page_head">Select to edit</label></td>
            <td align="right">&nbsp;</td>
          </tr>
        </table>
      </div>
       
<div class="page_middle_frame"><br />
  <label class="label_std" style="font-size:16px;"><?php echo $page_caption?></label>
  <br />
  <br />
  <form action="" method="get">
  <div class="wizard_frame">
    <label class="label_std"> Select <?php echo $line_name?> to edit : &nbsp;&nbsp;</label>
    <select name="job_no_select" autofocus class="selectbox300" id="job_no_select" onchange="window.location.href= this.form.job_no_select.options[this.form.job_no_select.selectedIndex].value"> 
      <option value=" " selected="selected" >&nbsp;</option>
      <?php
    	for ($j = 0; $j < count($arrId4); $j++) {
			echo "<option value=".$reference.$arrId4[$j]."&edit=0>".$arrName4[$j]."</option>";	
		}
     ?>
    </select>
  </div>
  </form>
  <br />
  <br />
<br />
<br />
<br />

</div>
    </td>
    </tr>
    </table>
</div>

<?php include ('../navigation/side_bar.php'); ?>


<?php } else {
    $_SESSION['denied_return'] = "store/store_main.php";	
    include ("../navigation/store_sidebar.php");?>
    <?php include ('../navigation/side_bar.php'); ?>
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>
</html>
</body>