Esempio n. 1
0
 /**
  * Main action to display contacts
  */
 function index_action($filter = null)
 {
     // Check if we need to add contacts
     $mps = MultiPersonSearch::load('contacts');
     $imported = 0;
     foreach ($mps->getAddedUsers() as $userId) {
         $user_to_add = User::find($userId);
         if ($user_to_add) {
             $new_contact = array('owner_id' => User::findCurrent()->id, 'user_id' => $user_to_add->id);
             if ($filter && $this->group) {
                 $new_contact['group_assignments'][] = array('statusgruppe_id' => $this->group->id, 'user_id' => $user_to_add->id);
             }
             $imported += (bool) Contact::import($new_contact)->store();
         }
     }
     if ($imported) {
         PageLayout::postMessage(MessageBox::success(sprintf(_("%s Kontakte wurden hinzugefügt."), $imported)));
     }
     $mps->clearSession();
     // write filter to local
     $this->filter = $filter;
     // Deal with navigation
     Navigation::activateItem('community/contacts');
     // Edit CSS for quicknavigation
     PageLayout::addStyle('div.letterlist span {color: #c3c8cc;}');
     if ($filter) {
         $selected = $this->group;
         $contacts = SimpleCollection::createFromArray(User::findMany($selected->members->pluck('user_id')));
     } else {
         $contacts = User::findCurrent()->contacts;
     }
     $this->allContacts = $contacts;
     // Retrive first letter and store in that contactgroup
     $this->contacts = array();
     foreach ($contacts as $contact) {
         $this->contacts[strtoupper(SimpleCollection::translitLatin1($contact->nachname[0]))][] = $contact;
     }
     // Humans are a lot better with sorted results
     ksort($this->contacts);
     $this->contacts = array_map(function ($g) {
         return SimpleCollection::createFromArray($g)->orderBy('nachname, vorname');
     }, $this->contacts);
     // Init sidebar
     $this->initSidebar($filter);
     // Init person search
     $mps = MultiPersonSearch::get('contacts')->setTitle(_('Kontakte hinzufügen'))->setDefaultSelectedUser($this->allContacts->pluck('user_id'))->setExecuteURL($this->url_for('contact/index/' . $filter))->setSearchObject(new StandardSearch('user_id'));
     // Set default title
     $this->title = _('Alle Kontakte');
     // If we have a group
     if ($selected) {
         // Set title of Table
         $this->title = $selected->name;
         // Set title of multipersonsearch
         $mps->setTitle(sprintf(_('Kontakte zu %s hinzufügen'), $selected->name));
         $mps->addQuickfilter(_('Kontakte'), User::findCurrent()->contacts->pluck('user_id'));
     }
     // Render multiperson search
     $this->multiPerson = $mps->render();
 }
