4 * Display a month view with users side by side.
7 * id (*) - specify view id in webcal_view table
8 * date - specify the starting date of the view.
9 * If not specified, current date will be used.
10 * friendly - if set to 1, then page does not include links or
15 * Must have "allow view others" enabled ($allow_view_other) in
16 * System Settings unless the user is an admin user ($is_admin).
17 * If the view is not global, the user must be owner of the view.
18 * If the view is global, then and user_sees_only_his_groups is
19 * enabled, then we remove users not in this user's groups
20 * (except for nonuser calendars... which we allow regardless of group).
22 include_once $gfplugins.'webcalendar/www/includes/init.php';
28 if ( $allow_view_other == "N" && ! $is_admin ) {
30 send_to_preferred_view ();
33 if ( empty ( $id ) ) {
34 do_redirect ( "views.php" );
37 // Find view name in $views[]
39 for ( $i = 0; $i < count ( $views ); $i++ ) {
40 if ( $views[$i]['cal_view_id'] == $id ) {
41 $view_name = $views[$i]['cal_name'];
45 // If view_name not found, then the specified view id does not
46 // belong to current user.
47 if ( $view_name == "" ) {
48 $error = translate ( "You are not authorized" );
51 $INC = array('js/popups.php');
56 $next = mktime ( 3, 0, 0, $thismonth + 1, 1, $thisyear );
57 $nextyear = date ( "Y", $next );
58 $nextmonth = date ( "m", $next );
59 $nextdate = sprintf ( "%04d%02d01", $nextyear, $nextmonth );
61 $prev = mktime ( 3, 0, 0, $thismonth - 1, 1, $thisyear );
62 $prevyear = date ( "Y", $prev );
63 $prevmonth = date ( "m", $prev );
64 $prevdate = sprintf ( "%04d%02d01", $prevyear, $prevmonth );
66 $startdate = sprintf ( "%04d%02d01", $thisyear, $thismonth );
67 $enddate = sprintf ( "%04d%02d31", $thisyear, $thismonth );
68 $monthstart = mktime ( 3, 0, 0, $thismonth, 1, $thisyear );
69 $monthend = mktime ( 3, 0, 0, $thismonth + 1, 0, $thisyear );
70 $thisdate = $startdate;
73 <div style="border-width:0px; width:99%;">
74 <a title="<?php etranslate("Previous")?>" class="prev" href="view_m.php?id=<?php echo $id?>&date=<?php echo $prevdate?>"><img src="leftarrow.gif" alt="<?php etranslate("Previous")?>" /></a>
75 <a title="<?php etranslate("Next")?>" class="next" href="view_m.php?id=<?php echo $id?>&date=<?php echo $nextdate?>"><img src="rightarrow.gif" alt="<?php etranslate("Next")?>" /></a>
77 <span class="date"><?php
78 printf ( "%s %d", month_name ( $thismonth - 1 ), $thisyear );
80 <span class="viewname"><?php echo $view_name ?></span>
85 // The table has names across the top and dates for rows. Since we need
86 // to spit out an entire row before we can move to the next date, we'll
87 // save up all the HTML for each cell and then print it out when we're
89 // Additionally, we only want to put at most 6 users in one table since
90 // any more than that doesn't really fit in the page.
92 // get users in this view
94 "SELECT cal_login FROM webcal_view_user WHERE cal_view_id = $id" );
95 $viewusers = array ();
98 while ( $row = dbi_fetch_row ( $res ) ) {
99 $viewusers[] = $row[0];
100 if ( $row[0] == "__all__" ) {
104 dbi_free_result ( $res );
106 $error = translate ( "Database error" ) . ": " . dbi_error ();
110 $viewusers = array ();
111 $users = get_my_users ();
112 for ( $i = 0; $i < count ( $users ); $i++ ) {
113 $viewusers[] = $users[$i]['cal_login'];
116 // Make sure this user is allowed to see all users in this view
117 // If this is a global view, it may include users that this user
118 // is not allowed to see.
119 if ( ! empty ( $user_sees_only_his_groups ) &&
120 $user_sees_only_his_groups == 'Y' ) {
121 $myusers = get_my_users ();
122 if ( ! empty ( $nonuser_enabled ) && $nonuser_enabled == "Y" ) {
123 $myusers = array_merge ( $myusers, get_nonuser_cals () );
125 $userlookup = array();
126 for ( $i = 0; $i < count ( $myusers ); $i++ ) {
127 $userlookup[$myusers[$i]['cal_login']] = 1;
130 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
131 if ( ! empty ( $userlookup[$viewusers[$i]] ) ) {
132 $newlist[] = $viewusers[$i];
135 $viewusers = $newlist;
138 if ( count ( $viewusers ) == 0 ) {
139 // This could happen if user_sees_only_his_groups = Y and
140 // this user is not a member of any group assigned to this view
141 $error = translate ( "No users for this view" );
144 if ( ! empty ( $error ) ) {
145 echo "<h2>" . translate ( "Error" ) .
153 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
154 /* Pre-Load the repeated events for quckier access */
155 $repeated_events = read_repeated_events ( $viewusers[$i], "", $startdate );
156 $re_save[$i] = $repeated_events;
157 /* Pre-load the non-repeating events for quicker access */
158 $events = read_events ( $viewusers[$i], $startdate, $enddate );
159 $e_save[$i] = $events;
162 for ( $j = 0; $j < count ($viewusers); $j += $USERS_PER_TABLE ) {
163 // since print_date_entries is rather stupid, we can swap the event data
164 // around for users by changing what $events points to.
166 // Calculate width of columns in this table.
167 $num_left = count ($viewusers) - $j;
168 if ($num_left > $USERS_PER_TABLE) {
169 $num_left = $USERS_PER_TABLE;
172 if ($num_left < $USERS_PER_TABLE) {
173 $tdw = (int) (90 / $num_left);
175 $tdw = (int) (90 / $USERS_PER_TABLE);
183 <table class="main" cellspacing="0" cellpadding="0">
184 <tr><th class="empty"> </th>
186 // $j points to start of this table/row
187 // $k is counter starting at 0
188 // $i starts at table start and goes until end of this table/row.
189 for ( $i = $j, $k = 0;
190 $i < count ($viewusers) && $k < $USERS_PER_TABLE; $i++, $k++ ) {
191 $user = $viewusers[$i];
192 user_load_variables ($user, "temp");
193 echo "<th style=\"width:$tdw%;\">$tempfullname</th>\n";
197 for ( $date = $monthstart; date ("Ymd", $date) <= date ("Ymd", $monthend);
198 $date += (24 * 3600), $wday++ ) {
199 $wday = strftime ("%w", $date);
200 $weekday = weekday_short_name ($wday);
202 if ( date ("Ymd", $date) == date ("Ymd", $today) ) {
203 echo " class=\"today\">";
205 if ($wday == 0 || $wday == 6) {
206 echo " class=\"weekend\">";
208 echo " class=\"row\">";
211 //non-breaking space below keeps event from wrapping prematurely
212 echo $weekday . " " .
213 round ( date ("d", $date) ) . "</th>\n";
214 for ( $i = $j, $k = 0;
215 $i < count ($viewusers) && $k < $USERS_PER_TABLE; $i++, $k++ ) {
216 $user = $viewusers[$i];
217 $events = $e_save[$i];
218 $repeated_events = $re_save[$i];
219 if ( date ("Ymd", $date) == date ("Ymd", $today) ) {
220 echo "<td class=\"today\"";
222 if ($wday == 0 || $wday == 6) {
223 echo "<td class=\"weekend\"";
228 echo " style=\"width:$tdw%;\">";
229 //echo date ( "D, m-d-Y H:i:s", $date ) . "<br />";
230 if ( empty ($add_link_in_views) || $add_link_in_views != "N" ) {
231 echo html_for_add_icon ( date ("Ymd", $date), "", "", $user );
233 print_date_entries ( date ("Ymd", $date), $user, true );
239 echo "</table>\n<br /><br />\n";
244 if ( ! empty ( $eventinfo ) ) {
249 translate("Generate printer-friendly version") . "\" class=\"printer\" " .
250 "href=\"view_m.php?id=$id&date=$thisdate&friendly=1\" " .
251 "target=\"cal_printer_friendly\" onmouseover=\"window.status='" .
252 translate("Generate printer-friendly version") . "'\">[" .
253 translate("Printer Friendly") . "]</a>\n";