<?php
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', '1');
?>
<?php include('config.php');?>
<?php 
$statType = 'STANDARD';
if(hasAccessTo($statType)){

include('standard_fetch.php');
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta name="description" content="">
	<meta name="author" content="">
	<title>Rapport standard</title>
	<?php include('include/css.php'); ?>
  <link rel="stylesheet" type="text/css" href="../dcc/assets/js/datatables/datatables.min.css"/>
  <link rel="stylesheet" href="css/standard.css">
</head>

<body ng-app="stats">
<?php 
    include('header.php');
?>
<div class="container-fluid" ng-controller="StatsCtrl" ng-init="init(<?php echo htmlspecialchars(json_encode($dataForJS)) ?>)">
  <div class="row">
    <fieldset class="col-md-12 col-lg-12 title card-box">     
      <form id="table_filter" name="table_form" method="GET">        
        
          <div class="form-group row">
            <label for="level_filter" class="col-sm-1 col-form-label">Agence:</label>
            <div class="col-sm-11">
              <select class="form-control" id="level_filter" name="level_filter" ng-model="level_filter">
                <?php echo getDropDownData($levels,$filterAgencies);?>
              </select>
            </div>
          </div>
        
          <div class="form-group row mt-3">
            <label for="date_preset" class="col-sm-1 col-form-label">Période:</label>
            <div class="col-sm-11">
              <select id="date_preset" class="form-control ng-pristine ng-valid ng-not-empty ng-touched" name="date_preset" ng-model="date_preset" ng-value="date_preset">
								<option value="today">Aujourd'hui</option>
								<option value="yesterday">Hier</option>
								<option value="current-week">Cette semaine</option>
								<option value="last-week">La semaine dernière</option>
								<option value="last-7-days">7 derniers jours</option>
								<option value="current-month">Ce mois-ci</option>
								<option value="last-month">Le mois dernier</option>
								<option value="last-30-days">30 derniers jours</option>
								<option value="current-year">Cette année</option>
								<option value="last-year">L'année dernière</option>
                <option value="custom-year">Comparaison par année</option>
								<option value="custom">Personnalisée</option>
							</select>
            </div>
          </div>

        <div class="form-group row mt-3" ng-show="date_preset == 'custom'">
          <div class="col pl-0">
            <div class="row p-0">
              <label for="start" class="col-sm-2 col-form-label">Début:</label>
              <div class="col-sm-10 pl-0">
                <!-- <input type="text" class="form-control date_picker mx-sm-3" id="start" placeholder="Sélectionner une date" autocomplete="off" ng-model="startDate" ng-value="startDate | date : 'dd/MM/yyyy'"> -->
                <input type="text" id="start" class="form-control mx-sm-3" uib-datepicker-popup="shortDate" ng-model="startDate" ng-focus="startDateOpen=true; endDateOpen=false;" show-button-bar="false" datepicker-options="datePickerOptions" is-open="startDateOpen" ng-required="date_preset=='custom'" close-text="Fermer" />
								<input type="hidden" name="start" ng-value="startDate | date : 'yyyy-MM-dd'">
              </div>
            </div>
          </div>

          <div class="col">
            <div class="row pr-0">
              <label for="end" class="col-sm-2 col-form-label">Fin:</label>
              <div class="col-sm-10 pl-0">
                <input type="text" id="end" class="form-control mx-sm-3" uib-datepicker-popup="shortDate" ng-model="endDate" ng-focus="startDateOpen=false; endDateOpen=true;" show-button-bar="false" datepicker-options="datePickerOptions" is-open="endDateOpen" ng-required="date_preset=='custom'" close-text="Fermer" />
								<!-- <input type="text" class="form-control date_picker mx-sm-3" id="end" placeholder="Sélectionner une date" autocomplete="off" ng-model="endDate" ng-value="endDate | date : 'dd/MM/yyyy'"> -->
                <input type="hidden" name="end" ng-value="endDate | date : 'yyyy-MM-dd'">
              </div>
            </div>
          </div>
        </div>

        
        <div class="form-group row mt-3" ng-show="date_preset == 'custom-year'">
          <div class="col pl-0">
            <div class="row p-0">
              <label for="start" class="col-sm-2 col-form-label">Début:</label>
              <div class="col-sm-10 pl-0">
                <select id="startYear" class="form-control  mx-sm-3" ng-model="startYear" ng-options="n for n in [] | range:2014:<?php echo date('Y')?>"></select>
                <input type="hidden" name="startYear" ng-value="startYear"/>
              </div>
            </div>
          </div>

          <div class="col">
            <div class="row pr-0">
              <label for="end" class="col-sm-2 col-form-label">Fin:</label>
              <div class="col-sm-10 pl-0">
                <select id="endYear" class="form-control  mx-sm-3" ng-model="endYear" ng-options="n for n in [] | range:startYear:<?php echo date('Y')?>"></select>
                <input type="hidden" name="endYear" ng-value="endYear"/>
              </div>
            </div>
          </div>
        </div>

        <fieldset class="form-group mt-3">
          <div class="row">
            <legend class="col-form-label col-sm-1 pt-0">RDV</legend>
            <div class="col-sm-11">
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="rdv" id="all" value="" <?php echo empty($_REQUEST["rdv"]) ? "checked" : "";?> >
                <label class="form-check-label" for="all">
                  RDV + SRDV
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="rdv" id="rdv" value="rdv" <?php echo (!empty($_REQUEST["rdv"]) && $_REQUEST["rdv"]=="rdv") ? "checked" : "";?>>
                <label class="form-check-label" for="rdv">
                  RDV
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="rdv" id="srdv" value="srdv" <?php echo (!empty($_REQUEST["rdv"]) && $_REQUEST["rdv"]=="srdv") ? "checked" : "";?>>
                <label class="form-check-label" for="srdv">
                 SRDV
                </label>
              </div>
            </div>
          </div>
        </fieldset>
        <?php if($nfc_enabled){?>
        <fieldset class="form-group mt-3">
          <div class="row">
            <legend class="col-form-label col-sm-1 pt-0">NFC</legend>
            <div class="col-sm-11">
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="checkbox" name="nfc" id="nfc" ng-model="nfc" ng-checked="nfc" <?php echo isset($_REQUEST["nfc"]) ? "checked" : "";?>>
                <label class="form-check-label">
                NFC
                </label>
              </div>
            </div>
          </div>
        </fieldset>
        <?php } ?>

        <?php if($motifs_enabled){?>
        <fieldset class="form-group mt-3">
          <div class="row">
            <legend class="col-form-label col-sm-1 pt-0">Motifs</legend>
            <div class="col-sm-11">
              <?php foreach($motifs as $motif){ ?>                
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="checkbox" name="presta_split[]" value="<?php echo $motif["id_motif"];?>" <?php echo (!empty($_REQUEST["presta_split"]) && in_array($motif["id_motif"],$_REQUEST["presta_split"])) ? "checked" : "";?>>
                <label class="form-check-label" for="presta_split[]">
                <?php echo $motif["titre"]; ?>
                </label>
              </div>
              <?php } ?>
            </div>
          </div>
        </fieldset>
        <?php } ?>

        <div class="form-row col">
          <label class="form-check-label">Une ligne par: </label>
        </div>       
        <hr/> 

        <fieldset class="form-group mt-3">
          <div class="row">
            <div class="col-sm-11">
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" value="non_split" id="non_split" <?php echo empty($_REQUEST["split_mode"]) ? "ng-checked='true'" : "";?>>
                <label class="form-check-label">
                  Total uniquement
                </label>
              </div>
            </div>
          </div>
        </fieldset>

        <fieldset class="form-group mt-3">
          <div class="row">
            <div class="col-sm-11">
              <?php 
              foreach($levels as $level){
              ?>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="<?php echo $level;?>" value="<?php echo $level;?>" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]==$level) ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="<?php echo $level;?>">
                  <?php echo ucfirst($level);?>
                </label>
              </div>
              <?php
              }
              ?>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="agence" value="agence" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="agence") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="agence">
                  Agence
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="conseiller" value="conseiller" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="conseiller") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="conseiller">
                 Conseiller
                </label>
              </div>
            </div>
          </div>
        </fieldset>

        <fieldset class="form-group mt-3">
          <div class="row">
            <div class="col-sm-11">
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="day" value="day" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="day") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="day">
                  Date
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="week" value="week" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="week") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="week">
                  Semaine
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="month" value="month" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="month") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="month">
                  Mois
                </label>
              </div>
              
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="dow" value="dow" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="dow") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="dow">
                  Jour de la semaine
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="hour" value="hour" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="hour") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="hour">
                  Heure
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="half_hour" value="half_hour" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="half_hour") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="half_hour">
                  Demi heure
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="dow_hour" value="dow_hour" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="dow_hour") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="dow_hour">
                  Jour de la semaine + heure
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="split_mode" ng-model="split_mode" id="dow_half_hour" value="dow_half_hour" data-split-type="time_split" <?php echo (!empty($_REQUEST["split_mode"]) && $_REQUEST["split_mode"]=="dow_half_hour") ? "ng-checked='true'" : "";?>>
                <label class="form-check-label" for="dow_half_hour">
                  Jour de la semaine + demi heure
                </label>
              </div>
            </div>
          </div>
        </fieldset>
        
        <div class="form-row col" ng-show="split_mode == 'conseiller'">
          <label class="form-check-label">Prise de RDV : </label>
        </div>
        <hr/>

        <fieldset class="form-group mt-3" ng-show="split_mode == 'conseiller'">
          <div class="row">
            <div class="col-sm-11">              
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="action_split" value="id_conseiller"  <?php echo (!empty($_REQUEST["action_split"]) && $_REQUEST["action_split"] == "id_conseiller") ? "checked" : "";?>>
                <label class="form-check-label" for="count">
                  Conseiller demandé
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="action_split" value="id_action" <?php echo (!empty($_REQUEST["action_split"]) && $_REQUEST["action_split"] == "id_action") ? "checked" : "";?>>
                <label class="form-check-label" for="rdv_count">
                  Conseiller qui a pris en charge
                </label>
              </div>
            </div>
          </div>
        </fieldset>

        <div class="form-row col">
          <label class="form-check-label">Grapher: </label>
        </div>
        <hr/>

        <fieldset class="form-group mt-3">
          <div class="row">
            <div class="col-sm-11">              
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="count" value="count"  <?php echo (empty($_REQUEST["graph_mode"]) || $_REQUEST["graph_mode"] == "count") ? "checked" : "";?>>
                <label class="form-check-label" for="count">
                  Nombre de visiteurs
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="rdv_count" value="rdv_count" <?php echo (!empty($_REQUEST["graph_mode"]) && $_REQUEST["graph_mode"] == "rdv_count") ? "checked" : "";?>>
                <label class="form-check-label" for="rdv_count">
                  RDV/SRDV (nombre)
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="rdv_percent" value="rdv_percent" <?php echo (!empty($_REQUEST["graph_mode"]) && $_REQUEST["graph_mode"]=="rdv_percent") ? "checked" : "";?>>
                <label class="form-check-label" for="rdv_percent">
                  RDV/SRDV (%)
                </label>
              </div>
              <?php if($motifs_enabled){ ?>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="presta_count" value="presta_count" <?php echo (!empty($_REQUEST["graph_mode"]) && $_REQUEST["graph_mode"] == "presta_count") ? "checked" : "";?>>
                <label class="form-check-label" for="presta_count">
                  Motif (nombre)
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="presta_percent" value="presta_percent" <?php echo (!empty($_REQUEST["graph_mode"]) && $_REQUEST["graph_mode"]=="presta_percent") ? "checked" : "";?>>
                <label class="form-check-label" for="presta_percent">
                Motif (%)
                </label>
              </div>
              <?php } ?>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="dma" value="dma" <?php echo (!empty($_REQUEST["graph_mode"]) && $_REQUEST["graph_mode"]=="dma") ? "checked" : "";?>>
                <label class="form-check-label" for="dma">
                  DMA
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="dme" value="dme" <?php echo (!empty($_REQUEST["graph_mode"]) && $_REQUEST["graph_mode"]=="dme") ? "checked" : "";?>>
                <label class="form-check-label" for="dme">
                  DME
                </label>
              </div>
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="radio" name="graph_mode" id="dma-dme" value="dma-dme" <?php echo (!empty($_REQUEST["graph_mode"]) && $_REQUEST["graph_mode"]=="dma-dme") ? "checked" : "";?>>
                <label class="form-check-label" for="dma-dme">
                  DMA + DME
                </label>
              </div>
            </div>
          </div>
        </fieldset>
        
        <?php if($GLOBALS["BO_CONF"]["HIERARCHICAL"]["ENABLED"]){?>

        <div class="form-row col">
          <label class="form-check-label">Comparatif hiérarchique: </label>
        </div> 
        <hr/>

        <fieldset class="form-group mt-3">
          <div class="row">
            <div class="col-sm-11">
              <div class="form-check custom-control-inline">
                <input class="form-check-input" type="checkbox" name="hierarchical_mode" id="hierarchical_mode" ng-model="hierarchical_mode" ng-checked="hierarchical_mode" <?php echo isset($_REQUEST["hierarchical_mode"]) ? "checked" : "";?>>
                <label class="form-check-label">
                Comparatif hiérarchique
                </label>
              </div>
            </div>
          </div>
        </fieldset>
        <?php } ?>

        <div class="form-row mt-3 d-flex align-items-end flex-column">
            <button type="submit" class="btn btn-primary"> Soumettre </button>   
        </div> 
      </form> 
    </fieldset>
         
    <div class="row display-none table-summary">
    	<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">
            STATISTIQUES RECAP
          </h6>
        </div>          
      </div>
    </div>

  <div class="table-result-summary card">
    <div class="row">
        <div class="col text-center" id ="recap-table">    
            <?php echo (isset($_REQUEST["agence"]) && !$table) ? "Pas de résultat." : $table;?>
        </div>
    </div>
  </div>
  
  <div class="card-box-chart col-md-12 col-lg-12 mt-3">
    <h5 class="textcenter  header-title m-t-0 m-b-30">Visualisation graphique</h5>
    <div class="widget-chart pull-in text-center">
      <div id="chart_div" class="chartMinhight"></div>
    </div>
  </div>
</div>


<div class="spacer">&nbsp;</div>

<!-- /.container -->
<!-- Bootstrap core JavaScript -->
<?php include('include/js.php') ?>
<script type="text/javascript" src="/statistiques/dcc/assets/js/datatables/tableHeadFixer.js"></script>
<script type="text/javascript" src="/statistiques/dcc/assets/js/datatables/datatables.min.js"></script>
<script type="text/javascript" src="/statistiques/dcc/assets/js/daterangepicker/moment.min.js"></script>
<script type="text/javascript" src="/statistiques/dcc/assets/js/daterangepicker/daterangepicker.js"></script>
<!-- bower:js -->
<script type="text/javascript" src="/statistiques/bower_components/angular/angular.js"></script>
<script type="text/javascript" src="/statistiques/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<!-- endbower -->
<script type="text/javascript" src="/statistiques/bower_components/angular-i18n/angular-locale_fr-fr.js"></script>
<script type="text/javascript" src="./chartjs/standardApp.js"></script>
<script type="text/javascript" src="./chartjs/standard.js"></script>
<?php
}
else{
?>
	<h2>Vous n'&ecirc;tes pas autoris&eacute; &agrave; acc&eacute;der &agrave; cette page !</h2>
<?php
}
?>
</body>
</html>