mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-18375 calendar: huge refactor of the initial patch
1) Moved the calendar types location to a sub-folder in the calendar directory. 2) Removed/moved language strings. 3) Removed calendar types that should be downloaded as plugins. 4) Removed a Non-English language pack for the Gregorian calendar type that should be downloaded separately. 5) Removed custom files responsible for checking for updates and uninstalling calendar types, which should be done by core. 6) Removed JS from the calendar_month block as there is no non-JS alternative provided and the JS written does not make use of the YUI library to ensure multiple browser support. 7) Removed code from the base class responsible for creating timestamps that are saved in the DB. 8) Added PHPDocs. Note: In the original patch we are editing core functions responsible for saving time in the database in the calendar base class. This is very dangerous, we do not want to touch these functions as it could cause a complete fubar of the database. There are places we are forcing the use of the gregorian calendar as we are passing dates generated by the PHP date function, where as sometimes we pass dates from usergetdate (which was being overwritten to return the date specific to the calendar). We can not expect third party modules to change the calendar type depending on the format they pass to these functions.
This commit is contained in:
parent
6dd59aabfa
commit
2f00e1b245
@ -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'),
|
||||
|
@ -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')));
|
||||
|
@ -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',
|
||||
|
@ -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 .= '<div class="filters calendar_filters">'.calendar_filter_controls($this->page->url).'</div>';
|
||||
}
|
||||
|
||||
// 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('<span style="font-weight: normal;">'.get_string('system', 'calendarsystem').'</span>');
|
||||
|
||||
$this->content->text .= '
|
||||
<div id="changecalendarlink" style="display: none; visibility: hidden;">
|
||||
<a style="font-weight: normal;" onclick="return toggleCalendarVisibility(document.getElementById(\'choosecalendar\'))" href="#">
|
||||
' . get_string('changecalendar', 'calendarsystem') . '
|
||||
</a>
|
||||
</div>
|
||||
' . $OUTPUT->render($calendarselect) . '
|
||||
<script language="JavaScript">
|
||||
function toggleCalendarVisibility (choosecalendar) {
|
||||
if (choosecalendar.style.visibility != "visible") {
|
||||
choosecalendar.style.display = "block";
|
||||
choosecalendar.style.visibility = "visible";
|
||||
} else {
|
||||
choosecalendar.style.display = "none";
|
||||
choosecalendar.style.visibility = "hidden";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
document.getElementById ( "choosecalendar" ).style.display = "none";
|
||||
document.getElementById ( "choosecalendar" ).style.visibility = "hidden";
|
||||
|
||||
document.getElementById ( "changecalendarlink" ).style.display = "inline";
|
||||
document.getElementById ( "changecalendarlink" ).style.visibility = "visible";
|
||||
</script>
|
||||
';
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
304
calendar/type/calendartype.class.php
Normal file
304
calendar/type/calendartype.class.php
Normal file
@ -0,0 +1,304 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Defines functions used by calendar type plugins.
|
||||
*
|
||||
* This library provides a unified interface for calendar types.
|
||||
*
|
||||
* @package core_calendar
|
||||
* @author Shamim Rezaie <support@foodle.org>
|
||||
* @author Mark Nelson <markn@moodle.com>
|
||||
* @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
|
||||
* <b>WARNING: note that the format is for strftime(), not date().</b>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -15,14 +16,12 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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';
|
133
calendar/type/gregorian/lib.php
Normal file
133
calendar/type/gregorian/lib.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Handles calendar functions for the gregorian calendar.
|
||||
*
|
||||
* @package calendar_type_plugin_gregorian
|
||||
* @author Shamim Rezaie <support@foodle.org>
|
||||
* @author Mark Nelson <markn@moodle.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
@ -15,17 +15,15 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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).
|
@ -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']);
|
||||
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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();
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
abstract class calendarsystem_plugin_base
|
||||
{
|
||||
public abstract function calendar_days_in_month($m, $y);
|
||||
public abstract function usergetdate($time, $timezone=99);
|
||||
public abstract function checkdate($m, $d, $y);
|
||||
public abstract function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true);
|
||||
public abstract function userdate($date, $format='', $timezone=99, $fixday = true, $fixhour = true);
|
||||
public abstract function today();
|
||||
public abstract function get_month_names();
|
||||
public abstract function get_min_year();
|
||||
public abstract function get_max_year();
|
||||
public abstract function gmmktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null);
|
||||
public abstract function mktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null);
|
||||
public abstract function dayofweek($day, $month, $year);
|
||||
}
|
||||
|
||||
/**
|
||||
* calendarsystem_plugin_factory is used to "manufacture" an instance of required calendar system.
|
||||
*/
|
||||
|
||||
class calendarsystem_plugin_factory {
|
||||
static function factory($system = '') {
|
||||
global $CFG;
|
||||
if (!$system) {
|
||||
$system = current_calendarsystem_plugin();
|
||||
// empty($CFG->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;
|
||||
}
|
||||
?>
|
@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
class calendarsystem_plugin_gregorian extends calendarsystem_plugin_base
|
||||
{
|
||||
public function calendar_days_in_month($m, $y)
|
||||
{
|
||||
return intval(date('t', mktime(0, 0, 0, $m, 1, $y)));
|
||||
}
|
||||
|
||||
public function usergetdate($time, $timezone=99) {
|
||||
return usergetdate_old($time, $timezone);
|
||||
}
|
||||
|
||||
public function checkdate($m, $d, $y)
|
||||
{
|
||||
return checkdate($m, $d, $y);
|
||||
}
|
||||
|
||||
public function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) {
|
||||
return make_timestamp_old($year, $month, $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_gregorian');
|
||||
$pmstring = get_string('pm', 'calendarsystem_gregorian');
|
||||
$AMstring = get_string('am_caps', 'calendarsystem_gregorian');
|
||||
$PMstring = get_string('pm_caps', 'calendarsystem_gregorian');
|
||||
}
|
||||
|
||||
$format = str_replace( array(
|
||||
"%p",
|
||||
"%P"
|
||||
),
|
||||
array(
|
||||
($date["hours"] < 12 ? $AMstring : $PMstring),
|
||||
($date["hours"] < 12 ? $amstring : $pmstring)
|
||||
),
|
||||
$format);
|
||||
|
||||
return userdate_old($date, $format, $timezone, $fixday, $fixhour);
|
||||
}
|
||||
|
||||
public function today()
|
||||
{
|
||||
list($y, $m, $d) = explode( "-", date("Y-m-d"));
|
||||
|
||||
return array((int)$m, (int)$d, (int)$y);
|
||||
}
|
||||
|
||||
public function get_month_names()
|
||||
{
|
||||
$months = array();
|
||||
|
||||
for ($i=1; $i<=12; $i++) {
|
||||
$months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
|
||||
}
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
public function get_min_year()
|
||||
{
|
||||
return 1970;
|
||||
}
|
||||
|
||||
public function get_max_year()
|
||||
{
|
||||
return 2020;
|
||||
}
|
||||
|
||||
public function gmmktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null) {
|
||||
return gmmktime($hour, $minute, $second, $month, $day, $year);
|
||||
}
|
||||
|
||||
public function mktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null) {
|
||||
return mktime($hour, $minute, $second, $month, $day, $year);
|
||||
}
|
||||
|
||||
function 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)));
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
$string['am'] = 'am';
|
||||
$string['am_caps'] = 'AM';
|
||||
$string['name'] = 'Gregorian';
|
||||
$string['pluginname'] = 'Gregorian calendar system';
|
||||
$string['pm'] = 'pm';
|
||||
$string['pm_caps'] = 'PM';
|
||||
?>
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
$string['am'] = 'صبح';
|
||||
$string['am_caps'] = 'صبح';
|
||||
$string['name'] = 'میلادی';
|
||||
$string['pluginname'] = 'تقویم میلادی';
|
||||
$string['pm'] = 'عصر';
|
||||
$string['pm_caps'] = 'عصر';
|
||||
?>
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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)
|
@ -1,250 +0,0 @@
|
||||
<?php
|
||||
|
||||
class calendarsystem_plugin_hijri extends calendarsystem_plugin_base
|
||||
{
|
||||
/*
|
||||
private function isleap($year) {
|
||||
return (((year * 11) + 14) % 30) < 11;
|
||||
}
|
||||
*/
|
||||
public function calendar_days_in_month($m, $y)
|
||||
{
|
||||
$temp = $this->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);
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
$string['am'] = 'am';
|
||||
$string['am_caps'] = 'AM';
|
||||
$string['name'] = 'Hijri';
|
||||
$string['month1'] = 'Muḥarram';
|
||||
$string['month2'] = 'Ṣafar';
|
||||
$string['month3'] = 'Rabīʿ al-Awwal';
|
||||
$string['month4'] = 'Rabīʿ al-Thānī';
|
||||
$string['month5'] = 'Jumādā al-Ūlā';
|
||||
$string['month6'] = 'Jumādā al-Thānī';
|
||||
$string['month7'] = 'Rajab';
|
||||
$string['month8'] = 'Shaʿbān';
|
||||
$string['month9'] = 'Ramaḍān';
|
||||
$string['month10'] = 'Shawwāl';
|
||||
$string['month11'] = 'Dhū al-Qaʿda';
|
||||
$string['month12'] = 'Dhū al-Ḥijja';
|
||||
$string['pm'] = 'pm';
|
||||
$string['pm_caps'] = 'PM';
|
||||
$string['weekday0'] = 'Sunday';
|
||||
$string['weekday1'] = 'Monday';
|
||||
$string['weekday2'] = 'Tuesday';
|
||||
$string['weekday3'] = 'Wednesday';
|
||||
$string['weekday4'] = 'Thursday';
|
||||
$string['weekday5'] = 'Friday';
|
||||
$string['weekday6'] = 'Saturday';
|
||||
$string['pluginname'] = 'Hijri calendar system';
|
||||
?>
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
$string['am'] = 'صبح';
|
||||
$string['am_caps'] = 'صبح';
|
||||
$string['name'] = 'هجری قمری';
|
||||
$string['month1'] = 'محرم';
|
||||
$string['month2'] = 'صفر';
|
||||
$string['month3'] = 'ربیعالاول';
|
||||
$string['month4'] = 'ربیعالثانی';
|
||||
$string['month5'] = 'جمادیالاول';
|
||||
$string['month6'] = 'جمادیالثانی';
|
||||
$string['month7'] = 'رجب';
|
||||
$string['month8'] = 'شعبان';
|
||||
$string['month9'] = 'رمضان';
|
||||
$string['month10'] = 'شوال';
|
||||
$string['month11'] = 'ذیقعده';
|
||||
$string['month12'] = 'ذیحجه';
|
||||
$string['pm'] = 'عصر';
|
||||
$string['pm_caps'] = 'عصر';
|
||||
$string['weekday0'] = 'یکشنبه';
|
||||
$string['weekday1'] = 'دوشنبه';
|
||||
$string['weekday2'] = 'سهشنبه';
|
||||
$string['weekday3'] = 'چهارشنبه';
|
||||
$string['weekday4'] = 'پنجشنبه';
|
||||
$string['weekday5'] = 'جمعه';
|
||||
$string['weekday6'] = 'شنبه';
|
||||
$string['pluginname'] = 'تقویم هجری قمری';
|
||||
?>
|
@ -1,175 +0,0 @@
|
||||
<?php
|
||||
|
||||
define('NO_OUTPUT_BUFFERING', true);
|
||||
|
||||
require('../config.php');
|
||||
require_once($CFG->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;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
@ -1,289 +0,0 @@
|
||||
<?php
|
||||
class calendarsystem_plugin_jalali extends calendarsystem_plugin_base
|
||||
{
|
||||
public function calendar_days_in_month($m, $y)
|
||||
{
|
||||
if ($m <= 6)
|
||||
return 31;
|
||||
elseif ($m != 12 or $this->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);
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
$string['am'] = 'am';
|
||||
$string['am_caps'] = 'AM';
|
||||
$string['name'] = 'Persian';
|
||||
$string['month1'] = 'Farvardin';
|
||||
$string['month2'] = 'Ordibehesht';
|
||||
$string['month3'] = 'Khordad';
|
||||
$string['month4'] = 'Tir';
|
||||
$string['month5'] = 'Mordad';
|
||||
$string['month6'] = 'Shahrivar';
|
||||
$string['month7'] = 'Mehr';
|
||||
$string['month8'] = 'Aban';
|
||||
$string['month9'] = 'Azar';
|
||||
$string['month10'] = 'Dey';
|
||||
$string['month11'] = 'Bahman';
|
||||
$string['month12'] = 'Esfand';
|
||||
$string['pm'] = 'pm';
|
||||
$string['pm_caps'] = 'PM';
|
||||
$string['weekday0'] = 'Sunday';
|
||||
$string['weekday1'] = 'Monday';
|
||||
$string['weekday2'] = 'Tuesday';
|
||||
$string['weekday3'] = 'Wednesday';
|
||||
$string['weekday4'] = 'Thursday';
|
||||
$string['weekday5'] = 'Friday';
|
||||
$string['weekday6'] = 'Saturday';
|
||||
$string['pluginname'] = 'Persian calendar system';
|
||||
?>
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
$string['am'] = 'صبح';
|
||||
$string['am_caps'] = 'صبح';
|
||||
$string['name'] = 'خورشیدی';
|
||||
$string['month1'] = 'فروردین';
|
||||
$string['month2'] = 'اردیبهشت';
|
||||
$string['month3'] = 'خرداد';
|
||||
$string['month4'] = 'تیر';
|
||||
$string['month5'] = 'مرداد';
|
||||
$string['month6'] = 'شهریور';
|
||||
$string['month7'] = 'مهر';
|
||||
$string['month8'] = 'آبان';
|
||||
$string['month9'] = 'آذر';
|
||||
$string['month10'] = 'دی';
|
||||
$string['month11'] = 'بهمن';
|
||||
$string['month12'] = 'اسفند';
|
||||
$string['pm'] = 'عصر';
|
||||
$string['pm_caps'] = 'عصر';
|
||||
$string['weekday0'] = 'یکشنبه';
|
||||
$string['weekday1'] = 'دوشنبه';
|
||||
$string['weekday2'] = 'سهشنبه';
|
||||
$string['weekday3'] = 'چهارشنبه';
|
||||
$string['weekday4'] = 'پنجشنبه';
|
||||
$string['weekday5'] = 'جمعه';
|
||||
$string['weekday6'] = 'شنبه';
|
||||
$string['pluginname'] = 'تقویم هجری شمسی';
|
||||
?>
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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)
|
@ -1,341 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* General exception thrown by the {@link calendarsystem_update_checker} class
|
||||
*/
|
||||
class calendarsystem_update_checker_exception extends moodle_exception {
|
||||
|
||||
/**
|
||||
* @param string $errorcode exception description identifier
|
||||
* @param mixed $debuginfo debugging data to display
|
||||
*/
|
||||
public function __construct($errorcode, $debuginfo=null) {
|
||||
parent::__construct($errorcode, 'calendarsystem', '', null, print_r($debuginfo, true));
|
||||
}
|
||||
}
|
||||
|
||||
class calendarsystem_update_checker {
|
||||
|
||||
/** @var calendarsystem_update_checker holds the singleton instance */
|
||||
protected static $singletoninstance;
|
||||
/** @var null|int the timestamp of when the most recent response was fetched */
|
||||
protected $recentfetch = null;
|
||||
/** @var null|array the recent response from the update notification provider */
|
||||
protected $recentresponse = null;
|
||||
/** @var null|string the numerical version of the local Moodle code */
|
||||
protected $currentversion = null;
|
||||
/** @var null|string the release info of the local Moodle code */
|
||||
protected $currentrelease = null;
|
||||
/** @var null|string branch of the local Moodle code */
|
||||
protected $currentbranch = null;
|
||||
/** @var array of (string)frankestyle => (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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 : '';
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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.';
|
||||
|
@ -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 <strong>there is no guarantee</strong> 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';
|
||||
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
$string['preferredcalendar'] = 'Preferred calendar';
|
||||
$string['helpcalendarsystem'] = 'helpcalendarsystem';
|
||||
$string['changecalendar'] = 'change';
|
||||
$string['checkforupdates'] = 'Check for available updates';
|
||||
$string['configcalendarsystem'] = 'Default calendar';
|
||||
$string['forcecalendarsystem'] = 'Force calendar';
|
||||
$string['system'] = 'Calendar';
|
||||
$string['calendarsystem'] = 'Calendar system';
|
||||
$string['calendarsystems'] = 'Calendar systems';
|
||||
$string['calendarsystemdeleteconfirm'] = 'You are about to completely delete the calendar system \'{$a}\'. This will completely delete everything in the database associated with this plugin. Are you SURE you want to continue?';
|
||||
$string['calendarsystemsmanage'] = 'Manage calendar systems';
|
||||
$string['updateavailable'] = 'There is a newer calendar system core version available!';
|
||||
$string['updateavailable_moreinfo'] = 'More info...';
|
||||
$string['updateavailable_version'] = 'Version {$a}';
|
||||
$string['updateavailableforplugin'] = 'There is a newer version for {$a} calendar system plugin available!';
|
||||
$string['updateavailablenot'] = 'Your calendar system code is up-to-date!';
|
||||
$string['updatecheck'] = 'Check for CalendarSystem update';
|
||||
?>
|
@ -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';
|
||||
|
@ -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:
|
||||
|
@ -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',
|
||||
|
@ -93,7 +93,7 @@
|
||||
<FIELD NAME="groupmodeforce" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="defaultgroupingid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="default grouping used in course modules, does not have key intentionally"/>
|
||||
<FIELD NAME="lang" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendarsystem" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendartype" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="theme" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
@ -772,7 +772,7 @@
|
||||
<FIELD NAME="city" TYPE="char" LENGTH="120" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="country" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="lang" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="en" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendarsystem" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendartype" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="theme" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timezone" TYPE="char" LENGTH="100" NOTNULL="true" DEFAULT="99" SEQUENCE="false"/>
|
||||
<FIELD NAME="firstaccess" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
|
@ -39,12 +39,10 @@ require_once($CFG->libdir . '/formslib.php');
|
||||
* @copyright 2007 Jamie Pratt <me@jamiep.org>
|
||||
* @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 {
|
||||
|
@ -39,11 +39,10 @@ require_once($CFG->libdir . '/formslib.php');
|
||||
* @copyright 2006 Jamie Pratt <me@jamiep.org>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user