人人商城

permission.ctrl.php 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. $dos = array('display', 'post', 'delete');
  8. $do = !empty($_GPC['do']) ? $_GPC['do'] : 'display';
  9. $module_name = trim($_GPC['m']);
  10. $modulelist = uni_modules();
  11. $module = $_W['current_module'] = $modulelist[$module_name];
  12. define('IN_MODULE', $module_name);
  13. if(empty($module)) {
  14. itoast('抱歉,你操作的模块不能被访问!');
  15. }
  16. if(!permission_check_account_user_module($module_name.'_permissions', $module_name)) {
  17. itoast('您没有权限进行该操作');
  18. }
  19. if ($do == 'display') {
  20. $user_permissions = module_clerk_info($module_name);
  21. $current_module_permission = module_permission_fetch($module_name);
  22. $permission_name = array();
  23. if (!empty($current_module_permission)) {
  24. foreach ($current_module_permission as $key => $permission) {
  25. $permission_name[$permission['permission']] = $permission['title'];
  26. }
  27. }
  28. if (!empty($user_permissions)) {
  29. foreach ($user_permissions as $key => &$permission) {
  30. if (!empty($permission['permission'])) {
  31. $permission['permission'] = explode('|', $permission['permission']);
  32. foreach ($permission['permission'] as $k => $val) {
  33. $permission['permission'][$val] = $permission_name[$val];
  34. unset($permission['permission'][$k]);
  35. }
  36. }
  37. }
  38. unset($permission);
  39. }
  40. }
  41. if ($do == 'post') {
  42. $uid = intval($_GPC['uid']);
  43. $user = user_single($uid);
  44. $module_and_plugins = array();
  45. $all_permission = array();
  46. if (!empty($module['plugin_list'])) {
  47. $module_and_plugins = array_reverse($module['plugin_list']);
  48. }
  49. array_push($module_and_plugins, $module_name);
  50. $module_and_plugins = array_reverse($module_and_plugins);
  51. foreach ($module_and_plugins as $key => $module_val) {
  52. $all_permission[$module_val]['info'] = module_fetch($module_val);
  53. $all_permission[$module_val]['permission'] = module_permission_fetch($module_val);
  54. }
  55. if (!empty($uid)) {
  56. foreach ($module_and_plugins as $key => $plugin) {
  57. $have_permission[$plugin] = permission_account_user_menu($uid, $_W['uniacid'], $plugin);
  58. foreach ($all_permission[$plugin]['permission'] as $key => $value) {
  59. $all_permission[$plugin]['permission'][$key]['checked'] = 0;
  60. if (in_array($value['permission'], $have_permission[$plugin]) || in_array('all', $have_permission[$plugin])) {
  61. $all_permission[$plugin]['permission'][$key]['checked'] = 1;
  62. }
  63. if (!empty($value['sub_permission'])) {
  64. foreach ($value['sub_permission'] as $sub_permission_key => $sub_permission_val) {
  65. if (in_array($sub_permission_val['permission'], $have_permission[$plugin])) {
  66. $all_permission[$plugin]['permission'][$key]['sub_permission'][$sub_permission_key]['checked'] = 1;
  67. }
  68. }
  69. }
  70. }
  71. }
  72. if (is_error($have_permission)) {
  73. itoast($have_permission['message']);
  74. }
  75. }
  76. if (checksubmit()) {
  77. $insert_user = array(
  78. 'username' => trim($_GPC['username']),
  79. 'remark' => trim($_GPC['remark']),
  80. 'password' => trim($_GPC['password']),
  81. 'repassword' => trim($_GPC['repassword']),
  82. 'type' => ACCOUNT_OPERATE_CLERK
  83. );
  84. if (empty($insert_user['username'])) {
  85. itoast('必须输入用户名,格式为 1-15 位字符,可以包括汉字、字母(不区分大小写)、数字、下划线和句点。');
  86. }
  87. $operator = array();
  88. if (empty($uid)) {
  89. if (user_check(array('username' => $insert_user['username']))) {
  90. itoast('非常抱歉,此用户名已经被注册,你需要更换注册名称!');
  91. }
  92. if (empty($insert_user['password']) || istrlen($insert_user['password']) < 8) {
  93. itoast('必须输入密码,且密码长度不得低于8位。');
  94. }
  95. if ($insert_user['repassword'] != $insert_user['password']) {
  96. itoast('两次输入密码不一致');
  97. }
  98. unset($insert_user['repassword']);
  99. $uid = user_register($insert_user, 'admin');
  100. if (is_error($uid)) {
  101. itoast($uid['message'], '', '');
  102. }
  103. if (!$uid) {
  104. itoast('注册账号失败', '', '');
  105. }
  106. } else {
  107. if (!empty($insert_user['password'])) {
  108. if (istrlen($insert_user['password']) < 8) {
  109. itoast('必须输入密码,且密码长度不得低于8位。');
  110. }
  111. if ($insert_user['repassword'] != $insert_user['password']) {
  112. itoast('两次输入密码不一致');
  113. }
  114. }
  115. $operator['password'] = $insert_user['password'];
  116. $operator['salt'] = $user['salt'];
  117. $operator['uid'] = $uid;
  118. $operator['username'] = $insert_user['username'];
  119. $operator['remark'] = $insert_user['remark'];
  120. $operator['type'] = $insert_user['type'];
  121. user_update($operator);
  122. }
  123. $permission = $_GPC['module_permission'];
  124. if (!empty($permission) && is_array($permission)) {
  125. foreach ($module_and_plugins as $name) {
  126. if (empty($permission[$name])) {
  127. $module_permission = '';
  128. } else {
  129. $module_permission = implode('|', array_unique($permission[$name]));
  130. }
  131. if (empty($module_permission) && !empty($have_permission[$name])) {
  132. pdo_delete('users_permission', array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'type' => $name));
  133. continue;
  134. }
  135. if (empty($module_permission)) {
  136. continue;
  137. }
  138. if (empty($have_permission[$name])) {
  139. pdo_insert('users_permission', array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'type' => $name, 'permission' => $module_permission));
  140. } else {
  141. pdo_update('users_permission', array('permission' => $module_permission), array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'type' => $name));
  142. }
  143. }
  144. } else {
  145. foreach ($module_and_plugins as $name) {
  146. if (!empty($have_permission[$name])) {
  147. pdo_delete('users_permission', array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'type' => $name));
  148. }
  149. }
  150. }
  151. $role = table('users')->userOwnedAccountRole($uid, $_W['uniacid']);
  152. if (empty($role)) {
  153. pdo_insert('uni_account_users', array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'role' => 'clerk'));
  154. } else {
  155. pdo_update('uni_account_users', array('role' => 'clerk'), array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  156. }
  157. itoast('编辑店员资料成功', url('module/permission', array('m' => $module_name)), 'success');
  158. }
  159. }
  160. if ($do == 'add_clerk') {
  161. $founders = explode(',', $_W['config']['setting']['founder']);
  162. $username = trim($_GPC['username']);
  163. $user = user_single(array('username' => $username));
  164. if (!empty($user)) {
  165. if ($user['status'] != 2) {
  166. itoast('用户未通过审核或不存在', url('module/permission', array('m' => $module_name)), 'error');
  167. }
  168. if (in_array($user['uid'], $founders)) {
  169. itoast('不可操作网站创始人!', url('module/permission', array('m' => $module_name)), 'error');
  170. }
  171. } else {
  172. itoast('用户不存在', url('module/permission', array('m' => $module_name)), 'error');
  173. }
  174. $data = array('uniacid' => $_W['uniacid'], 'uid' => $user['uid'], 'type' => $module_name);
  175. $exists = pdo_get('users_permission', $data);
  176. if (is_array($exists) && !empty($exists)) {
  177. itoast('操作员已经存在!', url('module/permission', array('m' => $module_name)), 'error');
  178. }
  179. $data['permission'] = 'all';
  180. $res = pdo_insert('users_permission', $data);
  181. if ($res) {
  182. $role = table('users')->userOwnedAccountRole($user['uid'], $_W['uniacid']);
  183. if (empty($role)) {
  184. pdo_insert('uni_account_users', array('uniacid' => $_W['uniacid'], 'uid' => $user['uid'], 'role' => 'clerk'));
  185. } else {
  186. pdo_update('uni_account_users', array('role' => 'clerk'), array('uniacid' => $_W['uniacid'], 'uid' => $user['uid']));
  187. }
  188. itoast('添加成功!', url('module/permission', array('m' => $module_name)), 'success');
  189. } else {
  190. itoast('操作失败!', url('module/permission', array('m' => $module_name)), 'error');
  191. }
  192. }
  193. if ($do == 'delete') {
  194. $operator_id = intval($_GPC['uid']);
  195. if (empty($operator_id)) {
  196. itoast('参数错误', referer(), 'error');
  197. } else {
  198. $user = pdo_get('users', array('uid' => $operator_id), array('uid'));
  199. if (!empty($user)) {
  200. $delete_account_users = pdo_delete('uni_account_users', array('uid' => $operator_id, 'role' => 'clerk', 'uniacid' => $_W['uniacid']));
  201. $delete_user_permission = pdo_delete('users_permission', array('uid' => $operator_id, 'type' => $module_name, 'uniacid' => $_W['uniacid']));
  202. }
  203. itoast('删除成功', referer(), 'success');
  204. }
  205. }
  206. template('module/permission');