/** * Query the permissions for a given user and store them in the database. */ protected function query_auth_data($user_id) { //$albums = array();//@todo $this->cache->obtain_album_list(); $albums = $this->cache->get('albums'); $user_groups_ary = self::get_usergroups($user_id); $sql_select = ''; foreach (self::$_permissions as $permission) { $sql_select .= " MAX({$permission}) as {$permission},"; } $this->_auth_data[self::OWN_ALBUM] = new \phpbbgallery\core\auth\set(); $this->_auth_data_never[self::OWN_ALBUM] = new \phpbbgallery\core\auth\set(); $this->_auth_data[self::PERSONAL_ALBUM] = new \phpbbgallery\core\auth\set(); $this->_auth_data_never[self::PERSONAL_ALBUM] = new \phpbbgallery\core\auth\set(); foreach ($albums as $album) { if ($album['album_user_id'] == self::PUBLIC_ALBUM) { $this->_auth_data[$album['album_id']] = new \phpbbgallery\core\auth\set(); $this->_auth_data_never[$album['album_id']] = new \phpbbgallery\core\auth\set(); } } $sql_array = array('SELECT' => "p.perm_album_id, {$sql_select} p.perm_system", 'FROM' => array($this->table_permissions => 'p'), 'LEFT_JOIN' => array(array('FROM' => array($this->table_roles => 'pr'), 'ON' => 'p.perm_role_id = pr.role_id')), 'WHERE' => 'p.perm_user_id = ' . $user_id . ' OR ' . $this->db->sql_in_set('p.perm_group_id', $user_groups_ary, false, true), 'GROUP_BY' => 'p.perm_system, p.perm_album_id', 'ORDER_BY' => 'p.perm_system DESC, p.perm_album_id ASC'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $this->db->sql_return_on_error(true); $result = $this->db->sql_query($sql); if ($this->db->get_sql_error_triggered()) { trigger_error('DATABASE_NOT_UPTODATE'); } $this->db->sql_return_on_error(false); while ($row = $this->db->sql_fetchrow($result)) { switch ($row['perm_system']) { case self::PERSONAL_ALBUM: $this->store_acl_row(self::PERSONAL_ALBUM, $row); break; case self::OWN_ALBUM: $this->store_acl_row(self::OWN_ALBUM, $row); break; case self::PUBLIC_ALBUM: $this->store_acl_row((int) $row['perm_album_id'], $row); break; } } $this->db->sql_freeresult($result); $this->merge_acl_row(); $this->restrict_pegas($user_id); $this->set_user_permissions($user_id, $this->_auth_data); }