Subversion Repositories Applications.bazar

Rev

Rev 234 | Blame | 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.17.2.1 2007-05-09 13:56:49 alexandre_tb Exp $
/**
*
* Fonctions calendrier du module bazar
*
*@package bazar
//Auteur original :
*@author        David Delon <david.delon@clapas.net>
//Autres auteurs :
*@copyright     Tela-Botanica 2000-2004
*@version       $Revision: 1.17.2.1 $ $Date: 2007-05-09 13:56:49 $
// +------------------------------------------------------------------------------------------------------+
*/

// +------------------------------------------------------------------------------------------------------+
// |                                            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 Calendrier
class 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_appplette
function GestionAffichageCalendrier($type = 'calendrier') {
        
        $retour = '';

        $url = $GLOBALS['_GEN_commun']['url'] ;
        $db =& $GLOBALS['_GEN_commun']['pear_db'] ;
        $auth =& $GLOBALS['_GEN_commun']['pear_auth'] ;
        
        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();
        
        // 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();
        
        $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);

        $retour.= "<div class=\"navi\">";
        $retour.= "<a href=\"".$prev."\"> &lt;&lt; </a>"; 

        $retour.= "&nbsp;&nbsp;";
        $retour.= "<a href=\"".$cur;
        $retour.= "\"> ";
        $retour.= $fr_month[(date('n',$curStamp))]; 
        $retour.= "&nbsp;";
        $retour.= (date('Y',$curStamp));
        $retour.= "</a>";
        $retour.= "&nbsp;&nbsp;";
        $retour.= "<a href=\"".$next."\"> &gt;&gt; </a>";

        $retour.= "</div>";

        $retour.="<br></br>";

        // Vue Mois calendrier ou vue applette
                
        if ((!isset($_GET['id_fiche']) && ($type=='calendrier')) || ($type=='calendrier_applette')){
                        
                // Recherche evenement de la periode selectionnée 
                
                // TODO : Selectionner element du mois en cours 
                
            $requete_evenements =       "SELECT DISTINCT bf_id_fiche, bf_titre, bf_lieu_evenement, DAY(bf_date_debut_evenement) AS bf_jour_debut_evenement , bf_date_fin_evenement, bf_description ".
                                                                "FROM bazar_fiche, bazar_nature ".
                                                                "WHERE YEAR(bf_date_debut_evenement) = ".date('Y',$curStamp)." ".
                                                                "AND month(bf_date_debut_evenement) = ".date('m',$curStamp)." ".
                                                                "AND bf_ce_nature = bn_id_nature ".
                                                                "AND bn_id_nature IN (".BAZ_NUM_ANNONCE_CALENDRIER.") ".
                                                                "AND bf_statut_fiche = 1 ".
                                                                "ORDER BY bf_jour_debut_evenement";
                
                $resultat_evenement = $db->query($requete_evenements);
                
            (DB::isError($resultat_evenement))
            ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_evenement->getMessage(), $requete_evenements))
            : '';
        
                $calcom="";
                
                $selection=array();
                $evenements=array();
                 
                $prev_curday_ymd=0;
                
            while ($ligne_evenements = $resultat_evenement->fetchRow(DB_FETCHMODE_OBJECT)) {
                
                        $curday_ymd=date('Ym',$curStamp).$ligne_evenements->bf_jour_debut_evenement;
                        if ($curday_ymd!=$prev_curday_ymd) {
                                $Day = new Calendar_Day(date('Y',$curStamp),date('m',$curStamp), $ligne_evenements->bf_jour_debut_evenement);
                                $DiaryEvent = new DiaryEvent($Day);
                                $prev_curday_ymd=$curday_ymd;
                        }
                        
                        $DiaryEvent->setEntry($ligne_evenements);
                        
                        // Add the decorator to the selection
                        $selection[] = $DiaryEvent;
                                
                }
                        
                // Affichage Calendrier
                
                
                $month->build($selection);
        
                if ($type=='calendrier') {
                        $retour.= "<table class=\"calendar\">
                         <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>
                         ";
                }
                else {
                        $retour.= "<table class=\"calendar\">
                         <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>
                         ";
                }
                
                        
                $todayStamp=time();
                
                $today_ymd=date('Ymd',$todayStamp);
        
                // Other month : mois 
                //
                
                while ($day = $month->fetch() ) {
                                
                                $dayStamp = $day->thisDay(true);
                                $day_ymd=date('Ymd',$dayStamp);
                                
                                if ( $day->isEmpty() ) {
                                                $class = "other_month";
                                }
                                else {
                                        if (($day_ymd < $today_ymd)) {
                                                $class= "previous_month";
                                        }
                                        else {
                                                 if ($day_ymd == $today_ymd) {
                                                        $class= "current_day";
                                                 }
                                                 else {
                                                        $class="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 week
                                if ($day->isFirst())
                                        $retour.= ( "<tr>\n" );
                                
                                //$retour.= ( "<td class=\"".$class."\"><a href=\"".$link."\">".$day->thisDay()."</a>\n" );
                                
                                if ($type=='calendrier') {
                                        $retour.= "<td class=\"".$class."\">".$day->thisDay()."\n";
                                        if ($day->isSelected() ) {
                                                $evenements=$day->getEntry();
                                                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();
                                                        $retour.= "<a href=\"".$link."\">".$ligne_evenement->bf_titre."</a>\n";
                                                        $url->removeQueryString ('id_fiches');
                                                }
                                        }
                                }
                                else {
                                        $lien_date= "<td class=\"".$class."\">".$day->thisDay()."\n";
                                        if ($day->isSelected() ) {
                                                $evenements=$day->getEntry();
                                                $id_fiches=array();
                                                while ($ligne_evenement=array_pop($evenements)) {
                                                        $id_fiches[]=$ligne_evenement->bf_id_fiche;
                                                }
                                                $url->addQueryString ('id_fiches',$id_fiches);
                                                $link = $url->getUrl();
                                                $lien_date= "<td class=\"".$class."\"><a href=\"".$link."\">".$day->thisDay()."</a>\n";
                                                $url->removeQueryString ('id_fiches');
                                        }
                                        $retour.=$lien_date;
                                }
                                
                                $retour.= ( "</td>\n" );
                                
                                // isLast() to find end of week
                                if ( $day->isLast() )
                                        $retour.= ( "</tr>\n" );
                        }
                
                        $retour.= "</table>";
                        
                        
                }
                
                // Vue detail
                
                if ((isset($_GET['id_fiches']))) {
                                // Ajout des styles du bazar
                                if (defined('PAP_VERSION')) { //si on est dans Papyrus
                                        GEN_stockerStyleExterne( 'bazar_interne2', 'client/bazar/bazar.interne.css');
                                }
                        
                                // 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_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'] );
                }

                // Nettoyage de l'url
                $url->removeQueryString('id_fiches');
                $url->removeQueryString('y');
                $url->removeQueryString('m');
                $url->removeQueryString('d');
                        
                return $retour;
        }
?>