<?php
/**
** @Artiphp 6
* @paquetage agenda
* @version index.php, 2015/07/23 arteam
* @copyright (c) 2001-2016 Ronald Guerin - webmaster@artiloo.com - http://www.artiloo.com
* @license consulter artpublic/license/index.html GNU Public License
**/

// Protection - Page
define('IN_ARTI', true);

// Chargement configuration
require('../artpublic/config.inc.php'); // ATTENTION : chemin relatif depuis racine Artiphp

// Debug de la page
//error_reporting(E_ALL ^ E_NOTICE);

// Connexion au noyau
// ------------------
include(ARTI_SYS_INT_FCT_PATH . 'identification.inc.php'); // zone membre

// Langue
// ------
if (empty($_SESSION['SESSION_IDSKIN'])) {
    include(ARTI_SYS_INT_FCT_PATH . 'donnees_skin.inc.php');
}
$SESSION_LANGSKIN = $_SESSION['SESSION_LANGSKIN'];
include(ARTI_SYS_INT_PATH . "langues/$SESSION_LANGSKIN/index.inc.php");

include('config_mod.inc.php'); //config specifique au module
include(ARTI_SYS_INT_FCT_PATH . 'verif_acl.inc.php'); // ACL general

// CODE SPECIFIQUE AU MODULE
// -------------------------

// personnalisation
include(ARTI_SYS_PATH . $mod_encours_dir . '/personnalisation.inc.php');

$date = date('Ymd');

if ($xlg3 && $resumer=='1') {
    function debutchaine($chaine, $nbmots) // 1er argument : chaîne - 2e argument : nombre de mots
    {
        $chaine = preg_replace('!<br.*>!iU', ' ', $chaine); // remplacement des BR par des espaces
        $chaine = strip_tags($chaine);                      // suppression des balises &eacute;ventuelles
        $chaine = preg_replace('/\s\s+/', ' ', $chaine);    // retrait des espaces inutiles
        $tab = explode(' ', $chaine);
        if (count($tab) <= $nbmots) {
            $affiche = $chaine;
        } else {
            $affiche = $tab[0];
            for ($i = 1; $i < $nbmots; $i++) {
                $affiche .= ' ' . $tab[$i];
            }
            $affiche .= '...';
        }
        return $affiche;
    }
}

// presentation
$rechnbcol = 'SESSION_mod_' . $mod_encours_dir;
$agennn = $_SESSION[$rechnbcol];

// traitement des valeurs passant par l'url

$date_evenement = $_GET['date_evenement'];


// ajout liens vers les 7 prochains jours
if ($date_evenement) { $date=$date_evenement; $date_selection="class=\"date_selec\""; } else { $date_selection=""; }

$dateretour = date('Ymd', strtotime($date.' - 1 DAY'));

$date1 = date('Ymd', strtotime($date.' + 1 DAY'));
$date2 = date('Ymd', strtotime($date.' + 2 DAY'));
$date3 = date('Ymd', strtotime($date.' + 3 DAY'));
$date4 = date('Ymd', strtotime($date.' + 4 DAY'));
$date5 = date('Ymd', strtotime($date.' + 5 DAY'));
$date6 = date('Ymd', strtotime($date.' + 6 DAY'));

$mois_nom  = array('Jan.', 'F&eacute;v.', 'Mars', 'Avr.', 'Mai', 'Juin', 'Juil.', 'Ao&ucirc;t', 'Sept.', 'Oct.', 'Nov.', 'D&eacute;c.');
$mois_chiffre = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');

	$month_dateR = substr($dateretour, 4 ,2);
	$day_dateR = substr($dateretour, 6, 2);
	$year_dateR = substr($dateretour, 0 ,4);
	$mois_affichage_dateR=str_replace($mois_chiffre, $mois_nom, $month_dateR);
	$affichage_dateR = "<a href=\"agenda_date_" . $year_dateR . "" . $month_dateR . "" . $day_dateR . ".html\" ". $date_selection . "><strong>&laquo;</strong>Pr&eacute;c&eacute;dent</a>";

	$month_date0 = substr($date, 4 ,2);
	$day_date0 = substr($date, 6, 2);
	$year_date0 = substr($date, 0 ,4);
	$mois_affichage_date0=str_replace($mois_chiffre, $mois_nom, $month_date0);
	$affichage_date0 = "<a href=\"agenda_date_" . $year_date0 . "" . $month_date0 . "" . $day_date0 . ".html\" ". $date_selection . "><strong>" . $day_date0 . "</strong>" . $mois_affichage_date0 . "</a>";

	$month_date1 = substr($date1, 4 ,2);
	$day_date1 = substr($date1, 6, 2);
	$year_date1 = substr($date1, 0 ,4);
	$mois_affichage_date1=str_replace($mois_chiffre, $mois_nom, $month_date1);
	$affichage_date1 = "<a href=\"agenda_date_" . $year_date1 . "" . $month_date1 . "" . $day_date1 . ".html\"><strong>" . $day_date1 . "</strong>" . $mois_affichage_date1 . "</a>";
	
	$month_date2 = substr($date2, 4 ,2);
	$day_date2 = substr($date2, 6, 2);
	$year_date2 = substr($date2, 0 ,4);
	$mois_affichage_date2=str_replace($mois_chiffre, $mois_nom, $month_date2);
	$affichage_date2 = "<a href=\"agenda_date_" . $year_date2 . "" . $month_date2 . "" . $day_date2 . ".html\"><strong>" . $day_date2 . "</strong>" . $mois_affichage_date2 . "</a>";
	
	$month_date3 = substr($date3, 4 ,2);
	$day_date3 = substr($date3, 6, 2);
	$year_date3 = substr($date3, 0 ,4);
	$mois_affichage_date3=str_replace($mois_chiffre, $mois_nom, $month_date3);
	$affichage_date3 = "<a href=\"agenda_date_" . $year_date3 . "" . $month_date3 . "" . $day_date3 . ".html\"><strong>" . $day_date3 . "</strong>" . $mois_affichage_date3 . "</a>";
	
	$month_date4 = substr($date4, 4 ,2);
	$day_date4 = substr($date4, 6, 2);
	$year_date4 = substr($date4, 0 ,4);
	$mois_affichage_date4=str_replace($mois_chiffre, $mois_nom, $month_date4);
	$affichage_date4 = "<a href=\"agenda_date_" . $year_date4 . "" . $month_date4 . "" . $day_date4 . ".html\"><strong>" . $day_date4 . "</strong>" . $mois_affichage_date4 . "</a>";
	
	$month_date5 = substr($date5, 4 ,2);
	$day_date5 = substr($date5, 6, 2);
	$year_date5 = substr($date5, 0 ,4);
	$mois_affichage_date5=str_replace($mois_chiffre, $mois_nom, $month_date5);
	$affichage_date5 = "<a href=\"agenda_date_" . $year_date5 . "" . $month_date5 . "" . $day_date5 . ".html\"><strong>" . $day_date5 . "</strong>" . $mois_affichage_date5 . "</a>";
	
	$month_date6 = substr($date6, 4 ,2);
	$day_date6 = substr($date6, 6, 2);
	$year_date6 = substr($date6, 0 ,4);
	$mois_affichage_date6=str_replace($mois_chiffre, $mois_nom, $month_date6);
	$affichage_date6 = "<a href=\"agenda_date_" . $year_date6 . "" . $month_date6 . "" . $day_date6 . ".html\"><strong>" . $day_date6 . "</strong>" . $mois_affichage_date6 . "</a>";

