<?php
/* **
 * @application PhpMyShopping
 * @part        Admin boutique (AB)
 * @file        commande.php
 * @path        ./admin/
 * @author      Stephane DINE <stephane@phpmyshopping.org>
 * @site        http://www.phpmyshopping.org
 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
 *
 * PHP version 5
 */

if ((!isset($_SESSION['LoginOk']) or $_SESSION['LoginOk'] != 'IdentOk')) {
    header('Location: ./login.php');
}

require_once 'include/class.order.php';
$order = new Order(10);

if ($_GET['debut']) {
    $data['debut'] = $_GET['debut'];
} else {
    $data['debut'] = 0;
}

if (empty($_REQUEST['orderStatus'])) {
    $data['orderStatus'] = 'CA';
} else {
    $data['orderStatus'] = $_REQUEST['orderStatus'];
}

if (empty($_REQUEST['field'])) {
    $data['field'] = 'BillNumber';
} else {
    $data['field'] = $_REQUEST['field'];
}

if (empty($_REQUEST['order'])) {
    $data['order'] = 'DESC';
} else {
    $data['order'] = $_REQUEST['order'];
}

switch ($C3) {
/** -------------------------------------------------------------------------------------
 * Liste des commandes par ordre chronologique (derniere comande passee en premier)
 */
case 'list':
    echo $order->orderListAdmin($data);
    break;

/** -------------------------------------------------------------------------------------
 * Affichage de la commande en mode edition
 */
case 'edit':
    echo $order->orderView($_GET['IDO']);
    break;

/** -------------------------------------------------------------------------------------
 * Prise en compte de la modification du status d'une commande
 */
case 'update_status':
    $data['ID_Shop']     = $_SESSION['ID_Shop'];
    $data['ID_Customer'] = $_POST['IDC'];
    $data['ID_Orders']   = $_POST['IDO'];
    $data['Status']      = $_POST['orderStatus'];
    $order->orderUpdateStatus($data);
    echo $order->orderView($data['ID_Orders']);
    break;

/** -------------------------------------------------------------------------------------
 * Demande de confirmation pour la suppression d'une commande
 */
case 'delete_confirm':
    echo '
    <p class="message_confirm">Souhaitez-vous vraiment effacer cette commande ?<br /><br />
      [<a class="lien_admin" href="?C1=CL&C2=CO&C3=delete_ok&IDC='.$_GET['IDC'].'&IDO='.$_GET['IDO'].'">Oui</a>]
      <b>::</b>
      [<a class="lien_admin" href="?C1=CL&C2=CO&C3=list">Non</a>]
    </p>
    <p class="message_alerte">
    ATTENTION ! Cette action entra&icirc;nera la suppression d&eacute;finitive de tout l\'historique des commandes pass&eacute;es par ce client
    </p>';
    break;    
    break;

/** -------------------------------------------------------------------------------------
 * Suppression de la commande
 */
case 'delete_ok':
    $order->orderDelete($_GET['IDC'], $_GET['IDO']);
    echo $order->orderListAdmin($data);
    break;

/** -------------------------------------------------------------------------------------
 * Affichage par defaut
 */
default:
    echo $order->orderListAdmin($data);
}
?>
