
<!-- DataTables -->
<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">

<div class="content-wrapper">

    <?php
        function duree($time) {
            $tabTemps = array("jours" => 86400,
                "h" => 3600,
                "m" => 60,
                "s" => 1);
            $result = "";

            foreach($tabTemps as $uniteTemps => $nombreSecondesDansUnite) {

                $$uniteTemps = floor($time/$nombreSecondesDansUnite);

                $time = $time%$nombreSecondesDansUnite;

                if($$uniteTemps > 0 || !empty($result)){

                    $result .= $$uniteTemps." $uniteTemps ";
                }
            }

            return $result;

        }

        function dateDiff($date1, $date2){
            $diff = abs($date1 - $date2); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
            $retour = array();

            $tmp = $diff;
            $second = $tmp % 60;

            $tmp = floor( ($tmp - $second) /60 );
            $minute = $tmp % 60;

            $tmp = floor( ($tmp - $minute)/60 );
            $heure = $tmp % 24;

            $tmp = floor( ($tmp - $heure)  /24 );
            $jour = $tmp;

            return 'Depuis '.$jour.' jours '.$heure.' heures '.$minute.' minutes '.$second.' secondes';
        }

        function traitementTemps($time,$dateAjout){
            if($time==null){
                $now   = time();
                $date2 = strtotime($dateAjout);

                return dateDiff($now, $date2);
            }
            else{
                return duree($time);
            }
        }
    ?>

    <section class="content">
        <div class="row">
            <div class="col-md-4 col-sm-6 col-xs-12">
                <div class="info-box">
                    <span class="info-box-icon bg-aqua"><i class="ion ion-android-arrow-down"></i></span>

                    <div class="info-box-content">
                        <span class="info-box-text"><?php echo $this->lang->line('Temps moyen de traitement entrant'); ?> </span>
                        <span class="info-box-number">
                            <?php
                                if($temp_moyen!=false){
                                    if(duree($temp_moyen)==""){
                                        echo "0s";
                                    }else{
                                        echo duree($temp_moyen);
                                    }
                                }else{
                                    echo $this->lang->line('Aucune demande traitée');
                                }
                            ?>
                        </span>
                    </div>
                </div>
            </div>
            <?php if($this->session->userdata('category')=='super' && $type!=$this->lang->line('Adhésion')){ ?>
            <div class="col-md-4 col-sm-6 col-xs-12">
                <div class="info-box">
                    <span class="info-box-icon bg-green"><i class="ion ion-android-arrow-up"></i></span>

                    <div class="info-box-content">
                        <span class="info-box-text"><?php echo $this->lang->line('Temps moyen de traitement sortant'); ?></span>
                        <span class="info-box-number">
                            <?php
                            if($temp_moyen_mine!=false){
                                if(duree($temp_moyen_mine)==""){
                                    echo "0s";
                                }else{
                                    echo duree($temp_moyen_mine);
                                }
                            }else{
                                echo $this->lang->line('Aucune demande traitée');
                            }
                            ?>
                        </span>
                    </div>
                </div>
            </div>
           <?php } ?>
        </div>
        <div class="row">
            <?php
                if($this->session->userdata('category')=='super' && $type!=$this->lang->line('Adhésion')){
            ?>
                    <div class="col-md-6">
                        <div class="box">
                            <?php


                            if($alert=="ok") {

                                if(!$success=="ok"){
                                    ?>
                                    <div class='alert alert-danger alert-dismissible'>
                                        <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                        <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success alert-dismissible">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                        <h4><i class="icon fa fa-check"></i> Success!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                }
                            }
                            ?>
                            <div class="box-header with-border">
                                <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('entrantes'); ?> </h3>
                            </div>
                            <div class="box-body">

                                <?php

                                $result=$list;
                                if($result!=false){

                                $numrows=$result->num_rows();
                                $num = 0;
                                if ($numrows > 0) {

                                ?>

                                <table id="listeMembres1" class="table table-bordered table-striped table-modified">
                                    <thead>
                                    <?php
                                    if($type==$this->lang->line('Adhésion')){
                                        echo "
                            <tr class='label-primary'>
                                <th>".$this->lang->line('Téléphone utilisateur')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Statut')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                        echo "<tr class='label-primary'>
                                <th>".$this->lang->line('Telephone')."</th>
                                <th>".$this->lang->line('Emetteur')."</th>
                                <th>Montant demandé</th>
                                <th>Montant envoyé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Statut')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                                    }
                                    ?>
                                    </thead>
                                    <tbody>


                                    <?php
                                    $site_url = base_url();
                                    $url = base_url('index.php/Listes_members/modif');
                                    // output data of each row
                                    foreach($result->result() as $row) {
                                        $num++;
                                        if($type==$this->lang->line('Adhésion')){
                                            $etat = $this->lang->line("Non traitée");
                                            if($row->etat==1){
                                                $etat = $this->lang->line("traitée");
                                            }
                                            $code = $row->code_membre;
                                            if($row->code_membre==$this->session->userdata('member_code')){
                                                $code = $this->lang->line('Vous');
                                            }
                                            echo "<tr>

                                    <td>  $row->phone </td>
                                    <td>$code</td>
                                    <td>$row->dateAjout </td>
                                    <td > $row->dateModif</td>
                                    <td>$etat</td>
                                    <td>".traitementTemps($row->temps,$row->dateAjout)."</td>
                                    
                                     </tr>";}else{
                                            $etat = $this->lang->line("Non traitée");
                                            if($row->statut==1){
                                                $etat = $this->lang->line("traitée");
                                            }
                                            $origin = $row->codeMembre;
                                            $destination = $row->ref_operateur;
                                            if($row->codeMembre==$this->session->userdata('member_code')){
                                                $origin = $this->lang->line('Vous');
                                            }
                                            if($row->ref_operateur=="0"){
                                                $destination = "XXX_XXX";
                                            }
                                            echo "<tr>

                                    <td>  $row->phone</td>
                                    <td >$origin </td>
                                    <td > $row->montant</td>
                                    <td > $row->montant_allowed</td>
                                    <td>$row->dateAjout </td>
                                    <td > $row->dateModif</td>
                                    <td>$etat</td>
                                    <td>".traitementTemps($row->temps,$row->dateAjout)."</td>
                                    
                                     </tr>";
                                        }
                                    }
                                    ?>
                                    </tbody>


                                    <?php
                                    } else {
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    }else{
                                        echo $this->lang->line('Aucune demande');
                                    }



                                    $this->db->close();

                                    ?>

                                </table>


                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="box">
                            <?php

                            if($alert=="ok") {

                                if(!$success=="ok"){
                                    ?>
                                    <div class='alert alert-danger alert-dismissible'>
                                        <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                        <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success alert-dismissible">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                        <h4><i class="icon fa fa-check"></i> Success!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                }
                            }
                            ?>
                            <div class="box-header with-border">
                                <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('Sortantes'); ?></h3>
                            </div>
                            <div class="box-body">

                                <?php

                                $result=$mydem;
                                if($result!=false){

                                $numrows=$result->num_rows();
                                $num = 0;
                                if ($numrows > 0) {

                                ?>

                                <table id="listeMembres2" class="table table-bordered table-striped table-modified">
                                    <thead>
                                    <?php
                                    if($type==$this->lang->line('Adhésion')){
                                        echo "
                            <tr class='label-primary'>
                                <th>".$this->lang->line('Téléphone utilisateur')."</th>
                                <th>".$this->lang->line('Catégorie')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Statut')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                        echo "<tr class='label-primary'>
                               <th>Montant demandé</th>
                               <th>Montant envoyé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Statut')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                                    }
                                    ?>
                                    </thead>
                                    <tbody>


                                    <?php
                                    $site_url = base_url();
                                    $url = base_url('index.php/Listes_members/modif');
                                    // output data of each row
                                    foreach($result->result() as $row) {
                                        $num++;
                                        if($type==$this->lang->line('Adhésion')){
                                            $etat = $this->lang->line("Non traitée");
                                            if($row->etat==1){
                                                $etat = $this->lang->line("traitée");
                                            }
                                            $code = $row->code;
                                            if($row->code==$this->session->userdata('member_code')){
                                                $code = $this->lang->line('Vous');
                                            }
                                            echo "<tr>

                                    <td>  $row->phone </td>
                                    <td >$row->categorie </td>
                                    <td>$code</td>
                                    <td>$row->dateAjout </td>
                                    <td > $row->dateModif</td>
                                    <td>$etat</td>
                                    <td>".traitementTemps($row->temps,$row->dateAjout)."</td>
                                    
                                     </tr>";}else{
                                            $etat = $this->lang->line("Non traitée");
                                            if($row->statut==1){
                                                $etat = $this->lang->line("traitée");
                                            }
                                            $origin = $row->codeMembre;
                                            $destination = $row->ref_operateur;
                                            if($row->codeMembre==$this->session->userdata('member_code')){
                                                $origin = $this->lang->line('Vous');
                                            }
                                            if($row->ref_operateur=="0"){
                                                $destination = "XXX_XXX";
                                            }
                                            echo "<tr>

                                    <td > $row->montant</td>
                                    <td > $row->montant_allowed</td>
                                    <td>$row->dateAjout </td>
                                    <td > $row->dateModif</td>
                                    <td>$etat</td>
                                    <td>".traitementTemps($row->temps,$row->dateAjout)."</td>
                                    
                                     </tr>";
                                        }
                                    }
                                    ?>
                                    </tbody>


                                    <?php
                                    } else {
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    }else{
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    ?>

                                </table>


                            </div>
                        </div>
                    </div>
        </div>
        <div class="row">
                    <div class="col-md-6">
                        <div class="box">
                            <?php

                            if($alert=="ok") {

                                if(!$success=="ok"){
                                    ?>
                                    <div class='alert alert-danger alert-dismissible'>
                                        <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                        <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success alert-dismissible">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                        <h4><i class="icon fa fa-check"></i> Success!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                }
                            }
                            ?>
                            <div class="box-header with-border">
                                <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('entrantes'); ?> <?php echo $this->lang->line('les plus rapidement traitées'); ?></h3>
                            </div>
                            <div class="box-body">

                                <?php

                                $result=$tab_fastDemande;
                                if($result!=false){

                                $numrows=$result->num_rows();
                                $num = 0;
                                if ($numrows > 0) {

                                ?>

                                <table id="listeDemandesRapides" class="table table-bordered table-striped table-modified">
                                    <thead>
                                    <?php
                                    if($type==$this->lang->line('Adhésion')){
                                        echo "
                            <tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Téléphone utilisateur')."</th>
                                <th>".$this->lang->line('Catégorie')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                        echo "<tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Membre')."</th>
                                <th>Ref. Opérateur</th>
                                <th>Montant demandé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                                    }
                                    ?>
                                    </thead>
                                    <tbody>


                                    <?php
                                    $site_url = base_url();
                                    $url = base_url('index.php/Listes_members/modif');
                                    // output data of each row
                                    foreach($result->result() as $row) {
                                        $num++;
                                        
                                        if($type==$this->lang->line('Adhésion')){
                                            $etat = $this->lang->line("Non traitée");
                                            if($row->etat==1){
                                                $etat = $this->lang->line("traitée");
                                            }

                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$superviseur</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";}else{
                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->ref_operateur</td>
                                    <td>$row->montant</td>
                                    <td>$row->montant_allowed</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";
                                        }
                                    }
                                    ?>
                                    </tbody>


                                    <?php
                                    } else {
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    }else{
                                        echo $this->lang->line('Aucune demande');
                                    }



                                    $this->db->close();

                                    ?>

                                </table>


                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="box">
                            <?php

                            if($alert=="ok") {

                                if(!$success=="ok"){
                                    ?>
                                    <div class='alert alert-danger alert-dismissible'>
                                        <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                        <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success alert-dismissible">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                        <h4><i class="icon fa fa-check"></i> Success!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                }
                            }
                            ?>
                            <div class="box-header with-border">
                                <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('Sortantes'); ?> <?php echo $this->lang->line('les plus rapidement traitées'); ?></h3>
                            </div>
                            <div class="box-body">

                                <?php

                                $result=$tab_fastDemande_s;
                                if($result!=false){

                                $numrows=$result->num_rows();
                                $num = 0;
                                if ($numrows > 0) {

                                ?>

                                <table id="listeDemandesRapides" class="table table-bordered table-striped table-modified">
                                    <thead>
                                    <?php
                                    if($type==$this->lang->line('Adhésion')){
                                        echo "
                            <tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Téléphone utilisateur')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                        echo "<tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Membre')."</th>
                                <th>Ref. Opérateur</th>
                                <th>Montant demandé</th>
                                <th>Montant envoyé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                                    }
                                    ?>
                                    </thead>
                                    <tbody>


                                    <?php
                                    $site_url = base_url();
                                    $url = base_url('index.php/Listes_members/modif');
                                    // output data of each row
                                    foreach($result->result() as $row) {
                                        $num++;
                                        
                                        if($type==$this->lang->line('Adhésion')){

                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$superviseur</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";}else{
                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->ref_operateur</td>
                                    <td>$row->montant</td>
                                    <td>$row->montant_allowed</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";
                                        }
                                    }
                                    ?>
                                    </tbody>


                                    <?php
                                    } else {
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    }else{
                                        echo $this->lang->line('Aucune demande');
                                    }



                                    $this->db->close();

                                    ?>

                                </table>


                            </div>
                        </div>
                    </div>
        </div>
        <div class="row">
                    <div class="col-md-6">
                <div class="box">
                    <?php

                    if($alert=="ok") {

                        if(!$success=="ok"){
                            ?>
                            <div class='alert alert-danger alert-dismissible'>
                                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                <?php echo $message; ?>
                            </div>

                            <?php
                        } else {
                            ?>
                            <div class="alert alert-success alert-dismissible">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4><i class="icon fa fa-check"></i> Success!</h4>
                                <?php echo $message; ?>
                            </div>

                            <?php
                        }
                    }
                    ?>
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('entrantes'); ?> <?php echo $this->lang->line('les plus tardivement traitées'); ?></h3>
                    </div>
                    <div class="box-body">

                        <?php

                        $result=$tab_slowDemande;
                        if($result!=false){

                        $numrows=$result->num_rows();
                        $num = 0;
                        if ($numrows > 0) {

                        ?>

                        <table id="listeDemandesTardives" class="table table-bordered table-striped table-modified">
                            <thead>
                            <?php
                            if($type==$this->lang->line('Adhésion')){
                                echo "
                            <tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Contact')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                echo "<tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Membre')."</th>
                                <th>Ref. Opérateur</th>
                                <th>Montant demandé</th>
                                <th>Montant envoyé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                            }
                            ?>
                            </thead>
                            <tbody>


                            <?php
                            $site_url = base_url();
                            $url = base_url('index.php/Listes_members/modif');
                            // output data of each row
                            foreach($result->result() as $row) {
                                $num++;
                                
                                if($type==$this->lang->line('Adhésion')){
                                    echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$superviseur</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";}else{
                                    echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->ref_operateur</td>
                                    <td>$row->montant</td>
                                    <td>$row->montant_allowed</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";
                                }
                            }
                            ?>
                            </tbody>


                            <?php
                            } else {
                                echo $this->lang->line('Aucune demande');
                            }
                            }else{
                                echo $this->lang->line('Aucune demande');
                            }



                            $this->db->close();

                            ?>

                        </table>


                    </div>
                </div>
            </div>
                    <div class="col-md-6">
                <div class="box">
                    <?php

                    if($alert=="ok") {

                        if(!$success=="ok"){
                            ?>
                            <div class='alert alert-danger alert-dismissible'>
                                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                <?php echo $message; ?>
                            </div>

                            <?php
                        } else {
                            ?>
                            <div class="alert alert-success alert-dismissible">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4><i class="icon fa fa-check"></i> Success!</h4>
                                <?php echo $message; ?>
                            </div>

                            <?php
                        }
                    }
                    ?>
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('Sortantes'); ?> <?php echo $this->lang->line('les plus tardivement traitées'); ?></h3>
                    </div>
                    <div class="box-body">

                        <?php

                        $result=$tab_slowDemande_s;
                        if($result!=false){

                        $numrows=$result->num_rows();
                        $num = 0;
                        if ($numrows > 0) {

                        ?>

                        <table id="listeDemandesTardives" class="table table-bordered table-striped table-modified">
                            <thead>
                            <?php
                            if($type==$this->lang->line('Adhésion')){
                                echo "
                            <tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Contact')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                echo "<tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Membre')."</th>
                                <th>Ref. Opérateur</th>
                                <th>Montant demandé</th>
                                <th>Montant envoyé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                            }
                            ?>
                            </thead>
                            <tbody>


                            <?php
                            $site_url = base_url();
                            $url = base_url('index.php/Listes_members/modif');
                            // output data of each row
                            foreach($result->result() as $row) {
                                $num++;
                                
                                if($type==$this->lang->line('Adhésion')){
                                    echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$superviseur</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";}else{
                                    echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->ref_operateur</td>
                                    <td>$row->montant</td>
                                    <td>$row->montant_allowed</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";
                                }
                            }
                            ?>
                            </tbody>


                            <?php
                            } else {
                                echo $this->lang->line('Aucune demande');
                            }
                            }else{
                                echo $this->lang->line('Aucune demande');
                            }



                            $this->db->close();

                            ?>

                        </table>


                    </div>
                </div>
            </div>
            <?php
                }else{
            ?>
                    <div class="col-md-12">
                        <div class="box">
                            <?php

                            if($alert=="ok") {

                                if(!$success=="ok"){
                                    ?>
                                    <div class='alert alert-danger alert-dismissible'>
                                        <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                        <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success alert-dismissible">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                        <h4><i class="icon fa fa-check"></i> Success!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                }
                            }
                            ?>
                            <div class="box-header with-border">
                                <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?></h3>
                            </div>
                            <div class="box-body">

                                <?php

                                $result=$list;
                                if($result!=false){

                                $numrows=$result->num_rows();
                                $num = 0;
                                if ($numrows > 0) {

                                ?>

                                <table id="listeMembres" class="table table-bordered table-striped table-modified">
                                    <thead>
                                    <?php
                                    if($type==$this->lang->line('Adhésion')){

                                        echo "
                                        <tr class='label-primary'>
                                            <th>".$this->lang->line('Téléphone utilisateur')."</th>
                                            <th>".$this->lang->line('Catégorie')."</th>
                                            <th>".$this->lang->line('Parrain')."</th>
                                            <th>".$this->lang->line('Date de la demande')."</th>
                                            <th>".$this->lang->line('Date de traitement')."</th>
                                            <th>".$this->lang->line('Statut')."</th>
                                            <th>".$this->lang->line('Délai de traitement')."</th>
                                        </tr>"; }else{
                                        echo "<tr class='label-primary'>
                                            <th>".$this->lang->line('Reseau')."</th>
                                            <th>".$this->lang->line('Téléphone utilisateur')."</th>
                                            <th>".$this->lang->line('Emetteur')."</th>
                                            <th>Ref. Opérateur</th>
                                            <th>Montant demandé</th>
                                            <th>Montant envoyé</th>
                                            <th>".$this->lang->line('Date de la demande')."</th>
                                            <th>".$this->lang->line('Date de traitement')."</th>
                                            <th>".$this->lang->line('Statut')."</th>
                                            <th>".$this->lang->line('Délai de traitement')."</th>
                                        </tr>";}
                                    ?>
                                    </thead>
                                    <tbody>


                                    <?php
                                    $site_url = base_url();
                                    $url = base_url('index.php/Listes_members/modif');
                                    // output data of each row
                                    foreach($result->result() as $row) {
                                        $num++;
                                    if($type==$this->lang->line('Adhésion')){
                                        $etat = $this->lang->line("Non traitée");
                                        if($row->etat==1){
                                            $etat = $this->lang->line("traitée");
                                        }
                                        $code = $row->code_membre;
                                        if($row->code_membre==$this->session->userdata('member_code')){
                                            $code = $this->lang->line('Vous');
                                        }
                                        echo "<tr>

                                    <td>  $row->phone </td>
                                    <td >Super </td>
                                    <td>$row->code_membre</td>
                                    <td>$row->date_creation </td>
                                    <td > $row->date_modified</td>
                                    <td>$etat</td>
                                    <td>".traitementTemps($row->temps,$row->date_creation)."</td>
                                    
                                     </tr>";}else{
                                        $etat = $this->lang->line("Non traitée");
                                        if($row->statut==1){
                                            $etat = $this->lang->line("traitée");
                                        }
                                            $origin = $row->codeMembre;
                                            $destination = $row->ref_operateur;
                                            if($row->codeMembre==$this->session->userdata('member_code')){
                                                $origin = $this->lang->line('Vous');
                                            }
                                            if($row->ref_operateur=="0"){
                                                $destination = "XXX_XXX";
                                            }
                                            echo "<tr>

                                    <td>  $row->reseau</td>
                                    <td>  $row->phone </td>
                                    <td >$origin </td>
                                    <td>$destination</td>
                                    <td > $row->montant</td>
                                    <td > $row->montant_allowed</td>
                                    <td>$row->dateAjout </td>
                                    <td > $row->dateModif</td>
                                    <td>$etat</td>
                                    <td>".traitementTemps($row->temps,$row->dateAjout)."</td>
                                    
                                     </tr>";}

                                    }
                                    ?>
                                    </tbody>

                                    <?php
                                    } else {
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    }else{
                                        echo $this->lang->line('Aucune demande');
                                    }

                                    ?>

                                </table>


                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="box">
                            <?php

                            if($alert=="ok") {

                                if(!$success=="ok"){
                                    ?>
                                    <div class='alert alert-danger alert-dismissible'>
                                        <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                        <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success alert-dismissible">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                        <h4><i class="icon fa fa-check"></i> Success!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                }
                            }
                            ?>
                            <div class="box-header with-border">
                                <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('les plus rapidement traitées'); ?></h3>
                            </div>
                            <div class="box-body">

                                <?php

                                $result=$tab_fastDemande;
                                if($result!=false){

                                $numrows=$result->num_rows();
                                $num = 0;
                                if ($numrows > 0) {

                                ?>

                                <table id="listeDemandesRapides" class="table table-bordered table-striped table-modified">
                                    <thead>
                                    <?php
                                    if($type==$this->lang->line('Adhésion')){
                                        echo "
                            <tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Téléphone utilisateur')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                        echo "<tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Membre')."</th>
                                <th>Ref. Opérateur</th>
                                <th>Montant demandé</th>
                                <th>Montant envoyé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                                    }
                                    ?>
                                    </thead>
                                    <tbody>


                                    <?php
                                    $site_url = base_url();
                                    $url = base_url('index.php/Listes_members/modif');
                                    // output data of each row
                                    foreach($result->result() as $row) {
                                        $num++;
                                        
                                        if($type==$this->lang->line('Adhésion')){

                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->superviseur</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";}else{
                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->ref_operateur</td>
                                    <td>$row->montant</td>
                                    <td>$row->montant_allowed</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";
                                        }
                                    }
                                    ?>
                                    </tbody>


                                    <?php
                                    } else {
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    }else{
                                        echo $this->lang->line('Aucune demande');
                                    }



                                    $this->db->close();

                                    ?>

                                </table>


                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="box">
                            <?php

                            if($alert=="ok") {

                                if(!$success=="ok"){
                                    ?>
                                    <div class='alert alert-danger alert-dismissible'>
                                        <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                        <h4><i class='icon fa fa-ban'></i> Error!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                } else {
                                    ?>
                                    <div class="alert alert-success alert-dismissible">
                                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                        <h4><i class="icon fa fa-check"></i> Success!</h4>
                                        <?php echo $message; ?>
                                    </div>

                                    <?php
                                }
                            }
                            ?>
                            <div class="box-header with-border">
                                <h3 class="box-title"><?php echo $this->lang->line('Demandes'); ?> <?php echo $type ?> <?php echo $this->lang->line('les plus tardivement traitées'); ?></h3>
                            </div>
                            <div class="box-body">

                                <?php

                                $result=$tab_slowDemande;
                                if($result!=false){

                                $numrows=$result->num_rows();
                                $num = 0;
                                if ($numrows > 0) {

                                ?>

                                <table id="listeDemandesTardives" class="table table-bordered table-striped table-modified">
                                    <thead>
                                    <?php
                                    if($type==$this->lang->line('Adhésion')){
                                        echo "
                            <tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Contact')."</th>
                                <th>".$this->lang->line('Parrain')."</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>"; }else{
                                        echo "<tr class='label-primary'>
                                <th>N°</th>
                                <th>".$this->lang->line('Membre')."</th>
                                <th>Ref. Opérateur</th>
                                <th>Montant demandé</th>
                                <th>Montant envoyé</th>
                                <th>".$this->lang->line('Date de la demande')."</th>
                                <th>".$this->lang->line('Date de traitement')."</th>
                                <th>".$this->lang->line('Délai de traitement')."</th>
                            </tr>";
                                    }
                                    ?>
                                    </thead>
                                    <tbody>


                                    <?php
                                    $site_url = base_url();
                                    $url = base_url('index.php/Listes_members/modif');
                                    // output data of each row
                                    foreach($result->result() as $row) {
                                        $num++;
                                        
                                        if($type==$this->lang->line('Adhésion')){
                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->superviseur</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";}else{
                                            echo "<tr>

                                    <td>$num</td>
                                    <td>$row->emetteur</td>
                                    <td>$row->ref_operateur</td>
                                    <td>$row->montant</td>
                                    <td>$row->montant_allowed</td>
                                    <td>$row->dateA</td>
                                    <td>$row->dateM</td>
                                    <td>".duree($row->temps)."</td>
                                    
                                     </tr>";
                                        }
                                    }
                                    ?>
                                    </tbody>


                                    <?php
                                    } else {
                                        echo $this->lang->line('Aucune demande');
                                    }
                                    }else{
                                        echo $this->lang->line('Aucune demande');
                                    }



                                    $this->db->close();

                                    ?>

                                </table>


                            </div>
                        </div>
                    </div>
            <?php
                }
            ?>
        </div>
    </section>


</div>
<!-- jQuery 3 -->
<script src="<?php echo base_url('bower_components/jquery/dist/jquery.min.js') ?>"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<?php echo base_url('bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
<!-- DataTables -->
<script src="<?php echo base_url('bower_components/datatables.net/js/jquery.dataTables.min.js') ?>"></script>
<script src="<?php echo base_url('bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js') ?>"></script>
<!-- SlimScroll -->
<script src="<?php echo base_url('bower_components/jquery-slimscroll/jquery.slimscroll.min.js') ?>"></script>
<!-- FastClick -->
<script src="<?php echo base_url('bower_components/fastclick/lib/fastclick.js') ?>"></script>
<!-- AdminLTE App -->
<script src="<?php echo base_url('dist/js/adminlte.min.js') ?>"></script>
<!-- AdminLTE for demo purposes -->
<script src="<?php echo base_url('dist/js/demo.js') ?>"></script>

<script>
    $(function () {
        $('#listeMembres').DataTable();
        $('#listeMembres1').DataTable();
        $('#listeMembres2').DataTable();

    })
</script>

<script type='text/javascript'>
    $(document).ready(function(){

        $('#pays').change(function(){
            var pays = $(this).val();
            $.ajax({
                url:'<?php echo base_url('index.php/Admin/getHypByPays')?>',
                type: 'post',
                data: {pays: pays},
                dataType: 'json',
                success: function(data){
                    var len = data.length;


                    if(len > 0){

                        var select = document.getElementById('hyper');
                        if(select===null){
                            var grpPays = document.getElementById('grp-pays');
                            $(grpPays).empty();
                            $(grpPays).append("<select class='form-control input-lg' name='hyper' required id='hyper'></select>");
                            select = document.getElementById('hyper');
                        }
                        $(select).empty();

                        for (var i in data) {
                            $(select).append('<option value=' + data[i].code_membre + '>' + data[i].lastname +'-' + data[i].network + ' ('+ data[i].code_membre +')</option>');
                        }

                        var code = data[0].code_membre;

                        $.ajax({
                            url:'<?php echo base_url('index.php/Admin/getVilleByHyp')?>',
                            type: 'post',
                            data: {code: code,pays:pays},
                            dataType: 'json',
                            success: function(list){
                                var len = list.length;

                                if(len > 0){

                                    var select = document.getElementById('ville');
                                    if(select===null){
                                        var grpVille = document.getElementById('grp-ville');
                                        $(grpVille).empty();
                                        $(grpVille).append("<select class='form-control input-lg' name='ville' required id='ville'></select>");
                                        select = document.getElementById('ville');
                                    }
                                    $(select).empty();

                                    for (var i in list) {
                                        $(select).append('<option value=' + list[i].town_id + '>' + list[i].town +'</option>');
                                    }


                                }else{

                                    var select = document.getElementById('ville');
                                    $(select).empty();

                                }

                            }
                        });


                    }else{

                        var select = document.getElementById('hyper');
                        $(select).empty();

                        var select2 = document.getElementById('ville');
                        $(select2).empty();
                    }

                }
            });
        });

        $('#hyper').change(function(){
            var code = $(this).val();
            $.ajax({
                url:'<?php echo base_url('index.php/Admin/getVilleByHyp')?>',
                type: 'post',
                data: {code: code},
                dataType: 'json',
                success: function(list){
                    var len = list.length;

                    if(len > 0){

                        var select = document.getElementById('ville');
                        $(select).empty();

                        for (var i in list) {
                            $(select).append('<option value=' + list[i].town_id + '>' + list[i].town +'</option>');
                        }

                    }else{

                        var select = document.getElementById('ville');
                        $(select).empty();

                    }

                }
            });
        });
    });
</script>
