~ubuntu-branches/ubuntu/dapper/moodle/dapper-backports

« back to all changes in this revision

Viewing changes to calendar/lib.php

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2006-12-01 14:00:21 UTC
  • mfrom: (6.1.5 feisty)
  • Revision ID: james.westby@ubuntu.com-20061201140021-rivugg5tgx6mujzg
Tags: 1.6.3-1ubuntu1~dapper1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php // $Id: lib.php,v 1.125.2.4 2005/10/21 00:26:06 defacer Exp $
 
1
<?php // $Id: lib.php,v 1.142.2.4 2006/10/05 07:20:42 vyshane Exp $
2
2
 
3
3
/////////////////////////////////////////////////////////////////////////////
4
4
//                                                                         //
104
104
    list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
105
105
    $display->maxdays = calendar_days_in_month($m, $y);
106
106
 
107
 
    // We 'll keep these values as GMT here, and offset them when the time comes to query the db
108
 
    $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
109
 
    $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
 
107
    if (get_user_timezone_offset() < 99) {
 
108
        // We 'll keep these values as GMT here, and offset them when the time comes to query the db
 
109
            $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
 
110
            $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
 
111
    } else {
 
112
        // no timezone info specified
 
113
            $display->tstart = mktime(0, 0, 0, $m, 1, $y);
 
114
            $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
 
115
    }
110
116
 
111
117
    $startwday = dayofweek(1, $m, $y);
112
118
 
116
122
        $startwday += 7;
117
123
    }
118
124
 
 
125
    // TODO: THIS IS TEMPORARY CODE!
 
126
    // [pj] I was just reading through this and realized that I when writing this code I was probably
 
127
    // asking for trouble, as all these time manipulations seem to be unnecessary and a simple
 
128
    // make_timestamp would accomplish the same thing. So here goes a test:
 
129
    //$test_start = make_timestamp($y, $m, 1);
 
130
    //$test_end   = make_timestamp($y, $m, $display->maxdays, 23, 59, 59);
 
131
    //if($test_start != usertime($display->tstart) - dst_offset_on($display->tstart)) {
 
132
        //notify('Failed assertion in calendar/lib.php line 126; display->tstart = '.$display->tstart.', dst_offset = '.dst_offset_on($display->tstart).', usertime = '.usertime($display->tstart).', make_t = '.$test_start);
 
133
    //}
 
134
    //if($test_end != usertime($display->tend) - dst_offset_on($display->tend)) {
 
135
        //notify('Failed assertion in calendar/lib.php line 130; display->tend = '.$display->tend.', dst_offset = '.dst_offset_on($display->tend).', usertime = '.usertime($display->tend).', make_t = '.$test_end);
 
136
    //}
 
137
 
 
138
 
119
139
    // Get the events matching our criteria. Don't forget to offset the timestamps for the user's TZ!
120
140
    $whereclause = calendar_sql_where(
121
141
        usertime($display->tstart) - dst_offset_on($display->tstart),
147
167
    //calendar_events_by_day($events, $display->tstart, $eventsbyday, $durationbyday, $typesbyday);
148
168
    calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday);
149
169
 
150
 
    $content .= '<table class="minicalendar">'; // Begin table
 
170
    //Accessibility: added summary and <abbr> elements.
 
171
    ///global $CALENDARDAYS; appears to be broken.
 
172
    $days_title = array('sunday','monday','tuesday','wednesday','thursday','friday','saturday');
 
173
 
 
174
    $summary = get_string('calendarheading', 'calendar', userdate(make_timestamp($y, $m), get_string('strftimemonthyear')));
 
175
    $summary = get_string('tabledata', 'access', $summary);
 
176
    $content .= '<table class="minicalendar" summary="'.$summary.'">'; // Begin table
151
177
    $content .= '<tr class="weekdays">'; // Header row: day names
152
178
 
153
179
    // Print out the names of the weekdays
155
181
    for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
156
182
        // This uses the % operator to get the correct weekday no matter what shift we have
157
183
        // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
158
 
        $content .= '<th>'.get_string($days[$i % 7], 'calendar').'</th>';
 
184
        $content .= '<th scope="col"><abbr title="'. get_string($days_title[$i % 7], 'calendar') .'">'.
 
185
            get_string($days[$i % 7], 'calendar') ."</abbr></th>\n";
159
186
    }
160
187
 
161
188
    $content .= '</tr><tr>'; // End of day names; prepare for day numbers
168
195
        $content .= '<td>&nbsp;</td>'."\n";
169
196
    }
170
197
 
