Subversion Repositories Applications.bazar

Rev

Rev 33 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ddelon 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: bazar.fonct.cal.php,v 1.1 2005-10-12 17:20:33 ddelon Exp $
23
/**
24
*
25
* Fonctions calendrier du module bazar
26
*
27
*@package bazar
28
//Auteur original :
29
*@author        David Delon <david.delon@clapas.net>
30
//Autres auteurs :
31
*@copyright     Tela-Botanica 2000-2004
32
*@version       $Revision: 1.1 $ $Date: 2005-10-12 17:20:33 $
33
// +------------------------------------------------------------------------------------------------------+
34
*/
35
 
36
// +------------------------------------------------------------------------------------------------------+
37
// |                                            ENTETE du PROGRAMME                                       |
38
// +------------------------------------------------------------------------------------------------------+
39
 
40
require_once 'Calendar/Month/Weekdays.php';
41
require_once 'Calendar/Day.php';
42
require_once 'Calendar/Decorator.php';
43
 
44
 
45
// +------------------------------------------------------------------------------------------------------+
46
// |                                           LISTE de FONCTIONS                                         |
47
// +------------------------------------------------------------------------------------------------------+
48
 
49
 
50
// Classe Utilitaire pour Calendrier
51
 
52
class DiaryEvent extends Calendar_Decorator {
53
	var $entry=array();
54
	function DiaryEvent($calendar) {
55
		Calendar_Decorator::Calendar_Decorator($calendar);
56
	}
57
	function setEntry($entry) {
58
		$this->entry[]=$entry;
59
 
60
	}
61
	function getEntry() {
62
		return $this->entry;
63
	}
64
}
65
 
66
 
67
function GestionAffichageCalendrier($prefixe_cal) {
68
 
69
 
70
	$retour='';
71
 
72
	$url = $GLOBALS['_GEN_commun']['url'] ;
73
	$db = &$GLOBALS['_GEN_commun']['pear_db'] ;
74
	$auth = &$GLOBALS['_GEN_commun']['pear_auth'] ;
75
 
76
	if (!isset($_GET['y'])) {
77
		$_GET['y'] = date('Y');
78
	}
79
 
80
	if (!isset($_GET['m'])) {
81
		$_GET['m'] = date('m');
82
	}
83
 
84
 
85
	// 	Construction Mois en Cours
86
	$month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']);
87
 
88
	$curStamp=$month->getTimeStamp();
89
	$url->addQueryString ('y', date('Y',$curStamp));
90
	$url->addQueryString ('m', date('n',$curStamp));
91
	$url->addQueryString ('d', date('j',$curStamp));
92
	$cur = $url->getUrl();
93
 
94
	// Navigation
95
	$prevStamp = $month->prevMonth(true);
96
	$url->addQueryString ('y', date('Y',$prevStamp));
97
	$url->addQueryString ('m', date('n',$prevStamp));
98
	$url->addQueryString ('d', date('j',$prevStamp));
99
	$prev = $url->getUrl();
100
	$nextStamp = $month->nextMonth(true);
101
	$url->addQueryString ('y', date('Y',$nextStamp));
102
	$url->addQueryString ('m', date('n',$nextStamp));
103
	$url->addQueryString ('d', date('j',$nextStamp));
104
	$next = $url->getUrl();
105
 
106
	$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);
107
 
108
	$retour.= "<div class=\"navi\">";
109
	$retour.= "<a href=\"".$prev."\"> &lt;&lt; </a>";
110
 
111
	$retour.= "&nbsp;&nbsp;";
112
	$retour.= "<a href=\"".$cur;
113
	$retour.= "\"> ";
114
	$retour.= $fr_month[(date('n',$curStamp))];
115
	$retour.= "&nbsp;";
116
	$retour.= (date('Y',$curStamp));
117
	$retour.= "</a>";
118
	$retour.= "&nbsp;&nbsp;";
119
	$retour.= "<a href=\"".$next."\"> &gt;&gt; </a>";
120
 
121
	$retour.= "</div>";
122
 
123
	$retour.="<br></br>";
124
 
125
		// Vue Mois
