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();
 }
 function Load()
 {
     /// Process the data before loading
     $this->ProcessEvents($this->mData, $this->mCategories);
     /// Make some links
     if (NULL !== $this->mPaths && NULL !== $this->mRangeFormat && NULL !== $this->mStartTime && NULL !== $this->mEndTime) {
         $days = Academic_time::DaysBetweenTimestamps($this->mStartTime, $this->mEndTime);
         $start = new Academic_time($this->mStartTime);
         $end = new Academic_time($this->mEndTime);
         $now = new Academic_time(time());
         $try_again = TRUE;
         if (0 === $start->AcademicDay() && 0 === $end->AcademicDay()) {
             $CI =& get_instance();
             $terms_apart = ($end->AcademicYear() - $start->AcademicYear()) * 6 + $end->AcademicTerm() - $start->AcademicTerm();
             // don't really need to scroll in years
             if (FALSE && $terms_apart >= 6) {
                 $this->SetData('ForwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() + 1, $start->AcademicTerm(), $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() + 1, $end->AcademicTerm(), $end->AcademicWeek())));
                 $this->SetData('BackwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() - 1, $start->AcademicTerm(), $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() - 1, $end->AcademicTerm(), $end->AcademicWeek())));
                 $try_again = FALSE;
             } elseif ($terms_apart > 0) {
                 $this->SetData('ForwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() + (5 === $start->AcademicTerm() ? 1 : 0), ($start->AcademicTerm() + 1) % 6, $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() + (5 === $start->AcademicTerm() ? 1 : 0), ($end->AcademicTerm() + 1) % 6, $end->AcademicWeek())));
                 $this->SetData('BackwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() - (0 === $start->AcademicTerm() ? 1 : 0), ($start->AcademicTerm() + 5) % 6, $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() - (0 === $start->AcademicTerm() ? 1 : 0), ($end->AcademicTerm() + 5) % 6, $end->AcademicWeek())));
                 $try_again = FALSE;
             }
             $this->SetData('NowUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($now->AcademicYear(), $now->AcademicTerm(), 1), $CI->academic_calendar->Academic($now->AcademicYear() + (5 === $start->AcademicTerm() ? 1 : 0), ($now->AcademicTerm() + 1) % 6, 1)));
             $this->SetData('NowUrlLabel', 'This term');
         }
         if ($try_again) {
             $now = $now->Midnight();
             if ($days >= 7) {
                 $forward_jump = '1week';
                 $now = $now->BackToMonday();
                 $this->SetData('NowUrlLabel', 'This week');
             } else {
                 $forward_jump = '1day';
                 $this->SetData('NowUrlLabel', 'Today');
             }
             $this->SetData('ForwardUrl', $this->GenerateRangeUrl($start->Adjust($forward_jump), $end->Adjust($forward_jump)));
             $this->SetData('BackwardUrl', $this->GenerateRangeUrl($start->Adjust('-' . $forward_jump), $end->Adjust('-' . $forward_jump)));
             $this->SetData('NowUrl', $this->GenerateRangeUrl($now, $now->Adjust('+' . $forward_jump)));
         }
     }
     parent::Load();
 }