示例#1
0
function calendar_format_event_time($event, $now, $morehref, $usecommonwords = true, $showtime = 0)
{
    $startdate = usergetdate($event->timestart);
    $enddate = usergetdate($event->timestart + $event->timeduration);
    $usermidnightstart = usergetmidnight($event->timestart);
    if ($event->timeduration) {
        // To avoid doing the math if one IF is enough :)
        $usermidnightend = usergetmidnight($event->timestart + $event->timeduration);
    } else {
        $usermidnightend = $usermidnightstart;
    }
    // OK, now to get a meaningful display...
    // First of all we have to construct a human-readable date/time representation
    if ($event->timeduration) {
        // It has a duration
        if ($usermidnightstart == $usermidnightend || $event->timestart == $usermidnightstart && ($event->timeduration == 86400 || $event->timeduration == 86399) || $event->timestart + $event->timeduration <= $usermidnightstart + 86400) {
            // But it's all on the same day
            $timestart = calendar_time_representation($event->timestart);
            $timeend = calendar_time_representation($event->timestart + $event->timeduration);
            $time = $timestart . ' <strong>&raquo;</strong> ' . $timeend;
            if ($event->timestart == $usermidnightstart && ($event->timeduration == 86400 || $event->timeduration == 86399)) {
                $time = get_string('allday', 'calendar');
            }
            // Set printable representation
            if (!$showtime) {
                $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
                $eventtime = calendar_get_link_tag($day, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']) . ', ' . $time;
            } else {
                $eventtime = $time;
            }
        } else {
            // It spans two or more days
            $daystart = calendar_day_representation($event->timestart, $now, $usecommonwords) . ', ';
            if ($showtime == $usermidnightstart) {
                $daystart = '';
            }
            $timestart = calendar_time_representation($event->timestart);
            $dayend = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords) . ', ';
            if ($showtime == $usermidnightend) {
                $dayend = '';
            }
            $timeend = calendar_time_representation($event->timestart + $event->timeduration);
            // Set printable representation
            if ($now >= $usermidnightstart && $now < $usermidnightstart + 86400) {
                $eventtime = $timestart . ' <strong>&raquo;</strong> ' . calendar_get_link_tag($dayend, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']) . $timeend;
            } else {
                $eventtime = calendar_get_link_tag($daystart, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']) . $timestart . ' <strong>&raquo;</strong> ' . calendar_get_link_tag($dayend, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']) . $timeend;
            }
        }
    } else {
        $time = ' ';
        // Set printable representation
        if (!$showtime) {
            $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
            $eventtime = calendar_get_link_tag($day, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']) . trim($time);
        } else {
            $eventtime = $time;
        }
    }
    if ($event->timestart + $event->timeduration < $now) {
        // It has expired
        $eventtime = '<span class="dimmed_text">' . str_replace(' href=', ' class="dimmed" href=', $eventtime) . '</span>';
    }
    return $eventtime;
}
function startCalendar($course)
{
    $view = optional_param('view', 'upcoming', PARAM_ALPHA);
    $day = optional_param('cal_d', 0, PARAM_INT);
    $mon = optional_param('cal_m', 0, PARAM_INT);
    $yr = optional_param('cal_y', 0, PARAM_INT);
    // Initialize the session variables
    calendar_session_vars();
    //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
    $now = usergetdate(time());
    $pagetitle = '';
    $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL . 'view.php?view=upcoming&amp;course=' . $course->id . '&amp;', $now['mday'], $now['mon'], $now['year']);
    if (!checkdate($mon, $day, $yr)) {
        $day = intval($now['mday']);
        $mon = intval($now['mon']);
        $yr = intval($now['year']);
    }
    $time = make_timestamp($yr, $mon, $day);
    switch ($view) {
        case 'day':
            $nav .= ' -> ' . userdate($time, get_string('strftimedate'));
            $pagetitle = get_string('dayview', 'calendar');
            break;
        case 'month':
            $nav .= ' -> ' . userdate($time, get_string('strftimemonthyear'));
            $pagetitle = get_string('detailedmonthview', 'calendar');
            break;
        case 'upcoming':
            $pagetitle = get_string('upcomingevents', 'calendar');
            break;
    }
    // If a course has been supplied in the URL, change the filters to show that one
    if (!empty($course->id)) {
        if ($course = get_record('course', 'id', $course->id)) {
            if ($course->id == SITEID) {
                // If coming from the home page, show all courses
                $SESSION->cal_courses_shown = calendar_get_default_courses(true);
                calendar_set_referring_course(0);
            } else {
                // Otherwise show just this one
                $SESSION->cal_courses_shown = $course->id;
                calendar_set_referring_course($SESSION->cal_courses_shown);
            }
        }
    } else {
        $course = null;
    }
    if (empty($USER->id) or isguest()) {
        $defaultcourses = calendar_get_default_courses();
        calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
    } else {
        calendar_set_filters($courses, $groups, $users);
    }
    // Let's see if we are supposed to provide a referring course link
    // but NOT for the "main page" course
    if ($SESSION->cal_course_referer != SITEID && ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) {
        // If we know about the referring course, show a return link and ALSO require login!
        require_login();
        $nav = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $SESSION->cal_course_referer . '">' . $shortname . '</a> -> ' . $nav;
        if (empty($course)) {
            $course = get_record('course', 'id', $SESSION->cal_course_referer);
            // Useful to have around
        }
    }
    $strcalendar = get_string('calendar', 'calendar');
    $prefsbutton = calendar_preferences_button();
    /// Print the page header
    if ($course->category) {
        $navigation = "<a href=\"../../course/view.php?id={$course->id}\">{$course->shortname}</a> ->";
    } else {
        $navigation = '';
    }
    echo calendar_overlib_html();
    // Layout the whole page as three big columns.
    echo '<table id="calendar" style="height:100%;">';
    echo '<tr>';
    // START: Main column
    /// Print the main part of the pageecho $user;
    echo '<td class="maincalendar">';
    echo '<div class="heightcontainer">';
}
示例#3
0
$action = required_param('action', PARAM_ALPHA);
$eventid = optional_param('id', 0, PARAM_INT);
$eventtype = optional_param('type', 'select', PARAM_ALPHA);
$urlcourse = optional_param('course', 0, PARAM_INT);
$cal_y = optional_param('cal_y');
$cal_m = optional_param('cal_m');
$cal_d = optional_param('cal_d');
$focus = '';
if (!($site = get_site())) {
    redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
}
$strcalendar = get_string('calendar', 'calendar');
// Initialize the session variables
calendar_session_vars();
$now = usergetdate(time());
$nav = calendar_get_link_tag($strcalendar, CALENDAR_URL . 'view.php?view=upcoming&amp;course=' . $urlcourse . '&amp;', $now['mday'], $now['mon'], $now['year']);
$day = intval($now['mday']);
$mon = intval($now['mon']);
$yr = intval($now['year']);
if ($usehtmleditor = can_use_richtext_editor()) {
    $defaultformat = FORMAT_HTML;
} else {
    $defaultformat = FORMAT_MOODLE;
}
// If a course has been supplied in the URL, change the filters to show that one
if ($urlcourse > 0 && record_exists('course', 'id', $urlcourse)) {
    require_login($urlcourse, false);
    if ($urlcourse == SITEID) {
        // If coming from the site page, show all courses
        $SESSION->cal_courses_shown = calendar_get_default_courses(true);
        calendar_set_referring_course(0);
 } else {
     $defaultformat = FORMAT_MOODLE;
 }
 $icon = '<img class="icon" src="' . $CFG->modpixpath . '/' . $module->name . '/icon.gif" alt="' . get_string('modulename', $module->name) . '"/>';
 print_heading_with_help($pageheading, "mods", $module->name, $icon);
 print_simple_box_start('center', '', '', 5, 'generalbox', $module->name);
 $view = optional_param('view', 'upcoming', PARAM_ALPHA);
 $day = optional_param('cal_d', 0, PARAM_INT);
 $mon = optional_param('cal_m', 0, PARAM_INT);
 $yr = optional_param('cal_y', 0, PARAM_INT);
 // Initialize the session variables
 calendar_session_vars();
 //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
 $now = usergetdate(time());
 $pagetitle = '';
 $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL . 'view.php?view=upcoming&amp;course=' . $course->id . '&amp;', $now['mday'], $now['mon'], $now['year']);
 if (!checkdate($mon, $day, $yr)) {
     $day = intval($now['mday']);
     $mon = intval($now['mon']);
     $yr = intval($now['year']);
 }
 $time = make_timestamp($yr, $mon, $day);
 switch ($view) {
     case 'day':
         $nav .= ' -> ' . userdate($time, get_string('strftimedate'));
         $pagetitle = get_string('dayview', 'calendar');
         break;
     case 'month':
         $nav .= ' -> ' . userdate($time, get_string('strftimemonthyear'));
         $pagetitle = get_string('detailedmonthview', 'calendar');
         break;
示例#5
0
function calendar_format_event_time($event, $now, $morehref, $usecommonwords = true)
{
    $startdate = usergetdate($event->timestart);
    $enddate = usergetdate($event->timestart + $event->timeduration);
    $usermidnightstart = usergetmidnight($event->timestart);
    if ($event->timeduration) {
        // To avoid doing the math if one IF is enough :)
        $usermidnightend = usergetmidnight($event->timestart + $event->timeduration);
    } else {
        $usermidnightend = $usermidnightstart;
    }
    // OK, now to get a meaningful display...
    // First of all we have to construct a human-readable date/time representation
    if ($event->timestart + $event->timeduration < $now) {
        // It has expired, so we don't care about duration
        $day = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords);
        $time = calendar_time_representation($event->timestart + $event->timeduration);
        // This var always has the printable time representation
        $eventtime = '<span class="dimmed_text"><a class="dimmed" href="' . calendar_get_link_href(CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']) . '">' . $day . '</a> (' . $time . ')</span>';
    } else {
        if ($event->timeduration) {
            // It has a duration
            if ($usermidnightstart == $usermidnightend) {
                // But it's all on the same day
                $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
                $timestart = calendar_time_representation($event->timestart);
                $timeend = calendar_time_representation($event->timestart + $event->timeduration);
                // Set printable representation
                $eventtime = calendar_get_link_tag($day, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']) . ' (' . $timestart . ' <strong>&raquo;</strong> ' . $timeend . ')';
            } else {
                // It spans two or more days
                $daystart = calendar_day_representation($event->timestart, $now, $usecommonwords);
                $dayend = calendar_day_representation($event->timestart + $event->timeduration, $now, $usecommonwords);
                $timestart = calendar_time_representation($event->timestart);
                $timeend = calendar_time_representation($event->timestart + $event->timeduration);
                // Set printable representation
                $eventtime = calendar_get_link_tag($daystart, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']) . ' (' . $timestart . ') <strong>&raquo;</strong> ' . calendar_get_link_tag($dayend, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']) . ' (' . $timeend . ')';
            }
        } else {
            // It's an "instantaneous" event
            $day = calendar_day_representation($event->timestart, $now, $usecommonwords);
            $time = calendar_time_representation($event->timestart);
            // Set printable representation
            $eventtime = calendar_get_link_tag($day, CALENDAR_URL . 'view.php?view=day' . $morehref . '&amp;', $startdate['mday'], $startdate['mon'], $startdate['year']) . ' (' . $time . ')';
        }
    }
    return $eventtime;
}