4 * This page will display a timebar for a week or month as
8 * id (*) - specify view id in webcal_view table
9 * date - specify the starting date of the view.
10 * If not specified, current date will be used.
11 * friendly - if set to 1, then page does not include links or
13 * timeb - 1 = week, else month
17 * Must have "allow view others" enabled ($allow_view_other) in
18 * System Settings unless the user is an admin user ($is_admin).
19 * If the view is not global, the user must be owner of the view.
20 * If the view is global, then and user_sees_only_his_groups is
21 * enabled, then we remove users not in this user's groups
22 * (except for nonuser calendars... which we allow regardless of group).
24 include_once $gfplugins.'webcalendar/www/includes/init.php';
29 if ( $allow_view_other == "N" && ! $is_admin ) {
31 send_to_preferred_view ();
34 if ( empty ( $id ) ) {
35 do_redirect ( "views.php" );
38 // Find view name in $views[]
40 for ( $i = 0; $i < count ( $views ); $i++ ) {
41 if ( $views[$i]['cal_view_id'] == $id ) {
42 $view_name = $views[$i]['cal_name'];
46 // If view_name not found, then the specified view id does not
47 // belong to current user.
48 if ( empty ( $view_name ) ) {
49 $error = translate ( "You are not authorized" );
52 $INC = array('js/popups.php');
55 // Initialize date to first of current month
57 $date = substr($date,0,6)."01";
64 $next = mktime ( 3, 0, 0, $thismonth, $thisday + 7, $thisyear );
66 $next = mktime ( 3, 0, 0, $thismonth + 1, $thisday, $thisyear );
68 $nextyear = date ( "Y", $next );
69 $nextmonth = date ( "m", $next );
70 $nextday = date ( "d", $next );
71 $nextdate = sprintf ( "%04d%02d%02d", $nextyear, $nextmonth, $nextday );
74 $prev = mktime ( 3, 0, 0, $thismonth, $thisday - 7, $thisyear );
76 $prev = mktime ( 3, 0, 0, $thismonth - 1, $thisday, $thisyear );
78 $prevyear = date ( "Y", $prev );
79 $prevmonth = date ( "m", $prev );
80 $prevday = date ( "d", $prev );
81 $prevdate = sprintf ( "%04d%02d%02d", $prevyear, $prevmonth, $prevday );
83 // We add 2 hours on to the time so that the switch to DST doesn't
84 // throw us off. So, all our dates are 2AM for that day.
86 if ( $WEEK_START == 1 ) {
87 $wkstart = get_monday_before ( $thisyear, $thismonth, $thisday );
89 $wkstart = get_sunday_before ( $thisyear, $thismonth, $thisday );
92 $wkstart = mktime ( 3, 0, 0, $thismonth, 1, $thisyear );
96 $wkend = $wkstart + ( 3600 * 24 * 6 );
98 $wkend = mktime ( 3, 0, 0, $thismonth + 1, 0, $thisyear );
100 $startdate = date ( "Ymd", $wkstart );
101 $enddate = date ( "Ymd", $wkend );
103 $thisdate = $startdate;
108 $val_boucle = date("t", $wkstart);
110 for ( $i = 0; $i < $val_boucle; $i++ ) {
111 $days[$i] = $wkstart + ( 24 * 3600 ) * $i;
112 $weekdays[$i] = weekday_short_name ( ( $i + $WEEK_START ) % $val_boucle );
113 $header[$i] = $weekdays[$i] . "<br />\n" .
114 month_short_name ( date ( "m", $days[$i] ) - 1 ) .
115 " " . date ( "d", $days[$i] );
118 // get users in this view
120 "SELECT cal_login FROM webcal_view_user WHERE cal_view_id = $id" );
121 $viewusers = array ();
124 while ( $row = dbi_fetch_row ( $res ) ) {
125 $viewusers[] = $row[0];
126 if ( $row[0] == "__all__" ) {
130 dbi_free_result ( $res );
132 $error = translate ( "Database error" ) . ": " . dbi_error ();
136 $viewusers = array ();
137 $users = get_my_users ();
138 for ( $i = 0; $i < count ( $users ); $i++ ) {
139 $viewusers[] = $users[$i]['cal_login'];
142 // Make sure this user is allowed to see all users in this view
143 // If this is a global view, it may include users that this user
144 // is not allowed to see.
145 if ( ! empty ( $user_sees_only_his_groups ) &&
146 $user_sees_only_his_groups == 'Y' ) {
147 $myusers = get_my_users ();
148 if ( ! empty ( $nonuser_enabled ) && $nonuser_enabled == "Y" ) {
149 $myusers = array_merge ( $myusers, get_nonuser_cals () );
151 $userlookup = array();
152 for ( $i = 0; $i < count ( $myusers ); $i++ ) {
153 $userlookup[$myusers[$i]['cal_login']] = 1;
156 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
157 if ( ! empty ( $userlookup[$viewusers[$i]] ) ) {
158 $newlist[] = $viewusers[$i];
161 $viewusers = $newlist;
164 if ( count ( $viewusers ) == 0 ) {
165 // This could happen if user_sees_only_his_groups = Y and
166 // this user is not a member of any group assigned to this view
167 $error = translate ( "No users for this view" );
170 if ( ! empty ( $error ) ) {
171 echo "<h2>" . translate ( "Error" ) .
179 <div style="border-width:0px; width:99%;">
180 <a title="<?php etranslate("Previous")?>" class="prev" href="view_t.php?timeb=
181 <?php echo $timeb?>&id=<?php echo $id?>&date=
182 <?php echo $prevdate?>"><img src="leftarrow.gif" alt="
183 <?php etranslate("Previous")?>" /></a>
185 <a title="<?php etranslate("Next")?>" class="next" href="view_t.php?timeb=
186 <?php echo $timeb?>&id=<?php echo $id?>&date=
187 <?php echo $nextdate?>"><img src="rightarrow.gif" alt="
188 <?php etranslate("Next")?>" /></a>
190 <span class="date"><?php
191 echo date_to_str ( date ( "Ymd", $wkstart ), false ) .
192 " - " .
193 date_to_str ( date ( "Ymd", $wkend ), false );
195 <span class="viewname"><?php
202 // The table has names across the top and dates for rows. Since we need
203 // to spit out an entire row before we can move to the next date, we'll
204 // save up all the HTML for each cell and then print it out when we're
206 // Additionally, we only want to put at most 6 users in one table since
207 // any more than that doesn't really fit in the page.
212 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
213 /* Pre-Load the repeated events for quckier access */
214 $repeated_events = read_repeated_events ( $viewusers[$i], "", $startdate );
215 $re_save = array_merge($re_save, $repeated_events);
216 /* Pre-load the non-repeating events for quicker access */
217 $events = read_events ( $viewusers[$i], $startdate, $enddate );
218 $e_save = array_merge($e_save, $events);
221 $repeated_events = $re_save;
224 <table class="viewt">
226 for ( $date = $wkstart, $h = 0;
227 date ( "Ymd", $date ) <= date ( "Ymd", $wkend );
228 $date += ( 24 * 3600 ), $h++ ) {
229 $wday = strftime ( "%w", $date );
230 $weekday = weekday_short_name ( $wday );
231 if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ) {
232 echo "<tr><th class=\"today\">";
234 echo "<tr><th class=\"row\">";
236 if ( empty ( $add_link_in_views ) || $add_link_in_views != "N" ) {
237 echo html_for_add_icon ( date ( "Ymd", $date ), "", "", $user );
239 echo $weekday . " " . round ( date ( "d", $date ) ) . "</th>\n";
241 //start the container cell for each day, with its appropriate style
242 if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ) {
243 echo "<td class=\"today\">";
245 if ( $wday == 0 || $wday == 6 ) {
246 echo "<td class=\"weekend\">";
248 echo "<td class=\"reg\">";
253 if ( ! isset ($prefarray["WORK_DAY_START_HOUR"] ) ||
254 ! isset ( $prefarray["WORK_DAY_END_HOUR"] ) ) {
255 $val = dbi_fetch_row ( dbi_query ( "SELECT cal_value FROM webcal_config
256 where cal_setting='WORK_DAY_START_HOUR'" ));
257 $prefarray["WORK_DAY_START_HOUR"]=$val[0];
258 $val = dbi_fetch_row ( dbi_query ( "SELECT cal_value FROM webcal_config
259 where cal_setting='WORK_DAY_END_HOUR'" ));
260 $prefarray["WORK_DAY_END_HOUR"]=$val[0];
263 print_header_timebar($prefarray["WORK_DAY_START_HOUR"],
264 $prefarray["WORK_DAY_END_HOUR"]);
265 print_date_entries_timebar ( date ( "Ymd", $date ), $GLOBALS["login"], true );
270 echo "</table>\n<br />\n";
274 if ( ! empty ( $eventinfo ) ) {
278 echo "<a title=\"" . translate("Generate printer-friendly version") . "\" " .
279 "class=\"printer\" href=\"view_t.php?timeb=$timeb&id=$id&date=" .
280 "$thisdate&friendly=1\" target=\"cal_printer_friendly\" " .
281 "onmouseover=\"window.status='" .
282 translate("Generate printer-friendly version") .
283 "'\">[" . translate("Printer Friendly") . "]</a>\n";