Permalink
Browse files

MDL-18375 calendar: added multiple calendar support

Conflicts:

	course/edit_form.php
	lib/db/install.xml
	lib/form/dateselector.php
	lib/form/datetimeselector.php
	lib/setup.php
  • Loading branch information...
1 parent b69ec28 commit 6dd59aabfae39566ec32a3108ebf848f87243b88 @rezaies rezaies committed with markn86 Jun 10, 2013
Showing with 1,806 additions and 60 deletions.
  1. +2 −0 admin/settings/appearance.php
  2. +7 −0 admin/settings/plugins.php
  3. +3 −1 admin/tool/uploaduser/index.php
  4. +40 −1 blocks/calendar_month/block_calendar_month.php
  5. +3 −2 calendar/event.php
  6. +15 −13 calendar/export_execute.php
  7. +19 −12 calendar/lib.php
  8. +6 −4 calendar/renderer.php
  9. +2 −1 calendar/view.php
  10. +98 −0 calendarsystem/admin.php
  11. +69 −0 calendarsystem/calendarsystem.class.php
  12. +88 −0 calendarsystem/gregorian/calendarsystem.php
  13. +8 −0 calendarsystem/gregorian/lang/en/calendarsystem_gregorian.php
  14. +8 −0 calendarsystem/gregorian/lang/fa/calendarsystem_gregorian.php
  15. +31 −0 calendarsystem/gregorian/version.php
  16. +250 −0 calendarsystem/hijri/calendarsystem.php
  17. +27 −0 calendarsystem/hijri/lang/en/calendarsystem_hijri.php
  18. +27 −0 calendarsystem/hijri/lang/fa/calendarsystem_hijri.php
  19. +31 −0 calendarsystem/hijri/version.php
  20. +175 −0 calendarsystem/index.php
  21. +289 −0 calendarsystem/jalali/calendarsystem.php
  22. +27 −0 calendarsystem/jalali/lang/en/calendarsystem_jalali.php
  23. +27 −0 calendarsystem/jalali/lang/fa/calendarsystem_jalali.php
  24. +31 −0 calendarsystem/jalali/version.php
  25. +341 −0 calendarsystem/updatechecker.php
  26. +28 −0 calendarsystem/version.php
  27. +7 −0 course/edit_form.php
  28. +3 −1 enrol/manual/ajax.php
  29. +3 −1 enrol/manual/lib.php
  30. +4 −1 enrol/manual/manage.php
  31. +19 −0 lang/en/calendarsystem.php
  32. +1 −0 lang/en/plugin.php
  33. +3 −1 lib/bennu/iCalendar_rfc2445.php
  34. +2 −0 lib/db/install.xml
  35. +15 −7 lib/form/dateselector.php
  36. +15 −7 lib/form/datetimeselector.php
  37. +45 −7 lib/moodlelib.php
  38. +28 −0 lib/setup.php
  39. +4 −0 user/editlib.php
  40. +5 −1 user/profile/field/datetime/define.class.php
