/**
  * Test all the core functions that use the calendar type system.
  *
  * @param string $type the calendar type we want to test
  */
 private function core_functions_test($type)
 {
     $this->set_calendar_type($type);
     // Get the calendar.
     $calendar = \core_calendar\type_factory::get_calendar_instance();
     // Test the userdate function.
     $this->assertEquals($calendar->timestamp_to_date_string($this->user->timecreated, '', 99, true, true), userdate($this->user->timecreated));
     // Test the calendar/lib.php functions.
     $this->assertEquals($calendar->get_weekdays(), calendar_get_days());
     $this->assertEquals($calendar->get_starting_weekday(), calendar_get_starting_weekday());
     $this->assertEquals($calendar->get_num_days_in_month('1986', '9'), calendar_days_in_month('9', '1986'));
     $this->assertEquals($calendar->get_next_month('1986', '9'), calendar_add_month('9', '1986'));
     $this->assertEquals($calendar->get_prev_month('1986', '9'), calendar_sub_month('9', '1986'));
     // Test the lib/moodle.php functions.
     $this->assertEquals($calendar->get_num_days_in_month('1986', '9'), days_in_month('9', '1986'));
     $this->assertEquals($calendar->get_weekday('1986', '9', '16'), dayofweek('16', '9', '1986'));
 }
