<?php
/**
** @Artiphp 5
* @paquetage agenda
* @version evenement.php, 2011/11/27 arteam
* @copyright (c) 2001-2011 Ronald Guérin - 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

include_once(ARTI_SYS_INT_FCT_PATH . 'fonctions_date.inc.php');

include(ARTI_SYS_INT_FCT_PATH . 'video.inc.php'); 		// miniature video

$date = date('Ymd');

// affichage d'un evenement specifique
// -----------------------------------
$id = $_GET['id'];

if ($_GET['val']) {
    $val = $_GET['val'];
    list($id, $suite) = explode('_', $val);
    $suite = htmlentities(urlencode($suite));
}
$id = intval($id);

if ($id) {

    /* 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;
                }
            }
        }
    }

    //$requete = "SELECT * FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "` WHERE ordateoutSortir>=$date AND id_sortir='$id' AND pubDossier='1'";
    $requete = "SELECT * FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "` WHERE id_sortir='$id' AND pubDossier='1'";
    $result2 = mysql_query($requete, $link);
    
    if (mysql_num_rows($result2)==0) {
	    header('HTTP/1.0 404 Not Found');
        header('Location: ' . ARTI_WEB_INT_FCT_PATH . '404.php');
        exit();
    } else {
        $sortir = mysql_fetch_object($result2); 
    }

    $sortir->titreSortir = stripslashes($sortir->titreSortir);
    $sortir->sstitreSortir = stripslashes($sortir->sstitreSortir);
    $sortir->texteSortir = stripslashes($sortir->texteSortir);
    $sortir->infoSortir = stripslashes($sortir->infoSortir);
    $sortir->billetterie = stripslashes($sortir->billetterie);
    
    $id_auteur = intval($sortir->id_auteur);

    // personnalisation
    include(ARTI_SYS_PATH . $mod_encours_dir . '/personnalisation.inc.php');
    if (!($ascdesc)) {$ascdesc = 'asc';}
    if (!($ordre)) {$ordre = 'ordateoutSortir';}
    $ajout_sql_suiv = 'AND ' . $ordre . ($ascdesc == 'asc' ? '>=' : '<=') . "'" . addslashes($sortir->{$ordre}) . "'";
    $ajout_sql_prec = 'AND ' . $ordre . ($ascdesc == 'asc' ? '<=' : '>=') . "'" . addslashes($sortir->{$ordre}) . "'";
    $ascdesc_prec = $ascdesc == 'asc' ? 'desc' : 'asc' ;

    // les categories
    $rechidCat = explode('][', trim($sortir->idCat, '[]'));
    $rechidCat2 = explode('][', trim($sortir->idCat2, '[]'));
    $rechidCat3 = explode('][', trim($sortir->id2Cat, '[]'));
    $verifnbCat = 0;
    $verifnbCat2 = 0;
    $verifnbCat3 = 0;

    $listetheme = $listetheme2 = $listetheme3 = array();

    $count_rechidCat = sizeof($rechidCat);
    for ($i = 0; $i < $count_rechidCat; $i++) {
        if (in_array($rechidCat[$i], $paddock1['id'])) {
            if (ARTI_URL_TYPE == 1) {
                $listetheme1[$i] = "<a href=\"index.php?val=" . $paddock1['id'][".$rechidCat[$i]."] . '_' . $paddock1['url'][".$rechidCat[$i]."] . "\">" . $paddock1['nom'][".$rechidCat[$i]."] . "</a>";
            } else {
                $listetheme1[$i] = "<a href=\"agenda_categorie_" . $paddock1['id'][".$rechidCat[$i]."] . '_' . $paddock1['url'][".$rechidCat[$i]."] . ".html\">" . $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 (ARTI_URL_TYPE == 1) {
                $listetheme2[$i] = "<a href=\"index.php?val=" . $paddock2['id'][".$rechidCat2[$i]."] . '_' . $paddock2['url'][".$rechidCat2[$i]."] . "\">" . $paddock2['nom'][".$rechidCat2[$i]."] . "</a>";
            } else {
                $listetheme2[$i] = "<a href=\"agenda_categorie_" . $paddock2['id'][".$rechidCat2[$i]."] . '_' . $paddock2['url'][".$rechidCat2[$i]."] . ".html\">" . $paddock2['nom'][".$rechidCat2[$i]."] . "</a>";
            }
            $lieuscheme = "" . $paddock2['nom'][".$rechidCat2[$i]."] . "";
            $verifnbCat2++;
        }
    }

/*
    $count_rechidCat3 = sizeof($rechidCat3);
    for ($i = 0; $i < $count_rechidCat3; $i++) {
        if (in_array($rechidCat3[$i], $paddock3['id'])) {
            if (ARTI_URL_TYPE == 1) {
                $listetheme3[$i] = "<a href=\"index.php?val=" . $paddock3['id'][".$rechidCat3[$i]."] . '_' . $paddock3['url'][".$rechidCat3[$i]."] . "\">" . $paddock3['nom'][".$rechidCat3[$i]."] . "</a>";
            } else {
                $listetheme3[$i] = "<a href=\"agenda_categorie_" . $paddock3['id'][".$rechidCat3[$i]."] . '_' . $paddock3['url'][".$rechidCat3[$i]."] . ".html\">" . $paddock3['nom'][".$rechidCat3[$i]."] . "</a>";
            }
            $verifnbCat3++;
        }
    }
*/

    // metatags
    $nDoss = htmlspecialchars($sortir->titreSortir);
    $nDoss2 = htmlspecialchars($sortir->sstitreSortir);
    $metatitle = $nDoss." ".$nDoss2." - ".ARTI_SITE_NAME;
    $nDossDes = strip_tags($sortir->texteSortir);
    $nDossDes = htmlspecialchars($nDossDes);
    $metaDescription = $nDoss." ".$nDoss2." - ".$nDossDes;
    // --------

    // transformation date
    $nommois = $LG_AGENDA_MOIS;

    if ($sortir->ordateinSortir == $sortir->ordateoutSortir) {
        $month = substr($sortir->ordateinSortir, 4, 2);
        $decmonth = substr($sortir->ordateinSortir, 4, 1);
        $decmonth2 = substr($sortir->ordateinSortir, 5, 1);
        if (!$decmonth) { $month = $decmonth2; }

        $day    = substr($sortir->ordateinSortir, 6, 2);
        $year   = substr($sortir->ordateinSortir, 0, 4);
        $nm     = $nommois[$month];
        $affichagedate = sprintf($LG_AGENDA_LE, $day, $nm, $year);
    } else {
        $month = substr($sortir->ordateinSortir, 4, 2);
        $decmonth = substr($sortir->ordateinSortir, 4, 1);
        $decmonth2 = substr($sortir->ordateinSortir, 5, 1);
        if (!$decmonth) { $month = $decmonth2; }

        $day    = substr($sortir->ordateinSortir, 6, 2);
        $year   = substr($sortir->ordateinSortir, 0, 4);
        $nm     = $nommois[$month];

        $month = substr($sortir->ordateoutSortir, 4, 2);
        $decmonth = substr($sortir->ordateoutSortir, 4, 1);
        $decmonth2 = substr($sortir->ordateoutSortir, 5, 1);
        if (!$decmonth) { $month = $decmonth2; }

        $day2   = substr($sortir->ordateoutSortir, 6, 2);
        $year2  = substr($sortir->ordateoutSortir, 0, 4);
        $nm2    = $nommois[$month];
        $affichagedate = sprintf($LG_AGENDA_DU_AU, $day, $nm, $year, $day2, $nm2, $year2);
    }
    // -------------------
    
    if ($sortir->imageSortir2=="") {
	  if ($sortir->imageSortir=="") {
	    $photo="";
	    $pos_video="top";
	    $photoSchemaorg="" . ARTI_SITE_URL . "" . $mod_encours_dir  . "/img/affiche_defaut.webp";
	  } else {
            $photo="<img alt=\"\" src=\"images/".$sortir->imageSortir."\">\n";
            $photoSchemaorg="" . ARTI_SITE_URL . "" . $mod_encours_dir  . "/images/".$sortir->imageSortir."";
	    $pos_video="top";
	  }
	} else {
          $photo="<img alt=\"\" src=\"images/".$sortir->imageSortir2."\" class=\"imgbig\">\n";
          $photoSchemaorg="" . ARTI_SITE_URL . "" . $mod_encours_dir  . "/images/".$sortir->imageSortir2."";
	  $pos_video="bottom";
	}
    
    // ---------------------
    // scheme.org
    // ---------------------
