public static function get_calendar_type() {
        global $CFG, $USER, $SESSION, $COURSE;

        // Course calendartype can override all other settings for this page.
        if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->calendartype)) {
            $return = $COURSE->calendartype;
        } else if (!empty($SESSION->calendartype)) { // Session calendartype can override other settings.
            $return = $SESSION->calendartype;
        } else if (!empty($USER->calendartype)) {
            $return = $USER->calendartype;
        } else if (!empty($CFG->calendartype)) {
            $return = $CFG->calendartype;
        } else {
            $return = 'gregorian';
        }

        return $return;
    }