Server : LiteSpeed System : Linux us-phx-web1202.main-hosting.eu 4.18.0-553.84.1.lve.el8.x86_64 #1 SMP Tue Nov 25 18:33:03 UTC 2025 x86_64 User : u615232177 ( 615232177) PHP Version : 8.1.33 Disable Function : NONE Directory : /home/u615232177/public_html/admin5352/ |
<?php session_start();
$page_name = basename($_SERVER['PHP_SELF']);
include("headerstrict.php"); ?>
<?php $cat_id="";
if (isset($_GET['search'])) {
$from = mysqli_real_escape_string($con,$_GET['from']);
$to = mysqli_real_escape_string($con,$_GET['to']);
$status = mysqli_real_escape_string($con,$_GET['status']);
}
else{
echo "<meta http-equiv=\"refresh\" content=\"0; url=orders.php\">";
exit();
}
?>
<title><?php echo $company_name; ?>, Admin, Orders</title>
<style>
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
font-size:14px;
}
th, td {
text-align: left;
padding: 8px 28px 8px 28px;
}
tr:nth-child(even){background-color: #f2f2f2}
</style>
<!-- ======= Breadcrumbs ======= -->
<section id="breadcrumbs" class="breadcrumbs">
<div class="container"> </div>
</section>
<!-- End Breadcrumbs -->
<!-- ======= Contact Section ======= -->
<section id="contact" class="contact inner-page">
<div class="container" data-aos="fade-up">
<div class="section-title">
<h2>Search Orders</h2>
<p><a style='color:cornflowerblue;' href="orders.php">All</a></p>
<p><a style='color:crimson;' href="orders_pending.php">Pending</a></p>
<p><a style='color:forestgreen;' href="orders_completed.php">Completed</a></p>
</div>
<div class='row'>
<div class='col-md-2'></div>
<div class='col-md-8'>
<h3>Search</h3>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="get" class="php-email-form1" enctype='multipart/form-data'>
<div class="form-row">
<div class="form-group col-md-4">
<label for="from">From</label>
<input type="date" id='from' name="from" class="form-control" required />
</div>
<div class="form-group col-md-4">
<label for="to">To</label>
<input type="date" id='to' name="to" class="form-control" required />
</div>
<div class="form-group col-md-4">
<label for="status">Status (optional)</label>
<select name="status" id="status" class="form-control">
<option value="">Filter by Status</option>
<option value="Pending">Pending</option>
<option value="Completed">Completed</option>
</select>
</div>
</div>
<div class="text-center">
<button type="submit" name='search'>Search</button>
</div>
</form>
</div>
<div class='col-md-12'>
<br><br>
<?php
if (isset($_GET['search'])) {
if($status == "Pending"){
$in_query = "status='Pending' AND ";
}
if($status == "Completed"){
$in_query = "status ='Completed' AND ";
}
if($status == ""){
$in_query = "";
}
$sql = "SELECT COUNT(id) FROM my_orders WHERE $in_query nice_date BETWEEN '$from' AND '$to' ORDER BY id DESC";
}
$query = mysqli_query($con, $sql);
$row = mysqli_fetch_row($query);
//here we have the total row count
$rows = $row[0];
//number of results we want per page
$page_rows = 300;
//tells us the page number of our last page
$last = ceil($rows/$page_rows);
//this makes sure last cannot be less than 1
if($last < 1){$last = 1;}
//establish the page num variable
$pagenum = 1;
//Get pageum from $GET if it is present, else its 1
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
//below 1 or more than last page
if($pagenum < 1){
$pagenum = 1;
}else if ($pagenum > $last) {
$pagenum = $last;
}
//this sets the range of rows to query for the chosen pagenum
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//grabs one page worth of rows
if (isset($_GET['search'])) {
if($status == "Pending"){
$in_query = "status='Pending' AND ";
}
if($status == "Completed"){
$in_query = "status ='Completed' AND ";
}
if($status == ""){
$in_query = "";
}
$sql = "SELECT * FROM my_orders WHERE $in_query nice_date BETWEEN '$from' AND '$to' ORDER BY id DESC $limit";
}
$query = mysqli_query($con, $sql);
//this shows the user what page they on and total number
$textline1 = "Messages $rows";
$textline2 = "Page $pagenum of $last";
//establish the pagination controls
$paginationCtrls = "";
//if there is more than one page worth of results
if($last != 1){
if($pagenum > 1){
$previous = $pagenum - 1;
//$paginationCtrls .='<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Previous</a>  ';
//$paginationCtrls .='<li><a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Prev</a></li>';
$paginationCtrls .= "<a href=\"$_SERVER[PHP_SELF]?pn=$previous&from=$from&to=$to&status=$status&search=1\"> Prev </a>";
//render clickable links to the left of target page number
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
//$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'"></a> ';
//$paginationCtrls .= '<li><a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a></li>';
$paginationCtrls .= "<a href=\"$_SERVER[PHP_SELF]?pn=$i&from=$from&to=$to&status=$status&search=1\"> $i </a>";
}
}
}
//render target number bt not link
//$paginationCtrls .= ''.$pagenum.' ';
$paginationCtrls .= '<a href="#">'.$pagenum.'</a>';
//render clickable number links to the right of target number
for($i = $pagenum+1; $i <= $last; $i++){
//$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> ';
//$paginationCtrls .= '<li><a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a></li>';
$paginationCtrls .= "<a href=\"$_SERVER[PHP_SELF]?pn=$i&from=$from&to=$to&status=$status&search=1\"> $i </a>";
if($i >= $pagenum+4){
break;
}
}
//this does the same as above, only checking if we are on the last page
if($pagenum != $last) {
$next = $pagenum + 1;
//$paginationCtrls .= '<li><a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a></li>';
$paginationCtrls .= "<a href=\"$_SERVER[PHP_SELF]?pn=$next&from=$from&to=$to&status=$status&search=1\"> Next </a>";
}
}
if (isset($_GET['search'])) {
$from_formatted1=date_create("$from");
$from_formatted = date_format($from_formatted1,"dS M Y");
$to_formatted1=date_create("$to");
$to_formatted = date_format($to_formatted1,"dS M Y");
echo"<div class='col-md-12'>
<h3>Showing Results from $from_formatted to $to_formatted</h3>"; ?>
<?php
//stats for total results
$grand_t_amount=0;
$stmt_total = $con -> prepare("SELECT total FROM my_orders WHERE $in_query nice_date BETWEEN '$from' AND '$to' ORDER BY id DESC");
$stmt_total -> execute();
$stmt_total -> store_result();
$stmt_total -> bind_result($t_amount);
$numrows_total = $stmt_total -> num_rows();
if($numrows_total > 0){
while ($stmt_total -> fetch()) {
$grand_t_amount += $t_amount;
}
}
echo"
<h4>Total Orders: $numrows_total <br>Total Amount: $currency"; echo number_format((float)$grand_t_amount, 2, '.', ','); echo"</h4>
"; ?>
<?php echo "<a class='btn btn-primary' href='orders.php'>Show All Results</a> <br><br>
</div>
";
}
if(mysqli_num_rows($query) > 0){
$count=0; $grand_total=0;
echo"
<div style='overflow-x:auto;'>
<table>
<tr>
<th>No</th>
<th>Order ID</th>
<th>Date</th>
<th>Status</th>
<th>Customer</th>
<th>Items</th>
<th>Amount</th>
<th>Payment Method</th>
<th>View Details</th>
</tr>
";
while ($row_back_deals = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$order_id = $row_back_deals['order_id'];
$order_status = $row_back_deals['status'];
$user_id = $row_back_deals['user_id'];
$total = $row_back_deals['total'];
$precise_date = $row_back_deals['nice_date'];
$payment_method = $row_back_deals['payment_method'];
$precise_date_formatted1=date_create("$precise_date");
$precise_date_formatted = date_format($precise_date_formatted1,"D,dS M, Y g:ia");
$count++;
$grand_total += $total;
//get user details
$stmt = $con -> prepare('SELECT * FROM users WHERE user_id=?');
$stmt -> bind_param('s',$user_id);
$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($id,$user_id,$first_name,$last_name,$email,$password,$phone,$address,$date_signed_up);
$numrows = $stmt -> num_rows();
if($numrows > 0){
while ($stmt -> fetch()) { }
}
if($order_status=="Pending"){$color_s="crimson";}
if($order_status=="Completed"){$color_s="forestgreen";}
//get cart details details
$stmt_cart = $con -> prepare('SELECT id FROM cart_details WHERE order_id=?');
$stmt_cart -> bind_param('s',$order_id);
$stmt_cart -> execute();
$stmt_cart -> store_result();
$stmt_cart -> bind_result($cart_id);
$numrows_cart = $stmt_cart -> num_rows();
if($numrows_cart > 0){
while ($stmt_cart -> fetch()) { }
}
echo"
<tr>
<td>$count</td>
<td>$order_id</td>
<td>$precise_date_formatted</td>
<td style='color:$color_s;'>$order_status</td>
<td>$first_name $last_name</td>
<td>";echo number_format((float)$numrows_cart, 0, '.', ',');echo"</td>
<td>$currency";echo number_format((float)$total, 2, '.', ',');echo"</td>
<td>$payment_method</td>
<td><a href='order_details.php?order_id=$order_id'>View Details</a></td>
</tr>
";
}
echo"
<tr>
<td>Total</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td style='font-weight:900;color:cornflowerblue;'>$currency";echo number_format((float)$grand_total, 2, '.', ',');echo"</td>
<td></td>
<td></td>
</tr>
</table>
</div>
";
}
else{echo"<div class='col-md-12'> <br><br> Nothing found</div>";}
?>
</div>
</div><!-- end row -->
<div class='double_line'></div>
<div class="row">
<div class="col-md-12"> <br><br>
<ul class="pagination clearfix">
<?php
echo"$paginationCtrls<br/><br/>";
echo "<div class='text_line'>$textline2</div>";
?>
</ul>
</div>
</div>
</div>
</section><!-- End Contact Section -->
<?php include("footer.php"); ?>