예제 #1
0
 /**
  * Displays the statusgruppen of a user.
  *
  * @param mixed $verify_action Optional name of an action to be verified
  * @param mixed $verify_id     Optional id that belongs to the action to
  *                             be verified
  */
 public function index_action($verify_action = null, $verify_id = null)
 {
     $all_rights = false;
     if ($this->user->username != $GLOBALS['user']->username) {
         $query = "SELECT Institut_id\n                      FROM Institute\n                      WHERE fakultaets_id = ? AND fakultaets_id != Institut_id\n                      ORDER BY Name";
         $inner_statement = DBManager::get()->prepare($query);
         $parameters = array();
         if ($GLOBALS['perm']->have_perm('root')) {
             $all_rights = true;
             $query = "SELECT Institut_id, Name, 1 AS is_fak\n                          FROM Institute\n                          WHERE Institut_id = fakultaets_id\n                          ORDER BY Name";
         } elseif ($GLOBALS['perm']->have_perm('admin')) {
             $query = "SELECT Institut_id, Name, b.Institut_id = b.fakultaets_id AS is_fak\n                          FROM user_inst AS a\n                          LEFT JOIN Institute AS b USING (Institut_id)\n                          WHERE a.user_id = ? AND a.inst_perms = 'admin'\n                          ORDER BY is_fak, Name";
             $parameters[] = $GLOBALS['user']->id;
         } else {
             $query = "SELECT a.Institut_id, Name\n                          FROM user_inst AS a\n                          LEFT JOIN Institute AS b USING (Institut_id)\n                          WHERE inst_perms IN ('tutor', 'dozent') AND user_id = ?\n                          ORDER BY Name";
             $parameters[] = $GLOBALS['user']->id;
         }
         $statement = DBManager::get()->prepare($query);
         $statement->execute($parameters);
         $institutes = $statement->fetchAll(PDO::FETCH_ASSOC);
         $admin_insts = array();
         foreach ($institutes as $institute) {
             $institute['groups'] = GetAllStatusgruppen($institute['Institut_id']) ?: array();
             if ($institute['is_fak']) {
                 $stmt = DBManager::get()->prepare("SELECT Institut_id, Name FROM Institute WHERE fakultaets_id = ? AND Institut_id != fakultaets_id ORDER BY Name");
                 $stmt->execute(array($institute['Institut_id']));
                 $institute['sub'] = $stmt->fetchGrouped(PDO::FETCH_ASSOC);
                 foreach ($institute['sub'] as $id => $sub) {
                     $sub['groups'] = GetAllStatusgruppen($id) ?: array();
                     $institute['sub'][$id] = $sub;
                 }
             }
             $admin_insts[] = $institute;
         }
     } else {
         $all_rights = true;
     }
     // get the roles the user is in
     $institutes = array();
     foreach ($this->about->user_inst as $inst_id => $details) {
         if ($details['inst_perms'] != 'user') {
             $institutes[$inst_id] = $details;
             $roles = GetAllStatusgruppen($inst_id, $this->user->user_id, true);
             $institutes[$inst_id]['roles'] = $roles ?: array();
             $institutes[$inst_id]['flattened'] = array_filter(Statusgruppe::getFlattenedRoles($roles), function ($role) {
                 return $role['user_there'];
             });
             $user_id = $this->user->user_id;
             $datafields = array();
             foreach ($institutes[$inst_id]['flattened'] as $role_id => $role) {
                 $datafields[$role_id] = DataFieldEntry::getDataFieldEntries(array($this->user->user_id, $role_id)) ?: array();
             }
             $institutes[$inst_id]['datafields'] = $datafields;
         }
     }
     // template for tree-view of roles, layout for infobox-location and content-variables
     $this->open = $_SESSION['edit_about_data']['open'];
     // the ids of the currently opened statusgroups
     $this->institutes = $institutes;
     $this->verify_action = $verify_action;
     $this->verify_id = $verify_id;
     // data for edit_about_add_person_to_role
     $this->admin_insts = $admin_insts;
     $this->locked = !$this->shallChange('', 'institute_data');
     if ($this->locked) {
         $message = LockRules::getObjectRule($this->user->user_id)->description;
         if ($message) {
             $this->reportInfo($message);
         }
     }
 }
예제 #2
0
 static function getFlattenedRoles($roles, $level = 0, $parent_name = false)
 {
     if (!is_array($roles)) {
         return array();
     }
     $ret = array();
     //var_dump($roles);
     foreach ($roles as $id => $role) {
         if (!isset($role['name'])) {
             $role['name'] = $role['role']->getName();
         }
         $spaces = '';
         for ($i = 0; $i < $level; $i++) {
             $spaces .= '&nbsp;&nbsp;';
         }
         // generate an indented version of the role-name
         $role['name'] = $spaces . $role['name'];
         // generate a name with all parent-roles in the name
         if ($parent_name) {
             $role['name_long'] = $parent_name . ' > ' . $role['role']->getName();
         } else {
             $role['name_long'] = $role['role']->getName();
         }
         $ret[$id] = $role;
         if ($role['child']) {
             $ret = array_merge($ret, Statusgruppe::getFlattenedRoles($role['child'], $level + 1, $role['name_long']));
         }
     }
     return $ret;
 }