<?php

if (isset($_GET['test'])) {
    $_SESSION['test'] = $_GET['test'];
}
include './membre/lib/php/classes/facture.class.php';
include './membre/lib/php/classes/facture_manager.class.php';
$mg = new facture_manager($db);
$liste = $mg->getDetailFacture($_SESSION['test']);
$nbr = count($liste);
$flag = true;
$i = 0;
while ($i < $nbr && $flag == true) {
    $id_prod = $liste[$i]->id_prod;
    $id_facture = $_SESSION['test'];
    $retour = $mg->DeleteDetailFacture($id_prod, $id_facture);
    $i++;
    if ($retour == 1) {
        $flag = true;
    } else {
        $flag = false;
    }
}
if ($flag == true) {
    $retour = $mg->DeleteFacture($id_facture);
    if ($retour == 1) {
        $flag = true;
        print "<h1>Commande annulée</h1>";
        $_SESSION['lignedf'] = 0;
        $_SESSION['test'] = null;
    } else {
<?php

if (isset($_GET['fac'])) {
    $_SESSION['fac'] = $_GET['fac'];
}
include './membre/lib/php/classes/facture.class.php';
include './membre/lib/php/classes/facture_manager.class.php';
$mg = new facture_manager($db);
$liste = $mg->getDetailFacture($_SESSION['fac']);
$nbr = count($liste);
?>
<h1><?php 
print "Facture n°" . $_SESSION['fac'];
?>
</h1>
<div id="table_facture_detail">
    <table width="100%">
        <tr>
            <th>
                Ligne
            </th>
            <th>
                Titre
            </th>
            <th>
                Prix
            </th>
            <th>
                Quantite
            </th>
        </tr>
<?php

include './nonmembre/lib/php/classes/produits_nm.class.php';
include './nonmembre/lib/php/classes/produits_nm_manager.class.php';
include './membre/lib/php/classes/facture.class.php';
include './membre/lib/php/classes/facture_manager.class.php';
$mg = new produits_nm_manager($db);
$mg3 = new facture_manager($db);
if (!isset($_SESSION['valeur'])) {
    $_SESSION['valeur'] = "default";
    $_SESSION['lignedf'] = 0;
}
if (isset($_GET['valeur'])) {
    $_SESSION['valeur'] = $_GET['valeur'];
}
$_SESSION['choix'] = "default";
?>
<h2>Nouvelle commande</h2>
<div id="table_newfacture_m">
    <?php 
if ($_SESSION['valeur'] == "default") {
    ?>
    <h1><?php 
    if (isset($_SESSION['test'])) {
        print "Commande n°" . $_SESSION['test'];
    }
    ?>
</h1>
    <table>
        <thead>
            <th id="tablethlnf">
<?php

include './membre/lib/php/classes/facture.class.php';
include './membre/lib/php/classes/facture_manager.class.php';
$mg = new facture_manager($db);
$liste = $mg->getFacture($_SESSION['id_utilisateur']);
$nbr = count($liste);
?>
<div id="table_facture_m">
<table>
    <?php 
for ($i = 0; $i < $nbr; $i++) {
    ?>
    <tr>
        <td>
            Numéro de commande: <?php 
    print $liste[$i]->id_facture;
    ?>
        </td>
        <td>
            Date: <?php 
    print $liste[$i]->date;
    ?>
        </td>
        <td>
            <a href="index.php?page=details_commande&fac=<?php 
    print $liste[$i]->id_facture;
    ?>
">Détails de la commande</a>
        </td>
    </tr>