123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- /**
- * [WeEngine System] Copyright (c) 2014 WE7.CC
- * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
- */
- defined('IN_IA') or exit('Access Denied');
- load()->model('module');
- load()->model('user');
- load()->model('module');
- $dos = array('display', 'delete', 'post', 'save', 'edit');
- $do = !empty($_GPC['do']) ? $_GPC['do'] : 'display';
- if (!in_array($_W['highest_role'], array(ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER))){
- itoast('无权限操作!', referer(), 'error');
- }
- if ($do == 'display') {
- $pageindex = max(1, intval($_GPC['page']));
- $pagesize = 10;
- $uni_group_table = table('uni_group');
- $uni_group_table->searchWithUniacidAndUid();
- $name = safe_gpc_string($_GPC['name']);
- if (!empty($name)) {
- $uni_group_table->searchWithName($name);
- }
- if (user_is_vice_founder($_W['uid'])) {
- $uni_group_table->searchWithFounderUid($_W['uid']);
- }
- $uni_group_table->searchWithPage($pageindex, $pagesize);
- $modules_group_list = $uni_group_table->getUniGroupList();
- $total = $uni_group_table->getLastQueryTotal();
- $pager = pagination($total, $pageindex, $pagesize);
- $module_support_type = module_support_type();
- if (!empty($modules_group_list)) {
- $all_module_names = array();
- foreach ($modules_group_list as $key => $value) {
- $value['modules'] = iunserializer($value['modules']);
- if (!is_array($value['modules'])) {
- $value['modules'] = array();
- }
- $modules_group_list[$key]['modules'] = $value['modules'];
- foreach ($value['modules'] as $type => $modulenames) {
- if (empty($modulenames) || !is_array($modulenames)) {
- $modules_group_list[$key][$type . '_num'] = 0;
- continue;
- } else {
- $type = $type == 'modules' ? 'account' : $type;
- $modules_group_list[$key][$type . '_num'] = count($modulenames);
- }
- $all_module_names = array_merge($all_module_names, $modulenames);
- }
- }
- $all_modules = table('modules')->searchWithName(array_unique($all_module_names))->getall('name');
- foreach ($modules_group_list as &$group) {
- if (empty($group['modules'])) {
- continue;
- }
- $template_ids = iunserializer($group['templates']);
- $group['templates'] = array();
- if (is_array($template_ids)) {
- $templates = table('site_templates')->searchWithId($template_ids)->getAll();
- if (is_array($templates)) {
- foreach ($templates as $k => $temp) {
- $temp['logo'] = $_W['siteroot'] . "app/themes/{$temp['name']}/preview.jpg";
- $group['templates'][$k] = $temp;
- }
- }
- }
- $group['modules_all'] = array();
- foreach ($module_support_type as $support => $info) {
- if ($support == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
- continue;
- }
- if ($support == MODULE_SUPPORT_ACCOUNT_NAME) {
- $info['type'] = 'modules';
- }
- if (empty($group['modules'][$info['type']])) {
- continue;
- }
- foreach ($group['modules'][$info['type']] as $modulename) {
- if (empty($all_modules[$modulename])) {
- continue;
- }
- if (empty($group['modules_all'][$modulename])) {
- $all_modules[$modulename]['logo'] = tomedia($all_modules[$modulename]['logo']);
- $group['modules_all'][$modulename] = $all_modules[$modulename];
- }
- if ($all_modules[$modulename][$support] == $info['support']) {
- $support_type = $info['type'] == 'modules' ? 'account' : $info['type'];
- $group['modules_all'][$modulename]['group_support'][] = $support_type;
- }
- }
- }
- }
- }
- }
- if (in_array($do, array('save', 'delete', 'post'))) {
- $id = intval($_GPC['id']);
- if (empty($id) && $do == 'delete') {
- itoast('请选择要操作的权限组', referer(), 'error');
- }
- if (!empty($id) && $_W['highest_role'] == ACCOUNT_MANAGE_NAME_VICE_FOUNDER) {
- $exists = table('users_founder_own_uni_groups')->getByFounderUidAndUniGroupId($_W['uid'], $id);
- if (empty($exists)) {
- itoast('无权限操作!', referer(), 'error');
- }
- }
- }
- if ($do == 'save') {
- $account_all_type = uni_account_type();
- $account_all_type_sign = array_keys(uni_account_type_sign());
- $modules = safe_gpc_array($_GPC['modules']);
- $package_info = array(
- 'id' => $id,
- 'name' => safe_gpc_string($_GPC['name']),
- 'modules' => array(),
- 'templates' => safe_gpc_array($_GPC['templates']),
- );
- foreach ($account_all_type_sign as $account_type) {
- if ($account_type == 'account') {
- $package_info['modules']['modules'] = empty($modules[$account_type]) ? array() : $modules[$account_type];
- } else {
- $package_info['modules'][$account_type] = empty($modules[$account_type]) ? array() : $modules[$account_type];
- }
- }
- $package_info = module_save_group_package($package_info);
- if (is_error($package_info)) {
- iajax(1, $package_info['message'], '');
- }
- iajax(0, ($id ? '更新成功' : '添加成功'), url('module/group'));
- }
- if ($do == 'delete') {
- if (!empty($id)) {
- pdo_delete('uni_group', array('id' => $id));
- pdo_delete('users_founder_own_uni_groups', array('uni_group_id' => $id));
- cache_build_uni_group();
- cache_build_account_modules();
- }
- itoast('删除成功!', referer(), 'success');
- }
- if ($do == 'post') {
- $group_id = $id;
- if (!empty($group_id)) {
- $group = table('uni_group')->getById($group_id);
- }
- $module_support_type = module_support_type();
- $module_list = array(
- 'modules' => array(),
- 'templates' => array(),
- );
- $user_modules = user_modules($_W['uid']);
- foreach($user_modules as $name => $module) {
- if (!empty($module['issystem'])) {
- continue;
- }
- foreach ($module_support_type as $support => $info) {
- if ($support == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
- continue;
- }
- $info['type'] = $info['type'] == 'account' ? 'modules' : $info['type'];
- if ($module[$support] == $info['support']) {
- $module_list['modules'][] = array(
- 'id' => $module['mid'],
- 'name' => $module['name'],
- 'title' => $module['title'],
- 'logo' => $module['logo'],
- 'support' => $support,
- 'checked' => !empty($group['modules'][$info['type']]) && in_array($module['name'], $group['modules'][$info['type']]) ? 1 : 0,
- );
- }
- }
- }
-
- if (user_is_vice_founder($_W['uid'])) {
- $template_list = user_founder_templates($_W['user']['groupid']);
- } else {
- $template_list = pdo_getall('site_templates');
- }
-
-
- foreach ($template_list as $temp) {
- $module_list['templates'][] = array(
- 'id' => $temp['id'],
- 'name' => $temp['name'],
- 'title' => $temp['title'],
- 'logo' => $_W['siteroot'] . "app/themes/{$temp['name']}/preview.jpg",
- 'support' => '',
- 'checked' => !empty($group['templates']) && is_array($group['templates']) && in_array($temp['id'], $group['templates']) ? 1 : 0,
- );
- }
- }
- template('module/group');
|