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 @@