126
	if (!isset($_GET['id_fiche'])) {
127
 
128
		// Recherche evenement de la periode selectionnée
129
 
130
	 	// TODO : Selectionner element du mois en cours
131
 
132
	    $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_label_nature='Évènements'";
133
 
134
 
135
	   	$resultat_evenement = $db->query($requete_evenements);
136
 
137
	    (DB::isError($resultat_evenement))
138
	    ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_evenement->getMessage(), $requete_evenements))
139
	    : '';
140
 
141
		$calcom="";
142
 
143
		$selection=array();
144
		$evenements=array();
145
 
146
		$prev_curday_ymd=0;
147
 
148
	    while ($ligne_evenements = $resultat_evenement->fetchRow(DB_FETCHMODE_OBJECT)) {
149
 
150
			$curday_ymd=date('Ym',$curStamp).$ligne_evenements->bf_jour_debut_evenement;
151
			if ($curday_ymd!=$prev_curday_ymd) {
152
				$Day = new Calendar_Day(date('Y',$curStamp),date('m',$curStamp), $ligne_evenements->bf_jour_debut_evenement);
153
				$DiaryEvent = new DiaryEvent($Day);
154
				$prev_curday_ymd=$curday_ymd;
155
			}
156
 
157
			$DiaryEvent->setEntry($ligne_evenements);
158
 
159
			// Add the decorator to the selection
160
			$selection[] = $DiaryEvent;
161
 
162
		}
163
 
164
		// Affichage Calendrier
165
 
166
 
167
		$month->build($selection);
168
 
169
		$retour.= "<table class=\"calendar\">
170
		 <tr>
171
 
172
		  <th> ". BAZ_LUNDI ."</th>
173
		  <th> ". BAZ_MARDI ."</th>
174
		  <th> ". BAZ_MERCREDI ."</th>
175
		  <th> ". BAZ_JEUDI ."</th>
176
		  <th> ". BAZ_VENDREDI ."</th>
177
		  <th> ". BAZ_SAMEDI ."</th>
178
		  <th> ". BAZ_DIMANCHE ."</th>
179
		 </tr>
180
		 ";
181
 
182
		$todayStamp=time();
183
 
184
		$today_ymd=date('Ymd',$todayStamp);
185
 
186
		// Other month : mois
187
		//
188
 
189
		while ($day = $month->fetch() ) {
190
 
191
				$dayStamp = $day->thisDay(true);
192
				$day_ymd=date('Ymd',$dayStamp);
193
 
194
				if ( $day->isEmpty() ) {
195
						$class = "other_month";
196
				}
197
				else {
198
					if (($day_ymd < $today_ymd)) {
199
						$class= "previous_month";
200
					}
201
					else {
202
						 if ($day_ymd == $today_ymd) {
203
						 	$class= "current_day";
204
						 }
205
						 else {
206
							$class="current_month";
207
						 }
208
					}
209
				}
210
 
211
				$url->addQueryString ('y', date('Y',$dayStamp));
212
				$url->addQueryString ('m', date('n',$dayStamp));
213
				$url->addQueryString ('d', date('j',$dayStamp));
214
 
215
				$link = $url->getUrl();
216
 
217
				// isFirst() to find start of week
218
				if ($day->isFirst())
219
					$retour.= ( "<tr>\n" );
220
 
221
				$retour.= ( "<td class=\"".$class."\"><a href=\"".$link."\">".$day->thisDay()."</a>\n" );
222
 
223
				if ($day->isSelected() ) {
224
					$evenements=$day->getEntry();
225
					while ($ligne_evenement=array_pop($evenements)) {
226
						$url->addQueryString ('id_fiche',$ligne_evenement->bf_id_fiche);
227
						$link = $url->getUrl();
228
						$retour.= ( "<a href=\"".$link."\">".$ligne_evenement->bf_titre."</a>\n" );
229
					}
230
 
231
				}
232
 
233
				$retour.= ( "</td>\n" );
234
 
235
				// isLast() to find end of week
236
				if ( $day->isLast() )
237
					$retour.= ( "</tr>\n" );
238
			}
239
 
240
			$retour.= "</table>";
241
 
242
			return $retour;
243
 
244
		}
245
		else {
246
			// Vue jour
247
			if (isset($_GET['id_fiche'])) {
248
				return 	$retour.baz_voir_fiche(0, $_GET['id_fiche']);
249
			}
250
		}
251
 
252
		;
253
	}
254
 
255
?>