<?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();

 $types = array('resultat', 'article', 'media');
 $pages = array('resultat'=>'Réultats', 'article'=>'Article', 'media'=>'Media');
 if (!empty($_GET['t']) && in_array($_GET['t'], $types)) $__t = $_GET['t']; else $__t = 'article';
 $__q = (!empty($_GET['q'])) ? implode(' ', explode('-', rawurldecode($_GET['q']))) : '' ;
?>

<?php $_shouldextend[1]=1; ?>

<?php $this->startSection('wisra_basic_content'); ?>
 @parentXYZABC


<?php if (empty($__q)) {?>

<div class="body-content js-body-content blue-body">
 <main id="main">
 <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/basic/stripes-left.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/basic/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/basic/stripes-right.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/basic/stripes-right.png" alt="Standings Background Pattern">
 </picture>
 </div>
 <div class="u-main-gradient">
 <div class="wrapper">
 <div class="col-12">
 <section class="standings">
 <div class="standings__header">
 <div class="standings-header">
 <h1> Recherche </h1>
 </div>
 </div>
 <div class="empty-search-page">
 <img src="<?php echo $config['app_url'] ?>sources/image/basic/semi-marathon-header.jpg" alt="Semi Marathon International de Béjaia logo">
 <div class="search-bar js-search-bar">
 <div class="search-bar__icon">
 <img type="image/svg+xml" src="<?php echo $config['app_url'] ?>sources/image/svg/search-black.svg" width="32" height="32"/>
 </div>
 <input class="search-bar__input" aria-label="Rechercher" name="Rechercher" id="rechercherb" type="text" placeholder="Rechercher résultats, les actualités et les vidéos du Semi Marathon International de Béjaia">
 </div>
 </div>
 </section>
 </div>
 </div>
 </div>
 </main>
</div>

<?php } else {?>

<div class="body-content js-body-content blue-body">
 <main id="main">
 <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/basic/stripes-left.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/basic/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/basic/stripes-right.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/basic/stripes-right.png" alt="Standings Background Pattern">
 </picture>
 </div>
 <div class="u-main-gradient">
 <div class="wrapper">
 <div class="col-12">
 <section class="standings">
 <div class="standings__header">
 <div class="standings-header">
 <h1> Recherche </h1>
 </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">
 <img src="<?php echo $config['app_url'] ?>sources/image/basic/semi-marathon-bejaia-footer.png" alt="<?php echo $config['app_name'] ?> logo" class="standings-pane-header__competition-logo">
 </div>
 <span class="standings-pane-header__name visually-hidden"></span>
 <div class="standings-pane-header__time-info">
 <div class="standings-pane-header__last-updated"> 
 Recherche de : <?php echo $pages[$__t]; ?> 
 </div>
 <div class="standings-pane-header__season-info-container">
 <span class="standings-pane-header__season-info js-season-info"> <?php echo $__q; ?> </span>
 <span class="standings-pane-header__match-week-info js-match-week-info">  </span>
 </div>
 </div>
 </div>
<?php
 $no__results = 0;
 $results = array();
 $q = explode(' ', implode(' ', explode('-', $__q)));

 $stopwords = array('alors', 'au', 'aucuns','aussi', 'autre', 'avant', 'avec', 'avoir','car', 'ce', 'cela', 'ces', 'ceux', 'chaque', 'ci','comme', 'dans', 'des', 'du', 'dedans','dehors', 'deux', 'doit', 'donc', 'dos', 'elle', 'elles', 'en', 'encore', 'essai', 'est', 'et', 'eu', 'haut', 'hors', 'ici', 'il', 'ils', 'je', 'la', 'le', 'les', 'leur', 'là', 'ma', 'maintenant', 'mais', 'mes', 'moins', 'mon', 'mot', 'même', 'ni', 'notre', 'nous', 'ou', 'où', 'par', 'parce', 'pas', 'peu', 'pour', 'quand', 'que', 'quel', 'quelle', 'quelles', 'quels', 'qui', 'sa', 'sans', 'ses', 'si', 'sien', 'son', 'sont', 'sous', 'soyez', 'sujet', 'sur', 'ta', 'tandis', 'tels', 'tes', 'ton', 'tous', 'tout', 'trop', 'très', 'tu', 'votre', 'vous', 'vu', 'ça', 'état', 'étions', 'été', 'être', 'un', 'une', 'etre', 'de', 'je', 'à', 'ne', 'plus', 'es', 'se', ',', '.', '-');
if ($__t=='resultat') {
/*==================
// Les résultats
======================*/
 function sectotime($sec) {
 $timo='';
 $hr=floor($sec/3600);
 if ($hr>0) $timo.=$hr.':';
 $sec=$sec-$hr*3600;
 $mn=floor($sec/60);
 if ($mn>0) $timo.=(($mn<9)?'0':'').$mn.':'; else $timo.='00:';
 $sec=$sec-$mn*60;
 if ($sec>0) $timo.=(($sec<9)?'0':'').$sec; else $timo.='00';
 return $timo;
 }

 $no__results = 1;
 $code2write = '';

 foreach ($q as $word) if (!in_array($word, $stopwords)) {

 //=> 2019 dassawen
 $req = "
 SELECT 
 B.course, B.catego, B.annee, B.dossard, B.time_course, 
 A.nom, A.prenom, A.datnes, A.sex, A.payspy, A.wilaya, A.wily_v, A.comune, 
 C.alpha2 AS pays_ico, C.nom_en_gb, C.nom_fr_fr, D.nom AS ville_s, 
 ((SELECT COUNT(*) FROM member_particip X INNER JOIN member Y ON Y.id=X.membre WHERE X.annee=B.annee AND X.course=B.course AND Y.sex=A.sex AND X.dossard>0 AND X.time_course)+1) AS classement 
 FROM member A 
 INNER JOIN member_particip B ON B.membre=A.id 
 LEFT JOIN ad_pays C ON C.id=A.payspy 
 LEFT JOIN ad_ville D ON D.id=A.wilaya 
 WHERE B.dossard>0 AND B.time_course>0 AND (A.nom LIKE :word OR A.prenom LIKE :word) 
 ORDER BY B.annee DESC LIMIT 0, 60;
 ";
 $arg = array('word'=>$word);
 $donnees = $db->select($req, $arg, true);
 foreach ($donnees as $x => $donnee) {
 $no__results = 0;
 $code2write .= '
 <tr class="table-standings-row'.$barco.'">
 <td class="position-row'.(($donnee['classement']<4)?' position-row--champions-league':(($donnee['classement']<6)?' position-row--europa-league':'')).'">
 <span class="position-row__number">'.$donnee['classement'].'</span>
 <div class="position-row__direction "></div>
 </td>
 <td class="table-stat-row table-stat-row--points"> '.$donnee['dossart'].' </td>
 <td class="badge-row" scope="row">
 <span class="badge-row__badge" title="'.$donnee['nom_fr_fr'].'">
 <span class="visually-hidden">'.$donnee['nom_fr_fr'].'</span>
 <img src="'.$config['app_url'].'sources/image/svg/flags/'.$donnee['pays_ico'].'.svg"  width="30" height="30" alt="'.$donnee['nom_en_gb'].'">
 </span>
 </td>
 <td class="table-stat-row"> '.$donnee['nom_en_gb'].' </td>
 <td class="table-stat-row"> '.(($donnee['payspy']==4)?utf8_encode($donnee['ville_s']):utf8_encode($donnee['wily_v'])).' </td>
 <td class="team-row" scope="row">
 <div class="team-row__name-container">
 <span class="team-row__name">'.utf8_encode($donnee['prenom'].' '.$donnee['nom']).'</span>
 <span class="team-row__name--short"></span>
 </div>
 </td>
 <td class="table-stat-row "> '.(($donnee['datnes']>0)?date('d/m/Y', $donnee['datnes']):'/').' </td>
 <td class="table-stat-row "> '.(($donnee['sex']==1)?'H':'F').' </td>
 <td class="table-stat-row "> '.(($donnee['course']==1)?'21Km':'7Km').' </td>
 <td class="table-stat-row table-stat-row--points"> '.(($donnee['course']==1)?sectotime($donnee['time_21_km']):sectotime($donnee['time_7_km'])).' </td>
 <td class="table-stat-row table-stat-row--points"> '.$donnee['annee'].' </td>
 <td class="standings-table__gap-filler"></td>
 </tr>
 ';
 }

 //=> 2018 Daksar
 $req = "
 SELECT 
 A.course, A.catego, A.annee, A.dossart, A.time_7_km, A.time_21_km, 
 A.nomnom, A.prenom, A.datnes, A.sexxxx, A.payspy, A.wilaya, A.wily_v, A.comune, B.nom AS pays, C.nom AS ville_s, 
 ((SELECT COUNT(*) FROM participant WHERE annee=A.annee AND course=A.course AND sexxxx=A.sexxxx AND dossart>0 AND ((course=1 AND time_21_km>0) OR (course=2 AND time_7_km>0)) AND ((course=1 AND time_21_km<A.time_21_km) OR (course=2 AND time_7_km<A.time_7_km)))+1) AS classement
 FROM participant A 
 INNER JOIN adex_pays B ON B.id=A.payspy 
 LEFT JOIN ad_ville C ON C.id=A.wilaya 
 WHERE 
 A.dossart>0 AND ((A.course=1 AND A.time_21_km>0) OR (A.course=2 AND A.time_7_km>0)) AND 
 (A.nomnom LIKE :word OR A.prenom LIKE :word) 
 ORDER BY A.annee DESC LIMIT 0, 60;
 ";
 $arg = array('word'=>$word);
 $donnees = $db->select($req, $arg, true);
 foreach ($donnees as $x => $donnee) {
 $no__results = 0;
 $code2write .= '
 <tr class="table-standings-row'.$barco.'">
 <td class="position-row'.(($donnee['classement']<4)?' position-row--champions-league':(($donnee['classement']<6)?' position-row--europa-league':'')).'">
 <span class="position-row__number">'.$donnee['classement'].'</span>
 <div class="position-row__direction "></div>
 </td>
 <td class="table-stat-row table-stat-row--points"> '.$donnee['dossart'].' </td>
 <td class="badge-row" scope="row">
 <span class="badge-row__badge" title="'.$donnee['pays'].'"></span>
 </td>
 <td class="table-stat-row"> '.utf8_encode($donnee['pays']).' </td>
 <td class="table-stat-row"> '.(($donnee['payspy']==4)?utf8_encode($donnee['ville_s']):utf8_encode($donnee['wily_v'])).' </td>
 <td class="team-row" scope="row">
 <div class="team-row__name-container">
 <span class="team-row__name">'.utf8_encode($donnee['prenom'].' '.$donnee['nomnom']).'</span>
 <span class="team-row__name--short"></span>
 </div>
 </td>
 <td class="table-stat-row "> '.(($donnee['datnes']>0)?date('d/m/Y', $donnee['datnes']):'/').' </td>
 <td class="table-stat-row "> '.(($donnee['sex']==1)?'H':'F').' </td>
 <td class="table-stat-row "> '.(($donnee['course']==1)?'21Km':'7Km').' </td>
 <td class="table-stat-row table-stat-row--points"> '.(($donnee['course']==1)?sectotime($donnee['time_21_km']):sectotime($donnee['time_7_km'])).' </td>
 <td class="table-stat-row table-stat-row--points"> '.$donnee['annee'].' </td>
 <td class="standings-table__gap-filler"></td>
 </tr>
 ';
 }
 }
 if (!empty($code2write) && $no__results == 0) {
?>
 <table class="standings-league__table standings-table">
 <thead class="standings-table__head">
 <tr>
<?php 
 $tablaxa=array(
 array('Classement', 'N° Dossard', '', 'Pays', 'Ville', 'Nom & Prénom', 'Date de Naissance', 'Sexe', 'Course', 'Temps', 'Année'), 
 array('Cls', 'N°', '', 'Pys', 'Vil', 'Nom', 'Naiss', 'Sex', 'Crs', 'Tps', 'An')
 );
 foreach ($tablaxa[0] as $x => $value) {
 echo '
 <th class="table-head" scope="col">
 <span class="table-head__heading">'.$value.'</span>
 <span class="table-head__heading--short">'.$tablaxa[1][$x].'</span>
 </th>
 ';
 }
?>
 <th class="standings-table__gap-filler"></th>
 </tr>
 </thead>
 <tbody class="standings-table__body">
<?php
 echo $code2write;
?>
 </tbody>
 </table>
<?php 
 }

/*==================
// Fin des résultats
======================*/
} elseif ($__t=='article') {
/*==================
// Les articles
======================*/
 $articl_srch = require 'config/data/articles-search.php';
 foreach ($q as $word) if (!in_array($word, $stopwords)) {
 foreach ($articl_srch as $key => $table) {
 $note   = 0;
 $keyz   = '';

 $keyz   = $key;
 $titre  = $table['title'];
 $import = $table['important'];
 $text   = $table['text'];

 $note += preg_match_all('/'.$word.'/i', $titre, $matches) * 3;
 $note += preg_match_all('/'.$word.'/i', $import, $matches) * 2;
 $note += preg_match_all('/'.$word.'/i', $text, $matches);

 if ($note>0 && !empty($keyz) && !in_array($keyz, array_keys($results))) $results[$keyz] = $note;
 }
 }

 arsort($results);
 if (!empty($results)) {
?>
<div class="feed__container js-feed-container">
 <div class="branding-bar"></div>
 <div class="feed__date">
 <div class="feed__day">Articles</div>
 <div class="feed__month">trouvés</div>
 </div>
 <div class="feed__items js-feed-items">

<?php 
 foreach ($results as $key => $note) if (!empty($articl_srch[$key]['result_title'])) {
 $resultats = $articl_srch[$key];
?>

 <a href="<?php echo $config['app_url'].$resultats['link'] ?>" class="thumbnail thumbnail--news thumbnail--wide js-thumbnail js-article-expand is-visible" data-article-id="1153200" data-is-initialised="true">
 <figure class="thumbnail__figure">
 <div class="thumbnail__picture-wrapper">
 <div class="thumbnail__picture">
 <picture class="js-lazy-picture thumbnail__picture-element lazy-load loaded">
 <img src="<?php echo $config['app_url'] ?>sources/image/artiles/<?php echo $resultats['result_image'] ?>.jpg?width=640&amp;height=400" data-image-src="<?php echo $config['app_url'] ?>sources/image/artiles/<?php echo $resultats['result_image'] ?>.jpg?width=640&amp;height=400" alt="<?php echo $resultats['result_title'] ?>" class="thumbnail__image">
 </picture>
 </div>
 </div>
 <figcaption class="thumbnail__caption">
 <div class="thumbnail__text">
 <div class="thumbnail__title"><?php echo $resultats['result_title'] ?></div>
 <div class="thumbnail__desc"><?php echo $resultats['result_descr'] ?></div>
 </div>
 <div class="thumbnail__meta">
 <div class="content-tag content-tag--left">
 <span>Trouvé: <?php echo $note ?></span>
 </div>
 </div>
 </figcaption>
 </figure>
 </a>

<?php } ?>

 </div>
</div>
<?php 
 } else $no__results = 1;


/*==================
// Fin des articles
======================*/
} elseif ($__t=='media') {
/*==================
// Les media
======================*/
 $title_write_v = 0;
 $videos_list = require 'config/data/gallerie-video.php';
 $q = explode(' ', implode(' ', explode('-', $__q)));
 foreach ($q as $word) if (!in_array($word, $stopwords)) {

 foreach ($videos_list as $link => $table) {
 $note   = 0;
 $note += preg_match_all('/'.$word.'/i', $table['titr'], $matches) * 2;
 $note += preg_match_all('/'.$word.'/i', $table['desc'], $matches);

 if ($note>0 && !in_array($link, $results)) {
 if ($title_write_v == 0) {
 $title_write_v = 1;
?>
 <div class="widget__header">
 <h3 class="widget__title">Vidéos</h3>
 </div>
 <div class="collections__list">
<?php
 }
 $results[] = $link;
?>
 <li class="collections__list-item">
 <a href="<?php echo $config['app_url']?>gallerie-video/<?php echo $link;?>" class="collection small__one">
 <div class="collection__photo-container">
 <picture class="collection__photo js-lazy-picture loaded">
 <img src="<?php echo $config['app_url']?>sources/image/gallery/video/<?php echo $table['code'];?>-moy.jpg" data-image-src="<?php echo $config['app_url']?>sources/image/gallery/video/<?php echo $table['code'];?>-moy.jpg" alt="Gallerie photos marathon semi marathon de béjaia">
 </picture>
 </div>
 <div class="collection__details">
 <div class="playlist-tag">
 <div class="video-tag">
 <img type="image/svg+xml" src="<?php echo $config['app_url'] ?>sources/image/svg/play-button.svg" width="32" height="32"/>
 </div>
 </div>
 <div class="collection__title"></div>
 <div class="collection__videos">
 <?php echo $table['titr'];?>
 </div>
 </div>
 </a>
 </li>
<?php 
 }
 }
 }
 if ($title_write_v == 1) {
?>
 </div>
<?php 
 }
?>




<?php
 $results = array();
 $title_write_p = 0;
 $photos_list = require 'config/data/gallerie-photo.php';
 foreach ($q as $word) if (!in_array($word, $stopwords)) {
 foreach ($photos_list as $annee => $albums) {
 foreach ($albums as $dir => $album) {

 $note   = 0;
 $note += preg_match_all('/'.$word.'/i', $album['name'], $matches);
 $link = $annee.'--'.$dir;

 if ($note>0 && !in_array($link, $results)) {
 $results[] = $link;
 if ($title_write_p == 0) {
 $title_write_p = 1;
?>
 <br/><br/><br/>
 <div class="widget__header">
 <h3 class="widget__title">Photos</h3>
 </div>
 <div class="collections__list">
<?php 
 }
?>
 <li class="collections__list-item">
 <a href="<?php echo $config['app_url']?>sources/image/gallery/<?php echo $annee?>/photos/<?php echo $dir?>/1.jpg" class="collection small__one" data-fancybox="marathon">
 <div class="collection__photo-container">
 <picture class="collection__photo js-lazy-picture loaded">
 <img src="<?php echo $config['app_url']?>sources/image/gallery/<?php echo $annee?>/<?php echo $dir?>.jpg" data-image-src="<?php echo $config['app_url']?>sources/image/gallery/<?php echo $annee?>/<?php echo $dir?>.jpg" alt="Gallerie photos marathon semi marathon de béjaia">
 </picture>
 </div>
 <div class="collection__details">
 <div class="playlist-tag">
 <span class="playlist-tag__barca">SMIB</span>
 <span class="playlist-tag__label">Dossier photos</span>
 </div>
 <div class="collection__title"><?php echo $album['name'].' '.$annee?></div>
 <div class="collection__videos">
 <span class="collection__videos-counter"><?php echo $album['last']?></span> Photos
 </div>
 </div>
 </a>
 <?php for ($i=2; $i <= $album['last']; $i++) {?>
 <a href="<?php echo $config['app_url']?>sources/image/gallery/<?php echo $annee?>/photos/<?php echo $dir?>/<?php echo $i?>.jpg" data-fancybox="marathon"></a>
 <?php }?>
 </li>
<?php 
 }
 }
 }
 }

 if ($title_write_p == 1) {
?>
 </div>
<?php 
 }


/*==================
// Fin des media
======================*/
 if ($title_write_v==0 && $title_write_p==0) $no__results = 1;
}


if ($no__results==1) {?>
 <section id="search-page">
 <div class="widget__header">
 <h3 class="widget__title">Aucun résultat trouvé!</h3>
 </div>
 </section>
<?php }?>

 </section>
 </div>
 </section>
 </div>
 </div>
 </div>
 </main>
</div>

<?php }?>

