function ajax_termdates() { OutputModes('ajax'); if (!CheckPermissions('public')) { return; } $error = false; $years = array(); if (isset($_GET['years'])) { $year_ranges = split(',', $_GET['years']); foreach ($year_ranges as $year_range) { if ($year_range === '') { continue; } $ends = split('-', $year_range); if (count($ends) > 2) { $this->main_frame->Error(array('class' => 'error', 'text' => 'Invalid year range: ' . $year_range)); $error = true; } else { if (count($ends) == 1) { $ends = array($year_range, $year_range); } $range_error = false; foreach ($ends as &$end) { if (is_numeric($end) && $end >= 1970 && $end < 2037) { $end = (int) $end; } else { $this->main_frame->Error(array('class' => 'error', 'text' => 'Invalid year: ' . $end)); $range_error = true; } } if (!$range_error) { for ($year = $ends[0]; $year <= $ends[1]; ++$year) { $years[] = $year; } } else { $error = true; } } } } if (!$error) { $root = array('_tag' => 'calendar', 'termdates' => array()); foreach ($years as $year) { $acyear = array('_tag' => 'academicyear', '_attr' => array('year' => $year)); for ($term = 0; $term < 6; ++$term) { $start_ts = Academic_time::StartOfAcademicTerm($year, $term); $monday_ts = Academic_time::MondayWeek1OfAcademicTerm($year, $term); $start = new Academic_time($start_ts); $days = Academic_time::LengthOfAcademicTerm($year, $term); $end = $start->Adjust($days . 'days'); $monday = new Academic_time($monday_ts); $acterm = array('_tag' => 'term', '_attr' => array('id' => "term_{$year}_{$term}", 'term' => $term), 'type' => $start->AcademicTermTypeName(), 'name' => $start->AcademicTermName(), 'unique' => $start->AcademicTermNameUnique(), 'start' => $start->Format('Y-m-d'), 'end' => $end->Format('Y-m-d'), 'days' => $days, 'mondayweek1' => $monday->Format('Y-m-d'), 'weeks' => $start->AcademicTermWeeks()); $acyear[] = $acterm; } $root['termdates'][] = $acyear; } $this->main_frame->SetXml($root); } $this->main_frame->Load(); }
/** * @brief Get a time object from an academic date & time. * @param $AcademicYear Year at start of academic year integer [2006..]. * @param $Term Term of the year integer [0..5]. * @param $Week Week integer [1..]. * @param $DayOfWeek Day of week integer [1..7]. * @param $Hour Hour of the day integer [0..23]. * @param $Minute Minute of the hour integer [0..59]. * @param $Second Second of the minute integer [0..59]. * @return Academic_time object set with academic term data. */ function Academic($AcademicYear, $Term = 0, $Week = 1, $DayOfWeek = 1, $Hour = 0, $Minute = 0, $Second = 0) { $start_of_term = Academic_time::MondayWeek1OfAcademicTerm($AcademicYear, $Term); return new Academic_time(strtotime($Week - 1 . 'week' . ($DayOfWeek - 1) . 'day' . $Hour . 'hour' . $Minute . 'min' . $Second . 'sec', $start_of_term)); }