diff -Naur moodle.orig/admin/roles/assign.php moodle/admin/roles/assign.php --- moodle.orig/admin/roles/assign.php 2008-12-12 02:33:22.000000000 +0330 +++ moodle/admin/roles/assign.php 2009-02-23 14:12:21.000000000 +0330 @@ -1,5 +1,6 @@ dirroot.'/mod/forum/lib.php'); @@ -85,7 +86,8 @@ $timeformat = get_string('strftimedate'); $today = time(); - $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); + $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 moodle.orig/calendar/event.php moodle/calendar/event.php --- moodle.orig/calendar/event.php 2008-07-03 04:46:56.000000000 +0430 +++ moodle/calendar/event.php 2009-02-23 17:25:14.000000000 +0330 @@ -1,5 +1,5 @@ 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); } @@ -568,6 +568,8 @@ function validate_form(&$form, &$err) { + global $CALENDAR_SYSTEM; + $form->name = trim($form->name); $form->description = trim($form->description); @@ -579,10 +581,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 moodle.orig/calendar/export.php moodle/calendar/export.php --- moodle.orig/calendar/export.php 2009-01-21 02:35:37.000000000 +0330 +++ moodle/calendar/export.php 2009-02-23 17:25:33.000000000 +0330 @@ -1,5 +1,5 @@ dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/calendar/lib.php'); @@ -45,7 +45,7 @@ $navigation = build_navigation($navlinks); -if(!checkdate($mon, $day, $yr)) { +if(!$CALENDAR_SYSTEM->checkdate($mon, $day, $yr)) { $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); diff -Naur moodle.orig/calendar/lib.php moodle/calendar/lib.php --- moodle.orig/calendar/lib.php 2008-05-01 04:46:17.000000000 +0430 +++ moodle/calendar/lib.php 2009-02-23 17:25:45.000000000 +0330 @@ -1,5 +1,5 @@ minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY); @@ -84,7 +84,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 +105,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 +687,7 @@ } function calendar_top_controls($type, $data) { - global $CFG, $CALENDARDAYS, $THEME; + global $CFG, $CALENDARDAYS, $THEME, $CALENDAR_SYSTEM; $content = ''; if(!isset($data['d'])) { $data['d'] = 1; @@ -700,11 +700,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 +973,9 @@ } function calendar_days_in_month($month, $year) { - return intval(date('t', mktime(0, 0, 0, $month, 1, $year))); + 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 +1530,15 @@ function calendar_print_month_selector($name, $selected) { - $months = array(); + 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 moodle.orig/calendar/view.php moodle/calendar/view.php --- moodle.orig/calendar/view.php 2009-01-01 02:34:13.000000000 +0330 +++ moodle/calendar/view.php 2009-02-23 17:25:57.000000000 +0330 @@ -1,5 +1,5 @@ 'misc'); - if(!checkdate($mon, $day, $yr)) { + if(!$CALENDAR_SYSTEM->checkdate($mon, $day, $yr)) { $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); @@ -223,9 +223,9 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) { - global $CFG, $USER; + 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 +307,7 @@ } function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) { - global $CFG, $SESSION, $USER, $CALENDARDAYS; + 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 +325,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 +347,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 moodle.orig/calendar_system/calendar_system.class.php moodle/calendar_system/calendar_system.class.php --- moodle.orig/calendar_system/calendar_system.class.php 1970-01-01 03:30:00.000000000 +0330 +++ moodle/calendar_system/calendar_system.class.php 2008-12-10 14:29:00.000000000 +0330 @@ -0,0 +1,50 @@ +calendar_system; + } + 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 moodle.orig/calendar_system/gregorian/calendar_system.php moodle/calendar_system/gregorian/calendar_system.php --- moodle.orig/calendar_system/gregorian/calendar_system.php 1970-01-01 03:30:00.000000000 +0330 +++ moodle/calendar_system/gregorian/calendar_system.php 2008-08-21 00:51:23.000000000 +0430 @@ -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 moodle.orig/calendar_system/jalali/calendar_system.php moodle/calendar_system/jalali/calendar_system.php --- moodle.orig/calendar_system/jalali/calendar_system.php 1970-01-01 03:30:00.000000000 +0330 +++ moodle/calendar_system/jalali/calendar_system.php 2009-02-19 03:34:00.000000000 +0330 @@ -0,0 +1,287 @@ +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; + } + + public function get_max_year() + { + return 1420; + } + + 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 moodle.orig/config.php moodle/config.php --- moodle.orig/config.php 1970-01-01 03:30:00.000000000 +0330 +++ moodle/config.php 2009-02-23 17:05:09.000000000 +0330 @@ -0,0 +1,25 @@ +dbtype = 'mysql'; +$CFG->dbhost = 'localhost'; +$CFG->dbname = 'moodletest'; +$CFG->dbuser = 'root'; +$CFG->dbpass = '1234'; +$CFG->dbpersist = false; +$CFG->prefix = 'mdl_'; + +$CFG->wwwroot = 'http://localhost/~shamim/moodletest/moodle'; +$CFG->dirroot = '/home/shamim/public_html/moodletest/moodle'; +$CFG->dataroot = '/home/shamim/public_html/moodletest/moodledata'; +$CFG->admin = 'admin'; + +$CFG->calendar_system = 'jalali'; + +$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode + +require_once("$CFG->dirroot/lib/setup.php"); +// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES, +// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE. +?> \ No newline at end of file diff -Naur moodle.orig/enrol/authorize/config_form.php moodle/enrol/authorize/config_form.php --- moodle.orig/enrol/authorize/config_form.php 2008-07-05 04:46:52.000000000 +0430 +++ moodle/enrol/authorize/config_form.php 2009-02-23 14:17:19.000000000 +0330 @@ -1,4 +1,7 @@ enrol_cost)) $frm->enrol_cost = '5'; if (!isset($frm->enrol_currency)) $frm->enrol_currency = 'USD'; @@ -105,7 +108,7 @@ 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 moodle.orig/lang/en_utf8/calendar_system_gregorian.php moodle/lang/en_utf8/calendar_system_gregorian.php --- moodle.orig/lang/en_utf8/calendar_system_gregorian.php 1970-01-01 03:30:00.000000000 +0330 +++ moodle/lang/en_utf8/calendar_system_gregorian.php 2008-12-10 14:37:42.000000000 +0330 @@ -0,0 +1,3 @@ + \ No newline at end of file diff -Naur moodle.orig/lang/en_utf8/calendar_system_jalali.php moodle/lang/en_utf8/calendar_system_jalali.php --- moodle.orig/lang/en_utf8/calendar_system_jalali.php 1970-01-01 03:30:00.000000000 +0330 +++ moodle/lang/en_utf8/calendar_system_jalali.php 2008-12-10 14:38:07.000000000 +0330 @@ -0,0 +1,22 @@ + \ No newline at end of file diff -Naur moodle.orig/lang/en_utf8/moodle.php moodle/lang/en_utf8/moodle.php --- moodle.orig/lang/en_utf8/moodle.php 2009-02-17 02:35:30.000000000 +0330 +++ moodle/lang/en_utf8/moodle.php 2009-02-23 17:43:24.000000000 +0330 @@ -1219,6 +1219,7 @@ $string['potentialstudents'] = 'Potential students'; $string['potentialteachers'] = 'Potential teachers'; $string['preferences'] = 'Preferences'; +$string['preferredcalendar'] = 'Preferred calendar'; $string['preferredlanguage'] = 'Preferred language'; $string['preferredtheme'] = 'Preferred theme'; $string['preview'] = 'Preview'; diff -Naur moodle.orig/lib/accesslib.php moodle/lib/accesslib.php --- moodle.orig/lib/accesslib.php 2009-02-13 02:35:45.000000000 +0330 +++ moodle/lib/accesslib.php 2009-02-23 14:43:20.000000000 +0330 @@ -1,5 +1,5 @@ make_timestamp(date('Y', $timestart), date('m', $timestart), date('d', $timestart), 0, 0, 0); if ($course->enrolperiod) { $timeend = $timestart + $course->enrolperiod; } else { diff -Naur moodle.orig/lib/bennu/iCalendar_rfc2445.php moodle/lib/bennu/iCalendar_rfc2445.php --- moodle.orig/lib/bennu/iCalendar_rfc2445.php 2006-11-24 05:32:15.000000000 +0330 +++ moodle/lib/bennu/iCalendar_rfc2445.php 2009-02-23 14:19:59.000000000 +0330 @@ -1,5 +1,5 @@ checkdate($m, $d, $y); break; case RFC2445_TYPE_DATE_TIME: diff -Naur moodle.orig/lib/form/dateselector.php moodle/lib/form/dateselector.php --- moodle.orig/lib/form/dateselector.php 2007-04-14 05:40:30.000000000 +0330 +++ moodle/lib/form/dateselector.php 2009-02-23 14:25:21.000000000 +0330 @@ -1,4 +1,5 @@ libdir/form/group.php"; require_once "$CFG->libdir/formslib.php"; @@ -22,8 +23,8 @@ * 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); + 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,10 @@ */ function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { + 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 +71,16 @@ function _createElements() { + 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 moodle.orig/lib/form/datetimeselector.php moodle/lib/form/datetimeselector.php --- moodle.orig/lib/form/datetimeselector.php 2007-08-09 20:26:36.000000000 +0330 +++ moodle/lib/form/datetimeselector.php 2009-02-23 14:28:30.000000000 +0330 @@ -1,4 +1,5 @@ libdir/form/group.php"; require_once "$CFG->libdir/formslib.php"; @@ -21,8 +22,8 @@ * 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); + 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,10 @@ */ function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { + 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,13 +70,16 @@ function _createElements() { + 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 moodle.orig/lib/moodlelib.php moodle/lib/moodlelib.php --- moodle.orig/lib/moodlelib.php 2009-02-08 02:35:27.000000000 +0330 +++ moodle/lib/moodlelib.php 2009-02-23 16:21:57.000000000 +0330 @@ -1,5 +1,5 @@ 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); +} + +/** * Given an amount of time in seconds, returns string * formatted nicely as weeks, days, hours etc as needed * @@ -1210,7 +1233,7 @@ * zero from %d is removed. If false then the leading zero is mantained. * @return string */ -function userdate($date, $format='', $timezone=99, $fixday = true) { +function userdate_old($date, $format='', $timezone=99, $fixday = true) { global $CFG; @@ -1267,6 +1290,30 @@ } /** + * Returns a formatted string that represents a date in user time + * WARNING: note that the format is for strftime(), not date(). + * Because of a bug in most Windows time libraries, we can't use + * the nicer %e, so we have to use %d which has leading zeroes. + * A lot of the fuss in the function is just getting rid of these leading + * zeroes as efficiently as possible. + * + * If parameter fixday = true (default), then take off leading + * zero from %d, else mantain it. + * + * @uses HOURSECS + * @param int $date timestamp in GMT + * @param string $format strftime format + * @param float $timezone + * @param bool $fixday If true (default) then the leading + * zero from %d is removed. If false then the leading zero is mantained. + * @return string + */ +function userdate($date, $format='', $timezone=99, $fixday = true) { + global $CALENDAR_SYSTEM; + return $CALENDAR_SYSTEM->userdate($date, $format, $timezone, $fixday); +} + +/** * Given a $time timestamp in GMT (seconds since epoch), * returns an array that represents the date in user time * @@ -1276,7 +1323,7 @@ * @return array An array that represents the date in user time * @todo Finish documenting this function */ -function usergetdate($time, $timezone=99) { +function usergetdate_old($time, $timezone=99) { $strtimezone = NULL; if (!is_numeric($timezone)) { @@ -1312,6 +1359,21 @@ } /** + * Given a $time timestamp in GMT (seconds since epoch), + * returns an array that represents the date in user time + * + * @uses HOURSECS + * @param int $time Timestamp in GMT + * @param float $timezone ? + * @return array An array that represents the date in user time + * @todo Finish documenting this function + */ +function usergetdate($time, $timezone=99) { + global $CALENDAR_SYSTEM; + return $CALENDAR_SYSTEM->usergetdate($time, $timezone); +} + +/** * Given a GMT timestamp (seconds since epoch), offsets it by * the timezone. eg 3pm in India is 3pm GMT - 7 * 3600 seconds * @@ -1494,7 +1556,7 @@ * @return bool */ function calculate_user_dst_table($from_year = NULL, $to_year = NULL, $strtimezone = NULL) { - global $CFG, $SESSION; + global $CFG, $SESSION, $CALENDAR_SYSTEM; $usertz = get_user_timezone($strtimezone); @@ -1526,8 +1588,8 @@ } if(empty($SESSION->dst_range)) { // If creating from scratch - $from = max((empty($from_year) ? intval(date('Y')) - 3 : $from_year), 1971); - $to = min((empty($to_year) ? intval(date('Y')) + 3 : $to_year), 2035); + $from = max((empty($from_year) ? intval(date('Y')) - 3 : $from_year), $CALENDAR_SYSTEM->get_min_year()); + $to = min((empty($to_year) ? intval(date('Y')) + 3 : $to_year), $CALENDAR_SYSTEM->get_max_year()); // Fill in the array with the extra years we need to process $yearstoprocess = array(); @@ -1542,8 +1604,8 @@ // If needing to extend the table, do the same $yearstoprocess = array(); - $from = max((empty($from_year) ? $SESSION->dst_range[0] : $from_year), 1971); - $to = min((empty($to_year) ? $SESSION->dst_range[1] : $to_year), 2035); + $from = max((empty($from_year) ? $SESSION->dst_range[0] : $from_year), $CALENDAR_SYSTEM->get_min_year()); + $to = min((empty($to_year) ? $SESSION->dst_range[1] : $to_year), $CALENDAR_SYSTEM->get_max_year()); if($from < $SESSION->dst_range[0]) { // Take note of which years we need to process and then note that we have processed them for future calls @@ -1684,6 +1746,8 @@ function find_day_in_month($startday, $weekday, $month, $year) { + global $CALENDAR_SYSTEM; + $daysinmonth = days_in_month($month, $year); if($weekday == -1) { @@ -1705,7 +1769,7 @@ if($startday < 1) { $startday = abs($startday); - $lastmonthweekday = strftime('%w', mktime(12, 0, 0, $month, $daysinmonth, $year, 0)); + $lastmonthweekday = strftime('%w', $CALENDAR_SYSTEM->mktime(12, 0, 0, $month, $daysinmonth, $year, 0)); // This is the last such weekday of the month $lastinmonth = $daysinmonth + $weekday - $lastmonthweekday; @@ -1723,7 +1787,7 @@ } else { - $indexweekday = strftime('%w', mktime(12, 0, 0, $month, $startday, $year, 0)); + $indexweekday = strftime('%w', $CALENDAR_SYSTEM->mktime(12, 0, 0, $month, $startday, $year, 0)); $diff = $weekday - $indexweekday; if($diff < 0) { @@ -1746,7 +1810,9 @@ * @return int */ function days_in_month($month, $year) { - return intval(date('t', mktime(12, 0, 0, $month, 1, $year, 0))); + global $CALENDAR_SYSTEM; + return $CALENDAR_SYSTEM->calendar_days_in_month($month, $year); +// return intval(date('t', mktime(12, 0, 0, $month, 1, $year, 0))); } /** @@ -1758,9 +1824,8 @@ * @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))); + global $CALENDAR_SYSTEM; + return $CALENDAR_SYSTEM->dayofweek($day, $month, $year); } /// USER AUTHENTICATION AND LOGIN //////////////////////////////////////// diff -Naur moodle.orig/lib/setup.php moodle/lib/setup.php --- moodle.orig/lib/setup.php 2009-02-17 02:35:35.000000000 +0330 +++ moodle/lib/setup.php 2009-02-23 16:48:38.000000000 +0330 @@ -1,4 +1,6 @@ libdir .'/moodlelib.php'); // Other general-purpose functions require_once($CFG->libdir .'/eventslib.php'); // Events functions require_once($CFG->libdir .'/grouplib.php'); // Groups functions + 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,9 @@ /// 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 + + if (empty($USER->calendar_system)) { + $USER->calendar_system = ''; + } + $CALENDAR_SYSTEM = calendar_system_factory::factory($USER->calendar_system); ?> diff -Naur moodle.orig/lib/weblib.php moodle/lib/weblib.php --- moodle.orig/lib/weblib.php 2009-02-17 02:35:37.000000000 +0330 +++ moodle/lib/weblib.php 2009-02-23 16:48:47.000000000 +0330 @@ -1,4 +1,5 @@ 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 moodle.orig/user/editlib.php moodle/user/editlib.php --- moodle.orig/user/editlib.php 2008-07-06 04:48:04.000000000 +0430 +++ moodle/user/editlib.php 2009-02-23 17:36:28.000000000 +0330 @@ -1,4 +1,5 @@ addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages()); $mform->setDefault('lang', $CFG->lang); + $mform->addElement('select', 'calendar_system', get_string('preferredcalendar'), get_list_of_calendars()); + $mform->setDefault('calendar_system', $CFG->calendar_system); + if (!empty($CFG->allowuserthemes)) { $choices = array(); $choices[''] = get_string('default'); diff -Naur moodle.orig/user/extendenrol.php moodle/user/extendenrol.php --- moodle.orig/user/extendenrol.php 2007-08-18 05:39:20.000000000 +0330 +++ moodle/user/extendenrol.php 2009-02-23 16:48:57.000000000 +0330 @@ -1,4 +1,5 @@ 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 moodle.orig/user/groupextendenrol.php moodle/user/groupextendenrol.php --- moodle.orig/user/groupextendenrol.php 2007-08-18 05:39:20.000000000 +0330 +++ moodle/user/groupextendenrol.php 2009-02-23 16:50:07.000000000 +0330 @@ -1,4 +1,5 @@ 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()) {