$menu_date = "" . $affichage_dateR . "" . $affichage_date0 . "" . $affichage_date1 . "" . $affichage_date2 . "" . $affichage_date3 . "" . $affichage_date4 . "" . $affichage_date5 . "" . $affichage_date6 . "";


if ($_GET['s']) {
	$date_semaine = $_GET['s'];
} else if ($_GET['date_evenement']) {
	$date_semaine = $_GET['date_evenement'];
}

if ($date) {
	$day = $date;
	// Calcul de l'&eacute;cart entre le jour de $day et le lundi (=1)
	$rel = 1 - date('N', strtotime ($day));
	// Calcul de l'&eacute;cart entre le jour de $day et le dimanche (=7)
	$rel2 = 7 - date('N', strtotime ($day));
	//calcul du lundi avec cet &eacute;cart
	$monday = date('Ymd', strtotime("$rel days", strtotime($day)));
	$sunday = date('Ymd', strtotime("$rel2 days", strtotime($day)));
	
	$month_monday = substr($monday, 4 ,2);
	$day_monday = substr($monday, 6, 2);
	$year_monday = substr($monday, 0 ,4);
	
	$month_sunday = substr($sunday, 4 ,2);
	$day_sunday = substr($sunday, 6, 2);
	$year_sunday = substr($sunday, 0 ,4);
}

if  ($date_semaine) {
	$day = $date_semaine;
	// Calcul de l'&eacute;cart entre le jour de $day et le lundi (=1)
	$rel = 1 - date('N', strtotime ($day));
	// Calcul de l'&eacute;cart entre le jour de $day et le dimanche (=7)
	$rel2 = 7 - date('N', strtotime ($day));
	//calcul du lundi avec cet &eacute;cart
	$monday = date('Ymd', strtotime("$rel days", strtotime($day)));
	$sunday = date('Ymd', strtotime("$rel2 days", strtotime($day)));
	
	$month_monday = substr($monday, 4 ,2);
	$day_monday = substr($monday, 6, 2);
	$year_monday = substr($monday, 0 ,4);
	
	$month_sunday = substr($sunday, 4 ,2);
	$day_sunday = substr($sunday, 6, 2);
	$year_sunday = substr($sunday, 0 ,4);

}

$date_mois = $_GET['m'];
if ($date_mois) {
	$m = substr($date_mois, 4 ,2);
	$y = substr($date_mois, 0 ,4);
	$mois_agenda = mktime( 0, 0, 0, $m, 1, $y );
	$dernierjour = intval(date("t",$mois_agenda));
	
	$finmois=$y.$m.$dernierjour;
	$debutmois=$y.$m."01";
}




$cat = $_GET['cat'];

$page = $_GET['page'];
if (!($limit)) {
    $limit = $_GET['limit'];
}
$pagination = '';
$debutpag = '';
$finpag = '';
$PHP_SELF = htmlspecialchars($_SERVER['PHP_SELF']);

// pages suivante et precedente
if ($_GET['val3']) {
    $val3 = $_GET['val3'];
    list($page, $limit) = explode('_', $val3);
    $suite = htmlentities(urlencode($suite));
}

// categorie
if ($_GET['val']) {
    $val = $_GET['val'];
    list($cat, $suite) = explode('_', $val);
    $suite = htmlentities(urlencode($suite));
}

// categorie pages suivante et precedente
if ($_GET['val2']) {
    $val2 = $_GET['val2'];
    list($cat, $page, $limit, $suite) = explode('_', $val2);
    $suite = htmlentities(urlencode($suite));
}

