<?php $usersValidationDecisionsByTimespanStatsData = array_filter(                $usersValidationDecisionsByTimespanStatsData, function($item) {if (array_sum($item['data']) > 0)return true;return false;});; ?>
<?php $searchGateList = ""; ?>
<?php foreach($gates as $gate) { ?>
  <?php if (isset($eventsStatisticsSearchForm->gates) && in_array($gate['ID'], $eventsStatisticsSearchForm->gates)) { ?>
    <?php $searchGateList.= $gate->Descrizione . ", "; ?>
  <?php } ?>
<?php } ?>
<?php $searchGateList = rtrim($searchGateList, ", "); ?>
<?php $encodedApprovedViolationsCountByTimespanStatsData = CJSON::encode($approvedViolationsCountByTimespanStatsData); ?>
<?php $encodedInvalidViolationsCountByTimespanStatsData = CJSON::encode($invalidViolationsCountByTimespanStatsData); ?>
<?php $encodedUsersApprovedViolationsCountByTimespanStatsData = CJSON::encode($usersApprovedViolationsCountByTimespanStatsData); ?>
<?php $encodedUsersInvalidViolationsCountByTimespanStatsData = CJSON::encode($usersInvalidViolationsCountByTimespanStatsData); ?>
<?php $encodedValidationDecisionsByTimespanStatsData = CJSON::encode($validationDecisionsByTimespanStatsData); ?>
<?php $encodedUsersValidationDecisionsByTimespanStatsData = CJSON::encode($usersValidationDecisionsByTimespanStatsData); ?>
<div class="stats-operators-statistics-search-results">
  <div class="print-only" style="margin-left: 1cm;margin-top: 1cm;margin-bottom:2cm">
    <h1 style="text-align:center;margin-bottom: 1cm;">
      <?php echo htmlspecialchars(t('Operators Statistics'),ENT_QUOTES,'UTF-8'); ?>
    </h1>
    <p style="font-size:22px;">
      <strong>
        <?php echo htmlspecialchars(t('Date') . ":",ENT_QUOTES,'UTF-8'); ?>
      </strong>
      <?php echo htmlspecialchars(t('From'),ENT_QUOTES,'UTF-8'); ?>
      <?php echo htmlspecialchars($eventsStatisticsSearchForm->startDateTime,ENT_QUOTES,'UTF-8'); ?>
      <?php echo htmlspecialchars(t('To'),ENT_QUOTES,'UTF-8'); ?>
      <?php echo htmlspecialchars($eventsStatisticsSearchForm->endDateTime,ENT_QUOTES,'UTF-8'); ?>
      <?php if (isset($eventsStatisticsSearchForm->gates)) { ?>
        <br />
        <br />
        <strong>
          <?php echo htmlspecialchars(t('Gates') . ":",ENT_QUOTES,'UTF-8'); ?>
        </strong>
        <?php echo htmlspecialchars($searchGateList,ENT_QUOTES,'UTF-8'); ?>
      <?php } ?>
    </p>
  </div>
  <h3 style="text-align:center">
    <?php echo htmlspecialchars(t('Operators Statistics Overview'),ENT_QUOTES,'UTF-8'); ?>
  </h3>
  <div class="row stats-operators-statistics-overview-container">
    <div class="span12">
      <div id="approved-vs-invalid-violations-trend-graph-container">
        <canvas id="approved-vs-invalid-violations-trend-graph" style="height:70%;width:40%;"></canvas>
      </div>
    </div>
  </div>
  <div class="row stats-operators-statistics-overview-container">
    <div class="span12">
      <div id="users-approved-vs-invalid-violations-graph-container">
        <canvas id="users-approved-vs-invalid-violations-graph" style="height:70%;width:40%;"></canvas>
      </div>
    </div>
  </div>
  <div class="row stats-operators-statistics-overview-container">
    <?php if (array_sum($validationDecisionsByTimespanStatsData) > 0) { ?>
      <div class="span12">
        <div id="approved-vs-invalid-events-reasons-graph-container">
          <canvas id="validation-decisions-trend-graph" style="height:70%;width:40%;"></canvas>
        </div>
      </div>
    <?php } ?>
  </div>
  <div class="display" id="break_page" style="page-break-after:always"></div>
  <div class="stats-operators-statistics-details-container">
    <?php if (!empty($usersValidationDecisionsByTimespanStatsData)) { ?>
      <h3 style="text-align:center">
        <?php echo htmlspecialchars(t('Invalid Violations Reasons Statistics: Users Details'),ENT_QUOTES,'UTF-8'); ?>
      </h3>
      <?php foreach(array_values($usersValidationDecisionsByTimespanStatsData) as $index => $userData) { ?>
        <div class="row">
          <div class="span12">
            <canvas <?php echo MtHaml\Runtime::renderAttributes(array(array('id', ("user-validation-decisions-trend-graph-".$userData['user']['id'])), array('style', 'height:70%;width:40%;')), 'html5', 'UTF-8'); ?>></canvas>
          </div>
        </div>
      <?php } ?>
    <?php } ?>
  </div>
  <input <?php echo MtHaml\Runtime::renderAttributes(array(array('id', 'approved-violations-count-by-timespan-graph-data'), array('type', ('hidden')), array('value', $encodedApprovedViolationsCountByTimespanStatsData)), 'html5', 'UTF-8'); ?> />
  <input <?php echo MtHaml\Runtime::renderAttributes(array(array('id', 'invalid-violations-count-by-timespan-graph-data'), array('type', ('hidden')), array('value', $encodedInvalidViolationsCountByTimespanStatsData)), 'html5', 'UTF-8'); ?> />
  <input <?php echo MtHaml\Runtime::renderAttributes(array(array('id', 'users-approved-violations-count-by-timespan-graph-data'), array('type', ('hidden')), array('value', $encodedUsersApprovedViolationsCountByTimespanStatsData)), 'html5', 'UTF-8'); ?> />
  <input <?php echo MtHaml\Runtime::renderAttributes(array(array('id', 'users-invalid-violations-count-by-timespan-graph-data'), array('type', ('hidden')), array('value', $encodedUsersInvalidViolationsCountByTimespanStatsData)), 'html5', 'UTF-8'); ?> />
  <input <?php echo MtHaml\Runtime::renderAttributes(array(array('id', 'validation-decisions-by-timespan-graph-data'), array('type', ('hidden')), array('value', $encodedValidationDecisionsByTimespanStatsData)), 'html5', 'UTF-8'); ?> />
  <input <?php echo MtHaml\Runtime::renderAttributes(array(array('id', 'users-validation-decisions-by-timespan-graph-data'), array('type', ('hidden')), array('value', $encodedUsersValidationDecisionsByTimespanStatsData)), 'html5', 'UTF-8'); ?> />
</div>