예제 #2
0
파일: lib.php 프로젝트: kai707/ITSA-backup
function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$durationbyday, &$typesbyday, &$courses)
{
    $eventsbyday = array();
    $typesbyday = array();
    $durationbyday = array();
    if ($events === false) {
        return;
    }
    foreach ($events as $event) {
        $startdate = usergetdate($event->timestart);
        // Set end date = start date if no duration
        if ($event->timeduration) {
            $enddate = usergetdate($event->timestart + $event->timeduration - 1);
        } else {
            $enddate = $startdate;
        }
        // Simple arithmetic: $year * 13 + $month is a distinct integer for each distinct ($year, $month) pair
        if (!($startdate['year'] * 13 + $startdate['mon'] <= $year * 13 + $month) && $enddate['year'] * 13 + $enddate['mon'] >= $year * 13 + $month) {
            // Out of bounds
            continue;
        }
        $eventdaystart = intval($startdate['mday']);
        if ($startdate['mon'] == $month && $startdate['year'] == $year) {
            // Give the event to its day
            $eventsbyday[$eventdaystart][] = $event->id;
            // Mark the day as having such an event
            if ($event->courseid == SITEID && $event->groupid == 0) {
                $typesbyday[$eventdaystart]['startglobal'] = true;
                // Set event class for global event
                $events[$event->id]->class = 'event_global';
            } else {
                if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
                    $typesbyday[$eventdaystart]['startcourse'] = true;
                    // Set event class for course event
                    $events[$event->id]->class = 'event_course';
                } else {
                    if ($event->groupid) {
                        $typesbyday[$eventdaystart]['startgroup'] = true;
                        // Set event class for group event
                        $events[$event->id]->class = 'event_group';
                    } else {
                        if ($event->userid) {
                            $typesbyday[$eventdaystart]['startuser'] = true;
                            // Set event class for user event
                            $events[$event->id]->class = 'event_user';
                        }
                    }
                }
            }
        }
        if ($event->timeduration == 0) {
            // Proceed with the next
            continue;
        }
        // The event starts on $month $year or before. So...
        $lowerbound = $startdate['mon'] == $month && $startdate['year'] == $year ? intval($startdate['mday']) : 0;
        // Also, it ends on $month $year or later...
        $upperbound = $enddate['mon'] == $month && $enddate['year'] == $year ? intval($enddate['mday']) : calendar_days_in_month($month, $year);
        // Mark all days between $lowerbound and $upperbound (inclusive) as duration
        for ($i = $lowerbound + 1; $i <= $upperbound; ++$i) {
            $durationbyday[$i][] = $event->id;
            if ($event->courseid == SITEID && $event->groupid == 0) {
                $typesbyday[$i]['durationglobal'] = true;
            } else {
                if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) {
                    $typesbyday[$i]['durationcourse'] = true;
                } else {
                    if ($event->groupid) {
                        $typesbyday[$i]['durationgroup'] = true;
                    } else {
                        if ($event->userid) {
                            $typesbyday[$i]['durationuser'] = true;
                        }
                    }
                }
            }
        }
    }
    return;
}
예제 #3
0
파일: view.php 프로젝트: nadavkav/MoodleTAO
function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid)
{
    global $CFG, $SESSION, $USER, $CALENDARDAYS;
    global $day, $mon, $yr;
    $getvars = 'from=month&amp;cal_d=' . $day . '&amp;cal_m=' . $mon . '&amp;cal_y=' . $yr;
    // For filtering
    $display =& new stdClass();
    $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
    $display->maxwday = $display->minwday + 6;
    if (!empty($m) && !empty($y)) {
        $thisdate = usergetdate(time());
        // Time and day at the user's location
        if ($m == $thisdate['mon'] && $y == $thisdate['year']) {
            // Navigated to this month
            $date = $thisdate;
            $display->thismonth = true;
        } else {
            // Navigated to other month, let's do a nice trick and save us a lot of work...
            if (!checkdate($m, 1, $y)) {
                $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
                $display->thismonth = true;
            } else {
                $date = array('mday' => 1, 'mon' => $m, 'year' => $y);
                $display->thismonth = false;
            }
        }
    } else {
        $date = usergetdate(time());
        $display->thismonth = true;
    }
    // Fill in the variables we 're going to use, nice and tidy
    list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']);
    // This is what we want to display
    $display->maxdays = calendar_days_in_month($m, $y);
    $startwday = 0;
    if (get_user_timezone_offset() < 99) {
        // We 'll keep these values as GMT here, and offset them when the time comes to query the db
        $display->tstart = gmmktime(0, 0, 0, $m, 1, $y);
        // This is GMT
        $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y);
        // GMT
        $startwday = gmdate('w', $display->tstart);
        // $display->tstart is already GMT, so don't use date(): messes with server's TZ
    } else {
        // no timezone info specified
        $display->tstart = mktime(0, 0, 0, $m, 1, $y);
        $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
        $startwday = date('w', $display->tstart);
        // $display->tstart not necessarily GMT, so use date()
    }
    // Align the starting weekday to fall in our display range
    if ($startwday < $display->minwday) {
        $startwday += 7;
    }
    // Get events from database
    $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
    if (!empty($events)) {
        foreach ($events as $eventid => $event) {
            if (!empty($event->modulename)) {
                $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
                if (!groups_course_module_visible($cm)) {
                    unset($events[$eventid]);
                }
            }
        }
    }
    // Extract information: events vs. time
    calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);
    $text = '';
    if (!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
        $text .= '<div class="buttons"><form action="' . CALENDAR_URL . 'event.php" method="get">';
        $text .= '<div>';
        $text .= '<input type="hidden" name="action" value="new" />';
        $text .= '<input type="hidden" name="course" value="' . $courseid . '" />';
        $text .= '<input type="hidden" name="cal_m" value="' . $m . '" />';
        $text .= '<input type="hidden" name="cal_y" value="' . $y . '" />';
        $text .= '<input type="submit" value="' . get_string('newevent', 'calendar') . '" />';
        $text .= '</div></form></div>';
    }
    $text .= '<label for="cal_course_flt_jump">' . get_string('detailedmonthview', 'calendar') . ':</label>' . calendar_course_filter_selector($getvars);
    echo '<div class="header">' . $text . '</div>';
    echo '<div class="controls">';
    echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y));
    echo '</div>';
    // Start calendar display
    echo '<table class="calendarmonth"><tr class="weekdays">';
    // Begin table. First row: day names
    // Print out the names of the weekdays
    for ($i = $display->minwday; $i <= $display->maxwday; ++$i) {
        // This uses the % operator to get the correct weekday no matter what shift we have
        // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
        echo '<th scope="col">' . get_string($CALENDARDAYS[$i % 7], 'calendar') . '</th>';
    }
    echo '</tr><tr>';
    // End of day names; prepare for day numbers
    // For the table display. $week is the row; $dayweek is the column.
    $week = 1;
    $dayweek = $startwday;
    // Paddding (the first week may have blank days in the beginning)
    for ($i = $display->minwday; $i < $startwday; ++$i) {
        echo '<td class="nottoday">&nbsp;</td>' . "\n";
    }
    // Now display all the calendar
    for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
        if ($dayweek > $display->maxwday) {
            // We need to change week (table row)
            echo "</tr>\n<tr>";
            $dayweek = $display->minwday;
            ++$week;
        }
        // Reset vars
        $cell = '';
        $dayhref = calendar_get_link_href(CALENDAR_URL . 'view.php?view=day&amp;course=' . $courseid . '&amp;', $day, $m, $y);
        if (CALENDAR_WEEKEND & 1 << $dayweek % 7) {
            // Weekend. This is true no matter what the exact range is.
            $class = 'weekend';
        } else {
            // Normal working day.
            $class = '';
        }
        // Special visual fx if an event is defined
        if (isset($eventsbyday[$day])) {
            if (count($eventsbyday[$day]) == 1) {
                $title = get_string('oneevent', 'calendar');
            } else {
                $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
            }
            $cell = '<div class="day"><a href="' . $dayhref . '" title="' . $title . '">' . $day . '</a></div>';
        } else {
            $cell = '<div class="day">' . $day . '</div>';
        }
        // Special visual fx if an event spans many days
        if (isset($typesbyday[$day]['durationglobal'])) {
            $class .= ' duration_global';
        } else {
            if (isset($typesbyday[$day]['durationcourse'])) {
                $class .= ' duration_course';
            } else {
                if (isset($typesbyday[$day]['durationgroup'])) {
                    $class .= ' duration_group';
                } else {
                    if (isset($typesbyday[$day]['durationuser'])) {
                        $class .= ' duration_user';
                    }
                }
            }
        }
        // Special visual fx for today
        if ($display->thismonth && $day == $d) {
            $class .= ' today';
        } else {
            $class .= ' nottoday';
        }
        // Just display it
        if (!empty($class)) {
            $class = ' class="' . trim($class) . '"';
        }
        echo '<td' . $class . '>' . $cell;
        if (isset($eventsbyday[$day])) {
            echo '<ul class="events-new">';
            foreach ($eventsbyday[$day] as $eventindex) {
                // If event has a class set then add it to the event <li> tag
                $eventclass = '';
                if (!empty($events[$eventindex]->class)) {
                    $eventclass = ' class="' . $events[$eventindex]->class . '"';
                }
                echo '<li' . $eventclass . '><a href="' . $dayhref . '#event_' . $events[$eventindex]->id . '">' . format_string($events[$eventindex]->name, true) . '</a></li>';
            }
            echo '</ul>';
        }
        if (isset($durationbyday[$day])) {
            echo '<ul class="events-underway">';
            foreach ($durationbyday[$day] as $eventindex) {
                echo '<li>[' . format_string($events[$eventindex]->name, true) . ']</li>';
            }
            echo '</ul>';
        }
        echo "</td>\n";
    }
    // Paddding (the last week may have blank days at the end)
    for ($i = $dayweek; $i <= $display->maxwday; ++$i) {
        echo '<td class="nottoday">&nbsp;</td>';
    }
    echo "</tr>\n";
    // Last row ends
    echo "</table>\n";
    // Tabular display of days ends
    // OK, now for the filtering display
    echo '<div class="filters"><table><tr>';
    // Global events
    if ($SESSION->cal_show_global) {
        echo '<td class="event_global" style="width: 8px;"></td><td><strong>' . get_string('globalevents', 'calendar') . ':</strong> ';
        echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showglobal&amp;' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n";
    } else {
        echo '<td style="width: 8px;"></td><td><strong>' . get_string('globalevents', 'calendar') . ':</strong> ';
        echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showglobal&amp;' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n";
    }
    // Course events
    if (!empty($SESSION->cal_show_course)) {
        echo '<td class="event_course" style="width: 8px;"></td><td><strong>' . get_string('courseevents', 'calendar') . ':</strong> ';
        echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showcourses&amp;' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n";
    } else {
        echo '<td style="width: 8px;"></td><td><strong>' . get_string('courseevents', 'calendar') . ':</strong> ';
        echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showcourses&amp;' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n";
    }
    echo "</tr>\n";
    if (!empty($USER->id) && !isguest()) {
        echo '<tr>';
        // Group events
        if ($SESSION->cal_show_groups) {
            echo '<td class="event_group" style="width: 8px;"></td><td><strong>' . get_string('groupevents', 'calendar') . ':</strong> ';
            echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showgroups&amp;' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n";
        } else {
            echo '<td style="width: 8px;"></td><td><strong>' . get_string('groupevents', 'calendar') . ':</strong> ';
            echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showgroups&amp;' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n";
        }
        // User events
        if ($SESSION->cal_show_user) {
            echo '<td class="event_user" style="width: 8px;"></td><td><strong>' . get_string('userevents', 'calendar') . ':</strong> ';
            echo get_string('shown', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showuser&amp;' . $getvars . '">' . get_string('clickhide', 'calendar') . '</a>)</td>' . "\n";
        } else {
            echo '<td style="width: 8px;"></td><td><strong>' . get_string('userevents', 'calendar') . ':</strong> ';
            echo get_string('hidden', 'calendar') . ' (<a href="' . CALENDAR_URL . 'set.php?var=showuser&amp;' . $getvars . '">' . get_string('clickshow', 'calendar') . '</a>)</td>' . "\n";
        }
        echo "</tr>\n";
    }
    echo '</table></div>';
}
예제 #4
0
 /**
  * Displays a month in detail
  *
  * @param calendar_information $calendar
  * @param moodle_url $returnurl the url to return to
  * @return string
  */
 public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null)
 {
     global $CFG;
     if (empty($returnurl)) {
         $returnurl = $this->page->url;
     }
     // Get the calendar type we are using.
     $calendartype = \core_calendar\type_factory::get_calendar_instance();
     // Store the display settings.
     $display = new stdClass();
     $display->thismonth = false;
     // Get the specified date in the calendar type being used.
     $date = $calendartype->timestamp_to_date_array($calendar->time);
     $thisdate = $calendartype->timestamp_to_date_array(time());
     if ($date['mon'] == $thisdate['mon'] && $date['year'] == $thisdate['year']) {
         $display->thismonth = true;
         $date = $thisdate;
         $calendar->time = time();
     }
     // Get Gregorian date for the start of the month.
     $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1);
     // Store the gregorian date values to be used later.
     list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']);
     // Get the starting week day for this month.
     $startwday = dayofweek(1, $date['mon'], $date['year']);
     // Get the days in a week.
     $daynames = calendar_get_days();
     // Store the number of days in a week.
     $numberofdaysinweek = $calendartype->get_num_weekdays();
     $display->minwday = calendar_get_starting_weekday();
     $display->maxwday = $display->minwday + ($numberofdaysinweek - 1);
     $display->maxdays = calendar_days_in_month($date['mon'], $date['year']);
     // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates.
     $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0);
     $display->tend = $display->tstart + $display->maxdays * DAYSECS - 1;
     // Align the starting weekday to fall in our display range
     // This is simple, not foolproof.
     if ($startwday < $display->minwday) {
         $startwday += $numberofdaysinweek;
     }
     // Get events from database
     $events = calendar_get_events($display->tstart, $display->tend, $calendar->users, $calendar->groups, $calendar->courses);
     if (!empty($events)) {
         foreach ($events as $eventid => $event) {
             $event = new calendar_event($event);
             if (!empty($event->modulename)) {
                 $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
                 if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
                     unset($events[$eventid]);
                 }
             }
         }
     }
     // Extract information: events vs. time
     calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday, $typesbyday, $calendar->courses);
     $output = html_writer::start_tag('div', array('class' => 'header'));
     $output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar'));
     if (calendar_user_can_add_event($calendar->course)) {
         $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
     }
     $output .= html_writer::end_tag('div', array('class' => 'header'));
     // Controls
     $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'time' => $calendar->time)), array('class' => 'controls'));
     $table = new html_table();
     $table->attributes = array('class' => 'calendarmonth calendartable');
     $table->summary = get_string('calendarheading', 'calendar', userdate($calendar->time, get_string('strftimemonthyear')));
     $table->data = array();
     // Get the day names as the header.
     $header = array();
     for ($i = $display->minwday; $i <= $display->maxwday; ++$i) {
         $header[] = $daynames[$i % $numberofdaysinweek]['shortname'];
     }
     $table->head = $header;
     // For the table display. $week is the row; $dayweek is the column.
     $week = 1;
     $dayweek = $startwday;
     $row = new html_table_row(array());
     // Paddding (the first week may have blank days in the beginning)
     for ($i = $display->minwday; $i < $startwday; ++$i) {
         $cell = new html_table_cell('&nbsp;');
         $cell->attributes = array('class' => 'nottoday dayblank');
         $row->cells[] = $cell;
     }
     // Now display all the calendar
     $weekend = CALENDAR_DEFAULT_WEEKEND;
     if (isset($CFG->calendar_weekend)) {
         $weekend = intval($CFG->calendar_weekend);
     }
     $daytime = $display->tstart - DAYSECS;
     for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
         $daytime = $daytime + DAYSECS;
         if ($dayweek > $display->maxwday) {
             // We need to change week (table row)
             $table->data[] = $row;
             $row = new html_table_row(array());
             $dayweek = $display->minwday;
             ++$week;
         }
         // Reset vars
         $cell = new html_table_cell();
         $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime);
         $cellclasses = array();
         if ($weekend & 1 << $dayweek % $numberofdaysinweek) {
             // Weekend. This is true no matter what the exact range is.
             $cellclasses[] = 'weekend';
         }
         // Special visual fx if an event is defined
         if (isset($eventsbyday[$day])) {
             if (count($eventsbyday[$day]) == 1) {
                 $title = get_string('oneevent', 'calendar');
             } else {
                 $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
             }
             $cell->text = html_writer::tag('div', html_writer::link($dayhref, $day, array('title' => $title)), array('class' => 'day'));
         } else {
             $cell->text = html_writer::tag('div', $day, array('class' => 'day'));
         }
         // Special visual fx if an event spans many days
         $durationclass = false;
         if (isset($typesbyday[$day]['durationglobal'])) {
             $durationclass = 'duration_global';
         } else {
             if (isset($typesbyday[$day]['durationcourse'])) {
                 $durationclass = 'duration_course';
             } else {
                 if (isset($typesbyday[$day]['durationgroup'])) {
                     $durationclass = 'duration_group';
                 } else {
                     if (isset($typesbyday[$day]['durationuser'])) {
                         $durationclass = 'duration_user';
                     }
                 }
             }
         }
         if ($durationclass) {
             $cellclasses[] = 'duration';
             $cellclasses[] = $durationclass;
         }
         // Special visual fx for today
         if ($display->thismonth && $day == $date['mday']) {
             $cellclasses[] = 'day today';
         } else {
             $cellclasses[] = 'day nottoday';
         }
         $cell->attributes = array('class' => join(' ', $cellclasses));
         if (isset($eventsbyday[$day])) {
             $cell->text .= html_writer::start_tag('ul', array('class' => 'events-new'));
             foreach ($eventsbyday[$day] as $eventindex) {
                 // If event has a class set then add it to the event <li> tag
                 $attributes = array();
                 if (!empty($events[$eventindex]->class)) {
                     $attributes['class'] = $events[$eventindex]->class;
                 }
                 $dayhref->set_anchor('event_' . $events[$eventindex]->id);
                 $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true));
                 $cell->text .= html_writer::tag('li', $link, $attributes);
             }
             $cell->text .= html_writer::end_tag('ul');
         }
         if (isset($durationbyday[$day])) {
             $cell->text .= html_writer::start_tag('ul', array('class' => 'events-underway'));
             foreach ($durationbyday[$day] as $eventindex) {
                 $cell->text .= html_writer::tag('li', '[' . format_string($events[$eventindex]->name, true) . ']', array('class' => 'events-underway'));
             }
             $cell->text .= html_writer::end_tag('ul');
         }
         $row->cells[] = $cell;
     }
     // Paddding (the last week may have blank days at the end)
     for ($i = $dayweek; $i <= $display->maxwday; ++$i) {
         $cell = new html_table_cell('&nbsp;');
         $cell->attributes = array('class' => 'nottoday dayblank');
         $row->cells[] = $cell;
     }
     $table->data[] = $row;
     $output .= html_writer::table($table);
     return $output;
 }