// date pages suivante et precedente
if ($_GET['val5']) {
    $val5 = $_GET['val5'];
    list($date_evenement, $page, $limit) = explode('_', $val5);
}

// semaine pages suivante et precedente
if ($_GET['val6']) {
    $val6 = $_GET['val6'];
    list($date_semaine, $page, $limit) = explode('_', $val6);
}

// mois pages suivante et precedente
if ($_GET['val7']) {
    $val7 = $_GET['val7'];
    list($date_mois, $page, $limit) = explode('_', $val7);
}

$cat = intval($cat);
$cat = $cat > 3 ? $cat : 0;
$date_evenement = intval($date_evenement);
$date_semaine = intval($date_semaine);
$date_mois = intval($date_mois);
$page = intval($page);
$limit = intval($limit);

// pagination le limit d&eacute;finit le nombre d'enregistrements par page
if (!($limit)) {
    $limit = 6;
}
if (!($page)) {
    $page = 0;
}

// Transformation date
// -------------------
$month10 = substr($date_evenement, 4 ,2);
$day10 = substr($date_evenement, 6, 2);
$year10 = substr($date_evenement, 0 ,4);

$month11 = substr($date_semaine, 4 ,2);
$day11 = substr($date_semaine, 6, 2);
$year11 = substr($date_semaine, 0 ,4);

$month12 = substr($date_mois, 4 ,2);
$day12 = substr($date_mois, 6, 2);
$year12 = substr($date_mois, 0 ,4);

$month13 = substr($date, 4 ,2);
$day13 = substr($date, 6, 2);
$year13 = substr($date, 0 ,4);

$ajschemlieu="";
if ($cat) {

    // recherche donnees categorie
    //-------------------------------
    
    $requete = "SELECT id_categorie, nomCategorie, id_parentcat, url_friendly, descCat FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "_themes` WHERE id_categorie='$cat'";
    $result = mysql_query($requete, $link);
    $cat_result = mysql_fetch_object($result);

    $nomCategorie = stripslashes($cat_result->nomCategorie);
    $describeCategorie = stripslashes($cat_result->descCat);
    $cat_url_friendly = stripslashes($cat_result->url_friendly);

    $rechid_parentcat = stripslashes($cat_result->id_parentcat);

    $requete2 = "SELECT supplevc1 FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "_themes` WHERE id_categorie='$rechid_parentcat'";
    $result2 = mysql_query($requete2, $link);
    $cat_result2 = mysql_fetch_object($result2);

    $rechsupplevc1 = $cat_result2->supplevc1;

    if ($rechsupplevc1 == '1') {
        $nomCategorieParent = $LG_AGENDA_PARTHEMES;
    } else if ($rechsupplevc1 == '2') {
        $nomCategorieParent = $LG_AGENDA_PARLIEUX;
        $ajschemlieu = $nomCategorie;
        
        
    } else {
        $nomCategorieParent = $LG_AGENDA_PARPUBLICS;
    }

    $ajoutcat = " AND (idCat LIKE '%[$cat]%' OR idCat2 LIKE '%[$cat]%' OR id2Cat LIKE '%[$cat]%')";
    $ajoutdate = "AND ordateoutSortir>=$date";

} else if ($date_evenement) {

    $ajoutcat = '';
    $ajoutdate = "AND ordateinSortir<=$date_evenement AND ordateoutSortir>=$date_evenement";
    
} else if ($date_semaine) {

    $ajoutcat = '';
    $ajoutdate = "AND ordateinSortir<=$sunday AND ordateoutSortir>=$monday";
    
} else if ($date_mois) {

    $ajoutcat = '';
    $ajoutdate = "AND ordateinSortir<=$finmois AND ordateoutSortir>=$debutmois";

} else {

    $ajoutcat = '';
    $ajoutdate = "AND ordateoutSortir>=$date";

}

/* EN-TETE */

