<style>

    #map {
        min-height: 250px;
        height: 100%;
    }

    body {
        height: 100%;
        margin: 0;
        padding: 0;
    }
    .btn-center{
        text-align: center;
    }

    .img-center {
        display: block;
        margin-left: auto;
        margin-right: auto;
        /*width: 65%;*/
    }

</style>

<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">

    <section class="content-header">

		<?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>
					<?= $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('Carte des'); ?> <?= $map_title ?>
            <small><?= $this->lang->line('zoom'); ?> <?= $map_title ?></small>
        </h1>
        <section class="content">
            <div id="map" style="width:100%;height:400px;"></div>
        </section>

        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title"><?= $this->lang->line('Tous les'); ?> <?= $map_title ?> <?php //if($this->session->userdata('category')=='super'){ echo  "(".$numberGeo." ".$this->lang->line('Restant').")";} ?></h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body" style="overflow-x:auto;">

                            <?php

                                /*$this->db->select('*');
                                $this->db->from('users');
                                $this->db->where('network',$network);
                                $this->db->where('code_parrain', $code_parrain);*/

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

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

                            ?>
                                <table id="liste_users" class="table table-bordered table-striped table-modified">
                                    <thead>
                                        <tr class="label-primary">
                                            <th><?= $this->lang->line('Catégorie'); ?></th>
                                            <th><?= $this->lang->line('Parrain'); ?></th>
                                            <th><?= $this->lang->line('Nom'); ?></th>
                                            <th><?= $this->lang->line('Adresse'); ?></th>
                                            <th><?= $this->lang->line('Reseau'); ?></th>
                                            <th><?= $this->lang->line('code membre'); ?></th>
                                            <th><?= $this->lang->line('Solde'); ?></th>
                                            <th><?= $this->lang->line('Email'); ?></th>
                                            <th><?= $this->lang->line('Contact'); ?></th>
                                            <th><?= $this->lang->line('Active'); ?></th>
                                            <?php if($this->session->userdata("category")=="0" or $this->session->userdata("category")=="1"){
                                                    echo "<th>".$this->lang->line('Modifier')."</th>";
                                                }
                                            ?>
                                        </tr>
                                    </thead>
                                    <tbody id="table">


                                    <?php
                                        $site_url = base_url();
                                        // output data of each row
                                        foreach($result->result() as $row) {
                                        $num++;
                                            $code_parrain = $row->code_parrain;
                                            if($row->code_parrain==$this->session->userdata('member_code')){
                                                $code_parrain = $this->lang->line("Vous");
                                            }
                                        echo "
                                        <tr><td>$row->childcat</td>";
                                            if (isset($row->sup_code_membre)){
                                            echo "   
                                            <td>
                                                <button id='modal-497395".$num."' href='#modal-container-497395".$num."' class='btn btn-default btn-center' role='button' role='button' data-toggle='modal'>$code_parrain</button>
                                                <div class='modal fade' id='modal-container-497395".$num."' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>                
                                                    <div class='modal-dialog'>
                                                      <div class='modal-content box box-widget widget-user'>
                                                        <div class='widget-user-header label-primary'>
                                                          <h3 class='widget-user-username btn-center'>".$this->lang->line('Parrain')."</h3>
                                                        </div>
                                                        <div class=\"box-footer\">
                                                          <div class=\"row\">
                                                            <div class=\"col-sm-4 border-right\">
                                                              <div class=\"description-block\">
                                                                <h5 class=\"description-header\"><strong>".$this->lang->line('Catégorie').": </strong></h5>
                                                                <span class=\"description-text\">$row->dadcat</span>
                                                              </div>
                                                            </div>
                                                            <div class=\"col-sm-4 border-right\">
                                                              <div class=\"description-block\">
                                                                <h5 class=\"description-header\"><strong>".$this->lang->line('Nom').": </strong></h5>
                                                                <span class=\"description-text\"> $row->suplastname</span>
                                                              </div>
                                                            </div>
                                                            <div class=\"col-sm-4 \">
                                                                <div class=\"description-block\">
                                                                    <h5 class=\"description-header\"><strong>".$this->lang->line('Reseau')." :</strong></h5>
                                                                    <span class=\"description-text\">$row->sup_network</span>
                                                                </div>
                                                            </div>
                                                          </div>
                                                          <div class='row'>  
                                                              <div class=\"col-sm-6 border-right\">
                                                                  <div class=\"description-block\">
                                                                    <h5 class=\"description-header\"><strong>".$this->lang->line('code membre')." : </strong></h5>
                                                                    <span >$row->sup_code_membre</span>
                                                                  </div>
                                                              </div>
                                                              <div class=\"col-sm-6 \">
                                                                  <div class=\"description-block\">
                                                                    <h5 class=\"description-header\"><strong>".$this->lang->line('Code parrain')." :  </strong></h5>
                                                                    <span >$row->sup_code_parrain</span>
                                                                  </div>
                                                              </div>
                                                          </div>
                                                        </div>
                                                        <div class='modal-footer'>
                                                            <button type='button' class='btn btn-lg btn-default pull-left' data-dismiss='modal'>".$this->lang->line('Fermer')."</button>
                                                        </div>
                                                      </div>
                                                    </div>
                                                </div>
                                            </td>";
                                            }else{
                                                echo "<td>$code_parrain</td>";
                                            }
                                            $statut = $this->lang->line('Non');
                                            if($row->active==1){
                                                $statut = $this->lang->line('Oui');
                                            }
                                            echo "
                                            <td>$row->lastname</td>
                                            <td>$row->adresse </td>
                                            <td>$row->network</td>
                                            <td>$row->member_code</td>
                                            <td>0</td>
                                            <td>$row->email</td>
                                            <td>$row->phone</td>
                                            <td>$statut</td>";
                                            if($this->session->userdata('category')=="0" or $this->session->userdata('category')=="1"){
                                                  echo "<td id='edition' align='center'>
                                                    <button data-toggle='modal' data-category='$row->childcat' data-lastname='$row->lastname' data-adresse='$row->adresse' data-network='$row->network' data-member_code='$row->member_code' data-email='$row->email' data-phone='$row->phone' class='open-modal modif btn btn-success' data-target='#editModal'><i class='fa fa-edit'></i></button>
                                                  </td>";
                                                  }
                                            echo "</tr>";
                                        }

                                    ?>

                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <th><?= $this->lang->line('Catégorie'); ?></th>
                                        <th><?= $this->lang->line('Parrain'); ?></th>
                                        <th><?= $this->lang->line('Nom'); ?></th>
                                        <th><?= $this->lang->line('Adresse'); ?></th>
                                        <th><?= $this->lang->line('Reseau'); ?></th>
                                        <th><?= $this->lang->line('code membre'); ?></th>
                                        <th><?= $this->lang->line('Solde'); ?></th>
                                        <th><?= $this->lang->line('Email'); ?></th>
                                        <th><?= $this->lang->line('Contact'); ?></th>
                                        <th><?= $this->lang->line('Active'); ?></th>
                                        <?php if($this->session->userdata("category")=="0" or $this->session->userdata("category")=="1"){
                                            echo "<th>".$this->lang->line('Modifier')."</th>";
                                        }
                                        ?>
                                    </tr>
                                    </tfoot>
                                </table>
                                        <?php
                                            } else {
                                            echo $this->lang->line('Aucun utilisateur trouvé');
                                            }
                                }else{
                                    echo $this->lang->line('Aucun utilisateur trouvé');
                                }


                            //echo $links;
                                            $this->db->close();

                                        ?>




                            <div class="modal fade" id="editModal">
                                <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('Mettre à jour des informations'); ?></h4>
                                        </div>
                                        <div class="modal-body">
                                            <form id="update-form" method="post" class="bottom-75 center-block">
                                                <div class="form-group">
                                                    <label for="code"><?= $this->lang->line('code membre'); ?></label>
                                                    <input type="text" class="form-control input-lg" name="code" readonly id="code">
                                                </div>
                                                <div class="form-group">
                                                    <label for="categorie"><?= $this->lang->line('Catégorie'); ?></label>
                                                    <input type="text" class="form-control input-lg" name="categorie" readonly id="categorie">
                                                </div>
                                                <div class="form-group">
                                                    <label for="nom"><?= $this->lang->line('Nom'); ?></label>
                                                    <input type="text" class="form-control input-lg" name="nom" required id="nom">
                                                </div>
                                                <div class="form-group">
                                                    <label for="adresse"><?= $this->lang->line('Adresse'); ?></label>
                                                    <input type="text" class="form-control input-lg" name="adresse" required id="adresse">
                                                </div>
                                                <div class="form-group">
                                                    <label for="email"><?= $this->lang->line('Email'); ?></label>
                                                    <input type="email" class="form-control input-lg" name="email" required id="email">
                                                </div>
                                                <div class="form-group">
                                                    <label for="contact"><?= $this->lang->line('Contact'); ?></label>
                                                    <input type="text" class="form-control input-lg" name="contact" required id="contact">
                                                </div>
                                                <div class="form-group">
                                                    <input id="btn-update" type="submit" value="Confirmer" class="btn btn-primary">
                                                    <button type="button" class="btn btn-default pull-right" data-dismiss="modal"><?= $this->lang->line('Fermer'); ?></button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="modal fade" id="suppreModal">
                                <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('Suppression'); ?></h4>
                                        </div>
                                        <div class="modal-body">
                                            <p id="message"></p>
                                        </div>
                                        <div class="modal-footer">
                                            <button class="btn btn-danger pull-left" id="delete">Confirmer</button>
                                            <button type="button" class="btn btn-default pull-right" data-dismiss="modal"><?= $this->lang->line('Fermer'); ?></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                                    </div>

                                </div>
                                <!-- /.box -->


                            </div>
                            <!-- /.col -->
                <div id='loader' class="center-div loader">
                    <div class="center-div">
                        <img style="text-align: center" class="img-center" src="<?= base_url('dist/img/loading.gif') ?>" alt="Loading" height="50" width="50">
                        <p style="text-align: center">Chargement</p>
                        <p style="text-align: center"><span id="charger">100</span>/<span id="total-point"><?= $total_points; ?></span></p>
                    </div>
                </div>
                        </div>
                        <!-- /.row -->
                    </section>
    </section>