예제 #5
0
echo '<tr>';
// START: Main column
echo '<td class="maincalendar">';
$username = $USER->username;
$usernameencoded = urlencode($USER->username);
$authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
switch ($action) {
    case 'advanced':
        break;
    case '':
    default:
        // Let's populate some vars to let "common tasks" be somewhat smart...
        // If today it's weekend, give the "next week" option
        $allownextweek = CALENDAR_WEEKEND & 1 << $now['wday'];
        // If it's the last week of the month, give the "next month" option
        $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < 7;
        // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option
        $allowthisweek = !(CALENDAR_WEEKEND & 1 << $now['wday'] && !(CALENDAR_WEEKEND & 1 << ($now['wday'] + 1) % 7));
        echo '<div class="header">' . get_string('export', 'calendar') . '</div>';
        include 'export_basic.html';
}
echo '</td>';
// END: Main column
// START: Last column (3-month display)
echo '<td class="sidecalendar">';
echo '<div class="header">' . get_string('monthlyview', 'calendar') . '</div>';
list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
$getvars = 'cal_d=' . $day . '&amp;cal_m=' . $mon . '&amp;cal_y=' . $yr;
// For filtering
echo '<div class="minicalendarblock">';
예제 #6
0
                $endmonth = $startmonth;
                $endyear = $startyear;
                if ($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
                    list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
                    $endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
                }
                $timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1;
                break;
            case 'monthnow':
                $timestart = make_timestamp($now['year'], $now['mon'], 1);
                $timeend = make_timestamp($now['year'], $now['mon'], calendar_days_in_month($now['mon'], $now['year']), 23, 59, 59);
                break;
            case 'monthnext':
                list($nextmonth, $nextyear) = calendar_add_month($now['mon'], $now['year']);
                $timestart = make_timestamp($nextyear, $nextmonth, 1);
                $timeend = make_timestamp($nextyear, $nextmonth, calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59);
                break;
            case 'recentupcoming':
                //Events in the last 5 or next 60 days
                $timestart = time() - 432000;
                $timeend = time() + 5184000;
                break;
        }
    } else {
        // Parameters given but incorrect, redirect back to export page
        redirect($CFG->wwwroot . '/calendar/export.php');
        die;
    }
}
$whereclause = calendar_sql_where($timestart, $timeend, $users, $groups, array_keys($courses), false);
if ($whereclause === false) {
예제 #7
0
$PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time));
$PAGE->navbar->add($pagetitle);
$PAGE->set_title($course->shortname . ': ' . get_string('calendar', 'calendar') . ': ' . $pagetitle);
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('standard');
$renderer = $PAGE->get_renderer('core_calendar');
$calendar->add_sidecalendar_blocks($renderer);
// Get the calendar type we are using.
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$now = $calendartype->timestamp_to_date_array($time);
$weekend = CALENDAR_DEFAULT_WEEKEND;
if (isset($CFG->calendar_weekend)) {
    $weekend = intval($CFG->calendar_weekend);
}
$numberofdaysinweek = $calendartype->get_num_weekdays();
$formdata = array('allownextweek' => $weekend & 1 << $now['wday'], 'allownextmonth' => calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek, 'allowthisweek' => !($weekend & 1 << $now['wday'] && !($weekend & 1 << ($now['wday'] + 1) % $numberofdaysinweek)));
$exportform = new core_calendar_export_form(null, $formdata);
$calendarurl = '';
if ($data = $exportform->get_data()) {
    $password = $DB->get_record('user', array('id' => $USER->id), 'password');
    $params = array();
    $params['userid'] = $USER->id;
    $params['authtoken'] = sha1($USER->id . (isset($password->password) ? $password->password : '') . $CFG->calendar_exportsalt);
    $params['preset_what'] = $data->events['exportevents'];
    $params['preset_time'] = $data->period['timeperiod'];
    $link = new moodle_url('/calendar/export_execute.php', $params);
    if (!empty($data->generateurl)) {
        $urlclasses = array('class' => 'generalbox calendarurl');
        $calendarurl = html_writer::tag('div', get_string('calendarurl', 'calendar', $link->out()), $urlclasses);
    }
    if (!empty($data->export)) {
예제 #8
0
 /**
  * Displays a month in detail
  *
  * @param calendar_information $calendar
  * @return string
  */
 public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null)
 {
     global $CFG;
     if (empty($returnurl)) {
         $returnurl = $this->page->url;
     }
     $date = usergetdate(time());
     $display = new stdClass();
     $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
     $display->maxwday = $display->minwday + 6;
     $display->thismonth = $date['mon'] == $calendar->month;
     $display->maxdays = calendar_days_in_month($calendar->month, $calendar->year);
     $startwday = 0;
     if (get_user_timezone_offset() < 99) {
         // We 'll keep these values as GMT here, and offset them when the time comes to query the db
         $display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year);
         // This is GMT
         $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year);
         // GMT
         $startwday = gmdate('w', $display->tstart);
         // $display->tstart is already GMT, so don't use date(): messes with server's TZ
     } else {
         // no timezone info specified
         $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year);
         $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year);
         $startwday = date('w', $display->tstart);
         // $display->tstart not necessarily GMT, so use date()
     }
     // Align the starting weekday to fall in our display range
     if ($startwday < $display->minwday) {
         $startwday += 7;
     }
     // Get events from database
     $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses);
     if (!empty($events)) {
         foreach ($events as $eventid => $event) {
             $event = new calendar_event($event);
             if (!empty($event->modulename)) {
                 $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
                 if (!groups_course_module_visible($cm)) {
                     unset($events[$eventid]);
                 }
             }
         }
     }
     // Extract information: events vs. time
     calendar_events_by_day($events, $calendar->month, $calendar->year, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses);
     $output = html_writer::start_tag('div', array('class' => 'header'));
     if (calendar_user_can_add_event($calendar->course)) {
         $output .= $this->add_event_button($calendar->course->id, null, $calendar->month, $calendar->year);
     }
     $output .= get_string('detailedmonthview', 'calendar') . ': ' . $this->course_filter_selector($returnurl);
     $output .= html_writer::end_tag('div', array('class' => 'header'));
     // Controls
     $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class' => 'controls'));
     $days = calendar_get_days();
     $table = new html_table();
     $table->attributes = array('class' => 'calendarmonth calendartable');
     $table->data = array();
     $header = new html_table_row();
     $header->attributes = array('class' => 'weekdays');
     $header->cells = array();
     for ($i = $display->minwday; $i <= $display->maxwday; ++$i) {
         // This uses the % operator to get the correct weekday no matter what shift we have
         // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
         $cell = new html_table_cell(get_string($days[$i % 7], 'calendar'));
         $cell->header = true;
         $header->cells[] = $cell;
     }
     // For the table display. $week is the row; $dayweek is the column.
     $week = 1;
     $dayweek = $startwday;
     // Create an array of all the week days.
     $wdays = array(0 => '<strong>' . get_string('sunday', 'calendar') . '</strong>', 1 => '<strong>' . get_string('monday', 'calendar') . '</strong>', 2 => '<strong>' . get_string('tuesday', 'calendar') . '</strong>', 3 => '<strong>' . get_string('wednesday', 'calendar') . '</strong>', 4 => '<strong>' . get_string('thursday', 'calendar') . '</strong>', 5 => '<strong>' . get_string('friday', 'calendar') . '</strong>', 6 => '<strong>' . get_string('saturday', 'calendar') . '</strong>');
     // Loop only if the day offset is greater than 0.
     // This loop involves shifting the days around until the desired start day
     // is at the start of the array.
     $daycount = 0;
     while ($display->minwday > $daycount++) {
         $wdays_end = array_shift($wdays);
         array_push($wdays, $wdays_end);
     }
     // Now we set the (modified) array to the table header to be displayed.
     $table->head = $wdays;
     $row = new html_table_row(array());
     // Paddding (the first week may have blank days in the beginning)
     for ($i = $display->minwday; $i < $startwday; ++$i) {
         $cell = new html_table_cell('&nbsp;');
         $cell->attributes = array('class' => 'nottoday');
         $row->cells[] = $cell;
     }
     // Now display all the calendar
     $weekend = CALENDAR_DEFAULT_WEEKEND;
     if (isset($CFG->calendar_weekend)) {
         $weekend = intval($CFG->calendar_weekend);
     }
     for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) {
         if ($dayweek > $display->maxwday) {
             // We need to change week (table row)
             $table->data[] = $row;
             $row = new html_table_row(array());
             $dayweek = $display->minwday;
             ++$week;
         }
         // Reset vars
         $cell = new html_table_cell();
         $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'day', 'course' => $calendar->courseid)), $calendar->day, $calendar->month, $calendar->year);
         $cellclasses = array();
         if ($weekend & 1 << $dayweek % 7) {
             // Weekend. This is true no matter what the exact range is.
             $cellclasses[] = 'weekend';
         }
         // Special visual fx if an event is defined
         if (isset($eventsbyday[$calendar->day])) {
             if (count($eventsbyday[$calendar->day]) == 1) {
                 $title = get_string('oneevent', 'calendar');
             } else {
                 $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day]));
             }
             $cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title' => $title)), array('class' => 'day'));
         } else {
             $cell->text = html_writer::tag('div', $calendar->day, array('class' => 'day'));
         }
         // Special visual fx if an event spans many days
         $durationclass = false;
         if (isset($typesbyday[$calendar->day]['durationglobal'])) {
             $durationclass = 'duration_global';
         } else {
             if (isset($typesbyday[$calendar->day]['durationcourse'])) {
                 $durationclass = 'duration_course';
             } else {
                 if (isset($typesbyday[$calendar->day]['durationgroup'])) {
                     $durationclass = 'duration_group';
                 } else {
                     if (isset($typesbyday[$calendar->day]['durationuser'])) {
                         $durationclass = 'duration_user';
                     }
                 }
             }
         }
         if ($durationclass) {
             $cellclasses[] = 'duration';
             $cellclasses[] = $durationclass;
         }
         // Special visual fx for today
         if ($display->thismonth && $calendar->day == $calendar->day) {
             $cellclasses[] = 'today';
         } else {
             $cellclasses[] = 'nottoday';
         }
         $cell->attributes = array('class' => join(' ', $cellclasses));
         if (isset($eventsbyday[$calendar->day])) {
             $cell->text .= html_writer::start_tag('ul', array('class' => 'events-new'));
             foreach ($eventsbyday[$calendar->day] as $eventindex) {
                 // If event has a class set then add it to the event <li> tag
                 $attributes = array();
                 if (!empty($events[$eventindex]->class)) {
                     $attributes['class'] = $events[$eventindex]->class;
                 }
                 $dayhref->set_anchor('event_' . $events[$eventindex]->id);
                 $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true));
                 $cell->text .= html_writer::tag('li', $link, $attributes);
             }
             $cell->text .= html_writer::end_tag('ul');
         }
         if (isset($durationbyday[$calendar->day])) {
             $cell->text .= html_writer::start_tag('ul', array('class' => 'events-underway'));
             foreach ($durationbyday[$calendar->day] as $eventindex) {
                 $cell->text .= html_writer::tag('li', '[' . format_string($events[$eventindex]->name, true) . ']', array('class' => 'events-underway'));
             }
             $cell->text .= html_writer::end_tag('ul');
         }
         $row->cells[] = $cell;
     }
     // Paddding (the last week may have blank days at the end)
     for ($i = $dayweek; $i <= $display->maxwday; ++$i) {
         $cell = new html_table_cell('&nbsp;');
         $cell->attributes = array('class' => 'nottoday');
         $row->cells[] = $cell;
     }
     $table->data[] = $row;
     $output .= html_writer::table($table);
     // OK, now for the filtering display
     $output .= $this->filter_selection_table($calendar);
     return $output;
 }
