<?php
session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone = "#tableZone" . $pageSequence;
$tblName = "tblReport" . $pageSequence;
$btAdd = "btnAdd" . $pageSequence;
$btDel = "btnDel" . $pageSequence;
$btDelObj = "btnDelObj" . $pageSequence;
$dataSection = "dataSection" . $pageSequence;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) ;

$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir'] . "veriflog.php");
include($_SESSION['basedir'] . "core.php");

//$res = $dba->getUserDetailByRight($_SESSION['right'], $_SESSION['ownerId'], false, 0, 0);
$res = $dba->getSCCFormsList(0);
?>


<!-- Content Header (Page header) -->
<section class="content-header">
    <div class="header-icon">
        <i class="fa fa-user-circle"></i>
    </div>
    <div class="header-title">
        <h1>Fiches</h1>
        <small>Gestion des fiches</small>
    </div>
</section>
<!-- Main content -->
<div id="<?php echo $dataSection; ?>">
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-bd lobidrag">
                    <div class="panel-heading">
                        <div class="btn-group" id="buttonexport">
                            <a href="#">
                                <h4>Liste des fiches</h4>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">
                        <!-- Plugin content:powerpoint,txt,pdf,png,word,xl -->
                        <div class="btn-group">
                            <button id="<?php echo $btAdd; ?>" class="btn  btn-sm " onclick="getPage('<?php echo $currentBaseDir; ?>/add_edit_forms.php?opId=0&rDiv=<?php echo $dataSection; ?>&rPage=<?php echo $_SERVER['PHP_SELF']; ?>', '<?php echo $dataSection; ?>');" ><i class="cus-add"></i> Ajouter</button>

                        </div>
                        <div class="btn-group">

                            <button class="btn  btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bars"></i> Exporter</button>
                            <ul class="dropdown-menu exp-drop" role="menu">
                               <li>
                                    <a href="#" onclick="$('#<?php echo $tblName; ?>').tableExport({type: 'excel', escape: 'false'});" > ,
                                        <img src="assets/dist/img/xls.png" width="24" alt="logo"> XLS</a>
                                </li>
                                <li>
                                    <a href="#" onclick="$('#<?php echo $tblName; ?>').tableExport({type: 'csv', escape: 'false'});"> 
                                        <img src="assets/dist/img/csv.png" width="24" alt="logo"> CSV</a>
                                </li>
                                <li>
                                    <a href="#" onclick="$('#<?php echo $tblName; ?>').tableExport({type: 'txt', escape: 'false'});"> 
                                        <img src="assets/dist/img/txt.png" width="24" alt="logo"> TXT</a>
                                </li>
                                
                                <li class="divider"></li> 
                            </ul>

                        </div>
                        <div class="btn-group">
                            <button id="<?php echo $btDel; ?>" class="btn  btn-sm "  disabled="disabled" data-href="<?php echo $currentBaseDir; ?>/exec_delete_callreason.php" toDiv="<?php echo $toDiv; ?>" rpage="<?php echo $_SERVER['PHP_SELF']; ?>"  ><i class="cus-delete"></i> Supprimer</button> 
                        </div>
                        <!-- ./Plugin content:powerpoint,txt,pdf,png,word,xl -->
                        <div class="table-responsive">
                            <table id="<?php echo $tblName; ?>" class="table table-striped table-bordered" width="100%" cellspacing="0">
                                <thead>
                                    <tr>
                                        <th width="1%" align="left"></th>
                                        <th width="1%" align="left"></th>
                                        <th width="15%" align="left">Date de création</th>
                                        <th width="23%" align="left">Identifiant</th>
                                         <th width="40%" align="left">Description</th>
                                         <th width="10%" align="left">Lien</th>
                                         <th width="10%" align="left">Créé par</th>
                                    </tr>
                                </thead>
                                <tbody>

                                    <?php
                                    $cmpt = 1;

                                    for ($i = 0; $i < count($res); $i++) {
                                        ?>




                                        <tr>
                                            <td align="left"><input type="checkbox" name="items[]" value="<?php echo $res[$i]['form_id_n']; ?>" class="delete-items" /></td>
                                            <td><a href="#" onclick="getPage('<?php echo $currentBaseDir; ?>/add_edit_forms.php?item=<?php echo $res[$i]['form_id_n']; ?>&opId=1&rDiv=<?php echo $dataSection; ?>&rPage=<?php echo $_SERVER['PHP_SELF']; ?>', '<?php echo $dataSection; ?>');"   title="Modifier" class="cus-application-form-edit" ></a></td>
                                            <td align="left"><?php echo $res[$i]['creation_date_d']; ?></td>
                                            <td align="left"><?php echo $res[$i]['form_name_v']; ?></td>
                                            <td align="left"><?php echo $res[$i]['form_desc_v']; ?></td>
                                            <td align="left"><?php echo $res[$i]['page_link_v']; ?></td>
                                            <td align="left"><?php echo $res[$i]['user_name_v']; ?></td>
                                        </tr>

<?php } ?>


                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </section>