</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 src="<?= base_url('bower_components/bootstrap-daterangepicker/daterangepicker.js') ?>"></script>
<script src="<?= base_url('bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js') ?>"></script>

<script type="text/javascript">
	$(window).on('load', function(){
		$(".loader").fadeOut("1000");
	});
</script>

<script>
    $(function() {
       // $('#liste_users').DataTable()

    })

</script>

<script>
    var member_code = null;
    var categorie = null;
    $(document).on("click", ".open-modal", function () {

        member_code= $(this).data('member_code');
        categorie = $(this).data('category');
        var nom = $(this).data('lastname');
        var adresse = $(this).data('adresse');
        var email = $(this).data('email');
        var contact = $(this).data('phone');

        $(".modal-body #nom").val( nom );
        $(".modal-body #adresse").val( adresse );
        $(".modal-body #email").val( email );
        $(".modal-body #contact").val( contact );
        $(".modal-body #categorie").val(categorie);
        $(".modal-body #code").val(member_code);

    });

    $("#update-form").submit(function(event){

        var m_nom = $('#update-form #nom').val();
        var m_adresse = $('#update-form #adresse').val();
        var m_email = $('#update-form #email').val();
        var m_contact = $('#update-form #contact').val();
        var m_code = $(".modal-body #code").val();
        var m_cat = $(".modal-body #categorie").val();

        $.ajax({
            url:'<?= base_url('Admin/updateUser')?>',
            type: 'post',
            data: {code: m_code,nom:m_nom,adresse:m_adresse,email:m_email,contact:m_contact,cat:m_cat},
            dataType: 'json',
            success: function(data){
                if(data==='completed'){
                    alert("Les informations ont été mises à jours");
                    location.reload(true);
                }else{
                    alert(data);
                    location.reload(true);
                }
            }
        });

        event.preventDefault();
    });

    $(document).on("click", ".supre-modal", function () {

        member_code = $(this).data('member_code');
        categorie = $(this).data('category');
        var nom = $(this).data('lastname');

        var message = "Voulez-vous vraiment retirer "+nom+" (code membre "+member_code+") ?";

        $(".modal-body #message").text(message);

    });

    $("#delete").click(function(){

        $.ajax({
            url:'<?= base_url('Admin/deleteUser')?>',
            type: 'post',
            data: {code: member_code,cat:categorie},
            dataType: 'json',
            success: function(data){
                if(data==='completed'){
                    alert("L'utilisateur a été retiré");
                    location.reload(true);
                }else{
                    alert(data);
                    location.reload(true);
                }
            }
        });

        event.preventDefault();
    });