if ($cat) {
    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>\n";
    $entete2 = "<h1>$nomCategorie - $lg_mod_titre</h1>\n\n";
} else if ($date_evenement) {
    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>\n";
    $entete2 = "<h1>" . $day10 . "/" . $month10 . "/" . $year10 . " - $lg_mod_titre</h1>\n\n";
    
    //transfo date semaine
    if ($year_monday==$year_sunday) { $yeardeb=""; $yearfin="/".$year_monday.""; } else { $yeardeb="/".$year_monday.""; $yearfin="/".$year_sunday.""; }
    if ($month_monday==$month_sunday) { $monthdeb=""; $monthfin="/".$month_monday.""; } else { $monthdeb="/".$month_monday.""; $monthfin="/".$month_sunday.""; }
    
    // transfo mois
    $mois_nom  = array('Janvier', 'F&eacute;vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Ao&ucirc;t', 'Septembre', 'Octobre', 'Novembre', 'D&eacute;cembre');
	$mois_chiffre = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
	$mois_affichage=str_replace($mois_chiffre, $mois_nom, $month10);
	
	
    //$entete2 .= "<div id=\"ag_semaine_mois\"><a href=\"agenda_semaine_".$date_evenement.".html\">Du " . $day_monday . "" . $monthdeb . "" . $yeardeb . " au  " . $day_sunday . "" . $monthfin . "" . $yearfin . "</a><a href=\"agenda_mois_".$date_evenement.".html\">En ".$mois_affichage." ".$year10."</a></div>\n\n";

    $entete2 .= "<div class=\"affichage_date_avenir\">" . $menu_date . "<a href=\"agenda_mois_".$date_evenement.".html\"><strong>".$mois_affichage."</strong>Tout le mois</a></div>";
       
} else if ($date_semaine) {
    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>\n";
    
    //transfo date
    if ($year_monday==$year_sunday) { $yeardeb=""; $yearfin="/".$year_monday.""; } else { $yeardeb="/".$year_monday.""; $yearfin="/".$year_sunday.""; }
    if ($month_monday==$month_sunday) { $monthdeb=""; $monthfin="/".$month_monday.""; } else { $monthdeb="/".$month_monday.""; $monthfin="/".$month_sunday.""; }
    
    $entete2 = "<h1>".$lg_mod_titre. " <br>Semaine du  " . $day_monday . "" . $monthdeb . "" . $yeardeb . " au  " . $day_sunday . "" . $monthfin . "" . $yearfin . "</h1>\n\n";

    
} else if ($date_mois) {
    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>\n";
    
    // transfo mois
    $mois_nom  = array('Janvier', 'F&eacute;vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Ao&ucirc;t', 'Septembre', 'Octobre', 'Novembre', 'D&eacute;cembre');
	$mois_chiffre = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
	$mois_affichage=str_replace($mois_chiffre, $mois_nom, $m);
    $entete2 = "<h1>".$lg_mod_titre. " - ".$mois_affichage." " . $y . "</h1>\n\n";

    
} else {
    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>\n";
    $entete2 = "<h1>$lg_mod_titre</h1>\n\n";
    
    //transfo date semaine
    if ($year_monday==$year_sunday) { $yeardeb=""; $yearfin="/".$year_monday.""; } else { $yeardeb="/".$year_monday.""; $yearfin="/".$year_sunday.""; }
    if ($month_monday==$month_sunday) { $monthdeb=""; $monthfin="/".$month_monday.""; } else { $monthdeb="/".$month_monday.""; $monthfin="/".$month_sunday.""; }
    
    // transfo mois
    $mois_nom  = array('Janvier', 'F&eacute;vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Ao&ucirc;t', 'Septembre', 'Octobre', 'Novembre', 'D&eacute;cembre');
	$mois_chiffre = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
	$mois_affichage=str_replace($mois_chiffre, $mois_nom, $month13);
	
    //$entete2 .= "<div id=\"ag_semaine_mois\"><a href=\"agenda_semaine_".$date_evenement.".html\">Du " . $day_monday . "" . $monthdeb . "" . $yeardeb . " au  " . $day_sunday . "" . $monthfin . "" . $yearfin . "</a><a href=\"agenda_mois_".$date_evenement.".html\">En ".$mois_affichage." ".$year13."</a></div>\n\n";

    $entete2 .= "<div class=\"affichage_date_avenir\">" . $menu_date . "<a href=\"agenda_mois_".$date.".html\"><strong>".$mois_affichage."</strong>Tout le mois</a></div>";

}

// comptage des enregistrements
//-----------------------------
$listedossiers = '';
$itemListElement = '';
$requete2 = "SELECT id_sortir FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "` WHERE pubDossier='1'  " . $ajoutcat . ' ' . $ajoutdate;
$results = mysql_query($requete2, $link);
$rows = mysql_num_rows($results);

$suppschem=="";
// A REVOIR
if ($rows == 0) {
    $listedossiers .= "<br><br><strong>$LG_AGENEMPTY</strong>\n";
    $suppschem ='1';
}
$pages = intval($rows / $limit);
if ($rows % $limit) {
    $pages++;
}
$current = ($page / $limit) + 1;
if (($pages < 1) || ($pages == 0)) {
    $total = 1;
} else {
    $total = $pages;
}
$first = $page + 1;
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
    $last = $page + $limit;
} else {
    $last = $rows;
}
mysql_free_result($results);
// ---------------------------

/* CATEGORIESSS */

$requete = "SELECT id_categorie, verifsscat, supplevc1 FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "_themes` WHERE id_parentcat='0'";
$result = mysql_query($requete, $link);
$icatgeneral = '1';
$paddock1 = array();
$paddock2 = array();
$paddock3 = array();

