<?php
/*
* Copyright © 2010-2012 MLECMS. All Rights Reserved.
* @Multi-Language Enterprise Content Management System
* This Is Not a Freeware, Use Is Subject To License Terms.
*/
require_once(dirname(__FILE__).'/header.php');
$order = shopping::get_order($_GET['id']);
isset($order['id']) or msgbox($language['page']['nodata'],'BACK');
$order['pid'] = explode(',',$order['pid']); 
$order['number'] = explode(',',$order['number']); 
$order['price'] = explode(',',$order['price']); 
$order['attribute'] = explode(STRING_DELIMITED,$order['attribute']); 
if(isset($_POST['oid'])){
	$total = 0; 
	foreach ($order['pid'] as $e => $n){
		is_numeric($_POST['price'][$e]) or msgbox($language['page']['msg'][0],'CURRENTS');
		is_numeric($_POST['number'][$e]) or msgbox($language['page']['msg'][1],'CURRENTS');
		$_POST['price'][$e] = number_format($_POST['price'][$e],2,'.','');
		$total += $_POST['price'][$e] * $_POST['number'][$e];
	}
	$amount = number_format(($total * $order['discount'] / 10 + numeric($_POST['freight'])),2,'.',''); 
	$sql = "UPDATE `{$DB['prefix']}order` SET
	`oid` = '{$_POST['oid']}',
	`number` = '".implode(',',$_POST['number'])."',
	`price` = '".implode(',',$_POST['price'])."',
	`amount` = '{$amount}',
	`attribute` = '".implode(STRING_DELIMITED,$_POST['attribute'])."',
	`status` = '{$_POST['status']}',
	`dispatching` = '{$_POST['dispatching']}',
	`waybill` = '{$_POST['waybill']}',
	`freight` = '".number_format(numeric($_POST['freight']),2,'.','')."',
	`customer` = '".numeric($_POST['customer'])."',
	`vouch` = '".numeric($_POST['vouch'])."',
	`consignee` = '{$_POST['consignee']}',
	`email` = '{$_POST['email']}',
	`address` = '{$_POST['address']}',
	`zipcode` = '{$_POST['zipcode']}',
	`tel` = '{$_POST['tel']}',
	`mobile` = '{$_POST['mobile']}',
	`building` = '{$_POST['building']}',
	`besttime` = '{$_POST['besttime']}',
	`message` = '{$_POST['message']}',
	`reply` = '{$_POST['reply']}'
	WHERE `id` = '{$_GET['id']}'";	
	if($db->execute($sql)){
		admin::logs(3,$language['page']['modify']."，{$language['common']['successful']}(id:{$id})"); 
		msgbox($language['common']['successful'],'shop_order_manage.php'); 
	} else { 
		admin::logs(3,$language['page']['modify']."，{$language['common']['failed']}(id:{$id})"); 
		msgbox($language['common']['failed'],'CURRENTS'); 
	}
}
$mle['order'] = $order;
require_once(ADMIN_PATH.'/footer.php');