人人商城

module-permission.ctrl.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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(false);
  11. $module = $_W['current_module'] = $modulelist[$module_name];
  12. if(empty($module)) {
  13. itoast('抱歉,你操作的模块不能被访问!');
  14. }
  15. if(!uni_user_module_permission_check($module_name.'_permissions', $module_name)) {
  16. itoast('您没有权限进行该操作');
  17. }
  18. if ($do == 'display') {
  19. $entries = module_entries($module_name);
  20. $user_permissions = pdo_getall('users_permission', array('uniacid' => $_W['uniacid'], 'type' => $module_name, 'uid <>' => ''), '', 'uid');
  21. $uids = !empty($user_permissions) && is_array($user_permissions) ? array_keys($user_permissions) : array();
  22. $users_lists = array();
  23. if (!empty($uids)) {
  24. $users_lists = pdo_getall('users', array('uid' => $uids), '', 'uid');
  25. }
  26. $current_module_permission = module_permission_fetch($module_name);
  27. $permission_name = array();
  28. if (!empty($current_module_permission)) {
  29. foreach ($current_module_permission as $key => $permission) {
  30. $permission_name[$permission['permission']] = $permission['title'];
  31. }
  32. }
  33. if (!empty($user_permissions)) {
  34. foreach ($user_permissions as $key => &$permission) {
  35. if (!empty($permission['permission'])) {
  36. $permission['permission'] = explode('|', $permission['permission']);
  37. foreach ($permission['permission'] as $k => $val) {
  38. $permission['permission'][$val] = $permission_name[$val];
  39. unset($permission['permission'][$k]);
  40. }
  41. }
  42. $permission['user_info'] = $users_lists[$key];
  43. }
  44. unset($permission);
  45. }
  46. }
  47. if ($do == 'post') {
  48. $uid = intval($_GPC['uid']);
  49. $user = user_single($uid);
  50. $have_permission = uni_user_menu_permission($uid, $_W['uniacid'], $module_name);
  51. if (is_error($have_permission)) {
  52. itoast($have_permission['message']);
  53. }
  54. if (checksubmit()) {
  55. $insert_user = array(
  56. 'username' => trim($_GPC['username']),
  57. 'remark' => trim($_GPC['remark']),
  58. 'password' => trim($_GPC['password']),
  59. 'repassword' => trim($_GPC['repassword']),
  60. 'type' => 3
  61. );
  62. if (empty($insert_user['username'])) {
  63. itoast('必须输入用户名,格式为 1-15 位字符,可以包括汉字、字母(不区分大小写)、数字、下划线和句点。');
  64. }
  65. $operator = array();
  66. if (empty($uid)) {
  67. if (user_check(array('username' => $insert_user['username']))) {
  68. itoast('非常抱歉,此用户名已经被注册,你需要更换注册名称!');
  69. }
  70. if (empty($insert_user['password']) || istrlen($insert_user['password']) < 8) {
  71. itoast('必须输入密码,且密码长度不得低于8位。');
  72. }
  73. if ($insert_user['repassword'] != $insert_user['password']) {
  74. itoast('两次输入密码不一致');
  75. }
  76. unset($insert_user['repassword']);
  77. $uid = user_register($insert_user);
  78. if (!$uid) {
  79. itoast('注册账号失败', '', '');
  80. }
  81. } else {
  82. if (!empty($insert_user['password'])) {
  83. if (istrlen($insert_user['password']) < 8) {
  84. itoast('必须输入密码,且密码长度不得低于8位。');
  85. }
  86. if ($insert_user['repassword'] != $insert_user['password']) {
  87. itoast('两次输入密码不一致');
  88. }
  89. }
  90. $operator['password'] = $insert_user['password'];
  91. $operator['salt'] = $user['salt'];
  92. $operator['uid'] = $uid;
  93. $operator['username'] = $insert_user['username'];
  94. $operator['remark'] = $insert_user['remark'];
  95. $operator['type'] = $insert_user['type'];
  96. user_update($operator);
  97. }
  98. $permission = $_GPC['module_permission'];
  99. if (!empty($permission) && is_array($permission)) {
  100. $permission = implode('|', array_unique($permission));
  101. } else {
  102. $permission = 'all';
  103. }
  104. if (empty($have_permission)) {
  105. pdo_insert('users_permission', array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'type' => $module_name, 'permission' => $permission));
  106. } else {
  107. pdo_update('users_permission', array('permission' => $permission), array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'type' => $module_name));
  108. }
  109. $role = uni_permission($uid, $_W['uniacid']);
  110. if (empty($role)) {
  111. pdo_insert('uni_account_users', array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'role' => 'operator'));
  112. } else {
  113. pdo_update('uni_account_users', array('role' => 'operator'), array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  114. }
  115. itoast('编辑店员资料成功', url('profile/module-permission', array('m' => $module_name)), 'success');
  116. }
  117. $current_module_permission = module_permission_fetch($module_name);
  118. if (!empty($current_module_permission)) {
  119. foreach ($current_module_permission as &$data) {
  120. $data['checked'] = 0;
  121. if (in_array($data['permission'], $have_permission) || in_array('all', $have_permission)) {
  122. $data['checked'] = 1;
  123. }
  124. }
  125. }
  126. unset($data);
  127. }
  128. if ($do == 'delete') {
  129. $operator_id = intval($_GPC['uid']);
  130. if (empty($operator_id)) {
  131. itoast('参数错误', referer(), 'error');
  132. } else {
  133. $user = pdo_get('users', array('uid' => $operator_id), array('uid'));
  134. if (!empty($user)) {
  135. $delete_account_users = pdo_delete('uni_account_users', array('uid' => $operator_id, 'role' => 'operator', 'uniacid' => $_W['uniacid']));
  136. $delete_user_permission = pdo_delete('users_permission', array('uid' => $operator_id, 'type' => $module_name, 'uniacid' => $_W['uniacid']));
  137. if (!empty($delete_account_users) && !empty($delete_user_permission)) {
  138. pdo_delete('users', array('uid' => $operator_id));
  139. }
  140. }
  141. itoast('删除成功', referer(), 'success');
  142. }
  143. }
  144. template('profile/module-permission');