$activschemeorg="1";  
$timein= strtotime ($sortir->ordateinSortir);
$transfodatein= date('Y-m-d', $timein);
$timeout= strtotime ($sortir->ordateoutSortir);
$transfodateout= date('Y-m-d', $timeout);
$descripscheme = strip_tags($sortir->texteSortir);
$descripscheme = preg_replace('/\s\s+/', ' ', $descripscheme);
$nbmots=20;



$tab = explode(' ', $descripscheme);
        if (count($tab) <= $nbmots) {
            $affichedesc = $descripscheme;
        } else {
            $affichedesc = $tab[0];
            for ($i = 1; $i < $nbmots; $i++) {
                $affichedesc .= ' ' . $tab[$i];
            }
            $affichedesc .= '...';
        }

$affichedesc=str_replace("&quot;"," ",$affichedesc);
$affichedesc=html_entity_decode($affichedesc, ENT_QUOTES | ENT_HTML5, 'UTF-8');

$schemeorg="
<!-- Scheme.org -->
  <script type=\"application/ld+json\">
  {
    \"@context\": \"https://schema.org\",
    \"@type\": \"Event\",
    \"name\": \"".$sortir->titreSortir."\",
    \"startDate\": \"". $transfodatein ."\",
    \"endDate\": \"". $transfodateout ."\",
    \"image\": \"" . $photoSchemaorg . "\",
    \"location\": {
      \"@type\": \"Place\",
      \"name\": \"".strip_tags($sortir->infoSortir)."\",
      \"address\": {
        \"@type\": \"PostalAddress\",
        \"addressLocality\": \"" . $lieuscheme . "\",
        \"addressCountry\": \"FR\"
      }
    },
    \"description\": \"".strip_tags($affichedesc)."\",
    \"eventStatus\": \"https://schema.org/EventScheduled\",
    \"eventAttendanceMode\": \"https://schema.org/OfflineEventAttendanceMode\"
  }
  </script>
