<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}

if($begin == ""){
        $begin=0;
        $num=1;
        $numBegin=1;
}

if(isset($_GET["txtSearch"]) and $_GET["txtSearch"]!=""){
	$txtSearch = $_GET["txtSearch"];
	$cmbSearchType = $_GET["cmbSearchType"];
}else if(isset($_POST["txtSearch"]) and $_POST["txtSearch"]!=""){
	$txtSearch = $_POST["txtSearch"];
	$cmbSearchType = $_POST["cmbSearchType"];
}


if(isset($_GET["msg"]) and $_GET["msg"]!=""){
	$msg = $_GET["msg"];
	switch($msg){
		case "deleted": $message = "Feedback deleted successfully!";break;
		default:
			;
	} // switch
	
}

$qryopt="";
if($txtSearch != ""){
   if($cmbSearchType == "username"){
   		$qryopt .= "  AND  u.user_name like '" . addslashes($txtSearch) . "%'";
   }else if($cmbSearchType == "dateordered"){
   		$dt = $txtSearch;
		$arrdt = explode("/",$dt) ;
		$day = $arrdt[1];
		$month = $arrdt[0];
		$year = $arrdt[2];
		$dt = $year."-". $month ."-".$day;
		$qryopt .= "  AND  o.order_date like '" . addslashes($dt) . "%'";
   }else if($cmbSearchType == "email"){
            $qryopt .= "  AND  u.email like '" . addslashes($txtSearch) . "%'";
   }
}

$sql=" SELECT o.*, u.user_name, u.email, sum(od.product_price * od.product_quantity) as total FROM ".$tableprefix."orders o 
		INNER JOIN ".$tableprefix."users u ON o.user_id = u.user_id 
		INNER JOIN ".$tableprefix."order_details od ON o.order_id = od.order_id 
		WHERE od.item_status = '2'
		" . $qryopt . " GROUP BY od.order_id ORDER BY o.order_date DESC    ";
//echo "<br>".$sql; 
$sess_back= $_SERVER["PHP_SELF"] . "?begin=" . $begin . "&num=" . $num . "&numBegin=" . $numBegin . "&cmbSearchType=" . $cmbSearchType . "&txtSearch=" . $txtSearch;
$_SESSION["gbackurl"] = $sess_back;

$totalrows = mysql_num_rows(mysql_query($sql));

$navigate = pageBrowser($totalrows,10,10,"&cmbSearchType=$cmbSearchType&txtSearch=$txtSearch",$_GET[numBegin],$_GET[start],$_GET[begin],$_GET[num]);
$sql = $sql.$navigate[0];
$rs = mysql_query($sql);

include "../includes/htmltop.php";
?>