171
 
    $strftimetimedayshort = get_string('strftimedayshort');
172
 
 
173
198
    // Now display all the calendar
174
199
    for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
175
200
        if($dayweek > $display->maxwday) {
219
244
                }
220
245
                $popupcontent .= '<div><img height="16" width="16" src="'.$popupicon.'" style="vertical-align: middle; margin-right: 4px;" alt="'.$popupalt.'" /><a href="'.$dayhref.'">'.format_string($event->name,true).'</a></div>';
221
246
            }
222
 
 
223
 
            $popupcaption = get_string('eventsfor', 'calendar', userdate($events[$eventid]->timestart, $strftimetimedayshort));
224
 
            $popupcontent = str_replace("'", "\'", htmlspecialchars($popupcontent));
225
 
            $popup = 'onmouseover="return overlib(\''.$popupcontent.'\', CAPTION, \''.$popupcaption.'\');" onmouseout="return nd();"';
 
247
            
 
248
            //Accessibility: functionality moved to calendar_get_popup.
 
249
            if($display->thismonth && $day == $d) {
 
250
                $popup = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
 
251
            } else {
 
252
                $popup = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
 
253
            } 
226
254
 
227
255
            // Class and cell content
228
256
            if(isset($typesbyday[$day]['startglobal'])) {
257
285
        }
258
286
 
259
287
        // Special visual fx for today
 
288
        //Accessibility: hidden text for today, and popup.
260
289
        if($display->thismonth && $day == $d) {
261
290
            $class .= ' today';
 
291
            $today = get_string('today', 'calendar').' '.userdate(time(), get_string('strftimedayshort'));
 
292
                        
 
293
            if(! isset($eventsbyday[$day])) {
 
294
                $class .= ' eventnone';
 
295
                $popup = calendar_get_popup(true, false);
 
296
                $cell = '<a href="#" '.$popup.'>'.$day.'</a>';
 
297
            }
 
298
            $cell = '<span class="accesshide">'.$today.' </span>'.$cell;
262
299
        }
263
300
 
264
301
        // Just display it
279
316
    return $content;
280
317
}
281
318
 
 
319
/**
 
320
 * calendar_get_popup, called at multiple points in from calendar_get_mini.
 
321
 *        Copied and modified from calendar_get_mini.
 
322
 * @uses OverLib popup.
 
323
 * @param $is_today bool, false except when called on the current day.
 
324
 * @param $event_timestart mixed, $events[$eventid]->timestart, OR false if there are no events.
 
325
 * @param $popupcontent string.
 
326
 * @return $popup string, contains onmousover and onmouseout events. 
 
327
 */
 
328
function calendar_get_popup($is_today, $event_timestart, $popupcontent='') {
 
329
    $popupcaption = '';
 
330
    if($is_today) {
 
331
        $popupcaption = get_string('today', 'calendar').' ';
 
332
    }
 
333
    if (false === $event_timestart) {
 
334
        $popupcaption .= userdate(time(), get_string('strftimedayshort'));
 
335
        $popupcontent = get_string('eventnone', 'calendar');
 
336
 
 
337
    } else {
 
338
        $popupcaption .= get_string('eventsfor', 'calendar', userdate($event_timestart, get_string('strftimedayshort')));
 
339
    }
 
340
    $popupcontent = str_replace("'", "\'", htmlspecialchars($popupcontent));
 
341
    $popupcaption = str_replace("'", "\'", htmlspecialchars($popupcaption)); 
 
342
    $popup = 'onmouseover="return overlib(\''.$popupcontent.'\', CAPTION, \''.$popupcaption.'\');" onmouseout="return nd();"';
 
343
    return $popup;
 
344
}
 
345
 
282
346
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
283
347
    global $CFG;
284
348
 
327
391
    }
328
392
 