<!-- Fin Scheme.org -->
";

    // ---------------------
    // FIN scheme.org
    // ---------------------




    $listesortir .= "<div class=\"dossier\">\n";
    $listesortir .= "<div class=\"titre\"><h1>$sortir->titreSortir</h1></div>\n";
    $listesortir .= "<div class=\"texte\"><h2>$affichagedate</h2>\n";

    if (!$sortir->sstitreSortir) {
        $listesortir .= "\n";
    } else {
        $listesortir .= "<h3>" . $sortir->sstitreSortir . "</h3>\n";
    }
    
    


	if ($sortir->video=="") {
		$video="";
	} else {

	  if ($sortir->imageSortir2=="") {$photo="";}

  
  		$url="$sortir->video";
  		$domain=parse_url($url,PHP_URL_HOST);
  		if($domain=='www.youtube.com' OR $domain=='youtube.com') {
	    	if($querystring=parse_url($url,PHP_URL_QUERY)) {  
	        	parse_str($querystring);
	        	if(!empty($v)) {
	        		$video = "<div class=\"youtube-facade\" data-id=\"" . $v . "\" style=\"background-image: url('https://i.ytimg.com/vi/" . $v . "/maxresdefault.jpg');\">\n";
	        		$video .= "<div class=\"play-button\"></div><small>En cliquant sur Play, vous acceptez le transfert de données vers YouTube.</small>\n";
	        		$video .= "</div>\n";
	        	}
	    	}
		} elseif ($domain == 'youtu.be') {

	    	$v= str_replace('/','', parse_url($url, PHP_URL_PATH));
	        	if(!empty($v)) {
	        		$video = "<div class=\"youtube-facade\" data-id=\"" . $v . "\" style=\"background-image: url('https://i.ytimg.com/vi/" . $v . "/maxresdefault.jpg');\">\n";
	        		$video .= "<div class=\"play-button\"></div><small>En cliquant sur Play, vous acceptez le transfert de données vers YouTube.</small>\n";
	        		$video .= "</div>\n";
	        	}
		} elseif ($domain == 'www.dailymotion.com' OR $domain=='dailymotion.com') {

	    	$v= str_replace('/video/','', parse_url($url, PHP_URL_PATH));
	        	if(!empty($v)) {
	        		$video = "\n<div class=\"video_agd\">\n";
					$video .= "<iframe class=\"video_youtube\" src=\"https://www.dailymotion.com/embed/video/" . $v . "\" frameborder=\"0\" allowfullscreen></iframe>";
					$video .= "</div>\n";
	        	}
		} elseif ($domain == 'vimeo.com') {
	    	$v= str_replace('/','', parse_url($url, PHP_URL_PATH));
	        	if(!empty($v)) {
	        		$video = "\n<div class=\"video_agd\">\n";
					$video .= "<iframe class=\"video_youtube\" src=\"//player.vimeo.com/video/" . $v . "?title=0&amp;byline=0&amp;portrait=0\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";
					$video .= "</div>\n";
	        	}
		}
	
	}

	if ($pos_video=='top') {
		$listesortir .= "".$video."\n";
	}


	$listesortir .= "<div class=\"age_txt\">". $photo ."";

	$listesortir .= "".$sortir->texteSortir."</div>\n";

	if ($pos_video=='bottom') {
		$listesortir .= "".$video."\n";
	}
	
	// test recherche mail dans infoSortir
	// l'expression pour reperer une adresse email
    $email_regex = "/^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}/";

    $in = array( '`([[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-_.]?[[:alnum:]])*\.([a-z]{2,' . '4}))`',); 
    $out = array( '<a href="mailto:\\1">\\1</a>',);
    
    $sortir->infoSortir = preg_replace("#((http(s?)://)(([[:alnum:]]|[-\%\.\?\=\#\_\:\&\/\~\+\@\,\;])*))#",
    "<a href = '\\0'>\\4</a>", $sortir->infoSortir);
    
    $sortir->infoSortir = preg_replace("#(([^/])www\.|(^www\.))(([[:alnum:]]|[-\%\.\?\=\#\_\:\&\/\~\+\@\,\;])*)#",
    " <a href = 'https://www.\\4'" . ">\\4</a>",$sortir->infoSortir);
     
