Ejemplo n.º 1
0
 /**
  * Shows a dialog for creating or editing a course wizard step.
  * @param string $id ID of step to edit, or null if new step
  */
 public function edit_action($id = '')
 {
     if ($id) {
         $title = _('Schritt bearbeiten');
         $this->step = CourseWizardStepRegistry::find($id);
     } else {
         $title = _('Schritt hinzufügen');
         $this->step = new CourseWizardStepRegistry();
         $this->step->name = '';
         $this->step->classname = '';
         $this->step->number = 0;
         $this->step->enabled = false;
         $this->availableClasses = array();
         foreach (get_declared_classes() as $className) {
             if (is_a($className, "CourseWizardStep", true) && $className !== "CourseWizardStep") {
                 $collection = new SimpleCollection(CourseWizardStepRegistry::findBySQL("1 ORDER BY `number`"));
                 if (!in_array($className, $collection->pluck("classname"))) {
                     $this->availableClasses[] = $className;
                 }
             }
         }
     }
     if (Request::isXhr()) {
         $this->response->add_header('X-Title', $title);
     }
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 public function getUsers()
 {
     if ($this->anonymous) {
         return $this->anonymous_users;
     }
     $result = array();
     foreach ($this->answers as $answer) {
         foreach ($answer->users as $user) {
             $result[$user->user_id] = $user;
         }
     }
     return SimpleCollection::createFromArray(array_values($result));
 }
Ejemplo n.º 4
0
 /**
  * List all contact groups of a user
  *
  * @get /user/:user_id/contact_groups
  */
 public function getUserContactGroups($user_id)
 {
     if ($GLOBALS['user']->id !== $user_id) {
         $this->error(401);
     }
     $contact_groups = \SimpleCollection::createFromArray(\Statusgruppen::findByRange_id($GLOBALS['user']->id))->orderBy('name ASC');
     $total = count($contact_groups);
     $contact_groups = $contact_groups->limit($this->offset, $this->limit);
     $contact_groups_json = $this->contactGroupsToJSON($contact_groups);
     $this->etag(md5(serialize($contact_groups_json)));
     return $this->paginated($contact_groups_json, $total, compact('user_id'));
 }
Ejemplo n.º 5
0
 /**
  * Returns a widget for semester selection
  * @param $sem
  * @return OptionsWidget
  */
 private function setSemesterWidget(&$sem)
 {
     $semesters = new SimpleCollection(Semester::getAll());
     $this->sem = $sem;
     $this->semesters = $semesters->orderBy('beginn desc');
     $sidebar = Sidebar::Get();
     $widget = new SidebarWidget();
     $widget->setTitle(_('Semesterfilter'));
     $this->render_template('my_courses/_semester_filter.php', null);
     $html = $this->response->body;
     $this->erase_response();
     $widget->addElement(new WidgetElement($html));
     $sidebar->addWidget($widget);
 }
Ejemplo n.º 6
0
 public function getMemberData($member)
 {
     $datafields = SimpleCollection::createFromArray(DatafieldEntryModel::findByModel($member));
     foreach ($this->datafields as $field => $useless_value_pls_refactor) {
         // since we have no only datafields we have to filter!
         if ($new = $datafields->findOneBy('datafield_id', $field)) {
             $result[] = $new;
         }
     }
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * Zeigt die Grunddaten an. Man beachte, dass eventuell zuvor eine andere
  * Action wie Set ausgeführt wurde, von der hierher weitergeleitet worden ist.
  * Wichtige Daten dazu wurden dann über $this->flash übertragen.
  *
  * @param md5 $course_id
  */
 public function view_action($course_id = null)
 {
     global $user, $perm, $_fullname_sql;
     $deputies_enabled = get_config('DEPUTIES_ENABLE');
     //damit QuickSearch funktioniert:
     Request::set('new_doz_parameter', $this->flash['new_doz_parameter']);
     if ($deputies_enabled) {
         Request::set('new_dep_parameter', $this->flash['new_dep_parameter']);
     }
     Request::set('new_tut_parameter', $this->flash['new_tut_parameter']);
     $this->course_id = Request::option('cid', $course_id);
     Navigation::activateItem('/course/admin/details');
     //Berechtigungscheck:
     if (!$perm->have_studip_perm("tutor", $this->course_id)) {
         throw new AccessDeniedException(_("Sie haben keine Berechtigung diese " . "Veranstaltung zu verändern."));
     }
     //Kopf initialisieren:
     PageLayout::setHelpKeyword("Basis.VeranstaltungenVerwaltenGrunddaten");
     PageLayout::setTitle(_("Verwaltung der Grunddaten"));
     if ($this->course_id) {
         PageLayout::setTitle(Course::find($this->course_id)->getFullname() . " - " . PageLayout::getTitle());
     }
     //Daten sammeln:
     $sem = Seminar::getInstance($this->course_id);
     $data = $sem->getData();
     //Erster Reiter des Akkordions: Grundeinstellungen
     $this->attributes = array();
     $this->attributes[] = array('title' => _("Name der Veranstaltung"), 'name' => "course_name", 'must' => true, 'type' => 'text', 'value' => $data['name'], 'locked' => LockRules::Check($this->course_id, 'Name'));
     $this->attributes[] = array('title' => _("Untertitel der Veranstaltung"), 'name' => "course_subtitle", 'type' => 'text', 'value' => $data['subtitle'], 'locked' => LockRules::Check($this->course_id, 'Untertitel'));
     $sem_types = array();
     if ($perm->have_perm("admin")) {
         foreach (SemClass::getClasses() as $sc) {
             foreach ($sc->getSemTypes() as $st) {
                 if (!$sc['course_creation_forbidden']) {
                     $sem_types[$st['id']] = $st['name'] . ' (' . $sc['name'] . ')';
                 }
             }
         }
     } else {
         $sc = $sem->getSemClass();
         foreach ($sc->getSemTypes() as $st) {
             $sem_types[$st['id']] = $st['name'] . ' (' . $sc['name'] . ')';
         }
     }
     if (!isset($sem_types[$data['status']])) {
         $sem_types[$data['status']] = $sem->getSemType()->offsetGet('name');
     }
     $this->attributes[] = array('title' => _("Typ der Veranstaltung"), 'name' => "course_status", 'must' => true, 'type' => 'select', 'value' => $data['status'], 'locked' => LockRules::Check($this->course_id, 'status'), 'choices' => array_map('htmlReady', $sem_types));
     $this->attributes[] = array('title' => _("Art der Veranstaltung"), 'name' => "course_form", 'type' => 'text', 'value' => $data['form'], 'locked' => LockRules::Check($this->course_id, 'art'));
     $this->attributes[] = array('title' => _("Veranstaltungs-Nummer"), 'name' => "course_seminar_number", 'type' => 'text', 'value' => $data['seminar_number'], 'locked' => LockRules::Check($this->course_id, 'VeranstaltungsNummer'));
     $this->attributes[] = array('title' => _("ECTS-Punkte"), 'name' => "course_ects", 'type' => 'text', 'value' => $data['ects'], 'locked' => LockRules::Check($this->course_id, 'ects'));
     $this->attributes[] = array('title' => _("max. Teilnehmerzahl"), 'name' => "course_admission_turnout", 'must' => false, 'type' => 'number', 'value' => $data['admission_turnout'], 'locked' => LockRules::Check($this->course_id, 'admission_turnout'), 'min' => '0');
     $this->attributes[] = array('title' => _("Beschreibung"), 'name' => "course_description", 'type' => 'textarea', 'value' => $data['description'], 'locked' => LockRules::Check($this->course_id, 'Beschreibung'));
     //Zweiter Reiter: Institute
     $this->institutional = array();
     $institute = Institute::getMyInstitutes();
     $choices = array();
     foreach ($institute as $inst) {
         //$choices[$inst['Institut_id']] = $inst['Name'];
         $choices[$inst['Institut_id']] = ($inst['is_fak'] ? "<span style=\"font-weight: bold\">" : "&nbsp;&nbsp;&nbsp;&nbsp;") . htmlReady($inst['Name']) . ($inst['is_fak'] ? "</span>" : "");
     }
     $this->institutional[] = array('title' => _("Heimat-Einrichtung"), 'name' => "course_institut_id", 'must' => true, 'type' => 'select', 'value' => $data['institut_id'], 'choices' => $choices, 'locked' => LockRules::Check($this->course_id, 'Institut_id'));
     $institute = Institute::getInstitutes();
     $choices = array();
     foreach ($institute as $inst) {
         $choices[$inst['Institut_id']] = ($inst['is_fak'] ? "<span style=\"font-weight: bold\">" : "&nbsp;&nbsp;&nbsp;&nbsp;") . htmlReady($inst['Name']) . ($inst['is_fak'] ? "</span>" : "");
     }
     $sem_institutes = $sem->getInstitutes();
     $inst = array_flip($sem_institutes);
     unset($inst[$sem->institut_id]);
     $inst = array_flip($inst);
     $this->institutional[] = array('title' => _("beteiligte Einrichtungen"), 'name' => "related_institutes[]", 'type' => 'multiselect', 'value' => $inst, 'choices' => $choices, 'locked' => LockRules::Check($this->course_id, 'seminar_inst'));
     $this->dozent_is_locked = LockRules::Check($this->course_id, 'dozent');
     $this->tutor_is_locked = LockRules::Check($this->course_id, 'tutor');
     //Dritter Reiter: Personal
     $this->dozenten = $sem->getMembers('dozent');
     $instUsers = new SimpleCollection(InstituteMember::findByInstituteAndStatus($sem->getInstitutId(), 'dozent'));
     $this->lecturersOfInstitute = $instUsers->pluck('user_id');
     if (SeminarCategories::getByTypeId($sem->status)->only_inst_user) {
         $search_template = "user_inst_not_already_in_sem";
     } else {
         $search_template = "user_not_already_in_sem";
     }
     $this->dozentUserSearch = new PermissionSearch($search_template, sprintf(_("%s suchen"), get_title_for_status('dozent', 1, $sem->status)), "user_id", array('permission' => 'dozent', 'seminar_id' => $this->course_id, 'sem_perm' => 'dozent', 'institute' => $sem_institutes));
     $this->dozenten_title = get_title_for_status('dozent', 1, $sem->status);
     $this->deputies_enabled = $deputies_enabled;
     if ($this->deputies_enabled) {
         $this->deputies = getDeputies($this->course_id);
         $this->deputySearch = new PermissionSearch("user_not_already_in_sem_or_deputy", sprintf(_("%s suchen"), get_title_for_status('deputy', 1, $sem->status)), "user_id", array('permission' => getValidDeputyPerms(), 'seminar_id' => $this->course_id));
         $this->deputy_title = get_title_for_status('deputy', 1, $sem->status);
     }
     $this->tutoren = $sem->getMembers('tutor');
     $this->tutorUserSearch = new PermissionSearch($search_template, sprintf(_("%s suchen"), get_title_for_status('tutor', 1, $sem->status)), "user_id", array('permission' => array('dozent', 'tutor'), 'seminar_id' => $this->course_id, 'sem_perm' => array('dozent', 'tutor'), 'institute' => $sem_institutes));
     $this->tutor_title = get_title_for_status('tutor', 1, $sem->status);
     $instUsers = new SimpleCollection(InstituteMember::findByInstituteAndStatus($sem->getInstitutId(), 'tutor'));
     $this->tutorsOfInstitute = $instUsers->pluck('user_id');
     unset($instUsers);
     //Vierter Reiter: Beschreibungen (darunter Datenfelder)
     $this->descriptions[] = array('title' => _("Teilnehmde"), 'name' => "course_participants", 'type' => 'textarea', 'value' => $data['participants'], 'locked' => LockRules::Check($this->course_id, 'teilnehmer'));
     $this->descriptions[] = array('title' => _("Voraussetzungen"), 'name' => "course_requirements", 'type' => 'textarea', 'value' => $data['requirements'], 'locked' => LockRules::Check($this->course_id, 'voraussetzungen'));
     $this->descriptions[] = array('title' => _("Lernorganisation"), 'name' => "course_orga", 'type' => 'textarea', 'value' => $data['orga'], 'locked' => LockRules::Check($this->course_id, 'lernorga'));
     $this->descriptions[] = array('title' => _("Leistungsnachweis"), 'name' => "course_leistungsnachweis", 'type' => 'textarea', 'value' => $data['leistungsnachweis'], 'locked' => LockRules::Check($this->course_id, 'leistungsnachweis'));
     $this->descriptions[] = array('title' => _("Ort") . "<br><span style=\"font-size: 0.8em\"><b>" . _("Achtung:") . "&nbsp;</b>" . _("Diese Ortsangabe wird nur angezeigt, wenn keine " . "Angaben aus Zeiten oder Sitzungsterminen gemacht werden können.") . "</span>", 'name' => "course_location", 'type' => 'textarea', 'value' => $data['location'], 'locked' => LockRules::Check($this->course_id, 'Ort'));
     $datenfelder = DataFieldEntry::getDataFieldEntries($this->course_id, 'sem', $data["status"]);
     if ($datenfelder) {
         foreach ($datenfelder as $datenfeld) {
             if ($datenfeld->isVisible()) {
                 $locked = !$datenfeld->isEditable() || LockRules::Check($this->course_id, $datenfeld->getID());
                 $this->descriptions[] = array('title' => $datenfeld->getName(), 'must' => $datenfeld->isRequired(), 'name' => "datafield_" . $datenfeld->getID(), 'type' => "datafield", 'html_value' => $datenfeld->getHTML("datafields"), 'display_value' => $datenfeld->getDisplayValue(), 'locked' => $locked, 'description' => !$datenfeld->isEditable() ? "Diese Felder werden zentral durch die zuständigen Administratoren erfasst." : $datenfeld->getDescription());
             }
         }
     }
     $this->descriptions[] = array('title' => _("Sonstiges"), 'name' => "course_misc", 'type' => 'textarea', 'value' => $data['misc'], 'locked' => LockRules::Check($this->course_id, 'Sonstiges'));
     $this->perm_dozent = $perm->have_studip_perm("dozent", $this->course_id);
     $this->mkstring = $data['mkdate'] ? date("d.m.Y, G:i", $data['mkdate']) : _("unbekannt");
     $this->chstring = $data['chdate'] ? date("d.m.Y, G:i", $data['chdate']) : _("unbekannt");
     $lockdata = LockRules::getObjectRule($this->course_id);
     if ($lockdata['description'] && LockRules::CheckLockRulePermission($this->course_id, $lockdata['permission'])) {
         $this->flash['msg'] = array_merge((array) $this->flash['msg'], array(array("info", formatLinks($lockdata['description']))));
     }
     $this->flash->discard();
     //schmeißt ab jetzt unnötige Variablen aus der Session.
     $sidebar = Sidebar::get();
     $sidebar->setImage("sidebar/admin-sidebar.png");
     $widget = new ActionsWidget();
     $widget->addLink(_('Bild ändern'), $this->url_for('course/avatar/update', $course_id), Icon::create('edit', 'clickable'));
     if ($this->deputies_enabled) {
         if (isDeputy($user->id, $this->course_id)) {
             $newstatus = 'dozent';
             $text = _('Lehrende werden');
         } else {
             if (in_array($user->id, array_keys($this->dozenten)) && sizeof($this->dozenten) > 1) {
                 $newstatus = 'deputy';
                 $text = _('Vertretung werden');
             }
         }
         $widget->addLink($text, $this->url_for('course/basicdata/switchdeputy', $this->course_id, $newstatus), Icon::create('persons', 'clickable'));
     }
     $sidebar->addWidget($widget);
     // Entry list for admin upwards.
     if ($perm->have_studip_perm("admin", $this->course_id)) {
         $list = new SelectorWidget();
         $list->setUrl("?#admin_top_links");
         $list->setSelectParameterName("cid");
         foreach (AdminCourseFilter::get()->getCoursesForAdminWidget() as $seminar) {
             $list->addElement(new SelectElement($seminar['Seminar_id'], $seminar['Name']), 'select-' . $seminar['Seminar_id']);
         }
         $list->setSelection($this->course_id);
         $sidebar->addWidget($list);
     }
 }
Ejemplo n.º 8
0
 /**
  * @depends testSimpleDirectoryConstruct
  * @expectedException Sabre\DAV\Exception\NotFound
  */
 public function testSimpleDirectoryGetChild404()
 {
     $dir = new SimpleCollection('simpledir');
     $dir->getChild('blabla');
 }
Ejemplo n.º 9
0
 public function execute($last_result, $parameters = array())
 {
     $verbose = $parameters['verbose'];
     $sets = DbManager::get()->fetchFirst("SELECT DISTINCT cr.set_id FROM courseset_rule cr INNER JOIN coursesets USING(set_id)\n                          WHERE type = 'ParticipantRestrictedAdmission' AND algorithm_run = 0");
     if (count($sets)) {
         if ($verbose) {
             echo date('r') . ' - Starting seat distribution ' . chr(10);
             $old_logger = Log::get()->getHandler();
             $old_log_level = Log::get()->getLogLevel();
             @mkdir($GLOBALS['TMP_PATH'] . '/seat_distribution_logs');
             $logfile = $GLOBALS['TMP_PATH'] . '/seat_distribution_logs/' . date('Y-m-d-H-i') . '_seat_distribution.log';
             if (is_dir($GLOBALS['TMP_PATH'] . '/seat_distribution_logs')) {
                 Log::get()->setHandler($logfile);
                 Log::get()->setLogLevel(Log::DEBUG);
                 echo 'logging to ' . $logfile . chr(10);
             } else {
                 echo 'could not create directory ' . $GLOBALS['TMP_PATH'] . '/seat_distribution_logs' . chr(10);
             }
         }
         foreach ($sets as $set_id) {
             $courseset = new CourseSet($set_id);
             if ($courseset->isSeatDistributionEnabled() && !$courseset->hasAlgorithmRun() && $courseset->getSeatDistributionTime() < time()) {
                 if ($verbose) {
                     echo ++$i . ' ' . $courseset->getId() . ' : ' . $courseset->getName() . chr(10);
                     $applicants = AdmissionPriority::getPriorities($set_id);
                     $courses = SimpleCollection::createFromArray(Course::findMany($courseset->getCourses()))->toGroupedArray('seminar_id', words('name veranstaltungsnummer'));
                     $captions = array(_("Nachname"), _("Vorname"), _("Nutzername"), _('Nutzer-ID'), _('Veranstaltung-ID'), _("Veranstaltung"), _("Nummer"), _("Priorität"));
                     $data = array();
                     $users = User::findEachMany(function ($user) use($courses, $applicants, &$data) {
                         $app_courses = $applicants[$user->id];
                         asort($app_courses);
                         foreach ($app_courses as $course_id => $prio) {
                             $row = array();
                             $row[] = $user->nachname;
                             $row[] = $user->vorname;
                             $row[] = $user->username;
                             $row[] = $user->id;
                             $row[] = $course_id;
                             $row[] = $courses[$course_id]['name'];
                             $row[] = $courses[$course_id]['veranstaltungsnummer'];
                             $row[] = $prio;
                             $data[] = $row;
                         }
                     }, array_keys($applicants), 'ORDER BY Nachname');
                     $applicants_file = $GLOBALS['TMP_PATH'] . '/seat_distribution_logs/applicants_' . $set_id . '.csv';
                     if (array_to_csv($data, $applicants_file, $captions)) {
                         echo 'applicants written to ' . $applicants_file . chr(10);
                     }
                 }
                 $courseset->distributeSeats();
             }
         }
         if ($verbose) {
             Log::get()->setHandler($old_logger);
             Log::get()->setLogLevel($old_log_level);
         }
     } else {
         if ($verbose) {
             echo date('r') . ' - Nothing to do' . chr(10);
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Returns the teacher for a given cours
  *
  * @param String $course_id Id of the course
  * @return array of user infos [user_id, username, Nachname, fullname]
  */
 private function getTeacher($course_id)
 {
     $teachers = CourseMember::findByCourseAndStatus($course_id, 'dozent');
     $collection = SimpleCollection::createFromArray($teachers);
     return $collection->map(function (CourseMember $teacher) {
         return array('user_id' => $teacher->user_id, 'username' => $teacher->username, 'Nachname' => $teacher->nachname, 'fullname' => $teacher->getUserFullname('no_title_rev'));
     });
 }
Ejemplo n.º 11
0
 /**
  *
  * @param type $user_id
  * @return type
  */
 public static function GetCoursesActivatedCalendar($user_id)
 {
     $courses_user = SimpleCollection::createFromArray(CourseMember::findByUser($user_id));
     $modules = new Modules();
     $courses = $courses_user->filter(function ($c) use($modules) {
         if ($modules->isBit($c->course->modules, $modules->registered_modules['calendar']['id'])) {
             return $c;
         }
     });
     return $courses->pluck('course');
 }
Ejemplo n.º 12
0
 /**
  * Get all user assigned institutes based on simple or map
  * @return array
  */
 public static function getMyInstitutes()
 {
     $memberShips = InstituteMember::findByUser($GLOBALS['user']->id);
     if (empty($memberShips)) {
         return null;
     }
     $insts = new SimpleCollection($memberShips);
     $institutes = array();
     $insts->filter(function ($a) use(&$institutes) {
         $array = $a->institute->toArray();
         $array['perms'] = $a->inst_perms;
         $array['visitdate'] = object_get_visit($a->institut_id, 'inst', '');
         $array['last_visitdate'] = object_get_visit($a->institut_id, 'inst', 'last');
         $institutes[] = $array;
         return true;
     });
     if (!empty($institutes)) {
         $Modules = new Modules();
         foreach ($institutes as $index => $inst) {
             $institutes[$index]['modules'] = $Modules->getLocalModules($inst['institut_id'], 'inst', $inst['modules'], $inst['type'] ?: 1);
             $institutes[$index]['obj_type'] = 'inst';
             $institutes[$index]['navigation'] = MyRealmModel::getAdditionalNavigations($inst['institut_id'], $institutes[$index], null, $GLOBALS['user']->id);
         }
         unset($Modules);
     }
     return $institutes;
 }
Ejemplo n.º 13
0
 function assign_role_institutes_action($role_id, $user_id)
 {
     if (Request::isXhr()) {
         $this->set_layout(null);
         $this->set_content_type('text/html;charset=windows-1252');
         $this->response->add_header('X-No-Buttons', 1);
         $this->response->add_header('X-Title', PageLayout::getTitle());
         foreach (array_keys($_POST) as $param) {
             Request::set($param, studip_utf8decode(Request::get($param)));
         }
     }
     if (Request::submitted('add_institute') && ($institut_id = Request::option('institute_id'))) {
         $roles = RolePersistence::getAllRoles();
         $role = $roles[$role_id];
         $user = new StudIPUser($user_id);
         RolePersistence::assignRole($user, $role, Request::option('institute_id'));
         PageLayout::postMessage(MessageBox::success(_("Die Einrichtung wurde zugewiesen.")));
     }
     if ($remove_institut_id = Request::option('remove_institute')) {
         $roles = RolePersistence::getAllRoles();
         $role = $roles[$role_id];
         $user = new StudIPUser($user_id);
         RolePersistence::deleteRoleAssignment($user, $role, $remove_institut_id);
         PageLayout::postMessage(MessageBox::success(_("Die Einrichtung wurde entfernt.")));
     }
     $roles = RolePersistence::getAllRoles();
     $this->role = $roles[$role_id];
     $this->user = new User($user_id);
     $this->institutes = SimpleCollection::createFromArray(Institute::findMany(RolePersistence::getAssignedRoleInstitutes($user_id, $role_id)));
     $this->institutes->orderBy('name');
     $this->qsearch = QuickSearch::get("institute_id", new StandardSearch("Institut_id"));
     if (Request::isXhr()) {
         $this->qsearch->withoutButton();
     }
 }
Ejemplo n.º 14
0
 /**
  * Creates an array with all seminars
  *
  * @return array
  */
 function getDozentSeminars()
 {
     $semester = $courses = array();
     $semester[] = Semester::findNext();
     $semester[] = Semester::findCurrent();
     $semester[] = Semester::findByTimestamp(Semester::findCurrent()->beginn - 1);
     if (Config::get()->IMPORTANT_SEMNUMBER) {
         $field = 'veranstaltungsnummer';
     } else {
         $field = 'name';
     }
     $allcourses = new SimpleCollection(Course::findBySQL("INNER JOIN seminar_user USING(Seminar_id) WHERE user_id=? AND seminar_user.status='dozent' AND seminare.visible=1", array($this->current_user->id)));
     foreach (array_filter($semester) as $one) {
         $courses[$one->name] = $allcourses->filter(function ($c) use($one) {
             return $c->start_time <= $one->beginn && ($one->beginn <= $c->start_time + $c->duration_time || $c->duration_time == -1);
         })->orderBy($field);
         if (!$courses[$one->name]->count()) {
             unset($courses[$one->name]);
         }
     }
     return $courses;
 }
Ejemplo n.º 15
0
 public function manage_access_action($range_id = null)
 {
     $this->range_id = $range_id ?: $this->range_id;
     $this->calendar = new SingleCalendar($this->range_id);
     $all_calendar_users = CalendarUser::getUsers($this->calendar->getRangeId());
     $this->filter_groups = Statusgruppen::findByRange_id($this->calendar->getRangeId());
     $this->users = array();
     $this->group_filter_selected = Request::option('group_filter', 'list');
     if ($this->group_filter_selected != 'list') {
         $contact_group = Statusgruppen::find($this->group_filter_selected);
         $calendar_users = array();
         foreach ($contact_group->members as $member) {
             $calendar_users[] = new CalendarUser(array($this->calendar->getRangeId(), $member->user_id));
         }
         $this->calendar_users = SimpleORMapCollection::createFromArray($calendar_users);
     } else {
         $this->group_filter_selected = 'list';
         $this->calendar_users = $all_calendar_users;
     }
     $this->own_perms = array();
     foreach ($this->calendar_users as $calendar_user) {
         $other_user = CalendarUser::find(array($calendar_user->user_id, $this->calendar->getRangeId()));
         if ($other_user) {
             $this->own_perms[$calendar_user->user_id] = $other_user->permission;
         } else {
             $this->own_perms[$calendar_user->user_id] = Calendar::PERMISSION_FORBIDDEN;
         }
         $this->users[strtoupper(SimpleCollection::translitLatin1($calendar_user->nachname[0]))][] = $calendar_user;
     }
     ksort($this->users);
     $this->users = array_map(function ($g) {
         return SimpleCollection::createFromArray($g)->orderBy('nachname, vorname');
     }, $this->users);
     $this->mps = MultiPersonSearch::get('calendar-manage_access')->setTitle(_('Personhinzufügen'))->setLinkText(_('Person hinzufügen'))->setDefaultSelectedUser($all_calendar_users->pluck('user_id'))->setJSFunctionOnSubmit('STUDIP.CalendarDialog.closeMps')->setExecuteURL($this->url_for('calendar/single/add_users/' . $this->calendar->getRangeId()))->setSearchObject(new StandardSearch('user_id'));
     PageLayout::setTitle($this->getTitle($this->calendar, _('Kalender freigeben')));
     $this->createSidebar('manage_access', $this->calendar);
     $this->createSidebarFilter();
 }
Ejemplo n.º 16
0
 /**
  * Validates the semester for required valies, properness of values
  * and possible overlaps with other semesters.
  *
  * The validation is also divided into these three steps, so the next
  * validation step only occurs when the previous one succeeded.
  *
  * @param Semester $semester Semester (data) to validate
  * @return Array filled with errors
  */
 protected function validateSemester(Semester $semester)
 {
     // Validation, step 1: Check required values
     $errors = array();
     if (!$this->semester->name) {
         $errors['name'] = _('Sie müssen den Namen des Semesters angeben.');
     }
     if (!$this->semester->beginn) {
         $errors['beginn'] = _('Sie müssen den Beginn des Semesters angeben.');
     }
     if (!$this->semester->ende) {
         $errors['ende'] = _('Sie müssen das Ende des Semesters angeben.');
     }
     if (!$this->semester->vorles_beginn) {
         $errors['vorles_beginn'] = _('Sie müssen den Beginn der Vorlesungzeit angeben.');
     }
     if (!$this->semester->vorles_ende) {
         $errors['vorles_ende'] = _('Sie müssen das Ende der Vorlesungzeit angeben.');
     }
     // Validation, step 2: Check properness of values
     if (empty($errors)) {
         if ($this->semester->beginn > $this->semester->vorles_beginn) {
             $errors['beginn'] = _('Der Beginn des Semester muss vor dem Beginn der Vorlesungszeit liegen.');
         }
         if ($this->semester->vorles_beginn > $this->semester->vorles_ende) {
             $errors['vorles_beginn'] = _('Der Beginn der Vorlesungszeit muss vor ihrem Ende liegen.');
         }
         if ($this->semester->vorles_ende > $this->semester->ende) {
             $errors['vorles_ende'] = _('Das Ende der Vorlesungszeit muss vor dem Semesterende liegen.');
         }
     }
     // Validation, step 3: Check overlapping with other semesters
     if (empty($errors)) {
         $all_semester = SimpleCollection::createFromArray(Semester::getAll())->findBy('id', $this->semester->id, '<>');
         $collisions = $all_semester->findBy('beginn', array($this->semester->beginn, $this->semester->ende), '>=<=');
         $collisions->merge($all_semester->findBy('ende', array($this->semester->beginn, $this->semester->ende), '>=<='));
         if ($collisions->count()) {
             $errors[] = sprintf(_('Der angegebene Zeitraum des Semester überschneidet sich mit einem anderen Semester (%s)'), join(', ', $collisions->pluck('name')));
         }
     }
     return $errors;
 }
Ejemplo n.º 17
0
 /**
  * Gets the list of applicants for the courses belonging to this course set.
  *
  * @param String $set_id course set ID
  * @param String $csv    export users to file
  */
 public function applications_list_action($set_id, $csv = null)
 {
     if (Request::isXhr()) {
         $this->response->add_header('X-Title', _('Liste der Anmeldungen'));
     }
     $courseset = new CourseSet($set_id);
     $applicants = AdmissionPriority::getPriorities($set_id);
     $users = User::findMany(array_keys($applicants), 'ORDER BY Nachname');
     $courses = SimpleCollection::createFromArray(Course::findMany($courseset->getCourses()));
     $captions = array(_("Nachname"), _("Vorname"), _("Nutzername"), _("Veranstaltung"), _("Nummer"), _("Priorität"));
     $data = array();
     foreach ($users as $user) {
         $row = array();
         $app_courses = $applicants[$user->id];
         asort($app_courses);
         foreach ($app_courses as $course_id => $prio) {
             $row = array();
             $row[] = $user->nachname;
             $row[] = $user->vorname;
             $row[] = $user->username;
             $row[] = $courses->findOneBy('id', $course_id)->name;
             $row[] = $courses->findOneBy('id', $course_id)->veranstaltungsnummer;
             $row[] = $prio;
             if ($csv) {
                 $row[] = $user->email;
             }
             $data[] = $row;
         }
     }
     if ($csv) {
         $tmpname = md5(uniqid('tmp'));
         $captions[] = _("Email");
         if (array_to_csv($data, $GLOBALS['TMP_PATH'] . '/' . $tmpname, $captions)) {
             $this->redirect(GetDownloadLink($tmpname, 'Anmeldungen_' . $courseset->getName() . '.csv', 4, 'force'));
             return;
         }
     }
     $this->captions = $captions;
     $this->data = $data;
     $this->set_id = $courseset->getId();
 }
Ejemplo n.º 18
0
 /**
  * Dateien/Ordner einer Veranstaltung
  *
  * @get /course/:course_id/files
  */
 public function getCourseFiles($course_id)
 {
     $folders = \SimpleCollection::createFromArray(\DocumentFolder::findBySeminar_id($course_id))->orderBy('name asc');
     // slice according to demanded pagination
     $total = count($folders);
     $json = array();
     foreach ($folders->limit($this->offset, $this->limit) as $folder) {
         $url = $this->urlf('/file/%s', array($folder->id));
         $json[$url] = $this->folderToJSON($folder, true);
     }
     return $this->paginated($json, $total, compact('course_id'));
 }
Ejemplo n.º 19
0
 /**
  * @param string $sort_status
  * @param string $order_by
  * @return SimpleCollection
  */
 function getAdmissionMembers($sort_status = 'autor', $order_by = 'nachname asc')
 {
     $cs = CourseSet::getSetForCourse($this->course_id);
     $claiming = array();
     if (is_object($cs) && !$cs->hasAlgorithmRun()) {
         foreach (AdmissionPriority::getPrioritiesByCourse($cs->getId(), $this->course_id) as $user_id => $p) {
             $user = User::find($user_id);
             $data = $user->toArray('user_id username vorname nachname email');
             $data['fullname'] = $user->getFullname('full_rev');
             $data['position'] = $p;
             $data['visible'] = 'unknown';
             $data['status'] = 'claiming';
             $claiming[] = $data;
         }
     }
     $query = "SELECT asu.user_id,username,vorname,nachname,email,status,position,asu.mkdate,asu.visible, asu.comment,\n                " . $GLOBALS['_fullname_sql']['full_rev'] . " as fullname\n                FROM admission_seminar_user asu INNER JOIN auth_user_md5 USING(user_id)\n                INNER JOIN user_info USING(user_id)\n                WHERE seminar_id = ? ORDER BY position, nachname ASC";
     $st = DBManager::get()->prepare($query);
     $st->execute(array($this->course_id));
     $application_members = SimpleCollection::createFromArray(array_merge($claiming, $st->fetchAll(PDO::FETCH_ASSOC)));
     $filtered_members = array();
     foreach (words('awaiting accepted claiming') as $status) {
         $filtered_members[$status] = $application_members->findBy('status', $status);
         if ($status == $sort_status) {
             $filtered_members[$status]->orderBy($order_by, strpos($order_by, 'nachname') === false ? SORT_NUMERIC : SORT_LOCALE_STRING);
         }
     }
     return $filtered_members;
 }
Ejemplo n.º 20
0
 /**
  * Sets the value at the specified index
  * checks if the value is an object of specified class
  *
  * @see ArrayObject::offsetSet()
  * @throws InvalidArgumentException if the given model does not fit (wrong type or id)
  */
 function offsetSet($index, $newval)
 {
     if (!is_null($index)) {
         $index = (int) $index;
     }
     if (!is_a($newval, $this->getClassName())) {
         throw new InvalidArgumentException('This collection only accepts objects of type: ' . $this->getClassName(), self::WRONG_OBJECT_TYPE);
     }
     if ($this->related_record && $this->relation_options['type'] === 'has_many') {
         $foreign_key_value = call_user_func($this->relation_options['assoc_func_params_func'], $this->related_record);
         call_user_func($this->relation_options['assoc_foreign_key_setter'], $newval, $foreign_key_value);
     }
     if ($newval->id !== null) {
         $exists = $this->find($newval->id);
         if ($exists) {
             throw new InvalidArgumentException('Element could not be appended, element with id: ' . $exists->id . ' is in the way', self::OBJECT_EXISTS);
         }
     }
     return parent::offsetSet($index, $newval);
 }
Ejemplo n.º 21
0
 protected function saveForRelationData($oObject, $before = false)
 {
     $saveForRelation = $before ? $oObject->aForSaveRelationsDataBefore : $oObject->aForSaveRelationsData;
     $objectId = $before ? 0 : (int) $oObject->getId();
     if (!empty($saveForRelation)) {
         $relations = $this->relations();
         foreach ($saveForRelation as $rel => $val) {
             $relation = $relations[$rel];
             foreach ($val as $action => $data) {
                 $oRelMapper = Manager::getInstance()->getMapper($relation['ToMapperAlias']);
                 $aRelContainer = $oRelMapper->getContainer();
                 $sRelClassName = $aRelContainer['Object'];
                 switch ($action) {
                     case 'Delete':
                         // Удаляем все что есть
                         $oQuery = new DbUpdater(DbUpdater::TYPE_DELETE, $relation['TableName'], $sRelClassName, $this->getDbConnectionAlias());
                         $oCriteria = new CriteriaElement($relation['Field2'], Criteria::EQUAL, $objectId);
                         $oQuery->addCriteria($this->parseUpdateCriteria($oCriteria->renderWhere()));
                         $oQuery->delete();
                         break;
                     case 'Add':
                         // сохраняем в базу
                         if (is_array($data)) {
                             foreach ($data as $data_val) {
                                 $oQuery = new DbUpdater(DbUpdater::TYPE_INSERT, $relation['TableName'], $sRelClassName, $this->getDbConnectionAlias());
                                 $oQuery->setElement(array($relation['Field'] => $data_val, $relation['Field2'] => $objectId));
                                 $oQuery->insert();
                             }
                         }
                         break;
                         // Has Many
                     // Has Many
                     case 'Set':
                         if (is_array($data)) {
                             $result = new SimpleCollection();
                             foreach ($data as $itm) {
                                 if (!empty($itm['Id'])) {
                                     $obj = $oRelMapper->findById($itm['Id']);
                                 } else {
                                     $obj = $oRelMapper->create();
                                 }
                                 unset($itm['Id']);
                                 $obj->import($itm);
                                 $obj->set($relation['Field'], $objectId);
                                 $obj->save();
                                 $result->add($obj);
                             }
                         }
                         break;
                         // Belongs To
                     // Belongs To
                     case 'SetOne':
                         if (is_array($data)) {
                             if (!empty($data['Id'])) {
                                 $obj = $oRelMapper->findById($data['Id']);
                             } else {
                                 $obj = $oRelMapper->create($data);
                             }
                             unset($data['Id']);
                             $obj->import($data);
                             $id = $obj->save();
                             $oObject->set($relation['Field'], $id);
                             $oObject->set($rel, $obj);
                         } else {
                             if (is_object($data)) {
                                 if (!$data->getId()) {
                                     $data->save();
                                 }
                                 $oObject->set($rel, $data);
                             }
                         }
                         break;
                 }
             }
         }
         if ($before) {
             $oObject->aForSaveRelationsDataBefore = array();
         } else {
             $oObject->aForSaveRelationsData = array();
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 22
0
 function getChild($name)
 {
     if (isset($this->newDirectories[$name])) {
         return new TreeDirectoryTester($name);
     }
     if (isset($this->newFiles[$name])) {
         return new TreeFileTester($name, $this->newFiles[$name]);
     }
     return parent::getChild($name);
 }
Ejemplo n.º 23
0
 /**
  * Aux input for users
  */
 public function additional_input_action()
 {
     // Activate the autoNavi otherwise we dont find this page in navi
     Navigation::activateItem('/course/members/additional');
     // Fetch datafields for the user
     $course = new Course($_SESSION['SessionSeminar']);
     $member = $course->members->findOneBy('user_id', $GLOBALS['user']->id);
     $this->datafields = $member ? $course->aux->getMemberData($member) : array();
     // We need aux data in the view
     $this->aux = $course->aux;
     // Update em if they got submittet
     if (Request::submitted('save')) {
         $datafields = SimpleCollection::createFromArray($this->datafields);
         foreach (Request::getArray('aux') as $aux => $value) {
             $datafield = $datafields->findOneBy('datafield_id', $aux);
             if ($datafield) {
                 $typed = $datafield->getTypedDatafield();
                 if ($typed->isEditable()) {
                     $typed->setValueFromSubmit($value);
                     $typed->store();
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
 /**
  * merge in another collection, elements are appended
  *
  * @param SimpleCollection $a_collection
  */
 function merge(SimpleCollection $a_collection)
 {
     $this->storage = array_merge($this->storage, $a_collection->getArrayCopy());
 }
Ejemplo n.º 25
0
 /**
  * @depends testConstruct
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage unknown operator: foo
  */
 public function testInvalidCompOperatorException($a)
 {
     SimpleCollection::getCompFunc('foo', null);
 }