create.ctrl.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. $dos = array('post', 'save');
  9. $do = in_array($do, $dos) ? $do: 'post';
  10. $is_used = safe_gpc_string($_GPC['is_used']);
  11. $groups = user_founder_group();
  12. $modules = user_modules($_W['uid']);
  13. $modules = array_filter($modules, function($module) {
  14. return empty($module['issystem']);
  15. });
  16. $templates = pdo_fetchall("SELECT * FROM " . tablename('site_templates'));
  17. $user_extra_modules = table('users_extra_modules')->getExtraModulesByUid($uid);
  18. $module_support_type = module_support_type();
  19. $user_modules = array('modules' => array(), 'templates' => array());
  20. if (!empty($modules)) {
  21. foreach ($modules as $item) {
  22. if ($item['issystem'] == 0) {
  23. foreach ($module_support_type as $module_support_type_key => $module_support_type_val) {
  24. if ($item[$module_support_type_key] == $module_support_type_val['support']) {
  25. $item['support'] = $module_support_type_key;
  26. $item['checked'] = 0;
  27. $user_modules['modules'][] = $item;
  28. }
  29. }
  30. }
  31. }
  32. }
  33. $source_templates = pdo_getall('site_templates', array(), array('id', 'name', 'title'));
  34. if (!empty($source_templates)) {
  35. foreach ($source_templates as &$source_template) {
  36. $source_template['checked'] = 0;
  37. }
  38. }
  39. if (user_is_vice_founder($_W['uid'])) {
  40. $founder_group_info = user_founder_group_detail_info($_W['user']['groupid']);
  41. $modules_group_list = $founder_group_info['package_detail'];
  42. } else {
  43. $uni_group_table = table('uni_group');
  44. $uni_group_table->searchWithUniacidAndUid();
  45. $modules_group_list = $uni_group_table->getUniGroupList();
  46. }
  47. if (!empty($modules_group_list)) {
  48. foreach ($modules_group_list as $key => $value) {
  49. $modules = (array)iunserializer($value['modules']);
  50. $modules_all = array();
  51. if (!empty($modules)) {
  52. foreach ($modules as $type => $modulenames) {
  53. if (empty($modulenames) || !is_array($modulenames)) {
  54. continue;
  55. }
  56. foreach ($modulenames as $name) {
  57. $modules_all[] = $name;
  58. }
  59. }
  60. }
  61. $modules_all = array_unique($modules_all);
  62. $module_support = array();
  63. foreach ($module_support_type as $support => $info) {
  64. if ($support == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
  65. continue;
  66. }
  67. if ($support == MODULE_SUPPORT_ACCOUNT_NAME) {
  68. $info['type'] = 'modules';
  69. }
  70. if (empty($modules[$info['type']])) {
  71. continue;
  72. }
  73. foreach ($modules[$info['type']] as $modulename) {
  74. $module_support[$modulename][$support] = $info['support'];
  75. }
  76. }
  77. foreach ($modules_all as $name) {
  78. $module = module_fetch($name);
  79. if (empty($module)) {
  80. continue;
  81. }
  82. $module['group_support'] = $module_support[$name];
  83. $modules_group_list[$key]['modules_all'][] = $module;
  84. }
  85. $templates = (array)iunserializer($value['templates']);
  86. $modules_group_list[$key]['template_num'] = !empty($templates) ? count($templates) : 0;
  87. $modules_group_list[$key]['templates'] = pdo_getall('site_templates', array('id' => $templates), array('id', 'name', 'title'));
  88. }
  89. }
  90. $uni_account_types = uni_account_type();
  91. $uni_account_type_signs = array_keys(uni_account_type_sign());
  92. foreach ($uni_account_type_signs as $type_sign_name) {
  93. $max_account_type_signs['max' . $type_sign_name] = 0;
  94. }
  95. $account_group_table = table('users_create_group');
  96. $account_group_lists = $account_group_table->getCreateGroupList();
  97. $user_extra_limits = table('users_extra_limit')->getExtraLimitByUid($uid);
  98. $create_account = array(
  99. 'create_groups' => $account_group_lists,
  100. 'create_numbers' => !empty($user_extra_limits) ? $user_extra_limits : $max_account_type_signs
  101. );
  102. if ($do == 'post') {
  103. template('founder/create');
  104. }
  105. if ($do == 'save') {
  106. $user = $_GPC['user'];
  107. $username = safe_gpc_string($_GPC['user']['username']);
  108. $user_info = user_single(array('username' => $username));
  109. if ($is_used == 'used' && empty($user_info)) {
  110. itoast('用户不存在!', '', 'error');
  111. }
  112. if (!user_is_founder($_W['uid'])) {
  113. itoast('没有权限!', '', 'error');
  114. }
  115. $user_founder = array(
  116. 'username' => $username,
  117. 'remark' => safe_gpc_string($user['remark']),
  118. 'founder_groupid' => ACCOUNT_MANAGE_GROUP_VICE_FOUNDER
  119. );
  120. if ($is_used == 'used') {
  121. $user_founder['uid'] = $user_info['uid'];
  122. $user_save_result = user_update($user_founder);
  123. } else {
  124. $user_founder['password'] = safe_gpc_string($user['password']);
  125. $user_founder['repassword'] = safe_gpc_string($user['repassword']);
  126. $user_founder['starttime'] = TIMESTAMP;
  127. $user_save_result = user_info_save($user_founder, true);
  128. }
  129. if (is_error($user_save_result)) {
  130. iajax(-1, $user_save_result['message'], url('user/display'));
  131. }
  132. $uid = $user_save_result['uid'];
  133. $user_update['groupid'] = intval($_GPC['groupid']) ? intval($_GPC['groupid']) : 0;
  134. $user_update['uid'] = $uid;
  135. if ($user_update['groupid'] == 0) {
  136. $user_update['endtime'] = empty($_GPC['timelimit']) ? USER_ENDTIME_GROUP_DELETE_TYPE : strtotime(intval($_GPC['timelimit']) . ' days', TIMESTAMP);
  137. }
  138. user_update($user_update);
  139. if (!empty($_GPC['uni_groups'])) {
  140. $ext_group_table = table('users_extra_group');
  141. foreach ($_GPC['uni_groups'] as $uni_group_key => $uni_group_val) {
  142. $uni_group_exists = $ext_group_table->getUniGroupByUidAndGroupid($uid, $uni_group_val['id']);
  143. if ($uni_group_exists) {
  144. continue;
  145. }
  146. $res = $ext_group_table->addExtraUniGroup($uid, $uni_group_val['id']);
  147. if (!$res) {
  148. iajax('-1', '添加应用权限组失败!', 'user/display');
  149. }
  150. }
  151. }
  152. if (!empty($_GPC['modules'])) {
  153. $extra_modules_table = table('users_extra_modules');
  154. foreach($_GPC['modules'] as $module_key => $module_val) {
  155. $extra_modules_table->searchByUid($uid);
  156. $extra_modules_table->searchBySupport($module_val['support']);
  157. $extra_modules_table->searchByModuleName($module_val['name']);
  158. $extra_module_exists = $extra_modules_table->get();
  159. if ($extra_module_exists) {
  160. continue;
  161. }
  162. $res = $extra_modules_table->addExtraModule($uid, $module_val['name'], $module_val['support']);
  163. if (!$res) {
  164. iajax('-1', '添加附加模块失败!', 'user/display');
  165. }
  166. }
  167. }
  168. if (!empty($_GPC['templates'])) {
  169. $extra_template_table = table('users_extra_templates');
  170. foreach($_GPC['templates'] as $template_key => $template_val) {
  171. $extra_template_exists = $extra_template_table->getExtraTemplateByUidAndTemplateid($uid, $template_val['id']);
  172. if ($extra_template_exists) {
  173. continue;
  174. }
  175. $res = $extra_template_table->addExtraTemplate($uid, $template_val['id']);
  176. if (!$res) {
  177. iajax('-1', '添加附加模板失败!', 'founder/display');
  178. }
  179. }
  180. }
  181. if (!empty($_GPC['create_account_groups'])) {
  182. $ext_group_table = table('users_extra_group');
  183. foreach ($_GPC['create_account_groups'] as $create_account_group_val) {
  184. $create_account_group_exists = $ext_group_table->getCreateGroupByUidAndGroupid($uid, $create_account_group_val['id']);
  185. if ($create_account_group_exists) {
  186. continue;
  187. }
  188. $res = $ext_group_table->addExtraCreateGroup($uid, $create_account_group_val['id']);
  189. if (!$res) {
  190. iajax('-1', '添加账户权限组失败!', 'founder/display');
  191. }
  192. }
  193. }
  194. if (!empty($_GPC['create_account_nums']) || !empty($_GPC['timelimit'])) {
  195. $extra_limit_table = table('users_extra_limit');
  196. $extra_limit_exists = $extra_limit_table->getExtraLimitByUid($uid);
  197. foreach ($max_account_type_signs as $type_sign_name => $type_sign_val) {
  198. $data[$type_sign_name] = intval($_GPC['create_account_nums'][$type_sign_name]);
  199. }
  200. if ($extra_limit_exists) {
  201. $data['uid'] = $uid;
  202. }
  203. $res = $extra_limit_table->saveExtraLimit($data, $uid);
  204. if (!$res) {
  205. iajax('-1', '添加附加账户数量失败!', 'founder/display');
  206. }
  207. }
  208. if (!empty($_GPC['timelimit'])) {
  209. $extra_limit_table = table('users_extra_limit');
  210. $extra_limit_exists = $extra_limit_table->getExtraLimitByUid($uid);
  211. $data = array(
  212. 'timelimit' => intval($_GPC['timelimit'])
  213. );
  214. if ($extra_limit_exists) {
  215. $data['uid'] = $uid;
  216. }
  217. $extra_limit_add_res = $extra_limit_table->saveExtraLimit($data, $uid);
  218. if (!$extra_limit_add_res) {
  219. iajax('-1', '添加有效时间失败', 'founder/display');
  220. }
  221. }
  222. iajax(0, '操作成功', url('founder/display'));
  223. }
  224. if (checksubmit()) {
  225. $username = safe_gpc_string($_GPC['username']);
  226. $user_info = user_single(array('username' => $username));
  227. if ($type == 'used' && empty($user_info)) {
  228. itoast('用户不存在!', '', 'error');
  229. }
  230. if (!user_is_founder($_W['uid'])) {
  231. itoast('没有权限!', '', 'error');
  232. }
  233. $user_founder = array(
  234. 'username' => $username,
  235. 'remark' => safe_gpc_string($_GPC['remark']),
  236. 'groupid' => intval($_GPC['groupid']),
  237. 'founder_groupid' => ACCOUNT_MANAGE_GROUP_VICE_FOUNDER
  238. );
  239. if ($type == 'used') {
  240. $user_founder['uid'] = $user_info['uid'];
  241. $result = user_update($user_founder);
  242. } else {
  243. $user_founder['password'] = safe_gpc_string($_GPC['password']);
  244. $user_founder['repassword'] = safe_gpc_string($_GPC['repassword']);
  245. $user_founder['starttime'] = TIMESTAMP;
  246. $user_founder['endtime'] = intval($_GPC['timelimit']);
  247. $result = user_info_save($user_founder, true);
  248. }
  249. if (is_error($result)) {
  250. itoast($result['message'], '', 'error');
  251. }
  252. itoast($result['message'], url('founder/display'), 'success');
  253. }