</div>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="plugins/datatables/dataTables.buttons.min.js"></script>
<script src="plugins/datatables/buttons.html5.min.js"></script>
<script type="text/javascript" src="js/jquery.loading.min.js"></script>


<!-- /.content -->
<script type="text/javascript" >
                                        $(document).ready(function () {
                                            var table = $('#<?php echo $tblName; ?>').DataTable({
                                                "language": {
                                                    "search": "Filtrer:",
                                                    "emptyTable": "Table vide",
                                                    "zeroRecords": "Table vide",
                                                    "lengthMenu": "Nombre de lignes  _MENU_ ",

                                                    "info": "Affichage de  _START_ &aacute; _END_ sur  _TOTAL_ entr&eacute;es",
                                                    "paginate": {
                                                        "first": "D&eacute;but",
                                                        "last": "Fin",
                                                        "next": "Suivant",
                                                        "previous": "Pr&eacute;c&eacute;dent"
                                                    },
                                                    "infoEmpty": "Affichage de  0 &agrave; 0 sur  0 entr&eacute;es"
                                                }
                                            });


                                            $('#<?php echo $btDel; ?>').on("click", function (e) {

                                                e.preventDefault();
                                                $.confirm({
                                                    title: 'Attention!',
                                                    content: 'Voulez-vous supprimer les éléments selectionnés?',
                                                    buttons: {
                                                        confirm: {
                                                            text: 'Confirmer',
                                                            btnClass: 'btn-blue',
                                                            action: function () {

                                                                var ids = "";
                                                                table.$('input:checked').each(function ()
                                                                {


                                                                    ids = ids + $(this).val() + ",";
                                                                });
                                                                //  alert(ids);

                                                                $.ajax({
                                                                    url: $('#<?php echo $btDel; ?>').attr('data-href') + "?ids=" + ids,
                                                                    type: 'post',
                                                                    dataType: 'json',
                                                                    success: function (obj) {
                                                                        //alert(data);
                                                                        if (obj.errorCode == 0) {

                                                                            $('#loader').hide();
                                                                            $.confirm({

                                                                                icon: 'glyphicon glyphicon-ok',
                                                                                title: 'RESULTAT',
                                                                                content: obj.errorMessage,
                                                                                type: 'green',
                                                                                typeAnimated: true,
                                                                                buttons: {
                                                                                    confirm: {
                                                                                        text: 'OK',
                                                                                        btnClass: 'btn-blue',
                                                                                        action: function () {

                                                                                            $("#content-wrapper").load('<?php echo $_SERVER['PHP_SELF']; ?>');


                                                                                        }

                                                                                    }}
                                                                            });
                                                                            //  alert(data);


                                                                        } else {

                                                                            $.alert({
                                                                                icon: 'glyphicon glyphicon-warning-sign',
                                                                                title: 'RESULTAT',
                                                                                content: obj.errorMessage,
                                                                                type: 'red',
                                                                                typeAnimated: true
                                                                            });
                                                                        }
                                                                    }
                                                                });
                                                            }},
                                                        cancel: {
                                                            text: 'Annuler',
                                                            action: function () {


                                                            }
                                                        }
                                                    }
                                                });
                                                //$('#sbmt01').submit() ;

                                            });
                                        });
</script>


<script type="text/javascript">





    var checkBoxes = $('tbody .<?php echo $btDelObj; ?>');
    var counterChecked = 0;
    $('body').on('change', 'input[type="checkbox"]', function () {

        this.checked ? counterChecked++ : counterChecked--;
        counterChecked > 0 ? $('#<?php echo $btDel; ?>').prop("disabled", false) : $('#<?php echo $btDel; ?>').prop("disabled", true);
    });

</script>

<script type="text/javascript" src="js/jquery.loading.min.js"></script>
<link rel="stylesheet" href="css/jquery-confirm.min.css">
<script src="js/jquery-confirm.min.js"></script>