</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>



<script>
    function myMap() {
        var mapProp = {
            center: new google.maps.LatLng(<?= $latitude; ?>, <?= $longitude; ?>),
            zoom: <?= $this->session->userdata('category') != 'admin' ? 10 : 1; ?>,
            mapId: "DEMO_MAP_ID" // Remplacez par votre propre Map ID si nécessaire
        };

        var myLatLng = {lat: <?= $latitude; ?>, lng: <?= $longitude; ?>};
        var map = new google.maps.Map(document.getElementById("map"), mapProp);

        <?php if($this->session->userdata('category') != 'admin'): ?>
            var myPosition = new google.maps.marker.AdvancedMarkerElement({
                map: map,
                position: myLatLng,
                title: '<?= $this->lang->line('Vous'); ?>'
            });
        <?php endif; ?>

        <?php
        $result = $positions;
        if ($result != false) {
            $numrows = $result->num_rows();
            $num = 0;
            if ($numrows > 0) {
                $site_url = base_url();
                foreach ($result->result() as $row) {
                    $num++;
                    $mlat = (float)$row->latitude;
                    $mlng = (float)$row->longitude;
                    echo "var marker = new google.maps.marker.AdvancedMarkerElement({
                        map: map,
                        position: {lat: " . $mlat . ", lng: " . $mlng . "},
                        title: '" . addslashes($row->lastname) . "'
                    });";
                }
            }
        }
        ?>
    }

        function loadScript() {
            var script = document.createElement("script");
            script.src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyDwljY6bNBeL6ZsY-1Lz9imVCAshEXVkNc&callback=myMap&libraries=marker";
            script.async = true;
            script.defer = true;
            document.body.appendChild(script);
        }

        window.onload = loadScript;

