<?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;
$frmName = "form" . $pageSequence;

$startDateTimeName = "startDate" . $pageSequence;
$endDateTimeName = "endDate" . $pageSequence;

$startDate = date('Y-m-d') . " 00:00:00";
$endDate = date('Y-m-d') . " 23:59:59";

$rPage = $_REQUEST['rPage'];
$rDiv = $_REQUEST['rDiv'];
if (isset($_REQUEST['opId'])) {
    $opId = $_REQUEST['opId'];
}

$_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);
?>

<!-- Main content -->
<div id="<?php echo $dataSection; ?>">
    <section class="content">
        <div class="row">
            <div class="col-sm-8">
                <div class="panel panel-bd lobidrag">
                    <div class="panel-heading">
                        <div class="btn-group">
                            <a href="#">
                                <h4>Statistiques des prestataires</h4>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">


                        <form action="<?php echo $currentBaseDir; ?>/get_scc_prestataire_type.php"  method="post" onsubmit="return false;" id="<?php echo $frmName; ?>">

                            <div class="col-sm-4" >



                                <div class="form-group">
                                    <label>Date de début</label>
                                    <div class="form-group">

                                        <div class='input-group date' id='<?php echo $startDateTimeName; ?>'>
                                            <input name="startDateTime" type='text' class="form-control" id="startDateTime"  value="<?php echo $startDate; ?>" size="10"/>
                                            <span class="input-group-addon">
                                                <span class="glyphicon glyphicon-calendar"></span>
                                            </span>
                                        </div>


                                    </div>
                                </div>




                                <div class="form-group">
                                    <label>Date de fin</label>
                                    <div class="form-group">
                                        <div class='input-group date' id='<?php echo $endDateTimeName; ?>'>
                                            <input name="endDateTime" type='text' class="form-control" id="endDateTime"  value="<?php echo $endDate; ?>" size="10"/>
                                            <span class="input-group-addon">
                                                <span class="glyphicon glyphicon-calendar"></span>
                                            </span>
                                        </div>
                                    </div>
                                </div>



                                <div class="reset-button">
                                    <button   type="submit" class="btn addition">Afficher</button>  <button type="button" class="btn close-btn" >Fermer</button>
                                </div>


                            </div>

                            <div class="col-sm-4" >




                                <div class="form-group">
                                    <label>Granularité</label>
                                    <select name="granularity" id="granularity" class="form-control">
                                        <option value="%d/%m/%Y %H" >Heure</option>
                                        <option value="%d/%m/%Y" selected="selected" >Jour</option>
                                        <option value="%m/%Y" >Mois</option>



                                    </select>
                                </div>
                             






                            </div>


                        </form>

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

    </section>

    <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>Résultats</h4>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">

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

                        <!-- ./Plugin content:powerpoint,txt,pdf,png,word,xl -->
                        <div class="table-responsive">

                            <table id="<?php echo $tblName; ?>"  width="100%" height="100%" class="table table-striped table-bordered" >
                                <thead>
                                    <tr>
                                        <th>Date</th>
                                        <th>Type de prestataire</th>
                                        <th>Total</th>
                                    </tr>
                                </thead>
                            </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 () {
                                            
                                             $(function () {
        $('#<?php echo $startDateTimeName; ?>').datetimepicker({format: 'yyyy-mm-dd hh:ii:ss', autoclose: true, language: 'fr'});



    });



    $(function () {
        $('#<?php echo $endDateTimeName; ?>').datetimepicker({format: 'yyyy-mm-dd hh:ii:ss', autoclose: true, language: 'fr'});
    });



                                            var dataUrl = "<?php echo $currentBaseDir; ?>/return_json_default.php?json=[]";
                                            table = $('#<?php echo $tblName; ?>').DataTable({
                                                ajax: {
                                                    url: dataUrl,
                                                    method: "POST",
                                                    dataSrc: ''
                                                },
                                                columns: [
                                                    {data: "Date"},
                                                    {data: "Name"},
                                                    {data: "Total"}
                                                ]
                                                ,
                                                processing: true
                                                ,
                                                "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"
                                                }
                                            });



                                        });
</script>


<script type="text/javascript">


    $(".close-btn").on('click', function () {
        // create the backdrop and wait for next modal to be triggered
        // $('body').modalmanager('loading');
        $('#loader').loading({
            message: "Chargement...",
            theme: 'dark'

        });

        $("#content-wrapper").load("<?php echo $rPage; ?>");
        $('#loader').loading('stop');

    });




    $('#<?php echo $frmName; ?>').on("submit", function (event) {
        $('#loader').loading({
            message: "Chargement...",
            theme: 'dark'

        });
        var tableStats = $("form").attr('tableStats');
        var chartStats = $("form").attr('chartStats');
        /* var startDateTime = document.getElementById('startDateTime').value;
         var endDateTime = document.getElementById('endDateTime').value;
         var userId = document.getElementById('userId').value;
         var status = document.getElementById('status').value;
         var statsMode = document.getElementById('statsMode').value;
         */

        ///alert(tableStats + "   " + chartStats );

        $.post($(this).attr("action"), $(this).serialize(), function (data) {


            table.clear();
            table.rows.add(JSON.parse(data));
            table.draw();

            $('#loader').loading('stop');
            /*
             if ( $.fn.dataTable.fnIsDataTable( '#tblGlobalStats' ) ){
             //alert("Alload");
             // reload instead
             
             
             }
             else {
             
             
             
             } */

        });







        // return false; // prevent normal submit
        event.preventDefault();

    });



   

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

