diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index b5293df9ab5..1ee3a7ad2c4 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -45,8 +45,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page array('0' => new lang_string('default', 'calendar'), '%I:%M %p' => new lang_string('timeformat_12', 'calendar'), '%H:%M' => new lang_string('timeformat_24', 'calendar')))); - // MDL-18375, Multi-Calendar Support - $temp->add(new admin_setting_configselect('calendarsystem', new lang_string('configcalendarsystem', 'calendarsystem'), new lang_string('helpcalendarsystem', 'calendarsystem'), 'gregorian', get_list_of_calendars())); $temp->add(new admin_setting_configselect('calendar_startwday', new lang_string('configstartwday', 'admin'), new lang_string('helpstartofweek', 'admin'), 0, array( 0 => new lang_string('sunday', 'calendar'), diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 4587d3412ee..502d5e667ad 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -454,13 +454,6 @@ if ($hassiteconfig) { } } -// calendarsystem plugins -if ($hassiteconfig) { - $ADMIN->add('modules', new admin_category('calendarsystems', new lang_string('calendarsystems', 'calendarsystem'))); - $ADMIN->add('calendarsystems', new admin_externalpage('managecalendarsystems', new lang_string('calendarsystemsmanage', 'calendarsystem'), $CFG->wwwroot .'/calendarsystem/admin.php')); - $ADMIN->add('calendarsystems', new admin_externalpage('updatecalendarsystems', new lang_string('checkforupdates', 'calendarsystem'), $CFG->wwwroot .'/calendarsystem/index.php')); -} - /// Add all local plugins - must be always last! if ($hassiteconfig) { $ADMIN->add('modules', new admin_category('localplugins', new lang_string('localplugins'))); diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php index d2144139cca..7949d94eada 100644 --- a/admin/tool/uploaduser/index.php +++ b/admin/tool/uploaduser/index.php @@ -81,10 +81,8 @@ $stryesnooptions = array(0=>$strno, 1=>$stryes); $returnurl = new moodle_url('/admin/tool/uploaduser/index.php'); $bulknurl = new moodle_url('/admin/user/user_bulk.php'); -// MDL-18375, Multi-Calendar Support -$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); $today = time(); -$today = $calendarsystem_gregorian->make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); +$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); // array of all valid fields for validation $STD_FIELDS = array('id', 'firstname', 'lastname', 'username', 'email', diff --git a/blocks/calendar_month/block_calendar_month.php b/blocks/calendar_month/block_calendar_month.php index 11e816264a9..abe28089e9e 100644 --- a/blocks/calendar_month/block_calendar_month.php +++ b/blocks/calendar_month/block_calendar_month.php @@ -10,7 +10,7 @@ class block_calendar_month extends block_base { } function get_content() { - global $USER, $CFG, $SESSION, $COURSE, $OUTPUT; + global $USER, $CFG, $SESSION; $cal_m = optional_param( 'cal_m', 0, PARAM_INT ); $cal_y = optional_param( 'cal_y', 0, PARAM_INT ); @@ -51,45 +51,6 @@ class block_calendar_month extends block_base { $this->content->text .= '
'.calendar_filter_controls($this->page->url).'
'; } - // MDL-18375, Multi-Calendar Support - if (empty($COURSE->calendarsystem)) { - // the course has not a forced calendarsystem - // so user can change it. - $url = $CFG->wwwroot . (!empty($COURSE->id) && ($COURSE->id!= SITEID) ? "/course/view.php?id={$COURSE->id}" : '/index.php'); - $url = new moodle_url($url); - - $calendarselect = new single_select($url, 'calendarsystem', get_list_of_calendars(), current_calendarsystem_plugin(), false, 'choosecalendar'); - $calendarselect->set_label(''.get_string('system', 'calendarsystem').''); - - $this->content->text .= ' - - ' . $OUTPUT->render($calendarselect) . ' - - '; - } - return $this->content; } } diff --git a/calendar/event.php b/calendar/event.php index 71717a8e151..027527bf9dc 100644 --- a/calendar/event.php +++ b/calendar/event.php @@ -133,10 +133,9 @@ if ($eventid !== 0) { unset($formoptions->eventtypes->groups); } } - // MDL-18375, Multi-Calendar Support - if($cal_y && $cal_m && $cal_d && $CALENDARSYSTEM->checkdate($cal_m, $cal_d, $cal_y)) { + if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) { $event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0); - } else if($cal_y && $cal_m && $CALENDARSYSTEM->checkdate($cal_m, 1, $cal_y)) { + } else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) { $now = usergetdate(time()); if($cal_y == $now['year'] && $cal_m == $now['mon']) { $event->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0); diff --git a/calendar/export_execute.php b/calendar/export_execute.php index f5e638a65f6..7cd585bdcf0 100644 --- a/calendar/export_execute.php +++ b/calendar/export_execute.php @@ -34,9 +34,7 @@ if (!$authuserid && !$authusername) { $what = optional_param('preset_what', 'all', PARAM_ALPHA); $time = optional_param('preset_time', 'weeknow', PARAM_ALPHA); -// MDL-18375, Multi-Calendar Support -$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); -$now = $calendarsystem_gregorian->usergetdate(time()); +$now = usergetdate(time()); // Let's see if we have sufficient and correct data $allowed_what = array('all', 'courses'); $allowed_time = array('weeknow', 'weeknext', 'monthnow', 'monthnext', 'recentupcoming', 'custom'); @@ -82,47 +80,47 @@ if(!empty($what) && !empty($time)) { $startmonthday = find_day_in_month($now['mday'] - 6, $startweekday, $now['mon'], $now['year']); $startmonth = $now['mon']; $startyear = $now['year']; - if($startmonthday > $calendarsystem_gregorian->calendar_days_in_month($startmonth, $startyear)) { + if($startmonthday > calendar_days_in_month($startmonth, $startyear)) { list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear); $startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear); } - $timestart = $calendarsystem_gregorian->make_timestamp($startyear, $startmonth, $startmonthday); + $timestart = make_timestamp($startyear, $startmonth, $startmonthday); $endmonthday = $startmonthday + 7; $endmonth = $startmonth; $endyear = $startyear; - if($endmonthday > $calendarsystem_gregorian->calendar_days_in_month($endmonth, $endyear)) { + 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 = $calendarsystem_gregorian->make_timestamp($endyear, $endmonth, $endmonthday) - 1; + $timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1; break; case 'weeknext': $startweekday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday()); $startmonthday = find_day_in_month($now['mday'] + 1, $startweekday, $now['mon'], $now['year']); $startmonth = $now['mon']; $startyear = $now['year']; - if($startmonthday > $calendarsystem_gregorian->calendar_days_in_month($startmonth, $startyear)) { + if($startmonthday > calendar_days_in_month($startmonth, $startyear)) { list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear); $startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear); } - $timestart = $calendarsystem_gregorian->make_timestamp($startyear, $startmonth, $startmonthday); + $timestart = make_timestamp($startyear, $startmonth, $startmonthday); $endmonthday = $startmonthday + 7; $endmonth = $startmonth; $endyear = $startyear; - if($endmonthday > $calendarsystem_gregorian->calendar_days_in_month($endmonth, $endyear)) { + 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 = $calendarsystem_gregorian->make_timestamp($endyear, $endmonth, $endmonthday) - 1; + $timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1; break; case 'monthnow': - $timestart = $calendarsystem_gregorian->make_timestamp($now['year'], $now['mon'], 1); - $timeend = $calendarsystem_gregorian->make_timestamp($now['year'], $now['mon'], calendar_days_in_month($now['mon'], $now['year']), 23, 59, 59); + $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 = $calendarsystem_gregorian->make_timestamp($nextyear, $nextmonth, 1); - $timeend = $calendarsystem_gregorian->make_timestamp($nextyear, $nextmonth, calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59); + $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 diff --git a/calendar/lib.php b/calendar/lib.php index 20f5a8f28e1..ede82803316 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -187,8 +187,6 @@ function calendar_get_starting_weekday() { */ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false, $placement = false, $courseid = false ) { global $CFG, $USER, $OUTPUT; - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; $display = new stdClass; $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday()); @@ -204,7 +202,7 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y $display->thismonth = true; } else { // Navigated to other month, let's do a nice trick and save us a lot of work... - if(!$CALENDARSYSTEM->checkdate($cal_month, 1, $cal_year)) { + if(!checkdate($cal_month, 1, $cal_year)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } else { @@ -223,12 +221,12 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y 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 = $CALENDARSYSTEM->gmmktime(0, 0, 0, $m, 1, $y); // This is GMT - $display->tend = $CALENDARSYSTEM->gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT + $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT + $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT } else { // no timezone info specified - $display->tstart = $CALENDARSYSTEM->mktime(0, 0, 0, $m, 1, $y); - $display->tend = $CALENDARSYSTEM->mktime(23, 59, 59, $m, $display->maxdays, $y); + $display->tstart = mktime(0, 0, 0, $m, 1, $y); + $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); } $startwday = dayofweek(1, $m, $y); @@ -826,8 +824,6 @@ function calendar_get_events_by_id($eventids) { */ function calendar_top_controls($type, $data) { global $CFG, $PAGE; - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; $content = ''; if(!isset($data['d'])) { $data['d'] = 1; @@ -840,11 +836,11 @@ function calendar_top_controls($type, $data) { $courseid = '&course='.$data['id']; } - if(!$CALENDARSYSTEM->checkdate($data['m'], $data['d'], $data['y'])) { + if(!checkdate($data['m'], $data['d'], $data['y'])) { $time = time(); } else { - $time = $CALENDARSYSTEM->make_timestamp($data['y'], $data['m'], $data['d']); + $time = make_timestamp($data['y'], $data['m'], $data['d']); } $date = usergetdate($time); @@ -1214,9 +1210,7 @@ function calendar_wday_name($englishname) { * @return int */ function calendar_days_in_month($month, $year) { - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; - return $CALENDARSYSTEM->calendar_days_in_month($month, $year); + return intval(date('t', mktime(0, 0, 0, $month, 1, $year))); } /** @@ -1739,11 +1733,10 @@ function calendar_format_event_time($event, $now, $linkparams = null, $usecommon * @param string|array $selected options for select elements */ function calendar_print_month_selector($name, $selected) { - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; - - $months = $CALENDARSYSTEM->get_month_names(); - + $months = array(); + for ($i=1; $i<=12; $i++) { + $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B'); + } echo html_writer::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide')); echo html_writer::select($months, $name, $selected, false); } diff --git a/calendar/renderer.php b/calendar/renderer.php index 1e05d89b463..4fc9a05d76c 100644 --- a/calendar/renderer.php +++ b/calendar/renderer.php @@ -380,8 +380,6 @@ class core_calendar_renderer extends plugin_renderer_base { */ public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) { global $CFG; - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; if (empty($returnurl)) { $returnurl = $this->page->url; @@ -398,13 +396,13 @@ class core_calendar_renderer extends plugin_renderer_base { $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 = $CALENDARSYSTEM->gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT - $display->tend = $CALENDARSYSTEM->gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT + $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 = $CALENDARSYSTEM->mktime(0, 0, 0, $calendar->month, 1, $calendar->year); - $display->tend = $CALENDARSYSTEM->mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); + $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() } diff --git a/calendar/type/calendartype.class.php b/calendar/type/calendartype.class.php new file mode 100644 index 00000000000..becdd642873 --- /dev/null +++ b/calendar/type/calendartype.class.php @@ -0,0 +1,304 @@ +. + +/** + * Defines functions used by calendar type plugins. + * + * This library provides a unified interface for calendar types. + * + * @package core_calendar + * @author Shamim Rezaie + * @author Mark Nelson + * @copyright 2008 onwards Foodle Group {@link http://foodle.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +abstract class calendar_type_plugin_base { + + /** + * Returns a list of all the possible days for all months. + * + * This is used to generate the select box for the days + * in the date selector elements. Some months contain more days + * than others so this function should return all possible days as + * we can not predict what month will be chosen (the user + * may have JS turned off and we need to support this situation in + * Moodle). + * + * @return array the days + */ + public abstract function get_days(); + + /** + * Returns a list of all the names of the months. + * + * @return array the month names + */ + public abstract function get_months(); + + /** + * Returns the minimum year of the calendar. + * + * @return int the minumum year + */ + public abstract function get_min_year(); + + /** + * Returns the maximum year of the calendar. + * + * @return int the max year + */ + public abstract function get_max_year(); + + /** + * Provided with a day, month, year, hour and minute in the specific + * calendar type convert it into the equivalent Gregorian date. + * + * @param int $year + * @param int $month + * @param int $day + * @param int $hour + * @param int $minute + * @return array the converted day, month and year. + */ + public abstract function convert_to_gregorian($year, $month, $day, $hour = 0, $minute = 0); + + /** + * Provided with a day, month, year, hour and minute in a Gregorian date + * convert it into the specific calendar type date. + * + * @param int $year + * @param int $month + * @param int $day + * @param int $hour + * @param int $minute + * @return array the converted day, month and year. + */ + public abstract function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0); + + /** + * Returns a formatted string that represents a date in user time. + * + * Returns a formatted string that represents a date in user time + * WARNING: note that the format is for strftime(), not date(). + * Because of a bug in most Windows time libraries, we can't use + * the nicer %e, so we have to use %d which has leading zeroes. + * A lot of the fuss in the function is just getting rid of these leading + * zeroes as efficiently as possible. + * + * If parameter fixday = true (default), then take off leading + * zero from %d, else maintain it. + * + * @param int $date the timestamp in UTC, as obtained from the database. + * @param string $format strftime format. You should probably get this using + * get_string('strftime...', 'langconfig'); + * @param int|float|string $timezone by default, uses the user's time zone. if numeric and + * not 99 then daylight saving will not be added. + * {@link http://docs.moodle.org/dev/Time_API#Timezone} + * @param bool $fixday if true (default) then the leading zero from %d is removed. + * If false then the leading zero is maintained. + * @param bool $fixhour if true (default) then the leading zero from %I is removed. + * @return string the formatted date/time. + */ + function userdate($date, $format, $timezone, $fixday, $fixhour) { + global $CFG; + + if (empty($format)) { + $format = get_string('strftimedaydatetime', 'langconfig'); + } + + if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed. + $fixday = false; + } else if ($fixday) { + $formatnoday = str_replace('%d', 'DD', $format); + $fixday = ($formatnoday != $format); + $format = $formatnoday; + } + + // Note: This logic about fixing 12-hour time to remove unnecessary leading + // zero is required because on Windows, PHP strftime function does not + // support the correct 'hour without leading zero' parameter (%l). + if (!empty($CFG->nofixhour)) { + // Config.php can force %I not to be fixed. + $fixhour = false; + } else if ($fixhour) { + $formatnohour = str_replace('%I', 'HH', $format); + $fixhour = ($formatnohour != $format); + $format = $formatnohour; + } + + // Add daylight saving offset for string timezones only, as we can't get dst for + // float values. if timezone is 99 (user default timezone), then try update dst. + if ((99 == $timezone) || !is_numeric($timezone)) { + $date += dst_offset_on($date, $timezone); + } + + $timezone = get_user_timezone_offset($timezone); + + // If we are running under Windows convert to windows encoding and then back to UTF-8 + // (because it's impossible to specify UTF-8 to fetch locale info in Win32). + if (abs($timezone) > 13) { // Server time. + $datestring = date_format_string($date, $format, $timezone); + if ($fixday) { + $daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $date))); + $datestring = str_replace('DD', $daystring, $datestring); + } + if ($fixhour) { + $hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $date))); + $datestring = str_replace('HH', $hourstring, $datestring); + } + } else { + $date += (int)($timezone * 3600); + $datestring = date_format_string($date, $format, $timezone); + if ($fixday) { + $daystring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $date))); + $datestring = str_replace('DD', $daystring, $datestring); + } + if ($fixhour) { + $hourstring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %I', $date))); + $datestring = str_replace('HH', $hourstring, $datestring); + } + } + + return $datestring; + } + + /** + * Given a $time timestamp in GMT (seconds since epoch), returns an array that + * represents the date in user time. + * + * @param int $time Timestamp in GMT + * @param float|int|string $timezone offset's time with timezone, if float and not 99, then no + * dst offset is applyed {@link http://docs.moodle.org/dev/Time_API#Timezone} + * @return array An array that represents the date in user time + */ + function usergetdate($time, $timezone) { + // Save input timezone, required for dst offset check. + $passedtimezone = $timezone; + + $timezone = get_user_timezone_offset($timezone); + + if (abs($timezone) > 13) { // Server time. + return getdate($time); + } + + // Add daylight saving offset for string timezones only, as we can't get dst for + // float values. if timezone is 99 (user default timezone), then try update dst. + if ($passedtimezone == 99 || !is_numeric($passedtimezone)) { + $time += dst_offset_on($time, $passedtimezone); + } + + $time += intval((float)$timezone * HOURSECS); + + $datestring = gmstrftime('%B_%A_%j_%Y_%m_%w_%d_%H_%M_%S', $time); + + // Be careful to ensure the returned array matches that produced by getdate() above. + list ( + $getdate['month'], + $getdate['weekday'], + $getdate['yday'], + $getdate['year'], + $getdate['mon'], + $getdate['wday'], + $getdate['mday'], + $getdate['hours'], + $getdate['minutes'], + $getdate['seconds'] + ) = explode('_', $datestring); + + // Set correct datatype to match with getdate(). + $getdate['seconds'] = (int) $getdate['seconds']; + $getdate['yday'] = (int) $getdate['yday'] - 1; + $getdate['year'] = (int) $getdate['year']; + $getdate['mon'] = (int) $getdate['mon']; + $getdate['wday'] = (int) $getdate['wday']; + $getdate['mday'] = (int) $getdate['mday']; + $getdate['hours'] = (int) $getdate['hours']; + $getdate['minutes'] = (int) $getdate['minutes']; + + return $getdate; + } +} + +/** + * Class calendar_type_plugin_factory. + * + * Factory class producing required subclasses of {@link calendar_type_plugin_base}. + */ +class calendar_type_plugin_factory { + + /** + * Returns an instance of the currently used calendar type. + * + * @return calendar_type_plugin_* the created calendar_type class + * @throws coding_exception if the calendar type file could not be loaded + */ + static function factory() { + global $CFG; + + $type = self::get_calendar_type(); + $file = 'calendar/type/' . $type . '/lib.php'; + $fullpath = $CFG->dirroot . '/' . $file; + if (is_readable($fullpath)) { + require_once($fullpath); + $class = "calendar_type_plugin_$type"; + return new $class(); + } else { + throw new coding_exception("The calendar type file $file could not be initialised, check that it exists + and that the web server has permission to read it."); + } + } + + /** + * Returns a list of calendar typess available for use. + * + * @return array the list of calendar types + */ + static function get_list_of_calendar_types() { + $calendars = array(); + $calendardirs = core_component::get_plugin_list('calendartype'); + + foreach ($calendardirs as $name => $location) { + $calendars[$name] = get_string('name', "calendartype_{$name}"); + } + + return $calendars; + } + + /** + * Returns the current calendar type in use. + * + * @return string the current calendar type being used + */ + static function get_calendar_type() { + global $CFG, $USER, $SESSION, $COURSE; + + if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->calendartype)) { // Course calendartype can override all other settings for this page. + $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; + } +} + diff --git a/calendarsystem/version.php b/calendar/type/gregorian/lang/en/calendartype_gregorian.php similarity index 67% rename from calendarsystem/version.php rename to calendar/type/gregorian/lang/en/calendartype_gregorian.php index 24c4d6d02a4..d6d8625746e 100644 --- a/calendarsystem/version.php +++ b/calendar/type/gregorian/lang/en/calendartype_gregorian.php @@ -1,4 +1,5 @@ . /** - * Version details + * Strings for component 'calendar_type_plugin_gregorian', language 'en'. * - * @package calendarsystem - * @author Shamim Rezaie - * @copyright 2008 onwards Foodle Group {@link http://foodle.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package calendar_type_plugin_gregorian + * @copyright 2008 onwards Foodle Group {@link http://foodle.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - -$version = 2013011900; // The current plugin version (Date: YYYYMMDDXX) +$string['name'] = 'Gregorian'; +$string['pluginname'] = 'Gregorian calendar type'; diff --git a/calendar/type/gregorian/lib.php b/calendar/type/gregorian/lib.php new file mode 100644 index 00000000000..3aa3143fe13 --- /dev/null +++ b/calendar/type/gregorian/lib.php @@ -0,0 +1,133 @@ +. + +/** + * Handles calendar functions for the gregorian calendar. + * + * @package calendar_type_plugin_gregorian + * @author Shamim Rezaie + * @author Mark Nelson + * @copyright 2008 onwards Foodle Group {@link http://foodle.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class calendar_type_plugin_gregorian extends calendar_type_plugin_base { + + /** + * Returns a list of all the possible days for all months. + * + * This is used to generate the select box for the days + * in the date selector elements. Some months contain more days + * than others so this function should return all possible days as + * we can not predict what month will be chosen (the user + * may have JS turned off and we need to support this situation in + * Moodle). + * + * @return array the days + */ + public function get_days() { + $days = array(); + + for ($i = 1; $i <= 31; $i++) { + $days[$i] = $i; + } + + return $days; + } + + /** + * Returns a list of all the names of the months. + * + * @return array the month names + */ + public function get_months() { + $months = array(); + + for ($i = 1; $i <= 12; $i++) { + $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B'); + } + + return $months; + } + + /** + * Returns the minimum year of the calendar. + * + * @return int the minumum year + */ + public function get_min_year() { + return 1900; + } + + /** + * Returns the maximum year of the calendar. + * + * @return int the max year + */ + public function get_max_year() { + return 2050; + } + + /** + * Provided with a day, month, year, hour and minute in a specific + * calendar type convert it into the equivalent Gregorian date. + * + * In this function we don't need to do anything except pass the data + * back as an array. This is because the date received is Gregorian. + * + * @param int $year + * @param int $month + * @param int $day + * @param int $hour + * @param int $minute + * @return array the converted day, month, year, hour and minute. + */ + public function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0) { + $date = array(); + $date['year'] = $year; + $date['month'] = $month; + $date['day'] = $day; + $date['hour'] = $hour; + $date['minute'] = $minute; + + return $date; + } + + /** + * Provided with a day, month, year, hour and minute in a specific + * calendar type convert it into the equivalent Gregorian date. + * + * In this function we don't need to do anything except pass the data + * back as an array. This is because the date received is Gregorian. + * + * @param int $year + * @param int $month + * @param int $day + * @param int $hour + * @param int $minute + * @return array the converted day, month, year, hour and minute. + */ + public function convert_to_gregorian($year, $month, $day, $hour = 0, $minute = 0) { + $date = array(); + $date['year'] = $year; + $date['month'] = $month; + $date['day'] = $day; + $date['hour'] = $hour; + $date['minute'] = $minute; + + return $date; + } +} diff --git a/calendarsystem/hijri/version.php b/calendar/type/gregorian/version.php similarity index 59% rename from calendarsystem/hijri/version.php rename to calendar/type/gregorian/version.php index 64024e6739a..5b0b203e49d 100644 --- a/calendarsystem/hijri/version.php +++ b/calendar/type/gregorian/version.php @@ -15,17 +15,15 @@ // along with Moodle. If not, see . /** - * Version details + * Version details. * - * @package calendarsystem - * @subpackage hijri - * @author Shamim Rezaie - * @copyright 2008 onwards Foodle Group {@link http://foodle.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package calendar_type_plugin_gregorian + * @copyright 2008 onwards Foodle Group {@link http://foodle.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2013011900; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2012120300; // Requires this Moodle version -$plugin->component = 'calendarsystem_hijri'; // Full name of the plugin (used for diagnostics) +$plugin->version = 2013062000; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2012120300; // Requires this Moodle version. +$plugin->component = 'calendartype_gregorian'; // Full name of the plugin (used for diagnostics). diff --git a/calendar/view.php b/calendar/view.php index 8995f6d3950..40a2d82a135 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -88,8 +88,7 @@ $pagetitle = ''; $strcalendar = get_string('calendar', 'calendar'); -// MDL-18375, Multi-Calendar Support -if (!$CALENDARSYSTEM->checkdate($mon, $day, $yr)) { +if (!checkdate($mon, $day, $yr)) { $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); diff --git a/calendarsystem/admin.php b/calendarsystem/admin.php deleted file mode 100644 index f32981a6d1c..00000000000 --- a/calendarsystem/admin.php +++ /dev/null @@ -1,98 +0,0 @@ -. - -require_once('../config.php'); -require_once($CFG->libdir.'/adminlib.php'); -require_once($CFG->libdir.'/tablelib.php'); - -admin_externalpage_setup('managecalendarsystems'); - -$delete = optional_param('delete', '', PARAM_PLUGIN); -$confirm = optional_param('confirm', '', PARAM_BOOL); - -/// If data submitted, then process and store. - -if (!empty($delete) and confirm_sesskey()) { - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('type_calendarsystem_plural', 'plugin')); - - if (!$confirm) { - if (get_string_manager()->string_exists('pluginname', 'calendarsystem_' . $delete)) { - $strpluginname = get_string('pluginname', 'calendarsystem_' . $delete); - } else { - $strpluginname = $delete; - } - echo $OUTPUT->confirm(get_string('calendarsystemdeleteconfirm', 'calendarsystem', $strpluginname), - new moodle_url($PAGE->url, array('delete' => $delete, 'confirm' => 1)), - $PAGE->url); - echo $OUTPUT->footer(); - die(); - - } else { - uninstall_plugin('calendarsystem', $delete); - $a = new stdclass(); - $a->name = $delete; - $pluginlocation = get_plugin_types(); - $a->directory = $pluginlocation['calendarsystem'] . '/' . $delete; - echo $OUTPUT->notification(get_string('plugindeletefiles', '', $a), 'notifysuccess'); - echo $OUTPUT->continue_button($PAGE->url); - echo $OUTPUT->footer(); - die(); - } -} - -echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('type_calendarsystem_plural', 'plugin')); - -/// Print the table of all installed local plugins - -$table = new flexible_table('calendarsystems_administration_table'); -$table->define_columns(array('name', 'version', 'delete')); -$table->define_headers(array(get_string('plugin'), get_string('version'), get_string('delete'))); -$table->define_baseurl($PAGE->url); -$table->set_attribute('id', 'calendarsystems'); -$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); -$table->setup(); - -$plugins = array(); -foreach (get_plugin_list('calendarsystem') as $plugin => $plugindir) { - if (get_string_manager()->string_exists('pluginname', 'calendarsystem_' . $plugin)) { - $strpluginname = get_string('pluginname', 'calendarsystem_' . $plugin); - } else { - $strpluginname = $plugin; - } - $plugins[$plugin] = $strpluginname; -} -collatorlib::asort($plugins); - -foreach ($plugins as $plugin => $name) { - $delete = new moodle_url($PAGE->url, array('delete' => $plugin, 'sesskey' => sesskey())); - $delete = html_writer::link($delete, get_string('delete')); - - $version = get_config('calendarsystem_' . $plugin); - if (!empty($version->version)) { - $version = $version->version; - } else { - $version = '?'; - } - - $table->add_data(array($name, $version, $delete)); -} - -$table->print_html(); -echo $OUTPUT->container(html_writer::link('index.php', get_string('checkforupdates', 'calendarsystem')), 'singlebutton'); -echo $OUTPUT->footer(); diff --git a/calendarsystem/calendarsystem.class.php b/calendarsystem/calendarsystem.class.php deleted file mode 100644 index cea0f3839db..00000000000 --- a/calendarsystem/calendarsystem.class.php +++ /dev/null @@ -1,69 +0,0 @@ -calendarsystem) ? 'gregorian' : $CFG->calendarsystem; // we might be in the installation process and $CFG->calendarststem might be undefined yet - } - if (file_exists("$CFG->dirroot/calendarsystem/$system/calendarsystem.php")) { - require_once("$CFG->dirroot/calendarsystem/$system/calendarsystem.php"); - $class = "calendarsystem_plugin_$system"; - return new $class; - } else { - trigger_error("$CFG->dirroot/calendarsystem/$system/calendarsystem.php does not exist"); - notify("Calendar system file $system/calendarsystem.php does not exist"); - } - } -} - -function get_list_of_calendars() { - $calendars = array(); - $calendardirs = get_list_of_plugins('calendarsystem'); - - foreach ($calendardirs as $calendar) { - $calendars[$calendar] = get_string('name', "calendarsystem_{$calendar}"); - } - - return $calendars; -} - -function current_calendarsystem_plugin() { - global $CFG, $USER, $SESSION, $COURSE; - - if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->calendarsystem)) { // Course calendarsystem can override all other settings for this page - $return = $COURSE->calendarsystem; - - } else if (!empty($SESSION->calendarsystem)) { // Session calendarsystem can override other settings - $return = $SESSION->calendarsystem; - - } else if (!empty($USER->calendarsystem)) { - $return = $USER->calendarsystem; - - } else { - $return = $CFG->calendarsystem; - } - - return $return; -} -?> \ No newline at end of file diff --git a/calendarsystem/gregorian/calendarsystem.php b/calendarsystem/gregorian/calendarsystem.php deleted file mode 100644 index bfe48052420..00000000000 --- a/calendarsystem/gregorian/calendarsystem.php +++ /dev/null @@ -1,88 +0,0 @@ - \ No newline at end of file diff --git a/calendarsystem/gregorian/lang/en/calendarsystem_gregorian.php b/calendarsystem/gregorian/lang/en/calendarsystem_gregorian.php deleted file mode 100644 index c0df03a3f48..00000000000 --- a/calendarsystem/gregorian/lang/en/calendarsystem_gregorian.php +++ /dev/null @@ -1,8 +0,0 @@ - \ No newline at end of file diff --git a/calendarsystem/gregorian/lang/fa/calendarsystem_gregorian.php b/calendarsystem/gregorian/lang/fa/calendarsystem_gregorian.php deleted file mode 100644 index 2cb6e5f6aed..00000000000 --- a/calendarsystem/gregorian/lang/fa/calendarsystem_gregorian.php +++ /dev/null @@ -1,8 +0,0 @@ - \ No newline at end of file diff --git a/calendarsystem/gregorian/version.php b/calendarsystem/gregorian/version.php deleted file mode 100644 index ae024527913..00000000000 --- a/calendarsystem/gregorian/version.php +++ /dev/null @@ -1,31 +0,0 @@ -. - -/** - * Version details - * - * @package calendarsystem - * @subpackage gregorian - * @author Shamim Rezaie - * @copyright 2008 onwards Foodle Group {@link http://foodle.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$plugin->version = 2013011900; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2012120300; // Requires this Moodle version -$plugin->component = 'calendarsystem_gregorian'; // Full name of the plugin (used for diagnostics) diff --git a/calendarsystem/hijri/calendarsystem.php b/calendarsystem/hijri/calendarsystem.php deleted file mode 100644 index 54ea267cf6a..00000000000 --- a/calendarsystem/hijri/calendarsystem.php +++ /dev/null @@ -1,250 +0,0 @@ -to_gregorian(1, $m+1, $y); - $temp = $this->from_gregorian($temp['day']-1, $temp['month'], $temp['year']); - return $temp['day']; - } - - public function usergetdate($time, $timezone=99) { - $date = usergetdate_old($time); - $new_date = $this->from_gregorian($date["mday"], $date["mon"], $date["year"]); - - $date["month"] = get_string("month{$new_date['month']}", 'calendarsystem_hijri'); - $date["weekday"] = get_string("weekday{$date['wday']}", 'calendarsystem_hijri'); - $date["yday"] = null; - $date["year"] = $new_date['year']; - $date["mon"] = $new_date['month']; - $date["mday"] = $new_date['day']; - - return $date; - } - - public function checkdate($m, $d, $y) - { - $temp = $this->to_gregorian($d, $m, $y); - $temp = $this->from_gregorian($temp['day'], $temp['month'], $temp['year']); - return ($temp['day'] == $d) && ($temp['month'] == $m) && ($temp['year'] == $y); - } - - public function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) { - $new_date = $this->to_gregorian($day, $month, $year); - return make_timestamp_old($new_date['year'], $new_date['month'], $new_date['day'], $hour, $minute, $second, $timezone, $applydst); - } - - public function userdate($date, $format='', $timezone=99, $fixday = true, $fixhour = true) { - static $amstring = null, $pmstring = null, $AMstring = null, $PMstring = null; - - if (!$amstring) { - $amstring = get_string('am', 'calendarsystem_hijri'); - $pmstring = get_string('pm', 'calendarsystem_hijri'); - $AMstring = get_string('am_caps', 'calendarsystem_hijri'); - $PMstring = get_string('pm_caps', 'calendarsystem_hijri'); - } - - if (empty($format)) { - $format = get_string('strftimedaydatetime'); - } - - if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed. - $fixday = false; - } - - $date_ = $this->usergetdate($date); - //this is not sufficient code, change it. but it works correctly. - $format = str_replace( array( - "%a", - "%A", - "%b", - "%B", - "%d", - "%m", - "%y", - "%Y", - "%p", - "%P" - ), - array( - $date_["weekday"], - $date_["weekday"], - $date_["month"], - $date_["month"], - (($date_["mday"] < 10 && !$fixday) ? '0' : '') . $date_["mday"], - ($date_["mon"] < 10 ? '0' : '') . $date_["mon"], - $date_["year"] % 100, - $date_["year"], - ($date_["hours"] < 12 ? $AMstring : $PMstring), - ($date_["hours"] < 12 ? $amstring : $pmstring) - ), - $format); - - return userdate_old($date, $format, $timezone, $fixday, $fixhour); - } - - public function today() - { - list($g_y, $g_m, $g_d) = explode( "-", date("Y-m-d")); - $today = $this->from_gregorian((int)$g_d, (int)$g_m, (int)$g_y); - - return array($today['month'], $today['day'], $today['year']); - } - - public function get_month_names() - { - $months = array(); - - for ($i=1; $i<=12; $i++) { - $months[$i] = get_string("month{$i}", 'calendarsystem_hijri'); - } - - return $months; - } - - public function get_min_year() - { - return 1390; - } - - public function get_max_year() - { - return 1440; - } - - public function gmmktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null) { - if (empty($day) || empty($month) || empty($year)) { - $today = $this->today(); - if (empty($day)) { - $day = $today['day']; - } - if (empty($month)) { - $month = $today['month']; - } - if (empty($year)) { - $year = $today['year']; - } - } - - $g_date = $this->to_gregorian($day, $month, $year); - - return gmmktime($hour, $minute, $second, $g_date['month'], $g_date['day'], $g_date['year']); - } - - public function mktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null) { - if (empty($day) || empty($month) || empty($year)) { - $today = $this->today(); - - if (empty($day)) { - $day = $today['day']; - } - if (empty($month)) { - $month = $today['month']; - } - if (empty($year)) { - $year = $today['year']; - } - } - - $g_date = $this->to_gregorian($day, $month, $year); - - return mktime($hour, $minute, $second, $g_date['month'], $g_date['day'], $g_date['year']); - } - - public function dayofweek($day, $month, $year) { - $g_date = $this->to_gregorian($day, $month, $year); - return intval(date('w', mktime(12, 0, 0, $g_date['month'], $g_date['day'], $g_date['year']))); - } - - private $ISLAMIC_EPOCH = 1948439.5; - private $GREGORIAN_EPOCH = 1721425.5; - - // LEAP_GREGORIAN -- Is a given year in the Gregorian calendar a leap year ? - private function leap_gregorian($year) - { - return (($year % 4) == 0) && - (!((($year % 100) == 0) && (($year % 400) != 0))); - } - - // GREGORIAN_TO_JD -- Determine Julian day number from Gregorian calendar date - private function gregorian_to_jd($year, $month, $day) - { - return ($this->GREGORIAN_EPOCH - 1) + - (365 * ($year - 1)) + - floor(($year - 1) / 4) + - (-floor(($year - 1) / 100)) + - floor(($year - 1) / 400) + - floor((((367 * $month) - 362) / 12) + - (($month <= 2) ? 0 : ($this->leap_gregorian($year) ? -1 : -2) - ) + - $day); - } - - // JD_TO_GREGORIAN -- Calculate Gregorian calendar date from Julian day - private function jd_to_gregorian($jd) { - $wjd = floor($jd - 0.5) + 0.5; - $depoch = $wjd - $this->GREGORIAN_EPOCH; - $quadricent = floor($depoch / 146097); - $dqc = $depoch % 146097; - $cent = floor($dqc / 36524); - $dcent = $dqc % 36524; - $quad = floor($dcent / 1461); - $dquad = $dcent % 1461; - $yindex = floor($dquad / 365); - $year = ($quadricent * 400) + ($cent * 100) + ($quad * 4) + $yindex; - if (!(($cent == 4) || ($yindex == 4))) { - $year++; - } - $yearday = $wjd - $this->gregorian_to_jd($year, 1, 1); - $leapadj = (($wjd < $this->gregorian_to_jd($year, 3, 1)) ? 0 : ($this->leap_gregorian($year) ? 1 : 2)); - $month = floor(((($yearday + $leapadj) * 12) + 373) / 367); - $day = ($wjd - $this->gregorian_to_jd($year, $month, 1)) + 1; - - return array('year' => $year, - 'month' => $month, - 'day' => $day); - } - - - private function islamic_to_jd($year, $month, $day) - { - return ($day + - ceil(29.5 * ($month - 1)) + - ($year - 1) * 354 + - floor((3 + (11 * $year)) / 30) + - $this->ISLAMIC_EPOCH) - 1; - } - - - - // JD_TO_ISLAMIC -- Calculate Islamic date from Julian day - private function jd_to_islamic($jd) - { - $jd = floor($jd) + 0.5; - $year = floor(((30 * ($jd - $this->ISLAMIC_EPOCH)) + 10646) / 10631); - $month = min(12, - ceil(($jd - (29 + $this->islamic_to_jd($year, 1, 1))) / 29.5) + 1); - $day = ($jd - $this->islamic_to_jd($year, $month, 1)) + 1; - - return array('year' => $year, - 'month' => $month, - 'day' => $day); - } - - private function from_gregorian($g_d, $g_m, $g_y) { - $jd = $this->gregorian_to_jd($g_y, $g_m, $g_d); - return $this->jd_to_islamic($jd); - } - - private function to_gregorian($i_d, $i_m, $i_y) { - $jd = $this->islamic_to_jd($i_y, $i_m, $i_d); - return $this->jd_to_gregorian($jd); - } -} -?> \ No newline at end of file diff --git a/calendarsystem/hijri/lang/en/calendarsystem_hijri.php b/calendarsystem/hijri/lang/en/calendarsystem_hijri.php deleted file mode 100644 index 04f02d017fd..00000000000 --- a/calendarsystem/hijri/lang/en/calendarsystem_hijri.php +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/calendarsystem/hijri/lang/fa/calendarsystem_hijri.php b/calendarsystem/hijri/lang/fa/calendarsystem_hijri.php deleted file mode 100644 index 233d14979a2..00000000000 --- a/calendarsystem/hijri/lang/fa/calendarsystem_hijri.php +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/calendarsystem/index.php b/calendarsystem/index.php deleted file mode 100644 index 839795664be..00000000000 --- a/calendarsystem/index.php +++ /dev/null @@ -1,175 +0,0 @@ -libdir.'/adminlib.php'); // various admin-only functions -require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions -require_once($CFG->libdir.'/pluginlib.php'); // available updates notifications -require_once('updatechecker.php'); // available updates notifications - -$fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL); - -// Check some PHP server settings - -$PAGE->set_url('/calendarsystem/index.php'); -$PAGE->set_pagelayout('admin'); // Set a default pagelayout - -$version = null; -require("$CFG->dirroot/calendarsystem/version.php"); -// Check version of calendarsystem code on disk - -$PAGE->set_context(context_system::instance()); - -// Check for valid admin user - no guest autologin -require_login(0, false); -$context = context_system::instance(); -require_capability('moodle/site:config', $context); - - -// Everything should now be set up, and the user is an admin - - -// Available updates for Moodle core -$updateschecker = calendarsystem_update_checker::instance(); -$availableupdates = array(); -$availableupdates['core'] = $updateschecker->get_update_info('core'); - -// Available updates for calendar system plugins -$calendars = get_plugin_list('calendarsystem'); -foreach ($calendars as $calendar => $calendarrootdir) { - $availableupdates[$calendar] = $updateschecker->get_update_info('calendarsystem_'.$calendar); -} -/* -$pluginman = plugin_manager::instance(); -foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) { - foreach ($plugintypeinstances as $pluginname => $plugininfo) { - if (!empty($plugininfo->availableupdates)) { - foreach ($plugininfo->availableupdates as $pluginavailableupdate) { - if ($pluginavailableupdate->version > $plugininfo->versiondisk) { - if (!isset($availableupdates[$plugintype.'_'.$pluginname])) { - $availableupdates[$plugintype.'_'.$pluginname] = array(); - } - $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate; - } - } - } - } -} -*/ -// The timestamp of the most recent check for available updates -$availableupdatesfetch = $updateschecker->get_last_timefetched(); - -//admin_externalpage_setup('adminnotifications'); - -if ($fetchupdates) { - require_sesskey(); - $updateschecker->fetch(); - redirect($PAGE->url); -} - -$strupdatecheck = get_string('updatecheck', 'calendarsystem'); -$PAGE->navbar->add($strupdatecheck); - -echo $OUTPUT->header(); -echo available_updates($availableupdates, $availableupdatesfetch); - -echo $OUTPUT->footer(); - - -/////////////////////////////////////////////////////////////////////////////////////// - /** - * Displays the info about available Moodle core and plugin updates - * - * The structure of the $updates param has changed since 2.4. It contains not only updates - * for the core itself, but also for all other installed plugins. - * - * @param array|null $updates array of (string)component => array of calendarsystem_update_info objects or null - * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown) - * @return string - */ - function available_updates($updates, $fetch) { - global $OUTPUT; - - $updateinfo = $OUTPUT->box_start('generalbox adminwarning calendarsystemupdatesinfo'); - $someupdateavailable = false; - if (is_array($updates)) { - if (is_array($updates['core'])) { - $someupdateavailable = true; - $updateinfo .= $OUTPUT->heading(get_string('updateavailable', 'calendarsystem'), 3); - foreach ($updates['core'] as $update) { - $updateinfo .= moodle_available_update_info($update); - } - } - unset($updates['core']); - // If something has left in the $updates array now, it is updates for plugins. - if (!empty($updates)) { - foreach ($updates as $pluginname=>$pluginupdates) { - if (is_array($pluginupdates)) { - $someupdateavailable = true; - $updateinfo .= $OUTPUT->heading(get_string('updateavailableforplugin', 'calendarsystem', get_string('name', 'calendarsystem_'.$pluginname)), 3); - - foreach ($pluginupdates as $update) { - $updateinfo .= moodle_available_update_info($update); - } - } - } - } - } - - if (!$someupdateavailable) { - $now = time(); - if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) { - $updateinfo .= $OUTPUT->heading(get_string('updateavailablenot', 'calendarsystem'), 3); - } - } - - $updateinfo .= $OUTPUT->container_start('checkforupdates'); - $updateinfo .= $OUTPUT->single_button(new moodle_url('', array('fetchupdates' => 1)), get_string('checkforupdates', 'calendarsystem')); - if ($fetch) { - $updateinfo .= $OUTPUT->container(get_string('checkforupdateslast', 'core_plugin', - userdate($fetch, get_string('strftimedatetime', 'core_langconfig')))); - } - $updateinfo .= $OUTPUT->container_end(); - - $updateinfo .= $OUTPUT->box_end(); - - return $updateinfo; - } - - - /** - * Helper method to render the information about the available Moodle update - * - * @param calendarsystem_update_info $updateinfo information about the available Moodle core update - */ - function moodle_available_update_info(calendarsystem_update_info $updateinfo) { - global $OUTPUT; - - $boxclasses = 'moodleupdateinfo'; - $info = array(); - - if (isset($updateinfo->version)) { - $info[] = html_writer::tag('span', get_string('updateavailable_version', 'calendarsystem', $updateinfo->version), - array('class' => 'info version')); - } - - if (isset($updateinfo->download)) { - $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download')); - } - - if (isset($updateinfo->url)) { - $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'calendarsystem'), - array('class' => 'info more')); - } - - $box = $OUTPUT->box_start($boxclasses); - $box .= $OUTPUT->box(implode(html_writer::tag('span', ' - ', array('class' => 'separator')), $info), ''); - $box .= $OUTPUT->box_end(); - - return $box; - } -/////////////////////////////////////////////////////////////////////////////////////// - - - diff --git a/calendarsystem/jalali/calendarsystem.php b/calendarsystem/jalali/calendarsystem.php deleted file mode 100644 index dd5e435398d..00000000000 --- a/calendarsystem/jalali/calendarsystem.php +++ /dev/null @@ -1,289 +0,0 @@ -isleap_solar($y)) - return 30; - - return 29; - } - - public function usergetdate($time, $timezone=99) { - $date = usergetdate_old($time); - $new_date = $this->from_gregorian($date["mday"], $date["mon"], $date["year"]); - - $date["month"] = get_string("month{$new_date['month']}", 'calendarsystem_jalali'); - $date["weekday"] = get_string("weekday{$date['wday']}", 'calendarsystem_jalali'); - $date["yday"] = null; - $date["year"] = $new_date['year']; - $date["mon"] = $new_date['month']; - $date["mday"] = $new_date['day']; - - return $date; -} - - public function checkdate($m, $d, $y) - { - // $m not in 1..12 or $d not in 1..31 - if ($m < 1 or 12 < $m or $d < 1 or $d > 31) - return false; - - // $m in 1..6 and at this line $d in 1..31 - if ($m < 7) - return true; - - // $m in 7..11 and possible value for $d is in 0..31 (but 31 is invalid) - if ($m != 12) - if ($d == 31) { - return false; - } else { - return true; - } - - // $m is 12 - if ($this->isleap_solar($y)) - { - if ($d == 31) - return false; - } - else // $y is not leap year. - if ($d == 31) - return false; - - return true; - } - - public function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) { - $new_date = $this->to_gregorian($day, $month, $year); - return make_timestamp_old($new_date['year'], $new_date['month'], $new_date['day'], $hour, $minute, $second, $timezone, $applydst); - } - - public function userdate($date, $format='', $timezone=99, $fixday = true, $fixhour = true) { - static $amstring = null, $pmstring = null, $AMstring = null, $PMstring = null; - - if (!$amstring) { - $amstring = get_string('am', 'calendarsystem_jalali'); - $pmstring = get_string('pm', 'calendarsystem_jalali'); - $AMstring = get_string('am_caps', 'calendarsystem_jalali'); - $PMstring = get_string('pm_caps', 'calendarsystem_jalali'); - } - - if (empty($format)) { - $format = get_string('strftimedaydatetime'); - } - - if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed. - $fixday = false; - } - - $date_ = $this->usergetdate($date); - //this is not sufficient code, change it. but it works correctly. - $format = str_replace( array( - "%a", - "%A", - "%b", - "%B", - "%d", - "%m", - "%y", - "%Y", - "%p", - "%P" - ), - array( - $date_["weekday"], - $date_["weekday"], - $date_["month"], - $date_["month"], - (($date_["mday"] < 10 && !$fixday) ? '0' : '') . $date_["mday"], - ($date_["mon"] < 10 ? '0' : '') . $date_["mon"], - $date_["year"] % 100, - $date_["year"], - ($date_["hours"] < 12 ? $AMstring : $PMstring), - ($date_["hours"] < 12 ? $amstring : $pmstring) - ), - $format); - - return userdate_old($date, $format, $timezone, $fixday, $fixhour); - } - - public function today() - { - list($g_y, $g_m, $g_d) = explode( "-", date("Y-m-d")); - $today = $this->from_gregorian((int)$g_d, (int)$g_m, (int)$g_y); - - return array($today['month'], $today['day'], $today['year']); - } - - public function get_month_names() - { - $months = array(); - - for ($i=1; $i<=12; $i++) { - $months[$i] = get_string("month{$i}", 'calendarsystem_jalali'); - } - - return $months; - } - - public function get_min_year() - { - return 1350; - } - - public function get_max_year() - { - return 1400; - } - - public function gmmktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null) { - if (empty($day) || empty($month) || empty($year)) { - $today = $this->today(); - if (empty($day)) { - $day = $today['day']; - } - if (empty($month)) { - $month = $today['month']; - } - if (empty($year)) { - $year = $today['year']; - } - } - - $g_date = $this->to_gregorian($day, $month, $year); - - return gmmktime($hour, $minute, $second, $g_date['month'], $g_date['day'], $g_date['year']); - } - - public function mktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null) { - if (empty($day) || empty($month) || empty($year)) { - $today = $this->today(); - - if (empty($day)) { - $day = $today['day']; - } - if (empty($month)) { - $month = $today['month']; - } - if (empty($year)) { - $year = $today['year']; - } - } - - $g_date = $this->to_gregorian($day, $month, $year); - - return mktime($hour, $minute, $second, $g_date['month'], $g_date['day'], $g_date['year']); - } - - public function dayofweek($day, $month, $year) { - $g_date = $this->to_gregorian($day, $month, $year); - return intval(date('w', mktime(12, 0, 0, $g_date['month'], $g_date['day'], $g_date['year']))); - } - - - private $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - private $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); - - private function isleap_solar($year) { - /* 33-year cycles, it better matches Iranian rules */ - return (($year+16)%33+33)%33*8%33 < 8; - } - - private function from_gregorian($g_d, $g_m, $g_y) { - $gy = $g_y-1600; - $gm = $g_m-1; - $gd = $g_d-1; - - $g_day_no = 365*$gy+$this->div($gy+3,4)-$this->div($gy+99,100)+$this->div($gy+399,400); - - for ($i=0; $i < $gm; ++$i) - $g_day_no += $this->g_days_in_month[$i]; - if ($gm>1 && (($gy%4==0 && $gy%100!=0) || ($gy%400==0))) - /* leap and after Feb */ - ++$g_day_no; - $g_day_no += $gd; - - $j_day_no = $g_day_no-79; - - $j_np = $this->div($j_day_no, 12053); - $j_day_no %= 12053; - - $jy = 979+33*$j_np+4*$this->div($j_day_no,1461); - - $j_day_no %= 1461; - - if ($j_day_no >= 366) { - $jy += $this->div($j_day_no-1, 365); - $j_day_no = ($j_day_no-1)%365; - } - - for ($i = 0; $i < 11 && $j_day_no >= $this->j_days_in_month[$i]; ++$i) { - $j_day_no -= $this->j_days_in_month[$i]; - } - $jm = $i+1; - $jd = $j_day_no+1; - - - return array('year' => $jy, - 'month' => $jm, - 'day' => $jd); - } - - private function to_gregorian($j_d, $j_m, $j_y) { - $jy = $j_y-979; - $jm = $j_m-1; - $jd = $j_d-1; - - $j_day_no = 365*$jy + $this->div($jy, 33)*8 + $this->div($jy%33+3, 4); - for ($i=0; $i < $jm; ++$i) - $j_day_no += $this->j_days_in_month[$i]; - - $j_day_no += $jd; - - $g_day_no = $j_day_no+79; - - $gy = 1600 + 400*$this->div($g_day_no, 146097); /* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */ - $g_day_no = $g_day_no % 146097; - - $leap = true; - if ($g_day_no >= 36525) /* 36525 = 365*100 + 100/4 */ - { - $g_day_no--; - $gy += 100*$this->div($g_day_no, 36524); /* 36524 = 365*100 + 100/4 - 100/100 */ - $g_day_no = $g_day_no % 36524; - - if ($g_day_no >= 365) - $g_day_no++; - else - $leap = false; - } - - $gy += 4*$this->div($g_day_no, 1461); /* 1461 = 365*4 + 4/4 */ - $g_day_no %= 1461; - - if ($g_day_no >= 366) { - $leap = false; - - $g_day_no--; - $gy += $this->div($g_day_no, 365); - $g_day_no = $g_day_no % 365; - } - - for ($i = 0; $g_day_no >= $this->g_days_in_month[$i] + ($i == 1 && $leap); $i++) - $g_day_no -= $this->g_days_in_month[$i] + ($i == 1 && $leap); - $gm = $i+1; - $gd = $g_day_no+1; - - return array('year' => $gy, - 'month' => $gm, - 'day' => $gd); - } - - private function div($a,$b) { - return (int) ($a / $b); - } -} -?> \ No newline at end of file diff --git a/calendarsystem/jalali/lang/en/calendarsystem_jalali.php b/calendarsystem/jalali/lang/en/calendarsystem_jalali.php deleted file mode 100644 index 64a7a86cef1..00000000000 --- a/calendarsystem/jalali/lang/en/calendarsystem_jalali.php +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/calendarsystem/jalali/lang/fa/calendarsystem_jalali.php b/calendarsystem/jalali/lang/fa/calendarsystem_jalali.php deleted file mode 100644 index 35d662c7c9f..00000000000 --- a/calendarsystem/jalali/lang/fa/calendarsystem_jalali.php +++ /dev/null @@ -1,27 +0,0 @@ - \ No newline at end of file diff --git a/calendarsystem/jalali/version.php b/calendarsystem/jalali/version.php deleted file mode 100644 index bb397749d64..00000000000 --- a/calendarsystem/jalali/version.php +++ /dev/null @@ -1,31 +0,0 @@ -. - -/** - * Version details - * - * @package calendarsystem - * @subpackage jalali - * @author Shamim Rezaie - * @copyright 2008 onwards Foodle Group {@link http://foodle.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$plugin->version = 2013011900; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2012120300; // Requires this Moodle version -$plugin->component = 'calendarsystem_jalali'; // Full name of the plugin (used for diagnostics) diff --git a/calendarsystem/updatechecker.php b/calendarsystem/updatechecker.php deleted file mode 100644 index cc6b69da3c9..00000000000 --- a/calendarsystem/updatechecker.php +++ /dev/null @@ -1,341 +0,0 @@ - (string)version list of additional plugins deployed at this site */ - protected $currentplugins = array(); - - /** - * Direct initiation not allowed, use the factory method {@link self::instance()} - */ - protected function __construct() { - } - - /** - * Sorry, this is singleton - */ - protected function __clone() { - } - - /** - * Factory method for this class - * - * @return calendarsystem_update_checker the singleton instance - */ - public static function instance() { - if (is_null(self::$singletoninstance)) { - self::$singletoninstance = new self(); - } - return self::$singletoninstance; - } - - /** - * Returns the timestamp of the last execution of {@link fetch()} - * - * @return int|null null if it has never been executed or we don't known - */ - public function get_last_timefetched() { - - $this->restore_response(); - - if (!empty($this->recentfetch)) { - return $this->recentfetch; - - } else { - return null; - } - } - - /** - * Fetches the available update status from the remote site - * - * @throws available_update_checker_exception - */ - public function fetch() { - $response = $this->get_response(); - $this->validate_response($response); - $this->store_response($response); - } - - /** - * Returns the available update information for the given component - * - * This method returns null if the most recent response does not contain any information - * about it. The returned structure is an array of available updates for the given - * component. Each update info is an object with at least one property called - * 'version'. Other possible properties are 'release', 'maturity', 'url' and 'downloadurl'. - * - * For the 'core' component, the method returns real updates only (those with higher version). - * For all other components, the list of all known remote updates is returned and the caller - * (usually the {@link plugin_manager}) is supposed to make the actual comparison of versions. - * - * @param string $component frankenstyle - * @param array $options with supported keys 'minmaturity' and/or 'notifybuilds' - * @return null|array null or array of calendarsystem_update_info objects - */ - public function get_update_info($component, array $options = array()) { - - if ($component == 'core') { - $this->load_current_environment(); - } - - $this->restore_response(); - - if (empty($this->recentresponse['updates'][$component])) { - return null; - } - - $updates = array(); - foreach ($this->recentresponse['updates'][$component] as $info) { - $update = new calendarsystem_update_info($component, $info); - if ($update->version <= $this->currentversion) { - continue; - } - $updates[] = $update; - } - - if (empty($updates)) { - return null; - } - - return $updates; - } - - /** - * Makes cURL request to get data from the remote site - * - * @return string raw request result - * @throws calendarsystem_update_checker_exception - */ - protected function get_response() { - global $CFG; - require_once($CFG->libdir.'/filelib.php'); - - $curl = new curl(array('proxy' => true)); - $response = $curl->post($this->prepare_request_url(), $this->prepare_request_params()); - $curlerrno = $curl->get_errno(); - if (!empty($curlerrno)) { - throw new calendarsystem_update_checker_exception('err_response_curl', 'cURL error '.$curlerrno.': '.$curl->error); - } - $curlinfo = $curl->get_info(); - if ($curlinfo['http_code'] != 200) { - throw new calendarsystem_update_checker_exception('err_response_http_code', $curlinfo['http_code']); - } - return $response; - } - -/////////////////////////// -// ino ezafe karde boodam - /** - * Makes sure the response is valid, has correct API format etc. - * - * @param string $response raw response as returned by the {@link self::get_response()} - * @throws calendarsystem_update_checker_exception - */ - protected function validate_response($response) { - - $response = $this->decode_response($response); - - if (empty($response)) { - throw new calendarsystem_update_checker_exception('err_response_empty'); - } - - if (empty($response['status']) or $response['status'] !== 'OK') { - throw new calendarsystem_update_checker_exception('err_response_status', $response['status']); - } - } - - /* Decodes the raw string response from the update notifications provider - * - * @param string $response as returned by {@link self::get_response()} - * @return array decoded response structure - */ - protected function decode_response($response) { - return json_decode($response, true); - } - - /** - * Stores the valid fetched response for later usage - * - * This implementation uses the config_plugins table as the permanent storage. - * - * @param string $response raw valid data returned by {@link self::get_response()} - */ - protected function store_response($response) { - - set_config('recentfetch', time(), 'calendarsystem_plugin'); - set_config('recentresponse', $response, 'calendarsystem_plugin'); - - $this->restore_response(true); - } - - /** - * Loads the most recent raw response record we have fetched - * - * After this method is called, $this->recentresponse is set to an array. If the - * array is empty, then either no data have been fetched yet or the fetched data - * do not have expected format (and thence they are ignored and a debugging - * message is displayed). - * - * This implementation uses the config_plugins table as the permanent storage. - * - * @param bool $forcereload reload even if it was already loaded - */ - protected function restore_response($forcereload = false) { - - if (!$forcereload and !is_null($this->recentresponse)) { - // we already have it, nothing to do - return; - } - - $config = get_config('calendarsystem_plugin'); - - if (!empty($config->recentresponse) and !empty($config->recentfetch)) { - try { - $this->validate_response($config->recentresponse); - $this->recentfetch = $config->recentfetch; - $this->recentresponse = $this->decode_response($config->recentresponse); - } catch (calendarsystem_update_checker_exception $e) { - // The server response is not valid. Behave as if no data were fetched yet. - // This may happen when the most recent update info (cached locally) has been - // fetched with the previous branch of Moodle (like during an upgrade from 2.x - // to 2.y) or when the API of the response has changed. - $this->recentresponse = array(); - } - - } else { - $this->recentresponse = array(); - } - } - - /** - * Returns the URL to send update requests to - * - * @return string URL - */ - protected function prepare_request_url() { - return 'http://foodle.org/calendarsystem/api/updates.php'; - } - - /** - * Sets the properties currentversion, currentrelease, currentbranch and currentplugins - * - * @param bool $forcereload - */ - protected function load_current_environment($forcereload=false) { - global $CFG; - - if (!is_null($this->currentversion) and !$forcereload) { - // nothing to do - return; - } - - $version = null; - $plugin = new stdClass(); - - include($CFG->dirroot.'/calendarsystem/version.php'); - $this->currentversion = $version; - - $calendars = get_plugin_list('calendarsystem'); - - foreach ($calendars as $calendar => $calendarrootdir) { - include($calendarrootdir.'/version.php'); - $this->currentplugins[$calendar] = $plugin->version; - } - } - - /** - * Returns the list of HTTP params to be sent to the updates provider URL - * - * @return array of (string)param => (string)value - */ - protected function prepare_request_params() { - global $CFG; - - $this->load_current_environment(); -// $this->restore_response(); - - $params = array(); - $params['format'] = 'json'; - - if (isset($this->currentversion)) { - $params['version'] = $this->currentversion; - } else { - throw new coding_exception('Main calendarsystem version must be already known here'); - } - - $plugins = array(); - foreach ($this->currentplugins as $plugin => $version) { - $plugins[] = $plugin.'@'.$version; - } - if (!empty($plugins)) { - $params['plugins'] = implode(',', $plugins); - } - - $params['url'] = $CFG->wwwroot; - - return $params; - } - -} - -/** - * Defines the structure of objects returned by {@link calendarsystem_update_checker::get_update_info()} - */ -class calendarsystem_update_info { - - /** @var string frankenstyle component name */ - public $component; - /** @var int the available version of the component */ - public $version; - /** @var string|null optional URL of a page with more info about the update */ - public $url = null; - /** @var string|null optional URL of a ZIP package that can be downloaded and installed */ - public $download = null; - /** @var string|null if self::download is set, then this must be the MD5 hash of the ZIP */ - public $downloadmd5 = null; - - /** - * Creates new instance of the class - * - * The $info array must provide at least the 'version' value and optionally all other - * values to populate the object's properties. - * - * @param string $name the frankenstyle component name - * @param array $info associative array with other properties - */ - public function __construct($name, array $info) { - $this->component = $name; - foreach ($info as $k => $v) { - if (property_exists('calendarsystem_update_info', $k) and $k != 'component') { - $this->$k = $v; - } - } - } -} -?> \ No newline at end of file diff --git a/course/edit_form.php b/course/edit_form.php index 983a7e0fb75..ca311ef4083 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -6,12 +6,18 @@ require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/completionlib.php'); require_once($CFG->libdir. '/coursecatlib.php'); +/** + * The form for handling editing a course. + */ class course_edit_form extends moodleform { protected $course; protected $context; + /** + * Form definition. + */ function definition() { - global $USER, $CFG, $DB, $PAGE; + global $CFG, $PAGE; $mform = $this->_form; $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', @@ -38,8 +44,7 @@ class course_edit_form extends moodleform { $this->course = $course; $this->context = $context; -/// form definition with new course defaults -//-------------------------------------------------------------------------------- + // Form definition with new course defaults. $mform->addElement('header','general', get_string('general', 'form')); $mform->addElement('hidden', 'returnto', null); @@ -247,10 +252,8 @@ class course_edit_form extends moodleform { $mform->setDefault('enablecompletion', 0); } -//-------------------------------------------------------------------------------- enrol_course_edit_form($mform, $course, $context); -//-------------------------------------------------------------------------------- $mform->addElement('header','groups', get_string('groupsettingsheader', 'group')); $choices = array(); @@ -270,17 +273,15 @@ class course_edit_form extends moodleform { $options[0] = get_string('none'); $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options); -//-------------------------------------------------------------------------------- - // MDL-18375, Multi-Calendar Support + // Multi-Calendar Support - see MDL-18375 $mform->addElement('header','', get_string('calendar', 'calendar')); - $calendarsystems = array(); - $calendarsystems[''] = get_string('forceno'); - $calendarsystems += get_list_of_calendars(); - $mform->addElement('select', 'calendarsystem', get_string('forcecalendarsystem', 'calendarsystem'), $calendarsystems); + $calendartypes = array(); + $calendartypes[''] = get_string('forceno'); + $calendartypes += calendar_type_plugin_factory::get_list_of_calendar_types(); + $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendartypes); -/// customizable role names in this course -//-------------------------------------------------------------------------------- + // Customizable role names in this course. $mform->addElement('header','rolerenaming', get_string('rolerenaming')); $mform->addHelpButton('rolerenaming', 'rolerenaming'); @@ -293,17 +294,18 @@ class course_edit_form extends moodleform { } } -//-------------------------------------------------------------------------------- $this->add_action_buttons(); -//-------------------------------------------------------------------------------- + $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); -/// finally set the current form data -//-------------------------------------------------------------------------------- + // Finally set the current form data $this->set_data($course); } + /** + * Fill in the current page data for this course. + */ function definition_after_data() { global $DB; @@ -334,7 +336,13 @@ class course_edit_form extends moodleform { } } -/// perform some extra moodle validation + /** + * Validation. + * + * @param array $data + * @param array $files + * @return array the errors that were found + */ function validation($data, $files) { global $DB, $CFG; diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index 6fcdb8dd1f8..c1a6f80c9b3 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -113,10 +113,8 @@ switch ($action) { break; case 3: default: - // MDL-18375, Multi-Calendar Support - $calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); $today = time(); - $today = $calendarsystem_gregorian->make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); + $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); $timestart = $today; break; } diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 03b2a9883c1..10e12e1e4b0 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -230,10 +230,8 @@ class enrol_manual_plugin extends enrol_plugin { if ($startdate > 0) { $startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $timeformat) . ')'; } - // MDL-18375, Multi-Calendar Support - $calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); $today = time(); - $today = $calendarsystem_gregorian->make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); + $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); $startdateoptions[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ; $defaultduration = $instance->enrolperiod > 0 ? $instance->enrolperiod / 86400 : ''; diff --git a/enrol/manual/manage.php b/enrol/manual/manage.php index 96ac9de6650..7d91e4b6017 100644 --- a/enrol/manual/manage.php +++ b/enrol/manual/manage.php @@ -92,11 +92,8 @@ if ($extendperiod) { // Build the list of options for the starting from dropdown. $timeformat = get_string('strftimedatefullshort'); - -// MDL-18375, Multi-Calendar Support -$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); $today = time(); -$today = $calendarsystem_gregorian->make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); +$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); // Enrolment start. $basemenu = array(); diff --git a/lang/en/admin.php b/lang/en/admin.php index d230f6755c1..ef68ec963b6 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -570,8 +570,9 @@ $string['gradeexport'] = 'Primary grade export methods'; $string['guestroleid'] = 'Role for guest'; $string['guestroleid_help'] = 'This role is automatically assigned to the guest user. It is also temporarily assigned to not enrolled users that enter the course via guest enrolment plugin.'; $string['helpadminseesall'] = 'Do admins see all calendar events or just those that apply to themselves?'; -$string['helpcalendarsettings'] = 'Configure various calendar and date/time-related aspects of Moodle'; $string['helpcalendarcustomexport'] = 'Enable custom date range export option in calendar exports. Calendar exports must be enabled before this is effective.'; +$string['helpcalendarsettings'] = 'Configure various calendar and date/time-related aspects of Moodle'; +$string['helpcalendartype'] = 'This is the calendar type that will be used throughout your site.'; $string['helpexportlookahead'] = 'How many days in the future does the calendar look for events during export for the custom export option?'; $string['helpexportlookback'] = 'How many days in the past does the calendar look for events during export for the custom export option?'; $string['helpforcetimezone'] = 'You can allow users to individually select their timezone, or force a timezone for everyone.'; diff --git a/lang/en/calendar.php b/lang/en/calendar.php index 75d51b9dcb6..7a6a6aff494 100644 --- a/lang/en/calendar.php +++ b/lang/en/calendar.php @@ -93,6 +93,7 @@ $string['export'] = 'Export'; $string['exportbutton'] = 'Export'; $string['exportcalendar'] = 'Export calendar'; $string['for'] = 'for'; +$string['forcecalendartype'] = 'Force calendar'; $string['fri'] = 'Fri'; $string['friday'] = 'Friday'; $string['generateurlbutton'] = 'Get calendar URL'; @@ -138,6 +139,7 @@ $string['pollinterval'] = 'Update interval'; $string['pollinterval_help'] = 'How often you would like the calendar to update with new events.'; $string['preferences'] = 'Preferences'; $string['preferences_available'] = 'Your personal preferences'; +$string['preferredcalendar'] = 'Preferred calendar'; $string['pref_lookahead'] = 'Upcoming events look-ahead'; $string['pref_lookahead_help'] = 'This sets the (maximum) number of days in the future that an event has to start in in order to be displayed as an upcoming event. Events that start beyond this will never be displayed as upcoming. Please note that there is no guarantee that all events starting in this time frame will be displayed; if there are too many (more than the "Maximum upcoming events" preference) then the most distant events will not be shown.'; $string['pref_maxevents'] = 'Maximum upcoming events'; diff --git a/lang/en/calendarsystem.php b/lang/en/calendarsystem.php deleted file mode 100644 index 51b607c0a84..00000000000 --- a/lang/en/calendarsystem.php +++ /dev/null @@ -1,19 +0,0 @@ - \ No newline at end of file diff --git a/lang/en/plugin.php b/lang/en/plugin.php index 630dbf64789..f1e79585dbf 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -91,7 +91,8 @@ $string['type_cachelock'] = 'Cache lock handler'; $string['type_cachelock_plural'] = 'Cache lock handlers'; $string['type_cachestore'] = 'Cache store'; $string['type_cachestore_plural'] = 'Cache stores'; -$string['type_calendarsystem_plural'] = 'Calendar systems'; +$string['type_calendartype'] = 'Calendar type'; +$string['type_calendartype_plural'] = 'Calendar types'; $string['type_coursereport'] = 'Course report'; $string['type_coursereport_plural'] = 'Course reports'; $string['type_editor'] = 'Editor'; diff --git a/lib/bennu/iCalendar_rfc2445.php b/lib/bennu/iCalendar_rfc2445.php index ffe4f85daff..d221217c610 100644 --- a/lib/bennu/iCalendar_rfc2445.php +++ b/lib/bennu/iCalendar_rfc2445.php @@ -203,9 +203,7 @@ function rfc2445_is_valid_value($value, $type) { $m = intval(substr($value, 4, 2)); $d = intval(substr($value, 6, 2)); - // MDL-18375, Multi-Calendar Support - $calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); - return $calendarsystem_gregorian->checkdate($m, $d, $y); + return checkdate($m, $d, $y); break; case RFC2445_TYPE_DATE_TIME: diff --git a/lib/classes/component.php b/lib/classes/component.php index d5ec8ac8597..7e63b28bd6d 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -341,6 +341,7 @@ $cache = '.var_export($cache, true).'; 'qtype' => $CFG->dirroot.'/question/type', 'mod' => $CFG->dirroot.'/mod', 'auth' => $CFG->dirroot.'/auth', + 'calendartype' => $CFG->dirroot.'/calendar/type', 'enrol' => $CFG->dirroot.'/enrol', 'message' => $CFG->dirroot.'/message/output', 'block' => $CFG->dirroot.'/blocks', diff --git a/lib/db/install.xml b/lib/db/install.xml index ac6eb778b64..e26ab472a00 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -93,7 +93,7 @@ - + @@ -772,7 +772,7 @@ - + diff --git a/lib/form/dateselector.php b/lib/form/dateselector.php index d578e84572e..5e6ddea89a9 100644 --- a/lib/form/dateselector.php +++ b/lib/form/dateselector.php @@ -39,12 +39,10 @@ require_once($CFG->libdir . '/formslib.php'); * @copyright 2007 Jamie Pratt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class MoodleQuickForm_date_selector extends MoodleQuickForm_group -{ +class MoodleQuickForm_date_selector extends MoodleQuickForm_group { + /** - * Control the fieldnames for form elements - * - * MDL-18375, Multi-Calendar Support + * Control the fieldnames for form elements. * * startyear => int start of range of years that can be selected * stopyear => int last year that can be selected @@ -78,13 +76,11 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * @param array $options Options to control the element's display * @param mixed $attributes Either a typical HTML attribute string or an associative array */ - function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) - { - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; - - $this->_options = array('startyear'=> $CALENDARSYSTEM->get_min_year(), 'stopyear'=>$CALENDARSYSTEM->get_max_year(), - 'timezone'=>99, 'optional'=>false); + function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { + // Get the calendar type used - see MDL-18375. + $calendartype = calendar_type_plugin_factory::factory(); + $this->_options = array('startyear' => $calendartype->get_min_year(), 'stopyear' => $calendartype->get_max_year(), + 'defaulttime' => 0, 'timezone' => 99, 'step' => 5, 'optional' => false); $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; @@ -111,18 +107,18 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * * @access private */ - function _createElements() - { - global $OUTPUT, $CALENDARSYSTEM; + function _createElements() { + global $OUTPUT; - $this->_elements = array(); - for ($i=1; $i<=31; $i++) { - $days[$i] = $i; - } - $months = $CALENDARSYSTEM->get_month_names(); - for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) { + // Get the calendar type used - see MDL-18375. + $calendartype = calendar_type_plugin_factory::factory(); + $days = $calendartype->get_days(); + $months = $calendartype->get_months(); + for ($i = $this->_options['startyear']; $i <= $this->_options['stopyear']; $i++) { $years[$i] = $i; } + + $this->_elements = array(); // E_STRICT creating elements without forms is nasty because it internally uses $this $this->_elements[] = @MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true); $this->_elements[] = @MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true); @@ -149,8 +145,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * @param object $caller calling object * @return bool */ - function onQuickFormEvent($event, $arg, &$caller) - { + function onQuickFormEvent($event, $arg, &$caller) { switch ($event) { case 'updateValue': // constant values override both default and submitted ones @@ -176,7 +171,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group 'month' => $currentdate['mon'], 'year' => $currentdate['year']); // If optional, default to off, unless a date was provided - if($this->_options['optional']) { + if($this->_options['optional']) { $value['enabled'] = $requestvalue != 0; } } else { @@ -216,8 +211,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * * @return string */ - function toHtml() - { + function toHtml() { include_once('HTML/QuickForm/Renderer/Default.php'); $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); @@ -241,8 +235,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * @param bool $required Whether a group is required * @param string $error An error message associated with a group */ - function accept(&$renderer, $required = false, $error = null) - { + function accept(&$renderer, $required = false, $error = null) { $renderer->renderElement($this, $required, $error); } @@ -253,8 +246,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group * @param bool $assoc specifies if returned array is associative * @return array */ - function exportValue(&$submitValues, $assoc = false) - { + function exportValue(&$submitValues, $assoc = false) { $value = null; $valuearray = array(); foreach ($this->_elements as $element){ @@ -271,13 +263,15 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group return $value; } } - - $value[$this->getName()] = make_timestamp($valuearray['year'], - $valuearray['month'], - $valuearray['day'], - 0, 0, 0, - $this->_options['timezone'], - true); + // Get the calendar type used - see MDL-18375. + $calendartype = core_calendar\type_factory::factory(); + $gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], $valuearray['month'], $valuearray['day']); + $value[$this->getName()] = make_timestamp($gregoriandate['year'], + $gregoriandate['month'], + $gregoriandate['day'], + 0, 0, 0, + $this->_options['timezone'], + true); return $value; } else { diff --git a/lib/form/datetimeselector.php b/lib/form/datetimeselector.php index cf4f884a49e..40a58132d95 100644 --- a/lib/form/datetimeselector.php +++ b/lib/form/datetimeselector.php @@ -39,11 +39,10 @@ require_once($CFG->libdir . '/formslib.php'); * @copyright 2006 Jamie Pratt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ +class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group { + /** - * Options for the element - * - * MDL-18375, Multi-Calendar Support + * Options for the element. * * startyear => int start of range of years that can be selected * stopyear => int last year that can be selected @@ -79,13 +78,11 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ * @param array $options Options to control the element's display * @param mixed $attributes Either a typical HTML attribute string or an associative array */ - function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) - { - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; - - $this->_options = array('startyear'=> $CALENDARSYSTEM->get_min_year(), 'stopyear'=>$CALENDARSYSTEM->get_max_year(), - 'defaulttime' => 0, 'timezone'=>99, 'step'=>5, 'optional'=>false); + function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { + // Get the calendar type used - see MDL-18375. + $calendartype = calendar_type_plugin_factory::factory(); + $this->_options = array('startyear' => $calendartype->get_min_year(), 'stopyear' => $calendartype->get_max_year(), + 'defaulttime' => 0, 'timezone' => 99, 'step' => 5, 'optional' => false); $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; @@ -112,16 +109,14 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ * * @access private */ - function _createElements() - { - global $OUTPUT, $CALENDARSYSTEM; + function _createElements() { + global $OUTPUT; - $this->_elements = array(); - for ($i=1; $i<=31; $i++) { - $days[$i] = $i; - } - $months = $CALENDARSYSTEM->get_month_names(); - for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) { + // Get the calendar type used - see MDL-18375. + $calendartype = calendar_type_plugin_factory::factory(); + $days = $calendartype->get_days(); + $months = $calendartype->get_months(); + for ($i = $this->_options['startyear']; $i <= $this->_options['stopyear']; $i++) { $years[$i] = $i; } for ($i=0; $i<=23; $i++) { @@ -130,6 +125,8 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ for ($i=0; $i<60; $i+=$this->_options['step']) { $minutes[$i] = sprintf("%02d",$i); } + + $this->_elements = array(); // E_STRICT creating elements without forms is nasty because it internally uses $this $this->_elements[] = @MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true); $this->_elements[] = @MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true); @@ -163,8 +160,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ * @param object $caller calling object * @return bool */ - function onQuickFormEvent($event, $arg, &$caller) - { + function onQuickFormEvent($event, $arg, &$caller) { switch ($event) { case 'updateValue': // constant values override both default and submitted ones @@ -237,8 +233,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ * * @return string */ - function toHtml() - { + function toHtml() { include_once('HTML/QuickForm/Renderer/Default.php'); $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); @@ -262,8 +257,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ * @param bool $required Whether a group is required * @param string $error An error message associated with a group */ - function accept(&$renderer, $required = false, $error = null) - { + function accept(&$renderer, $required = false, $error = null) { $renderer->renderElement($this, $required, $error); } @@ -274,8 +268,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ * @param bool $assoc specifies if returned array is associative * @return array */ - function exportValue(&$submitValues, $assoc = false) - { + function exportValue(&$submitValues, $assoc = false) { $value = null; $valuearray = array(); foreach ($this->_elements as $element){ @@ -292,20 +285,24 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ return $value; } } - $valuearray=$valuearray + array('year' => 1970, 'month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0); - $value[$this->getName()] = make_timestamp( - $valuearray['year'], - $valuearray['month'], - $valuearray['day'], - $valuearray['hour'], - $valuearray['minute'], - 0, - $this->_options['timezone'], - true); + // Get the calendar type used - see MDL-18375. + $calendartype = core_calendar\type_factory::factory(); + $gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], + $valuearray['month'], + $valuearray['day'], + $valuearray['hour'], + $valuearray['minute']); + $value[$this->getName()] = make_timestamp($gregoriandate['year'], + $gregoriandate['month'], + $gregoriandate['day'], + $gregoriandate['hour'], + $gregoriandate['minute'], + 0, + $this->_options['timezone'], + true); return $value; } else { - return null; } } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index e01f2b64780..3d82e230610 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2003,8 +2003,6 @@ function get_user_preferences($name = null, $default = null, $user = null) { /** * Given date parts in user time produce a GMT timestamp. * - * MDL-18375, Multi-Calendar Support - * * @package core * @category time * @param int $year The year part to create timestamp of @@ -2020,16 +2018,6 @@ function get_user_preferences($name = null, $default = null, $user = null) { * @return int GMT timestamp */ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) { - global $CALENDARSYSTEM; - if ($CALENDARSYSTEM->get_min_year() == 1350 && $year > 2000) { - debugging('Warning. Wrong call to make_timestamp().', DEBUG_DEVELOPER); - error('Your code must be fixed by a developer.'); - } - return $CALENDARSYSTEM->make_timestamp($year, $month, $day, $hour, $minute, $second, $timezone, $applydst); -} - -// MDL-18375, Multi-Calendar Support -function make_timestamp_old($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) { // Save input timezone, required for dst offset check. $passedtimezone = $timezone; @@ -2156,8 +2144,6 @@ function format_time($totalsecs, $str = null) { * If parameter fixday = true (default), then take off leading * zero from %d, else maintain it. * - * MDL-18375, Multi-Calendar Support - * * @package core * @category time * @param int $date the timestamp in UTC, as obtained from the database. @@ -2172,77 +2158,8 @@ function format_time($totalsecs, $str = null) { * @return string the formatted date/time. */ function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour = true) { - global $CALENDARSYSTEM; - return $CALENDARSYSTEM->userdate($date, $format, $timezone, $fixday, $fixhour); -} - -// MDL-18375, Multi-Calendar Support -function userdate_old($date, $format = '', $timezone = 99, $fixday = true, $fixhour = true) { - - global $CFG; - - if (empty($format)) { - $format = get_string('strftimedaydatetime', 'langconfig'); - } - - if (!empty($CFG->nofixday)) { - // Config.php can force %d not to be fixed. - $fixday = false; - } else if ($fixday) { - $formatnoday = str_replace('%d', 'DD', $format); - $fixday = ($formatnoday != $format); - $format = $formatnoday; - } - - // Note: This logic about fixing 12-hour time to remove unnecessary leading - // zero is required because on Windows, PHP strftime function does not - // support the correct 'hour without leading zero' parameter (%l). - if (!empty($CFG->nofixhour)) { - // Config.php can force %I not to be fixed. - $fixhour = false; - } else if ($fixhour) { - $formatnohour = str_replace('%I', 'HH', $format); - $fixhour = ($formatnohour != $format); - $format = $formatnohour; - } - - // Add daylight saving offset for string timezones only, as we can't get dst for - // float values. if timezone is 99 (user default timezone), then try update dst. - if ((99 == $timezone) || !is_numeric($timezone)) { - $date += dst_offset_on($date, $timezone); - } - - $timezone = get_user_timezone_offset($timezone); - - // If we are running under Windows convert to windows encoding and then back to UTF-8 - // (because it's impossible to specify UTF-8 to fetch locale info in Win32). - - if (abs($timezone) > 13) { - // Server time. - $datestring = date_format_string($date, $format, $timezone); - if ($fixday) { - $daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $date))); - $datestring = str_replace('DD', $daystring, $datestring); - } - if ($fixhour) { - $hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $date))); - $datestring = str_replace('HH', $hourstring, $datestring); - } - - } else { - $date += (int)($timezone * 3600); - $datestring = date_format_string($date, $format, $timezone); - if ($fixday) { - $daystring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $date))); - $datestring = str_replace('DD', $daystring, $datestring); - } - if ($fixhour) { - $hourstring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %I', $date))); - $datestring = str_replace('HH', $hourstring, $datestring); - } - } - - return $datestring; + $calendartype = calendar_type_plugin_factory::factory(); + return $calendartype->userdate($date, $format, $timezone, $fixday, $fixhour); } /** @@ -2287,8 +2204,6 @@ function date_format_string($date, $format, $tz = 99) { * Given a $time timestamp in GMT (seconds since epoch), * returns an array that represents the date in user time * - * MDL-18375, Multi-Calendar Support - * * @package core * @category time * @uses HOURSECS @@ -2297,58 +2212,9 @@ function date_format_string($date, $format, $tz = 99) { * dst offset is applied {@link http://docs.moodle.org/dev/Time_API#Timezone} * @return array An array that represents the date in user time */ - function usergetdate($time, $timezone=99) { - global $CALENDARSYSTEM; - return $CALENDARSYSTEM->usergetdate($time, $timezone); -} - -// MDL-18375, Multi-Calendar Support -function usergetdate_old($time, $timezone=99) { - - // Save input timezone, required for dst offset check. - $passedtimezone = $timezone; - - $timezone = get_user_timezone_offset($timezone); - - if (abs($timezone) > 13) { - // Server time. - return getdate($time); - } - - // Add daylight saving offset for string timezones only, as we can't get dst for - // float values. if timezone is 99 (user default timezone), then try update dst. - if ($passedtimezone == 99 || !is_numeric($passedtimezone)) { - $time += dst_offset_on($time, $passedtimezone); - } - - $time += intval((float)$timezone * HOURSECS); - - $datestring = gmstrftime('%B_%A_%j_%Y_%m_%w_%d_%H_%M_%S', $time); - - // Be careful to ensure the returned array matches that produced by getdate() above. - list( - $getdate['month'], - $getdate['weekday'], - $getdate['yday'], - $getdate['year'], - $getdate['mon'], - $getdate['wday'], - $getdate['mday'], - $getdate['hours'], - $getdate['minutes'], - $getdate['seconds'] - ) = explode('_', $datestring); - - // Set correct datatype to match with getdate(). - $getdate['seconds'] = (int)$getdate['seconds']; - $getdate['yday'] = (int)$getdate['yday'] - 1; // The function gmstrftime returns 0 through 365. - $getdate['year'] = (int)$getdate['year']; - $getdate['mon'] = (int)$getdate['mon']; - $getdate['wday'] = (int)$getdate['wday']; - $getdate['mday'] = (int)$getdate['mday']; - $getdate['hours'] = (int)$getdate['hours']; - $getdate['minutes'] = (int)$getdate['minutes']; - return $getdate; +function usergetdate($time, $timezone = 99) { + $calendartype = calendar_type_plugin_factory::factory(); + return $calendartype->usergetdate($time, $timezone); } /** @@ -2672,8 +2538,6 @@ function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone /** * Calculates the required DST change and returns a Timestamp Array * - * MDL-18375, Multi-Calendar Support - * * @package core * @category time * @uses HOURSECS @@ -2695,10 +2559,8 @@ function dst_changes_for_year($year, $timezone) { list($dsthour, $dstmin) = explode(':', $timezone->dst_time); list($stdhour, $stdmin) = explode(':', $timezone->std_time); - // MDL-18375, Multi-Calendar Support - $calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); - $timedst = $calendarsystem_gregorian->make_timestamp($year, $timezone->dst_month, $monthdaydst, 0, 0, 0, 99, false); - $timestd = $calendarsystem_gregorian->make_timestamp($year, $timezone->std_month, $monthdaystd, 0, 0, 0, 99, false); + $timedst = make_timestamp($year, $timezone->dst_month, $monthdaydst, 0, 0, 0, 99, false); + $timestd = make_timestamp($year, $timezone->std_month, $monthdaystd, 0, 0, 0, 99, false); // Instead of putting hour and minute in make_timestamp(), we add them afterwards. // This has the advantage of being able to have negative values for hour, i.e. for timezones @@ -2774,9 +2636,6 @@ function dst_offset_on($time, $strtimezone = null) { */ function find_day_in_month($startday, $weekday, $month, $year) { - // MDL-18375, Multi-Calendar Support - $calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian'); - $daysinmonth = days_in_month($month, $year); if ($weekday == -1) { @@ -2798,7 +2657,7 @@ function find_day_in_month($startday, $weekday, $month, $year) { if ($startday < 1) { $startday = abs($startday); - $lastmonthweekday = strftime('%w', $calendarsystem_gregorian->mktime(12, 0, 0, $month, $daysinmonth, $year)); + $lastmonthweekday = strftime('%w', mktime(12, 0, 0, $month, $daysinmonth, $year)); // This is the last such weekday of the month. $lastinmonth = $daysinmonth + $weekday - $lastmonthweekday; @@ -2815,7 +2674,7 @@ function find_day_in_month($startday, $weekday, $month, $year) { } else { - $indexweekday = strftime('%w', $calendarsystem_gregorian->mktime(12, 0, 0, $month, $startday, $year)); + $indexweekday = strftime('%w', mktime(12, 0, 0, $month, $startday, $year)); $diff = $weekday - $indexweekday; if ($diff < 0) { @@ -2846,8 +2705,6 @@ function days_in_month($month, $year) { /** * Calculate the position in the week of a specific calendar day * - * MDL-18375, Multi-Calendar Support - * * @package core * @category time * @param int $day The day of the date whose position in the week is sought @@ -2856,9 +2713,8 @@ function days_in_month($month, $year) { * @return int */ function dayofweek($day, $month, $year) { - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; - return $CALENDARSYSTEM->dayofweek($day, $month, $year); + // I wonder if this is any different from strftime('%w', mktime(12, 0, 0, $month, $daysinmonth, $year, 0));. + return intval(date('w', mktime(12, 0, 0, $month, $day, $year))); } // USER AUTHENTICATION AND LOGIN. diff --git a/lib/setup.php b/lib/setup.php index 27fb471b5ad..732fbfc99b0 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -482,13 +482,6 @@ global $FULLSCRIPT; */ global $SCRIPT; -/** - * MDL-18375, Multi-Calendar Support - * - * $CALENDARSYSTEM is a global that defines the calendar system - */ -global $CALENDARSYSTEM; - // Set httpswwwroot default value (this variable will replace $CFG->wwwroot // inside some URLs used in HTTPSPAGEREQUIRED pages. $CFG->httpswwwroot = $CFG->wwwroot; @@ -568,7 +561,7 @@ require_once($CFG->libdir .'/editorlib.php'); // All text editor related f require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions require_once($CFG->libdir .'/modinfolib.php'); // Cached information on course-module instances require_once($CFG->dirroot.'/cache/lib.php'); // Cache API -require_once($CFG->dirroot . '/calendarsystem/calendarsystem.class.php'); // MDL-18375, Multi-Calendar Support +require_once($CFG->dirroot.'/calendar/type/calendartype.class.php'); // Calendar type. // make sure PHP is not severly misconfigured setup_validate_php_configuration(); @@ -979,26 +972,6 @@ if (isset($CFG->maintenance_later) and $CFG->maintenance_later <= time()) { } } -// MDL-18375, Multi-Calendar Support -// note: do not accept calendarsystem parameter from POST -if (isset($_GET['calendarsystem']) and ($calendarsystem = optional_param('calendarsystem', '', PARAM_SAFEDIR))) { - if (file_exists($CFG->dirroot .'/calendarsystem/'. $calendarsystem)) { - $SESSION->calendarsystem = $calendarsystem; - } -} - -unset($calendarsystem); - -if (empty($CFG->calendarsystem)) { - if (empty($SESSION->calendarsystem)) { - $CFG->calendarsystem = 'gregorian'; - } else { - $CFG->calendarsystem = $SESSION->calendarsystem; - } -} - -$CALENDARSYSTEM = calendarsystem_plugin_factory::factory(); - // note: we can not block non utf-8 installations here, because empty mysql database // might be converted to utf-8 in admin/index.php during installation diff --git a/user/editlib.php b/user/editlib.php index 9b40e635389..7e3abf5eca0 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -262,9 +262,8 @@ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanager $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations()); $mform->setDefault('lang', $CFG->lang); - // MDL-18375, Multi-Calendar Support - $mform->addElement('select', 'calendarsystem', get_string('preferredcalendar', 'calendarsystem'), get_list_of_calendars()); - $mform->setDefault('calendarsystem', $CFG->calendarsystem); + // Multi-Calendar Support - see MDL-18375. + $mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), calendar_type_plugin_factory::get_list_of_calendar_types()); if (!empty($CFG->allowuserthemes)) { $choices = array(); diff --git a/user/profile/field/datetime/define.class.php b/user/profile/field/datetime/define.class.php index 53a9ad65f6e..5e454925b60 100644 --- a/user/profile/field/datetime/define.class.php +++ b/user/profile/field/datetime/define.class.php @@ -16,12 +16,8 @@ class profile_define_datetime extends profile_define_base { * @param object $form the user form */ function define_form_specific($form) { - // MDL-18375, Multi-Calendar Support - global $CALENDARSYSTEM; - // Create variables to store start and end - $userdate = $CALENDARSYSTEM->usergetdate(time()); - $currentyear = $userdate['year']; + $currentyear = date('Y'); $startyear = $currentyear - 100; $endyear = $currentyear + 20;