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).
27 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 + 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 if ( ! empty ( $bold_days_in_year ) && $bold_days_in_year == 'Y' ) {
70 $startdate = sprintf ( "%04d%02d01", $prevyear, $prevmonth );
71 $enddate = sprintf ( "%04d%02d31", $nextyear, $nextmonth );
74 $startdate = sprintf ( "%04d%02d01", $thisyear, $thismonth );
75 $enddate = sprintf ( "%04d%02d31", $thisyear, $thismonth );
78 $monthstart = mktime ( 3, 0, 0, $thismonth, 1, $thisyear );
79 $monthend = mktime ( 3, 0, 0, $thismonth + 1, 0, $thisyear );
81 $thisdate = $startdate;
83 // get users in this view
85 "SELECT cal_login FROM webcal_view_user WHERE cal_view_id = $id" );
86 $viewusers = array ();
89 while ( $row = dbi_fetch_row ( $res ) ) {
90 $viewusers[] = $row[0];
91 if ( $row[0] == "__all__" ) {
95 dbi_free_result ( $res );
97 $error = translate ( "Database error" ) . ": " . dbi_error ();
100 $viewusers = array ();
101 $users = get_my_users ();
102 for ( $i = 0; $i < count ( $users ); $i++ ) {
103 $viewusers[] = $users[$i]['cal_login'];
106 // Make sure this user is allowed to see all users in this view
107 // If this is a global view, it may include users that this user
108 // is not allowed to see.
109 if ( ! empty ( $user_sees_only_his_groups ) &&
110 $user_sees_only_his_groups == 'Y' ) {
111 $myusers = get_my_users ();
112 if ( ! empty ( $nonuser_enabled ) && $nonuser_enabled == "Y" ) {
113 $myusers = array_merge ( $myusers, get_nonuser_cals () );
115 $userlookup = array();
116 for ( $i = 0; $i < count ( $myusers ); $i++ ) {
117 $userlookup[$myusers[$i]['cal_login']] = 1;
120 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
121 if ( ! empty ( $userlookup[$viewusers[$i]] ) ) {
122 $newlist[] = $viewusers[$i];
125 $viewusers = $newlist;
128 if ( count ( $viewusers ) == 0 ) {
129 // This could happen if user_sees_only_his_groups = Y and
130 // this user is not a member of any group assigned to this view
131 $error = translate ( "No users for this view" );
134 if ( ! empty ( $error ) ) {
135 echo "<h2>" . translate ( "Error" ) .
143 for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
144 /* Pre-Load the repeated events for quckier access */
145 $repeated_events = read_repeated_events ( $viewusers[$i], "", $startdate );
146 $re_save = array_merge($re_save, $repeated_events);
147 /* Pre-load the non-repeating events for quicker access */
148 $events = read_events ( $viewusers[$i], $startdate, $enddate );
149 $e_save = array_merge($e_save, $events);
152 $repeated_events = array ();
154 for ( $i = 0; $i < count ( $e_save ); $i++ ) {
156 for ( $j = 0; $j < count ( $events ) && $should_add; $j++ ) {
157 if ( $e_save[$i]['cal_id'] == $events[$j]['cal_id'] ) {
162 array_push ( $events, $e_save[$i] );
166 for ( $i = 0; $i < count ( $re_save ); $i++ ) {
168 for ( $j = 0; $j < count ( $repeated_events ) && $should_add; $j++ ) {
169 if ( $re_save[$i]['cal_id'] == $repeated_events[$j]['cal_id'] ) {
174 array_push ( $repeated_events, $re_save[$i] );
178 display_small_month ( $prevmonth, $prevyear, true, true, "prevmonth",
179 "view_l.php?id=$id&" );
180 display_small_month ( $nextmonth, $nextyear, true, true, "nextmonth",
181 "view_l.php?id=$id&" );
185 <span class="date"><br /><?php
186 echo date_to_str ( sprintf ( "%04d%02d01", $thisyear, $thismonth ),
187 $DATE_FORMAT_MY, false, false );
189 <span class="viewname"><br /><?php echo $view_name; ?></span></div>
190 <br /><br /><br /><br />
192 <table class="main" style="clear:both;" cellspacing="0" cellpadding="0">
194 <?php if ( $WEEK_START == 0 ) { ?>
195 <th class="weekend"><?php etranslate("Sun")?></th>
197 <th><?php etranslate("Mon")?></th>
198 <th><?php etranslate("Tue")?></th>
199 <th><?php etranslate("Wed")?></th>
200 <th><?php etranslate("Thu")?></th>
201 <th><?php etranslate("Fri")?></th>
202 <th class="weekend"><?php etranslate("Sat")?></th>
203 <?php if ( $WEEK_START == 1 ) { ?>
204 <th class="weekend"><?php etranslate("Sun")?></th>
208 // We add 2 hours on to the time so that the switch to DST doesn't
209 // throw us off. So, all our dates are 2AM for that day.
210 //$sun = get_sunday_before ( $thisyear, $thismonth, 1 );
211 if ( $WEEK_START == 1 ) {
212 $wkstart = get_monday_before ( $thisyear, $thismonth, 1 );
214 $wkstart = get_sunday_before ( $thisyear, $thismonth, 1 );
216 // generate values for first day and last day of month
217 $monthstart = mktime ( 3, 0, 0, $thismonth, 1, $thisyear );
218 $monthend = mktime ( 3, 0, 0, $thismonth + 1, 0, $thisyear );
221 //echo "<br />sun = " . date ( "D, m-d-Y", $sun ) . "<br />";
222 //echo "<br />monthstart = " . date ( "D, m-d-Y", $monthstart ) . "<br />";
223 //echo "<br />monthend = " . date ( "D, m-d-Y", $monthend ) . "<br />";
225 //NOTE: if you make HTML changes to this table, make the same changes
226 //to the example table in pref.php.
227 for ( $i = $wkstart; date ( "Ymd", $i ) <= date ( "Ymd", $monthend );
228 $i += ( 24 * 3600 * 7 ) ) {
230 for ( $j = 0; $j < 7; $j++ ) {
231 $date = $i + ( $j * 24 * 3600 );
232 if ( date ( "Ymd", $date ) >= date ( "Ymd", $monthstart ) &&
233 date ( "Ymd", $date ) <= date ( "Ymd", $monthend ) ) {
234 $thiswday = date ( "w", $date );
235 $is_weekend = ( $thiswday == 0 || $thiswday == 6 );
236 if ( empty ( $WEEKENDBG ) ) $is_weekend = false;
239 if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ) {
243 if ( strlen ( $class ) ) $class .= " ";
246 if ( strlen ( $class ) ) echo " class=\"$class\"";
248 //echo date ( "D, m-d-Y H:i:s", $date ) . "<br />";
249 print_date_entries ( date ( "Ymd", $date ),
250 ( ! empty ( $user ) ) ? $user : $login, false );
253 print "<td> </td>\n";
262 if ( ! empty ( $eventinfo ) ) {
266 display_unapproved_events ( ( $is_assistant ||
267 $is_nonuser_admin ? $user : $login ) );
272 etranslate("Generate printer-friendly version")
273 ?>" class="printer" href="view_l.php?id=<?php echo $id?>&<?php
275 echo "year=$thisyear&month=$thismonth&";
277 if ( ! empty ( $user ) ) echo "user=$user&";
278 if ( ! empty ( $cat_id ) ) echo "cat_id=$cat_id&";
279 ?>friendly=1" target="cal_printer_friendly" onmouseover="window.status = '<?php
280 etranslate("Generate printer-friendly version")?>'">[<?php
281 etranslate("Printer Friendly")?>]</a>
283 <?php print_trailer ();?>