2 include_once $gfplugins.'webcalendar/www/includes/init.php';
4 if (($user != $login) && $is_nonuser_admin) {
5 load_user_layers ($user);
10 load_user_categories ();
12 $next = mktime ( 3, 0, 0, $thismonth, $thisday + 7, $thisyear );
13 $prev = mktime ( 3, 0, 0, $thismonth, $thisday - 7, $thisyear );
15 // We add 2 hours on to the time so that the switch to DST doesn't
16 // throw us off. So, all our dates are 2AM for that day.
17 if ( $WEEK_START == 1 ) {
18 $wkstart = get_monday_before ( $thisyear, $thismonth, $thisday );
20 $wkstart = get_sunday_before ( $thisyear, $thismonth, $thisday );
23 $wkend = $wkstart + ( 3600 * 24 * 6 );
25 $startdate = date ( "Ymd", $wkstart );
26 $enddate = date ( "Ymd", $wkend );
28 if ( ! empty ( $DISPLAY_WEEKENDS ) && $DISPLAY_WEEKENDS == "N" ) {
29 if ( $WEEK_START == 1 ) {
42 if ( ! empty ( $auto_refresh ) && $auto_refresh == "Y" &&
43 ! empty ( $auto_refresh_time ) ) {
44 $refresh = $auto_refresh_time * 60; // convert to seconds
45 $HeadX = "<meta http-equiv=\"refresh\" content=\"$refresh; url=week.php?$u_url" .
46 "date=$startdate$caturl" .
47 ( ! empty ( $friendly ) ? "&friendly=1" : "") . "\" />\n";
49 $INC = array('js/popups.php');
50 print_header($INC,$HeadX);
52 /* Pre-Load the repeated events for quckier access */
53 $repeated_events = read_repeated_events ( strlen ( $user ) ? $user : $login,
54 $cat_id, $startdate );
56 /* Pre-load the non-repeating events for quicker access */
57 $events = read_events ( strlen ( $user ) ? $user : $login,
58 $startdate, $enddate, $cat_id );
60 for ( $i = 0; $i < 7; $i++ ) {
61 $days[$i] = $wkstart + ( 24 * 3600 ) * $i;
62 $weekdays[$i] = weekday_short_name ( ( $i + $WEEK_START ) % 7 );
63 $header[$i] = $weekdays[$i] . "<br />\n" .
64 date_to_str ( date ( "Ymd", $days[$i] ), $DATE_FORMAT_MD, false );
69 <span class="date"><?php
70 echo date_to_str ( date ( "Ymd", $wkstart ), "", false ) .
71 " - " .
72 date_to_str ( date ( "Ymd", $wkend ), "", false );
75 if ( $GLOBALS["DISPLAY_WEEKNUMBER"] == "Y" ) {
76 echo "<br />\n<span class=\"weeknumber\">(" .
77 translate("Week") . " " . week_number ( $wkstart ) . ")</span>";
80 <a title="<?php etranslate("Previous")?>"
81 class="prev" href="week.php?<?php echo $u_url; ?>date=<?php echo
82 date("Ymd", $prev ) . $caturl;?>"><img src="leftarrow.gif"
83 alt="<?php etranslate("Previous")?>" /></a>
85 <a title="<?php etranslate("Next")?>" class="next"
86 href="week.php?<?php echo $u_url;?>date=<?php echo
87 date ("Ymd", $next ) . $caturl;?>"><img src="rightarrow.gif"
88 alt="<?php etranslate("Next")?>" /></a>
89 <span class="user"><?php
90 if ( $single_user == "N" ) {
91 echo "<br />".@$user_fullname;
93 if ( $is_nonuser_admin ) {
94 echo "<br />-- " . translate("Admin mode") . " --";
96 if ( $is_assistant ) {
97 echo "<br />-- " . translate("Assistant mode") . " --";
101 if ( $categories_enabled == "Y" && (!$user || ($user == $login ||
103 echo "<br /><br />\n";
104 print_category_menu('week', sprintf ( "%04d%02d%02d",$thisyear,
105 $thismonth, $thisday ), $cat_id );
110 <table class="main" cellspacing="0" cellpadding="0">
112 <th class="empty"> </th>
114 for ( $d = $start_ind; $d < $end_ind; $d++ ) {
115 $thiswday = date ( 'w', $days[$d] );
117 $is_weekend = ( $thiswday == 0 || $thiswday == 6 );
125 if ( date ( 'Ymd', $days[$d] ) == date ( 'Ymd', $today ) ) {
126 if ( $class != '' ) {
135 echo " class=\"$class\"";
140 echo html_for_add_icon ( date ( "Ymd", $days[$d] ), "", "", $user );
142 echo "<a href=\"day.php?" . $u_url .
143 "date=" . date ('Ymd', $days[$d] ) . $caturl . "\">" .
144 $header[$d] . "</a></th>\n";
150 if ( empty ( $TIME_SLOTS ) ) {
154 $interval = ( 24 * 60 ) / $TIME_SLOTS;
156 $first_slot = (int)( ( ( $WORK_DAY_START_HOUR - $TZ_OFFSET ) * 60 ) / $interval );
157 $last_slot = (int)( ( ( $WORK_DAY_END_HOUR - $TZ_OFFSET ) * 60 ) / $interval );
159 $untimed_found = false;
160 $get_unapproved = ( $GLOBALS["DISPLAY_UNAPPROVED"] == "Y" );
161 if ( $login == "__public__" ) {
162 $get_unapproved = false;
166 for ( $d = $start_ind; $d < $end_ind; $d++ ) {
167 // get all the repeating events for this date and store in array $rep
168 $date = date ( "Ymd", $days[$d] );
169 $rep = get_repeating_entries ( $user, $date );
172 // Get static non-repeating events
173 $ev = get_entries ( $user, $date, $get_unapproved );
174 $hour_arr = array ();
175 $rowspan_arr = array ();
176 for ( $i = 0; $i < count ( $ev ); $i++ ) {
177 // print out any repeating events that are before this one...
178 while ( $cur_rep < count ( $rep ) &&
179 $rep[$cur_rep]['cal_time'] < $ev[$i]['cal_time'] ) {
180 if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) {
181 if ( ! empty ( $rep[$cur_rep]['cal_ext_for_id'] ) ) {
182 $viewid = $rep[$cur_rep]['cal_ext_for_id'];
183 $viewname = $rep[$cur_rep]['cal_name'] . " (" .
184 translate("cont.") . ")";
186 $viewid = $rep[$cur_rep]['cal_id'];
187 $viewname = $rep[$cur_rep]['cal_name'];
189 if ( $rep[$cur_rep]['cal_duration'] == ( 24 * 60 ) ) {
192 html_for_event_week_at_a_glance ( $viewid,
193 $date, $rep[$cur_rep]['cal_time'],
194 $viewname, $rep[$cur_rep]['cal_description'],
195 $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'],
196 $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_duration'],
197 $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] );
201 if ( $get_unapproved || $ev[$i]['cal_status'] == 'A' ) {
202 if ( ! empty ( $ev[$i]['cal_ext_for_id'] ) ) {
203 $viewid = $ev[$i]['cal_ext_for_id'];
204 $viewname = $ev[$i]['cal_name'] . " (" .
205 translate("cont.") . ")";
207 $viewid = $ev[$i]['cal_id'];
208 $viewname = $ev[$i]['cal_name'];
210 if ( $ev[$i]['cal_duration'] == ( 24 * 60 ) ) {
213 html_for_event_week_at_a_glance ( $viewid,
214 $date, $ev[$i]['cal_time'],
215 $viewname, $ev[$i]['cal_description'],
216 $ev[$i]['cal_status'], $ev[$i]['cal_priority'],
217 $ev[$i]['cal_access'], $ev[$i]['cal_duration'],
218 $ev[$i]['cal_login'], $ev[$i]['cal_category'] );
221 // print out any remaining repeating events
222 while ( $cur_rep < count ( $rep ) ) {
223 if ( $get_unapproved || $rep[$cur_rep]['cal_status'] == 'A' ) {
224 if ( ! empty ( $rep[$cur_rep]['cal_ext_for_id'] ) ) {
225 $viewid = $rep[$cur_rep]['cal_ext_for_id'];
226 $viewname = $rep[$cur_rep]['cal_name'] . " (" .
227 translate("cont.") . ")";
229 $viewid = $rep[$cur_rep]['cal_id'];
230 $viewname = $rep[$cur_rep]['cal_name'];
232 if ( $rep[$cur_rep]['cal_duration'] == ( 24 * 60 ) ) {
235 html_for_event_week_at_a_glance ( $viewid,
236 $date, $rep[$cur_rep]['cal_time'],
237 $viewname, $rep[$cur_rep]['cal_description'],
238 $rep[$cur_rep]['cal_status'], $rep[$cur_rep]['cal_priority'],
239 $rep[$cur_rep]['cal_access'], $rep[$cur_rep]['cal_duration'],
240 $rep[$cur_rep]['cal_login'], $rep[$cur_rep]['cal_category'] );
245 // squish events that use the same cell into the same cell.
246 // For example, an event from 8:00-9:15 and another from 9:30-9:45 both
247 // want to show up in the 8:00-9:59 cell.
250 for ( $i = 0; $i < $TIME_SLOTS; $i++ ) {
251 if ( $rowspan > 1 ) {
252 if ( ! empty ( $hour_arr[$i] ) ) {
253 $diff_start_time = $i - $last_row;
254 if ( $rowspan_arr[$i] > 1 ) {
255 if ( $rowspan_arr[$i] + ( $diff_start_time ) > $rowspan_arr[$last_row] ) {
256 $rowspan_arr[$last_row] = ( $rowspan_arr[$i] + ( $diff_start_time ) );
258 $rowspan += ( $rowspan_arr[$i] - 1 );
260 $rowspan_arr[$last_row] += $rowspan_arr[$i];
262 // this will move entries apart that appear in one field,
263 // yet start on different hours
264 for ( $u = $diff_start_time ; $u > 0 ; $u-- ) {
265 $hour_arr[$last_row] .= "<br />\n";
267 $hour_arr[$last_row] .= $hour_arr[$i];
269 $rowspan_arr[$i] = 0;
272 } else if ( ! empty ( $rowspan_arr[$i] ) && $rowspan_arr[$i] > 1 ) {
273 $rowspan = $rowspan_arr[$i];
278 // now save the output...
279 if ( ! empty ( $hour_arr[9999] ) && strlen ( $hour_arr[9999] ) ) {
280 $untimed[$d] = $hour_arr[9999];
281 $untimed_found = true;
283 $save_hour_arr[$d] = $hour_arr;
284 $save_rowspan_arr[$d] = $rowspan_arr;
287 // untimed events first
288 if ( $untimed_found ) {
289 echo "<tr>\n<th class=\"empty\"> </th>\n";
290 for ( $d = $start_ind; $d < $end_ind; $d++ ) {
291 $thiswday = date ( "w", $days[$d] );
292 $is_weekend = ( $thiswday == 0 || $thiswday == 6 );
293 $class = ( $is_weekend ? "weekend" : "" );
295 if ( date ( 'Ymd', $days[$d] ) == date ( 'Ymd', $today ) ) {
303 // Use the class 'hasevents' for any hour block that has events
305 if ( ! empty ( $untimed[$d] ) && strlen ( $untimed[$d] ) ) {
306 $class = 'hasevents';
309 if ( $class != "" ) {
310 echo " class=\"$class\"";
314 if ( ! empty ( $untimed[$d] ) && strlen ( $untimed[$d] ) ) {
324 for ( $d = $start_ind; $d < $end_ind; $d++ ) {
325 $rowspan_day[$d] = 0;
328 for ( $i = $first_slot; $i <= $last_slot; $i++ ) {
329 $time_h = (int) ( ( $i * $interval ) / 60 );
330 $time_m = ( $i * $interval ) % 60;
331 $time = display_time ( ( $time_h * 100 + $time_m ) * 100 );
332 echo "<tr>\n<th class=\"row\">" . $time . "</th>\n";
333 for ( $d = $start_ind; $d < $end_ind; $d++ ) {
334 $thiswday = date ( "w", $days[$d] );
335 $is_weekend = ( $thiswday == 0 || $thiswday == 6 );
336 $class = ( $is_weekend ? "weekend" : "" );
337 if ( date ( 'Ymd', $days[$d] ) == date ( 'Ymd', $today ) ) {
338 if ( $class != "" ) {
344 // Use the class 'hasevents' for any hour block that has events
346 if ( ! empty ( $save_hour_arr[$d][$i] ) &&
347 strlen ( $save_hour_arr[$d][$i] ) ) {
348 $class = 'hasevents';
351 if ( $rowspan_day[$d] > 1 ) {
352 // this might mean there's an overlap, or it could mean one event
353 // ends at 11:15 and another starts at 11:30.
354 if ( ! empty ( $save_hour_arr[$d][$i] ) ) {
356 if ( $class != '' ) {
357 echo " class=\"$class\"";
359 echo ">" . $save_hour_arr[$d][$i] . "</td>\n";
362 } else if ( empty ( $save_hour_arr[$d][$i] ) ) {
364 if ( $class != "" ) {
365 echo " class=\"$class\"";
368 if ( $can_add ) { //if user can add events...
369 echo html_for_add_icon ( date ( "Ymd", $days[$d] ), $time_h, $time_m,
370 $user ); //..then echo the add event icon
372 echo " </td>\n";
374 $rowspan_day[$d] = $save_rowspan_arr[$d][$i];
375 if ( $rowspan_day[$d] > 1 ) {
377 if ( $class != '' ) {
378 echo " class=\"$class\"";
380 echo " rowspan=\"$rowspan_day[$d]\">";
382 echo html_for_add_icon ( date ( "Ymd", $days[$d] ), $time_h, $time_m, $user );
384 echo $save_hour_arr[$d][$i] . "</td>\n";
387 if ( $class != '' ) {
388 echo " class=\"$class\"";
392 echo html_for_add_icon ( date ( "Ymd", $days[$d] ), $time_h, $time_m, $user );
394 echo $save_hour_arr[$d][$i] . "</td>\n";
405 if ( ! empty ( $eventinfo ) ) {
408 display_unapproved_events ( ( $is_assistant ||
409 $is_nonuser_admin ? $user : $login ) );
413 <a title="<?php etranslate("Generate printer-friendly version")?>"
414 class="printer" href="week.php?<?php
417 echo "year=$thisyear&month=$thismonth&day=$thisday";
419 echo $caturl . "&";
420 ?>friendly=1" target="cal_printer_friendly"
421 onmouseover="window.status = '<?php etranslate("Generate printer-friendly version")?>'">[<?php etranslate("Printer Friendly")?>]</a>