group.ctrl.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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('module');
  8. load()->model('user');
  9. load()->model('module');
  10. $dos = array('display', 'delete', 'post', 'save', 'edit');
  11. $do = !empty($_GPC['do']) ? $_GPC['do'] : 'display';
  12. if (!in_array($_W['highest_role'], array(ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER))){
  13. itoast('无权限操作!', referer(), 'error');
  14. }
  15. if ($do == 'display') {
  16. $pageindex = max(1, intval($_GPC['page']));
  17. $pagesize = 10;
  18. $uni_group_table = table('uni_group');
  19. $uni_group_table->searchWithUniacidAndUid();
  20. $name = safe_gpc_string($_GPC['name']);
  21. if (!empty($name)) {
  22. $uni_group_table->searchWithName($name);
  23. }
  24. if (user_is_vice_founder($_W['uid'])) {
  25. $uni_group_table->searchWithFounderUid($_W['uid']);
  26. }
  27. $uni_group_table->searchWithPage($pageindex, $pagesize);
  28. $modules_group_list = $uni_group_table->getUniGroupList();
  29. $total = $uni_group_table->getLastQueryTotal();
  30. $pager = pagination($total, $pageindex, $pagesize);
  31. $module_support_type = module_support_type();
  32. if (!empty($modules_group_list)) {
  33. $all_module_names = array();
  34. foreach ($modules_group_list as $key => $value) {
  35. $value['modules'] = iunserializer($value['modules']);
  36. if (!is_array($value['modules'])) {
  37. $value['modules'] = array();
  38. }
  39. $modules_group_list[$key]['modules'] = $value['modules'];
  40. foreach ($value['modules'] as $type => $modulenames) {
  41. if (empty($modulenames) || !is_array($modulenames)) {
  42. $modules_group_list[$key][$type . '_num'] = 0;
  43. continue;
  44. } else {
  45. $type = $type == 'modules' ? 'account' : $type;
  46. $modules_group_list[$key][$type . '_num'] = count($modulenames);
  47. }
  48. $all_module_names = array_merge($all_module_names, $modulenames);
  49. }
  50. }
  51. $all_modules = table('modules')->searchWithName(array_unique($all_module_names))->getall('name');
  52. foreach ($modules_group_list as &$group) {
  53. if (empty($group['modules'])) {
  54. continue;
  55. }
  56. $template_ids = iunserializer($group['templates']);
  57. $group['templates'] = array();
  58. if (is_array($template_ids)) {
  59. $templates = table('site_templates')->searchWithId($template_ids)->getAll();
  60. if (is_array($templates)) {
  61. foreach ($templates as $k => $temp) {
  62. $temp['logo'] = $_W['siteroot'] . "app/themes/{$temp['name']}/preview.jpg";
  63. $group['templates'][$k] = $temp;
  64. }
  65. }
  66. }
  67. $group['modules_all'] = array();
  68. foreach ($module_support_type as $support => $info) {
  69. if ($support == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
  70. continue;
  71. }
  72. if ($support == MODULE_SUPPORT_ACCOUNT_NAME) {
  73. $info['type'] = 'modules';
  74. }
  75. if (empty($group['modules'][$info['type']])) {
  76. continue;
  77. }
  78. foreach ($group['modules'][$info['type']] as $modulename) {
  79. if (empty($all_modules[$modulename])) {
  80. continue;
  81. }
  82. if (empty($group['modules_all'][$modulename])) {
  83. $all_modules[$modulename]['logo'] = tomedia($all_modules[$modulename]['logo']);
  84. $group['modules_all'][$modulename] = $all_modules[$modulename];
  85. }
  86. if ($all_modules[$modulename][$support] == $info['support']) {
  87. $support_type = $info['type'] == 'modules' ? 'account' : $info['type'];
  88. $group['modules_all'][$modulename]['group_support'][] = $support_type;
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. if (in_array($do, array('save', 'delete', 'post'))) {
  96. $id = intval($_GPC['id']);
  97. if (empty($id) && $do == 'delete') {
  98. itoast('请选择要操作的权限组', referer(), 'error');
  99. }
  100. if (!empty($id) && $_W['highest_role'] == ACCOUNT_MANAGE_NAME_VICE_FOUNDER) {
  101. $exists = table('users_founder_own_uni_groups')->getByFounderUidAndUniGroupId($_W['uid'], $id);
  102. if (empty($exists)) {
  103. itoast('无权限操作!', referer(), 'error');
  104. }
  105. }
  106. }
  107. if ($do == 'save') {
  108. $account_all_type = uni_account_type();
  109. $account_all_type_sign = array_keys(uni_account_type_sign());
  110. $modules = safe_gpc_array($_GPC['modules']);
  111. $package_info = array(
  112. 'id' => $id,
  113. 'name' => safe_gpc_string($_GPC['name']),
  114. 'modules' => array(),
  115. 'templates' => safe_gpc_array($_GPC['templates']),
  116. );
  117. foreach ($account_all_type_sign as $account_type) {
  118. if ($account_type == 'account') {
  119. $package_info['modules']['modules'] = empty($modules[$account_type]) ? array() : $modules[$account_type];
  120. } else {
  121. $package_info['modules'][$account_type] = empty($modules[$account_type]) ? array() : $modules[$account_type];
  122. }
  123. }
  124. $package_info = module_save_group_package($package_info);
  125. if (is_error($package_info)) {
  126. iajax(1, $package_info['message'], '');
  127. }
  128. iajax(0, ($id ? '更新成功' : '添加成功'), url('module/group'));
  129. }
  130. if ($do == 'delete') {
  131. if (!empty($id)) {
  132. pdo_delete('uni_group', array('id' => $id));
  133. pdo_delete('users_founder_own_uni_groups', array('uni_group_id' => $id));
  134. cache_build_uni_group();
  135. cache_build_account_modules();
  136. }
  137. itoast('删除成功!', referer(), 'success');
  138. }
  139. if ($do == 'post') {
  140. $group_id = $id;
  141. if (!empty($group_id)) {
  142. $group = table('uni_group')->getById($group_id);
  143. }
  144. $module_support_type = module_support_type();
  145. $module_list = array(
  146. 'modules' => array(),
  147. 'templates' => array(),
  148. );
  149. $user_modules = user_modules($_W['uid']);
  150. foreach($user_modules as $name => $module) {
  151. if (!empty($module['issystem'])) {
  152. continue;
  153. }
  154. foreach ($module_support_type as $support => $info) {
  155. if ($support == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
  156. continue;
  157. }
  158. $info['type'] = $info['type'] == 'account' ? 'modules' : $info['type'];
  159. if ($module[$support] == $info['support']) {
  160. $module_list['modules'][] = array(
  161. 'id' => $module['mid'],
  162. 'name' => $module['name'],
  163. 'title' => $module['title'],
  164. 'logo' => $module['logo'],
  165. 'support' => $support,
  166. 'checked' => !empty($group['modules'][$info['type']]) && in_array($module['name'], $group['modules'][$info['type']]) ? 1 : 0,
  167. );
  168. }
  169. }
  170. }
  171. if (user_is_vice_founder($_W['uid'])) {
  172. $template_list = user_founder_templates($_W['user']['groupid']);
  173. } else {
  174. $template_list = pdo_getall('site_templates');
  175. }
  176. foreach ($template_list as $temp) {
  177. $module_list['templates'][] = array(
  178. 'id' => $temp['id'],
  179. 'name' => $temp['name'],
  180. 'title' => $temp['title'],
  181. 'logo' => $_W['siteroot'] . "app/themes/{$temp['name']}/preview.jpg",
  182. 'support' => '',
  183. 'checked' => !empty($group['templates']) && is_array($group['templates']) && in_array($temp['id'], $group['templates']) ? 1 : 0,
  184. );
  185. }
  186. }
  187. template('module/group');