<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>iLink </title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="<?= base_url('bower_components/bootstrap/dist/css/bootstrap.min.css') ?>">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<?= base_url('bower_components/font-awesome/css/font-awesome.min.css') ?>">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<?= base_url('bower_components/Ionicons/css/ionicons.min.css') ?>">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?= base_url('dist/css/AdminLTE.css') ?>">

    <link rel="stylesheet" href="<?= base_url('dist/css/main.css') ?>">
    <!-- iCheck -->
    <link rel="stylesheet" href="<?= base_url('plugins/iCheck/square/blue.css') ?>">
    <link rel="shortcut icon" href="<?= base_url('favicon.ico') ?>" type="image/x-icon">
    <link rel="icon" href="<?= base_url('favicon.ico') ?>" type="image/x-icon">
    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

    <style>
        .btn-link,.btn-link:hover{
            color:white;
            text-decoration: none;
        }
        .c{
            margin-left: auto;
            margin-right: auto;
            width: auto;
        }
    </style>
</head>
<body class="hold-transition login-page">
<div class="login-page">
    <!-- form -->
    <div class="form-content">
        <form action="<?= base_url('Admin_dash/firstFilter')?>" method="post" class="bottom-75 center-block">
            <div class="modal-header">
                <h4 class="modal-title"><p><?= $this->lang->line('Appliquer un filtre'); ?></h4>
            </div>
            <div class="table-form">
                <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 "Aucun pays";
                    }
                    ?>
                </div>
                <div class="form-group" id="grp-pays">
                    <?php
                    $result=$hyper;
                    $numrows=$result->num_rows();
                    if ($numrows > 0) { ?>
                        <select class="form-control input-lg" name="hyper" required id="hyper">
                            <?php foreach($result->result() as $row) {
                                echo "<option value='".$row->code_membre."'>".$row->lastname."-".$row->network." (".$row->code_membre.")</option>";
                            } ?>
                        </select>
                    <?php }else{
                        echo "Aucun hyperviseur";
                    }
                    ?>
                </div>
                <div class="form-group" id="grp-ville">
                    <?php
                    $result=$ville;
                    $numrows = 0;
                    if ($result!=null){
                        $numrows=$result->num_rows();
                    }
                    if ($numrows > 0) { ?>
                        <select class="form-control input-lg" name="ville" required id="ville">
                            <?php foreach($result->result() as $row) {
                                echo "<option value='".$row->town_id."'>".$row->town."</option>";
                            } ?>
                        </select>
                    <?php }else{
                        echo "Aucune ville";
                    }
                    ?>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger"><a class="btn-link" href="<?= base_url('Users/logout') ?>"><?= $this->lang->line('Retourner'); ?></a></button>
                <button type="submit" class="btn btn-primary"><?= $this->lang->line('Continuer'); ?></button>
            </div>
        </form>
		<div class="row" style="display: flex; justify-content: center">
			<div class="col-6">
				<button id="gestion_btn" class="btn btn-lg btn-success" style="margin-right: 25px;"><?= $this->lang->line('backoffice_management'); ?></button>
			</div>
			<div class="col-6">
				<a class="btn btn-lg btn-primary" href="<?= base_url('Admin_dash/documentation')?>">Documentation</a>
			</div>
		</div>
    </div>
</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>
<!-- iCheck -->
<script src="<?= base_url('plugins/iCheck/icheck.min.js') ?>"></script>
<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });
</script>
<script type='text/javascript'>
    $(document).ready(function(){
        $('#gestion_btn').click(function(){
            window.location.href = "<?= base_url('Gestion') ?>";
        });

        $('#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>
</body>
</html>