</script>

<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>

<script type='text/javascript'>
    $( document ).ready(function() {
        i = 0;
        var x = 1;
        var y = 1;
        var total = parseInt($( "#total-point" ).text(), 10);
        var index = 100;
        var start_at = index+1;
        var first_load = 1;
        var pas = 200;


        // Selectionne le noeud dont les mutations seront observées
        var targetNode = document.getElementById('charger');

        // Options de l'observateur (quelles sont les mutations à observer)
        var config = {childList:true};

        // Fonction callback à éxécuter quand une mutation est observée
        var callback = function(mutationsList) {
            for(var mutation of mutationsList) {
                if (mutation.type === 'childList') {
                    console.log('mutation '+x+' : '+$('#charger').text());
                    console.log(parseInt($('#charger').text(), 10) >= total);
                    if (parseInt($('#charger').text(), 10) < total){
                        $.ajax({
                            url: '<?= base_url('Admin/progressRequestUser_g')?>',
                            type: 'post',
                            data: {start_at: start_at},
                            dataType: 'json',
                            async: false,
                            success: function (data) {
                                start_at = start_at + pas;
                                var num = <?= $num++; ?>;
                                for (var c in data) {
                                    if(data[c].etat==1){
                                        active = "Oui";
                                    }else{
                                        active = "Non";
                                    }
                                    $('table').append('<tr><td>'+data[c].childcat+'</td>   \n' +
                                        '                                            <td>\n' +
                                        '                                                <button id=\'modal-497395'+num+'\' href=\'#modal-container-497395'+num+'\' class=\'btn btn-default btn-center\' role=\'button\' role=\'button\' data-toggle=\'modal\'>' + data[c].code_parrain + '</button>\n' +
                                        '                                                <div class=\'modal fade\' id=\'modal-container-497395'+num+'\' role=\'dialog\' aria-labelledby=\'myModalLabel\' aria-hidden=\'true\'>                \n' +
                                        '                                                    <div class=\'modal-dialog\'>\n' +
                                        '                                                      <div class=\'modal-content box box-widget widget-user\'>\n' +
                                        '                                                        <div class=\'widget-user-header label-primary\'>\n' +
                                        '                                                          <h3 class=\'widget-user-username btn-center\'><?= $this->lang->line('Parrain'); ?></h3>\n' +
                                        '                                                        </div>\n' +
                                        '                                                        <div class="box-footer">\n' +
                                        '                                                          <div class="row">\n' +
                                        '                                                            <div class="col-sm-4 border-right">\n' +
                                        '                                                              <div class="description-block">\n' +
                                        '                                                                <h5 class="description-header"><strong><?= $this->lang->line('Catégorie'); ?>: </strong></h5>\n' +
                                        '                                                                <span class="description-text">'+data[c].dadcat+'</span>\n' +
                                        '                                                              </div>\n' +
                                        '                                                            </div>\n' +
                                        '                                                            <div class="col-sm-4 border-right">\n' +
                                        '                                                              <div class="description-block">\n' +
                                        '                                                                <h5 class="description-header"><strong><?= $this->lang->line('Nom'); ?>: </strong></h5>\n' +
                                        '                                                                <span class="description-text">'+data[c].suplastname+'</span>\n' +
                                        '                                                              </div>\n' +
                                        '                                                            </div>\n' +
                                        '                                                            <div class="col-sm-4 ">\n' +
                                        '                                                                <div class="description-block">\n' +
                                        '                                                                    <h5 class="description-header"><strong><?= $this->lang->line('Reseau'); ?> :</strong></h5>\n' +
                                        '                                                                    <span class="description-text">'+data[c].sup_network+'</span>\n' +
                                        '                                                                </div>\n' +
                                        '                                                            </div>\n' +
                                        '                                                          </div>\n' +
                                        '                                                          <div class=\'row\'>  \n' +
                                        '                                                              <div class="col-sm-6 border-right">\n' +
                                        '                                                                  <div class="description-block">\n' +
                                        '                                                                    <h5 class="description-header"><strong><?= $this->lang->line('code membre'); ?> : </strong></h5>\n' +
                                        '                                                                    <span >'+data[c].sup_code_membre+'</span>\n' +
                                        '                                                                  </div>\n' +
                                        '                                                              </div>\n' +
                                        '                                                              <div class="col-sm-6 ">\n' +
                                        '                                                                  <div class="description-block">\n' +
                                        '                                                                    <h5 class="description-header"><strong><?= $this->lang->line('Code parrain'); ?> :  </strong></h5>\n' +
                                        '                                                                    <span >'+data[c].sup_code_parrain+'</span>\n' +
                                        '                                                                  </div>\n' +
                                        '                                                              </div>\n' +
                                        '                                                          </div>\n' +
                                        '                                                        </div>\n' +
                                        '                                                        <div class=\'modal-footer\'>\n' +
                                        '                                                            <button type=\'button\' class=\'btn btn-lg btn-default pull-left\' data-dismiss=\'modal\'><?= $this->lang->line('Fermer'); ?></button>\n' +
                                        '                                                        </div>\n' +
                                        '                                                      </div>\n' +
                                        '                                                    </div>\n' +
                                        '                                                </div>\n' +
                                        '                                            </td>\n' +
                                        '                                            <td>'+data[c].lastname+'</td>\n' +
                                        '                                            <td>'+data[c].adresse+'</td>\n' +
                                        '                                            <td>'+data[c].network+'</td>\n' +
                                        '                                            <td>'+data[c].member_code+'</td>\n' +
                                        '                                            <td>'+data[c].solde+'</td>\n' +
                                        '                                            <td>'+data[c].email+'</td>\n' +
                                        '                                            <td>'+data[c].phone+'</td>\n' +
                                        '                                            <td>'+active+'</td>\n');
                                    num++;
                                }
                                i++;
                                $('#charger').text(parseInt($('#charger').text(), 10) + pas);
                                console.log('success '+y+' on mutation '+x);
                                y++;
                                console.log(parseInt($('#charger').text(), 10));
                                
                                if (parseInt($('#charger').text(), 10) >= total){
                                    y--;
                                    $('#liste_users').DataTable();
                                    //alert('Tous les éléments ont été chargés');
                                    $("#loader").hide();
                                    observer.disconnect();
                                }
                            }
                        });

                    }
                    else {
                        //alert('fin du chargement');
                        $('#liste_users').DataTable();
                        $("#loader").hide();
                        // L'observation peut être arrêtée par la suite
                        observer.disconnect();
                    }
                    x++;
                }
            }
        };

        // Créé une instance de l'observateur lié à la fonction de callback
        var observer = new MutationObserver(callback);

        // Commence à observer le noeud cible pour les mutations précédemment configurées
        observer.observe(targetNode, config);

        if(total>parseInt($('#charger').text(), 10) && first_load===1){
            $.ajax({
                url:'<?= base_url('Admin/progressRequestUser_g')?>',
                type: 'post',
                data: {start_at: start_at},
                dataType: 'json',
                async:true,
                success: function(data){
                    start_at = start_at+pas;
                    var num = <?= $num++; ?>;
                    var active = "";
                    for (var c in data) {
                        if(data[c].etat==1){
                            active = "Oui";
                        }else{
                            active = "Non";
                        }
                        $('table').append('<tr><td>'+data[c].childcat+'</td>   \n' +
                            '                                            <td>\n' +
                            '                                                <button id=\'modal-497395'+num+'\' href=\'#modal-container-497395'+num+'\' class=\'btn btn-default btn-center\' role=\'button\' role=\'button\' data-toggle=\'modal\'>' + data[c].code_parrain + '</button>\n' +
                            '                                                <div class=\'modal fade\' id=\'modal-container-497395'+num+'\' role=\'dialog\' aria-labelledby=\'myModalLabel\' aria-hidden=\'true\'>                \n' +
                            '                                                    <div class=\'modal-dialog\'>\n' +
                            '                                                      <div class=\'modal-content box box-widget widget-user\'>\n' +
                            '                                                        <div class=\'widget-user-header label-primary\'>\n' +
                            '                                                          <h3 class=\'widget-user-username btn-center\'><?= $this->lang->line('Parrain'); ?></h3>\n' +
                            '                                                        </div>\n' +
                            '                                                        <div class="box-footer">\n' +
                            '                                                          <div class="row">\n' +
                            '                                                            <div class="col-sm-4 border-right">\n' +
                            '                                                              <div class="description-block">\n' +
                            '                                                                <h5 class="description-header"><strong><?= $this->lang->line('Catégorie'); ?>: </strong></h5>\n' +
                            '                                                                <span class="description-text">'+data[c].dadcat+'</span>\n' +
                            '                                                              </div>\n' +
                            '                                                            </div>\n' +
                            '                                                            <div class="col-sm-4 border-right">\n' +
                            '                                                              <div class="description-block">\n' +
                            '                                                                <h5 class="description-header"><strong><?= $this->lang->line('Nom'); ?>: </strong></h5>\n' +
                            '                                                                <span class="description-text">'+data[c].suplastname+'</span>\n' +
                            '                                                              </div>\n' +
                            '                                                            </div>\n' +
                            '                                                            <div class="col-sm-4 ">\n' +
                            '                                                                <div class="description-block">\n' +
                            '                                                                    <h5 class="description-header"><strong><?= $this->lang->line('Reseau'); ?> :</strong></h5>\n' +
                            '                                                                    <span class="description-text">'+data[c].sup_network+'</span>\n' +
                            '                                                                </div>\n' +
                            '                                                            </div>\n' +
                            '                                                          </div>\n' +
                            '                                                          <div class=\'row\'>  \n' +
                            '                                                              <div class="col-sm-6 border-right">\n' +
                            '                                                                  <div class="description-block">\n' +
                            '                                                                    <h5 class="description-header"><strong><?= $this->lang->line('code membre'); ?> : </strong></h5>\n' +
                            '                                                                    <span >'+data[c].sup_code_membre+'</span>\n' +
                            '                                                                  </div>\n' +
                            '                                                              </div>\n' +
                            '                                                              <div class="col-sm-6 ">\n' +
                            '                                                                  <div class="description-block">\n' +
                            '                                                                    <h5 class="description-header"><strong><?= $this->lang->line('Code parrain'); ?> :  </strong></h5>\n' +
                            '                                                                    <span >'+data[c].sup_code_parrain+'</span>\n' +
                            '                                                                  </div>\n' +
                            '                                                              </div>\n' +
                            '                                                          </div>\n' +
                            '                                                        </div>\n' +
                            '                                                        <div class=\'modal-footer\'>\n' +
                            '                                                            <button type=\'button\' class=\'btn btn-lg btn-default pull-left\' data-dismiss=\'modal\'><?= $this->lang->line('Fermer'); ?></button>\n' +
                            '                                                        </div>\n' +
                            '                                                      </div>\n' +
                            '                                                    </div>\n' +
                            '                                                </div>\n' +
                            '                                            </td>\n' +
                            '                                            <td>'+data[c].lastname+'</td>\n' +
                            '                                            <td>'+data[c].adresse+'</td>\n' +
                            '                                            <td>'+data[c].network+'</td>\n' +
                            '                                            <td>'+data[c].member_code+'</td>\n' +
                            '                                            <td>'+data[c].solde+'</td>\n' +
                            '                                            <td>'+data[c].email+'</td>\n' +
                            '                                            <td>'+data[c].phone+'</td>\n' +
                            '                                            <td>'+active+'</td>\n');
                        num++;
                    }
                    i++;
                    $('#charger').text(index+pas);
                    first_load++;
                }
            });
        }else{
            $("#loader").hide();
            //alert('Tous les éléments ont été chargés');
            $('#liste_users').DataTable();
        }
    });
</script>
