/** * Trägt den Benutzer in den Eingestellten veranstaltungen automatisch ein. * @param type $user_id * @param type $status Wenn Status nicht angegeben wird, wird der Status des Users aus user_id genommen * @return array 'added' Namen der Seminare in die der User eingetragen wurde * array 'removed' Namen der Seminare aus denen der User ausgetragen wurde */ public function saveUser($user_id, $status = FALSE) { $domains = array(); if (!$status) { $status = get_global_perm($user_id); } foreach (UserDomain::getUserDomainsForUser($user_id) as $d) { $domains[] = $d->getID(); //Domains des Users } if (count($domains) == 0) { $domains[] = 'keine'; } $settings = array(); $all_seminare = array(); foreach ($domains as $domain) { $key = $domain . '.' . $status; if (is_array($this->settings[$key])) { $id = key($this->settings[$key]); foreach ($this->settings[$key] as $id => $value) { $settings[$id] = $value; } } foreach ($this->settings as $key) { foreach ($key as $id => $sem) { $all_seminare[$id] = $sem; } } } $seminare = array(); $seminare_tutor_dozent = array(); foreach ($this->getUserSeminars($user_id, array_keys($all_seminare)) as $sem) { $seminare[$sem['Seminar_id']] = $sem; if (in_array($sem['status'], array('tutor', 'dozent'))) { $seminare_tutor_dozent[$sem['Seminar_id']] = $sem; } } $toAdd = array_diff_key($settings, $seminare); $toRemove = array_diff_key($all_seminare, $toAdd, $settings, $seminare_tutor_dozent); $added = array(); $removed = array(); foreach ($toAdd as $id => $seminar) { if ($this->addUser($user_id, $seminar)) { $added[] = $seminar['name']; } } foreach ($toRemove as $id => $seminar) { if ($this->removeUser($user_id, $seminar)) { $removed[] = $seminar['name']; } } return array('added' => $added, 'removed' => $removed); }
/** * Assign/add a user to a statusgruppe. */ public function assign_action() { $this->check_ticket(); $role_id = Request::option('role_id'); if ($role_id) { $group = new Statusgruppe($role_id); $range_id = $group->getRange_id(); $group = new Statusgruppe($range_id); while ($group->getRange_id()) { $range_id = $group->getRange_id(); $group = new Statusgruppe($range_id); } if (InsertPersonStatusgruppe($this->user->user_id, $role_id)) { $globalperms = get_global_perm($this->user->user_id); $query = "INSERT IGNORE INTO user_inst (Institut_id, user_id, inst_perms)\n VALUES (?, ?, ?)\n ON DUPLICATE KEY UPDATE inst_perms = VALUES(inst_perms)"; $statement = DBManager::get()->prepare($query); $statement->execute(array($range_id, $this->user->user_id, $globalperms)); if ($statement->rowCount() == 1) { log_event('INST_USER_ADD', $range_id, $this->user->user_id, $globalperms); } else { if ($statement->rowCount() == 2) { log_event('INST_USER_STATUS', $range_id, $this->user->user_id, $globalperms); } } checkExternDefaultForUser($this->user->user_id); $_SESSION['edit_about_data']['open'] = $role_id; $this->reportSuccess(_('Die Person wurde in die ausgewählte Gruppe eingetragen!')); } else { $this->reportError(_('Fehler beim Eintragen in die Gruppe!')); } } $this->redirect('settings/statusgruppen#' . $role_id); }
function ResourcesUserRoots($range_id='') { global $user, $perm, $auth; if($range_id){ $this->range_id = $range_id; } if (!$this->range_id) $this->range_id=$user->id; if (get_object_type($this->range_id) == "user") { //load the global perms in the resources-system (check if the user ist resources-root) $this->resources_global_perm=getGlobalPerms($this->range_id); //load the global studip perms (check, if user id root) $this->user_global_perm=get_global_perm($this->range_id); if ($this->resources_global_perm == "admin") $global_perm="root"; else $global_perm=$this->user_global_perm; } //root or resoures root are able to see all resources (roots in tree) if ($global_perm == "root") { $query = "SELECT resource_id FROM resources_objects WHERE resource_id = root_id ORDER BY name"; $statement = DBManager::get()->query($query); while ($resource_id = $statement->fetchColumn()) { $this->my_roots[$resource_id] = $resource_id; } } else { $my_objects = search_administrable_objects(); $my_objects[$user->id] = TRUE; $my_objects["global"] = TRUE; //create the clause with all my id's $i=0; $clause = " ("; foreach ($my_objects as $key=>$val) { if ($i) $clause .= ", "; $clause .= "'$key'"; $i++; } $clause .= ") "; //all objects where I have owner perms... $query = "SELECT resource_id, parent_id, root_id, level FROM resources_objects WHERE owner_id IN (?) ORDER BY level DESC"; $statement = DBManager::get()->prepare($query); $statement->execute(array( array_keys($my_objects) )); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $my_resources[$row['resource_id']] = array( 'root_id' => $row['root_id'], 'parent_id' => $row['parent_id'], 'level' => $row['level'] ); $roots[$row['root_id']][] = $row['resource_id']; } //...and all objects where I have add perms... $query = "SELECT resource_id, parent_id, root_id, level FROM resources_user_resources LEFT JOIN resources_objects USING (resource_id) WHERE user_id IN ('all', ?) ORDER BY level DESC"; $statement = DBManager::get()->prepare($query); $statement->execute(array( array_keys($my_objects) )); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $my_resources[$row['resource_id']] = array( 'root_id' => $row['root_id'], 'parent_id' => $row['parent_id'], 'level' => $row['level'] ); $roots[$row['root_id']][] = $row['resource_id']; } if (is_array($my_resources)) { $query = "SELECT parent_id FROM resources_objects WHERE resource_id = ?"; $statement = DBManager::get()->prepare($query); foreach ($my_resources as $key => $val) { if (!$this->checked[$key]) { if (sizeof($roots[$val["root_id"]]) == 1) { $this->my_roots[$key] = $key; } else { //there are more than 2 resources in one thread... $statement->execute(array($key)); $superordinated_id = $statement->fetchColumn(); $statement->closeCursor(); $top = FALSE; $last_found = $key; while (!$top && $superordinated_id) { $statement->execute(array($superordinated_id)); $parent_id = $statement->fetchColumn(); $statement->closeCursor(); if ($my_resources[$superordinated_id]) { $checked[$last_found] = TRUE; $last_found = $superordinated_id; } $superordinated_id = $parent_id; if ($parent_id == "0") { $top = TRUE; } } $this->my_roots[$last_found] = $last_found; } } } } } }
/** * adds a user to the seminar with the given status * @param user_id string: ID of the user * @param status string: status of the user for the seminar "user", "autor", "tutor", "dozent" * @param force bool: if false (default) the user will only be upgraded and not degraded in his/her status */ public function addMember($user_id, $status = 'autor', $force = false) { if (in_array(get_global_perm($user_id), array("admin", "root"))) { $this->createError(_("Admin und Root dürfen nicht Mitglied einer Veranstaltung sein.")); return false; } $db = DBManager::get(); $rangordnung = array_flip(array('user', 'autor', 'tutor', 'dozent')); if ($rangordnung[$status] > $rangordnung['autor'] && SeminarCategories::getByTypeId($this->status)->only_inst_user) { //überprüfe, ob im richtigen Institut: $user_institute_stmt = $db->prepare( "SELECT Institut_id " . "FROM user_inst " . "WHERE user_id = :user_id " . ""); $user_institute_stmt->execute(array('user_id' => $user_id)); $user_institute = $user_institute_stmt->fetchAll(PDO::FETCH_COLUMN, 0); if (!in_array($this->institut_id, $user_institute) && !count(array_intersect($user_institute, $this->getInstitutes()))) { $this->createError(_("Einzutragender Nutzer stammt nicht einem beteiligten Institut an.")); return false; } } if (!$force) { $query = "SELECT status FROM seminar_user WHERE user_id = ? AND Seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($user_id, $this->id)); $old_status = $statement->fetchColumn(); } $query = "SELECT MAX(position) + 1 FROM seminar_user WHERE status = ? AND Seminar_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($status, $this->id)); $new_position = $statement->fetchColumn(); $query = "SELECT COUNT(*) FROM seminar_user WHERE Seminar_id = ? AND status = 'dozent'"; $statement = DBManager::get()->prepare($query); $statement->execute(array($this->id)); $numberOfTeachers = $statement->fetchColumn(); if (!$old_status) { $query = "INSERT INTO seminar_user (Seminar_id, user_id, status, position, gruppe, visible, mkdate) VALUES (?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP())"; $statement = DBManager::get()->prepare($query); $statement->execute(array( $this->id, $user_id, $status, $new_position ?: 0, (int)select_group($this->getSemesterStartTime()), in_array($status, words('tutor dozent')) ? 'yes' : 'unknown', )); // delete the entries, user is now in the seminar $stmt = DBManager::get()->prepare('DELETE FROM admission_seminar_user WHERE user_id = ? AND seminar_id = ?'); $stmt->execute(array($user_id, $this->getId())); if ($stmt->rowCount()) { //renumber the waiting/accepted/lot list, a user was deleted from it renumber_admission($this->getId()); } $cs = $this->getCourseSet(); if ($cs) { $prio_delete = AdmissionPriority::unsetPriority($cs->getId(), $user_id, $this->getId()); } removeScheduleEntriesMarkedAsVirtual($user_id, $this->getId()); NotificationCenter::postNotification("CourseDidGetMember", $this, $user_id); NotificationCenter::postNotification('UserDidEnterCourse', $this->id, $user_id); StudipLog::log('SEM_USER_ADD', $this->id, $user_id, $status, 'Wurde in die Veranstaltung eingetragen'); $this->course->resetRelation('members'); $this->course->resetRelation('admission_applicants'); return $this; } elseif (($force || $rangordnung[$old_status] < $rangordnung[$status]) && ($old_status !== "dozent" || $numberOfTeachers > 1)) { $query = "UPDATE seminar_user SET status = ?, visible = IFNULL(?, visible), position = ? WHERE Seminar_id = ? AND user_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array( $status, in_array($status, words('tutor dozent')) ? 'yes' : null, $new_position, $this->id, $user_id, )); if ($old_status === 'dozent') { $query = "SELECT termin_id FROM termine WHERE range_id = ?"; $statement = DBManager::get()->prepare($query); $statement->execute(array($this->id)); $termine = $statement->fetchAll(PDO::FETCH_COLUMN); $query = "DELETE FROM termin_related_persons WHERE range_id = ? AND user_id = ?"; $statement = DBManager::get()->prepare($query); foreach ($termine as $termin_id) { $statement->execute(array($termin_id, $user_id)); } } NotificationCenter::postNotification("CourseDidChangeMember", $this, $user_id); $this->course->resetRelation('members'); $this->course->resetRelation('admission_applicants'); return $this; } else { if ($old_status === "dozent" && $numberOfTeachers <= 1) { $this->createError(sprintf(_("Die Veranstaltung muss wenigstens <b>einen/eine</b> VeranstaltungsleiterIn (%s) eingetragen haben!"), get_title_for_status('dozent', 1, $this->status)) . ' ' . _("Tragen Sie zunächst einen anderen ein, um diesen herabzustufen.")); } return false; } }
function addToStatusgroup($range_id, $statusgruppe_id, $workgroup_mode) { $mp = MultiPersonSearch::load("contacts_statusgroup_" . $statusgruppe_id); if (count($mp->getAddedUsers()) !== 0) { foreach ($mp->getAddedUsers() as $m) { $quickfilters = $mp->getQuickfilterIds(); if (in_array($m, $quickfilters[_("Veranstaltungsteilnehmende")])) { InsertPersonStatusgruppe ($m, $statusgruppe_id, false); } elseif (in_array($m, $quickfilters[_("Mitarbeiter/-innen")])) { $writedone = InsertPersonStatusgruppe ($m, $statusgruppe_id, false); if ($writedone) { if ($workgroup_mode == TRUE) { $globalperms = get_global_perm($m); if ($globalperms == "tutor" || $globalperms == "dozent") { insert_seminar_user($range_id, $m, "tutor"); } else { insert_seminar_user($range_id, $m, "autor"); } } else { insert_seminar_user($range_id, $m, "autor"); } } checkExternDefaultForUser($m); } else { $writedone = InsertPersonStatusgruppe ($m, $statusgruppe_id, false); if ($writedone) { if ($workgroup_mode == TRUE) { $globalperms = get_global_perm($m); if ($globalperms == "tutor" || $globalperms == "dozent") { insert_seminar_user($range_id, $m, "tutor"); } else { insert_seminar_user($range_id, $m, "autor"); } } else { insert_seminar_user($range_id, $m, "autor"); } } } } } $mp->clearSession(); }