source: trunk/forum/includes/ucp/ucp_groups.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 39.3 KB
Line 
1<?php
2/**
3*
4* @package ucp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* ucp_groups
21* @package ucp
22*/
23class ucp_groups
24{
25 var $u_action;
26
27 function main($id, $mode)
28 {
29 global $config, $phpbb_root_path, $phpEx;
30 global $db, $user, $auth, $cache, $template;
31
32 $user->add_lang('groups');
33
34 $return_page = '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '">', '</a>');
35
36 $mark_ary = request_var('mark', array(0));
37 $submit = (!empty($_POST['submit'])) ? true : false;
38 $delete = (!empty($_POST['delete'])) ? true : false;
39 $error = $data = array();
40
41 switch ($mode)
42 {
43 case 'membership':
44
45 $this->page_title = 'UCP_USERGROUPS_MEMBER';
46
47 if ($submit || isset($_POST['change_default']))
48 {
49 $action = (isset($_POST['change_default'])) ? 'change_default' : request_var('action', '');
50 $group_id = ($action == 'change_default') ? request_var('default', 0) : request_var('selected', 0);
51
52 if (!$group_id)
53 {
54 trigger_error('NO_GROUP_SELECTED');
55 }
56
57 $sql = 'SELECT group_id, group_name, group_type
58 FROM ' . GROUPS_TABLE . "
59 WHERE group_id IN ($group_id, {$user->data['group_id']})";
60 $result = $db->sql_query($sql);
61
62 $group_row = array();
63 while ($row = $db->sql_fetchrow($result))
64 {
65 $row['group_name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
66 $group_row[$row['group_id']] = $row;
67 }
68 $db->sql_freeresult($result);
69
70 if (!sizeof($group_row))
71 {
72 trigger_error('GROUP_NOT_EXIST');
73 }
74
75 switch ($action)
76 {
77 case 'change_default':
78 // User already having this group set as default?
79 if ($group_id == $user->data['group_id'])
80 {
81 trigger_error($user->lang['ALREADY_DEFAULT_GROUP'] . $return_page);
82 }
83
84 if (!$auth->acl_get('u_chggrp'))
85 {
86 trigger_error($user->lang['NOT_AUTHORISED'] . $return_page);
87 }
88
89 // User needs to be member of the group in order to make it default
90 if (!group_memberships($group_id, $user->data['user_id'], true))
91 {
92 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
93 }
94
95 if (confirm_box(true))
96 {
97 group_user_attributes('default', $group_id, $user->data['user_id']);
98
99 add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_CHANGE', sprintf($user->lang['USER_GROUP_CHANGE'], $group_row[$user->data['group_id']]['group_name'], $group_row[$group_id]['group_name']));
100
101 meta_refresh(3, $this->u_action);
102 trigger_error($user->lang['CHANGED_DEFAULT_GROUP'] . $return_page);
103 }
104 else
105 {
106 $s_hidden_fields = array(
107 'default' => $group_id,
108 'change_default'=> true
109 );
110
111 confirm_box(false, sprintf($user->lang['GROUP_CHANGE_DEFAULT'], $group_row[$group_id]['group_name']), build_hidden_fields($s_hidden_fields));
112 }
113
114 break;
115
116 case 'resign':
117
118 // User tries to resign from default group but is not allowed to change it?
119 if ($group_id == $user->data['group_id'] && !$auth->acl_get('u_chggrp'))
120 {
121 trigger_error($user->lang['NOT_RESIGN_FROM_DEFAULT_GROUP'] . $return_page);
122 }
123
124 if (!($row = group_memberships($group_id, $user->data['user_id'])))
125 {
126 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
127 }
128 list(, $row) = each($row);
129
130 $sql = 'SELECT group_type
131 FROM ' . GROUPS_TABLE . '
132 WHERE group_id = ' . $group_id;
133 $result = $db->sql_query($sql);
134 $group_type = (int) $db->sql_fetchfield('group_type');
135 $db->sql_freeresult($result);
136
137 if ($group_type != GROUP_OPEN && $group_type != GROUP_FREE)
138 {
139 trigger_error($user->lang['CANNOT_RESIGN_GROUP'] . $return_page);
140 }
141
142 if (confirm_box(true))
143 {
144 group_user_del($group_id, $user->data['user_id']);
145
146 add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_RESIGN', $group_row[$group_id]['group_name']);
147
148 meta_refresh(3, $this->u_action);
149 trigger_error($user->lang[($row['user_pending']) ? 'GROUP_RESIGNED_PENDING' : 'GROUP_RESIGNED_MEMBERSHIP'] . $return_page);
150 }
151 else
152 {
153 $s_hidden_fields = array(
154 'selected' => $group_id,
155 'action' => 'resign',
156 'submit' => true
157 );
158
159 confirm_box(false, ($row['user_pending']) ? 'GROUP_RESIGN_PENDING' : 'GROUP_RESIGN_MEMBERSHIP', build_hidden_fields($s_hidden_fields));
160 }
161
162 break;
163
164 case 'join':
165
166 $sql = 'SELECT ug.*, u.username, u.username_clean, u.user_email
167 FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
168 WHERE ug.user_id = u.user_id
169 AND ug.group_id = ' . $group_id . '
170 AND ug.user_id = ' . $user->data['user_id'];
171 $result = $db->sql_query($sql);
172 $row = $db->sql_fetchrow($result);
173 $db->sql_freeresult($result);
174
175 if ($row)
176 {
177 if ($row['user_pending'])
178 {
179 trigger_error($user->lang['ALREADY_IN_GROUP_PENDING'] . $return_page);
180 }
181
182 trigger_error($user->lang['ALREADY_IN_GROUP'] . $return_page);
183 }
184
185 // Check permission to join (open group or request)
186 if ($group_row[$group_id]['group_type'] != GROUP_OPEN && $group_row[$group_id]['group_type'] != GROUP_FREE)
187 {
188 trigger_error($user->lang['CANNOT_JOIN_GROUP'] . $return_page);
189 }
190
191 if (confirm_box(true))
192 {
193 if ($group_row[$group_id]['group_type'] == GROUP_FREE)
194 {
195 group_user_add($group_id, $user->data['user_id']);
196
197 $email_template = 'group_added';
198 }
199 else
200 {
201 group_user_add($group_id, $user->data['user_id'], false, false, false, 0, 1);
202
203 $email_template = 'group_request';
204 }
205
206 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
207 $messenger = new messenger();
208
209 $sql = 'SELECT u.username, u.username_clean, u.user_email, u.user_notify_type, u.user_jabber, u.user_lang
210 FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
211 WHERE ug.user_id = u.user_id
212 AND ' . (($group_row[$group_id]['group_type'] == GROUP_FREE) ? "ug.user_id = {$user->data['user_id']}" : 'ug.group_leader = 1') . "
213 AND ug.group_id = $group_id";
214 $result = $db->sql_query($sql);
215
216 while ($row = $db->sql_fetchrow($result))
217 {
218 $messenger->template($email_template, $row['user_lang']);
219
220 $messenger->to($row['user_email'], $row['username']);
221 $messenger->im($row['user_jabber'], $row['username']);
222
223 $messenger->assign_vars(array(
224 'USERNAME' => htmlspecialchars_decode($row['username']),
225 'GROUP_NAME' => htmlspecialchars_decode($group_row[$group_id]['group_name']),
226 'REQUEST_USERNAME' => $user->data['username'],
227
228 'U_PENDING' => generate_board_url() . "/ucp.$phpEx?i=groups&mode=manage&action=list&g=$group_id",
229 'U_GROUP' => generate_board_url() . "/memberlist.$phpEx?mode=group&g=$group_id")
230 );
231
232 $messenger->send($row['user_notify_type']);
233 }
234 $db->sql_freeresult($result);
235
236 $messenger->save_queue();
237
238 add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_JOIN' . (($group_row[$group_id]['group_type'] == GROUP_FREE) ? '' : '_PENDING'), $group_row[$group_id]['group_name']);
239
240 meta_refresh(3, $this->u_action);
241 trigger_error($user->lang[($group_row[$group_id]['group_type'] == GROUP_FREE) ? 'GROUP_JOINED' : 'GROUP_JOINED_PENDING'] . $return_page);
242 }
243 else
244 {
245 $s_hidden_fields = array(
246 'selected' => $group_id,
247 'action' => 'join',
248 'submit' => true
249 );
250
251 confirm_box(false, ($group_row[$group_id]['group_type'] == GROUP_FREE) ? 'GROUP_JOIN' : 'GROUP_JOIN_PENDING', build_hidden_fields($s_hidden_fields));
252 }
253
254 break;
255
256 case 'demote':
257
258 if (!($row = group_memberships($group_id, $user->data['user_id'])))
259 {
260 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
261 }
262 list(, $row) = each($row);
263
264 if (!$row['group_leader'])
265 {
266 trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
267 }
268
269 if (confirm_box(true))
270 {
271 group_user_attributes('demote', $group_id, $user->data['user_id']);
272
273 add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_DEMOTE', $group_row[$group_id]['group_name']);
274
275 meta_refresh(3, $this->u_action);
276 trigger_error($user->lang['USER_GROUP_DEMOTED'] . $return_page);
277 }
278 else
279 {
280 $s_hidden_fields = array(
281 'selected' => $group_id,
282 'action' => 'demote',
283 'submit' => true
284 );
285
286 confirm_box(false, 'USER_GROUP_DEMOTE', build_hidden_fields($s_hidden_fields));
287 }
288
289 break;
290 }
291 }
292
293 $sql = 'SELECT g.*, ug.group_leader, ug.user_pending
294 FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
295 WHERE ug.user_id = ' . $user->data['user_id'] . '
296 AND g.group_id = ug.group_id
297 ORDER BY g.group_type DESC, g.group_name';
298 $result = $db->sql_query($sql);
299
300 $group_id_ary = array();
301 $leader_count = $member_count = $pending_count = 0;
302 while ($row = $db->sql_fetchrow($result))
303 {
304 $block = ($row['group_leader']) ? 'leader' : (($row['user_pending']) ? 'pending' : 'member');
305
306 switch ($row['group_type'])
307 {
308 case GROUP_OPEN:
309 $group_status = 'OPEN';
310 break;
311
312 case GROUP_CLOSED:
313 $group_status = 'CLOSED';
314 break;
315
316 case GROUP_HIDDEN:
317 $group_status = 'HIDDEN';
318 break;
319
320 case GROUP_SPECIAL:
321 $group_status = 'SPECIAL';
322 break;
323
324 case GROUP_FREE:
325 $group_status = 'FREE';
326 break;
327 }
328
329 $template->assign_block_vars($block, array(
330 'GROUP_ID' => $row['group_id'],
331 'GROUP_NAME' => ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
332 'GROUP_DESC' => ($row['group_type'] <> GROUP_SPECIAL) ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'],
333 'GROUP_SPECIAL' => ($row['group_type'] <> GROUP_SPECIAL) ? false : true,
334 'GROUP_STATUS' => $user->lang['GROUP_IS_' . $group_status],
335 'GROUP_COLOUR' => $row['group_colour'],
336
337 'U_VIEW_GROUP' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']),
338
339 'S_GROUP_DEFAULT' => ($row['group_id'] == $user->data['group_id']) ? true : false,
340 'S_ROW_COUNT' => ${$block . '_count'}++)
341 );
342
343 $group_id_ary[] = (int) $row['group_id'];
344 }
345 $db->sql_freeresult($result);
346
347 // Hide hidden groups unless user is an admin with group privileges
348 $sql_and = ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? '<> ' . GROUP_SPECIAL : 'NOT IN (' . GROUP_SPECIAL . ', ' . GROUP_HIDDEN . ')';
349
350 $sql = 'SELECT group_id, group_name, group_colour, group_desc, group_desc_uid, group_desc_bitfield, group_desc_options, group_type, group_founder_manage
351 FROM ' . GROUPS_TABLE . '
352 WHERE ' . ((sizeof($group_id_ary)) ? $db->sql_in_set('group_id', $group_id_ary, true) . ' AND ' : '') . "
353 group_type $sql_and
354 ORDER BY group_type DESC, group_name";
355 $result = $db->sql_query($sql);
356
357 $nonmember_count = 0;
358 while ($row = $db->sql_fetchrow($result))
359 {
360 switch ($row['group_type'])
361 {
362 case GROUP_OPEN:
363 $group_status = 'OPEN';
364 break;
365
366 case GROUP_CLOSED:
367 $group_status = 'CLOSED';
368 break;
369
370 case GROUP_HIDDEN:
371 $group_status = 'HIDDEN';
372 break;
373
374 case GROUP_SPECIAL:
375 $group_status = 'SPECIAL';
376 break;
377
378 case GROUP_FREE:
379 $group_status = 'FREE';
380 break;
381 }
382
383 $template->assign_block_vars('nonmember', array(
384 'GROUP_ID' => $row['group_id'],
385 'GROUP_NAME' => ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
386 'GROUP_DESC' => ($row['group_type'] <> GROUP_SPECIAL) ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'],
387 'GROUP_SPECIAL' => ($row['group_type'] <> GROUP_SPECIAL) ? false : true,
388 'GROUP_CLOSED' => ($row['group_type'] <> GROUP_CLOSED || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? false : true,
389 'GROUP_STATUS' => $user->lang['GROUP_IS_' . $group_status],
390 'S_CAN_JOIN' => ($row['group_type'] == GROUP_OPEN || $row['group_type'] == GROUP_FREE) ? true : false,
391 'GROUP_COLOUR' => $row['group_colour'],
392
393 'U_VIEW_GROUP' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']),
394
395 'S_ROW_COUNT' => $nonmember_count++)
396 );
397 }
398 $db->sql_freeresult($result);
399
400 $template->assign_vars(array(
401 'S_CHANGE_DEFAULT' => ($auth->acl_get('u_chggrp')) ? true : false,
402 'S_LEADER_COUNT' => $leader_count,
403 'S_MEMBER_COUNT' => $member_count,
404 'S_PENDING_COUNT' => $pending_count,
405 'S_NONMEMBER_COUNT' => $nonmember_count,
406
407 'S_UCP_ACTION' => $this->u_action)
408 );
409
410 break;
411
412 case 'manage':
413
414 $this->page_title = 'UCP_USERGROUPS_MANAGE';
415 $action = (isset($_POST['addusers'])) ? 'addusers' : request_var('action', '');
416 $group_id = request_var('g', 0);
417
418 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
419
420 add_form_key('ucp_groups');
421
422 if ($group_id)
423 {
424 $sql = 'SELECT *
425 FROM ' . GROUPS_TABLE . "
426 WHERE group_id = $group_id";
427 $result = $db->sql_query($sql);
428 $group_row = $db->sql_fetchrow($result);
429 $db->sql_freeresult($result);
430
431 if (!$group_row)
432 {
433 trigger_error($user->lang['NO_GROUP'] . $return_page);
434 }
435
436 // Check if the user is allowed to manage this group if set to founder only.
437 if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage'])
438 {
439 trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . $return_page, E_USER_WARNING);
440 }
441
442 $group_name = $group_row['group_name'];
443 $group_type = $group_row['group_type'];
444
445 $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_root_path . 'adm/images/no_avatar.gif" alt="" />';
446
447 $template->assign_vars(array(
448 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
449 'GROUP_INTERNAL_NAME' => $group_name,
450 'GROUP_COLOUR' => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
451 'GROUP_DESC_DISP' => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']),
452 'GROUP_TYPE' => $group_row['group_type'],
453
454 'AVATAR' => $avatar_img,
455 'AVATAR_IMAGE' => $avatar_img,
456 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
457 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
458 ));
459 }
460
461 switch ($action)
462 {
463 case 'edit':
464
465 if (!$group_id)
466 {
467 trigger_error($user->lang['NO_GROUP'] . $return_page);
468 }
469
470 if (!($row = group_memberships($group_id, $user->data['user_id'])))
471 {
472 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
473 }
474 list(, $row) = each($row);
475
476 if (!$row['group_leader'])
477 {
478 trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
479 }
480
481 $file_uploads = (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
482 $user->add_lang(array('acp/groups', 'acp/common'));
483
484 $data = $submit_ary = array();
485
486 $update = (isset($_POST['update'])) ? true : false;
487
488 $error = array();
489
490 $avatar_select = basename(request_var('avatar_select', ''));
491 $category = basename(request_var('category', ''));
492
493 $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
494
495 // Did we submit?
496 if ($update)
497 {
498 $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
499 $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
500 $group_type = request_var('group_type', GROUP_FREE);
501
502 $allow_desc_bbcode = request_var('desc_parse_bbcode', false);
503 $allow_desc_urls = request_var('desc_parse_urls', false);
504 $allow_desc_smilies = request_var('desc_parse_smilies', false);
505
506 $submit_ary = array(
507 'colour' => request_var('group_colour', ''),
508 'rank' => request_var('group_rank', 0),
509 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0,
510 'message_limit' => request_var('group_message_limit', 0),
511 'max_recipients'=> request_var('group_max_recipients', 0),
512 );
513
514 $data['uploadurl'] = request_var('uploadurl', '');
515 $data['remotelink'] = request_var('remotelink', '');
516 $data['width'] = request_var('width', '');
517 $data['height'] = request_var('height', '');
518 $delete = request_var('delete', '');
519
520 if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
521 {
522 // Avatar stuff
523 $var_ary = array(
524 'uploadurl' => array('string', true, 5, 255),
525 'remotelink' => array('string', true, 5, 255),
526 'width' => array('string', true, 1, 3),
527 'height' => array('string', true, 1, 3),
528 );
529
530 if (!($error = validate_data($data, $var_ary)))
531 {
532 $data['user_id'] = "g$group_id";
533
534 if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload)
535 {
536 list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
537 }
538 else if ($data['remotelink'])
539 {
540 list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
541 }
542 }
543 }
544 else if ($avatar_select && $config['allow_avatar_local'])
545 {
546 // check avatar gallery
547 if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
548 {
549 $submit_ary['avatar_type'] = AVATAR_GALLERY;
550
551 list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
552 $submit_ary['avatar'] = $category . '/' . $avatar_select;
553 }
554 }
555 else if ($delete)
556 {
557 $submit_ary['avatar'] = '';
558 $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
559 }
560 else if ($data['width'] && $data['height'])
561 {
562 // Only update the dimensions?
563 if ($config['avatar_max_width'] || $config['avatar_max_height'])
564 {
565 if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
566 {
567 $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
568 }
569 }
570
571 if (!sizeof($error))
572 {
573 if ($config['avatar_min_width'] || $config['avatar_min_height'])
574 {
575 if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height'])
576 {
577 $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
578 }
579 }
580 }
581
582 if (!sizeof($error))
583 {
584 $submit_ary['avatar_width'] = $data['width'];
585 $submit_ary['avatar_height'] = $data['height'];
586 }
587 }
588
589 if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete)
590 {
591 if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
592 {
593 avatar_delete('group', $group_row, true);
594 }
595 }
596
597 if (!check_form_key('ucp_groups'))
598 {
599 $error[] = $user->lang['FORM_INVALID'];
600 }
601
602 if (!sizeof($error))
603 {
604 // Only set the rank, colour, etc. if it's changed or if we're adding a new
605 // group. This prevents existing group members being updated if no changes
606 // were made.
607
608 $group_attributes = array();
609 $test_variables = array(
610 'rank' => 'int',
611 'colour' => 'string',
612 'avatar' => 'string',
613 'avatar_type' => 'int',
614 'avatar_width' => 'int',
615 'avatar_height' => 'int',
616 'receive_pm' => 'int',
617 'legend' => 'int',
618 'message_limit' => 'int',
619 'max_recipients'=> 'int',
620 );
621
622 foreach ($test_variables as $test => $type)
623 {
624 if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test]))
625 {
626 settype($submit_ary[$test], $type);
627 $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
628 }
629 }
630
631 if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies)))
632 {
633 $cache->destroy('sql', GROUPS_TABLE);
634
635 $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
636 trigger_error($user->lang[$message] . $return_page);
637 }
638 }
639
640 if (sizeof($error))
641 {
642 $group_rank = $submit_ary['rank'];
643
644 $group_desc_data = array(
645 'text' => $group_desc,
646 'allow_bbcode' => $allow_desc_bbcode,
647 'allow_smilies' => $allow_desc_smilies,
648 'allow_urls' => $allow_desc_urls
649 );
650 }
651 }
652 else if (!$group_id)
653 {
654 $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
655 $group_desc_data = array(
656 'text' => '',
657 'allow_bbcode' => true,
658 'allow_smilies' => true,
659 'allow_urls' => true
660 );
661 $group_rank = 0;
662 $group_type = GROUP_OPEN;
663 }
664 else
665 {
666 $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
667 $group_rank = $group_row['group_rank'];
668 }
669
670 $sql = 'SELECT *
671 FROM ' . RANKS_TABLE . '
672 WHERE rank_special = 1
673 ORDER BY rank_title';
674 $result = $db->sql_query($sql);
675
676 $rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
677 while ($row = $db->sql_fetchrow($result))
678 {
679 $selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : '';
680 $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
681 }
682 $db->sql_freeresult($result);
683
684 $type_free = ($group_type == GROUP_FREE) ? ' checked="checked"' : '';
685 $type_open = ($group_type == GROUP_OPEN) ? ' checked="checked"' : '';
686 $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
687 $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
688
689 $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
690
691 if ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery)
692 {
693 avatar_gallery($category, $avatar_select, 4);
694 }
695
696 $avatars_enabled = ($config['allow_avatar'] && (($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) || ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false;
697
698 $template->assign_vars(array(
699 'S_EDIT' => true,
700 'S_INCLUDE_SWATCH' => true,
701 'S_FORM_ENCTYPE' => ($config['allow_avatar'] && $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) ? ' enctype="multipart/form-data"' : '',
702 'S_ERROR' => (sizeof($error)) ? true : false,
703 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false,
704 'S_AVATARS_ENABLED' => $avatars_enabled,
705 'S_DISPLAY_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false,
706 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
707
708 'S_UPLOAD_AVATAR_FILE' => ($config['allow_avatar'] && $config['allow_avatar_upload'] && $can_upload) ? true : false,
709 'S_UPLOAD_AVATAR_URL' => ($config['allow_avatar'] && $config['allow_avatar_remote_upload'] && $can_upload) ? true : false,
710 'S_LINK_AVATAR' => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false,
711
712 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
713 'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
714 'GROUP_MESSAGE_LIMIT' => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
715 'GROUP_MAX_RECIPIENTS' => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
716
717 'GROUP_DESC' => $group_desc_data['text'],
718 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'],
719 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'],
720 'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'],
721
722 'S_RANK_OPTIONS' => $rank_options,
723 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
724
725 'GROUP_TYPE_FREE' => GROUP_FREE,
726 'GROUP_TYPE_OPEN' => GROUP_OPEN,
727 'GROUP_TYPE_CLOSED' => GROUP_CLOSED,
728 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN,
729 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL,
730
731 'GROUP_FREE' => $type_free,
732 'GROUP_OPEN' => $type_open,
733 'GROUP_CLOSED' => $type_closed,
734 'GROUP_HIDDEN' => $type_hidden,
735
736 'U_SWATCH' => append_sid("{$phpbb_root_path}adm/swatch.$phpEx", 'form=ucp&amp;name=group_colour'),
737 'S_UCP_ACTION' => $this->u_action . "&amp;action=$action&amp;g=$group_id",
738 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024),
739 ));
740
741 break;
742
743 case 'list':
744
745 if (!$group_id)
746 {
747 trigger_error($user->lang['NO_GROUP'] . $return_page);
748 }
749
750 if (!($row = group_memberships($group_id, $user->data['user_id'])))
751 {
752 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
753 }
754 list(, $row) = each($row);
755
756 if (!$row['group_leader'])
757 {
758 trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
759 }
760
761 $user->add_lang(array('acp/groups', 'acp/common'));
762 $start = request_var('start', 0);
763
764 // Grab the leaders - always, on every page...
765 $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
766 FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
767 WHERE ug.group_id = $group_id
768 AND u.user_id = ug.user_id
769 AND ug.group_leader = 1
770 ORDER BY ug.user_pending DESC, u.username_clean";
771 $result = $db->sql_query($sql);
772
773 while ($row = $db->sql_fetchrow($result))
774 {
775 $template->assign_block_vars('leader', array(
776 'USERNAME' => $row['username'],
777 'USERNAME_COLOUR' => $row['user_colour'],
778 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
779 'U_USER_VIEW' => get_username_string('profile', $row['user_id'], $row['username']),
780 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
781 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
782 'USER_POSTS' => $row['user_posts'],
783 'USER_ID' => $row['user_id'])
784 );
785 }
786 $db->sql_freeresult($result);
787
788 // Total number of group members (non-leaders)
789 $sql = 'SELECT COUNT(user_id) AS total_members
790 FROM ' . USER_GROUP_TABLE . "
791 WHERE group_id = $group_id
792 AND group_leader = 0";
793 $result = $db->sql_query($sql);
794 $total_members = (int) $db->sql_fetchfield('total_members');
795 $db->sql_freeresult($result);
796
797 // Grab the members
798 $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
799 FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
800 WHERE ug.group_id = $group_id
801 AND u.user_id = ug.user_id
802 AND ug.group_leader = 0
803 ORDER BY ug.user_pending DESC, u.username_clean";
804 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
805
806 $pending = false;
807 $approved = false;
808
809 while ($row = $db->sql_fetchrow($result))
810 {
811 if ($row['user_pending'] && !$pending)
812 {
813 $template->assign_block_vars('member', array(
814 'S_PENDING' => true)
815 );
816 $template->assign_var('S_PENDING_SET', true);
817
818 $pending = true;
819 }
820 else if (!$row['user_pending'] && !$approved)
821 {
822 $template->assign_block_vars('member', array(
823 'S_APPROVED' => true)
824 );
825 $template->assign_var('S_APPROVED_SET', true);
826
827 $approved = true;
828 }
829
830 $template->assign_block_vars('member', array(
831 'USERNAME' => $row['username'],
832 'USERNAME_COLOUR' => $row['user_colour'],
833 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
834 'U_USER_VIEW' => get_username_string('profile', $row['user_id'], $row['username']),
835 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
836 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
837 'USER_POSTS' => $row['user_posts'],
838 'USER_ID' => $row['user_id'])
839 );
840 }
841 $db->sql_freeresult($result);
842
843 $s_action_options = '';
844 $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'deleteusers' => 'DELETE');
845
846 foreach ($options as $option => $lang)
847 {
848 $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
849 }
850
851 $template->assign_vars(array(
852 'S_LIST' => true,
853 'S_ACTION_OPTIONS' => $s_action_options,
854 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start),
855 'PAGINATION' => generate_pagination($this->u_action . "&amp;action=$action&amp;g=$group_id", $total_members, $config['topics_per_page'], $start),
856
857 'U_ACTION' => $this->u_action . "&amp;g=$group_id",
858 'S_UCP_ACTION' => $this->u_action . "&amp;g=$group_id",
859 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=ucp&amp;field=usernames'),
860 ));
861
862 break;
863
864 case 'approve':
865
866 if (!$group_id)
867 {
868 trigger_error($user->lang['NO_GROUP'] . $return_page);
869 }
870
871 if (!($row = group_memberships($group_id, $user->data['user_id'])))
872 {
873 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
874 }
875 list(, $row) = each($row);
876
877 if (!$row['group_leader'])
878 {
879 trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
880 }
881
882 $user->add_lang('acp/groups');
883
884 // Approve, demote or promote
885 group_user_attributes('approve', $group_id, $mark_ary, false, false);
886
887 trigger_error($user->lang['USERS_APPROVED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
888
889 break;
890
891 case 'default':
892
893 if (!$group_id)
894 {
895 trigger_error($user->lang['NO_GROUP'] . $return_page);
896 }
897
898 if (!($row = group_memberships($group_id, $user->data['user_id'])))
899 {
900 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
901 }
902 list(, $row) = each($row);
903
904 if (!$row['group_leader'])
905 {
906 trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
907 }
908
909 $group_row['group_name'] = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
910
911 if (confirm_box(true))
912 {
913 if (!sizeof($mark_ary))
914 {
915 $start = 0;
916
917 do
918 {
919 $sql = 'SELECT user_id
920 FROM ' . USER_GROUP_TABLE . "
921 WHERE group_id = $group_id
922 ORDER BY user_id";
923 $result = $db->sql_query_limit($sql, 200, $start);
924
925 $mark_ary = array();
926 if ($row = $db->sql_fetchrow($result))
927 {
928 do
929 {
930 $mark_ary[] = $row['user_id'];
931 }
932 while ($row = $db->sql_fetchrow($result));
933
934 group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
935
936 $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200;
937 }
938 else
939 {
940 $start = 0;
941 }
942 $db->sql_freeresult($result);
943 }
944 while ($start);
945 }
946 else
947 {
948 group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
949 }
950
951 $user->add_lang('acp/groups');
952
953 trigger_error($user->lang['GROUP_DEFS_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
954 }
955 else
956 {
957 $user->add_lang('acp/common');
958
959 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
960 'mark' => $mark_ary,
961 'g' => $group_id,
962 'i' => $id,
963 'mode' => $mode,
964 'action' => $action))
965 );
966 }
967
968 // redirect to last screen
969 redirect($this->u_action . '&amp;action=list&amp;g=' . $group_id);
970
971 break;
972
973 case 'deleteusers':
974
975 $user->add_lang(array('acp/groups', 'acp/common'));
976
977 if (!($row = group_memberships($group_id, $user->data['user_id'])))
978 {
979 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
980 }
981 list(, $row) = each($row);
982
983 if (!$row['group_leader'])
984 {
985 trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
986 }
987
988 $group_row['group_name'] = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
989
990 if (confirm_box(true))
991 {
992 if (!$group_id)
993 {
994 trigger_error($user->lang['NO_GROUP'] . $return_page);
995 }
996
997 $error = group_user_del($group_id, $mark_ary, false, $group_row['group_name']);
998
999 if ($error)
1000 {
1001 trigger_error($user->lang[$error] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
1002 }
1003
1004 trigger_error($user->lang['GROUP_USERS_REMOVE'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
1005 }
1006 else
1007 {
1008 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
1009 'mark' => $mark_ary,
1010 'g' => $group_id,
1011 'i' => $id,
1012 'mode' => $mode,
1013 'action' => $action))
1014 );
1015 }
1016
1017 // redirect to last screen
1018 redirect($this->u_action . '&amp;action=list&amp;g=' . $group_id);
1019
1020 break;
1021
1022 case 'addusers':
1023
1024 $user->add_lang(array('acp/groups', 'acp/common'));
1025
1026 $names = utf8_normalize_nfc(request_var('usernames', '', true));
1027
1028 if (!$group_id)
1029 {
1030 trigger_error($user->lang['NO_GROUP'] . $return_page);
1031 }
1032
1033 if (!$names)
1034 {
1035 trigger_error($user->lang['NO_USERS'] . $return_page);
1036 }
1037
1038 if (!($row = group_memberships($group_id, $user->data['user_id'])))
1039 {
1040 trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
1041 }
1042 list(, $row) = each($row);
1043
1044 if (!$row['group_leader'])
1045 {
1046 trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
1047 }
1048
1049 $name_ary = array_unique(explode("\n", $names));
1050 $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
1051
1052 $default = request_var('default', 0);
1053
1054 if (confirm_box(true))
1055 {
1056 // Add user/s to group
1057 if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, 0, 0, $group_row))
1058 {
1059 trigger_error($user->lang[$error] . $return_page);
1060 }
1061
1062 trigger_error($user->lang['GROUP_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
1063 }
1064 else
1065 {
1066 $s_hidden_fields = array(
1067 'default' => $default,
1068 'usernames' => $names,
1069 'g' => $group_id,
1070 'i' => $id,
1071 'mode' => $mode,
1072 'action' => $action
1073 );
1074 confirm_box(false, sprintf($user->lang['GROUP_CONFIRM_ADD_USER' . ((sizeof($name_ary) == 1) ? '' : 'S')], implode(', ', $name_ary)), build_hidden_fields($s_hidden_fields));
1075 }
1076
1077 trigger_error($user->lang['NO_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
1078
1079 break;
1080
1081 default:
1082 $user->add_lang('acp/common');
1083
1084 $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_desc, g.group_desc_uid, g.group_desc_bitfield, g.group_desc_options, g.group_type, ug.group_leader
1085 FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
1086 WHERE ug.user_id = ' . $user->data['user_id'] . '
1087 AND g.group_id = ug.group_id
1088 AND ug.group_leader = 1
1089 ORDER BY g.group_type DESC, g.group_name';
1090 $result = $db->sql_query($sql);
1091
1092 while ($value = $db->sql_fetchrow($result))
1093 {
1094 $template->assign_block_vars('leader', array(
1095 'GROUP_NAME' => ($value['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $value['group_name']] : $value['group_name'],
1096 'GROUP_DESC' => generate_text_for_display($value['group_desc'], $value['group_desc_uid'], $value['group_desc_bitfield'], $value['group_desc_options']),
1097 'GROUP_TYPE' => $value['group_type'],
1098 'GROUP_ID' => $value['group_id'],
1099 'GROUP_COLOUR' => $value['group_colour'],
1100
1101 'U_LIST' => $this->u_action . "&amp;action=list&amp;g={$value['group_id']}",
1102 'U_EDIT' => $this->u_action . "&amp;action=edit&amp;g={$value['group_id']}")
1103 );
1104 }
1105 $db->sql_freeresult($result);
1106
1107 break;
1108 }
1109
1110 break;
1111 }
1112
1113 $this->tpl_name = 'ucp_groups_' . $mode;
1114 }
1115}
1116
1117?>
Note: See TracBrowser for help on using the repository browser.