<?php
 if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();}
 global $config;
 require_once 'config/class/class.database.php';
 $db = new database();

 require_once 'config/class/class.memberspace.php';
 $member = new member_space();

 if (!$member->isadmin()) header("Location: ".$config['app_url']."admin-login");
 if (!empty($_SESSION['aid']) && $_SESSION['aid']>90) header("Location: ".$config['app_url']."special-adm");
 if ($_SESSION['aid']>3) header("Location: ".$config['app_url']."admin-lista");
?>

<?php $_shouldextend[1]=1; ?>


<?php $this->startSection('wisra_basic_content'); ?>
 @parentXYZABC

<div class="body-content js-body-content blue-body">
 <main id="main" class="violiii">
 <div class="standings-background-hero">
 <picture class="standings-background-hero__pattern left js-lazy-picture loaded">
 <img src="<?php echo $config['app_url'] ?>sources/image/admin/stripes-left.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/admin/stripes-left.png" alt="Standings Background Pattern">
 </picture>
 <picture class="standings-background-hero__pattern right js-lazy-picture loaded">
 <img src="<?php echo $config['app_url'] ?>sources/image/admin/stripes-right.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/admin/stripes-right.png" alt="Standings Background Pattern">
 </picture>
 </div>
 <div class="u-main-gradient admin-blocks">
 <div class="wrapper">
 <div class="col-12">
 <section class="standings">
 <div class="standings__header">
 <div class="standings-header admin">
 <div class="fixture-result-list__month-full">
 <span>Les</span> statistiques par année
 </div>
 </div>
 </div>

 <div class="standings__content js-standings-content">
 <section class="standings-league js-standings-pane">

 <div class="standings-league__header standings-pane-header">
 <div class="standings-pane-header__spacer"></div>
 <div class="standings-pane-header__info">
 </div>
 <span class="standings-pane-header__name visually-hidden"></span>
 <div class="standings-pane-header__time-info">
 <div class="standings-pane-header__last-updated"> 
 Chargement des statistiques : <?php echo $config['smib_annee_encours'];?>
 </div>
 <div class="standings-pane-header__season-info-container">
 <span class="standings-pane-header__season-info js-season-info"> type: </span>
 <span class="standings-pane-header__match-week-info js-match-week-info"> Tout </span>
 </div>
 </div>
 </div>

 <table class="standings-league__table standings-table">
 <thead class="standings-table__head">
 <tr>
<?php 
 $headras = array(
 array('Année', 'Hommes 21Km', 'Dames 21Km', 'Total'), 
 array('Année', 'Hommes 21Km', 'Dames 21Km', 'Total')
 );
 foreach ($headras[0] as $x => $value) {
 echo '
 <th class="table-head" scope="col">
 <span class="table-head__heading">'.$value.'</span>
 <span class="table-head__heading--short">'.$headras[1][$x].'</span>
 </th>
 ';
 }
?>
 </tr>
 </thead>
 <tbody class="standings-table__body">
<?php
 $j=$total_h=$total_f=$total=0;
 for ($i=date('Y'); $i > 2007; $i--) {
 if ($i!=2020 && $i>2018) {
 $req = "SELECT
 (SELECT COUNT(*) FROM member A INNER JOIN member_particip B ON B.membre=A.id WHERE B.annee=:i AND A.sex=1 AND B.course=1 AND B.dossard>0) AS total_h, 
 (SELECT COUNT(*) FROM member A INNER JOIN member_particip B ON B.membre=A.id WHERE B.annee=:i AND A.sex=0 AND B.course=1 AND B.dossard>0) AS total_f, 
 (SELECT COUNT(*) FROM member A INNER JOIN member_particip B ON B.membre=A.id WHERE B.annee=:i AND B.course=1 AND B.dossard>0) AS total;
 ";
 $arg = compact('i');
 $donnee = $db->select($req, $arg, false);
 if ($donnee['total']>0) $j++;
 $total_h+=$donnee['total_h'];
 $total_f+=$donnee['total_f'];
 $total+=$donnee['total'];
 if ($donnee['total']>0) {
?>
 <tr class="table-standings-row">
 <td class="table-stat-row "> <?php echo $i ?> </td>
 <td class="table-stat-row table-stat-row--points"> <?php echo $donnee['total_h'] ?> </td>
 <td class="table-stat-row table-stat-row--points"> <?php echo $donnee['total_f'] ?> </td>
 <td class="table-stat-row table-stat-row--points"> 
 <?php echo $donnee['total'] ?> 
 </td>
 </tr>
<?php
 }} elseif ($i!=2020) {
 $req = "SELECT
 (SELECT COUNT(*) FROM participant WHERE annee=:i AND course=1 AND sexxxx=1 AND dossart>0) AS total_h, 
 (SELECT COUNT(*) FROM participant WHERE annee=:i AND course=1 AND sexxxx!=1 AND dossart>0) AS total_f, 
 (SELECT COUNT(*) FROM participant WHERE annee=:i AND course=1 AND dossart>0) AS total;
 ";
 $arg = compact('i');
 $donnee = $db->select($req, $arg, false);
 $j++;
 $total_h+=$donnee['total_h'];
 $total_f+=$donnee['total_f'];
 $total+=$donnee['total'];
?>
 <tr class="table-standings-row">
 <td class="table-stat-row "> <?php echo $i ?> </td>
 <td class="table-stat-row table-stat-row--points"> <?php echo $donnee['total_h'] ?> </td>
 <td class="table-stat-row table-stat-row--points"> <?php echo $donnee['total_f'] ?> </td>
 <td class="table-stat-row table-stat-row--points"> 
 <?php echo $donnee['total'] ?> 
 </td>
 </tr>
<?php
 }
 }
 $total_h=ceil($total_h/$j);
 $total_f=ceil($total_f/$j);
 $total=ceil($total/$j);
?>
 <tr class="table-standings-row">
 <td class="table-stat-row "> Moyenne </td>
 <td class="table-stat-row table-stat-row--points"> <?php echo $total_h ?> </td>
 <td class="table-stat-row table-stat-row--points"> <?php echo $total_f ?> </td>
 <td class="table-stat-row table-stat-row--points"> 
 <?php echo $total ?> 
 </td>
 </tr>
 </tbody>
 </table>

 <br/><br/><hr class="violoo" /><br/><br/>

 </section>
 </div>
 </section>
 </div>
 </div>
 </div>
 </main>
</div>

<?php $this->stopSection(); ?>

<?php /*-------------------------------------- Put here your additional CSS files for this page --------------------------------------*/ ?>
<?php $this->startSection('wisra_css_content'); ?>
<link href="<?php echo $config['app_url'];?>sources/plugin/toastr/toastr.min.css" rel="stylesheet" type="text/css">
<?php $this->stopSection(); ?>

<?php /*-------------------------------------- Put here your additional JS files  for this page --------------------------------------*/ ?>
<?php $this->startSection('wisra_js_content'); ?>
<script src="<?php echo $config['app_url'];?>sources/plugin/toastr/toastr.min.js"></script>
<script src="<?php echo $config['app_url'];?>sources/script/admin.js"></script>
<?php $this->stopSection(); ?>
<?php if (@$_shouldextend[1]) { echo $this->runChild('layout', ['page_data' => array(
 'plugins' => array(), 
 'title' => "SMIB | Admin", 
 'description' => "SMIB | Admin", 
 'keywords' => array("SMIB | Admin"), 
 'facebook_integration' => false, 
 'google_maps_callback' => '', 
 'admin_interface' => 1
)]); } ?>