<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmFeedbacks.submit();
}
function changeStatus(id){
	var frm = document.frmFeedbacks;
	if(Confirm("Are you sure you want to change the status of this record?")){
		document.frmFeedbacks.submit();
	}
}
</script>
<body>
<table width="804" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center" bgcolor="#C15628">
			<table width="802" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td bgcolor="#000000">
						<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
            				<tr>
              					<td>
									<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="maintext">
                  						<tr>
                    						<td>
												<?php include "../includes/topheader_admin.php";?>
												<table width="100%"  border="0" cellspacing="0" cellpadding="0">
													<tr>
														<td valign="top" bgcolor="#FFFFFF">
															<?php 
																include "../includes/admintopmenu.php"; 
																include "../includes/dotline.php";
																//include "includes/centermain.php"; 
															?>
																<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																<tr>
																	<td style="width:1px" class="siteborder"><img src="../images/spacer.gif"></td>
																	<td width="98%">
																		<table width="100%"  border="0" cellspacing="0" cellpadding="0">
																			<tr>
																				<td align="center" valign="top">
																					<p>&nbsp;</p>
																						                                   
																						<table width="100%">
																							<tr>
																								<td>
																									<!-- ***************************************************** -->
																									<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" name="frmFeedbacks">
																										<table width="98%"  border="0" cellpadding="0" cellspacing="0" class=listingborder align="center">
																											<tr>
																												<td class=listingtdbgcolor>
																													<table width="100%"  border="0" cellpadding="2" cellspacing="1" class="maintext">
																														<tr align="center" bgcolor="#FFFFFF"><td align="center" colspan="6" class="infomessage"><?php echo $message?></td></tr>
																														<tr bgcolor="#FFFFFF" valign="top">
																															<td align="right" colspan="6" valign="top" >
																																<table width="100%" border=0  >
																																	<tr>
                                                                                                                                                                                                                                                                            <td width="100%" align=right valign="baseline" class="">Search ::
																																			<select name="cmbSearchType" class="selectbox">
																																				<option value="username"  <?php if($cmbSearchType == "username" || $cmbSearchType == ""){ echo("selected"); } ?>>User Name</option>
																																				<option value="email"  <?php if($cmbSearchType == "email"){ echo("selected"); } ?>>Email</option>
																																				<option value="dateordered"  <?php if($cmbSearchType == "dateordered"){ echo("selected"); } ?>>Order Date(mm/dd/yyyy)</option>
																																			</select> &nbsp;
																																	   		<input type="text" name="txtSearch" size="20" maxlength="50" value="<? echo(htmlentities($txtSearch)); ?>"  onKeyPress="if(window.event.keyCode == '13'){ return false; }" class="textbox">
																																			&nbsp;
																																			<a href="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>&nbsp;
																																		</td>
																																	</tr>
																																</table>
																															
																															</td>
																														</tr>
																														<tr bgcolor="#FFFFFF"><td align="left" colspan="6"><?php echo("Listing $navigate[1] of $totalrows results."); ?></td></tr>
																														<tr class=listingband>
																															<td>#</td>
																															<td>Order #</td>
																															<td>User Name</td>
																															<td>Email</td>
																															<td>Date Added(mm/dd/yyyy)</td>
																															<td>Total Refundable</td>
																														</tr>
																														<?php
																														$i=$begin+1;
																														while($row = mysql_fetch_array($rs)){
																															$link = "<a href='vieworder.php?orderid=".$row["order_id"]."'>";
																															
																															
																														?>
																														<tr bgcolor="#FFFFFF"> 
																															<td><?php echo $i?></td>
																															<td><?php echo $link .htmlentities($row["order_id"])."</a>";?></td>
																															<td><?php echo $link .htmlentities($row["user_name"])."</a>";?></td>
																															<td><?php echo $link .htmlentities($row["email"])."</a>";?></td>
																															<td><?php echo $link .dateFormat($row["order_date"], "Y-m-d", "m/d/Y")."</a>";?></td>
																															<td><?php echo $link .htmlentities($row["total"])."</a>";?></td>
																														</tr>
																														<?php
																														$i++;
																														}
																														
																														
																														?>
																														<tr bgcolor="#FFFFFF"><td align="center" colspan="6"><?php echo($navigate[2]); ?></td></tr>
																														<tr bgcolor="#FFFFFF"><td align="center" colspan="6">&nbsp;</td></tr>
																														<tr class=listingband>
																															<td colspan="6">&nbsp;</td>
																														</tr>
																													</table>
																												</td>
																											</tr>
																										</table>
																									</form>
																									<!-- ***************************************************** -->
																								</td>
																							</tr>
																						</table>
																					
                             														
																				</td>
                                											</tr>
                           												</table>
                             										</td>
                              										<td style="width:1px" class="siteborder"><img src="../images/spacer.gif"></td>
                                  								</tr>
                     										</table>	
															<?php
																include "../includes/dotline.php";
																include "../includes/adminbottommenu.php";
																include "../includes/bottomband.php";
															?>
														</td>
                          							</tr>
                      							</table>
											</td>
                  						</tr>
									</table>
								</td>
 							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?php
include "../includes/footer.php";
?>
</body>
</html>




