<link rel="stylesheet" href="<?= base_url('<link rel="stylesheet" 
	href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap.min.css">') ?>">
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">

        <?php
    $site_url = base_url();

    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>
                <?= $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>
                    <?= $message; ?>
                </div>

                <?php
    }
    }
     ?>
                    <h1>
                        <?= $this->lang->line("Demandes d'adhésions et codes valides"); ?>
                    </h1>

    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-6">


                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"><?= $this->lang->line("Demandes adhésion"); ?></h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body" style="overflow-x:auto;">
                        <?php

 $sql2 = $list_dem;
 if($sql2!=false){
 $numrows=$sql2->num_rows();
 $num = 3000;
 if ($numrows > 0) {



 ?>
                            <table id="validated" class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th><?= $this->lang->line("Téléphone"); ?></th>
                                        <th><?= $this->lang->line("Parrain"); ?></th>
                                        <th><?= $this->lang->line("Reseau"); ?></th>
                                        <th><?= $this->lang->line("Statut"); ?></th>
                                        <th><?= $this->lang->line("Date de la demande"); ?></th>
                                        <th><?= $this->lang->line("Supprimer"); ?></th>
                                    </tr>
                                </thead>
                                <tbody>


                                    <?php

 				 // output data of each row
       foreach($sql2->result() as $row) {
           $etat = $this->lang->line("Non traitée");
           if($row->etat==1){
               $etat = $this->lang->line("traitée");
           }
          $num ++;
          //$member_code = randomString1(10);
          echo "<tr>
          <td> $row->phone</td>
          <td >$row->code_membre </td>
          <td>$row->network</td>
          <td>$etat</td>
           <td >".$row->date_creation."</td>";
        if($row->etat==0){
            echo "
          <td>
          <a href='#myModal-1".$num."' role='button' class='btn btn-block btn-danger' data-toggle='modal'><i class='fa fa-remove'></i></a>
             <div class='modal fade' id='myModal-1".$num."' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
                <div class='modal-dialog'>
       <div class='modal-content'>
         <div class='modal-header'>
           <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
             <span aria-hidden='true'>&times;</span></button>
           <h4 class='modal-title'>".$this->lang->line('Confirmer la suppression')."</h4>
         </div>
         <div class='modal-body'>
           <p class='error-text'><i class='icon-warning-sign modal-icon'></i>".$this->lang->line('Message suppression')." ". $row->phone."?</p>
         </div>
         <div class='modal-footer'>
           <button type='button' class='btn btn-default pull-left' data-dismiss='modal'>".$this->lang->line('Fermer')."</button>
           <a href='".$site_url."Member_code_admin/delete/?recordId=".$row->phone."' role='button' class='btn btn-danger'>
           ".$this->lang->line('Supprimer')."</a>
         </div>
       </div>
       <!-- /.modal-content -->
     </div>
     <!-- /.modal-dialog -->
            </div>
         </td>";
            }
               echo "</tr>";

      }

      ?>
                                </tbody>
                            </table>

                            <?php

 }

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




                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <div class="col-xs-6">


                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"><?= $this->lang->line("Codes valides"); ?></h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body" style="overflow-x:auto;">
                        <?php

  $sql1 = $list_codes;
 if($sql1!=false){
  $numrows=$sql1->num_rows();
  $num = 0;

  if ($numrows > 0) {
  ?>

                            <table id="unvalidated" class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th><?= $this->lang->line("Code"); ?></th>
                                        <th><?= $this->lang->line("Catégorie"); ?></th>
                                        <th><?= $this->lang->line("Statut"); ?></th>
                                        <th><?= $this->lang->line("Créer le"); ?></th>
                                        <th><?= $this->lang->line("Parrain"); ?></th>
                                        <th><?= $this->lang->line("Supprimer"); ?></th>
                                    </tr>
                                </thead>
                                <tbody>

                                    <?php

           // output data of each row
       foreach($sql1->result() as $row) {
           $etat = $this->lang->line("Non assigné");
           if($row->etat==1){
               $etat = $this->lang->line("assigné");
           }

       $num ++;
           echo "<tr>
          <td> $row->code_membre</td>
           <td>$row->category </td>
           <td>$etat</td>
            <td >".$row->date_creation."</td>
            <td>$row->code_parrain</td>
            <td>";
           if($row->etat==0){
               echo "
              <a href='#myModal-2".$num."' role='button' class='btn btn-block btn-danger' data-toggle='modal'><i class='fa fa-remove'></i></a>
               <div class='modal smallfade' id='myModal-2".$num."' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
                <div class='modal-dialog'>
        <div class='modal-content'>
          <div class='modal-header'>
            <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
              <span aria-hidden='true'>&times;</span></button>
            <h4 class='modal-title'>".$this->lang->line('Confirmer la suppression')."</h4>
          </div>
          <div class='modal-body'>
            <p class='error-text'><i class='icon-warning-sign modal-icon'></i>".$this->lang->line('Message suppression code')." ".$row->code_membre."?</p>
          </div>
          <div class='modal-footer'>
            <button type='button' class='btn btn-default pull-left' data-dismiss='modal'>".$this->lang->line('Fermer')."</button>
            <a href='".$site_url."Member_code_admin/suppress/?recordId=".$row->code_membre."' role='button' class='btn btn-danger' id='delete'>
            ".$this->lang->line('Supprimer')."</a>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
                </div>
            </td>";

           }

            echo "</tr>  ";
       }

       ?>

                                </tbody>
                            </table>


                    </div>
                </div>
            </div>

            <?php


  }

  else {
      echo $this->lang->line("Aucun membre validé");
  }
            }

  $this->db->close();

  ?>





        </div>
        <!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->


</div>

<!-- jQuery 2.2.4 -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>

<!-- Bootstrap 3.3.7 -->
<script src="<?= base_url('bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
<!-- DataTables -->
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap.min.js"></script>
<!-- Slimscroll -->
<script src="<?= base_url('bower_components/jquery-slimscroll/jquery.slimscroll.min.js') ?>"></script>
<!-- FastClick -->
<script src="<?= base_url('bower_components/fastclick/lib/fastclick.js') ?>"></script>
<!-- AdminLTE App -->
<script src="<?= base_url('dist/js/adminlte.min.js') ?>"></script>
<!-- AdminLTE for demo purposes -->
<script src="<?= base_url('dist/js/demo.js') ?>"></script>
<script>
    $(function() {
        $('#unvalidated').DataTable()
        $('#validated').DataTable()

    })

</script>

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

        $('#pays').change(function(){
            var pays = $(this).val();
            $.ajax({
                url:'<?= base_url('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:'<?= base_url('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:'<?= base_url('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>
