<?php 
include('config.php');
$statType = 'MONTHLY';
if(hasAccessTo($statType)){
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Statistiques mensuelles</title>
    <?php include('include/css.php') ?>
</head>

<body>
    <?php include('header.php') ?>
    <?php 
    $filterAgencies = ((isset($GLOBALS["STATS_CONF"]["CLOISONNEMENT"]) && $GLOBALS["STATS_CONF"]["CLOISONNEMENT"]) || ($_SESSION['user'] == "admin" && $_SESSION["profil"] != 100)) ? true : false;
    $profils_access = $GLOBALS["BO_CONF"]["ACCESS_PROFILES"]["CHARTS"] ? $GLOBALS["BO_CONF"]["ACCESS_PROFILES"]["CHARTS"] : array('1','2','10');
    $filter = ((!hasAccess(false,true) || (isset($_SESSION['profil']) && in_array($_SESSION["profil"], $profils_access))) && $filterAgencies) ? (' AND id_agence IN ('.getAllowedAgencies().')') : '';
    $result = excuteQuery('select nom_agence, id_agence, code_agence  from '.AGENCIES_TABLE.' where supp = 0'.$filter.' and is_active = 1 order by nom_agence');
    ?>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12 col-lg-12 title card-box">
                <form autocomplete="off" class="form-inline monthly-inline-form" id="chart_filter" method="post">
                    <div class="form-group col-lg-3 col-md-6 col-sm-12">
                        <label for="agence" class="inline-form-label">Agence :</label>
                        <select class="form-control" id="agence" name="agence">
                            <option value="">-- Sélectionner --</option>
                            <?php if($GLOBALS["STATS_CONF"]["CAPCA_AMS_DR"]){?><option value="-1" style="background-color: #ddd;">RESEAU DE PROXIMITE</option><?php } ?>
                            <?php while($row = $result['stmt']->fetch(PDO::FETCH_ASSOC)){ ?>
                            <option value="<?= $row['id_agence']?>" <?php if($_SESSION['user'] == 'conseiller' && $_SESSION['agence'] == $row['id_agence']) echo 'selected'; ?>>
                                <?= $row['nom_agence']?>
                            </option>
                            <?php } ?>
                        </select>
                    </div>
                    <div class="form-group col-lg-3 col-md-6 col-sm-12">
                        <label for="jour" class="inline-form-label">Année :</label>
                        <input type="file" class="form-control date_picker_year" id="jour" placeholder="Sélectionner une année"
                            name="jour" autocomplete="new-password">
                    </div>
                    <div class="form-group col-lg-3 col-md-6 col-sm-12">
                        <label for="mois" class="inline-form-label">Mois :</label>
                        <input type="text" class="form-control date_picker_month w-75" id="mois" placeholder="Sélectionner mois"
                            name="mois" autocomplete="off">
                    </div>
                    <div class="form-group col-lg-2 col-md-6 col-sm-12">
                        <button type="submit" class="btn btn-primary ld-ext-right" id="submit-btn"> Soumettre <div class="ld ld-ring ld-spin"></div></button>
                    </div>
                </form>
            </div>
        </div>
        <div class="row display-none chart-summery">
            <div class="card-box col-md-12 col-lg-12">
                <div class="row">
                    <h6 class="col-sm-12 col-md-4 col-lg-4 mt-1 mb-0 boldfont">
                        STATISTIQUES MENSUELLES
                    </h6>
                    <h6 class="col-sm-12 col-md-4 col-lg-4 agence-name mt-1 mb-0 boldfont">
                    </h6>
                    <h6 class="col-sm-12 col-md-4 col-lg-4 generate-time mt-1 mb-0 boldfont">
                    </h6>
                </div>
            </div>
        </div>
        <div class="row chart-result-summery">
            <div class="card-box col-md-12 col-lg-12 ">
                <div id="cardValue"></div>
            </div>
        </div>
        <div class="row display-none chart-div">
            <div class="card-box-chart col-md-12 col-lg-12">
                <h5 class="textcenter  header-title m-t-0 m-b-30">Nombre de visites mensuelles (par jour)</h5>
                <div class="widget-chart pull-in text-center">
                    <div id="chart_div1" class="chartMinhight"></div>
                </div>
            </div>
        </div>
        <div class="row display-none chart-div">
            <div class="card-box-chart col-md-12 col-lg-12 ">
                <h5 class="textcenter header-title m-t-0 m-b-30">Part des RDV (taux mensuel)</h5>
                <div class="widget-chart pull-in text-center">
                    <div id="chart_div2" class="chartMinhight"></div>
                </div>
            </div>
        </div>
        <div class="row display-none chart-div">
            <div class="card-box-chart col-md-12 col-lg-12 ">
                <h5 class="textcenter  header-title m-t-0 m-b-30">Part des RDV (par jour)</h5>
                <div class="widget-chart pull-in text-center">
                    <div id="chart_div3" class="chartMinhight"></div>
                </div>
            </div>
        </div>
        <div class="row display-none chart-div">
            <div class="card-box-chart col-md-12 col-lg-12 ">
                <h5 class="textcenter  header-title m-t-0 m-b-30">Durées moyennes d'attente (minutes)</h5>
                <div class="widget-chart pull-in text-center">
                    <div id="chart_div4" class="chartMinhight"></div>
                </div>
            </div>
        </div>
        <div class="row display-none chart-div">
            <div class="card-box-chart col-md-12 col-lg-12 ">
                <h5 class="textcenter  header-title m-t-0 m-b-30">Durées moyennes d'entretien (minutes)</h5>
                <div class="widget-chart pull-in text-center">
                    <div id="chart_div5" class="chartMinhight"></div>
                </div>
            </div>
        </div>
    </div>
    <!-- /.container -->
    <!-- Bootstrap core JavaScript -->
    <?php include('include/js.php') ?>
    <script type="text/javascript" src="chartjs/monthlyChart.js?123"></script>
<?php
}
else{
?>
	<h2>Vous n'&ecirc;tes pas autoris&eacute; &agrave; acc&eacute;der &agrave; cette page !</h2>
<?php
}
?>
</body>
</html>