人人商城

edit.ctrl.php 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. load()->model('user');
  8. load()->func('file');
  9. load()->func('cache');
  10. load()->model('visit');
  11. $dos = array('edit_base', 'edit_modules_tpl', 'edit_account', 'edit_users_permission');
  12. $do = in_array($do, $dos) ? $do: 'edit_base';
  13. $_W['page']['title'] = '编辑用户 - 用户管理';
  14. $uid = intval($_GPC['uid']);
  15. $user = user_single($uid);
  16. if (empty($user)) {
  17. itoast('访问错误, 未找到该操作员.', url('user/display'), 'error');
  18. }
  19. if ($user['status'] != USER_STATUS_NORMAL) {
  20. itoast('', url('user/display'), 'info');
  21. }
  22. $founders = explode(',', $_W['config']['setting']['founder']);
  23. $profile = pdo_get('users_profile', array('uid' => $uid));
  24. if (!empty($profile)) $profile['avatar'] = tomedia($profile['avatar']);
  25. if ($do == 'edit_base') {
  26. $account_num = permission_user_account_num($uid);
  27. $user['last_visit'] = date('Y-m-d H:i:s', $user['lastvisit']);
  28. $user['joindate'] = date('Y-m-d H:i:s', $user['joindate']);
  29. $user['end'] = $user['endtime'] == 0 ? '永久' : date('Y-m-d', $user['endtime']);
  30. $user['endtype'] = $user['endtime'] == 0 ? 1 : 2;
  31. $user['url'] = user_invite_register_url($uid);
  32. $profile = user_detail_formate($profile);
  33. $table = table('core_profile_fields');
  34. $extra_fields = $table->getExtraFields();
  35. template('user/edit-base');
  36. }
  37. if ($do == 'edit_modules_tpl') {
  38. if ($_W['isajax'] && $_W['ispost']) {
  39. if ($user['status'] == USER_STATUS_CHECK || $user['status'] == USER_STATUS_BAN) {
  40. iajax(-1, '访问错误,该用户未审核或者已被禁用,请先修改用户状态!', '');
  41. }
  42. if (intval($_GPC['groupid']) == $user['groupid']){
  43. iajax(2, '未做更改!');
  44. }
  45. if (!empty($_GPC['type']) && !empty($_GPC['groupid'])) {
  46. $data['uid'] = $uid;
  47. $data[$_GPC['type']] = intval($_GPC['groupid']);
  48. $group_info = user_group_detail_info($_GPC['groupid']);
  49. $timelimit = intval($group_info['timelimit']);
  50. if ($timelimit > 0) {
  51. $data['endtime'] = strtotime($timelimit . ' days');
  52. } else {
  53. $data['endtime'] = 0;
  54. }
  55. if (user_update($data)) {
  56. cache_delete(cache_system_key('user_modules', array('uid' => $uid)));
  57. visit_system_delete($uid);
  58. iajax(0, $group_info, '');
  59. } else {
  60. iajax(1, '更改失败!', '');
  61. }
  62. } else {
  63. iajax(-1, '参数错误!', '');
  64. }
  65. }
  66. $modules = user_modules($_W['uid']);
  67. $templates = pdo_getall('site_templates', array(), array('id', 'name', 'title'));
  68. $groups = user_group();
  69. $group_info = user_group_detail_info($user['groupid']);
  70. $extend_permission = pdo_get('uni_group', array('uid' => $uid, 'uniacid' => 0));
  71. $extend_permission['templates'] = (array)iunserializer($extend_permission['templates']);
  72. $extend_permission['modules'] = iunserializer($extend_permission['modules']);
  73. if (!empty($templates) && !empty($extend_permission['templates'])) {
  74. foreach ($templates as $k => $temp) {
  75. if (in_array($temp['id'], $extend_permission['templates'])) {
  76. $templates[$k]['checked'] = 1;
  77. }
  78. }
  79. }
  80. $extend = array();
  81. if (!empty($extend_permission['templates'])) {
  82. $extend['templates'] = pdo_getall('site_templates', array('id' => $extend_permission['templates']), array('id', 'name', 'title'));
  83. }
  84. if (!empty($extend_permission['modules'])) {
  85. foreach ($extend_permission['modules'] as $type => $modulenames) {
  86. foreach ($modulenames as $name) {
  87. $module = module_fetch($name);
  88. if (!empty($module)) {
  89. if ($type == 'modules' && $module[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_SUPPORT_ACCOUNT) {
  90. $extend[$type.'_modules'][$name] = $module;
  91. }
  92. if ($type == 'wxapp' && $module[MODULE_SUPPORT_WXAPP_NAME] == MODULE_SUPPORT_WXAPP) {
  93. $extend[$type.'_modules'][$name] = $module;
  94. }
  95. if ($type == 'webapp' && $module[MODULE_SUPPORT_WEBAPP_NAME] == MODULE_SUPPORT_WEBAPP) {
  96. $extend[$type.'_modules'][$name] = $module;
  97. }
  98. if ($type == 'phoneapp' && $module[MODULE_SUPPORT_PHONEAPP_NAME] == MODULE_SUPPORT_PHONEAPP) {
  99. $extend[$type.'_modules'][$name] = $module;
  100. }
  101. if ($type == 'xzapp' && $module[MODULE_SUPPORT_XZAPP_NAME] == MODULE_SUPPORT_XZAPP) {
  102. $extend[$type.'_modules'][$name] = $module;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. $user_modules = array('account' => array(), 'wxapp' => array(), 'webapp' => array(), 'phoneapp' => array(), 'xzapp' => array());
  109. if (!empty($modules)) {
  110. foreach ($modules as $item) {
  111. if ($item['issystem'] == 0) {
  112. if ($item[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_SUPPORT_ACCOUNT) {
  113. if (!empty($extend_permission['modules']['modules']) && in_array($item['name'], $extend_permission['modules']['modules'])) {
  114. $item['checked'] = 1;
  115. }
  116. $user_modules['account'][] = $item;
  117. $item['checked'] = 0;
  118. }
  119. if ($item[MODULE_SUPPORT_WXAPP_NAME] == MODULE_SUPPORT_WXAPP) {
  120. if (!empty($extend_permission['modules']['wxapp']) && in_array($item['name'], $extend_permission['modules']['wxapp'])) {
  121. $item['checked'] = 1;
  122. }
  123. $user_modules['wxapp'][] = $item;
  124. $item['checked'] = 0;
  125. }
  126. if ($item[MODULE_SUPPORT_WEBAPP_NAME] == MODULE_SUPPORT_WEBAPP) {
  127. if (!empty($extend_permission['modules']['webapp']) && in_array($item['name'], $extend_permission['modules']['webapp'])) {
  128. $item['checked'] = 1;
  129. }
  130. $user_modules['webapp'][] = $item;
  131. $item['checked'] = 0;
  132. }
  133. if ($item[MODULE_SUPPORT_PHONEAPP_NAME] == MODULE_SUPPORT_PHONEAPP) {
  134. if (!empty($extend_permission['modules']['phoneapp']) && in_array($item['name'], $extend_permission['modules']['phoneapp'])) {
  135. $item['checked'] = 1;
  136. }
  137. $user_modules['phoneapp'][] = $item;
  138. $item['checked'] = 0;
  139. }
  140. if ($item[MODULE_SUPPORT_XZAPP_NAME] == MODULE_SUPPORT_XZAPP) {
  141. if (!empty($extend_permission['modules']['xzapp']) && in_array($item['name'], $extend_permission['modules']['xzapp'])) {
  142. $item['checked'] = 1;
  143. }
  144. $user_modules['xzapp'][] = $item;
  145. $item['checked'] = 0;
  146. }
  147. }
  148. }
  149. }
  150. template('user/edit-modules-tpl');
  151. }
  152. if ($do == 'edit_account') {
  153. $account_detail = user_account_detail_info($uid);
  154. template('user/edit-account');
  155. }
  156. if ($do == 'edit_users_permission') {
  157. if ($_W['isajax'] && $_W['ispost']) {
  158. $module = $_GPC['module'];
  159. $tpl = $_GPC['tpl'];
  160. if (!empty($module) || !empty($tpl)) {
  161. $data = array(
  162. 'modules' => iserializer(array(
  163. 'modules' => empty($module['modules']) ? array() : $module['modules'],
  164. 'wxapp' => empty($module['wxapp']) ? array() : $module['wxapp'],
  165. 'webapp' => empty($module['webapp']) ? array(): $module['webapp'],
  166. 'xzapp' => empty($module['xzapp']) ? array() : $module['xzapp'],
  167. 'phoneapp' => empty($module['phoneapp']) ? array() : $module['phoneapp']
  168. )),
  169. 'templates' => empty($tpl) ? '' : iserializer($tpl),
  170. 'uid' => $uid,
  171. 'uniacid' => 0,
  172. 'owner_uid' => 0,
  173. 'name' => '',
  174. );
  175. $id = pdo_fetchcolumn("SELECT id FROM " . tablename('uni_group') . " WHERE uid=:uid and uniacid=:uniacid", array(":uniacid" => 0, ":uid" => $uid));
  176. if (empty($id)) {
  177. $res = pdo_insert('uni_group', $data);
  178. } else {
  179. $res = pdo_update('uni_group', $data, array('id' => $id));
  180. }
  181. } else {
  182. $res = pdo_delete('uni_group', array('uid' => $uid, 'uniacid' => 0));
  183. }
  184. if ($res === false) {
  185. iajax(-1, '修改失败', '');
  186. } else {
  187. iajax(0, '修改成功', '');
  188. }
  189. }
  190. }