Example #1
0
 /**
  * this action is the main action of the schedule-controller, setting the environment
  * for the timetable, accepting a comma-separated list of days.
  *
  * @param  string  $days  a list of an arbitrary mix of the numbers 0-6, separated
  *                        with a comma (e.g. 1,2,3,4,5 (for Monday to Friday, the default))
  * @return void
  */
 function index_action($days = false)
 {
     global $user;
     $schedule_settings = CalendarScheduleModel::getScheduleSettings();
     if ($GLOBALS['perm']->have_perm('admin')) {
         $inst_mode = true;
     }
     if ($inst_mode) {
         // try to find the correct institute-id
         $institute_id = Request::option('institute_id', $SessSemName[1] ? $SessSemName[1] : Request::option('cid', false));
         if (!$institute_id) {
             $institute_id = UserConfig::get($user->id)->MY_INSTITUTES_DEFAULT;
         }
         if (!$institute_id || !in_array(get_object_type($institute_id), words('fak inst'))) {
             throw new Exception('Cannot display institute-calender. No valid ID given!');
         }
         Navigation::activateItem('/browse/my_courses/schedule');
     } else {
         Navigation::activateItem('/calendar/schedule');
     }
     // check, if the hidden seminar-entries shall be shown
     $show_hidden = Request::int('show_hidden', 0);
     // load semester-data and current semester
     $semdata = new SemesterData();
     $this->semesters = array_reverse($semdata->getAllSemesterData());
     if (Request::option('semester_id')) {
         $this->current_semester = $semdata->getSemesterData(Request::option('semester_id'));
     } else {
         $this->current_semester = $semdata->getCurrentSemesterData();
     }
     // check type-safe if days is false otherwise sunday (0) cannot be chosen
     if ($days === false) {
         if (Request::getArray('days')) {
             $this->days = array_keys(Request::getArray('days'));
         } else {
             $this->days = $schedule_settings['glb_days'];
             foreach ($this->days as $key => $day_number) {
                 $this->days[$key] = ($day_number + 6) % 7;
             }
         }
     } else {
         $this->days = explode(',', $days);
     }
     $this->controller = $this;
     $this->calendar_view = $inst_mode ? CalendarScheduleModel::getInstCalendarView($institute_id, $show_hidden, $this->current_semester, $this->days) : CalendarScheduleModel::getUserCalendarView($GLOBALS['user']->id, $show_hidden, $this->current_semester, $this->days);
     // have we chosen an entry to display?
     if ($this->flash['entry']) {
         if ($inst_mode) {
             $this->show_entry = $this->flash['entry'];
         } else {
             if ($this->flash['entry']['id'] == null) {
                 $this->show_entry = $this->flash['entry'];
             } else {
                 foreach ($this->calendar_view->getColumns() as $entry_days) {
                     foreach ($entry_days->getEntries() as $entry) {
                         if ($this->flash['entry']['cycle_id']) {
                             if ($this->flash['entry']['id'] . '-' . $this->flash['entry']['cycle_id'] == $entry['id']) {
                                 $this->show_entry = $entry;
                                 $this->show_entry['id'] = reset(explode('-', $this->show_entry['id']));
                             }
                         } else {
                             if ($entry['id'] == $this->flash['entry']['id']) {
                                 $this->show_entry = $entry;
                             }
                         }
                     }
                 }
             }
         }
     }
     $style_parameters = array('whole_height' => $this->calendar_view->getOverallHeight(), 'entry_height' => $this->calendar_view->getHeight());
     $factory = new Flexi_TemplateFactory($this->dispatcher->trails_root . '/views');
     PageLayout::addStyle($factory->render('calendar/stylesheet', $style_parameters), 'screen, print');
     if (Request::option('printview')) {
         $this->calendar_view->setReadOnly();
         PageLayout::addStylesheet('print.css');
     } else {
         PageLayout::addStylesheet('print.css', array('media' => 'print'));
     }
     $this->show_hidden = $show_hidden;
     $inst = get_object_name($institute_id, 'inst');
     $this->inst_mode = $inst_mode;
     $this->institute_name = $inst['name'];
     $this->institute_id = $institute_id;
     if (Request::get('show_settings')) {
         $this->show_settings = true;
     }
 }