$sortir->infoSortir = preg_replace($in, $out, $sortir->infoSortir);
	
	// fin test recherche mail

	// recherche numero de tel et formatage
		$pattern = '/\d{10}|\+33\d{9}|\+33\s\d{1}\s\d{2}\s\d{2}\s\d{2}\s\d{2}|\d{2}\s\d{2}\s\d{2}\s\d{2}\s\d{2}|0\d(?:\.\d{2}){4}|0\d(?:-\d{2}){4}/';
	
		if (preg_match($pattern, $sortir->infoSortir, $m)) {

    		$affnumero = $m[0];
    		$numerotel = $m[0];
    		
    		$numerotel = str_replace('.', '', $numerotel);
    		$numerotel = str_replace(' ', '', $numerotel);
    		$numerotel = str_replace('-', '', $numerotel);
    		
    		$sortir->infoSortir = str_replace($affnumero, " <a href = 'tel:$numerotel'>$affnumero</a>",$sortir->infoSortir);

		}

	// fin recherche numero de tel
	
	
	$listesortir .= "<div><div class=\"age_supp\">".$sortir->infoSortir."</div></div>\n";

	if ($pos_video=='very_bottom') {
		$listesortir .= "".$video."\n";
	}



/* BILLETTERIE */
  	  if (!$sortir->billetterie) {
  	  
	  } else {  
	  		$listesortir .= "<p id=\"billetterie\"><a href=\"".$sortir->billetterie."\" title=\"".$sortir->titreSortir." - Achetez votre billet\"><img src=\"reservation.webp?2026\" alt=\"".$sortir->titreSortir." - Réserver votre place\"></a></p>\n";
  	  }




