<?php session_start();?>
<?php include("../includes/connection.php"); 
include("../includes/func.php");?>
<?php if (empty($_SESSION["admin"])) redirectS("index.php?e=1");

$pg = new paging;
$pg->setpages("SELECT count(*) FROM order_master");
if ($_GET["sort"]!='')
	$_SESSION["sortme"]=$_GET["sort"];

if ($_SESSION["sortme"]==1)
	$sort=" order by " . $_GET["sortby"] ." asc";
else
	$sort=" order by " .$_GET["sortby"] ." desc";
	
if ($_GET["sortby"]=='')
	$sort=" order by order_id  desc";


$sql="select O.* from order_master O";

//if ($_SESSION["sortme"]!='')
	$sql.=$sort;

$sql .=$pg->getlimit();

if ($_GET["what"]!='')
{
	$sql="select O.* from order_master O  where " . $_GET["criteria"] . " like '%" . $_GET["what"] . "%'  ".$sort." ".$sortorder;

	$_SESSION["errorMessage"]="Filtered Results";
}

$cmd = mysql_query($sql);

//Single Delete
if (!empty($_GET["delid"])) {
	mysql_query("delete from order_master where order_id=" . $_GET["delid"]);
	redirectS($_SERVER["HTTP_REFERER"]);
}

?>
<?php include("includes/header.php"); ?>
<??>

<table width="98%" height="100" border="0" align="center" cellpadding="5" cellspacing="5">
	<tr>
		<td height="50"><span style="font-weight: bold">Order Management </span>  [<a href="#search" class="BlackAri12B">Search</a>]
	      <hr size="1">  </td>
	</tr>
	
	<?php
	//if any records retrieved
	if (mysql_num_rows($cmd) != 0) {
	?>
	
	<tr>
		<td class="BlackAri12B" colspan=2><table width="100%" border="0" cellpadding="2" cellspacing="1" class="bgDarkGray">
            <tr class="bgLightGray">
                <td width="5%">&nbsp;</td>
				<td width="14%" class="BlackAri12B">Name</td>
                <td width="15%" class="BlackAri12B">Address</td>
				<td width="20%" class="BlackAri12B">Amount</td>
                <td width="40%" class="BlackAri12B">Serial</td>
				<td width="10%" class="BlackAri12B">Date</td>
				<td width="10%" class="BlackAri12B">Status</td>
				
			</tr>
			<?php getErr("6"); ?>
            <tr>
                <td colspan="8" height="10" class="bgWhite"></td>
            </tr>
			<?php
			//loop thru records and display category listing
			while ($rs = mysql_fetch_array($cmd)) {
				if ($bgclass == "bgExtraLightGray")
					$bgclass = "bgWhite";
				else
					$bgclass = "bgExtraLightGray";
					
				
			?>
			
            <tr class="<?php echo($bgclass); ?>">
                <td><table border="0" align="center">
                    <tr>
                                                <td><a href="order_master.php?delid=<?php echo($rs["order_id"]); ?>" onClick="return window.confirm('Are you sure you want to delete this record.');"><img 
						src="../images/icons/delete.gif" width="16" height="16" border="0" alt="Delete Record"></a></td>
					 </tr>
                </table>
				<?if ($rs["merchant_image"]=='') {?>
					 
					 <?}else {?>
				<img src=../files/<?=$rs["merchant_image"];?> >
				<?}?>
				</td>
				<td class="BlackAri12" valign=top width="20%"><small>&nbsp;<?php echo($rs["order_name"]); ?><br>
				<a href="mailto:<?php echo($rs["order_email"]); ?>"><font class=Blue><small><?php echo($rs["order_email"]); ?><small></font> </a>
				</td>
				<td class="BlackAri12" width="20%" valign=top>&nbsp;<small><?php echo($rs["order_address"]); ?> <br>
				<?php echo($rs["order_phone"]); ?> 
				</small></td>
				<td class="BlackAri12" valign=top width="20%"><small>&nbsp;
				$<?echo $rs["order_amount"];?>
				<td class="BlackAri12" valign=top width="30%"><small>&nbsp;
				<?echo $rs["order_serial"];?> <br> <a href="#" onClick="openWin('OrderDetails.php?order_id=<?php echo($rs["order_id"]); ?>', 'width=650, height=630');"><font class=Blue><b>Order Details<b></font> </a>
				<br> <a href="#" onClick="openWin('OrderPopup.php?order_id=<?php echo($rs["order_id"]); ?>', 'width=650, height=330');"><font class=Blue><b>Add Comments/status<b></font> </a>
				<td class="BlackAri12" valign=top width="20%"><small>&nbsp;
				<?echo $rs["order_date"];?> 
				</td>
				<td align="center"><small>
				<? if ($rs["order_status"]==0) echo "<font color=red>Pending</font>";?>
	<? if ($rs["order_status"]==3) echo "<font color=gray>Rejected</font>";?>
	<? if ($rs["order_status"]==2) echo "In Process";?>
	<? if ($rs["order_status"]==4) echo "<font color=green>Ready For Delivery</font>";?>
	<? if ($rs["order_status"]==5) echo "<font color=green>Delivered</font>";?></small></td>
				
            </tr>
			<?php } ?>
            <?if ($_GET["what"]=='')
				{?>
					<tr class="bgGray">
					   <td colspan="9" align="center" class="BlackAri12">
							<?php $pg->showPaging("", "&ps=".$_GET["ps"]."&sort=".$_GET["sort"]."&sortorder=".$_GET["sortorder"]."&criteria=".$_GET["criteria"]."&what=".$_GET["what"]); ?>
					  </td>
					</tr>
			<?}?>
        </table></td>
	</tr>
	
	<?php } else { ?>
	<tr>
		<td align="center" class="err">No Order found.</td>
	</tr>
	<?php } ?>
	<tr>
		<td height="50" align="center">&nbsp;</td>
	</tr>
	 <tr class="bgLightGray"><form name=search action="" method=get>
     <td width="100%" colspan=7 class="BlackAri12B">Search Orders <a name=search></a>:
	
<input type=text name=what size=15 value="<?=$_GET["what"];?>">
<select name=criteria>
<option value=order_name <?if ($_GET["criteria"]=='order_name') echo "selected";?>>Name</option>
<option value=order_email <?if ($_GET["criteria"]=='order_email') echo "selected";?>>Email </option>
<option value=order_address <?if ($_GET["criteria"]=='order_address') echo "selected";?>>Address </option>
<option value=order_phone <?if ($_GET["criteria"]=='order_phone') echo "selected";?>>Phone </option>
<option value=order_amount <?if ($_GET["criteria"]=='order_amount') echo "selected";?>>Amount </option>
<option value=order_comments <?if ($_GET["criteria"]=='order_comments') echo "selected";?>>User Comments </option>
<option value=order_admin_comments <?if ($_GET["criteria"]=='order_admin_comments') echo "selected";?>>Admin Comments </option>
<option value=order_serial <?if ($_GET["criteria"]=='order_serial') echo "selected";?>>Serial </option>
</select>
<input type=submit name=search value=Search>
</form>
</td></tr>


</table>



<?php include("includes/footer.php"); ?>
