1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package groups
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright Ryan Djurovich
|
8
|
* @copyright WebsiteBaker Org. e.V.
|
9
|
* @link http://websitebaker.org/
|
10
|
* @license http://www.gnu.org/licenses/gpl.html
|
11
|
* @platform WebsiteBaker 2.8.3
|
12
|
* @requirements PHP 5.3.6 and higher
|
13
|
* @version $Id: groups.php 2 2017-07-02 15:14:29Z Manuela $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/admin/groups/groups.php $
|
15
|
* @lastmodified $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
|
16
|
*
|
17
|
*/
|
18
|
/*---------------------------------------------------------------------------------------------------------*/
|
19
|
// Include config file and admin class file
|
20
|
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
|
21
|
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
|
22
|
// Set parameter 'action' as alternative to javascript mechanism
|
23
|
$js_back = ADMIN_URL.'/groups/index.php';
|
24
|
$requestMethod = '_'.($GLOBALS['_SERVER']['REQUEST_METHOD']);
|
25
|
$aRequestVars = (@(${$requestMethod}) ? : null);
|
26
|
|
27
|
$bAdvanced = intval (@$aRequestVars['advanced'] ?: 0);
|
28
|
$bAdvancedSave = intval(@$aRequestVars['advanced_exented'] ?: 0);
|
29
|
$sDefaultModules = array();
|
30
|
$sDefaultTemplates = array();
|
31
|
|
32
|
$action = 'cancel';
|
33
|
// Set parameter 'action' as alternative to javascript mechanism
|
34
|
$action = (isset($aRequestVars['action']) && ($aRequestVars['action'] ='modify') ? 'modify' : $action );
|
35
|
$action = (isset($aRequestVars['modify']) ? 'modify' : $action );
|
36
|
$action = (isset($aRequestVars['delete']) ? 'delete' : $action );
|
37
|
/*-------------------------------------------------------------------------------------------------------*/
|
38
|
switch ($action):
|
39
|
case 'cancel' :
|
40
|
header('HTTP/1.1 301 Moved Permanently');
|
41
|
header('Location: '.$js_back);
|
42
|
exit;
|
43
|
case 'modify' :
|
44
|
// Create new admin object
|
45
|
$admin = new admin('Access', 'groups_modify' );
|
46
|
// Check if group group_id is a valid number and doesnt equal 1
|
47
|
$group_id = intval($admin->checkIDKEY('group_id', false, $_SERVER['REQUEST_METHOD']));
|
48
|
if($group_id === false){
|
49
|
$admin->print_error($MESSAGE['USERS_NO_GROUP'], $js_back);
|
50
|
}
|
51
|
if( ($group_id < 2 ) )
|
52
|
{
|
53
|
// if($admin_header) { $admin->print_header(); }
|
54
|
$sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION).'_'.$group_id.'_::');
|
55
|
$sDEBUG=(@DEBUG?$sInfo:'');
|
56
|
$admin->print_error($sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
|
57
|
}
|
58
|
// Get existing values
|
59
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'groups` '
|
60
|
. 'WHERE `group_id` = '.$group_id;
|
61
|
$results = $database->query($sql);
|
62
|
$group = $results->fetchRow(MYSQLI_ASSOC);
|
63
|
// Setup template object, parse vars to it, then parse it
|
64
|
// Create new template object
|
65
|
$template = new Template(dirname($admin->correct_theme_source('groups_form.htt')), 'remove');
|
66
|
// $template->debug = true;
|
67
|
//$template->set_unknowns('keep');
|
68
|
$template->set_file('page', 'groups_form.htt');
|
69
|
$template->set_block('page', 'main_block', 'main');
|
70
|
$template->set_var(array(
|
71
|
'ADMIN_URL' => ADMIN_URL,
|
72
|
'WB_URL' => WB_URL,
|
73
|
'THEME_URL' => THEME_URL,
|
74
|
'ACTION_URL' => ADMIN_URL.'/groups/save.php',
|
75
|
'SUBMIT_TITLE' => $TEXT['SAVE'],
|
76
|
'GROUP_ID' => $admin->getIDKEY($group['group_id']),
|
77
|
'GROUP_NAME' => $group['name'],
|
78
|
'ADVANCED_LINK' => ADMIN_URL.'/groups/groups.php',
|
79
|
'CANCEL_LINK' => ADMIN_URL.'/groups/index.php',
|
80
|
'FTAN' => $admin->getFTAN(),
|
81
|
));
|
82
|
// Tell the browser whether or not to show advanced options
|
83
|
$template->set_block('main_block', 'groups_basic_block', 'groups_basic');
|
84
|
$template->set_block('main_block', 'groups_extended_block', 'groups_extended');
|
85
|
// Explode system permissions
|
86
|
if ($group['system_permissions']) {
|
87
|
$system_permissions = explode(',', $group['system_permissions']);
|
88
|
// Check system permissions boxes
|
89
|
foreach($system_permissions as $name) {
|
90
|
// echo (@DEBUG?$name.'_checked':'');
|
91
|
// $template->set_var($name.'_checked', '');
|
92
|
$template->set_var($name.'_checked', ($admin->get_permission($name) ?' checked="checked"':''));
|
93
|
}
|
94
|
}
|
95
|
if($bAdvanced)
|
96
|
{
|
97
|
$template->set_var('DISPLAY_ADVANCED', '');
|
98
|
$template->set_var('DISPLAY_BASIC', 'display:none;');
|
99
|
$template->set_var('ADVANCED_VALUE', 0);
|
100
|
$template->set_var('ADVANCED_BUTTON', '« '.$TEXT['HIDE_ADVANCED']);
|
101
|
$template->parse('groups_extended', 'groups_extended_block', true);
|
102
|
$template->set_block('groups_basic', '', '');
|
103
|
} else {
|
104
|
$template->set_var('DISPLAY_ADVANCED', 'display:none;');
|
105
|
$template->set_var('DISPLAY_BASIC', '');
|
106
|
$template->set_var('ADVANCED_VALUE', 1);
|
107
|
$template->set_var('ADVANCED_BUTTON', $TEXT['SHOW_ADVANCED'].' »');
|
108
|
$template->parse('groups_basic', 'groups_basic_block', true);
|
109
|
$template->set_block('groups_extended', '');
|
110
|
}
|
111
|
// Explode module permissions
|
112
|
$module_permissions = explode(',', $group['module_permissions']);
|
113
|
$module_permissions = array_diff($module_permissions, $sDefaultModules);
|
114
|
// Explode template permissions
|
115
|
$template_permissions = explode(',', $group['template_permissions']);
|
116
|
$template_permissions = array_diff($template_permissions, $sDefaultTemplates);
|
117
|
/*-------------------------------------------------------------------------------------------------------*/
|
118
|
// Insert values into module list
|
119
|
$template->set_block('main_block', 'module_list_block', 'module_list');
|
120
|
$template->set_block('main_block', 'module_group_block', 'module_group');
|
121
|
$aTmp = [];
|
122
|
$aCheckedList = array();
|
123
|
$GroupsFunction = '';
|
124
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
|
125
|
. 'WHERE `type` = \'module\' '
|
126
|
. 'AND `function` IN (\'page\', \'tool\') '
|
127
|
. 'ORDER BY `function`, `name`';
|
128
|
if($result = $database->query($sql))
|
129
|
{
|
130
|
$i=0;
|
131
|
while($addon = $result->fetchRow(MYSQLI_ASSOC)) {
|
132
|
$template->set_var('OPTGROUP', '');
|
133
|
$template->set_block('module_function', '');
|
134
|
if (!is_readable(WB_PATH.'/modules/'.$addon['directory'])){
|
135
|
$aTmp[] = $addon['directory'];
|
136
|
continue;
|
137
|
}
|
138
|
if (strcasecmp($addon['function'], $GroupsFunction)!== 0){
|
139
|
$template->set_var('OPTGROUP', ucwords($addon['function']));
|
140
|
$template->parse('module_group', 'module_group_block', true);
|
141
|
}
|
142
|
$template->set_var('VALUE', $addon['directory']);
|
143
|
$template->set_var('NAME', (($addon['function'] == 'page') ? $addon['name'] :''.$addon['name']));
|
144
|
if (!is_numeric(array_search($addon['directory'], $module_permissions)) )
|
145
|
{
|
146
|
$template->set_var('CHECKED', ' checked="checked"');
|
147
|
$aCheckedList[$i]['directory'] = $addon['directory'];
|
148
|
$aCheckedList[$i]['name'] = $addon['name'];
|
149
|
++$i;
|
150
|
} else {
|
151
|
$template->set_var('CHECKED', '');
|
152
|
}
|
153
|
$GroupsFunction = $addon['function'];
|
154
|
$template->parse('module_list', 'module_list_block', true);
|
155
|
}
|
156
|
}
|
157
|
/*-------------------------------------------------------------------------------------------------------*/
|
158
|
// Insert values into template list
|
159
|
$template->set_block('main_block', 'template_list_block', 'template_list');
|
160
|
$template->set_block('main_block', 'template_group_block', 'template_group');
|
161
|
$aTmp = [];
|
162
|
$aCheckedList = array();
|
163
|
$GroupsFunction = '';
|
164
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` '
|
165
|
. 'WHERE `type` = \'template\' '
|
166
|
. 'ORDER BY `function`, `name`';
|
167
|
if($result = $database->query($sql))
|
168
|
{
|
169
|
$i=0;
|
170
|
while( $addon = $result->fetchRow(MYSQLI_ASSOC)) {
|
171
|
$template->set_var('OPTGROUP', '');
|
172
|
$template->set_block('template_function', '');
|
173
|
if (!is_readable(WB_PATH.'/templates/'.$addon['directory'])){
|
174
|
$aTmp[] = $addon['directory'];
|
175
|
continue;
|
176
|
}
|
177
|
if (strcasecmp($addon['function'], $GroupsFunction)!== 0){
|
178
|
$template->set_var('OPTGROUP', ucwords($addon['function']));
|
179
|
$template->parse('template_group', 'template_group_block', true);
|
180
|
}
|
181
|
$template->set_var('VALUE', $addon['directory']);
|
182
|
$template->set_var('NAME', $addon['name'] );
|
183
|
if(!is_numeric(array_search($addon['directory'], $template_permissions)))
|
184
|
{
|
185
|
$template->set_var('CHECKED', ' checked="checked"');
|
186
|
$aCheckedList[$i]['directory'] = $addon['directory'];
|
187
|
$aCheckedList[$i]['name'] = $addon['name'];
|
188
|
++$i;
|
189
|
} else {
|
190
|
$template->set_var('CHECKED', '');
|
191
|
}
|
192
|
$GroupsFunction = $addon['function'];
|
193
|
$template->parse('template_list', 'template_list_block', true);
|
194
|
}
|
195
|
}
|
196
|
/*-------------------------------------------------------------------------------------------------------*/
|
197
|
// Insert language text and messages
|
198
|
$template->set_var(array(
|
199
|
'TEXT_CANCEL' => $TEXT['CANCEL'],
|
200
|
'TEXT_RESET' => $TEXT['RESET'],
|
201
|
'TEXT_FILESYSTEM_PERMISSIONS' => $TEXT['FILESYSTEM_PERMISSIONS'],
|
202
|
'TEXT_ACTIVE' => $TEXT['ACTIVE'],
|
203
|
'TEXT_DISABLED' => $TEXT['DISABLED'],
|
204
|
'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
|
205
|
'TEXT_USERNAME' => $TEXT['USERNAME'],
|
206
|
'TEXT_PASSWORD' => $TEXT['PASSWORD'],
|
207
|
'TEXT_RETYPE_PASSWORD' => $TEXT['RETYPE_PASSWORD'],
|
208
|
'TEXT_DISPLAY_NAME' => $TEXT['DISPLAY_NAME'],
|
209
|
'TEXT_EMAIL' => $TEXT['EMAIL'],
|
210
|
'TEXT_GROUP' => $TEXT['GROUP'],
|
211
|
'TEXT_GROUPS' => $MENU['GROUPS'],
|
212
|
'TEXT_SYSTEM_PERMISSIONS' => $TEXT['SYSTEM_PERMISSIONS'],
|
213
|
'TEXT_MODULE_PERMISSIONS' => $TEXT['MODULE_PERMISSIONS'],
|
214
|
'TEXT_TEMPLATE_PERMISSIONS' => $TEXT['TEMPLATE_PERMISSIONS'],
|
215
|
'TEXT_NAME' => $TEXT['NAME'],
|
216
|
'SECTION_PAGES' => $MENU['PAGES'],
|
217
|
'SECTION_MEDIA' => $MENU['MEDIA'],
|
218
|
'SECTION_MODULES' => $MENU['MODULES'],
|
219
|
'SECTION_TEMPLATES' => $MENU['TEMPLATES'],
|
220
|
'SECTION_LANGUAGES' => $MENU['LANGUAGES'],
|
221
|
'SECTION_SETTINGS' => $MENU['SETTINGS'],
|
222
|
'SECTION_USERS' => $MENU['USERS'],
|
223
|
'SECTION_GROUPS' => $MENU['GROUPS'],
|
224
|
'SECTION_ADMINTOOLS' => $MENU['ADMINTOOLS'],
|
225
|
'TEXT_VIEW' => $TEXT['VIEW'],
|
226
|
'TEXT_ADD' => $TEXT['ADD'],
|
227
|
'TEXT_LEVEL' => $TEXT['LEVEL'],
|
228
|
'TEXT_MODIFY' => $TEXT['MODIFY'],
|
229
|
'TEXT_DELETE' => $TEXT['DELETE'],
|
230
|
'TEXT_MODIFY_CONTENT' => $TEXT['MODIFY_CONTENT'],
|
231
|
'TEXT_MODIFY_SETTINGS' => $TEXT['MODIFY_SETTINGS'],
|
232
|
'HEADING_MODIFY_INTRO_PAGE' => $TEXT['INTRO_PAGE'],
|
233
|
'TEXT_CREATE_FOLDER' => $TEXT['CREATE_FOLDER'],
|
234
|
'TEXT_RENAME' => $TEXT['RENAME'],
|
235
|
'TEXT_UPLOAD_FILES' => $TEXT['UPLOAD_FILES'],
|
236
|
'TEXT_BASIC' => $TEXT['BASIC'],
|
237
|
'TEXT_ADVANCED' => $TEXT['ADVANCED'],
|
238
|
'CHANGING_PASSWORD' => $MESSAGE['USERS_CHANGING_PASSWORD'],
|
239
|
'DISPLAY_EXTRA' => 'display:block;',
|
240
|
'HEADING_MODIFY_GROUP' => $HEADING['MODIFY_GROUP'],
|
241
|
'DEBUG_MSG'=>(@$DebugOLutput?:'')
|
242
|
));
|
243
|
/*-------------------------------------------------------------------------------------------------------*/
|
244
|
// Parse template object
|
245
|
$template->parse('main', 'main_block', false);
|
246
|
$template->pparse('output', 'page');
|
247
|
// Print admin footer
|
248
|
$admin->print_footer();
|
249
|
break;
|
250
|
case 'delete' :
|
251
|
// Create new admin object
|
252
|
$admin = new admin('Access', 'groups_delete', false);
|
253
|
$group_id = intval($admin->checkIDKEY('group_id', false, $_SERVER['REQUEST_METHOD']));
|
254
|
if($group_id === false){
|
255
|
$admin->print_header();
|
256
|
$admin->print_error($MESSAGE['USERS_NO_GROUP'], $js_back); // GENERIC_CANNOT_UNINSTALL
|
257
|
}
|
258
|
// Check if user id is a valid number and doesnt equal 1
|
259
|
if( ($group_id < 2 ) )
|
260
|
{
|
261
|
$admin->print_header();
|
262
|
$sInfo = strtoupper(basename(__DIR__).'_'.basename(__FILE__, ''.PAGE_EXTENSION).'_idkey::');
|
263
|
$sDEBUG=(@DEBUG?$sInfo:'');
|
264
|
$admin->print_error($sDEBUG.$MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
|
265
|
}
|
266
|
// Print header
|
267
|
$admin->print_header();
|
268
|
$sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'groups` '
|
269
|
.'WHERE `group_id`='.(int)$group_id.''
|
270
|
.'';
|
271
|
if ( ($group_name = $database->get_one($sql)) ) { }
|
272
|
$query = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` '
|
273
|
. 'WHERE `groups_id` like \'%'.$group_id.'%\'';
|
274
|
if ( $database->get_one($query) == 0 ) {
|
275
|
// Delete the group
|
276
|
$sql = 'DELETE FROM `'.TABLE_PREFIX.'groups` '
|
277
|
.'WHERE `group_id`='.(int)$group_id.''
|
278
|
.'';
|
279
|
$database->query($sql);
|
280
|
if($database->is_error()) {
|
281
|
$admin->print_error($database->get_error());
|
282
|
} else {
|
283
|
$admin->print_success($MESSAGE['GROUPS_DELETED'], $js_back);
|
284
|
}
|
285
|
} else {
|
286
|
$admin->print_error('('.$TEXT['GROUP'].' '.$group_name.') '.$MESSAGE['GENERIC_CANNOT_UNINSTALL'], $js_back);
|
287
|
}
|
288
|
$admin->print_footer();
|
289
|
break;
|
290
|
default:
|
291
|
break;
|
292
|
endswitch;
|