Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 691 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
acp_groups | |
0.00% |
0 / 689 |
|
0.00% |
0 / 2 |
35156 | |
0.00% |
0 / 1 |
main | |
0.00% |
0 / 558 |
|
0.00% |
0 / 1 |
23256 | |||
manage_position | |
0.00% |
0 / 131 |
|
0.00% |
0 / 1 |
1260 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | /** |
15 | * @ignore |
16 | */ |
17 | if (!defined('IN_PHPBB')) |
18 | { |
19 | exit; |
20 | } |
21 | |
22 | class acp_groups |
23 | { |
24 | var $u_action; |
25 | |
26 | function main($id, $mode) |
27 | { |
28 | global $config, $db, $user, $auth, $template, $cache; |
29 | global $phpbb_root_path, $phpbb_admin_path, $phpEx; |
30 | global $request, $phpbb_container, $phpbb_dispatcher; |
31 | |
32 | /** @var \phpbb\language\language $language Language object */ |
33 | $language = $phpbb_container->get('language'); |
34 | |
35 | $user->add_lang('acp/groups'); |
36 | $this->tpl_name = 'acp_groups'; |
37 | $this->page_title = 'ACP_GROUPS_MANAGE'; |
38 | |
39 | $form_key = 'acp_groups'; |
40 | add_form_key($form_key); |
41 | |
42 | if ($mode == 'position') |
43 | { |
44 | $this->manage_position(); |
45 | return; |
46 | } |
47 | |
48 | if (!function_exists('group_user_attributes')) |
49 | { |
50 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
51 | } |
52 | |
53 | // Check and set some common vars |
54 | $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addusers'])) ? 'addusers' : $request->variable('action', '')); |
55 | $group_id = $request->variable('g', 0); |
56 | $mark_ary = $request->variable('mark', array(0)); |
57 | $name_ary = $request->variable('usernames', '', true); |
58 | $leader = $request->variable('leader', 0); |
59 | $default = $request->variable('default', 0); |
60 | $start = $request->variable('start', 0); |
61 | $update = (isset($_POST['update'])) ? true : false; |
62 | |
63 | /** @var \phpbb\group\helper $group_helper */ |
64 | $group_helper = $phpbb_container->get('group_helper'); |
65 | |
66 | // Clear some vars |
67 | $group_row = array(); |
68 | |
69 | // Grab basic data for group, if group_id is set and exists |
70 | if ($group_id) |
71 | { |
72 | $sql = 'SELECT g.*, t.teampage_position AS group_teampage |
73 | FROM ' . GROUPS_TABLE . ' g |
74 | LEFT JOIN ' . TEAMPAGE_TABLE . ' t |
75 | ON (t.group_id = g.group_id) |
76 | WHERE g.group_id = ' . $group_id; |
77 | $result = $db->sql_query($sql); |
78 | $group_row = $db->sql_fetchrow($result); |
79 | $db->sql_freeresult($result); |
80 | |
81 | if (!$group_row) |
82 | { |
83 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
84 | } |
85 | |
86 | // Check if the user is allowed to manage this group if set to founder only. |
87 | if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) |
88 | { |
89 | trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
90 | } |
91 | } |
92 | |
93 | // Which page? |
94 | switch ($action) |
95 | { |
96 | case 'approve': |
97 | case 'demote': |
98 | case 'promote': |
99 | if (!check_form_key($form_key)) |
100 | { |
101 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); |
102 | } |
103 | |
104 | if (!$group_id) |
105 | { |
106 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
107 | } |
108 | |
109 | // Approve, demote or promote |
110 | $group_name = $group_helper->get_name($group_row['group_name']); |
111 | $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name); |
112 | |
113 | if (!$error) |
114 | { |
115 | switch ($action) |
116 | { |
117 | case 'demote': |
118 | $message = 'GROUP_MODS_DEMOTED'; |
119 | break; |
120 | |
121 | case 'promote': |
122 | $message = 'GROUP_MODS_PROMOTED'; |
123 | break; |
124 | |
125 | case 'approve': |
126 | $message = 'USERS_APPROVED'; |
127 | break; |
128 | } |
129 | |
130 | trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); |
131 | } |
132 | else |
133 | { |
134 | trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); |
135 | } |
136 | |
137 | break; |
138 | |
139 | case 'default': |
140 | if (!$group_id) |
141 | { |
142 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
143 | } |
144 | else if (empty($mark_ary)) |
145 | { |
146 | trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); |
147 | } |
148 | |
149 | if (confirm_box(true)) |
150 | { |
151 | $group_name = $group_helper->get_name($group_row['group_name']); |
152 | group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); |
153 | trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); |
154 | } |
155 | else |
156 | { |
157 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
158 | 'mark' => $mark_ary, |
159 | 'g' => $group_id, |
160 | 'i' => $id, |
161 | 'mode' => $mode, |
162 | 'action' => $action)) |
163 | ); |
164 | } |
165 | break; |
166 | |
167 | case 'set_default_on_all': |
168 | if (confirm_box(true)) |
169 | { |
170 | $group_name = $group_helper->get_name($group_row['group_name']); |
171 | |
172 | $start = 0; |
173 | |
174 | do |
175 | { |
176 | $sql = 'SELECT user_id |
177 | FROM ' . USER_GROUP_TABLE . " |
178 | WHERE group_id = $group_id |
179 | ORDER BY user_id"; |
180 | $result = $db->sql_query_limit($sql, 200, $start); |
181 | |
182 | $mark_ary = array(); |
183 | if ($row = $db->sql_fetchrow($result)) |
184 | { |
185 | do |
186 | { |
187 | $mark_ary[] = $row['user_id']; |
188 | } |
189 | while ($row = $db->sql_fetchrow($result)); |
190 | |
191 | group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); |
192 | |
193 | $start = (count($mark_ary) < 200) ? 0 : $start + 200; |
194 | } |
195 | else |
196 | { |
197 | $start = 0; |
198 | } |
199 | $db->sql_freeresult($result); |
200 | } |
201 | while ($start); |
202 | |
203 | trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); |
204 | } |
205 | else |
206 | { |
207 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
208 | 'mark' => $mark_ary, |
209 | 'g' => $group_id, |
210 | 'i' => $id, |
211 | 'mode' => $mode, |
212 | 'action' => $action)) |
213 | ); |
214 | } |
215 | break; |
216 | |
217 | case 'deleteusers': |
218 | if (empty($mark_ary)) |
219 | { |
220 | trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); |
221 | } |
222 | case 'delete': |
223 | if (!$group_id) |
224 | { |
225 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
226 | } |
227 | else if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL) |
228 | { |
229 | send_status_line(403, 'Forbidden'); |
230 | trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); |
231 | } |
232 | |
233 | if (confirm_box(true)) |
234 | { |
235 | $error = ''; |
236 | |
237 | switch ($action) |
238 | { |
239 | case 'delete': |
240 | if (!$auth->acl_get('a_groupdel')) |
241 | { |
242 | send_status_line(403, 'Forbidden'); |
243 | trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); |
244 | } |
245 | |
246 | $error = group_delete($group_id, $group_row['group_name']); |
247 | break; |
248 | |
249 | case 'deleteusers': |
250 | $group_name = $group_helper->get_name($group_row['group_name']); |
251 | $error = group_user_del($group_id, $mark_ary, false, $group_name); |
252 | break; |
253 | } |
254 | |
255 | $back_link = ($action == 'delete') ? $this->u_action : $this->u_action . '&action=list&g=' . $group_id; |
256 | |
257 | if ($error) |
258 | { |
259 | trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING); |
260 | } |
261 | |
262 | $message = ($action == 'delete') ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE'; |
263 | trigger_error($user->lang[$message] . adm_back_link($back_link)); |
264 | } |
265 | else |
266 | { |
267 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
268 | 'mark' => $mark_ary, |
269 | 'g' => $group_id, |
270 | 'i' => $id, |
271 | 'mode' => $mode, |
272 | 'action' => $action)) |
273 | ); |
274 | } |
275 | break; |
276 | |
277 | case 'addusers': |
278 | if (!check_form_key($form_key)) |
279 | { |
280 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); |
281 | } |
282 | |
283 | if (!$group_id) |
284 | { |
285 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
286 | } |
287 | |
288 | if (!$name_ary) |
289 | { |
290 | trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); |
291 | } |
292 | |
293 | $name_ary = array_unique(explode("\n", $name_ary)); |
294 | $group_name = $group_helper->get_name($group_row['group_name']); |
295 | |
296 | // Add user/s to group |
297 | if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row)) |
298 | { |
299 | $display_message = $language->lang($error); |
300 | |
301 | if ($error == 'GROUP_USERS_INVALID') |
302 | { |
303 | // Find which users don't exist |
304 | $actual_name_ary = $name_ary; |
305 | $actual_user_id_ary = []; |
306 | user_get_id_name($actual_user_id_ary, $actual_name_ary, false, true); |
307 | |
308 | $display_message = $language->lang('GROUP_USERS_INVALID', implode($language->lang('COMMA_SEPARATOR'), array_udiff($name_ary, $actual_name_ary, 'strcasecmp'))); |
309 | } |
310 | |
311 | trigger_error($display_message . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); |
312 | } |
313 | |
314 | $message = ($leader) ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; |
315 | trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); |
316 | break; |
317 | |
318 | case 'edit': |
319 | case 'add': |
320 | |
321 | if (!function_exists('display_forums')) |
322 | { |
323 | include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
324 | } |
325 | |
326 | if ($action == 'edit' && !$group_id) |
327 | { |
328 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
329 | } |
330 | |
331 | if ($action == 'add' && !$auth->acl_get('a_groupadd')) |
332 | { |
333 | send_status_line(403, 'Forbidden'); |
334 | trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); |
335 | } |
336 | |
337 | $error = array(); |
338 | $user->add_lang('ucp'); |
339 | |
340 | // Setup avatar data for later |
341 | $avatars_enabled = false; |
342 | $avatar_drivers = null; |
343 | $avatar_data = null; |
344 | $avatar_error = array(); |
345 | |
346 | /** @var \phpbb\avatar\manager $phpbb_avatar_manager */ |
347 | $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); |
348 | |
349 | if ($config['allow_avatar']) |
350 | { |
351 | $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); |
352 | |
353 | // This is normalised data, without the group_ prefix |
354 | $avatar_data = \phpbb\avatar\manager::clean_row($group_row, 'group'); |
355 | if (!isset($avatar_data['id'])) |
356 | { |
357 | $avatar_data['id'] = 'g' . $group_id; |
358 | } |
359 | } |
360 | |
361 | if ($request->is_set_post('avatar_delete')) |
362 | { |
363 | if (confirm_box(true)) |
364 | { |
365 | $avatar_data['id'] = substr($avatar_data['id'], 1); |
366 | $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, GROUPS_TABLE, 'group_'); |
367 | |
368 | $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED'; |
369 | trigger_error($user->lang[$message] . adm_back_link($this->u_action)); |
370 | } |
371 | else |
372 | { |
373 | confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array( |
374 | 'avatar_delete' => true, |
375 | 'i' => $id, |
376 | 'mode' => $mode, |
377 | 'g' => $group_id, |
378 | 'action' => $action)) |
379 | ); |
380 | } |
381 | } |
382 | |
383 | // Did we submit? |
384 | if ($update) |
385 | { |
386 | if (!check_form_key($form_key)) |
387 | { |
388 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); |
389 | } |
390 | |
391 | $group_name = $request->variable('group_name', '', true); |
392 | $group_desc = $request->variable('group_desc', '', true); |
393 | $group_type = $request->variable('group_type', GROUP_FREE); |
394 | |
395 | $allow_desc_bbcode = $request->variable('desc_parse_bbcode', false); |
396 | $allow_desc_urls = $request->variable('desc_parse_urls', false); |
397 | $allow_desc_smilies = $request->variable('desc_parse_smilies', false); |
398 | |
399 | $submit_ary = [ |
400 | 'colour' => $request->variable('group_colour', ''), |
401 | 'rank' => $request->variable('group_rank', 0), |
402 | 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, |
403 | 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0, |
404 | 'teampage' => isset($_REQUEST['group_teampage']) ? 1 : 0, |
405 | 'message_limit' => $request->variable('group_message_limit', 0), |
406 | 'max_recipients' => $request->variable('group_max_recipients', 0), |
407 | 'founder_manage' => 0, |
408 | 'skip_auth' => $request->variable('group_skip_auth', 0), |
409 | |
410 | // Initialize avatar data |
411 | 'avatar' => $avatar_data['avatar'] ?? '', |
412 | 'avatar_type' => $avatar_data['avatar_type'] ?? '', |
413 | 'avatar_height' => $avatar_data['avatar_height'] ?? 0, |
414 | 'avatar_width' => $avatar_data['avatar_width'] ?? 0, |
415 | ]; |
416 | |
417 | if ($user->data['user_type'] == USER_FOUNDER) |
418 | { |
419 | $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; |
420 | } |
421 | |
422 | if ($config['allow_avatar']) |
423 | { |
424 | // Handle avatar |
425 | $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); |
426 | |
427 | if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) |
428 | { |
429 | $driver = $phpbb_avatar_manager->get_driver($driver_name); |
430 | $result = $driver->process_form($request, $template, $user, $avatar_data, $avatar_error); |
431 | |
432 | if ($result && empty($avatar_error)) |
433 | { |
434 | $result['avatar_type'] = $driver_name; |
435 | $submit_ary = array_merge($submit_ary, $result); |
436 | } |
437 | } |
438 | else |
439 | { |
440 | $driver = $phpbb_avatar_manager->get_driver($avatar_data['avatar_type']); |
441 | if ($driver) |
442 | { |
443 | $driver->delete($avatar_data); |
444 | } |
445 | |
446 | // Removing the avatar |
447 | $submit_ary['avatar_type'] = ''; |
448 | $submit_ary['avatar'] = ''; |
449 | $submit_ary['avatar_width'] = 0; |
450 | $submit_ary['avatar_height'] = 0; |
451 | } |
452 | |
453 | // Merge any avatar errors into the primary error array |
454 | $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); |
455 | } |
456 | |
457 | /* |
458 | * Validate the length of "Maximum number of allowed recipients per |
459 | * private message" setting. We use 16777215 as a maximum because it matches |
460 | * MySQL unsigned mediumint maximum value which is the lowest amongst DBMSes |
461 | * supported by phpBB3. Also validate the submitted colour value. |
462 | */ |
463 | $validation_checks = array( |
464 | 'max_recipients' => array('num', false, 0, 16777215), |
465 | 'colour' => array('hex_colour', true), |
466 | ); |
467 | |
468 | /** |
469 | * Request group data and operate on it |
470 | * |
471 | * @event core.acp_manage_group_request_data |
472 | * @var string action Type of the action: add|edit |
473 | * @var int group_id The group id |
474 | * @var array group_row Array with new group data |
475 | * @var array error Array of errors, if you add errors |
476 | * ensure to update the template variables |
477 | * S_ERROR and ERROR_MSG to display it |
478 | * @var string group_name The group name |
479 | * @var string group_desc The group description |
480 | * @var int group_type The group type |
481 | * @var bool allow_desc_bbcode Allow bbcode in group description: true|false |
482 | * @var bool allow_desc_urls Allow urls in group description: true|false |
483 | * @var bool allow_desc_smilies Allow smiles in group description: true|false |
484 | * @var array submit_ary Array with new group data |
485 | * @var array validation_checks Array with validation data |
486 | * @since 3.1.0-b5 |
487 | */ |
488 | $vars = array( |
489 | 'action', |
490 | 'group_id', |
491 | 'group_row', |
492 | 'error', |
493 | 'group_name', |
494 | 'group_desc', |
495 | 'group_type', |
496 | 'allow_desc_bbcode', |
497 | 'allow_desc_urls', |
498 | 'allow_desc_smilies', |
499 | 'submit_ary', |
500 | 'validation_checks', |
501 | ); |
502 | extract($phpbb_dispatcher->trigger_event('core.acp_manage_group_request_data', compact($vars))); |
503 | |
504 | if ($validation_error = validate_data($submit_ary, $validation_checks)) |
505 | { |
506 | // Replace "error" string with its real, localised form |
507 | $error = array_merge($error, $validation_error); |
508 | } |
509 | |
510 | if (!count($error)) |
511 | { |
512 | // Only set the rank, colour, etc. if it's changed or if we're adding a new |
513 | // group. This prevents existing group members being updated if no changes |
514 | // were made. |
515 | // However there are some attributes that need to be set everytime, |
516 | // otherwise the group gets removed from the feature. |
517 | $set_attributes = array('legend', 'teampage'); |
518 | |
519 | $group_attributes = array(); |
520 | $test_variables = array( |
521 | 'rank' => 'int', |
522 | 'colour' => 'string', |
523 | 'avatar' => 'string', |
524 | 'avatar_type' => 'string', |
525 | 'avatar_width' => 'int', |
526 | 'avatar_height' => 'int', |
527 | 'receive_pm' => 'int', |
528 | 'legend' => 'int', |
529 | 'teampage' => 'int', |
530 | 'message_limit' => 'int', |
531 | 'max_recipients'=> 'int', |
532 | 'founder_manage'=> 'int', |
533 | 'skip_auth' => 'int', |
534 | ); |
535 | |
536 | /** |
537 | * Initialise data before we display the add/edit form |
538 | * |
539 | * @event core.acp_manage_group_initialise_data |
540 | * @var string action Type of the action: add|edit |
541 | * @var int group_id The group id |
542 | * @var array group_row Array with new group data |
543 | * @var array error Array of errors, if you add errors |
544 | * ensure to update the template variables |
545 | * S_ERROR and ERROR_MSG to display it |
546 | * @var string group_name The group name |
547 | * @var string group_desc The group description |
548 | * @var int group_type The group type |
549 | * @var bool allow_desc_bbcode Allow bbcode in group description: true|false |
550 | * @var bool allow_desc_urls Allow urls in group description: true|false |
551 | * @var bool allow_desc_smilies Allow smiles in group description: true|false |
552 | * @var array submit_ary Array with new group data |
553 | * @var array test_variables Array with variables for test |
554 | * @since 3.1.0-b5 |
555 | */ |
556 | $vars = array( |
557 | 'action', |
558 | 'group_id', |
559 | 'group_row', |
560 | 'error', |
561 | 'group_name', |
562 | 'group_desc', |
563 | 'group_type', |
564 | 'allow_desc_bbcode', |
565 | 'allow_desc_urls', |
566 | 'allow_desc_smilies', |
567 | 'submit_ary', |
568 | 'test_variables', |
569 | ); |
570 | extract($phpbb_dispatcher->trigger_event('core.acp_manage_group_initialise_data', compact($vars))); |
571 | |
572 | foreach ($test_variables as $test => $type) |
573 | { |
574 | if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || isset($group_attributes['group_avatar']) && strpos($test, 'avatar') === 0 || in_array($test, $set_attributes))) |
575 | { |
576 | settype($submit_ary[$test], $type); |
577 | $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; |
578 | } |
579 | } |
580 | |
581 | if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) |
582 | { |
583 | $group_perm_from = $request->variable('group_perm_from', 0); |
584 | |
585 | // Copy permissions? |
586 | // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred. |
587 | // We do not limit on one auth category because this can lead to incomplete permissions being tricky to fix for the admin, roles being assigned or added non-default permissions. |
588 | // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise. |
589 | if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) |
590 | { |
591 | $sql = 'SELECT group_founder_manage |
592 | FROM ' . GROUPS_TABLE . ' |
593 | WHERE group_id = ' . $group_perm_from; |
594 | $result = $db->sql_query($sql); |
595 | $check_row = $db->sql_fetchrow($result); |
596 | $db->sql_freeresult($result); |
597 | |
598 | // Check the group if non-founder |
599 | if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0)) |
600 | { |
601 | // From the mysql documentation: |
602 | // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. |
603 | // Due to this we stay on the safe side if we do the insertion "the manual way" |
604 | |
605 | // Copy permisisons from/to the acl groups table (only group_id gets changed) |
606 | $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting |
607 | FROM ' . ACL_GROUPS_TABLE . ' |
608 | WHERE group_id = ' . $group_perm_from; |
609 | $result = $db->sql_query($sql); |
610 | |
611 | $groups_sql_ary = array(); |
612 | while ($row = $db->sql_fetchrow($result)) |
613 | { |
614 | $groups_sql_ary[] = array( |
615 | 'group_id' => (int) $group_id, |
616 | 'forum_id' => (int) $row['forum_id'], |
617 | 'auth_option_id' => (int) $row['auth_option_id'], |
618 | 'auth_role_id' => (int) $row['auth_role_id'], |
619 | 'auth_setting' => (int) $row['auth_setting'] |
620 | ); |
621 | } |
622 | $db->sql_freeresult($result); |
623 | |
624 | // Now insert the data |
625 | $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary); |
626 | |
627 | $auth->acl_clear_prefetch(); |
628 | } |
629 | } |
630 | |
631 | $cache->destroy('sql', array(GROUPS_TABLE, TEAMPAGE_TABLE)); |
632 | |
633 | $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED'; |
634 | trigger_error($user->lang[$message] . adm_back_link($this->u_action)); |
635 | } |
636 | } |
637 | |
638 | if (count($error)) |
639 | { |
640 | $error = array_map(array(&$user, 'lang'), $error); |
641 | $group_rank = $submit_ary['rank']; |
642 | |
643 | $group_desc_data = array( |
644 | 'text' => $group_desc, |
645 | 'allow_bbcode' => $allow_desc_bbcode, |
646 | 'allow_smilies' => $allow_desc_smilies, |
647 | 'allow_urls' => $allow_desc_urls |
648 | ); |
649 | } |
650 | } |
651 | else if (!$group_id) |
652 | { |
653 | $group_name = $request->variable('group_name', '', true); |
654 | $group_desc_data = array( |
655 | 'text' => '', |
656 | 'allow_bbcode' => true, |
657 | 'allow_smilies' => true, |
658 | 'allow_urls' => true |
659 | ); |
660 | $group_rank = 0; |
661 | $group_type = GROUP_OPEN; |
662 | } |
663 | else |
664 | { |
665 | $group_name = $group_row['group_name']; |
666 | $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']); |
667 | $group_type = $group_row['group_type']; |
668 | $group_rank = $group_row['group_rank']; |
669 | } |
670 | |
671 | $sql = 'SELECT * |
672 | FROM ' . RANKS_TABLE . ' |
673 | WHERE rank_special = 1 |
674 | ORDER BY rank_title'; |
675 | $result = $db->sql_query($sql); |
676 | |
677 | $rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>'; |
678 | |
679 | while ($row = $db->sql_fetchrow($result)) |
680 | { |
681 | $selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : ''; |
682 | $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; |
683 | } |
684 | $db->sql_freeresult($result); |
685 | |
686 | $type_free = ($group_type == GROUP_FREE) ? ' checked="checked"' : ''; |
687 | $type_open = ($group_type == GROUP_OPEN) ? ' checked="checked"' : ''; |
688 | $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : ''; |
689 | $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : ''; |
690 | |
691 | // Load up stuff for avatars |
692 | if ($config['allow_avatar']) |
693 | { |
694 | $avatars_enabled = false; |
695 | $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $avatar_data['avatar_type'])); |
696 | |
697 | // Assign min and max values before generating avatar driver html |
698 | $template->assign_vars(array( |
699 | 'AVATAR_MIN_WIDTH' => $config['avatar_min_width'], |
700 | 'AVATAR_MAX_WIDTH' => $config['avatar_max_width'], |
701 | 'AVATAR_MIN_HEIGHT' => $config['avatar_min_height'], |
702 | 'AVATAR_MAX_HEIGHT' => $config['avatar_max_height'], |
703 | )); |
704 | |
705 | foreach ($avatar_drivers as $current_driver) |
706 | { |
707 | $driver = $phpbb_avatar_manager->get_driver($current_driver); |
708 | |
709 | $avatars_enabled = true; |
710 | $template->set_filenames(array( |
711 | 'avatar' => $driver->get_acp_template_name(), |
712 | )); |
713 | |
714 | if ($driver->prepare_form($request, $template, $user, $avatar_data, $avatar_error)) |
715 | { |
716 | $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); |
717 | $driver_upper = strtoupper($driver_name); |
718 | $template->assign_block_vars('avatar_drivers', array( |
719 | 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), |
720 | 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), |
721 | |
722 | 'DRIVER' => $driver_name, |
723 | 'SELECTED' => $current_driver == $selected_driver, |
724 | 'OUTPUT' => $template->assign_display('avatar'), |
725 | )); |
726 | } |
727 | } |
728 | } |
729 | |
730 | if (isset($phpbb_avatar_manager) && !$update) |
731 | { |
732 | // Merge any avatar errors into the primary error array |
733 | $error = array_merge($error, $phpbb_avatar_manager->localize_errors($user, $avatar_error)); |
734 | } |
735 | |
736 | $back_link = $request->variable('back_link', ''); |
737 | |
738 | switch ($back_link) |
739 | { |
740 | case 'acp_users_groups': |
741 | $u_back = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=groups&u=' . $request->variable('u', 0)); |
742 | break; |
743 | |
744 | default: |
745 | $u_back = $this->u_action; |
746 | break; |
747 | } |
748 | |
749 | /** @var \phpbb\avatar\helper $avatar_helper */ |
750 | $avatar_helper = $phpbb_container->get('avatar.helper'); |
751 | |
752 | $group_avatar = $avatar_helper->get_group_avatar($group_row, 'GROUP_AVATAR', true); |
753 | $template->assign_vars($avatar_helper->get_template_vars($group_avatar)); |
754 | |
755 | $template->assign_vars(array( |
756 | 'S_EDIT' => true, |
757 | 'S_ADD_GROUP' => ($action == 'add') ? true : false, |
758 | 'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false, |
759 | 'S_INCLUDE_SWATCH' => true, |
760 | 'S_ERROR' => (count($error)) ? true : false, |
761 | 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false, |
762 | 'S_USER_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false, |
763 | 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), |
764 | |
765 | 'ERROR_MSG' => (count($error)) ? implode('<br />', $error) : '', |
766 | 'GROUP_NAME' => $group_helper->get_name($group_name), |
767 | 'GROUP_INTERNAL_NAME' => $group_name, |
768 | 'GROUP_DESC' => $group_desc_data['text'], |
769 | 'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '', |
770 | 'GROUP_FOUNDER_MANAGE' => (isset($group_row['group_founder_manage']) && $group_row['group_founder_manage']) ? ' checked="checked"' : '', |
771 | 'GROUP_LEGEND' => (isset($group_row['group_legend']) && $group_row['group_legend']) ? ' checked="checked"' : '', |
772 | 'GROUP_TEAMPAGE' => (isset($group_row['group_teampage']) && $group_row['group_teampage']) ? ' checked="checked"' : '', |
773 | 'GROUP_MESSAGE_LIMIT' => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0, |
774 | 'GROUP_MAX_RECIPIENTS' => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0, |
775 | 'GROUP_COLOUR' => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '', |
776 | 'GROUP_SKIP_AUTH' => (!empty($group_row['group_skip_auth'])) ? ' checked="checked"' : '', |
777 | |
778 | 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], |
779 | 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], |
780 | 'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'], |
781 | |
782 | 'S_RANK_OPTIONS' => $rank_options, |
783 | 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)), |
784 | 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], |
785 | |
786 | 'GROUP_TYPE_FREE' => GROUP_FREE, |
787 | 'GROUP_TYPE_OPEN' => GROUP_OPEN, |
788 | 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, |
789 | 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, |
790 | 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, |
791 | |
792 | 'GROUP_FREE' => $type_free, |
793 | 'GROUP_OPEN' => $type_open, |
794 | 'GROUP_CLOSED' => $type_closed, |
795 | 'GROUP_HIDDEN' => $type_hidden, |
796 | |
797 | 'U_BACK' => $u_back, |
798 | 'U_ACTION' => "{$this->u_action}&action=$action&g=$group_id", |
799 | 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), |
800 | )); |
801 | |
802 | /** |
803 | * Modify group template data before we display the form |
804 | * |
805 | * @event core.acp_manage_group_display_form |
806 | * @var string action Type of the action: add|edit |
807 | * @var bool update Do we display the form only |
808 | * or did the user press submit |
809 | * @var int group_id The group id |
810 | * @var array group_row Array with new group data |
811 | * @var string group_name The group name |
812 | * @var int group_type The group type |
813 | * @var array group_desc_data The group description data |
814 | * @var string group_rank The group rank |
815 | * @var string rank_options The rank options |
816 | * @var array error Array of errors, if you add errors |
817 | * ensure to update the template variables |
818 | * S_ERROR and ERROR_MSG to display it |
819 | * @since 3.1.0-b5 |
820 | */ |
821 | $vars = array( |
822 | 'action', |
823 | 'update', |
824 | 'group_id', |
825 | 'group_row', |
826 | 'group_desc_data', |
827 | 'group_name', |
828 | 'group_type', |
829 | 'group_rank', |
830 | 'rank_options', |
831 | 'error', |
832 | ); |
833 | extract($phpbb_dispatcher->trigger_event('core.acp_manage_group_display_form', compact($vars))); |
834 | |
835 | return; |
836 | break; |
837 | |
838 | case 'list': |
839 | |
840 | if (!$group_id) |
841 | { |
842 | trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); |
843 | } |
844 | |
845 | /* @var $pagination \phpbb\pagination */ |
846 | $pagination = $phpbb_container->get('pagination'); |
847 | $this->page_title = 'GROUP_MEMBERS'; |
848 | |
849 | // Grab the leaders - always, on every page... |
850 | $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending |
851 | FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug |
852 | WHERE ug.group_id = $group_id |
853 | AND u.user_id = ug.user_id |
854 | AND ug.group_leader = 1 |
855 | ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; |
856 | $result = $db->sql_query($sql); |
857 | |
858 | while ($row = $db->sql_fetchrow($result)) |
859 | { |
860 | $template->assign_block_vars('leader', array( |
861 | 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"), |
862 | |
863 | 'USERNAME' => $row['username'], |
864 | 'USERNAME_COLOUR' => $row['user_colour'], |
865 | 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false, |
866 | 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ', |
867 | 'USER_POSTS' => $row['user_posts'], |
868 | 'USER_ID' => $row['user_id'], |
869 | )); |
870 | } |
871 | $db->sql_freeresult($result); |
872 | |
873 | // Total number of group members (non-leaders) |
874 | $sql = 'SELECT COUNT(user_id) AS total_members |
875 | FROM ' . USER_GROUP_TABLE . " |
876 | WHERE group_id = $group_id |
877 | AND group_leader = 0"; |
878 | $result = $db->sql_query($sql); |
879 | $total_members = (int) $db->sql_fetchfield('total_members'); |
880 | $db->sql_freeresult($result); |
881 | |
882 | $s_action_options = ''; |
883 | $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE'); |
884 | |
885 | foreach ($options as $option => $lang) |
886 | { |
887 | $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>'; |
888 | } |
889 | |
890 | $base_url = $this->u_action . "&action=$action&g=$group_id"; |
891 | $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start); |
892 | |
893 | $template->assign_vars(array( |
894 | 'S_LIST' => true, |
895 | 'S_GROUP_SPECIAL' => ($group_row['group_type'] == GROUP_SPECIAL) ? true : false, |
896 | 'S_ACTION_OPTIONS' => $s_action_options, |
897 | |
898 | 'GROUP_NAME' => $group_helper->get_name($group_row['group_name']), |
899 | |
900 | 'U_ACTION' => $this->u_action . "&g=$group_id", |
901 | 'U_BACK' => $this->u_action, |
902 | 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'), |
903 | 'U_DEFAULT_ALL' => "{$this->u_action}&action=set_default_on_all&g=$group_id", |
904 | )); |
905 | |
906 | // Grab the members |
907 | $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending |
908 | FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug |
909 | WHERE ug.group_id = $group_id |
910 | AND u.user_id = ug.user_id |
911 | AND ug.group_leader = 0 |
912 | ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; |
913 | $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); |
914 | |
915 | $pending = false; |
916 | |
917 | while ($row = $db->sql_fetchrow($result)) |
918 | { |
919 | if ($row['user_pending'] && !$pending) |
920 | { |
921 | $template->assign_block_vars('member', array( |
922 | 'S_PENDING' => true) |
923 | ); |
924 | |
925 | $pending = true; |
926 | } |
927 | |
928 | $template->assign_block_vars('member', array( |
929 | 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"), |
930 | |
931 | 'USERNAME' => $row['username'], |
932 | 'USERNAME_COLOUR' => $row['user_colour'], |
933 | 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false, |
934 | 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ', |
935 | 'USER_POSTS' => $row['user_posts'], |
936 | 'USER_ID' => $row['user_id']) |
937 | ); |
938 | } |
939 | $db->sql_freeresult($result); |
940 | |
941 | return; |
942 | break; |
943 | } |
944 | |
945 | $template->assign_vars(array( |
946 | 'U_ACTION' => $this->u_action, |
947 | 'S_GROUP_ADD' => ($auth->acl_get('a_groupadd')) ? true : false) |
948 | ); |
949 | |
950 | // Get us all the groups |
951 | $sql = 'SELECT g.group_id, g.group_name, g.group_type, g.group_colour |
952 | FROM ' . GROUPS_TABLE . ' g |
953 | ORDER BY g.group_type ASC, g.group_name'; |
954 | $result = $db->sql_query($sql); |
955 | |
956 | $lookup = $cached_group_data = array(); |
957 | while ($row = $db->sql_fetchrow($result)) |
958 | { |
959 | $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : 'normal'; |
960 | |
961 | // used to determine what type a group is |
962 | $lookup[$row['group_id']] = $type; |
963 | |
964 | // used for easy access to the data within a group |
965 | $cached_group_data[$type][$row['group_id']] = $row; |
966 | $cached_group_data[$type][$row['group_id']]['total_members'] = 0; |
967 | $cached_group_data[$type][$row['group_id']]['pending_members'] = 0; |
968 | } |
969 | $db->sql_freeresult($result); |
970 | |
971 | // How many people are in which group? |
972 | $sql = 'SELECT COUNT(ug.user_id) AS total_members, SUM(ug.user_pending) AS pending_members, ug.group_id |
973 | FROM ' . USER_GROUP_TABLE . ' ug |
974 | WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . ' |
975 | GROUP BY ug.group_id'; |
976 | $result = $db->sql_query($sql); |
977 | |
978 | while ($row = $db->sql_fetchrow($result)) |
979 | { |
980 | $type = $lookup[$row['group_id']]; |
981 | $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members']; |
982 | $cached_group_data[$type][$row['group_id']]['pending_members'] = $row['pending_members']; |
983 | } |
984 | $db->sql_freeresult($result); |
985 | |
986 | // The order is... normal, then special |
987 | ksort($cached_group_data); |
988 | |
989 | foreach ($cached_group_data as $type => $row_ary) |
990 | { |
991 | if ($type == 'special') |
992 | { |
993 | $template->assign_block_vars('groups', array( |
994 | 'S_SPECIAL' => true) |
995 | ); |
996 | } |
997 | |
998 | foreach ($row_ary as $group_id => $row) |
999 | { |
1000 | $group_name = (!empty($user->lang['G_' . $row['group_name']]))? $user->lang['G_' . $row['group_name']] : $row['group_name']; |
1001 | |
1002 | $template->assign_block_vars('groups', array( |
1003 | 'U_LIST' => "{$this->u_action}&action=list&g=$group_id", |
1004 | 'U_EDIT' => "{$this->u_action}&action=edit&g=$group_id", |
1005 | 'U_DELETE' => ($auth->acl_get('a_groupdel')) ? "{$this->u_action}&action=delete&g=$group_id" : '', |
1006 | |
1007 | 'S_GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL) ? true : false, |
1008 | |
1009 | 'GROUP_NAME' => $group_name, |
1010 | 'GROUP_COLOR' => $row['group_colour'], |
1011 | 'TOTAL_MEMBERS' => $row['total_members'], |
1012 | 'PENDING_MEMBERS' => $row['pending_members'] |
1013 | )); |
1014 | } |
1015 | } |
1016 | } |
1017 | |
1018 | public function manage_position() |
1019 | { |
1020 | global $config, $db, $template, $user, $request, $phpbb_container; |
1021 | |
1022 | $this->tpl_name = 'acp_groups_position'; |
1023 | $this->page_title = 'ACP_GROUPS_POSITION'; |
1024 | |
1025 | $field = $request->variable('field', ''); |
1026 | $action = $request->variable('action', ''); |
1027 | $group_id = $request->variable('g', 0); |
1028 | $teampage_id = $request->variable('t', 0); |
1029 | $category_id = $request->variable('c', 0); |
1030 | |
1031 | /** @var \phpbb\group\helper $group_helper */ |
1032 | $group_helper = $phpbb_container->get('group_helper'); |
1033 | |
1034 | if ($field && !in_array($field, array('legend', 'teampage'))) |
1035 | { |
1036 | // Invalid mode |
1037 | trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); |
1038 | } |
1039 | else if ($field && in_array($field, array('legend', 'teampage'))) |
1040 | { |
1041 | /* @var $group_position \phpbb\groupposition\groupposition_interface */ |
1042 | $group_position = $phpbb_container->get('groupposition.' . $field); |
1043 | } |
1044 | |
1045 | if ($field == 'teampage') |
1046 | { |
1047 | try |
1048 | { |
1049 | switch ($action) |
1050 | { |
1051 | case 'add': |
1052 | $group_position->add_group_teampage($group_id, $category_id); |
1053 | break; |
1054 | |
1055 | case 'add_category': |
1056 | $group_position->add_category_teampage($request->variable('category_name', '', true)); |
1057 | break; |
1058 | |
1059 | case 'delete': |
1060 | $group_position->delete_teampage($teampage_id); |
1061 | break; |
1062 | |
1063 | case 'move_up': |
1064 | $group_position->move_up_teampage($teampage_id); |
1065 | break; |
1066 | |
1067 | case 'move_down': |
1068 | $group_position->move_down_teampage($teampage_id); |
1069 | break; |
1070 | } |
1071 | } |
1072 | catch (\phpbb\groupposition\exception $exception) |
1073 | { |
1074 | trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING); |
1075 | } |
1076 | } |
1077 | else if ($field == 'legend') |
1078 | { |
1079 | try |
1080 | { |
1081 | switch ($action) |
1082 | { |
1083 | case 'add': |
1084 | $group_position->add_group($group_id); |
1085 | break; |
1086 | |
1087 | case 'delete': |
1088 | $group_position->delete_group($group_id); |
1089 | break; |
1090 | |
1091 | case 'move_up': |
1092 | $group_position->move_up($group_id); |
1093 | break; |
1094 | |
1095 | case 'move_down': |
1096 | $group_position->move_down($group_id); |
1097 | break; |
1098 | } |
1099 | } |
1100 | catch (\phpbb\groupposition\exception $exception) |
1101 | { |
1102 | trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING); |
1103 | } |
1104 | } |
1105 | else |
1106 | { |
1107 | switch ($action) |
1108 | { |
1109 | case 'set_config_teampage': |
1110 | $config->set('teampage_forums', $request->variable('teampage_forums', 0)); |
1111 | $config->set('teampage_memberships', $request->variable('teampage_memberships', 0)); |
1112 | trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); |
1113 | break; |
1114 | |
1115 | case 'set_config_legend': |
1116 | $config->set('legend_sort_groupname', $request->variable('legend_sort_groupname', 0)); |
1117 | trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); |
1118 | break; |
1119 | } |
1120 | } |
1121 | |
1122 | if (($action == 'move_up' || $action == 'move_down') && $request->is_ajax()) |
1123 | { |
1124 | $json_response = new \phpbb\json_response; |
1125 | $json_response->send(array('success' => true)); |
1126 | } |
1127 | |
1128 | $sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend |
1129 | FROM ' . GROUPS_TABLE . ' |
1130 | ORDER BY group_legend ASC, group_type DESC, group_name ASC'; |
1131 | $result = $db->sql_query($sql); |
1132 | |
1133 | while ($row = $db->sql_fetchrow($result)) |
1134 | { |
1135 | $group_name = $group_helper->get_name($row['group_name']); |
1136 | if ($row['group_legend']) |
1137 | { |
1138 | $template->assign_block_vars('legend', array( |
1139 | 'GROUP_NAME' => $group_name, |
1140 | 'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '', |
1141 | 'GROUP_TYPE' => $user->lang[\phpbb\groupposition\legend::group_type_language($row['group_type'])], |
1142 | |
1143 | 'U_MOVE_DOWN' => "{$this->u_action}&field=legend&action=move_down&g=" . $row['group_id'], |
1144 | 'U_MOVE_UP' => "{$this->u_action}&field=legend&action=move_up&g=" . $row['group_id'], |
1145 | 'U_DELETE' => "{$this->u_action}&field=legend&action=delete&g=" . $row['group_id'], |
1146 | )); |
1147 | } |
1148 | else |
1149 | { |
1150 | $template->assign_block_vars('add_legend', array( |
1151 | 'GROUP_ID' => (int) $row['group_id'], |
1152 | 'GROUP_NAME' => $group_name, |
1153 | 'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL), |
1154 | )); |
1155 | } |
1156 | } |
1157 | $db->sql_freeresult($result); |
1158 | |
1159 | $category_url_param = (($category_id) ? '&c=' . $category_id : ''); |
1160 | |
1161 | $sql = 'SELECT t.*, g.group_name, g.group_colour, g.group_type |
1162 | FROM ' . TEAMPAGE_TABLE . ' t |
1163 | LEFT JOIN ' . GROUPS_TABLE . ' g |
1164 | ON (t.group_id = g.group_id) |
1165 | WHERE t.teampage_parent = ' . $category_id . ' |
1166 | OR t.teampage_id = ' . $category_id . ' |
1167 | ORDER BY t.teampage_position ASC'; |
1168 | $result = $db->sql_query($sql); |
1169 | |
1170 | while ($row = $db->sql_fetchrow($result)) |
1171 | { |
1172 | if ($row['teampage_id'] == $category_id) |
1173 | { |
1174 | $template->assign_vars(array( |
1175 | 'CURRENT_CATEGORY_NAME' => $row['teampage_name'], |
1176 | )); |
1177 | continue; |
1178 | } |
1179 | |
1180 | if ($row['group_id']) |
1181 | { |
1182 | $group_name = $group_helper->get_name($row['group_name']); |
1183 | $group_type = $user->lang[\phpbb\groupposition\teampage::group_type_language($row['group_type'])]; |
1184 | } |
1185 | else |
1186 | { |
1187 | $group_name = $row['teampage_name']; |
1188 | $group_type = ''; |
1189 | } |
1190 | |
1191 | $template->assign_block_vars('teampage', array( |
1192 | 'GROUP_NAME' => $group_name, |
1193 | 'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '', |
1194 | 'GROUP_TYPE' => $group_type, |
1195 | |
1196 | 'U_CATEGORY' => (!$row['group_id']) ? "{$this->u_action}&c=" . $row['teampage_id'] : '', |
1197 | 'U_MOVE_DOWN' => "{$this->u_action}&field=teampage&action=move_down{$category_url_param}&t=" . $row['teampage_id'], |
1198 | 'U_MOVE_UP' => "{$this->u_action}&field=teampage&action=move_up{$category_url_param}&t=" . $row['teampage_id'], |
1199 | 'U_DELETE' => "{$this->u_action}&field=teampage&action=delete{$category_url_param}&t=" . $row['teampage_id'], |
1200 | )); |
1201 | } |
1202 | $db->sql_freeresult($result); |
1203 | |
1204 | $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type |
1205 | FROM ' . GROUPS_TABLE . ' g |
1206 | LEFT JOIN ' . TEAMPAGE_TABLE . ' t |
1207 | ON (t.group_id = g.group_id) |
1208 | WHERE t.teampage_id IS NULL |
1209 | ORDER BY g.group_type DESC, g.group_name ASC'; |
1210 | $result = $db->sql_query($sql); |
1211 | |
1212 | while ($row = $db->sql_fetchrow($result)) |
1213 | { |
1214 | $group_name = $group_helper->get_name($row['group_name']); |
1215 | $template->assign_block_vars('add_teampage', array( |
1216 | 'GROUP_ID' => (int) $row['group_id'], |
1217 | 'GROUP_NAME' => $group_name, |
1218 | 'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL), |
1219 | )); |
1220 | } |
1221 | $db->sql_freeresult($result); |
1222 | |
1223 | $template->assign_vars(array( |
1224 | 'U_ACTION' => $this->u_action, |
1225 | 'U_ACTION_LEGEND' => $this->u_action . '&field=legend', |
1226 | 'U_ACTION_TEAMPAGE' => $this->u_action . '&field=teampage' . $category_url_param, |
1227 | 'U_ACTION_TEAMPAGE_CAT' => $this->u_action . '&field=teampage_cat', |
1228 | |
1229 | 'S_TEAMPAGE_CATEGORY' => $category_id, |
1230 | 'DISPLAY_FORUMS' => ($config['teampage_forums']) ? true : false, |
1231 | 'DISPLAY_MEMBERSHIPS' => $config['teampage_memberships'], |
1232 | 'LEGEND_SORT_GROUPNAME' => ($config['legend_sort_groupname']) ? true : false, |
1233 | )); |
1234 | } |
1235 | } |