Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcalendar/user/monthview.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: monthview.php 7697 2001-10-08 14:39:10Z jhe $
5 //
6 // Created on: <27-Dec-2000 14:09:56 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License2
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlog.php" );
30 // include_once( "classes/ezlocale.php" );
31 // include_once( "classes/ezdatetime.php" );
32 // include_once( "classes/ezdate.php" );
33
34 // include_once( "ezcalendar/classes/ezappointment.php" );
35 // include_once( "eztodo/classes/eztodo.php" );
36
37 $ini =& eZINI::instance( 'site.ini' );
38
39 $Language = $ini->variable( "eZCalendarMain", "Language" );
40 $Locale = new eZLocale( $Language );
41
42 $user =& eZUser::currentUser();
43 $session =& eZSession::globalSession();
44 $session->fetch();
45
46 if ( $user == false )
47 $userID = false;
48 else
49 $userID = $user->id();
50
51 if ( isset( $GetByUser ) )
52 {
53 $userID = $GetByUserID;
54 }
55
56 if ( $session->variable( "ShowOtherCalendarUsers" ) == false || isset( $GetByUser ) )
57 $session->setVariable( "ShowOtherCalendarUsers", $userID );
58 else
59 $userID = $session->variable( "ShowOtherCalendarUsers" );
60
61 $appOwnerUser = new eZUser( $userID );
62
63 $date = new eZDate();
64
65 if ( $Year != "" && $Month != "" )
66 {
67 $date->setYear( $Year );
68 $date->setMonth( $Month );
69 }
70 else
71 {
72 $Year = $date->year();
73 $Month = $date->month();
74 }
75
76 $session->setVariable( "Year", $Year );
77 $session->setVariable( "Month", $Month );
78
79 $zMonth = addZero( $Month );
80 $isMyCalendar = ( $user && $user->id() == $userID ) ? "-private" : "";
81 $t = new eZTemplate( "kernel/ezcalendar/user/" . $ini->variable( "eZCalendarMain", "TemplateDir" ),
82 "kernel/ezcalendar/user/intl", $Language, "monthview.php",
83 "default", "ezcalendar" . "/user", "$Year-$zMonth-$userID" . $isMyCalendar );
84
85 $t->set_file( "month_view_page_tpl", "monthview.tpl" );
86
87 if ( $t->hasCache() )
88 {
89 print( $t->cache() );
90 }
91 else
92 {
93 $t->setAllStrings();
94
95 $t->set_block( "month_view_page_tpl", "user_item_tpl", "user_item" );
96 $t->set_block( "month_view_page_tpl", "month_tpl", "month" );
97 $t->set_block( "month_tpl", "week_tpl", "week" );
98 $t->set_block( "month_tpl", "week_day_tpl", "week_day" );
99 $t->set_block( "week_tpl", "day_tpl", "day" );
100 $t->set_block( "day_tpl", "public_appointment_tpl", "public_appointment" );
101 $t->set_block( "day_tpl", "private_appointment_tpl", "private_appointment" );
102 $t->set_block( "day_tpl", "public_todo_tpl", "public_todo" );
103
104 $t->set_var( "month_name", $Locale->monthName( $date->monthName(), false ) );
105 $t->set_var( "month_number", $Month );
106 $t->set_var( "current_year_number", $Year );
107 $t->set_var( "week", "" );
108
109 // Draw the week day header.
110 $headerDate = new eZDate();
111 $headerDate->setYear( 2001 );
112 if ( $Locale->mondayFirst() )
113 {
114 // January 2001 starts on a Monday
115 $headerDate->setMonth( 1 );
116 }
117 else
118 {
119 // April 2001 starts on a Sunday
120 $headerDate->setMonth( 4 );
121 }
122
123 for ( $week_day = 1; $week_day <= 7; $week_day++ )
124 {
125 $headerDate->setDay( $week_day );
126 $t->set_var( "week_day_name", $Locale->dayName( $headerDate->dayName( $Locale->mondayFirst() ), false ) );
127
128 $t->parse( "week_day", "week_day_tpl", true );
129 }
130
131 $today = new eZDate();
132 $tmpDate = new eZDate();
133 $tmpAppointment = new eZAppointment();
134 $firstDay = false;
135
136 for ( $week = 0; $week < 6; $week++ )
137 {
138 $t->set_var( "day", "" );
139
140 if ( ( ( $week * 7 ) - $firstDay + 1 ) < ( $date->daysInMonth() ) )
141 {
142 $date->setDay( 1 );
143 $firstDay = $date->dayOfWeek( $Locale->mondayFirst() );
144
145 for ( $day = 1; $day <= 7; $day++ )
146 {
147 $currentDay = $day + ( $week * 7 ) - $firstDay + 1;
148
149 // this month
150 if ( ( ( $day + ( $week * 7 ) ) >= $firstDay ) &&
151 ( $currentDay <= $date->daysInMonth() ) )
152 {
153 $date->setDay( $currentDay );
154
155 // fetch the appointments for today
156 $tmpDate->setYear( $date->year() );
157 $tmpDate->setMonth( $date->month() );
158 $tmpDate->setDay( $date->day() );
159 $appointments =& $tmpAppointment->getByDate( $tmpDate, $appOwnerUser, true );
160
161 $t->set_var( "public_appointment", "" );
162 $t->set_var( "private_appointment", "" );
163 $t->set_var( "public_todo", "" );
164
165 foreach ( $appointments as $appointment )
166 {
167 $t->set_var( "appointment_id", $appointment->id() );
168 if ( $appointment->allDay() )
169 {
170 $t->set_var( "start_time", $ini->variable( "eZCalendarMain", "DayStartTime" ) );
171 $t->set_var( "stop_time", $ini->variable( "eZCalendarMain", "DayStopTime" ) );
172 }
173 else
174 {
175 $t->set_var( "start_time", $Locale->format( $appointment->startTime(), true ) );
176 $t->set_var( "stop_time", $Locale->format( $appointment->stopTime(), true ) );
177 }
178
179 if ( $appointment->isPrivate() == false || $userID == $appointment->userID() )
180 $t->parse( "public_appointment", "public_appointment_tpl", true );
181 else
182 $t->parse( "private_appointment", "private_appointment_tpl", true );
183 }
184
185 // fetch todos for today
186 if ( !$userID )
187 $todos = array();
188 else
189 $todos =& eZTodo::getByDate( $userID, $tmpDate );
190
191 foreach ( $todos as $todo )
192 {
193 $t->set_var( "todo_id", $todo->id() );
194 $t->set_var( "todo_desc", $todo->name() );
195 $t->parse( "public_todo", "public_todo_tpl", true );
196 }
197
198 // set special colours for today and weekend
199 if ( $tmpDate->equals( $today ) )
200 {
201 $t->set_var( "td_class", "bgcurrent" );
202 }
203 else if ( $day == 7 )
204 {
205 $t->set_var( "td_class", "bgweekend" );
206 }
207 else if ( $day == 6 )
208 {
209 if ( $Locale->mondayFirst() == true )
210 $t->set_var( "td_class", "bgweekend" );
211 else
212 $t->set_var( "td_class", "bglight" );
213 }
214 else if ( $day == 1 )
215 {
216 if ( $Locale->mondayFirst() == false )
217 $t->set_var( "td_class", "bgweekend" );
218 else
219 $t->set_var( "td_class", "bglight" );
220 }
221 else
222 {
223 $t->set_var( "td_class", "bglight" );
224 }
225
226 $t->set_var( "day_number", $currentDay );
227 $t->set_var( "month_number", $Month );
228 $t->set_var( "year_number", $Year );
229 }
230 else // previous or next month
231 {
232 $prevNextDate = new eZDate( $date->year(), $date->month(), $date->day() );
233
234 // prevous month
235 if ( ( $currentDay <= $date->daysInMonth() ) )
236 {
237 $t->set_var( "public_appointment", "" );
238 $t->set_var( "private_appointment", "" );
239
240 if ( $date->month() == 1 )
241 {
242 $prevNextDate->setYear( $date->year() - 1 );
243 $prevNextDate->setMonth( 12 );
244 }
245 else
246 {
247 $prevNextDate->setMonth( $date->month() - 1 );
248 }
249
250 $prevNextDate->setDay( $prevNextDate->daysInMonth() - $firstDay + $day + 1 );
251 $t->set_var( "day_number", $prevNextDate->day() );
252 $t->set_var( "month_number", $prevNextDate->month() );
253 $t->set_var( "year_number", $prevNextDate->year() );
254 $t->set_var( "prev_month_number", $prevNextDate->month() );
255 $t->set_var( "prev_year_number", $prevNextDate->year() );
256
257 $t->set_var( "appointment", "" );
258 }
259 else
260 {
261 // next month
262 $t->set_var( "public_appointment", "" );
263 $t->set_var( "private_appointment", "" );
264
265 if ( $date->month() == 12 )
266 {
267 $prevNextDate->setYear( $date->year() + 1 );
268 $prevNextDate->setMonth( 1 );
269 }
270 else
271 {
272 $prevNextDate->setMonth( $date->month() + 1 );
273 }
274
275 $tmp = ( $firstDay + $date->daysInMonth() ) % 7;
276 if ( $tmp == 0 )
277 $tmp = 7;
278
279 $prevNextDate->setDay( ( 7 - $tmp - 6 ) + $day );
280 $t->set_var( "day_number", $prevNextDate->day() );
281 $t->set_var( "month_number", $prevNextDate->month() );
282 $t->set_var( "year_number", $prevNextDate->year() );
283 $t->set_var( "next_month_number", $prevNextDate->month() );
284 $t->set_var( "next_year_number", $prevNextDate->year() );
285
286 $t->set_var( "appointment", "" );
287 }
288 $t->set_var( "td_class", "bgdark" );
289 if ( $prevNextDate->equals( $today ) )
290 $t->set_var( "td_class", "bgcurrent" );
291 }
292 $t->parse( "day", "day_tpl", true );
293 }
294 }
295 $t->parse( "week", "week_tpl", true );
296 }
297 $t->parse( "month", "month_tpl", true );
298
299 // User list
300 if ( $ini->variable( "eZCalendarMain", "OnlyShowTrustees" ) == "enabled" )
301 {
302 $user_array = array_merge( array( $appOwnerUser ), $appOwnerUser->getByTrustee( -1, true ) );
303 }
304 else
305 {
306 $user_array =& eZUser::getAll();
307 }
308 foreach ( $user_array as $userItem )
309 {
310 $t->set_var( "user_id", $userItem->id() );
311 $t->set_var( "user_firstname", $userItem->firstName() );
312 $t->set_var( "user_lastname", $userItem->lastName() );
313
314 if ( $appOwnerUser->id() == $userItem->id() )
315 {
316 $t->set_var( "user_is_selected", "selected" );
317 }
318 else
319 {
320 $t->set_var( "user_is_selected", "" );
321 }
322
323 $t->parse( "user_item", "user_item_tpl", true );
324 }
325
326
327 // next previous values.
328 $t->set_var( "next_year_number", $Year );
329 $t->set_var( "prev_year_number", $Year );
330
331 if ( $Month == 12 )
332 {
333 $t->set_var( "next_month_number", 1 );
334 $t->set_var( "next_year_number", $Year + 1 );
335 }
336 else
337 {
338 $t->set_var( "next_month_number", $Month + 1 );
339 }
340
341 if ( $Month == 1 )
342 {
343 $t->set_var( "prev_month_number", 12 );
344 $t->set_var( "prev_year_number", $Year - 1 );
345 }
346 else
347 {
348 $t->set_var( "prev_month_number", $Month - 1 );
349 }
350
351
352 $t->storeCache( "output", "month_view_page_tpl", true );
353 }
354
355
356 //Adds a "0" in front of the value if it's below 10.
357 function addZero( $value )
358 {
359 settype( $value, "integer" );
360 $ret = $value;
361 if ( $ret < 10 )
362 {
363 $ret = "0". $ret;
364 }
365 return $ret;
366 }
367
368 ?>
$day
else $day
Definition: appointmentedit.php:665
$appointment
$appointment
Definition: appointmentview.php:89
$tmp
$tmp
Definition: bugview.php:99
eZAppointment
Definition: ezappointment.php:43
eZDate
Definition: ezdate.php:46
eZLocale
Definition: ezlocale.php:119
eZSession\globalSession
static & globalSession( $id="", $fetch=true)
Definition: kernel/ezsession/classes/ezsession.php:614
eZTemplate
Definition: eztemplate.php:107
eZTodo\getByDate
static & getByDate( $user, $date)
Definition: eztodo.php:289
eZUser
Definition: ezuser.php:76
eZUser\getAll
static & getAll( $order="Login", $as_object=true, $search=false, $max=-1, $index=0)
Definition: ezuser.php:330
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$user_array
while( $tmpTime->isGreater( $stopTime)) $user_array
Definition: ezcalendar/user/dayview.php:495
$appointments
$appointments
Definition: ezcalendar/user/dayview.php:136
$isMyCalendar
$isMyCalendar
Definition: ezcalendar/user/monthview.php:80
$tmpDate
$tmpDate
Definition: ezcalendar/user/monthview.php:132
$tmpAppointment
$tmpAppointment
Definition: ezcalendar/user/monthview.php:133
$t
$t
Definition: ezcalendar/user/monthview.php:81
$headerDate
$headerDate
Definition: ezcalendar/user/monthview.php:110
$date
$date
Definition: ezcalendar/user/monthview.php:63
$zMonth
$zMonth
Definition: ezcalendar/user/monthview.php:79
$user
$user
Definition: ezcalendar/user/monthview.php:42
$Month
$Month
Definition: ezcalendar/user/monthview.php:73
$Locale
$Locale
Definition: ezcalendar/user/monthview.php:40
$Language
$Language
Definition: ezcalendar/user/monthview.php:39
$ini
$ini
Definition: ezcalendar/user/monthview.php:37
addZero
addZero( $value)
Definition: ezcalendar/user/monthview.php:357
$userID
else $userID
Definition: ezcalendar/user/monthview.php:49
$today
for( $week_day=1; $week_day<=7; $week_day++) $today
Definition: ezcalendar/user/monthview.php:131
$firstDay
$firstDay
Definition: ezcalendar/user/monthview.php:134
$session
$session
Definition: ezcalendar/user/monthview.php:43
$appOwnerUser
$appOwnerUser
Definition: ezcalendar/user/monthview.php:61
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$todo
$todo
Definition: todolist.php:125
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.