Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

weekview.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: weekview.php
5 //
6 //
7 // This source file is part of Exponential Basic, publishing software.
8 // Copyright (C) 1999-2001 eZ systems as
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License
12 // as published by the Free Software Foundation; either version 2
13 // of the License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
23 //
24
25 // include_once( "classes/INIFile.php" );
26 // include_once( "classes/eztemplate.php" );
27 // include_once( "classes/ezlog.php" );
28 // include_once( "classes/ezlocale.php" );
29
30 // include_once( "classes/ezdatetime.php" );
31 // include_once( "classes/ezdate.php" );
32
33 // include_once( "ezuser/classes/ezusergroup.php" );
34 // include_once( "ezuser/classes/ezpermission.php" );
35
36 // include_once( "ezgroupeventcalendar/classes/ezgroupevent.php" );
37 // include_once( "ezgroupeventcalendar/classes/ezgroupeventtype.php" );
38 // include_once( "ezgroupeventcalendar/classes/ezgroupnoshow.php" );
39 // include_once( "ezgroupeventcalendar/classes/ezgroupeditor.php" );
40
41 function shortenText($text, $chars=25) {
42 //$text = $text."||";
43 // print(strlen($text));
44 $text = substr($text,0,$chars);
45 //$text = substr($text,0,strrpos($text,'||'));
46 // die($text);
47 $text .= "...";
48
49 return $text;
50 }
51
52 $ini = &eZINI::instance( 'site.ini' );
53
54 $SiteDesign = $ini->variable( "site", "SiteDesign" );
55 $Language = $ini->variable( "eZGroupEventCalendarMain", "Language" );
56 $Sitedesign = $ini->variable( "site", "SiteDesign" );
57 $TruncateTitle = $ini->variable( "eZGroupEventCalendarMain", "TruncateTitle" );
58
59 $TemplateDir = $ini->variable( "eZGroupEventCalendarMain", "TemplateDir" );
60 $GlobalSectionID = $ini->variable( "eZGroupEventCalendarMain", "DefaultSection" );
61
62 $Locale = new eZLocale( $Language );
63
64 $user = eZUser::currentUser();
65 $session =& eZSession::globalSession();
66 $session->fetch();
67
68 $URL = explode( "/", $_SERVER['REQUEST_URI'] );
69
70 if( count( $URL ) <= 5 )
71 {
72 if ( is_numeric( $URL[3] ) )
73 $groupID = $URL[3];
74 else
75 $groupID = 0;
76 }
77 else
78 {
79 $readGroup = new eZUserGroup( $session->variable( "ShowOtherCalendarGroups" ) );
80 $groupID = $readGroup->id();
81 }
82
83 if( !isset( $GetByGroupID ) )
84 $GetByGroupID = $groupID;
85 else
86 {
87 $GetByGroupID = 0;
88 }
89
90 if ( $GetByGroupID == false )
91 $GetByGroupID = $groupID;
92
93
94 if ( ( $session->variable( "ShowOtherCalendarGroups" ) == false ) || ( isSet( $GetByGroup ) ) )
95 {
96 $session->setVariable( "ShowOtherCalendarGroups", $GetByGroupID );
97 }
98
99 $eventGroup = new eZUserGroup( $session->variable( "ShowOtherCalendarGroups" ) );
100
101 //Get the TYPE session data
102 if ( ( $session->variable( "ShowOtherCalendarTypes" ) == false ) || ( isSet( $GetByTypeID ) ) )
103 {
104 if( !isSet( $GetByTypeID ) )
105 $GetByTypeID = 0;
106
107 $session->setVariable( "ShowOtherCalendarTypes", $GetByTypeID );
108 }
109
110 $type = new eZGroupEventType( $session->variable( "ShowOtherCalendarTypes" ) );
111
112 if( !isSet( $GetByTypeID ) )
113 $GetByTypeID = $type->id();
114
115 $date = new eZDate();
116
117 if ( $Year != "" && $Month != "" && $Day != "" )
118 {
119 $date->setYear( $Year );
120 $date->setMonth( $Month );
121 $date->setDay( $Day );
122 }
123 else
124 {
125 $Year = $date->year();
126 $Month = $date->month();
127 $Day = $date->day();
128 }
129
130 $Week = date("W",$date->timestamp());
131
132 $session->setVariable( "Year", $Year );
133 $session->setVariable( "Month", $Month );
134 $session->setVariable( "Day", $Day );
135 $session->setVariable ( "Week", $Week );
136
137 $zMonth = addZero($Month);
138 $isMyCalendar = ( $groupID && $groupID == $GetByGroupID )? "-private" :"";
139
140
141 // init the section
142 $sectionObject =& eZSection::globalSectionObject( $GlobalSectionID );
143 $sectionObject->setOverrideVariables();
144
145 $templateDirTmp = $sectionObject->templateStyle();
146
147 if ( $templateDirTmp != null && trim( $templateDirTmp ) != "" )
148 {
149 $TemplateDir = "kernel/ezgroupeventcalendar/user/" . preg_replace( "/(.+)\/.+(\/?)/", "/\\1/$templateDirTmp\\2", $TemplateDir );
150 }
151 else
152 {
153 $TemplateDir = "kernel/ezgroupeventcalendar/user/" . $ini->variable( "eZGroupEventCalendarMain", "TemplateDir" );
154 }
155
156 $t = new eZTemplate( $TemplateDir,
157 "kernel/ezgroupeventcalendar/user/intl", $Language, "weekview.php",
158 "default", "kernel/ezgroupeventcalendar" . "/user", "$Year-$zMonth-$Day-$GetByGroupID" . $isMyCalendar );
159
160 $t->set_file( "week_view_page_tpl", "weekview.tpl" );
161 $nextDate = $date;
162 $prevDate = $date;
163 // next previous values.
164 $nextDate->move(0, 0, 7);
165 $prevDate->move(0, 0, -7);
166 $t->set_var( "next_year_number", $nextDate->year() );
167 $t->set_var( "next_day_number", $nextDate->day() );
168 $t->set_var( "next_month_number",$nextDate->month() );
169 $t->set_var( "prev_year_number", $prevDate->year() );
170 $t->set_var( "prev_day_number", $prevDate->day() );
171 $t->set_var( "prev_month_number", $prevDate->month() );
172
173 // group not to include
174 $noShowGroup = new eZGroupNoShow();
175
176 $user_groupID = "-1";
177 $groupsList = "-1";
178
179 $rootAccess = false;
180 $new_event_link = false;
181
182 $permission = new eZGroupEditor();
183
184
185 // retreive all the groups the user is a member of
186 if( $user )
187 {
188 // if the user has root access, then the user has access to all groups
189 if( $user->hasRootAccess() == true || eZPermission::checkPermission( $user, "eZGroupEventCalendar", "WriteToRoot" ) )
190 {
191 $groups = new eZUserGroup();
192 $groupsList = $groups->getAll( true );
193 $rootAccess = true;
194 }
195 else
196 $groupsList = $user->groups();
197 }
198
199 // Determin if the user get the time stamps as "new event" links or not
200 if( $user )
201 if( $permission->hasEditPermission( $user->id(), $eventGroup->id() ) == true || $rootAccess == true )
202 $new_event_link = true;
203 elseif( $permission->getByGroup( $eventGroup->id() ) == false )
204 {
205 foreach( $groupsList as $groups )
206 {
207 if( $permission->groupHasEditor( $groups->id() ) == false && $noShowGroup->groupEntry( $groups->id() ) == false )
208 {
209 if( $eventGroup->id() != 0 && $groups->id() == $eventGroup->id() )
210 {
211 $new_event_link = true;
212 break;
213 }
214 elseif( $eventGroup->id() == 0 )
215 {
216 $new_event_link = true;
217 break;
218 }
219 }
220 }
221 }
222
223 //if ( $t->hasCache() )
224 //{
225 // print( "cached<br />" );
226 // print( $t->cache() );
227 //}
228 //else
229 //{
230 // print( "not cached<br />" );
231 $t->setAllStrings();
232
233 $t->set_block( "week_view_page_tpl", "group_item_tpl", "group_item" );
234 $t->set_block( "week_view_page_tpl", "type_item_tpl", "type_item" );
235 $t->set_block( "week_view_page_tpl", "group_print_tpl", "group_print" );
236 $t->set_block( "week_view_page_tpl", "week_tpl", "week" );
237 $t->set_block( "week_view_page_tpl", "new_event_form_tpl", "new_event_form" );
238 $t->set_block( "week_tpl", "week_day_tpl", "week_day" );
239 $t->set_block( "week_tpl", "day_tpl", "day" );
240
241 $t->set_block( "day_tpl", "day_link_tpl", "day_link" );
242 $t->set_block( "day_tpl", "day_no_link_tpl", "day_no_link" );
243
244 $t->set_block( "day_tpl", "public_appointment_tpl", "public_appointment" );
245 $t->set_block( "day_tpl", "private_appointment_tpl", "private_appointment" );
246 $t->set_block( "day_tpl", "new_event_link_tpl", "new_event_link" );
247 $t->set_block( "day_tpl", "no_new_event_link_tpl", "no_new_event_link" );
248
249 $t->set_var( "sitedesign", $SiteDesign );
250 $t->set_var( "month_name", $Locale->monthName( $date->monthName(), false ) );
251 $t->set_var( "month_number", $Month );
252 $t->set_var( "current_year_number", $Year );
253 $t->set_var( "week", "" );
254 $t->set_var( "sitedesign", $Sitedesign );
255 $t->set_var("date_month", $date->month());
256 $t->set_var("date_year", $date->year());
257 $t->set_var("date_day", $date->day());
258 $t->set_var( "week_num", $Week );
259
260
261 if( $new_event_link == true )
262 {
263 $t->parse( "new_event_link", "new_event_link_tpl" );
264 $t->parse( "new_event_form", "new_event_form_tpl" );
265 $t->set_var( "no_new_event_link", "" );
266 }
267 else
268 {
269 $t->parse( "no_new_event_link", "no_new_event_link_tpl" );
270 $t->set_var( "new_event_form", "" );
271 $t->set_var( "new_event_link", "" );
272 }
273
274
275 if ( $eventGroup->id() != 0 )
276 {
277 $t->set_var( "group_print_name", $eventGroup->name() );
278 $t->set_var( "group_print_id", $eventGroup->id() );
279 $t->parse( "group_print", "group_print_tpl", true );
280 }
281 else
282 {
283 $t->set_var( "group_print", "" );
284 }
285
286 // Draw the week day header.
287 $headerDate = new eZDate();
288 $headerDate->setYear( 2001 );
289 if ( $Locale->mondayFirst() )
290 {
291 // January 2001 starts on a Monday
292 $headerDate->setMonth( 1 );
293 }
294 else
295 {
296 // April 2001 starts on a Sunday
297 $headerDate->setMonth( 4 );
298 }
299
300 for ( $week_day=1; $week_day<=7; $week_day++ )
301 {
302 $headerDate->setDay( $week_day );
303 $t->set_var( "week_day_name", $Locale->dayName( $headerDate->dayName( $Locale->mondayFirst() ), false ) );
304
305 $t->parse( "week_day", "week_day_tpl", true );
306 }
307
308 $today = new eZDate();
309 $tmpDate = new eZDate();
310 $tmpGroupEvent = new eZGroupEvent();
311
312 /* for ( $week=0; $week<7; $week++ )
313 {
314 $t->set_var( "day", "" );
315 */
316 /* if ( ( ( $week * 7 ) - $firstDay + 1 ) < ( $date->daysInMonth() ) )
317 {
318 $date->setDay( 1 );
319 $firstDay = $date->dayOfWeek( $Locale->mondayFirst() );
320 */
321 $tmpMove = moveToWeekBegin($date, $Locale->mondayFirst());
322 $date->move(0,0, -$tmpMove);
323 for ( $day=1; $day<=7; $day++ )
324 {
325
326 // fetch the appointments for today
327 $tmpDate->setYear( $date->year() );
328 $tmpDate->setMonth( $date->month() );
329 $tmpDate->setDay( $date->day() );
330
331 // Fetch all the appointments
332 if( $eventGroup->id() == 0 && $type->id() == 0)
333 $appointments =& $tmpGroupEvent->getAllByDate( $tmpDate, true );
334 // Fetch all appointments by type
335 elseif( $eventGroup->id() == 0 && $type->id() != 0 )
336 $appointments =& $tmpGroupEvent->getAllByType( $tmpDate, $type, true );
337 // Fetch all appointments by Group and Type
338 elseif( $eventGroup->id() != 0 && $type->id() != 0 )
339 $appointments =& $tmpGroupEvent->getByGroupType( $tmpDate, $eventGroup, $type, true );
340 // Fetch all appointments by Group
341 else
342 $appointments =& $tmpGroupEvent->getByDate( $tmpDate, $eventGroup, true );
343
344 $t->set_var( "public_appointment", "" );
345 $t->set_var( "private_appointment", "" );
346
347
348
349
350 foreach ( $appointments as $appointment )
351 {
352 if ( !isset( $appointmentFullName ) )
353 {
354 $appointmentFullName = $appointment->name();
355 }
356 if ( !isset( $day_loop_count ) )
357 {
358 $day_loop_count = 0;
359 }
360 // kracker : trim apointment name to keep the calendar easy to read
361 $appointmentName = $appointment->name();
362 $t->set_var ( "appointment_name", stripslashes($appointmentName) );
363 $t->set_var ( "appointment_full_name", stripslashes($appointmentName) );
364 $t->set_var ( "overlib_full_name", addslashes($appointmentFullName));
365 $t->set_var ( "overlib_description", addslashes($appointment->description()) );
366 $t->set_var ( "appointment_id" , $appointment->id() );
367 $t->set_var ( "event_description", stripslashes($appointment->description()) );
368 $eStartTime = $appointment->startTime();
369 $eStopTime = $appointment->stopTime();
370 $event_start_time = addZero($eStartTime->hour()) . ':'. addZero( $eStartTime->minute() );
371 $event_stop_time = addZero($eStopTime->hour()) . ':'. addZero( $eStopTime->minute() );
372 $t->set_var ( "event_start_time", $event_start_time );
373 $t->set_var ( "event_stop_time", $event_stop_time );
374 if( $groupsList != "-1" )
375 {
376 foreach ( $groupsList as $groups )
377 {
378 //If the user has a matching group set their group id to the matching group else there group id will be -1.
379 if( $appointment->groupID() == $groups->id() )
380 {
381 $user_groupID = $groups->id();
382 break;
383 }
384 }
385 }
386
387 $groupName = new eZUserGroup( $appointment->groupID() );
388 $t->set_var ( "appointment_group", $groupName->name() );
389
390 if ( ( $appointment->isPrivate() == true && $user_groupID == $appointment->groupID() ) || ( $appointment->isPrivate() == true && eZPermission::checkPermission( $user, "eZGroupEventCalendar", "Read" ) ) || $appointment->isPrivate() == false )
391 {
392 $t->parse( "public_appointment", "public_appointment_tpl", true );
393 }
394 else
395 {
396 $t->parse( "private_appointment", "private_appointment_tpl", true );
397 }
398 }
399
400 $t->set_var( "day_number", $tmpDate->day() );
401 $t->set_var( "month_number_p", $Month );
402 $t->set_var( "year_number", $Year );
403
404 $t->set_var( "day_link", "" );
405
406 // if ( count($appointments) > 0 && $day_loop_count < 30 )
407 // print(count($appointments) ." | $a1 |" ."<br />\n");
408
409 // print(count($appointments) ." | $a1 |" ."<br />\n");
410 // print(count($appointments) ."<br />\n");
411
412 if( !isset( $currentDay ) )
413 {
414 $currentDay = $date->day();
415 }
416 else
417 {
418 $currentDay = $tmpDate->day();
419 }
420
421 $day_appointment_count = count($appointments);
422 $day_appointment_day = $currentDay;
423
424 if ( $day_appointment_count > 0 ) {
425 // needs calculation to say start / end of month begin / reached, note that items on the
426 // first and last few days of every month do not render their events only within the
427 // calendar's current month (? bug, negative feature), this is a hack fix to prevent
428 // the display of the links to days without events.
429 if ( $day_appointment_count > 0 && $day_loop_count <= 33 ){
430 // print("Rare: $day_appointment_day | $day_appointment_count | $day_loop_count <br />");
431 $t->set_var( "day_no_link", "" );
432 $t->parse( "day_link", "day_link_tpl" );
433 } else {
434 // print("Rare2: $day_appointment_day | $day_appointment_count | $day_loop_count <br />");
435
436 $t->set_var( "day_link", "" );
437 $t->parse( "day_no_link", "day_no_link_tpl" );
438 }
439 } else {
440 $t->set_var( "day_link", "" );
441 $t->parse( "day_no_link", "day_no_link_tpl" );
442 }
443
444 $t->parse( "day", "day_tpl", true );
445 $date->move(0,0,1);
446 }
447 $t->parse( "week", "week_tpl", true );
448
449 // group list
450 $group = new eZUserGroup();
451 $group_array =& $group->getAll();
452
453 foreach( $group_array as $groupItem )
454 {
455 if( $noShowGroup->groupEntry( $groupItem->id() ) == false )
456 {
457 $t->set_var( "group_id", $groupItem->id() );
458 $t->set_var( "group_name", $groupItem->Name() );
459
460 if ( $eventGroup->id() == $groupItem->id() )
461 {
462 $t->set_var( "selected_group_id", $eventGroup->id() );
463 $t->set_var( "group_is_selected", "selected" );
464 }
465 elseif ( $eventGroup->id() == 0 )
466 $t->set_var( "selected_group_id", 0 );
467 else
468 $t->set_var( "group_is_selected", "" );
469
470 $t->parse( "group_item", "group_item_tpl", true );
471 }
472 }
473
474 //type list
475 $typeList = $type->getAll();
476
477 foreach( $typeList as $type )
478 {
479 $t->set_var( "type_id", $type->id() );
480 $t->set_var( "type_name", $type->name( true ) );
481
482 if( $type->id() == $GetByTypeID )
483 {
484 $t->set_var( "selected_type_id", $type->id() );
485 $t->set_var( "type_is_selected", "selected" );
486 }
487 else
488 $t->set_var( "type_is_selected", "" );
489
490 $t->parse( "type_item", "type_item_tpl", true );
491 }
492
493 $t->storeCache( "output", "week_view_page_tpl", true );
494 //}
495
496
497 //Adds a "0" in front of the value if it's below 10.
498 function addZero( $value )
499 {
500 settype( $value, "integer" );
501 $ret = $value;
502 if ( $ret < 10 )
503 {
504 $ret = "0". $ret;
505 }
506 return $ret;
507 }
508 //Returns the day of week numerically 1-7
509 function moveToWeekBegin ( $date, $mondayFirst )
510 {
511 switch ($date->dayName( $mondayFirst ) )
512 {
513 case 'mon':
514 $ret = 0;
515 break;
516 case 'tue':
517 $ret = 1;
518 break;
519 case 'wed':
520 $ret = 2;
521 break;
522 case 'thu':
523 $ret = 3;
524 break;
525 case 'fri':
526 $ret = 4;
527 break;
528 case 'sat':
529 $ret = 5;
530 break;
531 case 'sun':
532 $ret = 6;
533 break;
534 }
535 return $ret;
536 }
537
538 ?>
$day
else $day
Definition: appointmentedit.php:665
$appointment
$appointment
Definition: appointmentview.php:89
eZDate
Definition: ezdate.php:46
eZGroupEditor
Definition: ezgroupeditor.php:33
eZGroupEventType
Definition: ezgroupeventtype.php:37
eZGroupEvent
Definition: ezgroupevent.php:85
eZGroupNoShow
Definition: ezgroupnoshow.php:34
eZLocale
Definition: ezlocale.php:119
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZSection\globalSectionObject
static & globalSectionObject( $sectionID)
Definition: ezsection.php:366
eZSession\globalSession
static & globalSession( $id="", $fetch=true)
Definition: kernel/ezsession/classes/ezsession.php:614
eZTemplate
Definition: eztemplate.php:107
eZUserGroup
Definition: ezusergroup.php:66
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
set_var
set_var( $group_name, $var_name, $var_value)
Definition: eZPBINIFile.php:456
$groups
if( $CategoryID !=0) $groups
Definition: ezbulkmail/admin/categoryedit.php:108
$appointments
$appointments
Definition: ezcalendar/user/dayview.php:136
$GetByGroupID
else $GetByGroupID
Definition: ezgroupeventcalendar/user/monthview.php:91
$day_loop_count
$day_loop_count
Definition: ezgroupeventcalendar/user/monthview.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$isMyCalendar
$isMyCalendar
Definition: weekview.php:138
$tmpDate
$tmpDate
Definition: weekview.php:309
$rootAccess
$rootAccess
Definition: weekview.php:179
$tmpGroupEvent
$tmpGroupEvent
Definition: weekview.php:310
$nextDate
$nextDate
Definition: weekview.php:161
$TruncateTitle
$TruncateTitle
Definition: weekview.php:57
$tmpMove
$tmpMove
Definition: weekview.php:321
$groupID
$groupID
Definition: weekview.php:80
$t
$t
Definition: weekview.php:156
$headerDate
$headerDate
Definition: weekview.php:287
$noShowGroup
$noShowGroup
Definition: weekview.php:174
$date
$date
Definition: weekview.php:115
$TemplateDir
$TemplateDir
Definition: weekview.php:59
$zMonth
$zMonth
Definition: weekview.php:137
$groupsList
$groupsList
Definition: weekview.php:177
$user
$user
Definition: weekview.php:64
$GlobalSectionID
$GlobalSectionID
Definition: weekview.php:60
$Month
$Month
Definition: weekview.php:126
$sectionObject
$sectionObject
Definition: weekview.php:142
else
if(count( $URL)<=5) else
Definition: weekview.php:78
$URL
$URL
Definition: weekview.php:68
$user_groupID
$user_groupID
Definition: weekview.php:176
$Locale
$Locale
Definition: weekview.php:62
$Language
$Language
Definition: weekview.php:55
$ini
$ini
Definition: weekview.php:52
addZero
addZero( $value)
Definition: weekview.php:498
$Week
$Week
Definition: weekview.php:130
moveToWeekBegin
moveToWeekBegin( $date, $mondayFirst)
Definition: weekview.php:509
$today
for( $week_day=1; $week_day<=7; $week_day++) $today
Definition: weekview.php:308
$permission
$permission
Definition: weekview.php:182
$prevDate
$prevDate
Definition: weekview.php:162
$new_event_link
$new_event_link
Definition: weekview.php:180
$group_array
$group_array
Definition: weekview.php:451
$Day
$Day
Definition: weekview.php:127
$session
$session
Definition: weekview.php:65
$typeList
foreach( $group_array as $groupItem) $typeList
Definition: weekview.php:475
$templateDirTmp
$templateDirTmp
Definition: weekview.php:145
$group
$group
Definition: weekview.php:450
$type
if(( $session->variable("ShowOtherCalendarTypes")==false)||(isSet( $GetByTypeID))) $type
Definition: weekview.php:110
$SiteDesign
$SiteDesign
Definition: weekview.php:54
$eventGroup
if(( $session->variable("ShowOtherCalendarGroups")==false)||(isSet( $GetByGroup))) $eventGroup
Definition: weekview.php:99
$Sitedesign
$Sitedesign
Definition: weekview.php:56
shortenText
shortenText($text, $chars=25)
Definition: weekview.php:41
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.