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

        <h1>
            <?= $this->lang->line('Géolocalisation'); ?>
        </h1>
        <?php
        $site_url = base_url();

        if($alert=="ok") {

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

                <?php
            } else {
                ?>
                <div class="alert alert-success alert-dismissible col-xs-6">
                    <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
            }
        }
        ?>
    </section>

    <section class="content">
        <div class="box box-danger">
            <div class="box-header with-border">
                <h3 class="box-title"><?= $this->lang->line('Agent'); ?></h3>
            </div>
            <div class="box-body">
                <form name="form_login"  action="<?= base_url('Gestion/infos_geolocalisation') ?>" method="post">
                    <div class="row">
                        <div class="col-xs-3">
                            <div class="form-group">
                                <?php
                                $result=$pays;
                                $numrows=$result->num_rows();
                                if ($numrows > 0) { ?>
                                    <select class="form-control input-lg" name="pays" required id="pays">
                                        <?php foreach($result->result() as $row) {
                                            echo "<option value='".$row->id."'>".$row->name."</option>";
                                        } ?>
                                    </select>
                                <?php }else{
                                    echo $this->lang->line('Aucun pays');
                                }
                                ?>
                            </div>
                        </div>
                        <div class="col-xs-3">
                            <div class="form-group" id="grp-ville">
                                <?php
                                $result=$villes;
                                $numrows=$result->num_rows();
                                if ($numrows > 0) { ?>
                                    <select class="form-control input-lg" name="ville" required id="ville">
                                        <option value='<?= $active_ville_id ?>'><?= $active_ville_name ?></option>
                                        <?php foreach($result->result() as $row) {
                                            if($row->id!=$active_ville_id){
                                                echo "<option value='".$row->id."'>".$row->name."</option>";
                                            }
                                        } ?>
                                    </select>
                                <?php }else{
                                    echo $this->lang->line('Aucune ville');
                                }
                                ?>
                            </div>
                        </div>
                        <div class="col-xs-3">
                            <div class="form-group" id="grp-agent">
                                <?php
                                $result=$agent;
                                if($result!=false){
                                    $numrows=$result->num_rows();
                                    if ($numrows > 0) { ?>
                                        <select class="form-control input-lg" name="agent" required id="agent">
                                            <?php foreach($result->result() as $row) {
                                                echo "<option value='".$row->lastname."'>".$row->lastname."</option>";
                                            } ?>
                                        </select>
                                    <?php }else{
                                        echo $this->lang->line('Aucun agent');
                                    }
                                }else{
                                    echo $this->lang->line('Aucun agent');
                                }
                                ?>
                            </div>
                        </div>
                        <div class="col-xs-3">
                            <input class="btn btn-block btn-danger" name='b'  type='submit'  value='<?= $this->lang->line('Voir les détails'); ?>'/>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="box box-danger">
            <div class="box-header with-border">
                <h3 class="box-title"><?= $current_agent; ?></h3>
            </div>
            <div class="box-body">
                <div class="row">
            <?php
            $recap = 0;
            for($i=0; $i < $total; ++$i) {
                echo "<div class='col-lg-3 col-xs-6'>
                    <div class='small-box bg-aqua'>
                        <div class='inner'>
                            <h3>".$number_geolocalisation[$i]."</h3>
                            <p>".$network_geolocalisation[$i]."</p>
                        </div>
                        <div class='icon'>
                            <i class='ion ion-person-add'></i>
                        </div>
                    </div>
                </div>";
                $recap = $recap + $number_geolocalisation[$i];
                }
            echo "<div class='col-lg-3 col-xs-6'>
                    <div class='small-box bg-red'>
                        <div class='inner'>
                            <h3>".$recap."</h3>
                            <p>Total</p>
                        </div>
                        <div class='icon'>
                            <i class='ion ion-person-add'></i>
                        </div>
                    </div>
                </div>";
            ?>
        </div>
            </div>
    </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="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.js"></script>

<script>
    $('#pays').change(function(){
        var pays = $(this).val();
        $.ajax({
            url:'<?= base_url('Gestion/getVilleByPays')?>',
            type: 'post',
            data: {pays: pays},
            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].id + "'>" + list[i].name +"</option>");
                    }

                    var id_ville = list[0].id;

                    $.ajax({
                        url:'<?= base_url('Gestion/getAgentByVilles')?>',
                        type: 'post',
                        data: {id_ville: id_ville},
                        dataType: 'json',
                        success: function(list){
                            var len = list.length;

                            if(len > 0){

                                var select = document.getElementById('agent');

                                $(select).empty();

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


                            }else{

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

                            }

                        }
                    });


                }else{

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

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

            }
        });
    });

    $('#ville').change(function(){
        var ville = $(this).val();
        $.ajax({
                        url:'<?= base_url('Gestion/getAgentByVilles')?>',
                        type: 'post',
                        data: {id_ville: ville},
                        dataType: 'json',
                        success: function(list){
                            var len = list.length;

                            if(len > 0){

                                var select = document.getElementById('agent');

                                $(select).empty();

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


                            }else{

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

                            }

                        }
                    });
        });

</script>