329
393
    if($events !== false) {
 
394
 
330
395
        foreach($events as $event) {
331
396
 
332
397
            if($processed >= $display->maxevents) {
555
620
    $data['m'] = $date['mon'];
556
621
    $data['y'] = $date['year'];
557
622
 
 
623
    //Accessibility: calendar block controls, replaced <table> with <div>.
 
624
    $nexttext = '<img src="'. $CFG->pixpath .'/a/r_next.gif" alt="'.get_string('monthnext','access').'" class="resize" />';
 
625
    $prevtext = '<img src="'. $CFG->pixpath .'/a/r_previous.gif" alt="'.get_string('monthprev','access').'" class="resize" />';
 
626
 
558
627
    switch($type) {
559
628
        case 'frontpage':
560
629
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
561
630
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
562
 
            $nextlink = calendar_get_link_tag('&gt;&gt;', 'index.php?', 0, $nextmonth, $nextyear);
563
 
            $prevlink = calendar_get_link_tag('&lt;&lt;', 'index.php?', 0, $prevmonth, $prevyear);
564
 
            $content .= '<table class="calendar-controls"><tr>';
565
 
            $content .= '<td class="previous">'.$prevlink."</td>\n";
566
 
            $content .= '<td class="current"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear')).'</a></td>';
567
 
            $content .= '<td class="next">'.$nextlink."</td>\n";
568
 
            $content .= '</tr></table>';
 
631
            $nextlink = calendar_get_link_tag($nexttext, 'index.php?', 0, $nextmonth, $nextyear);
 
632
            $prevlink = calendar_get_link_tag($prevtext, 'index.php?', 0, $prevmonth, $prevyear);
 
633
            $content .= '<div class="calendar-controls">';
 
634
            $content .= '<span class="previous" title="'.get_string('monthprev','access').'">'.$prevlink."</span>\n";
 
635
            $content .= '<span class="hide"> | </span><span class="current"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear')).'</a></span>';
 
636
            $content .= '<span class="hide"> | </span><span class="next" title="'.get_string('monthnext','access').'">'.$nextlink."</span>\n";
 
637
            $content .= "<span class=\"clearer\"></span></div>\n";
569
638
        break;
570
639
        case 'course':
571
640
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
572
641
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
573
 
            $nextlink = calendar_get_link_tag('&gt;&gt;', 'view.php?id='.$data['id'].'&amp;', 0, $nextmonth, $nextyear);
574
 
            $prevlink = calendar_get_link_tag('&lt;&lt;', 'view.php?id='.$data['id'].'&amp;', 0, $prevmonth, $prevyear);
575
 
            $content .= '<table class="calendar-controls"><tr>';
576
 
            $content .= '<td class="previous">'.$prevlink."</td>\n";
577
 
            $content .= '<td class="current"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;course='.$data['id'].'&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear')).'</a></td>';
578
 
            $content .= '<td class="next">'.$nextlink."</td>\n";
579
 
            $content .= '</tr></table>';
 
642
            $nextlink = calendar_get_link_tag($nexttext, 'view.php?id='.$data['id'].'&amp;', 0, $nextmonth, $nextyear);
 
643
            $prevlink = calendar_get_link_tag($prevtext, 'view.php?id='.$data['id'].'&amp;', 0, $prevmonth, $prevyear);
 
644
            $content .= '<div class="calendar-controls">';
 
645
            $content .= '<span class="previous" title="'.get_string('monthprev','access').'">'.$prevlink."</span>\n";
 
646
            $content .= '<span class="hide"> | </span><span class="current"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month&amp;course='.$data['id'].'&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear')).'</a></span>';
 
647
            $content .= '<span class="hide"> | </span><span class="next" title="'.get_string('monthnext','access').'">'.$nextlink."</span>\n";
 
648
            $content .= "<span class=\"clearer\"></span></div>\n";
580
649
        break;
581
650
        case 'upcoming':
582
651
            $content .= '<div style="text-align: center;"><a href="'.CALENDAR_URL.'view.php?view=upcoming">'.userdate($time, get_string('strftimemonthyear'))."</a></div>\n";
589
658
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
590
659
            $prevdate = make_timestamp($prevyear, $prevmonth, 1);
591
660
            $nextdate = make_timestamp($nextyear, $nextmonth, 1);
592
 
            $content .= '<table class="calendar-controls"><tr>';
593
 
            $content .= '<td class="previous"><a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $prevmonth, $prevyear).'">&lt;&lt; '.userdate($prevdate, get_string('strftimemonthyear')).'</a></td>';
594
 
            $content .= '<td class="current">'.userdate($time, get_string('strftimemonthyear'))."</td>\n";
595
 
            $content .= '<td class="next"><a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $nextmonth, $nextyear).'">'.userdate($nextdate, get_string('strftimemonthyear'))." &gt;&gt;</a></td>\n";
596
 
            $content .= "</tr></table>\n";
 
661
            $content .= '<div class="calendar-controls">';
 
662
            $content .= '<span class="previous"><a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $prevmonth, $prevyear).'">&lt; '.userdate($prevdate, get_string('strftimemonthyear')).'</a></span>';
 
663
            $content .= '<span class="hide"> | </span><span class="current">'.userdate($time, get_string('strftimemonthyear'))."</span>\n";
 
