<!DOCTYPE html>
<html>
<?php

    $MesCommandes = new ClassLpf();
    if($rub=="cde") {?>
    <?php
        $LstCmd = $MesCommandes->LstCmd( $no , $id ); // $no = j:jour / p:prochaine / t:toutes
        if($no=="j") {
            $Titre  = "Commande(s) du jour";
            $Quand  = "aujourd'hui";
        }
        elseif($no=="p") {
            $Titre  = "Commande(s) prochaine(s)";
            $Quand  = "à venir.";
        }
        elseif($no=="t") {
            $Titre  = "Commande(s)";
            $Quand  = "";
        }
    ?>
    <?php if($Message) echo $Message['msg'];?>
    <form action="" method="post" class="">
        <div class="form-group row">
            <div class="col-12" >
                <h2><?=$Titre?></h2>
                <?php if($LstCmd['0']>0) { ?>
                <table class="table table-bordered table-sm" style="font-size:0.9em">
                    <thead>
                    <tr style="color:#e5692c">
                        <th>Retrait</th>
                        <th>N°Cmd</th>
                        <th>Nom, prénom</th>
                        <th>Mobile</th>
                        <th>E-mail</th>
                        <th style="text-align:center">Qté</th>
                        <th width="10px">Allergie</th>
                        <th>Menu</th>
                        <th style="width:40px; text-align:center">€</th>
                        <th style="width:20px">Paiement</th>
                        <th style="width:20px">Email</th>

                    </tr>
                    </thead>
                    <tbody>
                    <?php   // Liste les commandes
                    foreach($LstCmd['1'] as $Date=>$Dtl1) {
                        $Date = substr($Date,8,2)."/" .substr($Date,5,2)."/" .substr($Date,0,4);
                        echo "<tr style=\"color:#8d4019; background: rgba(229,105,44,0.08)\"><td colspan=\"12\"><b>".$Date."</b></td></tr>";
                        foreach($Dtl1 as $Heure=>$Dtl1a) {
                            foreach($Dtl1a as $nox=>$Dtl2) {

                                ($Dtl2['allergie'] && $Dtl2['allergie']<>'""' && $Dtl2['allergie']<>'null')                  ? $picto_a = "<i class=\"fas fa-exclamation-triangle\" style='color:#d9534f'></i>" : $picto_a = "";

                                ($Dtl2['confirm'] && $Dtl2['confirm'] != "0000-00-00 00:00:00" && $Dtl2['confirm']<>'NULL') ? $picto_m = "<i class=\"fas fa-check\" style='color:#5cb85c'></i>" : $picto_m = "<i class=\"fas fa-times\" style='color:#d9534f'></i>";

                                if      ($Dtl2['paiement'] == "paiement_ok") $picto_p = "<i class=\"fas fa-check\" style='color:#5cb85c'></i>";
                                else if ($Dtl2['paiement'] == "paiement_ko") $picto_p = "<i class=\"fas fa-times\" style='color:#d9534f'></i>";
                                else                                        $picto_p ="";



                                echo "<tr>
                                <td>$Heure</td>
                                <td>". $Dtl2['idu']."</td>
                                <td>" . $Dtl2['nom'] . "</td>
                                <td>" . $Dtl2['mobile'] . "</td>
                                <td>" . $Dtl2['email'] . "</td>
                                <td style=\"text-align:center\">" . $Dtl2['qte'] . "</td>
                                <td style=\"text-align:center\">$picto_a</td>
                                <td>" . $Dtl2['menu'] . "</td>
                                <td style=\"text-align:center\">" . ($Dtl2['total']/100) . "</td>
                                <td style=\"text-align:center\">$picto_p</td>
                                <td style=\"text-align:center\">$picto_m</td>
                               
                            </tr>";
                            }
                        }
                    }
                    ?>
                    </tbody>
                </table>
                <?php } else {?>
                    <div class="alert alert-danger" role="alert"><b><?=$Titre?></b><br>Vous n'avez aucune commande enregistrée <?=$Quand?>.</div>
                <?php }?>
                <br>
                <div class="float-right">
                    <button type="button"   class="btn btn-orange" style="width:200px" Onclick="location=('index.php')">Accueil</button>
                    <button type="button"   class="btn btn-orange" style="width:200px" Onclick="location=('index.php?p=voir,<?=$no?>')">Voir le détail</button>
                </div>
            </div>

        </div>
    </form>
<?php
    } ?>


<?php
    if($rub=="voir") {
        $LstCmd = $MesCommandes->LstCmd( $no , "" ); // $no = j:jour / p:prochaine / t:toutes

        ?>
    <div class="form-group row">
        <div class="col-12" >
            <h2>Commande(s)</h2>

                <?php
                // Liste les commandes
                echo $MesCommandes->Recapitulatif_Cmd($LstCmd);
                ?>

            <div class="float-right">
                <button type="button"   class="btn btn-orange" style="width:200px" Onclick="javascript: window.history.back();">Retour</button>

            </div>

        </div>
    </div>
<?php
    } ?>