예제 #9
0
             $timeend = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']);
             break;
         case 'monthnow':
             // Convert to gregorian.
             $gregoriandate = $calendartype->convert_to_gregorian($now['year'], $now['mon'], 1);
             $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']);
             $timeend = $timestart + calendar_days_in_month($now['mon'], $now['year']) * DAYSECS;
             break;
         case 'monthnext':
             // Get the next month for this calendar.
             list($nextmonth, $nextyear) = calendar_add_month($now['mon'], $now['year']);
             // Convert to gregorian.
             $gregoriandate = $calendartype->convert_to_gregorian($nextyear, $nextmonth, 1);
             // Create the timestamps.
             $timestart = make_timestamp($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'], $gregoriandate['hour'], $gregoriandate['minute']);
             $timeend = $timestart + calendar_days_in_month($nextmonth, $nextyear) * DAYSECS;
             break;
         case 'recentupcoming':
             //Events in the last 5 or next 60 days
             $timestart = time() - 432000;
             $timeend = time() + 5184000;
             break;
         case 'custom':
             // Events based on custom date range.
             $timestart = time() - $CFG->calendar_exportlookback * DAYSECS;
             $timeend = time() + $CFG->calendar_exportlookahead * DAYSECS;
             break;
     }
 } else {
     // Parameters given but incorrect, redirect back to export page
     redirect($CFG->wwwroot . '/calendar/export.php');
예제 #10
0
function get_display_info($d, $m, $y) {
    $display = new stdClass;
    $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
    $display->maxwday = $display->minwday + 6;

    $thisdate = usergetdate(time()); // Time and day at the user's location
    if ($m == $thisdate['mon'] && $y == $thisdate['year']) {
        // Navigated to this month
        $date = $thisdate;
        $display->thismonth = true;
    }
    else {
        // Navigated to other month, let's do a nice trick and save us a lot of work...
        if (!checkdate($m, 1, $y)) {
            $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
            $display->thismonth = true;
        }
        else {
            $date = array('mday' => 1, 'mon' => $m, 'year' => $y);
            $display->thismonth = false;
        }
    }

    // Fill in the variables we 're going to use, nice and tidy
    list($day, $month, $year) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
    $display->maxdays = calendar_days_in_month($m, $y);

    $startwday = 0;
    if (get_user_timezone_offset() < 99) {
        // We 'll keep these values as GMT here, and offset them when the time comes to query the db
        $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
        $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
        $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
    } else {
        // no timezone info specified
        $display->tstart = mktime(0, 0, 0, $m, 1, $y);
        $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
        $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
    }

    // Align the starting weekday to fall in our display range
    if ($startwday < $display->minwday) {
        $startwday += 7;
    }

    $display->startwday = $startwday;
    return $display;
}
예제 #11
0
        // Why nothing?
        break;
    case '':
    default:
        $weekend = CALENDAR_DEFAULT_WEEKEND;
        if (isset($CFG->calendar_weekend)) {
            $weekend = intval($CFG->calendar_weekend);
        }
        // Get the number of days.
        $numberofdaysinweek = $calendartype->get_num_weekdays();
        $authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id' => $USER->id)) . $CFG->calendar_exportsalt);
        // Let's populate some vars to let "common tasks" be somewhat smart...
        // If today it's weekend, give the "next week" option.
        $allownextweek = $weekend & 1 << $now['wday'];
        // If it's the last week of the month, give the "next month" option.
        $allownextmonth = calendar_days_in_month($now['mon'], $now['year']) - $now['mday'] < $numberofdaysinweek;
        // If today it's weekend but tomorrow it isn't, do NOT give the "this week" option.
        $allowthisweek = !($weekend & 1 << $now['wday'] && !($weekend & 1 << ($now['wday'] + 1) % $numberofdaysinweek));
        echo $renderer->basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $USER->id, $authtoken);
        break;
}
if (!empty($generateurl)) {
    $params['userid'] = optional_param('userid', 0, PARAM_INT);
    $params['authtoken'] = optional_param('authtoken', '', PARAM_ALPHANUM);
    $params['preset_what'] = optional_param('preset_what', 'all', PARAM_ALPHA);
    $params['preset_time'] = optional_param('preset_time', 'weeknow', PARAM_ALPHA);
    $link = new moodle_url('/calendar/export_execute.php', $params);
    print html_writer::tag('div', get_string('calendarurl', 'calendar', $link->out()), array('class' => 'generalbox calendarurl'));
}
echo $renderer->complete_layout();
echo $OUTPUT->footer();