public function getPurviewsByOwner($group_id, $user_id) { $_r = array(); // $role = GroupModel::inst()->getGroupsByCache($group_id); $group_purviews = json_decode($role['purviews'], true); // $user = UserModel::inst()->getUserById($user_id); $user_purviews = json_decode($user['purviews'], true); //合并权限 $purviews = is_array($group_purviews) ? array_merge($group_purviews, $user_purviews) : $user_purviews; // $_r = array(); foreach ($this->getPurviewsByCache() as $_k => $_v) { if ($role['purviews'] == 'all' || in_array($_v['purview_id'], $purviews)) { $_r[] = $_v; } } return $_r; }
public function updateAction($id) { $user = UserModel::inst()->getUserById($id); if ($user) { $user['purviews'] = $user['purviews'] ? json_decode($user['purviews'], true) : array(); $user['purviews'] = is_array($user['purviews']) ? array($user['purviews']) : array(); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['Admin'])) { $administrator = $user['user_name']; $_POST['Admin']['purviews'] = isset($_POST['Admin']['purviews']) ? json_encode($_POST['Admin']['purviews']) : json_encode(array()); $password = empty($_POST['Admin']['password']) ? $user['password'] : md5(md5($_POST['Admin']['password']) . $user['salt']); $allow_groups = GroupModel::inst()->getGroupsByOwner($this->user->group_id); if ($user['user_id'] == $this->user->id) { $update_data = array('user_name' => $_POST['Admin']['user_name'], 'realname' => $_POST['Admin']['realname'], 'email' => $_POST['Admin']['email'], 'password' => $password, 'lasttime' => $_SERVER['REQUEST_TIME']); } else { $allow_groups = GroupModel::inst()->getGroupsByOwner($this->user->group_id); if ($allow_groups[$this->user->group_id]['purviews'] != 'all' && (!isset($allow_groups[$_POST['Admin']['group_id']]) || $_POST['Admin']['group_id'] == $this->user->group_id)) { $this->redirect[] = array('text' => '', 'href' => $this->forward); $this->message('您无权限在该角色组下添加新用户', self::MSG_ERROR, true); } $update_data = array('user_name' => $_POST['Admin']['user_name'], 'realname' => $_POST['Admin']['realname'], 'email' => $_POST['Admin']['email'], 'password' => $password, 'group_id' => isset($_POST['Admin']['group_id']) ? $_POST['Admin']['group_id'] : $user['group_id'], 'purviews' => isset($_POST['Admin']['purviews']) ? $_POST['Admin']['purviews'] : $user['purviews'], 'user_rank' => isset($_POST['Admin']['user_rank']) ? $_POST['Admin']['user_rank'] : $user['user_rank'], 'status' => isset($_POST['Admin']['status']) ? $_POST['Admin']['status'] : $user['status'], 'lasttime' => $_SERVER['REQUEST_TIME']); } $flag = $this->db->update('{{user}}', $update_data, 'user_id=:user_id', array(':user_id' => $id)); if ($flag) { //记录操作日志 $message = '{user_name}修改了管理员{administrator}信息'; if ($administrator != $_POST['Admin']['user_name']) { $message .= ',改名为:{new_administrator}'; } $data = array('administrator' => $administrator, 'new_administrator' => $_POST['Admin']['user_name'], 'data' => $_POST['Admin']); UserLogsModel::inst()->add('Admin/User', $id, 'Insert', 'success', $message, $data); $this->redirect[] = array('text' => '', 'href' => $this->forward); $this->message('修改管理员资料完成', self::MSG_SUCCESS, true); } } $groups = GroupModel::inst()->getGroupsByOwner($this->user->group_id); $purviews = PurviewModel::inst()->getPurviewsByOwner($this->user->group_id, $this->user->id); $this->getView()->assign(array('my_user_id' => $this->user->id, 'my_group_id' => $this->user->group_id, 'user' => $user, 'groups' => $groups, 'purviews' => $purviews)); }
/** * @param integer pagesize * @param integer CID * @param integer CState * @param integer GState * * @param string order * * @return array $rows */ public function Pages($params = array()) { //设置默认参数 $_defaults_params = array('allow_cache' => false, 'page' => isset($_GET['page']) ? intval($_GET['page']) : 1, 'pagesize' => 15); $params = array_merge($_defaults_params, $params); //有开启缓存功能,则从缓存中取数据, 如果有数据,则直接返回结果 if ($params['allow_cache'] && isset($this->cache)) { $cache_key = 'user.pages.' . serialize($params); $ret = $this->cache->get($_cache_key); if ($ret && is_array($ret)) { return $ret; } } //添加条件 $builds = array('select' => 'COUNT(u.user_id) AS COUNT', 'from' => array('{{user}}', 'u'), 'leftJoin' => array('{{group}}', 'g', '`g`.`group_id`=`u`.`group_id`')); if (isset($params['status']) && !empty($params['status'])) { $builds['where'][] = array('AND', 'u.status=:status'); $sql_params = array(':status' => $params['status']); } else { $builds['where'][] = array('AND', 'u.status>:status'); $sql_params = array(':status' => self::STAT_STATUS_DELETED); } if (isset($params['group_id']) && !empty($params['group_id'])) { $groups = GroupModel::inst()->getGroupsByOwner($params['group_id']); $group_ids = array(); $_addons_groups = array(); foreach ($groups as $_k => $_v) { $_addons_groups[] = array("OR", "`u`.`group_id`=:group_id_{$_k}"); $sql_params[":group_id_{$_k}"] = $_v['group_id']; } $builds['where'][] = array('AND', $_addons_groups); } if (isset($params['search_key']) && $params['search_key']) { $builds['where'][] = array('AND', array('OR LIKE', 'u.user_name', ':search_key_1'), array('OR LIKE', 'u.realname', ':search_key_2'), array('OR LIKE', 'u.email', ':search_key_3')); $sql_params[':search_key_1'] = "%{$params['search_key']}%"; $sql_params[':search_key_2'] = "%{$params['search_key']}%"; $sql_params[':search_key_3'] = "%{$params['search_key']}%"; } $sql = $this->buildQuery($builds); //统计数量 $count = $this->db->queryScalar($sql, $sql_params); //分页处理 $pages = new CPagination($count); //设置分页大小 $pages->pageSize = $params['pagesize']; //清空前面执行过的SQL if (isset($params['orderby']) && $params['orderby']) { $builds['order'] = $params['orderby']; } else { $builds['order'] = array('`r`.`role_rank` ASC', '`u`.`user_rank` ASC', '`u`.`user_id` ASC'); } $builds['select'] = 'u.user_id, u.user_name, u.realname, u.email, u.user_id, u.group_id, g.group_name, u.logintimes, u.lastvisit, u.lastip, u.user_rank, u.lasttime, u.dateline, u.is_system, u.status'; $pages->applyLimit($builds); $sql = $this->buildQuery($builds); $result['pages'] = $pages; $result['rows'] = $this->db->queryAll($sql, $sql_params); //有开启缓存,则把结果添加到缓存中 if ($params['allow_cache'] && isset($this->cache)) { $cache_time_out = SettingModel::inst()->getSettingCache('ADMIN_LOGS_TIME_OUT'); $this->cache->add($cache_key, $result, $cache_time_out); unset($cache_time_out, $cache_key); } return $result; }
public function indexAction() { $this->getView()->assign(array('groups' => GroupModel::inst()->getGroupsByOwner($this->user->group_id))); }