/* FIN BILLETTERIE */



        $listesortir .= "</div>\n";
        




    // en-tete de page
    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>";
    

    $ary_cats_entete = array();

    if ($verifnbCat >= 1) {
        $listesortir .= '<span class="liencat2">' . $LG_AGENTHEME1 . ' ' . implode(' | ', $listetheme1) . "</span>\n";
        //$ary_cats_entete[] = $LG_AGENDA_PARTHEMES . ' [' . implode('][', $listetheme1) . ']';
    }
    if ($verifnbCat2 >= 1) {
        $listesortir .= '<span class="liencat2">' . $LG_AGENTHEME2 . ' ' . implode(' | ', $listetheme2) . "</span>\n";
        //$ary_cats_entete[] = $LG_AGENDA_PARLIEUX . ' [' . implode('][', $listetheme2) . ']';
    }
    
    /*
    if ($verifnbCat3 >= 1) {
        $listesortir .= '<span class="liencat2">' . $LG_AGENTHEME3 . ' ' . implode(' | ', $listetheme3) . "</span>\n";
        //$ary_cats_entete[] = $LG_AGENDA_PARPUBLICS . ' [' . implode('][', $listetheme3) . ']';
    }
    */

    // suite en-tete de page
    //$entete .= implode(' | ', $ary_cats_entete) . '/'; // Mettre en commentaire pour ne pas afficher les catégories
    
    //$entete .= "$sortir->titreSortir\n";


    


    $listesortir .= "</div>\n";

    // DEBUT Rapid'Admin
    //if ($rapid_admin == '1' && $SESSION_ARTIGROUP == '1') {
    if ($rapid_admin == '1') {
    
        $reqprec = "SELECT group_contenu FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "_admin` WHERE id_categorie='1'";
    	$result2 = mysql_query($reqprec, $link);
		$breveprec = mysql_fetch_object($result2);
        
    	$groupcat = explode('][', trim($breveprec->group_contenu, '[]'));
    	if (in_array($SESSION_ARTIGROUP, $groupcat)) {
        	$listesortir .= "<div class=\"rapid_admin\">" . $LG_RAPID_ADMIN . " <a href=\"" . ARTI_WEB_ADM_PATH . $mod_encours_dir . "/saisie.php?id_dossier=" . $id . "\"><img src=\"" . ARTI_WEB_ADM_ADM_PATH . "imgadmin/bbmodif.gif\" alt=\"" . $LG_FORMMOD . "\"></a></div>\n";
		}
    }
    // FIN Rapid'Admin
}

// Presentation
// ------------

$milieu  = "<div id=\"mod_agenda\" class=\"mod_content\">\n";
$milieu .= $listesortir;

        if ($sortir->dateDossier=='0000-00-00 00:00:00') {
        } else {
        	$milieu .= "<p><br><br><em>Derni&egrave;re mise &agrave; jour : " . arti_date_court($sortir->dateDossier) . "</em></p>";
        }

$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);
?>