664
            $content .= '<span class="hide"> | </span><span class="next"><a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $nextmonth, $nextyear).'">'.userdate($nextdate, get_string('strftimemonthyear'))." &gt;</a></span>\n";
 
665
            $content .= "<span class=\"clearer\"></span></div>\n";
597
666
        break;
598
667
        case 'day':
599
668
            $data['d'] = $date['mday']; // Just for convenience
601
670
            $nextdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] + 1));
602
671
            $prevname = calendar_wday_name($CALENDARDAYS[$prevdate['wday']]);
603
672
            $nextname = calendar_wday_name($CALENDARDAYS[$nextdate['wday']]);
604
 
            $content .= '<table class="calendar-controls"><tr>';
605
 
            $content .= '<td class="previous"><a href="'.calendar_get_link_href('view.php?view=day&amp;', $prevdate['mday'], $prevdate['mon'], $prevdate['year']).'">&lt;&lt; '.$prevname."</a></td>\n";
 
673
            $content .= '<div class="calendar-controls">';
 
674
            $content .= '<span class="previous"><a href="'.calendar_get_link_href('view.php?view=day&amp;', $prevdate['mday'], $prevdate['mon'], $prevdate['year']).'">&lt; '.$prevname."</a></span>\n";
606
675
 
607
676
            // Get the format string
608
677
            $text = get_string('strftimedaydate');
614
683
            // Replace with actual values and lose any day leading zero
615
684
            $text = userdate($time, $text);
616
685
            // Print the actual thing
617
 
            $content .= '<td class="current">'.$text.'</td>';
 
686
            $content .= '<span class="hide"> | </span><span class="current">'.$text.'</span>';
618
687
 
619
 
            $content .= '<td class="next"><a href="'.calendar_get_link_href('view.php?view=day&amp;', $nextdate['mday'], $nextdate['mon'], $nextdate['year']).'">'.$nextname." &gt;&gt;</a></td>\n";
620
 
            $content .= '</tr></table>';
 
688
            $content .= '<span class="hide"> | </span><span class="next"><a href="'.calendar_get_link_href('view.php?view=day&amp;', $nextdate['mday'], $nextdate['mon'], $nextdate['year']).'">'.$nextname." &gt;</a></span>\n";
 
689
            $content .= "<span class=\"clearer\"></span></div>\n";
621
690
        break;
622
691
    }
623
692
    return $content;
628
697
 
629
698
    $groupevents = true;
630
699
    $getvars = '';
 
700
   
 
701
    $id = optional_param( 'id',0,PARAM_INT );
631
702
 
632
703
    switch($type) {
633
704
        case 'event':
637
708
            $getvars = '&amp;from='.$type;
638
709
        break;
639
710
        case 'course':
640
 
            if (isset($_GET['id'])) {
641
 
                $getvars = '&amp;from=course&amp;id='.$_GET['id'];
 
711
            if ($id > 0) {
 
712
                $getvars = '&amp;from=course&amp;id='.$id;
642
713
            } else {
643
714
                $getvars = '&amp;from=course';
644
715
            }
790
861
            continue;
791
862
        }
792
863
        $events[$i] = calendar_add_event_metadata($events[$i]);
793
 
        $content .= '<div class="event">'.$events[$i]->icon.' ';
 
864
        $content .= '<div class="event"><span class="icon c0">'.$events[$i]->icon.'</span> ';
794
865
        if (!empty($events[$i]->referer)) {
795
866
            // That's an activity event, so let's provide the hyperlink
796
867
            $content .= $events[$i]->referer;
1023
1094
    else {
1024
1095
        $courses = false;
1025
1096
    }
 
1097
   //BUG 6130 clean $courses array as SESSION has bad entries. 
 
1098
   foreach ($courses as $index => $value) {
 
1099
       if (empty($value)) unset($courses[$index]);
 
1100
   }
1026
1101
 
1027
1102
    if($SESSION->cal_show_user || $ignorefilters) {
1028
1103
        // This doesn't work for arrays yet (maybe someday it will)
1066
1141
 
1067
1142
                // Otherwise (not editing teacher) show events from the group he is a member of
1068
1143
                else if(isset($USER->groupmember[$courseid])) {
1069
 
                    $grouparray[] = $USER->groupmember[$courseid];
 
1144
                    //changed to 2D array
 
1145
                    foreach ($USER->groupmember[$courseid] as $groupid){
 
1146
                        $grouparray[] = $groupid;
 
1147
                    }
1070
1148
                }
1071
1149
            }
1072
1150
            if(empty($grouparray)) {