4 * This page will display the month "view" with all users's events
5 * on the same calendar. (The other month "view" displays each user
6 * calendar in a separate column, side-by-side.) This view gives you
7 * the same effect as enabling layers, but with layers you can only
8 * have one configuration of users.
11 * id (*) - specify view id in webcal_view table
12 * date - specify the starting date of the view.
13 * If not specified, current date will be used.
14 * friendly - if set to 1, then page does not include links or
19 * Must have "allow view others" enabled ($allow_view_other) in
20 * System Settings unless the user is an admin user ($is_admin).
21 * If the view is not global, the user must be owner of the view.
22 * If the view is global, then and user_sees_only_his_groups is
23 * enabled, then we remove users not in this user's groups
24 * (except for nonuser calendars... which we allow regardless of group).
26 include_once $gfplugins.'webcalendar/www/includes/init.php';
31 if ( $allow_view_other == "N" && ! $is_admin ) {
33 send_to_preferred_view ();
35 if ( empty ( $id ) ) {
36 do_redirect ( "views.php" );
39 // Find view name in $views[]
41 for ( $i = 0; $i < count ( $views ); $i++ ) {
42 if ( $views[$i]['cal_view_id'] == $id ) {
43 $view_name = $views[$i]['cal_name'];
47 // If view_name not found, then the specified view id does not
48 // belong to current user.
49 if ( empty( $view_name ) ) {
50 $error = translate ( "You are not authorized" );
53 $INC = array('js/popups.php');
58 $next = mktime ( 3, 0, 0, $thismonth, $thisday + 7, $thisyear );
59 $nextyear = date ( "Y", $next );
60 $nextmonth = date ( "m", $next );
61 $nextday = date ( "d", $next );
62 $nextdate = sprintf ( "%04d%02d%02d", $nextyear, $nextmonth, $nextday );
64 $prev = mktime ( 3, 0, 0, $thismonth, $thisday - 7, $thisyear );
65 $prevyear = date ( "Y", $prev );
66 $prevmonth = date ( "m", $prev );
67 $prevday = date ( "d", $prev );
68 $prevdate = sprintf ( "%04d%02d%02d", $prevyear, $prevmonth, $prevday );
70 // We add 2 hours on to the time so that the switch to DST doesn't
71 // throw us off. So, all our dates are 2AM for that day.
72 if ( $WEEK_START == 1 ) {
73 $wkstart = get_monday_before ( $thisyear, $thismonth, $thisday );
75 $wkstart = get_sunday_before ( $thisyear, $thismonth, $thisday );
77 $wkend = $wkstart + ( 3600 * 24 * 6 );
78 $startdate = date ( "Ymd", $wkstart );
79 $enddate = date ( "Ymd", $wkend );
81 $thisdate = $startdate;
83 for ( $i = 0; $i < 7; $i++ ) {
84 $days[$i] = $wkstart + ( 24 * 3600 ) * $i;
85 $weekdays[$i] = weekday_short_name ( ( $i + $WEEK_START ) % 7 );
86 $header[$i] = $weekdays[$i] . "<br />" .
87 month_short_name ( date ( "m", $days[$i] ) - 1 ) .
88 " " . date ( "d", $days[$i] );
92 <div style="border-width:0px; width:99%;">
93 <a title="<?php etranslate("Previous")?>" class="prev"
94 href="view_v.php?id=<?php echo $id?>&date=<?php echo $prevdate?>">
95 <img src="leftarrow.gif" alt="<?php etranslate("Previous")?>" /></a>
97 <a title="<?php etranslate("Next")?>" class="next"
98 href="view_v.php?id=<?php echo $id?>&date=<?php echo $nextdate?>">
99 <img src="rightarrow.gif" class="prevnext" alt="<?php etranslate("Next")?>" /></a>
101 <span class="date"><?php
102 echo date_to_str ( date ( "Ymd", $wkstart ), false ) .
103 " - " .
104 date_to_str ( date ( "Ymd", $wkend ), false );
106 <span class="viewname"><?php echo $view_name ?></span>
110 // The table has names across the top and dates for rows. Since we need
111 // to spit out an entire row before we can move to the next date, we'll
112 // save up all the HTML for each cell and then print it out when we're
114 // Additionally, we only want to put at most 6 users in one table since
115 // any more than that doesn't really fit in the page.
117 // get users in this view
119 "SELECT cal_login FROM webcal_view_user WHERE cal_view_id = $id" );
120 $viewusers = array ();
123 while ( $row = dbi_fetch_row ( $res ) ) {
124 $viewusers[] = $row[0];
125 if ( $row[0] == "__all__" ) {
129 dbi_free_result ( $res );
131 $error = translate ( "Database error" ) . ": " . dbi_error ();
135 $viewusers = array ();
136 $users = get_my_users ();
137 for ( $i = 0; $i < count ( $users ); $i++ ) {
138 $viewusers[] = $users[$i]['cal_login'];
141 // Make sure this user is allowed to see all users in this view
142 // If this is a global view, it may include users that this user
143 // is not allowed to see.
144 if ( ! empty ( $user_sees_only_his_groups ) &&
145 $user_sees_only_his_groups == 'Y' ) {
146 $myusers = get_my_users ();
147 if ( ! empty ( $nonuser_enabled ) && $nonuser_enabled == "Y" ) {
148 $myusers = array_merge ( $myusers, get_nonuser_cals () );
150 $userlookup = array ();
151 for ( $i = 0; $i < count ( $myusers ); $i++ ) {
152 $userlookup[$myusers[$i]['cal_login']] = 1;
155 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
156 if ( ! empty ( $userlookup[$viewusers[$i]] ) ) {
157 $newlist[] = $viewusers[$i];
160 $viewusers = $newlist;
163 if ( count ( $viewusers ) == 0 ) {
164 // This could happen if user_sees_only_his_groups = Y and
165 // this user is not a member of any group assigned to this view
166 $error = translate ( "No users for this view" );
169 if ( ! empty ( $error ) ) {
170 echo "<h2>" . translate ( "Error" ) .
178 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
179 /* Pre-Load the repeated events for quckier access */
180 $repeated_events = read_repeated_events ( $viewusers[$i], "", $startdate );
181 $re_save[$i] = $repeated_events;
182 /* Pre-load the non-repeating events for quicker access */
183 $events = read_events ( $viewusers[$i], $startdate, $enddate );
184 $e_save[$i] = $events;
187 for ( $j = 0; $j < 7; $j += $DAYS_PER_TABLE ) {
188 // since print_date_entries is rather stupid, we can swap the event data
189 // around for users by changing what $events points to.
191 $tdw = 12; // column width percent
194 <table class="main" cellspacing="0" cellpadding="0">
195 <tr><th class="empty"> </th>
197 for ( $date = $wkstart, $h = 0;
198 date ( "Ymd", $date ) <= date ( "Ymd", $wkend );
199 $date += ( 24 * 3600 ), $h++ ) {
200 $wday = strftime ( "%w", $date );
201 $weekday = weekday_short_name ( $wday );
202 if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ) {
203 echo "<th class=\"today\" style=\"width:$tdw%;\">";
205 echo "<th style=\"width:$tdw%;\">";
207 echo $weekday . " " .
208 round ( date ( "d", $date ) ) . "</th>\n";
211 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
213 $user = $viewusers[$i];
214 user_load_variables ( $user, "temp" );
215 echo "<th class=\"row\" style=\"width:$tdw%;\">$tempfullname</th>";
216 for ( $date = $wkstart, $h = 0;
217 date ( "Ymd", $date ) <= date ( "Ymd", $wkend );
218 $date += ( 24 * 3600 ), $h++ ) {
219 $wday = strftime ( "%w", $date );
220 if ( $wday == 0 || $wday == 6 ) {
221 echo "<td class=\"weekend\" style=\"width:$tdw%;\">";
223 echo "<td style=\"width:$tdw%;\">";
225 $events = $e_save[$i];
226 $repeated_events = $re_save[$i];
227 if ( empty ( $add_link_in_views ) || $add_link_in_views != "N" ) {
228 echo html_for_add_icon ( date ( "Ymd", $date ), "", "", $user );
230 print_date_entries ( date ( "Ymd", $date ), $user, true );
235 echo "</table>\n<br /><br />\n";
240 if ( ! empty ( $eventinfo ) ) {
244 echo "<a title=\"" . translate("Generate printer-friendly version") .
245 "\" class=\"printer\" href=\"view_v.php?id=$id&date=" .
246 "$thisdate&friendly=1\" " .
247 "target=\"cal_printer_friendly\" onmouseover=\"window.status='" .
248 translate("Generate printer-friendly version") .
249 "'\">[" . translate("Printer Friendly") . "]</a>\n";