2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: groupcp.php,v 1.58.2.27 2006/12/16 13:11:24 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 ***************************************************************************/
23 define('IN_PHPBB', true);
24 $phpbb_root_path = './';
25 include($phpbb_root_path . 'extension.inc');
26 include($phpbb_root_path . 'common.'.$phpEx);
28 // -------------------------
30 function generate_user_info(&$row, $date_format, $group_mod, &$from, &$posts, &$joined, &$poster_avatar, &$profile_img, &$profile, &$search_img, &$search, &$pm_img, &$pm, &$email_img, &$email, &$www_img, &$www, &$icq_status_img, &$icq_img, &$icq, &$aim_img, &$aim, &$msn_img, &$msn, &$yim_img, &$yim)
32 global $lang, $images, $board_config, $phpEx;
34 $from = ( !empty($row['user_from']) ) ? $row['user_from'] : ' ';
35 $joined = create_date($date_format, $row['user_regdate'], $board_config['board_timezone']);
36 $posts = ( $row['user_posts'] ) ? $row['user_posts'] : 0;
39 if ( $row['user_avatar_type'] && $row['user_id'] != ANONYMOUS && $row['user_allowavatar'] )
41 switch( $row['user_avatar_type'] )
43 case USER_AVATAR_UPLOAD:
44 $poster_avatar = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $row['user_avatar'] . '" alt="" border="0" />' : '';
46 case USER_AVATAR_REMOTE:
47 $poster_avatar = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $row['user_avatar'] . '" alt="" border="0" />' : '';
49 case USER_AVATAR_GALLERY:
50 $poster_avatar = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $row['user_avatar'] . '" alt="" border="0" />' : '';
55 if ( !empty($row['user_viewemail']) || $group_mod )
57 $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&" . POST_USERS_URL .'=' . $row['user_id']) : 'mailto:' . $row['user_email'];
59 $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
60 $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
64 $email_img = ' ';
68 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']);
69 $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
70 $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
72 $temp_url = append_sid("privmsg.$phpEx?mode=post&" . POST_USERS_URL . "=" . $row['user_id']);
73 $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
74 $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
76 $www_img = ( $row['user_website'] ) ? '<a href="' . $row['user_website'] . '" target="_userwww"><img src="' . $images['icon_www'] . '" alt="' . $lang['Visit_website'] . '" title="' . $lang['Visit_website'] . '" border="0" /></a>' : '';
77 $www = ( $row['user_website'] ) ? '<a href="' . $row['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
79 if ( !empty($row['user_icq']) )
81 $icq_status_img = '<a href="http://wwp.icq.com/' . $row['user_icq'] . '#pager"><img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&img=5" width="18" height="18" border="0" /></a>';
82 $icq_img = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $row['user_icq'] . '"><img src="' . $images['icon_icq'] . '" alt="' . $lang['ICQ'] . '" title="' . $lang['ICQ'] . '" border="0" /></a>';
83 $icq = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $row['user_icq'] . '">' . $lang['ICQ'] . '</a>';
92 $aim_img = ( $row['user_aim'] ) ? '<a href="aim:goim?screenname=' . $row['user_aim'] . '&message=Hello+Are+you+there?"><img src="' . $images['icon_aim'] . '" alt="' . $lang['AIM'] . '" title="' . $lang['AIM'] . '" border="0" /></a>' : '';
93 $aim = ( $row['user_aim'] ) ? '<a href="aim:goim?screenname=' . $row['user_aim'] . '&message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
95 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']);
96 $msn_img = ( $row['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
97 $msn = ( $row['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
99 $yim_img = ( $row['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $row['user_yim'] . '&.src=pg"><img src="' . $images['icon_yim'] . '" alt="' . $lang['YIM'] . '" title="' . $lang['YIM'] . '" border="0" /></a>' : '';
100 $yim = ( $row['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $row['user_yim'] . '&.src=pg">' . $lang['YIM'] . '</a>' : '';
102 $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($row['username']) . "&showresults=posts");
103 $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . sprintf($lang['Search_user_posts'], $row['username']) . '" title="' . sprintf($lang['Search_user_posts'], $row['username']) . '" border="0" /></a>';
104 $search = '<a href="' . $temp_url . '">' . sprintf($lang['Search_user_posts'], $row['username']) . '</a>';
109 // --------------------------
112 // Start session management
114 $userdata = session_pagestart($user_ip, PAGE_GROUPCP);
115 init_userprefs($userdata);
117 // End session management
120 $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path']));
121 $script_name = ( $script_name != '' ) ? $script_name . '/groupcp.'.$phpEx : 'groupcp.'.$phpEx;
122 $server_name = trim($board_config['server_name']);
123 $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
124 $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
126 $server_url = $server_protocol . $server_name . $server_port . $script_name;
128 if ( isset($HTTP_GET_VARS[POST_GROUPS_URL]) || isset($HTTP_POST_VARS[POST_GROUPS_URL]) )
130 $group_id = ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) ) ? intval($HTTP_POST_VARS[POST_GROUPS_URL]) : intval($HTTP_GET_VARS[POST_GROUPS_URL]);
137 if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
139 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
140 $mode = htmlspecialchars($mode);
147 $confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? TRUE : 0;
148 $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? TRUE : 0;
150 $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
151 $start = ($start < 0) ? 0 : $start;
154 // Default var values
156 $is_moderator = FALSE;
158 if ( isset($HTTP_POST_VARS['groupstatus']) && $group_id )
160 if ( !$userdata['session_logged_in'] )
162 redirect(append_sid("login.$phpEx?redirect=groupcp.$phpEx&" . POST_GROUPS_URL . "=$group_id", true));
165 $sql = "SELECT group_moderator
166 FROM " . GROUPS_TABLE . "
167 WHERE group_id = $group_id";
168 if ( !($result = $db->sql_query($sql)) )
170 message_die(GENERAL_ERROR, 'Could not obtain user and group information', '', __LINE__, __FILE__, $sql);
173 $row = $db->sql_fetchrow($result);
175 if ( $row['group_moderator'] != $userdata['user_id'] && $userdata['user_level'] != ADMIN )
177 $template->assign_vars(array(
178 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("index.$phpEx") . '">')
181 $message = $lang['Not_group_moderator'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
183 message_die(GENERAL_MESSAGE, $message);
186 $sql = "UPDATE " . GROUPS_TABLE . "
187 SET group_type = " . intval($HTTP_POST_VARS['group_type']) . "
188 WHERE group_id = $group_id";
189 if ( !($result = $db->sql_query($sql)) )
191 message_die(GENERAL_ERROR, 'Could not obtain user and group information', '', __LINE__, __FILE__, $sql);
194 $template->assign_vars(array(
195 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">')
198 $message = $lang['Group_type_updated'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
200 message_die(GENERAL_MESSAGE, $message);
203 else if ( isset($HTTP_POST_VARS['joingroup']) && $group_id )
206 // First, joining a group
207 // If the user isn't logged in redirect them to login
209 if ( !$userdata['session_logged_in'] )
211 redirect(append_sid("login.$phpEx?redirect=groupcp.$phpEx&" . POST_GROUPS_URL . "=$group_id", true));
214 $sql = "SELECT ug.user_id, g.group_type
215 FROM " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
216 WHERE g.group_id = $group_id
217 AND g.group_type <> " . GROUP_HIDDEN . "
218 AND ug.group_id = g.group_id";
219 if ( !($result = $db->sql_query($sql)) )
221 message_die(GENERAL_ERROR, 'Could not obtain user and group information', '', __LINE__, __FILE__, $sql);
224 if ( $row = $db->sql_fetchrow($result) )
226 if ( $row['group_type'] == GROUP_OPEN )
230 if ( $userdata['user_id'] == $row['user_id'] )
232 $template->assign_vars(array(
233 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("index.$phpEx") . '">')
236 $message = $lang['Already_member_group'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
238 message_die(GENERAL_MESSAGE, $message);
240 } while ( $row = $db->sql_fetchrow($result) );
244 $template->assign_vars(array(
245 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("index.$phpEx") . '">')
248 $message = $lang['This_closed_group'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
250 message_die(GENERAL_MESSAGE, $message);
255 message_die(GENERAL_MESSAGE, $lang['No_groups_exist']);
258 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
259 VALUES ($group_id, " . $userdata['user_id'] . ", 1)";
260 if ( !($result = $db->sql_query($sql)) )
262 message_die(GENERAL_ERROR, "Error inserting user group subscription", "", __LINE__, __FILE__, $sql);
265 $sql = "SELECT u.user_email, u.username, u.user_lang, g.group_name
266 FROM ".USERS_TABLE . " u, " . GROUPS_TABLE . " g
267 WHERE u.user_id = g.group_moderator
268 AND g.group_id = $group_id";
269 if ( !($result = $db->sql_query($sql)) )
271 message_die(GENERAL_ERROR, "Error getting group moderator data", "", __LINE__, __FILE__, $sql);
274 $moderator = $db->sql_fetchrow($result);
276 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
277 $emailer = new emailer($board_config['smtp_delivery']);
279 $emailer->from($board_config['board_email']);
280 $emailer->replyto($board_config['board_email']);
282 $emailer->use_template('group_request', $moderator['user_lang']);
283 $emailer->email_address($moderator['user_email']);
284 $emailer->set_subject($lang['Group_request']);
286 $emailer->assign_vars(array(
287 'SITENAME' => $board_config['sitename'],
288 'GROUP_MODERATOR' => $moderator['username'],
289 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
291 'U_GROUPCP' => $server_url . '?' . POST_GROUPS_URL . "=$group_id&validate=true")
296 $template->assign_vars(array(
297 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("index.$phpEx") . '">')
300 $message = $lang['Group_joined'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
302 message_die(GENERAL_MESSAGE, $message);
304 else if ( isset($HTTP_POST_VARS['unsub']) || isset($HTTP_POST_VARS['unsubpending']) && $group_id )
307 // Second, unsubscribing from a group
308 // Check for confirmation of unsub.
312 redirect(append_sid("groupcp.$phpEx", true));
314 elseif ( !$userdata['session_logged_in'] )
316 redirect(append_sid("login.$phpEx?redirect=groupcp.$phpEx&" . POST_GROUPS_URL . "=$group_id", true));
321 $sql = "DELETE FROM " . USER_GROUP_TABLE . "
322 WHERE user_id = " . $userdata['user_id'] . "
323 AND group_id = $group_id";
324 if ( !($result = $db->sql_query($sql)) )
326 message_die(GENERAL_ERROR, 'Could not delete group memebership data', '', __LINE__, __FILE__, $sql);
329 if ( $userdata['user_level'] != ADMIN && $userdata['user_level'] == MOD )
331 $sql = "SELECT COUNT(auth_mod) AS is_auth_mod
332 FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug
333 WHERE ug.user_id = " . $userdata['user_id'] . "
334 AND aa.group_id = ug.group_id
335 AND aa.auth_mod = 1";
336 if ( !($result = $db->sql_query($sql)) )
338 message_die(GENERAL_ERROR, 'Could not obtain moderator status', '', __LINE__, __FILE__, $sql);
341 if ( !($row = $db->sql_fetchrow($result)) || $row['is_auth_mod'] == 0 )
343 $sql = "UPDATE " . USERS_TABLE . "
344 SET user_level = " . USER . "
345 WHERE user_id = " . $userdata['user_id'];
346 if ( !($result = $db->sql_query($sql)) )
348 message_die(GENERAL_ERROR, 'Could not update user level', '', __LINE__, __FILE__, $sql);
353 $template->assign_vars(array(
354 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("index.$phpEx") . '">')
357 $message = $lang['Unsub_success'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
359 message_die(GENERAL_MESSAGE, $message);
363 $unsub_msg = ( isset($HTTP_POST_VARS['unsub']) ) ? $lang['Confirm_unsub'] : $lang['Confirm_unsub_pending'];
365 $s_hidden_fields = '<input type="hidden" name="' . POST_GROUPS_URL . '" value="' . $group_id . '" /><input type="hidden" name="unsub" value="1" />';
367 $page_title = $lang['Group_Control_Panel'];
368 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
370 $template->set_filenames(array(
371 'confirm' => 'confirm_body.tpl')
374 $template->assign_vars(array(
375 'MESSAGE_TITLE' => $lang['Confirm'],
376 'MESSAGE_TEXT' => $unsub_msg,
377 'L_YES' => $lang['Yes'],
378 'L_NO' => $lang['No'],
379 'S_CONFIRM_ACTION' => append_sid("groupcp.$phpEx"),
380 'S_HIDDEN_FIELDS' => $s_hidden_fields)
383 $template->pparse('confirm');
385 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
389 else if ( $group_id )
392 // Did the group moderator get here through an email?
393 // If so, check to see if they are logged in.
395 if ( isset($HTTP_GET_VARS['validate']) )
397 if ( !$userdata['session_logged_in'] )
399 redirect(append_sid("login.$phpEx?redirect=groupcp.$phpEx&" . POST_GROUPS_URL . "=$group_id", true));
404 // For security, get the ID of the group moderator.
409 $sql = "SELECT g.group_moderator, g.group_type, aa.auth_mod
410 FROM " . GROUPS_TABLE . " g, " . AUTH_ACCESS_TABLE . " aa
411 WHERE g.group_id = $group_id
412 AND aa.group_id = g.group_id
414 SELECT g.group_moderator, g.group_type, NULL
415 FROM " . GROUPS_TABLE . " g
416 WHERE g.group_id = $group_id
419 FROM " . AUTH_ACCESS_TABLE . " aa
420 WHERE aa.group_id = g.group_id
423 ORDER BY aa.auth_mod DESC";
427 $sql = "SELECT g.group_moderator, g.group_type, aa.auth_mod
428 FROM " . GROUPS_TABLE . " g, " . AUTH_ACCESS_TABLE . " aa
429 WHERE g.group_id = $group_id
430 AND aa.group_id (+) = g.group_id
431 ORDER BY aa.auth_mod DESC";
435 $sql = "SELECT g.group_moderator, g.group_type, aa.auth_mod
436 FROM ( " . GROUPS_TABLE . " g
437 LEFT JOIN " . AUTH_ACCESS_TABLE . " aa ON aa.group_id = g.group_id )
438 WHERE g.group_id = $group_id
439 ORDER BY aa.auth_mod DESC";
442 if ( !($result = $db->sql_query($sql)) )
444 message_die(GENERAL_ERROR, 'Could not get moderator information', '', __LINE__, __FILE__, $sql);
447 if ( $group_info = $db->sql_fetchrow($result) )
449 $group_moderator = $group_info['group_moderator'];
451 if ( $group_moderator == $userdata['user_id'] || $userdata['user_level'] == ADMIN )
453 $is_moderator = TRUE;
457 // Handle Additions, removals, approvals and denials
459 if ( !empty($HTTP_POST_VARS['add']) || !empty($HTTP_POST_VARS['remove']) || isset($HTTP_POST_VARS['approve']) || isset($HTTP_POST_VARS['deny']) )
461 if ( !$userdata['session_logged_in'] )
463 redirect(append_sid("login.$phpEx?redirect=groupcp.$phpEx&" . POST_GROUPS_URL . "=$group_id", true));
466 if ( !$is_moderator )
468 $template->assign_vars(array(
469 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("index.$phpEx") . '">')
472 $message = $lang['Not_group_moderator'] . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
474 message_die(GENERAL_MESSAGE, $message);
477 if ( isset($HTTP_POST_VARS['add']) )
479 $username = ( isset($HTTP_POST_VARS['username']) ) ? phpbb_clean_username($HTTP_POST_VARS['username']) : '';
481 $sql = "SELECT user_id, user_email, user_lang, user_level
482 FROM " . USERS_TABLE . "
483 WHERE username = '" . str_replace("\'", "''", $username) . "'";
484 if ( !($result = $db->sql_query($sql)) )
486 message_die(GENERAL_ERROR, "Could not get user information", $lang['Error'], __LINE__, __FILE__, $sql);
489 if ( !($row = $db->sql_fetchrow($result)) )
491 $template->assign_vars(array(
492 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">')
495 $message = $lang['Could_not_add_user'] . "<br /><br />" . sprintf($lang['Click_return_group'], "<a href=\"" . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_index'], "<a href=\"" . append_sid("index.$phpEx") . "\">", "</a>");
497 message_die(GENERAL_MESSAGE, $message);
500 if ( $row['user_id'] == ANONYMOUS )
502 $template->assign_vars(array(
503 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">')
506 $message = $lang['Could_not_anon_user'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
508 message_die(GENERAL_MESSAGE, $message);
511 $sql = "SELECT ug.user_id, u.user_level
512 FROM " . USER_GROUP_TABLE . " ug, " . USERS_TABLE . " u
513 WHERE u.user_id = " . $row['user_id'] . "
514 AND ug.user_id = u.user_id
515 AND ug.group_id = $group_id";
516 if ( !($result = $db->sql_query($sql)) )
518 message_die(GENERAL_ERROR, 'Could not get user information', '', __LINE__, __FILE__, $sql);
521 if ( !($db->sql_fetchrow($result)) )
523 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (user_id, group_id, user_pending)
524 VALUES (" . $row['user_id'] . ", $group_id, 0)";
525 if ( !$db->sql_query($sql) )
527 message_die(GENERAL_ERROR, 'Could not add user to group', '', __LINE__, __FILE__, $sql);
530 if ( $row['user_level'] != ADMIN && $row['user_level'] != MOD && $group_info['auth_mod'] )
532 $sql = "UPDATE " . USERS_TABLE . "
533 SET user_level = " . MOD . "
534 WHERE user_id = " . $row['user_id'];
535 if ( !$db->sql_query($sql) )
537 message_die(GENERAL_ERROR, 'Could not update user level', '', __LINE__, __FILE__, $sql);
542 // Get the group name
543 // Email the user and tell them they're in the group
545 $group_sql = "SELECT group_name
546 FROM " . GROUPS_TABLE . "
547 WHERE group_id = $group_id";
548 if ( !($result = $db->sql_query($group_sql)) )
550 message_die(GENERAL_ERROR, 'Could not get group information', '', __LINE__, __FILE__, $group_sql);
553 $group_name_row = $db->sql_fetchrow($result);
555 $group_name = $group_name_row['group_name'];
557 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
558 $emailer = new emailer($board_config['smtp_delivery']);
560 $emailer->from($board_config['board_email']);
561 $emailer->replyto($board_config['board_email']);
563 $emailer->use_template('group_added', $row['user_lang']);
564 $emailer->email_address($row['user_email']);
565 $emailer->set_subject($lang['Group_added']);
567 $emailer->assign_vars(array(
568 'SITENAME' => $board_config['sitename'],
569 'GROUP_NAME' => $group_name,
570 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
572 'U_GROUPCP' => $server_url . '?' . POST_GROUPS_URL . "=$group_id")
579 $template->assign_vars(array(
580 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">')
583 $message = $lang['User_is_member_group'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
585 message_die(GENERAL_MESSAGE, $message);
590 if ( ( ( isset($HTTP_POST_VARS['approve']) || isset($HTTP_POST_VARS['deny']) ) && isset($HTTP_POST_VARS['pending_members']) ) || ( isset($HTTP_POST_VARS['remove']) && isset($HTTP_POST_VARS['members']) ) )
593 $members = ( isset($HTTP_POST_VARS['approve']) || isset($HTTP_POST_VARS['deny']) ) ? $HTTP_POST_VARS['pending_members'] : $HTTP_POST_VARS['members'];
596 for($i = 0; $i < count($members); $i++)
598 $sql_in .= ( ( $sql_in != '' ) ? ', ' : '' ) . intval($members[$i]);
601 if ( isset($HTTP_POST_VARS['approve']) )
603 if ( $group_info['auth_mod'] )
605 $sql = "UPDATE " . USERS_TABLE . "
606 SET user_level = " . MOD . "
607 WHERE user_id IN ($sql_in)
608 AND user_level NOT IN (" . MOD . ", " . ADMIN . ")";
609 if ( !$db->sql_query($sql) )
611 message_die(GENERAL_ERROR, 'Could not update user level', '', __LINE__, __FILE__, $sql);
615 $sql = "UPDATE " . USER_GROUP_TABLE . "
617 WHERE user_id IN ($sql_in)
618 AND group_id = $group_id";
619 $sql_select = "SELECT user_email
620 FROM ". USERS_TABLE . "
621 WHERE user_id IN ($sql_in)";
623 else if ( isset($HTTP_POST_VARS['deny']) || isset($HTTP_POST_VARS['remove']) )
625 if ( $group_info['auth_mod'] )
627 $sql = "SELECT ug.user_id, ug.group_id
628 FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug
629 WHERE ug.user_id IN ($sql_in)
630 AND aa.group_id = ug.group_id
632 GROUP BY ug.user_id, ug.group_id
633 ORDER BY ug.user_id, ug.group_id";
634 if ( !($result = $db->sql_query($sql)) )
636 message_die(GENERAL_ERROR, 'Could not obtain moderator status', '', __LINE__, __FILE__, $sql);
639 if ( $row = $db->sql_fetchrow($result) )
641 $group_check = array();
642 $remove_mod_sql = '';
646 $group_check[$row['user_id']][] = $row['group_id'];
648 while ( $row = $db->sql_fetchrow($result) );
650 while( list($user_id, $group_list) = @each($group_check) )
652 if ( count($group_list) == 1 )
654 $remove_mod_sql .= ( ( $remove_mod_sql != '' ) ? ', ' : '' ) . $user_id;
658 if ( $remove_mod_sql != '' )
660 $sql = "UPDATE " . USERS_TABLE . "
661 SET user_level = " . USER . "
662 WHERE user_id IN ($remove_mod_sql)
663 AND user_level NOT IN (" . ADMIN . ")";
664 if ( !$db->sql_query($sql) )
666 message_die(GENERAL_ERROR, 'Could not update user level', '', __LINE__, __FILE__, $sql);
672 $sql = "DELETE FROM " . USER_GROUP_TABLE . "
673 WHERE user_id IN ($sql_in)
674 AND group_id = $group_id";
677 if ( !$db->sql_query($sql) )
679 message_die(GENERAL_ERROR, 'Could not update user group table', '', __LINE__, __FILE__, $sql);
683 // Email users when they are approved
685 if ( isset($HTTP_POST_VARS['approve']) )
687 if ( !($result = $db->sql_query($sql_select)) )
689 message_die(GENERAL_ERROR, 'Could not get user email information', '', __LINE__, __FILE__, $sql);
693 while ($row = $db->sql_fetchrow($result))
695 $bcc_list[] = $row['user_email'];
699 // Get the group name
701 $group_sql = "SELECT group_name
702 FROM " . GROUPS_TABLE . "
703 WHERE group_id = $group_id";
704 if ( !($result = $db->sql_query($group_sql)) )
706 message_die(GENERAL_ERROR, 'Could not get group information', '', __LINE__, __FILE__, $group_sql);
709 $group_name_row = $db->sql_fetchrow($result);
710 $group_name = $group_name_row['group_name'];
712 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
713 $emailer = new emailer($board_config['smtp_delivery']);
715 $emailer->from($board_config['board_email']);
716 $emailer->replyto($board_config['board_email']);
718 for ($i = 0; $i < count($bcc_list); $i++)
720 $emailer->bcc($bcc_list[$i]);
723 $emailer->use_template('group_approved');
724 $emailer->set_subject($lang['Group_approved']);
726 $emailer->assign_vars(array(
727 'SITENAME' => $board_config['sitename'],
728 'GROUP_NAME' => $group_name,
729 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
731 'U_GROUPCP' => $server_url . '?' . POST_GROUPS_URL . "=$group_id")
740 // END approve or deny
745 message_die(GENERAL_MESSAGE, $lang['No_groups_exist']);
752 FROM " . GROUPS_TABLE . "
753 WHERE group_id = $group_id
754 AND group_single_user = 0";
755 if ( !($result = $db->sql_query($sql)) )
757 message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
760 if ( !($group_info = $db->sql_fetchrow($result)) )
762 message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
766 // Get moderator details for this group
768 $sql = "SELECT username, user_id, user_viewemail, user_posts, user_regdate, user_from, user_website, user_email, user_icq, user_aim, user_yim, user_msnm
769 FROM " . USERS_TABLE . "
770 WHERE user_id = " . $group_info['group_moderator'];
771 if ( !($result = $db->sql_query($sql)) )
773 message_die(GENERAL_ERROR, 'Error getting user list for group', '', __LINE__, __FILE__, $sql);
776 $group_moderator = $db->sql_fetchrow($result);
779 // Get user information for this group
781 $sql = "SELECT u.username, u.user_id, u.user_viewemail, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_msnm, ug.user_pending
782 FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug
783 WHERE ug.group_id = $group_id
784 AND u.user_id = ug.user_id
785 AND ug.user_pending = 0
786 AND ug.user_id <> " . $group_moderator['user_id'] . "
787 ORDER BY u.username";
788 if ( !($result = $db->sql_query($sql)) )
790 message_die(GENERAL_ERROR, 'Error getting user list for group', '', __LINE__, __FILE__, $sql);
793 $group_members = $db->sql_fetchrowset($result);
794 $members_count = count($group_members);
795 $db->sql_freeresult($result);
797 $sql = "SELECT u.username, u.user_id, u.user_viewemail, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_msnm
798 FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug, " . USERS_TABLE . " u
799 WHERE ug.group_id = $group_id
800 AND g.group_id = ug.group_id
801 AND ug.user_pending = 1
802 AND u.user_id = ug.user_id
803 ORDER BY u.username";
804 if ( !($result = $db->sql_query($sql)) )
806 message_die(GENERAL_ERROR, 'Error getting user pending information', '', __LINE__, __FILE__, $sql);
809 $modgroup_pending_list = $db->sql_fetchrowset($result);
810 $modgroup_pending_count = count($modgroup_pending_list);
811 $db->sql_freeresult($result);
813 $is_group_member = 0;
814 if ( $members_count )
816 for($i = 0; $i < $members_count; $i++)
818 if ( $group_members[$i]['user_id'] == $userdata['user_id'] && $userdata['session_logged_in'] )
820 $is_group_member = TRUE;
825 $is_group_pending_member = 0;
826 if ( $modgroup_pending_count )
828 for($i = 0; $i < $modgroup_pending_count; $i++)
830 if ( $modgroup_pending_list[$i]['user_id'] == $userdata['user_id'] && $userdata['session_logged_in'] )
832 $is_group_pending_member = TRUE;
837 if ( $userdata['user_level'] == ADMIN )
839 $is_moderator = TRUE;
842 if ( $userdata['user_id'] == $group_info['group_moderator'] )
844 $is_moderator = TRUE;
846 $group_details = $lang['Are_group_moderator'];
848 $s_hidden_fields = '<input type="hidden" name="' . POST_GROUPS_URL . '" value="' . $group_id . '" />';
850 else if ( $is_group_member || $is_group_pending_member )
852 $template->assign_block_vars('switch_unsubscribe_group_input', array());
854 $group_details = ( $is_group_pending_member ) ? $lang['Pending_this_group'] : $lang['Member_this_group'];
856 $s_hidden_fields = '<input type="hidden" name="' . POST_GROUPS_URL . '" value="' . $group_id . '" />';
858 else if ( $userdata['user_id'] == ANONYMOUS )
860 $group_details = $lang['Login_to_join'];
861 $s_hidden_fields = '';
865 if ( $group_info['group_type'] == GROUP_OPEN )
867 $template->assign_block_vars('switch_subscribe_group_input', array());
869 $group_details = $lang['This_open_group'];
870 $s_hidden_fields = '<input type="hidden" name="' . POST_GROUPS_URL . '" value="' . $group_id . '" />';
872 else if ( $group_info['group_type'] == GROUP_CLOSED )
874 $group_details = $lang['This_closed_group'];
875 $s_hidden_fields = '';
877 else if ( $group_info['group_type'] == GROUP_HIDDEN )
879 $group_details = $lang['This_hidden_group'];
880 $s_hidden_fields = '';
884 $page_title = $lang['Group_Control_Panel'];
885 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
890 $template->set_filenames(array(
891 'info' => 'groupcp_info_body.tpl',
892 'pendinginfo' => 'groupcp_pending_info.tpl')
894 make_jumpbox('viewforum.'.$phpEx);
899 $username = $group_moderator['username'];
900 $user_id = $group_moderator['user_id'];
902 generate_user_info($group_moderator, $board_config['default_dateformat'], $is_moderator, $from, $posts, $joined, $poster_avatar, $profile_img, $profile, $search_img, $search, $pm_img, $pm, $email_img, $email, $www_img, $www, $icq_status_img, $icq_img, $icq, $aim_img, $aim, $msn_img, $msn, $yim_img, $yim);
904 $s_hidden_fields .= '';
906 $template->assign_vars(array(
907 'L_GROUP_INFORMATION' => $lang['Group_Information'],
908 'L_GROUP_NAME' => $lang['Group_name'],
909 'L_GROUP_DESC' => $lang['Group_description'],
910 'L_GROUP_TYPE' => $lang['Group_type'],
911 'L_GROUP_MEMBERSHIP' => $lang['Group_membership'],
912 'L_SUBSCRIBE' => $lang['Subscribe'],
913 'L_UNSUBSCRIBE' => $lang['Unsubscribe'],
914 'L_JOIN_GROUP' => $lang['Join_group'],
915 'L_UNSUBSCRIBE_GROUP' => $lang['Unsubscribe'],
916 'L_GROUP_OPEN' => $lang['Group_open'],
917 'L_GROUP_CLOSED' => $lang['Group_closed'],
918 'L_GROUP_HIDDEN' => $lang['Group_hidden'],
919 'L_UPDATE' => $lang['Update'],
920 'L_GROUP_MODERATOR' => $lang['Group_Moderator'],
921 'L_GROUP_MEMBERS' => $lang['Group_Members'],
922 'L_PENDING_MEMBERS' => $lang['Pending_members'],
923 'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
924 'L_PM' => $lang['Private_Message'],
925 'L_EMAIL' => $lang['Email'],
926 'L_POSTS' => $lang['Posts'],
927 'L_WEBSITE' => $lang['Website'],
928 'L_FROM' => $lang['Location'],
929 'L_ORDER' => $lang['Order'],
930 'L_SORT' => $lang['Sort'],
931 'L_SUBMIT' => $lang['Sort'],
932 'L_AIM' => $lang['AIM'],
933 'L_YIM' => $lang['YIM'],
934 'L_MSNM' => $lang['MSNM'],
935 'L_ICQ' => $lang['ICQ'],
936 'L_SELECT' => $lang['Select'],
937 'L_REMOVE_SELECTED' => $lang['Remove_selected'],
938 'L_ADD_MEMBER' => $lang['Add_member'],
939 'L_FIND_USERNAME' => $lang['Find_username'],
941 'GROUP_NAME' => $group_info['group_name'],
942 'GROUP_DESC' => $group_info['group_description'],
943 'GROUP_DETAILS' => $group_details,
944 'MOD_ROW_COLOR' => '#' . $theme['td_color1'],
945 'MOD_ROW_CLASS' => $theme['td_class1'],
946 'MOD_USERNAME' => $username,
948 'MOD_JOINED' => $joined,
949 'MOD_POSTS' => $posts,
950 'MOD_AVATAR_IMG' => $poster_avatar,
951 'MOD_PROFILE_IMG' => $profile_img,
952 'MOD_PROFILE' => $profile,
953 'MOD_SEARCH_IMG' => $search_img,
954 'MOD_SEARCH' => $search,
955 'MOD_PM_IMG' => $pm_img,
957 'MOD_EMAIL_IMG' => $email_img,
958 'MOD_EMAIL' => $email,
959 'MOD_WWW_IMG' => $www_img,
961 'MOD_ICQ_STATUS_IMG' => $icq_status_img,
962 'MOD_ICQ_IMG' => $icq_img,
964 'MOD_AIM_IMG' => $aim_img,
966 'MOD_MSN_IMG' => $msn_img,
968 'MOD_YIM_IMG' => $yim_img,
971 'U_MOD_VIEWPROFILE' => append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id"),
972 'U_SEARCH_USER' => append_sid("search.$phpEx?mode=searchuser"),
974 'S_GROUP_OPEN_TYPE' => GROUP_OPEN,
975 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED,
976 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN,
977 'S_GROUP_OPEN_CHECKED' => ( $group_info['group_type'] == GROUP_OPEN ) ? ' checked="checked"' : '',
978 'S_GROUP_CLOSED_CHECKED' => ( $group_info['group_type'] == GROUP_CLOSED ) ? ' checked="checked"' : '',
979 'S_GROUP_HIDDEN_CHECKED' => ( $group_info['group_type'] == GROUP_HIDDEN ) ? ' checked="checked"' : '',
980 'S_HIDDEN_FIELDS' => $s_hidden_fields,
981 'S_MODE_SELECT' => $select_sort_mode,
982 'S_ORDER_SELECT' => $select_sort_order,
983 'S_GROUPCP_ACTION' => append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id"))
987 // Dump out the remaining users
989 for($i = $start; $i < min($board_config['topics_per_page'] + $start, $members_count); $i++)
991 $username = $group_members[$i]['username'];
992 $user_id = $group_members[$i]['user_id'];
994 generate_user_info($group_members[$i], $board_config['default_dateformat'], $is_moderator, $from, $posts, $joined, $poster_avatar, $profile_img, $profile, $search_img, $search, $pm_img, $pm, $email_img, $email, $www_img, $www, $icq_status_img, $icq_img, $icq, $aim_img, $aim, $msn_img, $msn, $yim_img, $yim);
996 if ( $group_info['group_type'] != GROUP_HIDDEN || $is_group_member || $is_moderator )
998 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
999 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1001 $template->assign_block_vars('member_row', array(
1002 'ROW_COLOR' => '#' . $row_color,
1003 'ROW_CLASS' => $row_class,
1004 'USERNAME' => $username,
1006 'JOINED' => $joined,
1008 'USER_ID' => $user_id,
1009 'AVATAR_IMG' => $poster_avatar,
1010 'PROFILE_IMG' => $profile_img,
1011 'PROFILE' => $profile,
1012 'SEARCH_IMG' => $search_img,
1013 'SEARCH' => $search,
1014 'PM_IMG' => $pm_img,
1016 'EMAIL_IMG' => $email_img,
1018 'WWW_IMG' => $www_img,
1020 'ICQ_STATUS_IMG' => $icq_status_img,
1021 'ICQ_IMG' => $icq_img,
1023 'AIM_IMG' => $aim_img,
1025 'MSN_IMG' => $msn_img,
1027 'YIM_IMG' => $yim_img,
1030 'U_VIEWPROFILE' => append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id"))
1033 if ( $is_moderator )
1035 $template->assign_block_vars('member_row.switch_mod_option', array());
1040 if ( !$members_count )
1045 $template->assign_block_vars('switch_no_members', array());
1046 $template->assign_vars(array(
1047 'L_NO_MEMBERS' => $lang['No_group_members'])
1051 $current_page = ( !$members_count ) ? 1 : ceil( $members_count / $board_config['topics_per_page'] );
1053 $template->assign_vars(array(
1054 'PAGINATION' => generate_pagination("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id", $members_count, $board_config['topics_per_page'], $start),
1055 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), $current_page ),
1057 'L_GOTO_PAGE' => $lang['Goto_page'])
1060 if ( $group_info['group_type'] == GROUP_HIDDEN && !$is_group_member && !$is_moderator )
1065 $template->assign_block_vars('switch_hidden_group', array());
1066 $template->assign_vars(array(
1067 'L_HIDDEN_MEMBERS' => $lang['Group_hidden_members'])
1072 // We've displayed the members who belong to the group, now we
1073 // do that pending memebers...
1075 if ( $is_moderator )
1078 // Users pending in ONLY THIS GROUP (which is moderated by this user)
1080 if ( $modgroup_pending_count )
1082 for($i = 0; $i < $modgroup_pending_count; $i++)
1084 $username = $modgroup_pending_list[$i]['username'];
1085 $user_id = $modgroup_pending_list[$i]['user_id'];
1087 generate_user_info($modgroup_pending_list[$i], $board_config['default_dateformat'], $is_moderator, $from, $posts, $joined, $poster_avatar, $profile_img, $profile, $search_img, $search, $pm_img, $pm, $email_img, $email, $www_img, $www, $icq_status_img, $icq_img, $icq, $aim_img, $aim, $msn_img, $msn, $yim_img, $yim);
1089 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1090 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1092 $user_select = '<input type="checkbox" name="member[]" value="' . $user_id . '">';
1094 $template->assign_block_vars('pending_members_row', array(
1095 'ROW_CLASS' => $row_class,
1096 'ROW_COLOR' => '#' . $row_color,
1097 'USERNAME' => $username,
1099 'JOINED' => $joined,
1101 'USER_ID' => $user_id,
1102 'AVATAR_IMG' => $poster_avatar,
1103 'PROFILE_IMG' => $profile_img,
1104 'PROFILE' => $profile,
1105 'SEARCH_IMG' => $search_img,
1106 'SEARCH' => $search,
1107 'PM_IMG' => $pm_img,
1109 'EMAIL_IMG' => $email_img,
1111 'WWW_IMG' => $www_img,
1113 'ICQ_STATUS_IMG' => $icq_status_img,
1114 'ICQ_IMG' => $icq_img,
1116 'AIM_IMG' => $aim_img,
1118 'MSN_IMG' => $msn_img,
1120 'YIM_IMG' => $yim_img,
1123 'U_VIEWPROFILE' => append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id"))
1127 $template->assign_block_vars('switch_pending_members', array() );
1129 $template->assign_vars(array(
1130 'L_SELECT' => $lang['Select'],
1131 'L_APPROVE_SELECTED' => $lang['Approve_selected'],
1132 'L_DENY_SELECTED' => $lang['Deny_selected'])
1135 $template->assign_var_from_handle('PENDING_USER_BOX', 'pendinginfo');
1140 if ( $is_moderator )
1142 $template->assign_block_vars('switch_mod_option', array());
1143 $template->assign_block_vars('switch_add_member', array());
1146 $template->pparse('info');
1151 // Show the main groupcp.php screen where the user can select a group.
1153 // Select all group that the user is a member of or where the user has
1154 // a pending membership.
1156 $in_group = array();
1158 if ( $userdata['session_logged_in'] )
1160 $sql = "SELECT g.group_id, g.group_name, g.group_type, ug.user_pending
1161 FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
1162 WHERE ug.user_id = " . $userdata['user_id'] . "
1163 AND ug.group_id = g.group_id
1164 AND g.group_single_user <> " . TRUE . "
1165 ORDER BY g.group_name, ug.user_id";
1166 if ( !($result = $db->sql_query($sql)) )
1168 message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
1171 if ( $row = $db->sql_fetchrow($result) )
1173 $in_group = array();
1174 $s_member_groups_opt = '';
1175 $s_pending_groups_opt = '';
1179 $in_group[] = $row['group_id'];
1180 if ( $row['user_pending'] )
1182 $s_pending_groups_opt .= '<option value="' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
1186 $s_member_groups_opt .= '<option value="' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
1189 while( $row = $db->sql_fetchrow($result) );
1191 $s_pending_groups = '<select name="' . POST_GROUPS_URL . '">' . $s_pending_groups_opt . "</select>";
1192 $s_member_groups = '<select name="' . POST_GROUPS_URL . '">' . $s_member_groups_opt . "</select>";
1197 // Select all other groups i.e. groups that this user is not a member of
1199 $ignore_group_sql = ( count($in_group) ) ? "AND group_id NOT IN (" . implode(', ', $in_group) . ")" : '';
1200 $sql = "SELECT group_id, group_name, group_type
1201 FROM " . GROUPS_TABLE . " g
1202 WHERE group_single_user <> " . TRUE . "
1204 ORDER BY g.group_name";
1205 if ( !($result = $db->sql_query($sql)) )
1207 message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
1210 $s_group_list_opt = '';
1211 while( $row = $db->sql_fetchrow($result) )
1213 if ( $row['group_type'] != GROUP_HIDDEN || $userdata['user_level'] == ADMIN )
1215 $s_group_list_opt .='<option value="' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
1218 $s_group_list = '<select name="' . POST_GROUPS_URL . '">' . $s_group_list_opt . '</select>';
1220 if ( $s_group_list_opt != '' || $s_pending_groups_opt != '' || $s_member_groups_opt != '' )
1223 // Load and process templates
1225 $page_title = $lang['Group_Control_Panel'];
1226 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1228 $template->set_filenames(array(
1229 'user' => 'groupcp_user_body.tpl')
1231 make_jumpbox('viewforum.'.$phpEx);
1233 if ( $s_pending_groups_opt != '' || $s_member_groups_opt != '' )
1235 $template->assign_block_vars('switch_groups_joined', array() );
1238 if ( $s_member_groups_opt != '' )
1240 $template->assign_block_vars('switch_groups_joined.switch_groups_member', array() );
1243 if ( $s_pending_groups_opt != '' )
1245 $template->assign_block_vars('switch_groups_joined.switch_groups_pending', array() );
1248 if ( $s_group_list_opt != '' )
1250 $template->assign_block_vars('switch_groups_remaining', array() );
1253 $s_hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
1255 $template->assign_vars(array(
1256 'L_GROUP_MEMBERSHIP_DETAILS' => $lang['Group_member_details'],
1257 'L_JOIN_A_GROUP' => $lang['Group_member_join'],
1258 'L_YOU_BELONG_GROUPS' => $lang['Current_memberships'],
1259 'L_SELECT_A_GROUP' => $lang['Non_member_groups'],
1260 'L_PENDING_GROUPS' => $lang['Memberships_pending'],
1261 'L_SUBSCRIBE' => $lang['Subscribe'],
1262 'L_UNSUBSCRIBE' => $lang['Unsubscribe'],
1263 'L_VIEW_INFORMATION' => $lang['View_Information'],
1265 'S_USERGROUP_ACTION' => append_sid("groupcp.$phpEx"),
1266 'S_HIDDEN_FIELDS' => $s_hidden_fields,
1268 'GROUP_LIST_SELECT' => $s_group_list,
1269 'GROUP_PENDING_SELECT' => $s_pending_groups,
1270 'GROUP_MEMBER_SELECT' => $s_member_groups)
1273 $template->pparse('user');
1277 message_die(GENERAL_MESSAGE, $lang['No_groups_exist']);
1282 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);