3 * $Id: view_v.php,v 1.33 2005/03/06 23:26:35 umcesrjones Exp $
6 * This page will display the month "view" with all users's events
7 * on the same calendar. (The other month "view" displays each user
8 * calendar in a separate column, side-by-side.) This view gives you
9 * the same effect as enabling layers, but with layers you can only
10 * have one configuration of users.
13 * id (*) - specify view id in webcal_view table
14 * date - specify the starting date of the view.
15 * If not specified, current date will be used.
16 * friendly - if set to 1, then page does not include links or
21 * Must have "allow view others" enabled ($allow_view_other) in
22 * System Settings unless the user is an admin user ($is_admin).
23 * If the view is not global, the user must be owner of the view.
24 * If the view is global, then and user_sees_only_his_groups is
25 * enabled, then we remove users not in this user's groups
26 * (except for nonuser calendars... which we allow regardless of group).
28 include_once $gfplugins.'webcalendar/www/includes/init.php';
33 if ( $allow_view_other == "N" && ! $is_admin ) {
35 send_to_preferred_view ();
37 if ( empty ( $id ) ) {
38 do_redirect ( "views.php" );
41 // Find view name in $views[]
43 for ( $i = 0; $i < count ( $views ); $i++ ) {
44 if ( $views[$i]['cal_view_id'] == $id ) {
45 $view_name = $views[$i]['cal_name'];
49 // If view_name not found, then the specified view id does not
50 // belong to current user.
51 if ( empty( $view_name ) ) {
52 $error = translate ( "You are not authorized" );
55 $INC = array('js/popups.php');
60 $next = mktime ( 3, 0, 0, $thismonth, $thisday + 7, $thisyear );
61 $nextyear = date ( "Y", $next );
62 $nextmonth = date ( "m", $next );
63 $nextday = date ( "d", $next );
64 $nextdate = sprintf ( "%04d%02d%02d", $nextyear, $nextmonth, $nextday );
66 $prev = mktime ( 3, 0, 0, $thismonth, $thisday - 7, $thisyear );
67 $prevyear = date ( "Y", $prev );
68 $prevmonth = date ( "m", $prev );
69 $prevday = date ( "d", $prev );
70 $prevdate = sprintf ( "%04d%02d%02d", $prevyear, $prevmonth, $prevday );
72 // We add 2 hours on to the time so that the switch to DST doesn't
73 // throw us off. So, all our dates are 2AM for that day.
74 if ( $WEEK_START == 1 ) {
75 $wkstart = get_monday_before ( $thisyear, $thismonth, $thisday );
77 $wkstart = get_sunday_before ( $thisyear, $thismonth, $thisday );
79 $wkend = $wkstart + ( 3600 * 24 * 6 );
80 $startdate = date ( "Ymd", $wkstart );
81 $enddate = date ( "Ymd", $wkend );
83 $thisdate = $startdate;
85 for ( $i = 0; $i < 7; $i++ ) {
86 $days[$i] = $wkstart + ( 24 * 3600 ) * $i;
87 $weekdays[$i] = weekday_short_name ( ( $i + $WEEK_START ) % 7 );
88 $header[$i] = $weekdays[$i] . "<br />" .
89 month_short_name ( date ( "m", $days[$i] ) - 1 ) .
90 " " . date ( "d", $days[$i] );
94 <div style="border-width:0px; width:99%;">
95 <a title="<?php etranslate("Previous")?>" class="prev"
96 href="view_v.php?id=<?php echo $id?>&date=<?php echo $prevdate?>">
97 <img src="leftarrow.gif" alt="<?php etranslate("Previous")?>" /></a>
99 <a title="<?php etranslate("Next")?>" class="next"
100 href="view_v.php?id=<?php echo $id?>&date=<?php echo $nextdate?>">
101 <img src="rightarrow.gif" class="prevnext" alt="<?php etranslate("Next")?>" /></a>
103 <span class="date"><?php
104 echo date_to_str ( date ( "Ymd", $wkstart ), false ) .
105 " - " .
106 date_to_str ( date ( "Ymd", $wkend ), false );
108 <span class="viewname"><?php echo $view_name ?></span>
112 // The table has names across the top and dates for rows. Since we need
113 // to spit out an entire row before we can move to the next date, we'll
114 // save up all the HTML for each cell and then print it out when we're
116 // Additionally, we only want to put at most 6 users in one table since
117 // any more than that doesn't really fit in the page.
119 // get users in this view
121 "SELECT cal_login FROM webcal_view_user WHERE cal_view_id = $id" );
122 $viewusers = array ();
125 while ( $row = dbi_fetch_row ( $res ) ) {
126 $viewusers[] = $row[0];
127 if ( $row[0] == "__all__" ) {
131 dbi_free_result ( $res );
133 $error = translate ( "Database error" ) . ": " . dbi_error ();
137 $viewusers = array ();
138 $users = get_my_users ();
139 for ( $i = 0; $i < count ( $users ); $i++ ) {
140 $viewusers[] = $users[$i]['cal_login'];
143 // Make sure this user is allowed to see all users in this view
144 // If this is a global view, it may include users that this user
145 // is not allowed to see.
146 if ( ! empty ( $user_sees_only_his_groups ) &&
147 $user_sees_only_his_groups == 'Y' ) {
148 $myusers = get_my_users ();
149 if ( ! empty ( $nonuser_enabled ) && $nonuser_enabled == "Y" ) {
150 $myusers = array_merge ( $myusers, get_nonuser_cals () );
152 $userlookup = array ();
153 for ( $i = 0; $i < count ( $myusers ); $i++ ) {
154 $userlookup[$myusers[$i]['cal_login']] = 1;
157 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
158 if ( ! empty ( $userlookup[$viewusers[$i]] ) ) {
159 $newlist[] = $viewusers[$i];
162 $viewusers = $newlist;
165 if ( count ( $viewusers ) == 0 ) {
166 // This could happen if user_sees_only_his_groups = Y and
167 // this user is not a member of any group assigned to this view
168 $error = translate ( "No users for this view" );
171 if ( ! empty ( $error ) ) {
172 echo "<h2>" . translate ( "Error" ) .
180 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
181 /* Pre-Load the repeated events for quckier access */
182 $repeated_events = read_repeated_events ( $viewusers[$i], "", $startdate );
183 $re_save[$i] = $repeated_events;
184 /* Pre-load the non-repeating events for quicker access */
185 $events = read_events ( $viewusers[$i], $startdate, $enddate );
186 $e_save[$i] = $events;
189 for ( $j = 0; $j < 7; $j += $DAYS_PER_TABLE ) {
190 // since print_date_entries is rather stupid, we can swap the event data
191 // around for users by changing what $events points to.
193 $tdw = 12; // column width percent
196 <table class="main" cellspacing="0" cellpadding="0">
197 <tr><th class="empty"> </th>
199 for ( $date = $wkstart, $h = 0;
200 date ( "Ymd", $date ) <= date ( "Ymd", $wkend );
201 $date += ( 24 * 3600 ), $h++ ) {
202 $wday = strftime ( "%w", $date );
203 $weekday = weekday_short_name ( $wday );
204 if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ) {
205 echo "<th class=\"today\" style=\"width:$tdw%;\">";
207 echo "<th style=\"width:$tdw%;\">";
209 echo $weekday . " " .
210 round ( date ( "d", $date ) ) . "</th>\n";
213 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
215 $user = $viewusers[$i];
216 user_load_variables ( $user, "temp" );
217 echo "<th class=\"row\" style=\"width:$tdw%;\">$tempfullname</th>";
218 for ( $date = $wkstart, $h = 0;
219 date ( "Ymd", $date ) <= date ( "Ymd", $wkend );
220 $date += ( 24 * 3600 ), $h++ ) {
221 $wday = strftime ( "%w", $date );
222 if ( $wday == 0 || $wday == 6 ) {
223 echo "<td class=\"weekend\" style=\"width:$tdw%;\">";
225 echo "<td style=\"width:$tdw%;\">";
227 $events = $e_save[$i];
228 $repeated_events = $re_save[$i];
229 if ( empty ( $add_link_in_views ) || $add_link_in_views != "N" ) {
230 echo html_for_add_icon ( date ( "Ymd", $date ), "", "", $user );
232 print_date_entries ( date ( "Ymd", $date ), $user, true );
237 echo "</table>\n<br /><br />\n";
242 if ( ! empty ( $eventinfo ) ) {
246 echo "<a title=\"" . translate("Generate printer-friendly version") .
247 "\" class=\"printer\" href=\"view_v.php?id=$id&date=" .
248 "$thisdate&friendly=1\" " .
249 "target=\"cal_printer_friendly\" onmouseover=\"window.status='" .
250 translate("Generate printer-friendly version") .
251 "'\">[" . translate("Printer Friendly") . "]</a>\n";