Location: PHPKode > projects > Simple PHP Shopping cart - asaancart > asaancart v-0.9/admin/list_all_orders.php
<?php
session_start();
/*
asaancart - easy shopping cart solution
---------------------------------------

Copyright 2009 Nasir Ahmad Khan
Email: hide@address.com

This file is part of asaancart - open source easy shopping cart solution.

asaancart is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

asaancart is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with asaancart.  If not, see <http://www.gnu.org/licenses/>.

*/

include("../config/config.php");
include("includes/chk_login_status_inc.php");

$smarty->assign('title','Manage Orders');


//delete

if($_GET['mode']=="delete"){
	$sql = "DELETE FROM orders WHERE order_number='".$_GET['order_number']."'";
	$results = mysql_query($sql);
	
	$sql = "DELETE FROM order_item WHERE order_number='".$_GET['order_number']."'";
	$results = mysql_query($sql);
	
	$smarty->assign('msg','Deleted Successfully');
}

if($_GET['mode']=="update"){
	$sql = "UPDATE orders SET order_status='".$_GET['status_value']."' WHERE order_number='".$_GET['order_number']."'";
	$results = mysql_query($sql);
	
	if($_GET['status_value']=="delivered" || $_GET['status_value']=="sent"){
		$sql = "SELECT * FROM order_item WHERE order_number='".$_GET['order_number']."'";
		$results = mysql_query($sql);
		
		while($row = mysql_fetch_array($results) )
		{
			$stock_ref = $row['stock_ref'];
			$product_code = $row['product_code'];
			$product_id = $row['product_id'];
			$product_quantity = $row['product_quantity'];
			
			if($stock_ref!="product_based_stock_level"){
			
				$sql_inner = "SELECT * FROM product_variants WHERE product_id = '".$product_id."' AND id = ".$stock_ref;
				$results_inner = mysql_query($sql_inner);
				while($row_inner = mysql_fetch_array($results_inner) )
				{	
					$qty_temp = $row_inner['qty'];
					
					$qty_temp = $qty_temp - $product_quantity;
					if($qty_temp<0){$qty_temp=0;}
					$sql_update = "UPDATE product_variants SET qty=$qty_temp WHERE product_id='".$product_id."' AND id=".$stock_ref;
					$results_update = mysql_query($sql_update);
				}
				
			}else{
			
				$qty_temp = $qty_temp - $product_quantity;
				if($qty_temp<0){$qty_temp=0;}
				$sql_select = "SELECT * FROM products  WHERE product_code='".$product_code."'";
				$results_select = mysql_query($sql_select);
				while($row_select = mysql_fetch_array($results_select) )
				{
					$qty_temp = $row_select['product_qty'];
					$qty_temp = $qty_temp - $product_quantity;

				}
				
				$sql_update = "UPDATE products SET product_qty=$qty_temp WHERE product_code='".$product_code."'";
				$results_update = mysql_query($sql_update);
			}
		}
		
		
	}
	$smarty->assign('msg','Status changed Successfully');
	
	//send email to customer about change
	
}


//manage
$sql = "SELECT * FROM orders ORDER BY order_id DESC";
$results = mysql_query($sql);
$total_orders = mysql_num_rows($results);
$smarty->assign('total_orders', $total_orders);

while($row = mysql_fetch_assoc($results) )
{
	$all_order_list[] = $row;
}
$smarty->assign('all_order_list', $all_order_list);


$sql = "SELECT * FROM order_item";
$results = mysql_query($sql);
$total_order_items = mysql_num_rows($results);
$smarty->assign('total_order_items', $total_order_items);

while($row = mysql_fetch_assoc($results) )
{
	$all_order_item_list[] = $row;
}
$smarty->assign('all_order_item_list', $all_order_item_list);


//end manage


//if($_GET['mode']!=""){

//}else{
	$smarty->display('list_all_orders.tpl');
//}
?>
Return current item: Simple PHP Shopping cart - asaancart