<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include ("../navigation/header.php");
$page_name = "Orders-edit";
include ("../navigation/access.php");
?>

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
</head>
<?php
if ($permission_num==1) {
	include ("../navigation/orders_sidebar.php");

$page = $_GET['page'];
	
if ($page=='orders') {
$reference='edit_order.php?edit=&e=0&order_reference=';	
$page_name='Edit order.';
$table_name = $_SESSION['db_prefix']."_orders";
$ordersQuery = "SELECT order_no, order_reference, cust_id, order_date FROM $table_name WHERE delivered IS NULL OR delivered = 'part' ORDER BY order_no ASC";
$ordersResult = execsql($ordersQuery);
$ordersNum = mysql_num_rows($ordersResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $ordersNum) {
		$cust_id = mysql_result($ordersResult, $w, 'cust_id');
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$cust_name = mysql_result($customer_result, 0, "comp_name"); 
		
		
		$arrId4[$w] = mysql_result($ordersResult, $w, 'order_reference');
		$arrName4[$w] = mysql_result($ordersResult, $w, 'order_no').'&nbsp;&nbsp;'.date("d-m-Y", strtotime(mysql_result($ordersResult, $w, 'order_date'))).'&nbsp;&nbsp;'.$cust_name;
		$w++;
	}
}

if ($page=='cancel') {
$reference='cancel_order.php?cancel=&order_reference=';	
$page_name='Cancel order.';
$table_name = $_SESSION['db_prefix']."_orders";
$ordersQuery = "SELECT order_no, order_reference, cust_id, order_date FROM $table_name WHERE ordered = 'yes' AND ( delivered IS NULL OR delivered = 'part' ) ORDER BY order_no ASC";
$ordersResult = execsql($ordersQuery);
$ordersNum = mysql_num_rows($ordersResult);
	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $ordersNum) {
		$cust_id = mysql_result($ordersResult, $w, 'cust_id');
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT comp_name FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);	
		$cust_name = mysql_result($customer_result, 0, "comp_name"); 
		
		
		$arrId4[$w] = mysql_result($ordersResult, $w, 'order_reference');
		$arrName4[$w] = mysql_result($ordersResult, $w, 'order_no').'&nbsp;&nbsp;'.date("d-m-Y", strtotime(mysql_result($ordersResult, $w, 'order_date'))).'&nbsp;&nbsp;'.$cust_name;
		$w++;
	}
}

if ($page=='accounts') {
$reference='account_details_edit.php?cust_id=';
$page_name='Account details';
$branch = '';
$table_name = $_SESSION['db_prefix']."_customer";
$account_query = "SELECT comp_name, cust_id FROM $table_name ORDER BY comp_name ASC";
$account_result = mySQL_query($account_query);
$account_num = mysql_num_rows($account_result);
$account_id = mysql_result($account_result, 0, "cust_id"); 	

	$w = 0;
	$arrId4 = array ();
	$arrName4 = array ();
	while ($w < $account_num) {
		$arrId4[$w] = mysql_result($account_result, $w, 'cust_id');
		$arrName4[$w] = mysql_result($account_result, $w, 'comp_name');
		$w++;
	}



}

?>
<body>

<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>
       <br />
<br /><br />
<br />

<div class="page_middle_frame"><br />
  <label class="label_std" style="font-size:16px;"><?php echo $page_name?></label>
  <br />
  <br />
  <form action="" method="get">
  <div class="wizard_frame">
    <label class="label_std"> Select  to <?php echo $page_name?> : &nbsp;&nbsp;</label>
    <select name="job_no_select" autofocus="autofocus" class="selectbox400"  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'); ?>

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