@@ -45,6 +45,8 @@
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,6 +454,13 @@
}
}
+// 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,8 +81,10 @@
$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 = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
+$today = $calendarsystem_gregorian->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 @@ function preferred_width() {
}
function get_content() {
- global $USER, $CFG, $SESSION;
+ global $USER, $CFG, $SESSION, $COURSE, $OUTPUT;
$cal_m = optional_param( 'cal_m', 0, PARAM_INT );
$cal_y = optional_param( 'cal_y', 0, PARAM_INT );
@@ -51,6 +51,45 @@ function get_content() {
$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;
}
}
View
@@ -133,9 +133,10 @@
unset($formoptions->eventtypes->groups);
}
}
- if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
+ // MDL-18375, Multi-Calendar Support
+ if($cal_y && $cal_m && $cal_d && $CALENDARSYSTEM->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 && checkdate($cal_m, 1, $cal_y)) {
+ } else if($cal_y && $cal_m && $CALENDARSYSTEM->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,7 +34,9 @@
$what = optional_param('preset_what', 'all', PARAM_ALPHA);
$time = optional_param('preset_time', 'weeknow', PARAM_ALPHA);
-$now = usergetdate(time());
+// MDL-18375, Multi-Calendar Support
+$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian');
+$now = $calendarsystem_gregorian->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');
@@ -80,47 +82,47 @@
$startmonthday = find_day_in_month($now['mday'] - 6, $startweekday, $now['mon'], $now['year']);
$startmonth = $now['mon'];
$startyear = $now['year'];
- if($startmonthday > calendar_days_in_month($startmonth, $startyear)) {
+ if($startmonthday > $calendarsystem_gregorian->calendar_days_in_month($startmonth, $startyear)) {
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
}
- $timestart = make_timestamp($startyear, $startmonth, $startmonthday);
+ $timestart = $calendarsystem_gregorian->make_timestamp($startyear, $startmonth, $startmonthday);
$endmonthday = $startmonthday + 7;
$endmonth = $startmonth;
$endyear = $startyear;
- if($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
+ if($endmonthday > $calendarsystem_gregorian->calendar_days_in_month($endmonth, $endyear)) {
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
}
- $timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1;
+ $timeend = $calendarsystem_gregorian->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 > calendar_days_in_month($startmonth, $startyear)) {
+ if($startmonthday > $calendarsystem_gregorian->calendar_days_in_month($startmonth, $startyear)) {
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
}
- $timestart = make_timestamp($startyear, $startmonth, $startmonthday);
+ $timestart = $calendarsystem_gregorian->make_timestamp($startyear, $startmonth, $startmonthday);
$endmonthday = $startmonthday + 7;
$endmonth = $startmonth;
$endyear = $startyear;
- if($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
+ if($endmonthday > $calendarsystem_gregorian->calendar_days_in_month($endmonth, $endyear)) {
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
}
- $timeend = make_timestamp($endyear, $endmonth, $endmonthday) - 1;
+ $timeend = $calendarsystem_gregorian->make_timestamp($endyear, $endmonth, $endmonthday) - 1;
break;
case 'monthnow':
- $timestart = make_timestamp($now['year'], $now['mon'], 1);
- $timeend = make_timestamp($now['year'], $now['mon'], calendar_days_in_month($now['mon'], $now['year']), 23, 59, 59);
+ $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);
break;
case 'monthnext':
list($nextmonth, $nextyear) = calendar_add_month($now['mon'], $now['year']);
- $timestart = make_timestamp($nextyear, $nextmonth, 1);
- $timeend = make_timestamp($nextyear, $nextmonth, calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59);
+ $timestart = $calendarsystem_gregorian->make_timestamp($nextyear, $nextmonth, 1);
+ $timeend = $calendarsystem_gregorian->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
View
@@ -187,6 +187,8 @@ 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());
@@ -202,7 +204,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(!checkdate($cal_month, 1, $cal_year)) {
+ if(!$CALENDARSYSTEM->checkdate($cal_month, 1, $cal_year)) {
$date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
$display->thismonth = true;
} else {
@@ -221,12 +223,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 = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
- $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
+ $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
} else {
// no timezone info specified
- $display->tstart = mktime(0, 0, 0, $m, 1, $y);
- $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
+ $display->tstart = $CALENDARSYSTEM->mktime(0, 0, 0, $m, 1, $y);
+ $display->tend = $CALENDARSYSTEM->mktime(23, 59, 59, $m, $display->maxdays, $y);
}
$startwday = dayofweek(1, $m, $y);
@@ -824,6 +826,8 @@ 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;
@@ -836,11 +840,11 @@ function calendar_top_controls($type, $data) {
$courseid = '&amp;course='.$data['id'];
}
- if(!checkdate($data['m'], $data['d'], $data['y'])) {
+ if(!$CALENDARSYSTEM->checkdate($data['m'], $data['d'], $data['y'])) {
$time = time();
}
else {
- $time = make_timestamp($data['y'], $data['m'], $data['d']);
+ $time = $CALENDARSYSTEM->make_timestamp($data['y'], $data['m'], $data['d']);
}
$date = usergetdate($time);
@@ -1210,7 +1214,9 @@ function calendar_wday_name($englishname) {
* @return int
*/
function calendar_days_in_month($month, $year) {
- return intval(date('t', mktime(0, 0, 0, $month, 1, $year)));
+ // MDL-18375, Multi-Calendar Support
+ global $CALENDARSYSTEM;
+ return $CALENDARSYSTEM->calendar_days_in_month($month, $year);
}
/**
@@ -1733,10 +1739,11 @@ 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) {
- $months = array();
- for ($i=1; $i<=12; $i++) {
- $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B');
- }
+ // MDL-18375, Multi-Calendar Support
+ global $CALENDARSYSTEM;
+
+ $months = $CALENDARSYSTEM->get_month_names();
+
echo html_writer::label(get_string('months'), 'menu'. $name, false, array('class' => 'accesshide'));
echo html_writer::select($months, $name, $selected, false);
}
View
@@ -380,6 +380,8 @@ public function event(calendar_event $event, $showactions=true) {
*/
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;
@@ -396,13 +398,13 @@ public function show_month_detailed(calendar_information $calendar, moodle_url $
$startwday = 0;
if (get_user_timezone_offset() < 99) {
// We 'll keep these values as GMT here, and offset them when the time comes to query the db
- $display->tstart = gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year); // This is GMT
- $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT
+ $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
$startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
} else {
// no timezone info specified
- $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year);
- $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year);
+ $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);
$startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
}
View
@@ -88,7 +88,8 @@
$strcalendar = get_string('calendar', 'calendar');
-if (!checkdate($mon, $day, $yr)) {
+// MDL-18375, Multi-Calendar Support
+if (!$CALENDARSYSTEM->checkdate($mon, $day, $yr)) {
$day = intval($now['mday']);
$mon = intval($now['mon']);
$yr = intval($now['year']);
@@ -0,0 +1,98 @@
+<?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();
Oops, something went wrong.

0 comments on commit 6dd59aa

Please sign in to comment.