while ($cat_themes = mysql_fetch_object($result)) {

    if ($cat_themes->verifsscat == '2') {

        $sscat_themes = $cat_themes->id_categorie;
        $supplevc1 = $cat_themes->supplevc1;

        $requete2 = "SELECT id_categorie, nomCategorie, url_friendly FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "_themes` WHERE id_parentcat=$sscat_themes";
        $result2 = mysql_query($requete2, $link);

        while ($cat2_themes = mysql_fetch_object($result2)) {
            // construction des tableaux
            if ($supplevc1 == '1') {
                $paddock1['id'][".$cat2_themes->id_categorie."] = $cat2_themes->id_categorie;
                $paddock1['nom'][".$cat2_themes->id_categorie."] = $cat2_themes->nomCategorie;
                $paddock1['url'][".$cat2_themes->id_categorie."] = $cat2_themes->url_friendly;
            } else if ($supplevc1 == '2') {
                $paddock2['id'][".$cat2_themes->id_categorie."] = $cat2_themes->id_categorie;
                $paddock2['nom'][".$cat2_themes->id_categorie."] = $cat2_themes->nomCategorie;
                $paddock2['url'][".$cat2_themes->id_categorie."] = $cat2_themes->url_friendly;
            } else {
                $paddock3['id'][".$cat2_themes->id_categorie."] = $cat2_themes->id_categorie;
                $paddock3['nom'][".$cat2_themes->id_categorie."] = $cat2_themes->nomCategorie;
                $paddock3['url'][".$cat2_themes->id_categorie."] = $cat2_themes->url_friendly;
            }
        }

    }
}

/* AFFICHAGE DES MANIFESTATIONS */

$page = intval($page);
$limit = intval($limit);
//$requete = "SELECT id_sortir, titreSortir, texteSortir, sstitreSortir, ordateinSortir, ordateoutSortir, dosrewriting, idCat, idCat2, id2Cat, imageSortir FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "` WHERE pubDossier='1' " . $ajoutdate . ' ' . $ajoutcat . " ORDER BY $ordre $ascdesc LIMIT $page, $limit";
$requete = "SELECT id_sortir, titreSortir, texteSortir, sstitreSortir, ordateinSortir, ordateoutSortir, dosrewriting, idCat, idCat2, id2Cat, imageSortir FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "` WHERE pubDossier='1' " . $ajoutdate . ' ' . $ajoutcat . " ORDER BY $ordre $ascdesc LIMIT $page, $limit";


$result = mysql_query($requete, $link) or die(mysql_error());
$ix = 0;
$testschema=$limit-1;

if (mysql_num_rows($result)<=$testschema) {

 	$limitschema=mysql_num_rows($result);

} else {
	$limitschema=$limit;
}

while ($dossier = mysql_fetch_object($result)) {

    if ($cat) {
        if ($rechsupplevc1 == '1') {
            $listetheme1 = '<span class="liencat2">' . $LG_AGENTHEME1_1 . ' ';
        } else {
            $listetheme1 = '<span class="liencat2">' . $LG_AGENTHEME1 . ' ';
        }
        if ($rechsupplevc1 == '2') {
            $listetheme2 = '<span class="liencat2">' . $LG_AGENTHEME2_1 . ' ';
        } else {
            $listetheme2 = '<span class="liencat2">' . $LG_AGENTHEME2 . ' ';
        }
/*
        if ($rechsupplevc1 == '3') {
            $listetheme3 = '<span class="liencat2">' . $LG_AGENTHEME3_1 . ' ';
        } else {
        	$listetheme3 = '<span class="liencat2">' . $LG_AGENTHEME3 . ' ';
        }
*/
    } else {
        $listetheme1 = '<span class="liencat2">' . $LG_AGENTHEME1 . ' ';
        $listetheme2 = '<span class="liencat2">' . $LG_AGENTHEME2 . ' ';
        //$listetheme3 = '<span class="liencat2">' . $LG_AGENTHEME3 . ' ';
    }

    // decodage du texte
    $dossier->titreSortir = stripslashes($dossier->titreSortir);
    $dossier->texteSortir = stripslashes($dossier->texteSortir);
    $dossier->sstitreSortir = stripslashes($dossier->sstitreSortir);
    if ($xlg3 && $resumer == '1') { $dossier->texteSortir = debutchaine($dossier->texteSortir, $xlg3); }
    if (!$xlg3 && $resumer == '1') { $dossier->texteSortir = ''; }
    $dossier->nomCategorie = stripslashes($dossier->nomCategorie);
    $urlfriendly = stripslashes($dossier->dosrewriting);
    $dossier->imageSortir = stripslashes($dossier->imageSortir);
    
    if ($dossier->imageSortir=="") {
        $photo="";
        $photoSchemaorg="" . ARTI_SITE_URL . "" . $mod_encours_dir  . "/img/affiche_defaut.webp";
    } else {
    	$photo="<img alt=\"\" class=\"imgmini\" src=\"images/".$dossier->imageSortir."\">\n";
    	$photoSchemaorg="" . ARTI_SITE_URL . "" . $mod_encours_dir  . "/images/".$dossier->imageSortir."";
    }

    if (ARTI_URL_TYPE == 1) {
        $valurl = 'evenement.php?val=' . $dossier->id_sortir . '_' . $urlfriendly;
    } else {
        $valurl = 'evenement_' . $dossier->id_sortir . '_' . $urlfriendly . '.html';
    }

    // les categories
    $rechidCat = explode('][', trim($dossier->idCat, '[]'));
    $rechidCat2 = explode('][', trim($dossier->idCat2, '[]'));
    $rechidCat3 = explode('][', trim($dossier->id2Cat, '[]'));
    $verifnbCat = 0;
    $verifnbCat2 = 0;
    $verifnbCat3 = 0;
    
    $commune_schemaorg="";

    $ary_listetheme1 = $ary_listetheme1 = $ary_listetheme1 = array();
    $ary_listetheme2 = $ary_listetheme2 = $ary_listetheme2 = array();
    
    $ary_commune_schemaorg = $ary_commune_schemaorg = $ary_commune_schemaorg = array();


    $count_rechidCat = sizeof($rechidCat);
    for ($i = 0; $i < $count_rechidCat; $i++) {
        if (in_array($rechidCat[$i], $paddock1['id'])) {
            if ($cat != $rechidCat[$i]) {
                if (ARTI_URL_TYPE == 1) {
                    $ary_listetheme1[$i] = "<a href=\"index.php?val=" . $paddock1['id'][".$rechidCat[$i]."] . '_' . $paddock1['url'][".$rechidCat[$i]."] . "\">" . stripcslashes($paddock1['nom'][".$rechidCat[$i]."]) . "</a>";
                } else {
                    $ary_listetheme1[$i] = "<a href=\"agenda_categorie_" . $paddock1['id'][".$rechidCat[$i]."] . '_' . $paddock1['url'][".$rechidCat[$i]."] . ".html\">" . stripcslashes($paddock1['nom'][".$rechidCat[$i]."]) . "</a>";
                }
                $verifnbCat++;
            }
        }
    }

    $count_rechidCat2 = sizeof($rechidCat2);
    for ($i = 0; $i < $count_rechidCat2; $i++) {
        if (in_array($rechidCat2[$i], $paddock2['id'])) {
            if ($cat != $rechidCat2[$i]) {
                if (ARTI_URL_TYPE == 1) {
                    $ary_listetheme2[$i] = "<a href=\"index.php?val=" . $paddock2['id'][".$rechidCat2[$i]."] . '_' . $paddock2['url'][".$rechidCat2[$i]."] . "\">" . stripcslashes($paddock2['nom'][".$rechidCat2[$i]."]) . "</a>";
                    $ary_commune_schemaorg[$i] = "" . stripcslashes($paddock2['nom'][".$rechidCat2[$i]."]) . "";
                } else {
                    $ary_listetheme2[$i] = "<a href=\"agenda_categorie_" . $paddock2['id'][".$rechidCat2[$i]."] . '_' . $paddock2['url'][".$rechidCat2[$i]."] . ".html\">" . stripcslashes($paddock2['nom'][".$rechidCat2[$i]."]) . "</a>";
                    $ary_commune_schemaorg[$i] = "" . stripcslashes($paddock2['nom'][".$rechidCat2[$i]."]) . "";
                }
                $verifnbCat2++;
            }
        }
    }
    
    $listetheme1 .= implode(' | ', $ary_listetheme1) . '</span>';
    $listetheme2 .= implode(' | ', $ary_listetheme2) . '</span>';
    $listetheme3 .= implode(' | ', $ary_listetheme3) . '</span>';
    
    $commune_schemaorg .= implode(' - ', $ary_commune_schemaorg) . '';

    // transformation date
    $nommois = $LG_AGENDA_MOIS;

    if ($dossier->ordateinSortir == $dossier->ordateoutSortir) {
        $month = substr($dossier->ordateinSortir, 4, 2);
        $decmonth = substr($dossier->ordateinSortir, 4, 1);
        $decmonth2 = substr($dossier->ordateinSortir, 5, 1);
        if (!$decmonth) { $month = $decmonth2; }

        $day    = substr($dossier->ordateinSortir, 6, 2);
        $year   = substr($dossier->ordateinSortir, 0, 4);
        $nm     = $nommois[$month];
        $affichagedate = sprintf($LG_AGENDA_LE, $day, $nm, $year);
    } else {
        $month = substr($dossier->ordateinSortir, 4, 2);
        $decmonth = substr($dossier->ordateinSortir, 4, 1);
        $decmonth2 = substr($dossier->ordateinSortir, 5, 1);
        if (!$decmonth) { $month = $decmonth2; }

        $day    = substr($dossier->ordateinSortir, 6, 2);
        $year   = substr($dossier->ordateinSortir, 0, 4);
        $nm     = $nommois[$month];

        $month = substr($dossier->ordateoutSortir, 4, 2);
        $decmonth = substr($dossier->ordateoutSortir, 4, 1);
        $decmonth2 = substr($dossier->ordateoutSortir, 5, 1);
        if (!$decmonth) { $month = $decmonth2; }

        $day2   = substr($dossier->ordateoutSortir, 6, 2);
        $year2  = substr($dossier->ordateoutSortir, 0, 4);
        $nm2    = $nommois[$month];
        $affichagedate = sprintf($LG_AGENDA_DU_AU, $day, $nm, $year, $day2, $nm2, $year2);
    }
    // -------------------

    if (!$dossier->sstitreSortir) {
        $listesortir = "\n";
    } else {
        $listesortir = "<br>" . $dossier->sstitreSortir . "\n";
    }

    $liscategorie = '';
    if ($verifnbCat >= 1) {
        $liscategorie .= $listetheme1 . "\n";
    }
    if ($verifnbCat2 >= 1) {
        $liscategorie .= $listetheme2 . "\n";
    }



        $listedossiers .= "<div class=\"catphp\">$photo\n";
        $listedossiers .= "<div class=\"catphp_titre\"><h2><a href=\"" . $valurl . "\">" . $dossier->titreSortir . "</a></h2> <h3>" . $affichagedate . "" . $listesortir . "</h3></div>\n";
        $listedossiers .= "<div class=\"catphp_texte\">" . $dossier->texteSortir . $liscategorie . "\n";
        $listedossiers .= "<span class=\"liencat\"><a href=\"" . $valurl . "\">" . $LG_AGENDETAIL . ' ' . $dossier->titreSortir . "</a></span>\n";
        $listedossiers .= "</div></div>\n";


	// ajout pour schema.org
	$formattedDatein = DateTime::createFromFormat("Ymd", $dossier->ordateinSortir)->format("Y-m-d");
	$formattedDateout = DateTime::createFromFormat("Ymd", $dossier->ordateoutSortir)->format("Y-m-d");
	$affichedesc=str_replace("&quot;"," ",$dossier->texteSortir);
	$affichedesc = html_entity_decode($affichedesc, ENT_QUOTES | ENT_HTML5, 'UTF-8');
	$ix++;
	
	if ($ix<$limitschema) { $virgule=","; } else { $virgule=""; }
	if (empty($commune_schemaorg)) { $commune_schemaorg=$ajschemlieu; }
	$itemListElement .="
	    {
            \"@type\": \"ListItem\",
            \"position\": ".$ix.",
            \"item\": {
              \"@type\": \"Event\",
              \"name\": \"" . $dossier->titreSortir . "\",
              \"description\": \"" . $affichedesc . "\",
              \"url\": \"https://www.cholet.fr/agenda/" . $valurl . "\", 
              \"image\": \"" . $photoSchemaorg . "\",
              \"startDate\": \"".$formattedDatein."\",
              \"endDate\": \"".$formattedDateout."\",
              \"eventStatus\": \"https://schema.org/EventScheduled\",
              \"eventAttendanceMode\": \"https://schema.org/OfflineEventAttendanceMode\",
    		  \"location\": {
      			\"@type\": \"Place\",
      			\"name\": \"" . $commune_schemaorg . "\",
      			\"address\": {
        			\"@type\": \"PostalAddress\",
        			\"addressLocality\": \"" . $commune_schemaorg . "\",
        			\"addressCountry\": \"FR\"
      			}
      		  }
            }
        }".$virgule."
	";



}



// -----------------------------------------------------------------------
// Deuxieme partie du code de pagination
// (à modifier si vous avez d'autres donn&eacute;es à faire circuler dans l'URL)
// -----------------------------------------------------------------------

if ($cat) {

    $ajoutrewrite2 = '_' . $cat_url_friendly;
    $ajoutmotcat = 'agenda_categorie_';
    $ajoutmotcat2 = 'agenda_cat_';

    $ajoutval = 'val2=' . $cat . '_';
    $ajoutval2 = 'val=' . $cat;

} else if ($date_evenement) {

    $ajoutrewrite2 = '';
    $ajoutmotcat = 'agenda_date_';
    $ajoutmotcat2 = 'agenda_date2_';

    $ajoutval = 'val5=' . $date_evenement . '_';
    $ajoutval2 ='date_evenement=' . $date_evenement;
    
} else if ($date_semaine) {

    $ajoutrewrite2 = '';
    $ajoutmotcat = 'agenda_semaine_';
    $ajoutmotcat2 = 'agenda_semaine2_';

    $ajoutval = 'val6=' . $semaine . '_';
    $ajoutval2 ='s=' . $semaine;
    
} else if ($date_mois) {

    $ajoutrewrite2 = '';
    $ajoutmotcat = 'agenda_mois_';
    $ajoutmotcat2 = 'agenda_mois2_';

    $ajoutval = 'val7=' . $mois . '_';
    $ajoutval2 ='m=' . $mois;

} else {

    $ajoutrewrite2 = '';
    $ajoutmotcat = 'index.php';
    $ajoutmotcat2 = 'agenda_';

    $ajoutval = 'val3=';
    $ajoutval2 = '';

}

if ($page != 0) {
    $pagination = '';
    $back_page = $page - $limit;

    if (ARTI_URL_TYPE == 1) {

        if ($back_page == '0') {
            if ($cat) {
                $pagination .= "<a href=\"$PHP_SELF?" . $ajoutval2 . $ajoutrewrite2 . "\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_evenement) {
                $pagination .= "<a href=\"$PHP_SELF?" . $ajoutval2 . "\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_semaine) {
                $pagination .= "<a href=\"$PHP_SELF?" . $ajoutval2 . "\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_mois) {
                $pagination .= "<a href=\"$PHP_SELF?" . $ajoutval2 . "\">&#171; $LG_PGPRECED</a> | \n";
            } else {
                $pagination .= "<a href=\"$PHP_SELF\">&#171; $LG_PGPRECED</a> | \n";
            }
        } else {
            $pagination .= "<a href=\"$PHP_SELF?" . $ajoutval . $back_page . '_' . $limit . $ajoutrewrite2 . "\">&#171; $LG_PGPRECED</a> | \n";
        }

    } else {

        if ($back_page == '0') {
            if ($cat) {
                $pagination .= "<a href=\"" . $ajoutmotcat . $cat . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_evenement) {
                $pagination .= "<a href=\"" . $ajoutmotcat . $date_evenement . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_semaine) {
                $pagination .= "<a href=\"" . $ajoutmotcat . $date_semaine . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_mois) {
                $pagination .= "<a href=\"" . $ajoutmotcat . $date_mois . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else {
                $pagination .= "<a href=\"" . $ajoutmotcat . "\">&#171; $LG_PGPRECED</a> | \n";
            }
        } else {
            if ($cat) {
                $pagination .= "<a href=\"" . $ajoutmotcat2 . $cat . '_' . $back_page . '_' . $limit . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_evenement) {
                $pagination .= "<a href=\"" . $ajoutmotcat2 . $date_evenement . '_' . $back_page . '_' . $limit . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_semaine) {
                $pagination .= "<a href=\"" . $ajoutmotcat2 . $date_semaine . '_' . $back_page . '_' . $limit . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else if ($date_mois) {
                $pagination .= "<a href=\"" . $ajoutmotcat2 . $date_mois . '_' . $back_page . '_' . $limit . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
            } else {
                $pagination .= "<a href=\"" . $ajoutmotcat2 . $back_page . '_' . $limit . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
            }
        }
    }
}

for ($i = 1; $i <= $pages; $i++) {
    $ppage = $limit * ($i - 1);
    if ($ppage == $page) {
        if ($total == 1) {
            $pagination .= '';
        } else {
            $pagination .= "<strong>" . $LG_PAGE . " $i/$pages</strong> | \n";
            $ajmeta = '- ' . $LG_PAGE . " $i/$pages -";
        }
    }
}

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
    $next_page = $page + $limit;

    if (ARTI_URL_TYPE == 1) {
        $pagination .= "<a href=\"$PHP_SELF?" . $ajoutval . $next_page . '_' . $limit . $ajoutrewrite2 . "\">$LG_PGSUITE &#187;</a>\n";
    } else {
        if ($cat) {
            $pagination .= "<a href=\"" . $ajoutmotcat2 . $cat . '_' . $next_page . '_' . $limit . $ajoutrewrite2 . ".html\">$LG_PGSUITE &#187;</a>\n";
        } else if ($date_evenement) {
            $pagination .= "<a href=\"" . $ajoutmotcat2 . $date_evenement . '_' . $next_page . '_' . $limit . ".html\">$LG_PGSUITE &#187;</a>\n";
        } else if ($date_semaine) {
            $pagination .= "<a href=\"" . $ajoutmotcat2 . $date_semaine . '_' . $next_page . '_' . $limit . ".html\">$LG_PGSUITE &#187;</a>\n";
        } else if ($date_mois) {
            $pagination .= "<a href=\"" . $ajoutmotcat2 . $date_mois . '_' . $next_page . '_' . $limit . ".html\">$LG_PGSUITE &#187;</a>\n";
        } else {
            $pagination .= "<a href=\"" . $ajoutmotcat2 . $next_page . '_' . $limit . ".html\">$LG_PGSUITE &#187;</a>\n";
        }
    }
}

if (!$pagination) {
    $finpag .= '';
} else {
    $debutpag .= "<div class=\"entete2\">";
    $finpag .= "</div>";
}
// -------------------------------------------------------------------------

// metatags
if ($cat) {
    $nCat = htmlspecialchars($nomCategorie);
    $nCat2 = htmlspecialchars($nomCategorieParent);
    $metatitle = $nCat . ' ' . $ajmeta . ' ' . $nCat2 . ' - ' . ARTI_SITE_NAME;
    $nCatDes = strip_tags($describeCategorie);
    $nCatDes = htmlspecialchars($nCatDes);
    $metaDescription = $LG_METACAT . ' ' . $nCatDes . ' - ' . $nCat . ' ' . $nCat2 . ' ' . $LG_METADESCCAT;
} else if ($date_evenement) {
    include('langues/' . $SESSION_LANGSKIN . '/metatags.inc.php');
    $metatitle = $day10 . '-' . $month10 . '-' . $year10 . ' - ' . $ajmeta . ' ' . $LG_METATITLE . ' - ' . ARTI_SITE_NAME;
    $metaDescription = $LG_METADESC . ' - ' . $metaplus;
} else if ($date_semaine) {
    include('langues/' . $SESSION_LANGSKIN . '/metatags.inc.php');
    $metatitle = 'Semaine du ' . $day11 . '-' . $month11 . '-' . $year11 . ' - ' . $ajmeta . ' ' . $LG_METATITLE . ' - ' . ARTI_SITE_NAME;
    $metaDescription = $LG_METADESC . ' - ' . $metaplus;
} else if ($date_mois) {
    include('langues/' . $SESSION_LANGSKIN . '/metatags.inc.php');
    $metatitle = 'Agenda du mois ' . $month12 . '-' . $year12 . ' - ' . $ajmeta . ' ' . $LG_METATITLE . ' - ' . ARTI_SITE_NAME;
    $metaDescription = $LG_METADESC . ' - ' . $metaplus;
} else {
    include('langues/' . $SESSION_LANGSKIN . '/metatags.inc.php');
    $metatitle = $ajmeta . ' ' . $LG_METATITLE . ' - ' . ARTI_SITE_NAME;
    $metaDescription = $LG_METADESC . ' - ' . $metaplus;
}


// schema.org
// -----------------------

$activschemeorg="1";  

if (empty($suppschem))	 {
 $schemeorg="
 <script type=\"application/ld+json\">
 {
  \"@context\": \"https://schema.org\",
  \"@graph\": [
    {
      \"@type\": \"CollectionPage\",
      \"@id\": \"https://www.cholet.fr/agenda/#webpage\",
      \"url\": \"https://www.cholet.fr/agenda/\",
      \"name\": \"Agenda Officiel : Événements de la Ville et de l'Agglomération de Cholet\",
      \"description\": \"Retrouvez le calendrier complet des manifestations, spectacles, expositions et événements sportifs à Cholet et dans son agglomération.\",
      \"publisher\": {
        \"@id\": \"https://www.cholet.fr/#organization\"
      },

      \"mainEntity\": {
        \"@type\": \"ItemList\",
        \"itemListElement\": [
                
        ".$itemListElement."


        ]
      }
    },
    
    {
      \"@type\": \"GovernmentOrganization\",
      \"@id\": \"https://www.cholet.fr/#organization\",
      \"name\": \"Cholet, Ville et Agglomération\"
    }
  ]
 }
 </script>
 ";
}
// -----------------------
// fin schema.org



mysql_free_result($result);
// --------

// presentation
// ------------
$milieu  = "<div id=\"mod_agenda\" class=\"mod_content\">\n";
$milieu .= $entete2;
$milieu .= $debutpag . ' ' . $pagination . ' ' . $finpag;
$milieu .= $listedossiers;
$milieu .= $debutpag . ' ' . $pagination . ' ' . $finpag;
$milieu .= "</div>\n";

// Template
// --------
$SESSION_SKIN = $_SESSION['SESSION_SKIN'];
include(ARTI_SYS_INT_PATH . "templates/temp$SESSION_SKIN/temp.html");
echo $arti;
mysql_close($link);
?>