Rev 399 | Rev 468 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*vim: set expandtab tabstop=4 shiftwidth=4: */// +------------------------------------------------------------------------------------------------------+// | PHP version 4.1 |// +------------------------------------------------------------------------------------------------------+// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |// +------------------------------------------------------------------------------------------------------+// | This library is free software; you can redistribute it and/or |// | modify it under the terms of the GNU Lesser General Public |// | License as published by the Free Software Foundation; either |// | version 2.1 of the License, or (at your option) any later version. |// | |// | This library is distributed in the hope that it will be useful, |// | but WITHOUT ANY WARRANTY; without even the implied warranty of |// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |// | Lesser General Public License for more details. |// | |// | You should have received a copy of the GNU Lesser General Public |// | License along with this library; if not, write to the Free Software |// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |// +------------------------------------------------------------------------------------------------------+// CVS : $Id: bazar.fonct.cal.php,v 1.29 2008-10-29 10:38:51 alexandre_tb Exp $/**** Fonctions calendrier du module bazar** TODO : ajouter la gestion du multilinguisme**@package bazar//Auteur original :*@author David Delon <david.delon@clapas.net>//Autres auteurs :*@copyright Tela-Botanica 2000-2004*@version $Revision: 1.29 $ $Date: 2008-10-29 10:38:51 $// +------------------------------------------------------------------------------------------------------+*/// +------------------------------------------------------------------------------------------------------+// | ENTETE du PROGRAMME |// +------------------------------------------------------------------------------------------------------+require_once PAP_CHEMIN_RACINE.'api/pear/Calendar/Month/Weekdays.php';require_once PAP_CHEMIN_RACINE.'api/pear/Calendar/Day.php';require_once PAP_CHEMIN_RACINE.'api/pear/Calendar/Decorator.php';// +------------------------------------------------------------------------------------------------------+// | LISTE de FONCTIONS |// +------------------------------------------------------------------------------------------------------+// Classe Utilitaire pour Calendrierclass DiaryEvent extends Calendar_Decorator {var $entry = array();function DiaryEvent($calendar){Calendar_Decorator::Calendar_Decorator($calendar);}function setEntry($entry){$this->entry[] = $entry;}function getEntry(){return $this->entry;}}// $type : calendrier// $type : calendrier_appplettefunction GestionAffichageCalendrier($arguments = array(), $type = 'calendrier') {$script = '';// recuperation des arguments de l applette$balise = isset ($arguments[0]) ? $arguments[0] : '';$tab_arguments = $arguments;if (is_string ($tab_arguments)) {$tab_arguments = substr($tab_arguments, 1);} else {unset($tab_arguments[0]);}if (is_array($tab_arguments)) {foreach($tab_arguments as $argument) {if ($argument != '') {$tab_parametres = explode('=', $argument, 2);if (is_array($tab_parametres)) {$options[$tab_parametres[0]] =(isset($tab_parametres[1])? trim($tab_parametres[1], '"') : '') ;}}}}if (!isset($options['template'])) {$options['template'] = BAZ_CHEMIN_SQUELETTE.BAZ_SQUELETTE_DEFAUT;} else {if (file_exists(BAZ_CHEMIN_SQUELETTE.$options['template'])) {$options['template'] = BAZ_CHEMIN_SQUELETTE.$options['template'];}}$retour = '';$url = $GLOBALS['_GEN_commun']['url'] ;$db =& $GLOBALS['_GEN_commun']['pear_db'] ;$auth =& $GLOBALS['_GEN_commun']['pear_auth'] ;// Nettoyage de l'url de la query string$chaine_url = $url->getQueryString();$tab_params = explode('&', $chaine_url);if (count($tab_params) == 0) {$tab_params = explode('&', $chaine_url);}foreach ($tab_params as $param) {$tab_parametre = explode('=', $param);$url->removeQueryString($tab_parametre[0]);}if (!isset($_GET['y'])) {$_GET['y'] = date('Y');}if (!isset($_GET['m'])) {$_GET['m'] = date('m');}// Construction Mois en Cours$month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']);$curStamp = $month->getTimeStamp();$url->addQueryString('y', date('Y',$curStamp));$url->addQueryString('m', date('n',$curStamp));$url->addQueryString('d', date('j',$curStamp));$cur = $url->getUrl();// Gestion de l'affichage du filtre des natures d'évènements$cal_num_annonce = BAZ_NUM_ANNONCE_CALENDRIER;$ficnat_id = null;if (isset($_GET['ficnat']) && $_GET['ficnat'] != '*') {$ficnat_id = $_GET['ficnat'];$url->addQueryString('ficnat', $_GET['ficnat']);$cal_num_annonce = $_GET['ficnat'];}// Gestion de l'affichage des titres des évènementsif (isset($_GET['ctt']) && $_GET['ctt'] == '1') {$url->addQueryString('tt', '0');if (isset($_GET['tt']) && $_GET['tt'] == '0') {$url->addQueryString('tt', '1');}$tc_lien = $url->getUrl();} else {$url->addQueryString('tt', '0');if (isset($_GET['tt']) && $_GET['tt'] == '0') {$url->addQueryString('tt', '1');}$url->addQueryString('ctt', '1');$tc_lien = $url->getUrl();}$url->removeQueryString('ctt');$url->removeQueryString('tt');$tc_txt = 'Afficher les titres complets des évènements';if (isset($_GET['tt']) && $_GET['tt'] == '0') {$tc_txt = 'Tronquer les titres des évènements';$url->addQueryString('tt', $_GET['tt']);}// Gestion des champs cachés pour le formulaire de filtre// Attention à la position dans le fichier...$ficnat_chps_cache = $url->querystring;unset($ficnat_chps_cache['ficnat']);// Navigation$prevStamp = $month->prevMonth(true);$url->addQueryString('y', date('Y',$prevStamp));$url->addQueryString('m', date('n',$prevStamp));$url->addQueryString('d', date('j',$prevStamp));$prev = $url->getUrl();$nextStamp = $month->nextMonth(true);$url->addQueryString('y', date('Y',$nextStamp));$url->addQueryString('m', date('n',$nextStamp));$url->addQueryString('d', date('j',$nextStamp));$next = $url->getUrl();// Suppression du paramêtre de troncage des titres$url->removeQueryString('tt');$fr_month = array( "1"=>BAZ_JANVIER,"2"=>BAZ_FEVRIER,"3"=>BAZ_MARS,"4"=>BAZ_AVRIL,"5"=>BAZ_MAI,"6"=>BAZ_JUIN,"7"=>BAZ_JUILLET,"8"=>BAZ_AOUT,"9"=>BAZ_SEPTEMBRE,"10"=>BAZ_OCTOBRE,"11"=>BAZ_NOVEMBRE,"12"=>BAZ_DECEMBRE);// Récupération des infos sur les natures des fiches pour le filtre$requete_nature_fiche = 'SELECT DISTINCT bn_id_nature, bn_ce_i18n, bn_label_nature '.'FROM bazar_nature '.'WHERE bn_id_nature IN ('.BAZ_NUM_ANNONCE_CALENDRIER.') ';$resultat_nature_fiche = $db->query($requete_nature_fiche);(DB::isError($resultat_nature_fiche)) ? trigger_error(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_nature_fiche->getMessage(), $requete_nature_fiche), E_USER_WARNING) : '';// Ajout du javascript et des styles du bazarif (defined('PAP_VERSION')) { //si on est dans PapyrusGEN_stockerStyleExterne( 'bazar_interne', 'client/bazar/bazar.interne.css');GEN_stockerFichierScript('domLib', '/api/js/domtooltip/domLib.js');GEN_stockerFichierScript('domTT', '/api/js/domtooltip/domTT.js');// DomToolTip$script = 'var domTT_styleClass = "niceTitle";'."\n";$script .= 'function nicetitleDecorator(el) {'."\n";$script .= ' var result = el.title;'."\n";$script .= ' result = result.replace(new RegExp("\n", "g"), "<br />");'."\n";$script .= ' //if (el.href) {'."\n";$script .= ' //result += "<p>" + el.href + "<\/p>";'."\n";$script .= ' //}'."\n";$script .= ' return result;'."\n";$script .= '}'."\n";$script .= 'domTT_replaceTitles(nicetitleDecorator);'."\n";GEN_stockerCodeScript('var domTT_styleClass = "niceTitle";'."\n");}// Titreif ($type == 'calendrier') {$retour .= '<div id="cal_entete">'."\n";$retour .= '<span class="cal_navigation">'."\n";$retour .= '<a id="cal_precedent_lien" href="'.$prev.'" title="Allez au mois précédent"><img id="cal_precedent_img" src="client/bazar/images/cal_precedent.png" alt="<<"/></a>'."\n";$retour .= ' '."\n";$retour .= '<span id="cal_encadre_mois_courrant"><a id="cal_mois_courrant" href="'.$cur.'">';$retour .= $fr_month[(date('n',$curStamp))];$retour .= ' ';$retour .= (date('Y',$curStamp));$retour .= '</a></span>'."\n";$retour .= ' '."\n";$retour .= '<a id="cal_suivant_lien" href="'.$next.'" title="Allez au mois suivant"><img id="cal_suivant_img" src="client/bazar/images/cal_suivant.png" alt=">>"/></a>'."\n";$retour .= '</span>'."\n";$retour .= '<h1 id="cal_titre"><img id="cal_titre_img" src="client/bazar/images/cal_titre.png" alt="Calendrier"/></h1>'."\n";$retour .= '</div>'."\n";$retour .= '<form action="'.$tc_lien.'" method="get">'."\n";$retour .= '<a href="'.$tc_lien.'">'.$tc_txt.'</a>'."\n";$retour .= '<fieldset>'."\n";$retour .= '<legend>'.'Filtrer : '.'</legend>'."\n";$retour .= '<select id="ficnat" name="ficnat" class="filtre_'.((!is_null($ficnat_id)) ? $ficnat_id: 'tous').'" onchange="javascript:this.form.submit();">'."\n";$retour .= '<option id="filtre_tous" value="*" ';if (isset($_GET['ficnat']) && '*' == $_GET['ficnat']) {$retour .= 'selected="selected" ';}$retour .= '>'.'Tout afficher'.'</option>';while ($ligne_nature_fiche = $resultat_nature_fiche->fetchRow(DB_FETCHMODE_OBJECT)) {$opt = '<option class="filtre_'.$ligne_nature_fiche->bn_id_nature.'" value="'.$ligne_nature_fiche->bn_id_nature.'" ';if (isset($_GET['ficnat']) && $ligne_nature_fiche->bn_id_nature == $_GET['ficnat']) {$opt .= 'selected="selected" ';}$opt .= '>';$retour .= $opt.$ligne_nature_fiche->bn_label_nature.'</option>'."\n";}$retour .= '</select>'."\n";$retour .= '<input id="ficnat_ok" type="submit" value="'.'OK'.'" onload="javascript:this.setAttribute(\'style\', \'display:none;\')"/>'."\n";$script_ok = 'if (document.getElementById(\'ficnat_ok\')) {'.' document.getElementById(\'ficnat_ok\').style.display = \'none\';'.'}';$retour.= '<script type="text/javascript">//<![CDATA['."\n".$script_ok.'//]]></script>'."\n";foreach ($ficnat_chps_cache as $cle => $val) {$retour .= '<input id="'.$cle.'" name="'.$cle.'" type="hidden" value="'.$val.'" />'."\n";}$retour .= '</fieldset>'."\n";$retour .= '</form>'."\n";} else {// Appel du templateob_start();include $options['template'];$retour .= ob_get_contents();ob_end_clean();}// Vue Mois calendrier ou vue appletteif ((!isset($_GET['id_fiche']) && $type == 'calendrier') || ($type == 'calendrier_applette')){// trigger_error('ICI', E_USER_NOTICE);// Recherche evenement de la periode selectionnée$ts_jour_fin_mois = $month->nextMonth('timestamp');$ts_jour_debut_mois = $month->thisMonth('timestamp');;$requete_evenements = "SELECT DISTINCT bf_id_fiche, bf_titre, bf_lieu_evenement, "." DAY(bf_date_debut_evenement) AS bf_jour_debut_evenement, bf_date_debut_evenement, "." bf_date_fin_evenement, bf_description, bn_id_nature "."FROM bazar_fiche, bazar_nature "."WHERE bf_date_debut_evenement < '".date('Y-m-d', $ts_jour_fin_mois)."' "."AND bf_date_fin_evenement >= '".date('Y-m-d', $ts_jour_debut_mois)."' "."AND bf_ce_nature = bn_id_nature "."AND bn_id_nature IN (".$cal_num_annonce.") "."AND bf_statut_fiche = 1 "."ORDER BY bf_jour_debut_evenement";$resultat_evenement = $db->query($requete_evenements);(DB::isError($resultat_evenement)) ? trigger_error(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_evenement->getMessage(), $requete_evenements), E_USER_WARNING) : '';$selection = array();$evenements = array();$annee = date('Y', $curStamp);$mois = date('m', $curStamp);$tablo_jours = array();while ($ligne_evenements = $resultat_evenement->fetchRow(DB_FETCHMODE_OBJECT)) {list($annee_debut, $mois_debut, $jour_debut) = explode('-', $ligne_evenements->bf_date_debut_evenement);list($annee_fin, $mois_fin, $jour_fin) = explode('-', $ligne_evenements->bf_date_fin_evenement);$Calendrier = new Calendar($annee_debut, $mois_debut, $jour_debut);$ts_jour_suivant = $Calendrier->thisDay('timestamp');$ts_jour_fin = mktime(0,0,0,$mois_fin, $jour_fin, $annee_fin);$naviguer = true;while ($naviguer && ($ts_jour_suivant <= $ts_jour_fin)) {// Si le jours suivant est inferieur a la date de fin du mois courrant, on continue...if ($ts_jour_suivant < $ts_jour_fin_mois) {$cle_j = date('Y-m-d', $ts_jour_suivant);if (!isset($tablo_jours[$cle_j])) {$tablo_jours[$cle_j]['Calendar_Day'] = new Calendar_Day(date('Y', $ts_jour_suivant),date('m', $ts_jour_suivant), date('d', $ts_jour_suivant));$tablo_jours[$cle_j]['Diary_Event'] = new DiaryEvent($tablo_jours[$cle_j]['Calendar_Day']);}$tablo_jours[$cle_j]['Diary_Event']->setEntry($ligne_evenements);$ts_jour_suivant = $Calendrier->nextDay('timestamp');//echo "ici$ts_jour_suivant-";$Calendrier->setTimestamp($ts_jour_suivant);//echo "la".$Calendrier->thisDay('timestamp')."-";} else {$naviguer = false;}}}// Add the decorator to the selectionforeach ($tablo_jours as $jour) {$selection[] = $jour['Diary_Event'];}// Affichage Calendrier$month->build($selection);if ($type == 'calendrier') {$retour.= '<table class="calendrier">'.'<colgroup>'.'<col class="cal_lundi"/>'.'<col class="cal_mardi"/>'.'<col class="cal_mercredi"/>'.'<col class="cal_jeudi"/>'.'<col class="cal_vendredi"/>'.'<col class="cal_samedi"/>'.'<col class="cal_dimanche"/>'.'</colgroup>'.'<thead>'."<tr><th> ". BAZ_LUNDI ."</th><th> ". BAZ_MARDI ."</th><th> ". BAZ_MERCREDI ."</th><th> ". BAZ_JEUDI ."</th><th> ". BAZ_VENDREDI ."</th><th> ". BAZ_SAMEDI ."</th><th> ". BAZ_DIMANCHE ."</th></tr>".'</thead>'.'<tbody>';} else {$retour.= '<table class="calendrier_applette">'.'<colgroup>'.'<col class="cal_lundi"/>'.'<col class="cal_mardi"/>'.'<col class="cal_mercredi"/>'.'<col class="cal_jeudi"/>'.'<col class="cal_vendredi"/>'.'<col class="cal_samedi"/>'.'<col class="cal_dimanche"/>'.'</colgroup>'.'<thead>'."<tr><th> ". BAZ_LUNDI_COURT ."</th><th> ". BAZ_MARDI_COURT ."</th><th> ". BAZ_MERCREDI_COURT ."</th><th> ". BAZ_JEUDI_COURT ."</th><th> ". BAZ_VENDREDI_COURT ."</th><th> ". BAZ_SAMEDI_COURT ."</th><th> ". BAZ_DIMANCHE_COURT ."</th></tr>".'</thead>'.'<tbody>';}$todayStamp=time();$today_ymd=date('Ymd',$todayStamp);// Other month : moiswhile ($day = $month->fetch() ) {$dayStamp = $day->thisDay(true);$day_ymd = date('Ymd',$dayStamp);if ( $day->isEmpty() ) {$class = "cal_ma other_month";} else {if (($day_ymd < $today_ymd)) {$class= "cal_mp previous_month";} else {if ($day_ymd == $today_ymd) {$class= "cal_jc current_day";} else {$class="cal_mc current_month";}}}$url->addQueryString ('y', date('Y',$dayStamp));$url->addQueryString ('m', date('n',$dayStamp));$url->addQueryString ('d', date('j',$dayStamp));$link = $url->getUrl();// isFirst() to find start of weekif ($day->isFirst()) {$retour.= ( "<tr>\n" );}if ($type == 'calendrier') {$retour.= "<td class=\"".$class."\">".'<span class="cal_j">'.$day->thisDay().'</span>'."\n";if ($day->isSelected() ) {$evenements = $day->getEntry();$evenements_nbre = count($evenements);$evenemt_xhtml = '';while ($ligne_evenement = array_pop($evenements)) {$id_fiches = array();$id_fiches[] = $ligne_evenement->bf_id_fiche;$url->addQueryString ('id_fiches',$id_fiches);$link = $url->getUrl();if (!isset($_GET['tt']) || (isset($_GET['tt']) && $_GET['tt'] == '1')) {$titre_taille = strlen($ligne_evenement->bf_titre);$titre = ($titre_taille > 20)?substr($ligne_evenement->bf_titre, 0, 20).'...':$ligne_evenement->bf_titre;} else {$titre = $ligne_evenement->bf_titre;}$evenemt_xhtml .= '<li class="tooltip nature_'.$ligne_evenement->bn_id_nature.'" title="'.str_replace('"', '\'', $ligne_evenement->bf_titre).'"><a class="cal_evenemt" href="'.$link.'">'.$titre.'</a></li>'."\n";$url->removeQueryString ('id_fiches');}if ($evenements_nbre > 0) {$retour .= '<ul class="cal_evenemt_liste">';$retour .= $evenemt_xhtml;$retour .= '</ul>';}}} else {$lien_date= "<td class=\"".$class."\">".$day->thisDay();if ($day->isSelected() ) {$evenements = $day->getEntry();$id_fiches = array();$info_fiches = null;while ($ligne_evenement = array_pop($evenements)) {$id_fiches[] = $ligne_evenement->bf_id_fiche;$info_fiches .= '⇒ '.str_replace('"', '\'', $ligne_evenement->bf_titre)."\n";}$url->addQueryString('id_fiches', $id_fiches);$link = $url->getUrl();$lien_date = '<td class="'.$class.'"><a href="'.$link.'" class="tooltip" title="'.$info_fiches.'">'.$day->thisDay()."</a>\n";$url->removeQueryString('id_fiches');}$retour .= $lien_date;}$retour.= ( "</td>\n" );// isLast() to find end of weekif ( $day->isLast() ) {$retour.= ( "</tr>\n" );}}$retour.= "</tbody></table>";}$retour.= '<script type="text/javascript">//<![CDATA['."\n".$script.'//]]></script>'."\n";// Vue detailif ((isset($_GET['id_fiches']))) {// Ajout d'un titre pour la page avec la date$jours = array ('dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi') ;$mois = array ('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre','octobre', 'novembre', 'décembre') ;$timestamp = strtotime ($_GET['y'].'/'.$_GET['m'].'/'.$_GET['d']) ;$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_NAVIGATION'] = '';$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_TETE'] = '';$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_CORPS'] = '<h1>'.$jours[date('w', $timestamp)].' '.$_GET['d'].' '.$mois[$_GET['m']-1].' '.$_GET['y'].'</h1>' ;$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_CORPS'] .= baz_voir_fiches(0,$_GET['id_fiches'] );$GLOBALS['_GEN_commun']['info_menu'] = '';// Un lien pour retourner au calendrier$url->removeQueryString('id_fiches');$url->removeQueryString('y');$url->removeQueryString('m');$url->removeQueryString('d');$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_PIED'] = '<div class="retour"><a href="'.$url->getURL().'">Retour au calendrier</a></div>';}// Nettoyage de l'url$url->removeQueryString('id_fiches');$url->removeQueryString('y');$url->removeQueryString('m');$url->removeQueryString('d');return $retour;}?>