3 * $Id: view_m.php,v 1.41 2005/03/06 23:26:35 umcesrjones Exp $
6 * Display a month view with users side by side.
9 * id (*) - specify view id in webcal_view table
10 * date - specify the starting date of the view.
11 * If not specified, current date will be used.
12 * friendly - if set to 1, then page does not include links or
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 'includes/init.php';
30 if ( $allow_view_other == "N" && ! $is_admin ) {
32 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 ( $view_name == "" ) {
50 $error = translate ( "You are not authorized" );
53 $INC = array('js/popups.php');
58 $next = mktime ( 3, 0, 0, $thismonth + 1, 1, $thisyear );
59 $nextyear = date ( "Y", $next );
60 $nextmonth = date ( "m", $next );
61 $nextdate = sprintf ( "%04d%02d01", $nextyear, $nextmonth );
63 $prev = mktime ( 3, 0, 0, $thismonth - 1, 1, $thisyear );
64 $prevyear = date ( "Y", $prev );
65 $prevmonth = date ( "m", $prev );
66 $prevdate = sprintf ( "%04d%02d01", $prevyear, $prevmonth );
68 $startdate = sprintf ( "%04d%02d01", $thisyear, $thismonth );
69 $enddate = sprintf ( "%04d%02d31", $thisyear, $thismonth );
70 $monthstart = mktime ( 3, 0, 0, $thismonth, 1, $thisyear );
71 $monthend = mktime ( 3, 0, 0, $thismonth + 1, 0, $thisyear );
72 $thisdate = $startdate;
75 <div style="border-width:0px; width:99%;">
76 <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>
77 <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>
79 <span class="date"><?php
80 printf ( "%s %d", month_name ( $thismonth - 1 ), $thisyear );
82 <span class="viewname"><?php echo $view_name ?></span>
87 // The table has names across the top and dates for rows. Since we need
88 // to spit out an entire row before we can move to the next date, we'll
89 // save up all the HTML for each cell and then print it out when we're
91 // Additionally, we only want to put at most 6 users in one table since
92 // any more than that doesn't really fit in the page.
94 // get users in this view
96 "SELECT cal_login FROM webcal_view_user WHERE cal_view_id = $id" );
97 $viewusers = array ();
100 while ( $row = dbi_fetch_row ( $res ) ) {
101 $viewusers[] = $row[0];
102 if ( $row[0] == "__all__" ) {
106 dbi_free_result ( $res );
108 $error = translate ( "Database error" ) . ": " . dbi_error ();
112 $viewusers = array ();
113 $users = get_my_users ();
114 for ( $i = 0; $i < count ( $users ); $i++ ) {
115 $viewusers[] = $users[$i]['cal_login'];
118 // Make sure this user is allowed to see all users in this view
119 // If this is a global view, it may include users that this user
120 // is not allowed to see.
121 if ( ! empty ( $user_sees_only_his_groups ) &&
122 $user_sees_only_his_groups == 'Y' ) {
123 $myusers = get_my_users ();
124 if ( ! empty ( $nonuser_enabled ) && $nonuser_enabled == "Y" ) {
125 $myusers = array_merge ( $myusers, get_nonuser_cals () );
127 $userlookup = array();
128 for ( $i = 0; $i < count ( $myusers ); $i++ ) {
129 $userlookup[$myusers[$i]['cal_login']] = 1;
132 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
133 if ( ! empty ( $userlookup[$viewusers[$i]] ) ) {
134 $newlist[] = $viewusers[$i];
137 $viewusers = $newlist;
140 if ( count ( $viewusers ) == 0 ) {
141 // This could happen if user_sees_only_his_groups = Y and
142 // this user is not a member of any group assigned to this view
143 $error = translate ( "No users for this view" );
146 if ( ! empty ( $error ) ) {
147 echo "<h2>" . translate ( "Error" ) .
155 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
156 /* Pre-Load the repeated events for quckier access */
157 $repeated_events = read_repeated_events ( $viewusers[$i], "", $startdate );
158 $re_save[$i] = $repeated_events;
159 /* Pre-load the non-repeating events for quicker access */
160 $events = read_events ( $viewusers[$i], $startdate, $enddate );
161 $e_save[$i] = $events;
164 for ( $j = 0; $j < count ($viewusers); $j += $USERS_PER_TABLE ) {
165 // since print_date_entries is rather stupid, we can swap the event data
166 // around for users by changing what $events points to.
168 // Calculate width of columns in this table.
169 $num_left = count ($viewusers) - $j;
170 if ($num_left > $USERS_PER_TABLE) {
171 $num_left = $USERS_PER_TABLE;
174 if ($num_left < $USERS_PER_TABLE) {
175 $tdw = (int) (90 / $num_left);
177 $tdw = (int) (90 / $USERS_PER_TABLE);
185 <table class="main" cellspacing="0" cellpadding="0">
186 <tr><th class="empty"> </th>
188 // $j points to start of this table/row
189 // $k is counter starting at 0
190 // $i starts at table start and goes until end of this table/row.
191 for ( $i = $j, $k = 0;
192 $i < count ($viewusers) && $k < $USERS_PER_TABLE; $i++, $k++ ) {
193 $user = $viewusers[$i];
194 user_load_variables ($user, "temp");
195 echo "<th style=\"width:$tdw%;\">$tempfullname</th>\n";
199 for ( $date = $monthstart; date ("Ymd", $date) <= date ("Ymd", $monthend);
200 $date += (24 * 3600), $wday++ ) {
201 $wday = strftime ("%w", $date);
202 $weekday = weekday_short_name ($wday);
204 if ( date ("Ymd", $date) == date ("Ymd", $today) ) {
205 echo " class=\"today\">";
207 if ($wday == 0 || $wday == 6) {
208 echo " class=\"weekend\">";
210 echo " class=\"row\">";
213 //non-breaking space below keeps event from wrapping prematurely
214 echo $weekday . " " .
215 round ( date ("d", $date) ) . "</th>\n";
216 for ( $i = $j, $k = 0;
217 $i < count ($viewusers) && $k < $USERS_PER_TABLE; $i++, $k++ ) {
218 $user = $viewusers[$i];
219 $events = $e_save[$i];
220 $repeated_events = $re_save[$i];
221 if ( date ("Ymd", $date) == date ("Ymd", $today) ) {
222 echo "<td class=\"today\"";
224 if ($wday == 0 || $wday == 6) {
225 echo "<td class=\"weekend\"";
230 echo " style=\"width:$tdw%;\">";
231 //echo date ( "D, m-d-Y H:i:s", $date ) . "<br />";
232 if ( empty ($add_link_in_views) || $add_link_in_views != "N" ) {
233 echo html_for_add_icon ( date ("Ymd", $date), "", "", $user );
235 print_date_entries ( date ("Ymd", $date), $user, true );
241 echo "</table>\n<br /><br />\n";
246 if ( ! empty ( $eventinfo ) ) {
251 translate("Generate printer-friendly version") . "\" class=\"printer\" " .
252 "href=\"view_m.php?id=$id&date=$thisdate&friendly=1\" " .
253 "target=\"cal_printer_friendly\" onmouseover=\"window.status='" .
254 translate("Generate printer-friendly version") . "'\">[" .
255 translate("Printer Friendly") . "]</a>\n";