diff -Naur moodle197_orig/admin/roles/assign.php foodle197/admin/roles/assign.php --- moodle197_orig/admin/roles/assign.php 2010-02-13 00:02:57.000000000 +0000 +++ foodle197/admin/roles/assign.php 2010-02-23 18:29:58.609890107 +0000 @@ -85,7 +85,9 @@ $timeformat = get_string('strftimedate'); $today = time(); - $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); + // MDL-18375, Multi-Calendar Support + $calendar_system_gregorian = calendar_system_factory::factory('gregorian'); + $today = $calendar_system_gregorian->make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); // MDL-12420, preventing course start date showing up as an option at system context and front page roles. if ($course->startdate > 0) { diff -Naur moodle197_orig/admin/settings/appearance.php foodle197/admin/settings/appearance.php --- moodle197_orig/admin/settings/appearance.php 2009-04-03 16:16:09.000000000 +0100 +++ foodle197/admin/settings/appearance.php 2010-02-24 04:22:33.683126508 +0000 @@ -31,6 +31,7 @@ array('0' => get_string('default', 'calendar'), '%I:%M %p' => get_string('timeformat_12', 'calendar'), '%H:%M' => get_string('timeformat_24', 'calendar')))); + $temp->add(new admin_setting_configselect('calendar_system', get_string('configcalendarsystem', 'calendar_system'), get_string('helpcalendarsystem', 'calendar_system'), 'gregorian', get_list_of_calendars())); $temp->add(new admin_setting_configselect('calendar_startwday', get_string('configstartwday', 'admin'), get_string('helpstartofweek', 'admin'), 0, array( 0 => get_string('sunday', 'calendar'), diff -Naur moodle197_orig/calendar/event.php foodle197/calendar/event.php --- moodle197_orig/calendar/event.php 2009-11-20 16:36:19.000000000 +0000 +++ foodle197/calendar/event.php 2010-02-23 18:32:18.869876160 +0000 @@ -381,10 +381,11 @@ break; case 'new': - 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 && $CALENDAR_SYSTEM->checkdate($cal_m, $cal_d, $cal_y)) { $form->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 && $CALENDAR_SYSTEM->checkdate($cal_m, 1, $cal_y)) { if($cal_y == $now['year'] && $cal_m == $now['mon']) { $form->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0); } @@ -569,6 +570,9 @@ function validate_form(&$form, &$err) { + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; + $form->name = trim($form->name); $form->description = trim($form->description); @@ -580,10 +584,10 @@ $err['description'] = get_string('errornodescription', 'calendar'); } */ - if(!checkdate($form->startmon, $form->startday, $form->startyr)) { + if(!$CALENDAR_SYSTEM->checkdate($form->startmon, $form->startday, $form->startyr)) { $err['timestart'] = get_string('errorinvaliddate', 'calendar'); } - if($form->duration == 2 and !checkdate($form->endmon, $form->endday, $form->endyr)) { + if($form->duration == 2 and !$CALENDAR_SYSTEM->checkdate($form->endmon, $form->endday, $form->endyr)) { $err['timeduration'] = get_string('errorinvaliddate', 'calendar'); } if($form->duration == 2 and !($form->minutes > 0 and $form->minutes < 1000)) { diff -Naur moodle197_orig/calendar/export_execute.php foodle197/calendar/export_execute.php --- moodle197_orig/calendar/export_execute.php 2009-01-20 23:05:38.000000000 +0000 +++ foodle197/calendar/export_execute.php 2010-02-24 03:31:13.246125221 +0000 @@ -26,7 +26,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 +$calendar_system_gregorian = calendar_system_factory::factory('gregorian'); +$now = $calendar_system_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'); @@ -60,47 +62,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 > $calendar_system_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 = $calendar_system_gregorian->make_timestamp($startyear, $startmonth, $startmonthday); $endmonthday = $startmonthday + 7; $endmonth = $startmonth; $endyear = $startyear; - if($endmonthday > calendar_days_in_month($endmonth, $endyear)) { + if($endmonthday > $calendar_system_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 = $calendar_system_gregorian->make_timestamp($endyear, $endmonth, $endmonthday) - 1; break; case 'weeknext': $startweekday = get_user_preferences('calendar_startwday', CALENDAR_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 > $calendar_system_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 = $calendar_system_gregorian->make_timestamp($startyear, $startmonth, $startmonthday); $endmonthday = $startmonthday + 7; $endmonth = $startmonth; $endyear = $startyear; - if($endmonthday > calendar_days_in_month($endmonth, $endyear)) { + if($endmonthday > $calendar_system_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 = $calendar_system_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 = $calendar_system_gregorian->make_timestamp($now['year'], $now['mon'], 1); + $timeend = $calendar_system_gregorian->make_timestamp($now['year'], $now['mon'], $calendar_system_gregorian->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 = $calendar_system_gregorian->make_timestamp($nextyear, $nextmonth, 1); + $timeend = $calendar_system_gregorian->make_timestamp($nextyear, $nextmonth, $calendar_system_gregorian->calendar_days_in_month($nextmonth, $nextyear), 23, 59, 59); break; case 'recentupcoming': //Events in the last 5 or next 60 days diff -Naur moodle197_orig/calendar/export.php foodle197/calendar/export.php --- moodle197_orig/calendar/export.php 2009-01-20 23:05:37.000000000 +0000 +++ foodle197/calendar/export.php 2010-02-23 18:32:52.049885811 +0000 @@ -45,7 +45,8 @@ $navigation = build_navigation($navlinks); -if(!checkdate($mon, $day, $yr)) { +// MDL-18375, Multi-Calendar Support +if(!$CALENDAR_SYSTEM->checkdate($mon, $day, $yr)) { $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); diff -Naur moodle197_orig/calendar/lib.php foodle197/calendar/lib.php --- moodle197_orig/calendar/lib.php 2009-11-20 16:36:19.000000000 +0000 +++ foodle197/calendar/lib.php 2010-02-23 18:38:15.722124961 +0000 @@ -67,7 +67,8 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) { - global $CFG, $USER; + // MDL-18375, Multi-Calendar Support + global $CFG, $USER, $CALENDAR_SYSTEM; $display = new stdClass; $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); @@ -84,7 +85,7 @@ } 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(!$CALENDAR_SYSTEM->checkdate($cal_month, 1, $cal_year)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } @@ -105,12 +106,12 @@ 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 = $CALENDAR_SYSTEM->gmmktime(0, 0, 0, $m, 1, $y); // This is GMT + $display->tend = $CALENDAR_SYSTEM->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 = $CALENDAR_SYSTEM->mktime(0, 0, 0, $m, 1, $y); + $display->tend = $CALENDAR_SYSTEM->mktime(23, 59, 59, $m, $display->maxdays, $y); } $startwday = dayofweek(1, $m, $y); @@ -687,7 +688,8 @@ } function calendar_top_controls($type, $data) { - global $CFG, $CALENDARDAYS, $THEME; + // MDL-18375, Multi-Calendar Support + global $CFG, $CALENDARDAYS, $THEME, $CALENDAR_SYSTEM; $content = ''; if(!isset($data['d'])) { $data['d'] = 1; @@ -700,11 +702,11 @@ $courseid = '&course='.$data['id']; } - if(!checkdate($data['m'], $data['d'], $data['y'])) { + if(!$CALENDAR_SYSTEM->checkdate($data['m'], $data['d'], $data['y'])) { $time = time(); } else { - $time = make_timestamp($data['y'], $data['m'], $data['d']); + $time = $CALENDAR_SYSTEM->make_timestamp($data['y'], $data['m'], $data['d']); } $date = usergetdate($time); @@ -973,7 +975,10 @@ } function calendar_days_in_month($month, $year) { - return intval(date('t', mktime(0, 0, 0, $month, 1, $year))); + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; +// return intval(date('t', mktime(0, 0, 0, $month, 1, $year))); + return $CALENDAR_SYSTEM->calendar_days_in_month($month, $year); } function calendar_get_sideblock_upcoming($events, $linkhref = NULL) { @@ -1528,11 +1533,16 @@ function calendar_print_month_selector($name, $selected) { - $months = array(); + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; - for ($i=1; $i<=12; $i++) { - $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B'); - } +// $months = array(); +// +// for ($i=1; $i<=12; $i++) { +// $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B'); +// } + + $months = $CALENDAR_SYSTEM->get_month_names(); choose_from_menu($months, $name, $selected, ''); } diff -Naur moodle197_orig/calendar/view.php foodle197/calendar/view.php --- moodle197_orig/calendar/view.php 2009-10-02 01:05:35.000000000 +0100 +++ foodle197/calendar/view.php 2010-02-23 18:51:27.972875870 +0000 @@ -75,7 +75,8 @@ 'type' => 'misc'); - if(!checkdate($mon, $day, $yr)) { + // MDL-18375, Multi-Calendar Support + if(!$CALENDAR_SYSTEM->checkdate($mon, $day, $yr)) { $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); @@ -223,9 +224,10 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) { - global $CFG, $USER; + // MDL-18375, Multi-Calendar Support + global $CFG, $USER, $CALENDAR_SYSTEM; - if (!checkdate($m, $d, $y)) { + if (!$CALENDAR_SYSTEM->checkdate($m, $d, $y)) { $now = usergetdate(time()); list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year'])); } @@ -307,7 +309,8 @@ } function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) { - global $CFG, $SESSION, $USER, $CALENDARDAYS; + // MDL-18375, Multi-Calendar Support + global $CFG, $SESSION, $USER, $CALENDARDAYS, $CALENDAR_SYSTEM; global $day, $mon, $yr; $getvars = 'from=month&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering @@ -325,7 +328,7 @@ } else { // Navigated to other month, let's do a nice trick and save us a lot of work... - if(!checkdate($m, 1, $y)) { + if(!$CALENDAR_SYSTEM->checkdate($m, 1, $y)) { $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']); $display->thismonth = true; } @@ -347,13 +350,13 @@ $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, $m, 1, $y); // This is GMT - $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT + $display->tstart = $CALENDAR_SYSTEM->gmmktime(0, 0, 0, $m, 1, $y); // This is GMT + $display->tend = $CALENDAR_SYSTEM->gmmktime(23, 59, 59, $m, $display->maxdays, $y); // 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, $m, 1, $y); - $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); + $display->tstart = $CALENDAR_SYSTEM->mktime(0, 0, 0, $m, 1, $y); + $display->tend = $CALENDAR_SYSTEM->mktime(23, 59, 59, $m, $display->maxdays, $y); $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date() } diff -Naur moodle197_orig/calendar_system/calendar_system.class.php foodle197/calendar_system/calendar_system.class.php --- moodle197_orig/calendar_system/calendar_system.class.php 1970-01-01 01:00:00.000000000 +0100 +++ foodle197/calendar_system/calendar_system.class.php 2010-02-23 20:37:54.141877685 +0000 @@ -0,0 +1,50 @@ +calendar_system) ? 'gregorian' : $CFG->calendar_system; // we might be in the installation process and $CFG->calendar_ststem might be undefined yet + } + if (file_exists("$CFG->dirroot/calendar_system/$system/calendar_system.php")) { + require_once("$CFG->dirroot/calendar_system/$system/calendar_system.php"); + $class = "calendar_system_$system"; + return new $class; + } else { + trigger_error("$CFG->dirroot/calendar_system/$system/calendar_system.php does not exist"); + notify("Calendar system file $system/calendar_system.php does not exist"); + } + } +} + +function get_list_of_calendars() { + $calendars = array(); + $calendardirs = get_list_of_plugins('calendar_system'); + + foreach ($calendardirs as $calendar) { + $calendars[$calendar] = get_string('name', "calendar_system_{$calendar}"); + } + + return $calendars; +} +?> diff -Naur moodle197_orig/calendar_system/gregorian/calendar_system.php foodle197/calendar_system/gregorian/calendar_system.php --- moodle197_orig/calendar_system/gregorian/calendar_system.php 1970-01-01 01:00:00.000000000 +0100 +++ foodle197/calendar_system/gregorian/calendar_system.php 2009-08-27 03:31:22.000000000 +0100 @@ -0,0 +1,74 @@ +rootdir . '../calendar_system.php'); +class calendar_system_gregorian extends calendar_system_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) { + return userdate_old($date, $format, $timezone, $fixday); + } + + public function today() + { + list($y, $m, $d) = explode( "-", date("Y-m-d")); + + return array((int)$m, (int)$d, (int)$y); + } + + public function getStartWDay() + { + return get_user_preferences('calendar_getStartWDay', CALENDAR_STARTING_WEEKDAY); + } + + 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, $dst=null) { + return gmmktime($hour, $minute, $second, $month, $day, $year, $dst); + } + + public function mktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null, $dst=null) { + return mktime($hour, $minute, $second, $month, $day, $year, $dst); + } + + 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, 0))); + } +} +?> diff -Naur moodle197_orig/calendar_system/jalali/calendar_system.php foodle197/calendar_system/jalali/calendar_system.php --- moodle197_orig/calendar_system/jalali/calendar_system.php 1970-01-01 01:00:00.000000000 +0100 +++ foodle197/calendar_system/jalali/calendar_system.php 2010-02-24 01:17:26.352125939 +0000 @@ -0,0 +1,289 @@ +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']}", 'calendar_system_jalali'); + $date["weekday"] = get_string("weekday{$date['wday']}", 'calendar_system_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) { + if (empty($format)) + { + $format = get_string('strftimedaydatetime'); + } + + $date_ = $this->usergetdate($date); + //this is not sufficient code, change it. but it is work correctly. + $format = str_replace( array( + "%a", + "%A", + "%b", + "%B", + "%d", + "%m", + "%y", + "%Y" + ), + array( + $date_["weekday"], + $date_["weekday"], + $date_["month"], + $date_["month"], + ($date_["mday"] < 10 ? '0' : '') . $date_["mday"], + ($date_["mon"] < 10 ? '0' : '') . $date_["mon"], + $date_["year"] % 100, + $date_["year"] + ), + $format); + + return userdate_old($date, $format); + } + + 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 getStartWDay() + { + //return 6; + return get_user_preferences('calendar_getStartWDay', CALENDAR_STARTING_WEEKDAY); + } + + public function get_month_names() + { + $months = array(); + + for ($i=1; $i<=12; $i++) { + $months[$i] = $this->userdate(gmmktime(12,0,0,($i+3)%12,15,2000), "%B"); + } + + return $months; + } + + public function get_min_year() + { + return 1370; +// return 1971; + } + + public function get_max_year() + { + return 1420; +// return 2035; + } + + public function gmmktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null, $dst=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'], $dst); + } + + public function mktime($hour=null, $minute=null, $second=null, $month=null, $day=null, $year=null, $dst=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'], $dst); + } + + 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'], 0))); + } + + + 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); + } + + private function fa_month_name($m) { + $j_month_name = array("", "Farvardin", "Ordibehesht", "Khordad", "Tir", + "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", + "Dey", "Bahman", "Esfand"); + return $j_month_name[$m]; + } +} +?> diff -Naur moodle197_orig/enrol/authorize/config_form.php foodle197/enrol/authorize/config_form.php --- moodle197_orig/enrol/authorize/config_form.php 2008-07-05 01:16:52.000000000 +0100 +++ foodle197/enrol/authorize/config_form.php 2010-02-23 18:58:04.454126276 +0000 @@ -103,9 +103,14 @@ + + an_cutoff: - an_cutoff_hour,$frm->an_cutoff_min),5); ?>
+ make_timestamp(2000,1,1,$frm->an_cutoff_hour,$frm->an_cutoff_min),5); ?>
diff -Naur moodle197_orig/lang/en_utf8/calendar_system_gregorian.php foodle197/lang/en_utf8/calendar_system_gregorian.php --- moodle197_orig/lang/en_utf8/calendar_system_gregorian.php 1970-01-01 01:00:00.000000000 +0100 +++ foodle197/lang/en_utf8/calendar_system_gregorian.php 2010-02-23 20:45:49.595876004 +0000 @@ -0,0 +1,3 @@ + \ No newline at end of file diff -Naur moodle197_orig/lang/en_utf8/calendar_system_jalali.php foodle197/lang/en_utf8/calendar_system_jalali.php --- moodle197_orig/lang/en_utf8/calendar_system_jalali.php 1970-01-01 01:00:00.000000000 +0100 +++ foodle197/lang/en_utf8/calendar_system_jalali.php 2010-02-23 20:46:28.333126483 +0000 @@ -0,0 +1,22 @@ + \ No newline at end of file diff -Naur moodle197_orig/lang/en_utf8/calendar_system.php foodle197/lang/en_utf8/calendar_system.php --- moodle197_orig/lang/en_utf8/calendar_system.php 1970-01-01 01:00:00.000000000 +0100 +++ foodle197/lang/en_utf8/calendar_system.php 2010-02-24 04:19:18.324126236 +0000 @@ -0,0 +1,5 @@ + \ No newline at end of file diff -Naur moodle197_orig/lib/accesslib.php foodle197/lib/accesslib.php --- moodle197_orig/lib/accesslib.php 2009-10-09 01:06:08.000000000 +0100 +++ foodle197/lib/accesslib.php 2010-02-23 19:11:17.766130544 +0000 @@ -3103,7 +3103,9 @@ $timestart = time(); // remove time part from the timestamp and keep only the date part - $timestart = make_timestamp(date('Y', $timestart), date('m', $timestart), date('d', $timestart), 0, 0, 0); + // MDL-18375, Multi-Calendar Support + $calendar_system_gregorian = calendar_system_factory::factory('gregorian'); + $timestart = $calendar_system_gregorian->make_timestamp(date('Y', $timestart), date('m', $timestart), date('d', $timestart), 0, 0, 0); if ($course->enrolperiod) { $timeend = $timestart + $course->enrolperiod; } else { diff -Naur moodle197_orig/lib/bennu/iCalendar_rfc2445.php foodle197/lib/bennu/iCalendar_rfc2445.php --- moodle197_orig/lib/bennu/iCalendar_rfc2445.php 2009-11-20 16:36:29.000000000 +0000 +++ foodle197/lib/bennu/iCalendar_rfc2445.php 2010-02-23 19:02:15.654876521 +0000 @@ -201,7 +201,9 @@ $m = intval(substr($value, 4, 2)); $d = intval(substr($value, 6, 2)); - return checkdate($m, $d, $y); + // MDL-18375, Multi-Calendar Support + $calendar_system_gregorian = calendar_system_factory::factory('gregorian'); + return $calendar_system_gregorian->checkdate($m, $d, $y); break; case RFC2445_TYPE_DATE_TIME: diff -Naur moodle197_orig/lib/db/install.xml foodle197/lib/db/install.xml --- moodle197_orig/lib/db/install.xml 2010-02-02 00:02:49.000000000 +0000 +++ foodle197/lib/db/install.xml 2010-03-06 06:09:19.609403050 +0000 @@ -458,8 +458,9 @@ - - + + + diff -Naur moodle197_orig/lib/form/dateselector.php foodle197/lib/form/dateselector.php --- moodle197_orig/lib/form/dateselector.php 2007-04-14 03:10:30.000000000 +0100 +++ foodle197/lib/form/dateselector.php 2010-02-23 19:06:24.242876654 +0000 @@ -22,8 +22,9 @@ * applydst => apply users daylight savings adjustment? * optional => if true, show a checkbox beside the date to turn it on (or off) */ - var $_options = array('startyear'=>1970, 'stopyear'=>2020, - 'timezone'=>99, 'applydst'=>true, 'optional'=>false); + // MDL-18375, Multi-Calendar Support + var $_options;/* = array('startyear'=>1970, 'stopyear'=>2020, + 'timezone'=>99, 'applydst'=>true, 'optional'=>false);*/ /** * These complement separators, they are appended to the resultant HTML @@ -43,6 +44,11 @@ */ function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; + $this->_options = array('startyear'=> $CALENDAR_SYSTEM->get_min_year(), 'stopyear'=>$CALENDAR_SYSTEM->get_max_year(), + 'timezone'=>99, 'applydst'=>true, 'optional'=>false); + $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_appendName = true; @@ -66,13 +72,17 @@ function _createElements() { + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; + $this->_elements = array(); for ($i=1; $i<=31; $i++) { $days[$i] = $i; } - for ($i=1; $i<=12; $i++) { - $months[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B"); - } +// for ($i=1; $i<=12; $i++) { +// $months[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B"); +// } + $months = $CALENDAR_SYSTEM->get_month_names(); for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) { $years[$i] = $i; } diff -Naur moodle197_orig/lib/form/datetimeselector.php foodle197/lib/form/datetimeselector.php --- moodle197_orig/lib/form/datetimeselector.php 2007-08-09 17:56:36.000000000 +0100 +++ foodle197/lib/form/datetimeselector.php 2010-02-23 19:08:22.335922448 +0000 @@ -21,8 +21,9 @@ * applydst => apply users daylight savings adjustment? * step => step to increment minutes by */ - var $_options = array('startyear'=>1970, 'stopyear'=>2020, - 'timezone'=>99, 'applydst'=>true, 'step'=>5, 'optional'=>false); + // MDL-18375, Multi-Calendar Support + var $_options;/* = array('startyear'=>1970, 'stopyear'=>2020, + 'timezone'=>99, 'applydst'=>true, 'step'=>5, 'optional'=>false);*/ /** * These complement separators, they are appended to the resultant HTML @@ -42,6 +43,11 @@ */ function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; + $this->_options = array('startyear'=> $CALENDAR_SYSTEM->get_min_year(), 'stopyear'=>$CALENDAR_SYSTEM->get_max_year(), + 'timezone'=>99, 'applydst'=>true, 'step'=>5, 'optional'=>false); + $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_appendName = true; @@ -65,10 +71,14 @@ function _createElements() { + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; + $this->_elements = array(); - for ($i=1; $i<=31; $i++) { - $days[$i] = $i; - } +// for ($i=1; $i<=31; $i++) { +// $days[$i] = $i; +// } + $months = $CALENDAR_SYSTEM->get_month_names(); for ($i=1; $i<=12; $i++) { $months[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B"); } diff -Naur moodle197_orig/lib/moodlelib.php foodle197/lib/moodlelib.php --- moodle197_orig/lib/moodlelib.php 2010-01-09 00:02:43.000000000 +0000 +++ foodle197/lib/moodlelib.php 2010-02-24 02:34:48.914125085 +0000 @@ -1119,7 +1119,18 @@ * @return int timestamp * @todo Finish documenting this function */ +// MDL-18375, Multi-Calendar Support function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) { + global $CALENDAR_SYSTEM; + if ($CALENDAR_SYSTEM->get_min_year() == 1370 && $year > 2000) { + debugging('Warning. Wrong call to make_timestamp().', DEBUG_DEVELOPER); + error('Your code must be fixed by a developer.'); + } + return $CALENDAR_SYSTEM->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) { $strtimezone = NULL; if (!is_numeric($timezone)) { @@ -1142,6 +1153,8 @@ } + + /** * Given an amount of time in seconds, returns string * formatted nicely as weeks, days, hours etc as needed @@ -1226,7 +1239,14 @@ * zero from %d is removed. If false then the leading zero is mantained. * @return string */ +// MDL-18375, Multi-Calendar Support function userdate($date, $format='', $timezone=99, $fixday = true) { + global $CALENDAR_SYSTEM; + return $CALENDAR_SYSTEM->userdate($date, $format, $timezone, $fixday); +} + +// MDL-18375, Multi-Calendar Support +function userdate_old($date, $format='', $timezone=99, $fixday = true) { global $CFG; @@ -1292,7 +1312,14 @@ * @return array An array that represents the date in user time * @todo Finish documenting this function */ +// MDL-18375, Multi-Calendar Support function usergetdate($time, $timezone=99) { + global $CALENDAR_SYSTEM; + return $CALENDAR_SYSTEM->usergetdate($time, $timezone); +} + +// MDL-18375, Multi-Calendar Support +function usergetdate_old($time, $timezone=99) { $strtimezone = NULL; if (!is_numeric($timezone)) { @@ -1644,8 +1671,10 @@ list($dst_hour, $dst_min) = explode(':', $timezone->dst_time); list($std_hour, $std_min) = explode(':', $timezone->std_time); - $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); + // MDL-18375, Multi-Calendar Support + $calendar_system_gregorian = calendar_system_factory::factory('gregorian'); + $timedst = $calendar_system_gregorian->make_timestamp($year, $timezone->dst_month, $monthdaydst, 0, 0, 0, 99, false); + $timestd = $calendar_system_gregorian->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 @@ -1701,6 +1730,9 @@ function find_day_in_month($startday, $weekday, $month, $year) { + // MDL-18375, Multi-Calendar Support + $calendar_system_gregorian = calendar_system_factory::factory('gregorian'); + $daysinmonth = days_in_month($month, $year); if($weekday == -1) { @@ -1722,7 +1754,7 @@ if($startday < 1) { $startday = abs($startday); - $lastmonthweekday = strftime('%w', mktime(12, 0, 0, $month, $daysinmonth, $year, 0)); + $lastmonthweekday = strftime('%w', $calendar_system_gregorian->mktime(12, 0, 0, $month, $daysinmonth, $year, 0)); // This is the last such weekday of the month $lastinmonth = $daysinmonth + $weekday - $lastmonthweekday; @@ -1740,7 +1772,7 @@ } else { - $indexweekday = strftime('%w', mktime(12, 0, 0, $month, $startday, $year, 0)); + $indexweekday = strftime('%w', $calendar_system_gregorian->mktime(12, 0, 0, $month, $startday, $year, 0)); $diff = $weekday - $indexweekday; if($diff < 0) { @@ -1775,9 +1807,9 @@ * @return int */ 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, 0))); + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; + return $CALENDAR_SYSTEM->dayofweek($day, $month, $year); } /// USER AUTHENTICATION AND LOGIN //////////////////////////////////////// diff -Naur moodle197_orig/lib/setup.php foodle197/lib/setup.php --- moodle197_orig/lib/setup.php 2009-06-09 01:07:09.000000000 +0100 +++ foodle197/lib/setup.php 2010-02-23 20:33:46.099875956 +0000 @@ -68,6 +68,11 @@ * @global object(theme) $THEME */ global $THEME; +// MDL-18375, Multi-Calendar Support +/** + * $CALENDAR_SYSTEM is a global that defines the calendar system + */ +global $CALENDAR_SYSTEM; /** * HTTPSPAGEREQUIRED is a global to define if the page being displayed must run under HTTPS. @@ -218,6 +223,8 @@ require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions require_once($CFG->libdir .'/eventslib.php'); // Events functions require_once($CFG->libdir .'/grouplib.php'); // Groups functions + // MDL-18375, Multi-Calendar Support + require_once($CFG->dirroot . '/calendar_system/calendar_system.class.php'); //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else //the problem is that we need specific version of quickforms and hacked excel files :-( @@ -781,4 +788,10 @@ /// note: we can not block non utf-8 installatrions here, because empty mysql database /// might be converted to utf-8 in admin/index.php during installation + + // MDL-18375, Multi-Calendar Support + if (empty($USER->calendar_system)) { + $USER->calendar_system = ''; + } + $CALENDAR_SYSTEM = calendar_system_factory::factory($USER->calendar_system); ?> diff -Naur moodle197_orig/lib/weblib.php foodle197/lib/weblib.php --- moodle197_orig/lib/weblib.php 2010-02-17 00:03:05.000000000 +0000 +++ foodle197/lib/weblib.php 2010-02-23 19:42:15.097874095 +0000 @@ -5557,6 +5557,9 @@ */ function print_date_selector($day, $month, $year, $currenttime=0, $return=false) { + // MDL-18375, Multi-Calendar Support + global $CALENDAR_SYSTEM; + if (!$currenttime) { $currenttime = time(); } @@ -5565,10 +5568,14 @@ for ($i=1; $i<=31; $i++) { $days[$i] = $i; } - for ($i=1; $i<=12; $i++) { - $months[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B"); - } - for ($i=1970; $i<=2020; $i++) { +// for ($i=1; $i<=12; $i++) { +// $months[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B"); +// } + $months = $CALENDAR_SYSTEM->get_month_names(); +// for ($i=1970; $i<=2020; $i++) { +// $years[$i] = $i; +// } + for ($i=$CALENDAR_SYSTEM->get_min_year(); $i<=$CALENDAR_SYSTEM->get_max_year(); $i++) { $years[$i] = $i; } diff -Naur moodle197_orig/user/editlib.php foodle197/user/editlib.php --- moodle197_orig/user/editlib.php 2009-10-07 01:05:55.000000000 +0100 +++ foodle197/user/editlib.php 2010-02-23 19:45:27.610876489 +0000 @@ -218,6 +218,10 @@ $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages()); $mform->setDefault('lang', $CFG->lang); + // MDL-18375, Multi-Calendar Support + $mform->addElement('select', 'calendar_system', get_string('preferredcalendar', 'calendar_system'), get_list_of_calendars()); + $mform->setDefault('calendar_system', $CFG->calendar_system); + if (!empty($CFG->allowuserthemes)) { $choices = array(); $choices[''] = get_string('default'); diff -Naur moodle197_orig/user/extendenrol.php foodle197/user/extendenrol.php --- moodle197_orig/user/extendenrol.php 2007-08-18 03:09:20.000000000 +0100 +++ foodle197/user/extendenrol.php 2010-02-23 19:46:34.053875868 +0000 @@ -14,7 +14,10 @@ // to extend enrolments current user needs to be able to do role assignments require_capability('moodle/role:assign', $context); $today = time(); -$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); +// MDL-18375, Multi-Calendar Support +$calendar_system_gregorian = calendar_system_factory::factory('gregorian'); +$today = $calendar_system_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); if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) { if (count($form->userid) != count($form->extendperiod) || count($form->userid) != count($form->extendbase)) { error('Parameters malformation', $CFG->wwwroot.'/user/index.php?id='.$id); diff -Naur moodle197_orig/user/groupextendenrol.php foodle197/user/groupextendenrol.php --- moodle197_orig/user/groupextendenrol.php 2007-08-18 03:09:20.000000000 +0100 +++ foodle197/user/groupextendenrol.php 2010-02-23 20:18:35.011875885 +0000 @@ -14,7 +14,10 @@ // to extend enrolments current user needs to be able to do role assignments require_capability('moodle/role:assign', $context); $today = time(); -$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); +// MDL-18375, Multi-Calendar Support +$calendar_system_gregorian = calendar_system_factory::factory('gregorian'); +$today = $calendar_system_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); if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) {