人人商城

permission.ctrl.php 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $_W['page']['title'] = '查看用户权限 - 用户管理 - 用户管理';
  8. load()->model('setting');
  9. $uid = intval($_GPC['uid']);
  10. $user = user_single($uid);
  11. if(empty($user)) {
  12. message('访问错误, 未找到指定操作用户.');
  13. }
  14. $founders = explode(',', $_W['config']['setting']['founder']);
  15. $isfounder = in_array($user['uid'], $founders);
  16. if($isfounder) {
  17. message('访问错误, 无法编辑站长.');
  18. }
  19. $do = $_GPC['do'];
  20. $dos = array('deny', 'delete', 'auth', 'revo', 'revos', 'select', 'role', 'menu', 'edit', 'module');
  21. $do = in_array($do, $dos) ? $do: 'edit';
  22. if($do == 'edit') {
  23. if (!empty($user['groupid'])) {
  24. $group = pdo_fetch("SELECT * FROM ".tablename('users_group')." WHERE id = '{$user['groupid']}'");
  25. if (!empty($group)) {
  26. $package = iunserializer($group['package']);
  27. $group['package'] = uni_groups($package);
  28. }
  29. }
  30. $weids = pdo_fetchall("SELECT uniacid, role FROM ".tablename('uni_account_users')." WHERE uid = '$uid'", array(), 'uniacid');
  31. if (!empty($weids)) {
  32. $wechats = pdo_fetchall("SELECT * FROM ".tablename('uni_account')." WHERE uniacid IN (".implode(',', array_keys($weids)).")");
  33. }
  34. template('user/permission');
  35. }
  36. if($do == 'deny') {
  37. if($_W['ispost'] && $_W['isajax']) {
  38. $founders = explode(',', $_W['config']['setting']['founder']);
  39. if(in_array($uid, $founders)) {
  40. exit('管理员用户不能禁用.');
  41. }
  42. $somebody = array();
  43. $somebody['uid'] = $uid;
  44. if (intval($user['status']) == 2) {
  45. $somebody['status'] = 1;
  46. } else {
  47. $somebody['status'] = 2;
  48. }
  49. if(user_update($somebody)) {
  50. exit('success');
  51. }
  52. }
  53. }
  54. if ($do == 'select') {
  55. $uid = intval($_GPC['uid']);
  56. $condition = '';
  57. $params = array();
  58. if(!empty($_GPC['keyword'])) {
  59. $condition = ' AND `name` LIKE :name';
  60. $params[':name'] = "%{$_GPC['keyword']}%";
  61. }
  62. $pindex = max(1, intval($_GPC['page']));
  63. $psize = 10;
  64. $total = 0;
  65. $list = pdo_fetchall("SELECT * FROM ".tablename('uni_account')." WHERE 1 $condition LIMIT ".(($pindex - 1) * $psize).",{$psize}");
  66. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('uni_account')." WHERE 1 $condition");
  67. $pager = pagination($total, $pindex, $psize, '', array('ajaxcallback'=>'null'));
  68. $permission = pdo_fetchall("SELECT uniacid FROM ".tablename('uni_account_users')." WHERE uid = '$uid'", array(), 'uniacid');
  69. template('user/select');
  70. }
  71. if($do == 'module') {
  72. if($_W['isajax']) {
  73. load()->model('module');
  74. $m = trim($_GPC['m']);
  75. $uniacid = intval($_GPC['uniacid']);
  76. $uid = intval($_GPC['uid']);
  77. $module = pdo_fetch('SELECT * FROM ' . tablename('modules') . ' WHERE name = :m', array(':m' => $m));
  78. $purview = pdo_fetch('SELECT * FROM ' . tablename('users_permission') . ' WHERE uniacid = :aid AND uid = :uid AND type = :type', array(':aid' => $uniacid, ':uid' => $uid, ':type' => $m));
  79. if(!empty($purview['permission'])) {
  80. $purview['permission'] = explode('|', $purview['permission']);
  81. } else {
  82. $purview['permission'] = array();
  83. }
  84. $mineurl = array();
  85. $all = 0;
  86. if(!empty($mods)) {
  87. foreach($mods as $mod) {
  88. if($mod['url'] == 'all') {
  89. $all = 1;
  90. break;
  91. } else {
  92. $mineurl[] = $mod['url'];
  93. }
  94. }
  95. }
  96. $data = array();
  97. if($module['settings']) {
  98. $data[] = array('title' => '参数设置', 'permission' => $m.'_settings');
  99. }
  100. if($module['isrulefields']) {
  101. $data[] = array('title' => '回复规则列表', 'permission' => $m.'_rule');
  102. }
  103. $entries = module_entries($m);
  104. if(!empty($entries['home'])) {
  105. $data[] = array('title' => '微站首页导航', 'permission' => $m.'_home');
  106. }
  107. if(!empty($entries['profile'])) {
  108. $data[] = array('title' => '个人中心导航', 'permission' => $m.'_profile');
  109. }
  110. if(!empty($entries['shortcut'])) {
  111. $data[] = array('title' => '快捷菜单', 'permission' => $m.'_shortcut');
  112. }
  113. if(!empty($entries['cover'])) {
  114. foreach($entries['cover'] as $cover) {
  115. $data[] = array('title' => $cover['title'], 'permission' => $m.'_cover_'.$cover['do']);
  116. }
  117. }
  118. if(!empty($entries['menu'])) {
  119. foreach($entries['menu'] as $menu) {
  120. $data[] = array('title' => $menu['title'], 'permission' => $m.'_menu_'.$menu['do']);
  121. }
  122. }
  123. unset($entries);
  124. if(!empty($module['permissions'])) {
  125. $module['permissions'] = (array)iunserializer($module['permissions']);
  126. $data = array_merge($data, $module['permissions']);
  127. }
  128. foreach($data as &$da) {
  129. $da['checked'] = 0;
  130. if(in_array($da['permission'], $purview['permission']) || in_array('all', $purview['permission'])) {
  131. $da['checked'] = 1;
  132. }
  133. }
  134. $out['errno'] = 0;
  135. $out['errmsg'] = '';
  136. if(empty($data)) {
  137. $out['errno'] = 1;
  138. } else {
  139. $out['errmsg'] = $data;
  140. }
  141. exit(json_encode($out));
  142. }
  143. }
  144. if ($do == 'menu') {
  145. $uniacid = intval($_GPC['uniacid']);
  146. $uid = intval($_GPC['uid']);
  147. load()->model('user');
  148. load()->model('module');
  149. load()->model('frame');
  150. $user = user_single(array('uid' => $uid));
  151. if (empty($user)) {
  152. message('您操作的用户不存在或是已经被删除!');
  153. }
  154. if (!pdo_fetchcolumn("SELECT id FROM ".tablename('uni_account_users')." WHERE uid = :uid AND uniacid = :uniacid", array(':uid' => $uid, ':uniacid' => $uniacid))) {
  155. message('此用户没有操作该统一公众号的权限,请选指派“管理者”权限!');
  156. }
  157. $system_permission = pdo_fetch('SELECT * FROM ' . tablename('users_permission') . ' WHERE uniacid = :aid AND uid = :uid AND type = :type', array(':aid' => $uniacid, ':uid' => $uid, ':type' => 'system'));
  158. if(!empty($system_permission['permission'])) {
  159. $system_permission['permission'] = explode('|', $system_permission['permission']);
  160. } else {
  161. $system_permission['permission'] = array();
  162. }
  163. $mods = pdo_fetchall('SELECT * FROM ' . tablename('users_permission') . ' WHERE uniacid = :aid AND uid = :uid AND type != :type', array(':aid' => $uniacid, ':uid' => $uid, ':type' => 'system'), 'type');
  164. $mod_keys = array_keys($mods);
  165. if (checksubmit('submit')) {
  166. $system_temp = array();
  167. if(!empty($_GPC['system'])) {
  168. foreach($_GPC['system'] as $li) {
  169. $li = trim($li);
  170. if(!empty($li)) {
  171. $system_temp[] = $li;
  172. }
  173. }
  174. }
  175. if(!empty($system_temp)) {
  176. if(empty($system_permission['id'])) {
  177. $insert = array(
  178. 'uniacid' => $uniacid,
  179. 'uid' => $uid,
  180. 'type' => 'system',
  181. );
  182. $insert['permission'] = implode('|', $_GPC['system']);
  183. pdo_insert('users_permission', $insert);
  184. } else {
  185. $update = array(
  186. 'permission' => implode('|', $_GPC['system'])
  187. );
  188. pdo_update('users_permission', $update, array('uniacid' => $uniacid, 'uid' => $uid));
  189. }
  190. } else {
  191. pdo_delete('users_permission', array('uniacid' => $uniacid, 'uid' => $uid));
  192. }
  193. pdo_query('DELETE FROM ' . tablename('users_permission') . ' WHERE uniacid = :uniacid AND uid = :uid AND type != :type', array(':uniacid' => $uniacid, ':uid' => $uid, ':type' => 'system'));
  194. if(!empty($_GPC['module'])) {
  195. $arr = array();
  196. foreach($_GPC['module'] as $li) {
  197. $insert = array(
  198. 'uniacid' => $uniacid,
  199. 'uid' => $uid,
  200. 'type' => $li,
  201. );
  202. if(empty($_GPC['module_'. $li]) || $_GPC[$li . '_select'] == 1) {
  203. $insert['permission'] = 'all';
  204. pdo_insert('users_permission', $insert);
  205. continue;
  206. } else {
  207. $data = array();
  208. foreach($_GPC['module_'. $li] as $v) {
  209. $data[] = $v;
  210. }
  211. if(!empty($data)) {
  212. $insert['permission'] = implode('|', $data);
  213. pdo_insert('users_permission', $insert);
  214. }
  215. }
  216. }
  217. }
  218. message('操作菜单权限成功!', url('user/permission/menu', array('uid' => $uid, 'uniacid' => $uniacid)), 'success');
  219. }
  220. $menus = frame_lists();
  221. foreach($menus as &$li) {
  222. $li['childs'] = array();
  223. if(!empty($li['child'])) {
  224. foreach($li['child'] as $da) {
  225. if(!empty($da['grandchild'])) {
  226. foreach($da['grandchild'] as &$ca) {
  227. $li['childs'][] = $ca;
  228. }
  229. }
  230. }
  231. unset($li['child']);
  232. }
  233. }
  234. $_W['uniacid'] = $uniacid;
  235. $module = uni_modules();
  236. template('user/menu');
  237. }
  238. if ($do == 'auth') {
  239. $uniacid = intval($_GPC['uniacid']);
  240. $uid = intval($uid);
  241. $isexists = pdo_fetch("SELECT * FROM ".tablename('uni_account_users')." WHERE uid = :uid AND uniacid = :uniacid", array(':uid' => $uid, ':uniacid' => $uniacid));
  242. if (empty($isexists)) {
  243. pdo_insert('uni_account_users', array('uniacid' => $uniacid, 'uid' => $uid));
  244. }
  245. exit('success');
  246. }
  247. if ($do == 'revo') {
  248. $uniacid = intval($_GPC['uniacid']);
  249. $uid = intval($uid);
  250. $isexists = pdo_fetch("SELECT * FROM ".tablename('uni_account_users')." WHERE uid = :uid AND uniacid = :uniacid", array(':uid' => $uid, ':uniacid' => $uniacid));
  251. if (!empty($isexists)) {
  252. pdo_delete('uni_account_users', array('uniacid' => $uniacid, 'uid' => $uid));
  253. }
  254. exit('success');
  255. }
  256. if ($do == 'role') {
  257. $uid = intval($_GPC['uid']);
  258. $uniacid = intval($_GPC['uniacid']);
  259. $role = !empty($_GPC['role']) && in_array($_GPC['role'], array('operator', 'manager')) ? $_GPC['role'] : 'operator';
  260. pdo_update('uni_account_users', array('role' => $role), array('uid' => $uid, 'uniacid' => $uniacid));
  261. }