edit.ctrl.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. load()->model('module');
  12. $dos = array('edit_base', 'edit_modules_tpl', 'edit_account', 'edit_users_permission', 'edit_account_dateline', 'edit_create_account_list', 'edit_user_group', 'edit_user_extra_limit', 'edit_user_extra_group', 'edit_uni_groups', 'edit_extra_modules', 'delete_user_group');
  13. $do = in_array($do, $dos) ? $do: 'edit_base';
  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['endtype'] = $user['endtime'] == 0 ? 1 : 2;
  30. $user['url'] = user_invite_register_url($uid);
  31. $user['end'] = user_end_time($uid);
  32. $user['end'] = $user['end'] == 0 ? '永久' : $user['end'];
  33. $profile = user_detail_formate($profile);
  34. $extra_fields = user_available_extra_fields();
  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['groupid'] = intval($_GPC['groupid']);
  48. $update_res = user_update($data);
  49. cache_clean(cache_system_key('user_modules'));
  50. cache_clean(cache_system_key('unimodules'));
  51. $user_uni_accounts = uni_user_accounts($uid);
  52. foreach ($user_uni_accounts as $uni_account_key => $uni_account_val) {
  53. cache_build_account_modules($uni_account_key, $uid);
  54. }
  55. if ($update_res) {
  56. visit_system_delete($uid);
  57. if (user_is_vice_founder($uid)) {
  58. $group_info = user_founder_group_detail_info($data['groupid']);
  59. } else {
  60. $group_info = user_group_detail_info($_GPC['groupid']);
  61. }
  62. iajax(0, $group_info, '');
  63. } else {
  64. iajax(1, '更改失败!', '');
  65. }
  66. } else {
  67. iajax(-1, '参数错误!', '');
  68. }
  69. }
  70. cache_clean(cache_system_key('unimodules'));
  71. $modules = user_modules($_W['uid']);
  72. $templates = pdo_getall('site_templates', array(), array('id', 'name', 'title'));
  73. $groups = user_group();
  74. $group_info = user_group_detail_info($user['groupid']);
  75. $extend = array();
  76. $users_extra_template_table = table('users_extra_templates');
  77. $user_extend_templates_ids = array_keys($users_extra_template_table->getExtraTemplatesIdsByUid($_GPC['uid']));
  78. if (!empty($user_extend_templates_ids)) {
  79. $extend['templates'] = pdo_getall('site_templates', array('id' => $user_extend_templates_ids), array('id', 'name', 'title'));
  80. }
  81. if (!empty($templates) && !empty($user_extend_templates_ids)) {
  82. foreach($templates as $template_key => $template_val) {
  83. if (in_array($template_val['id'], $user_extend_templates_ids)) {
  84. $templates[$template_key]['checked'] = 1;
  85. }
  86. }
  87. }
  88. $group_keys = array();
  89. if (user_is_vice_founder($_W['uid'])) {
  90. $founder_own_table = table('users_founder_own_uni_groups');
  91. $founder_own_uni_groups = $founder_own_table->getOwnUniGroupsByFounderUid($_W['uid']);
  92. $group_keys = array_keys((array)$founder_own_uni_groups);
  93. }
  94. $uni_groups = uni_groups($group_keys);
  95. $users_extra_group_table = table('users_extra_group');
  96. $user_extra_groups = $users_extra_group_table->getUniGroupsByUid($uid);
  97. $user_extra_groups = !empty($user_extra_groups) ? uni_groups(array_keys($user_extra_groups)) : array();
  98. if (!empty($uni_groups)) {
  99. foreach ($uni_groups as $module_group_key => &$module_group_val) {
  100. if (!empty($user_extra_groups[$module_group_key])) {
  101. $module_group_val['checked'] = 1;
  102. } else {
  103. $module_group_val['checked'] = 0;
  104. }
  105. unset($module_group_val);
  106. }
  107. }
  108. $users_extra_modules_table = table('users_extra_modules');
  109. $user_extend_modules = $users_extra_modules_table->where('uid', $uid)->getall('id');
  110. $extra_module_types = array();
  111. if (!empty($user_extend_modules)) {
  112. foreach($user_extend_modules as $extend_module_info) {
  113. $module_info = module_fetch($extend_module_info['module_name']);
  114. $module_info['support'] = $extend_module_info['support'];
  115. if (!empty($module_info)) {
  116. $extend['modules'][] = $module_info;
  117. $extra_module_types[] = $extend_module_info['module_name'] . $module_info['support'];
  118. }
  119. }
  120. }
  121. $module_support_type = module_support_type();
  122. if (!empty($modules)) {
  123. foreach ($modules as $item) {
  124. if ($item['issystem'] == 0) {
  125. foreach ($module_support_type as $module_support_type_key => $module_support_type_val) {
  126. if ($item[$module_support_type_key] == $module_support_type_val['support']) {
  127. $item['support'] = $module_support_type_key;
  128. $item['checked'] = 0;
  129. $user_modules['modules'][] = $item;
  130. }
  131. }
  132. }
  133. }
  134. }
  135. foreach ($user_modules['modules'] as &$user_module_info) {
  136. if (in_array($user_module_info['name'] . $user_module_info['support'], $extra_module_types)) {
  137. $user_module_info['checked'] = 1;
  138. }
  139. unset($user_module_info);
  140. }
  141. template('user/edit-modules-tpl');
  142. }
  143. if ($do == 'edit_account') {
  144. $account_detail = user_account_detail_info($uid);
  145. $account_list = array();
  146. if (!empty($account_detail)) {
  147. foreach($account_detail as $account_type => $accounts) {
  148. foreach ($accounts as $uniacid => $account) {
  149. $account['type_name'] = $account_type == 'wechats' ? 'account' : $account_type;
  150. $account_list[$uniacid] = $account;
  151. }
  152. }
  153. }
  154. template('user/edit-account');
  155. }
  156. if ($do == 'edit_users_permission') {
  157. if ($_W['isajax'] && $_W['ispost']) {
  158. $uid = intval($_GPC['uid']);
  159. $modules = array_unique(safe_gpc_array($_GPC['modules']));
  160. $templates = safe_gpc_array($_GPC['templates']);
  161. $users_extra_template_table = table('users_extra_templates');
  162. $users_extra_modules_table = table('users_extra_modules');
  163. if (!empty($modules)) {
  164. $users_extra_modules_table->deleteExtraModulesByUid($uid);
  165. foreach($modules as $module_name) {
  166. $users_extra_modules_table->addExtraModule($uid, $module_name);
  167. }
  168. }
  169. if (!empty($templates)) {
  170. $users_extra_template_table->deleteExtraTemplatesByUid($uid);
  171. foreach($templates as $template_id) {
  172. $add_res = $users_extra_template_table->addExtraTemplate($uid, $template_id);
  173. }
  174. }
  175. iajax(0, '修改成功', '');
  176. }
  177. }
  178. if ($do == 'edit_account_dateline') {
  179. if (user_is_vice_founder($uid)) {
  180. $groups = user_founder_group();
  181. $group_info = table('users_founder_group')->getById($user['groupid']);
  182. } else {
  183. $groups = user_group();
  184. $group_info = table('users_group')->getById($user['groupid']);
  185. }
  186. $extra_limit_table = table('users_extra_limit');
  187. $extra_limit_info = $extra_limit_table->getExtraLimitByUid($uid);
  188. $endtime = $user['endtime'];
  189. $total_timelimit = $group_info['timelimit'] + $extra_limit_info['timelimit'];
  190. $user_end_time_check = $user['endtime'] == strtotime($total_timelimit . ' days', $user['joindate']);
  191. if (!$user_end_time_check && $group_info['timelimit'] != 0) {
  192. user_update(array('uid' => $uid, 'endtime' => strtotime($total_timelimit . ' days', $user['joindate'])));
  193. }
  194. if (!empty($group_info) && $group_info['timelimit'] == 0) {
  195. user_update(array('uid' => $uid, 'endtime' => USER_ENDTIME_GROUP_UNLIMIT_TYPE));
  196. }
  197. if ($endtime == USER_ENDTIME_GROUP_EMPTY_TYPE || $endtime == USER_ENDTIME_GROUP_UNLIMIT_TYPE) {
  198. $total_timelimit = '永久';
  199. $endtime = '永久';
  200. } elseif ($endtime == USER_ENDTIME_GROUP_DELETE_TYPE && $total_timelimit == 0) {
  201. $endtime = $total_timelimit == 0 ? date('Y-m-d', $user['joindate']) : date('Y-m-d', $user['endtime']);
  202. } else {
  203. $endtime = date('Y-m-d', $endtime);
  204. }
  205. template('user/edit-account-dateline');
  206. }
  207. if ($do == 'edit_create_account_list') {
  208. $uid = intval($_GPC['uid']);
  209. $user_permission_account = permission_user_account_num($uid);
  210. if (user_is_vice_founder()) {
  211. $create_groups = table('users_founder_own_create_groups')->getallGroupsByFounderUid($_W['uid']);
  212. } else {
  213. $create_groups = table('users_create_group')->getall();
  214. }
  215. $extra_groupids = array();
  216. if (!empty($user_permission_account['create_groups'])) {
  217. foreach ($user_permission_account['create_groups'] as $item) {
  218. $extra_groupids[] = $item['id'];
  219. }
  220. }
  221. foreach ($create_groups as &$group) {
  222. if (in_array($group['id'], $extra_groupids)) {
  223. $group['checked'] = 1;
  224. } else {
  225. $group['checked'] = 0;
  226. }
  227. }
  228. $create_numbers = array();
  229. $module_support_type = module_support_type();
  230. foreach ($module_support_type as $info) {
  231. if ($info['type'] == WELCOMESYSTEM_TYPE_SIGN) {
  232. continue;
  233. }
  234. $max_type = 'max' . $info['type'];
  235. $extra_type = 'extra_' . $info['type'];
  236. $create_numbers[$max_type] = $user_permission_account[$extra_type];
  237. }
  238. $create_account = array(
  239. 'create_groups' => $create_groups,
  240. 'create_numbers' => $create_numbers,
  241. );
  242. if (user_is_vice_founder($uid)) {
  243. $user_groups = user_founder_group();
  244. } else {
  245. $user_groups = user_group();
  246. }
  247. $group_info = user_group_detail_info($user['groupid']);
  248. template('user/edit-create-account-list');
  249. }
  250. if ($do == 'edit_user_group') {
  251. if ($_W['isajax'] && $_W['ispost']) {
  252. $user = array(
  253. 'groupid' => intval($_GPC['groupid']),
  254. 'uid' => $uid,
  255. );
  256. $res = user_update($user);
  257. if ($res) {
  258. iajax(0, '修改成功');
  259. } else {
  260. iajax(-1, '修改失败');
  261. }
  262. }
  263. }
  264. if ($do == 'edit_user_extra_limit') {
  265. $extra_limit_table = table('users_extra_limit');
  266. $extra_limit_info = $extra_limit_table->getExtraLimitByUid($uid);
  267. $post_timelimit = intval($_GPC['timelimit']);
  268. $time_limit = $post_timelimit - $extra_limit_info['timelimit'];
  269. $data = array(
  270. 'timelimit' => $post_timelimit,
  271. );
  272. if (user_is_vice_founder()) {
  273. $permission_check_result = permission_check_vice_founder_limit($data);
  274. if (is_error($permission_check_result)) {
  275. iajax(-1, $permission_check_result['message']);
  276. }
  277. }
  278. if ($extra_limit_info) {
  279. $data['uid'] = $extra_limit_info['uid'];
  280. }
  281. if ($_W['isajax'] && $_W['ispost']) {
  282. $res = $extra_limit_table->saveExtraLimit($data, $uid);
  283. if ($res) {
  284. if ($user['endtime'] != USER_ENDTIME_GROUP_EMPTY_TYPE && $user['endtime'] != USER_ENDTIME_GROUP_UNLIMIT_TYPE) {
  285. $user_endtime = $user['endtime'] == USER_ENDTIME_GROUP_DELETE_TYPE ? $user['joindate'] : $user['endtime'];
  286. $end_time = strtotime($time_limit . ' days', $user_endtime);
  287. user_update(array('endtime' => $end_time, 'uid' => $uid));
  288. }
  289. iajax(0, '修改成功', url('user/edit/edit_account_dateline', array('uid' => $uid)));
  290. } else {
  291. iajax(-1, '修改失败');
  292. }
  293. }
  294. }
  295. if ($do == 'edit_user_extra_group') {
  296. $operate = $_GPC['operate'];
  297. $extra_group_table = table('users_extra_group');
  298. if ($operate == 'delete') {
  299. $group_ids = safe_gpc_array($_GPC['group_ids']);
  300. $extra_group_table->searchWithUidCreateGroupId($uid, $group_ids)->delete();
  301. } elseif ($operate == 'extend_group') {
  302. $group_ids = safe_gpc_array($_GPC['group_ids']);
  303. $del_ids = safe_gpc_array($_GPC['del_ids']);
  304. if (!empty($group_ids)) {
  305. foreach ($group_ids as $group_id) {
  306. $extra_group = $extra_group_table->searchWithUidCreateGroupId($uid, $group_id)->get();
  307. if (!empty($extra_group)) {
  308. continue;
  309. }
  310. $extra_group_table->addExtraCreateGroup($uid, $group_id);
  311. }
  312. }
  313. if (!empty($del_ids)) {
  314. $extra_group_table->searchWithUidCreateGroupId($uid, $del_ids)->delete();
  315. }
  316. } elseif ($operate == 'extend_numbers') {
  317. $extra_limit_table = table('users_extra_limit');
  318. $uni_account_types = uni_account_type();
  319. $uni_account_type_signs = array_keys(uni_account_type_sign());
  320. foreach ($uni_account_type_signs as $type_sign_name) {
  321. $max_type = 'max' . $type_sign_name;
  322. $data[$max_type] = intval($_GPC['numbers'][$max_type]);
  323. }
  324. if (user_is_vice_founder()) {
  325. $permission_check_result = permission_check_vice_founder_limit($data);
  326. if (is_error($permission_check_result)) {
  327. iajax(-1, $permission_check_result['message']);
  328. }
  329. }
  330. $extra_limit_info = $extra_limit_table->getExtraLimitByUid($uid);
  331. if ($extra_limit_info) {
  332. $data['uid'] = $extra_limit_info['uid'];
  333. }
  334. $extra_limit_table->saveExtraLimit($data, $uid);
  335. }
  336. iajax(0, '修改成功', referer());
  337. }
  338. if ($do == 'edit_uni_groups') {
  339. $uni_group_ids = $_GPC['uni_groups'];
  340. $ext_group_table = table('users_extra_group');
  341. if (!empty($uni_group_ids)) {
  342. $ext_group_table->where(array('uid' => $uid, 'uni_group_id !=' => 0))->delete();
  343. foreach ($uni_group_ids as $uni_group_id) {
  344. $ext_group_table->addExtraUniGroup($uid, $uni_group_id);
  345. }
  346. } else {
  347. $ext_group_table->where(array('uid' => $uid))->delete();
  348. }
  349. iajax(0, '修改成功!', referer());
  350. }
  351. if ($do == 'edit_extra_modules') {
  352. $extra_modules = $_GPC['extra_modules'];
  353. $extra_modules_table = table('users_extra_modules');
  354. $extra_modules_table->where(array('uid' => $uid))->delete();
  355. foreach ($extra_modules as $module_info) {
  356. $extra_modules_table->addExtraModule($uid, $module_info['name'], $module_info['support']);
  357. }
  358. $templates = $_GPC['extra_templates'];
  359. $users_extra_template_table = table('users_extra_templates');
  360. $users_extra_template_table->deleteExtraTemplatesByUid($uid);
  361. if (!empty($templates)) {
  362. foreach($templates as $template_id) {
  363. $users_extra_template_table->addExtraTemplate($uid, $template_id['id']);
  364. }
  365. }
  366. iajax(0, '修改成功!', referer());
  367. }
  368. if ($do == 'delete_user_group') {
  369. $groupid = intval($_GPC['groupid']);
  370. if (!user_is_founder($_W['uid'])) {
  371. itoast('权限错误', referer(), 'error');
  372. }
  373. if (user_is_vice_founder($_W['uid'])) {
  374. $founder_own_users = table('users_founder_own_users')->getFounderOwnUsersList($_W['uid']);
  375. if (!in_array($uid, array_keys($founder_own_users))) {
  376. itoast('信息有误', referer(), 'error');
  377. }
  378. }
  379. if (user_is_vice_founder($uid)) {
  380. $group_info = user_founder_group_detail_info($groupid);
  381. } else {
  382. $group_info = user_group_detail_info($groupid);
  383. }
  384. if ($user['groupid'] != $groupid) {
  385. itoast('信息有误', referer(), 'error');
  386. }
  387. $user_end_time = $user['endtime'];
  388. $users_extra_limit_table = table('users_extra_limit');
  389. $extra_limit_info = $users_extra_limit_table->getExtraLimitByUid($uid);
  390. if (empty($extra_limit_info)) {
  391. $result = user_update(array('uid' => $uid, 'groupid' => '', 'endtime' => 1));
  392. } else {
  393. $group_info_timelimit = $group_info['timelimit'];
  394. if ($group_info_timelimit == 0) {
  395. $end_time = !empty($extra_limit_info) && $extra_limit_info['timelimit'] > 0 ? strtotime($extra_limit_info['timelimit'] . ' days', $user['joindate']) : $user['joindate'];
  396. } else {
  397. $end_time = strtotime('-' . $group_info_timelimit . ' days', $user_end_time);
  398. }
  399. $result = user_update(array('uid' => $uid, 'groupid' => '', 'endtime' => $end_time));
  400. }
  401. if ($result) {
  402. itoast('修改成功', referer(), 'success');
  403. } else {
  404. itoast('修改失败', referer(), 'error');
  405. }
  406. }