Esempio n. 2
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  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))
  */
 function index_action($days = false)
 {
     if ($GLOBALS['perm']->have_perm('admin')) {
         $inst_mode = true;
     }
     $my_schedule_settings = $GLOBALS['user']->cfg->SCHEDULE_SETTINGS;
     // set the days to be displayed
     if ($days === false) {
         if (Request::getArray('days')) {
             $this->days = array_keys(Request::getArray('days'));
         } else {
             $this->days = array(0, 1, 2, 3, 4, 5, 6);
         }
     } else {
         $this->days = explode(',', $days);
     }
     // 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 = $GLOBALS['user']->cfg->MY_INSTITUTES_DEFAULT;
     }
     if (!$institute_id || in_array(get_object_type($institute_id), words('inst fak')) === false) {
         throw new Exception(sprintf(_('Kann Einrichtungskalendar nicht anzeigen!' . 'Es wurde eine ungültige Instituts-Id übergeben (%s)!', $institute_id)));
     }
     // load semester-data and current semester
     $semdata = new SemesterData();
     $this->semesters = $semdata->getAllSemesterData();
     if (Request::option('semester_id')) {
         $this->current_semester = $semdata->getSemesterData(Request::option('semester_id'));
     } else {
         $this->current_semester = $semdata->getCurrentSemesterData();
     }
     $this->entries = (array) CalendarInstscheduleModel::getInstituteEntries($GLOBALS['user']->id, $this->current_semester, 8, 20, $institute_id, $this->days);
     Navigation::activateItem('/course/main/schedule');
     PageLayout::setHelpKeyword('Basis.TerminkalenderStundenplan');
     PageLayout::setTitle($GLOBALS['SessSemName']['header_line'] . ' - ' . _('Veranstaltungs-Stundenplan'));
     $zoom = Request::int('zoom', 0);
     $this->controller = $this;
     $this->calendar_view = new CalendarWeekView($this->entries, 'instschedule');
     $this->calendar_view->setHeight(40 + 20 * $zoom);
     $this->calendar_view->setRange($my_schedule_settings['glb_start_time'], $my_schedule_settings['glb_end_time']);
     $this->calendar_view->groupEntries();
     // if enabled, group entries with same start- and end-date
     URLHelper::addLinkParam('zoom', $zoom);
     URLHelper::addLinkParam('semester_id', $this->current_semester['semester_id']);
     $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));
     if (Request::option('printview')) {
         PageLayout::addStylesheet('print.css');
     } else {
         PageLayout::addStylesheet('print.css', array('media' => 'print'));
     }
 }
Esempio n. 3
0
 /**
  * outputs the CalendarView with all (grouped) dates in columns.
  *
  * @param  array  $params  you can pass some additional variables to the templates
  *
  * @return string
  */
 public function render($params = array())
 {
     $style_parameters = array('whole_height' => $this->getOverallHeight(), 'entry_height' => $this->getHeight());
     $factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/../../app/views');
     PageLayout::addStyle($factory->render('calendar/stylesheet', $style_parameters));
     $template = $GLOBALS['template_factory']->open("calendar/calendar_view.php");
     $template->set_attribute("calendar_view", $this);
     $template->set_attribute("view_id", $this->view_id);
     return $template->render($params);
 }
Esempio n. 4
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;
     }
 }
Esempio n. 5
0
 /**
  * Includes given stylesheet in page, compiles less if neccessary
  *
  * @param String $filename Name of the stylesheet (css or less) to include
  *                         (relative to plugin directory)
  */
 protected function addStylesheet($filename)
 {
     if (substr($filename, -5) !== '.less') {
         $url = $this->getPluginURL() . '/' . $filename;
         PageLayout::addStylesheet($url);
         return;
     }
     // Create absolute path to less file
     $less_file = $GLOBALS['ABSOLUTE_PATH_STUDIP'] . $this->getPluginPath() . '/' . $filename;
     // Fail if file does not exist
     if (!file_exists($less_file)) {
         throw new Exception('Could not locate LESS file "' . $filename . '"');
     }
     // Get plugin version from metadata
     $metadata = $this->getMetadata();
     $plugin_version = $metadata['version'];
     // Get plugin id (or parent plugin id if any)
     $plugin_id = $this->plugin_info['depends'] ?: $this->getPluginId();
     // Get asset file from storage
     $asset = Assets\Storage::getFactory()->createCSSFile($less_file, array('plugin_id' => $this->plugin_info['depends'] ?: $this->getPluginId(), 'plugin_version' => $metadata['version']));
     // Compile asset if neccessary
     if ($asset->isNew()) {
         $less = file_get_contents($less_file);
         $css = Assets\Compiler::compileLESS($less, array('plugin-path' => $this->getPluginURL()));
         $asset->setContent($css);
     }
     // Include asset in page by reference or directly
     $download_uri = $asset->getDownloadLink();
     if ($download_uri === false) {
         PageLayout::addStyle($asset->getContent());
     } else {
         PageLayout::addHeadElement('link', ['rel' => 'stylesheet', 'href' => $download_uri, 'type' => 'text/css']);
     }
 }