<?php include_once("sources/include/sponsors.php");?>

<?php $this->stopSection(); ?>

<?php /*-------------------------------------- Put here your additional CSS files for this page --------------------------------------*/ ?>
<?php $this->startSection('wisra_css_content'); ?>
<link rel="stylesheet" href="<?php echo $config['app_url']?>sources/plugin/fancybox/jquery.fancybox.min.css" />
<style type="text/css">.fancybox-container {z-index: 99999999992!important;}</style>
<?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/fancybox/jquery.fancybox.min.js"></script>
<script type="text/javascript">
 $(document).ready(function(){$('[data-fancybox]').fancybox()});
</script>
<?php $this->stopSection(); ?>
<?php if (@$_shouldextend[1]) { echo $this->runChild('layout', ['page_data' => array(
 'plugins' => array(), 
 'title' => ((empty($__q))?"Recherche ".$pages[$__t]:"Recherche ".$__q)." | Semi Marathon International de Béjaia", 
 'description' => ((empty($__q))?"Recherche ".$pages[$__t]:"Recherche ".$__q).", Semi Marathon International de la ville de Béjaia: course 21km, 7km et 3km pour enfants, handisports. organisé par l'Athlétic Méditerranéen Club Béjaia AMCB chaque année, a la vile de Béjaia - Algérie", 
 'keywords' => array(((empty($__q))?"Recherche ".$pages[$__t]:"Recherche ".$__q), ((empty($__q))?"Recherche ".$pages[$__t]:"Recherche ".$__q)." Semi Marathon Bejaia", "Semi Marathon International de la ville de Béjaia", "Semi Marathon International de Béjaia", "Semi Marathon Béjaia", "SemiMarathon Béjaia", "Demi Marathon Béjaia", "Semi Marathon International Bejaia", "Semi", "Marathon", "Semi-Marathon", "International", "Semi-Marathon International", "Béjaia", "Semi-Marathon International Béjaia", "course 21km", "course 7km", "course 3km", "course enfants", "course handisports", "Athlétic Méditerranéen Club Béjaia", "Athlétic Club", "Athlétic Club Béjaia",  "Athlétic Méditerranéen Club Béjaia", "AMCB", "la vile de Béjaia", "Algérie", "Béjaia Algérie"), 
 'facebook_integration' => false, 
 'google_maps_callback' => '', 
 'secondary_header' => 1, 
 'secondary_name' => 'search', 
 'secondary_type' => $__t, 
 'secondary_srch' => $__q
)]); } ?>