2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_groups.php,v 1.25.2.9 2004/03/25 15:57:20 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', 1);
25 if ( !empty($setmodules) )
27 $filename = basename(__FILE__);
28 $module['Groups']['Manage'] = $filename;
34 // Load default header
36 $phpbb_root_path = './../';
37 require($phpbb_root_path . 'extension.inc');
38 require('./pagestart.' . $phpEx);
40 if ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) || isset($HTTP_GET_VARS[POST_GROUPS_URL]) )
42 $group_id = ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) ) ? intval($HTTP_POST_VARS[POST_GROUPS_URL]) : intval($HTTP_GET_VARS[POST_GROUPS_URL]);
49 if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
51 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
52 $mode = htmlspecialchars($mode);
59 if ( isset($HTTP_POST_VARS['edit']) || isset($HTTP_POST_VARS['new']) )
62 // Ok they are editing a group or creating a new group
64 $template->set_filenames(array(
65 'body' => 'admin/group_edit_body.tpl')
68 if ( isset($HTTP_POST_VARS['edit']) )
71 // They're editing. Grab the vars.
74 FROM " . GROUPS_TABLE . "
75 WHERE group_single_user <> " . TRUE . "
76 AND group_id = $group_id";
77 if ( !($result = $db->sql_query($sql)) )
79 message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
82 if ( !($group_info = $db->sql_fetchrow($result)) )
84 message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
88 $template->assign_block_vars('group_edit', array());
91 else if ( isset($HTTP_POST_VARS['new']) )
95 'group_description' => '',
96 'group_moderator' => '',
97 'group_type' => GROUP_OPEN);
98 $group_open = ' checked="checked"';
105 // Ok, now we know everything about them, let's show the page.
107 $sql = "SELECT user_id, username
108 FROM " . USERS_TABLE . "
109 WHERE user_id <> " . ANONYMOUS . "
111 if ( !($result = $db->sql_query($sql)) )
113 message_die(GENERAL_ERROR, 'Could not obtain user info for moderator list', '', __LINE__, __FILE__, $sql);
116 while ( $row = $db->sql_fetchrow($result) )
118 if ( $row['user_id'] == $group_info['group_moderator'] )
120 $group_moderator = $row['username'];
124 $group_open = ( $group_info['group_type'] == GROUP_OPEN ) ? ' checked="checked"' : '';
125 $group_closed = ( $group_info['group_type'] == GROUP_CLOSED ) ? ' checked="checked"' : '';
126 $group_hidden = ( $group_info['group_type'] == GROUP_HIDDEN ) ? ' checked="checked"' : '';
128 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_GROUPS_URL . '" value="' . $group_id . '" />';
130 $template->assign_vars(array(
131 'GROUP_NAME' => $group_info['group_name'],
132 'GROUP_DESCRIPTION' => $group_info['group_description'],
133 'GROUP_MODERATOR' => $group_moderator,
135 'L_GROUP_TITLE' => $lang['Group_administration'],
136 'L_GROUP_EDIT_DELETE' => ( isset($HTTP_POST_VARS['new']) ) ? $lang['New_group'] : $lang['Edit_group'],
137 'L_GROUP_NAME' => $lang['group_name'],
138 'L_GROUP_DESCRIPTION' => $lang['group_description'],
139 'L_GROUP_MODERATOR' => $lang['group_moderator'],
140 'L_FIND_USERNAME' => $lang['Find_username'],
141 'L_GROUP_STATUS' => $lang['group_status'],
142 'L_GROUP_OPEN' => $lang['group_open'],
143 'L_GROUP_CLOSED' => $lang['group_closed'],
144 'L_GROUP_HIDDEN' => $lang['group_hidden'],
145 'L_GROUP_DELETE' => $lang['group_delete'],
146 'L_GROUP_DELETE_CHECK' => $lang['group_delete_check'],
147 'L_SUBMIT' => $lang['Submit'],
148 'L_RESET' => $lang['Reset'],
149 'L_DELETE_MODERATOR' => $lang['delete_group_moderator'],
150 'L_DELETE_MODERATOR_EXPLAIN' => $lang['delete_moderator_explain'],
151 'L_YES' => $lang['Yes'],
153 'U_SEARCH_USER' => append_sid("../search.$phpEx?mode=searchuser"),
155 'S_GROUP_OPEN_TYPE' => GROUP_OPEN,
156 'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED,
157 'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN,
158 'S_GROUP_OPEN_CHECKED' => $group_open,
159 'S_GROUP_CLOSED_CHECKED' => $group_closed,
160 'S_GROUP_HIDDEN_CHECKED' => $group_hidden,
161 'S_GROUP_ACTION' => append_sid("admin_groups.$phpEx"),
162 'S_HIDDEN_FIELDS' => $s_hidden_fields)
165 $template->pparse('body');
168 else if ( isset($HTTP_POST_VARS['group_update']) )
171 // Ok, they are submitting a group, let's save the data based on if it's new or editing
173 if ( isset($HTTP_POST_VARS['group_delete']) )
176 // Reset User Moderator Level
179 // Is Group moderating a forum ?
180 $sql = "SELECT auth_mod FROM " . AUTH_ACCESS_TABLE . "
181 WHERE group_id = " . $group_id;
182 if ( !($result = $db->sql_query($sql)) )
184 message_die(GENERAL_ERROR, 'Could not select auth_access', '', __LINE__, __FILE__, $sql);
187 $row = $db->sql_fetchrow($result);
188 if (intval($row['auth_mod']) == 1)
190 // Yes, get the assigned users and update their Permission if they are no longer moderator of one of the forums
191 $sql = "SELECT user_id FROM " . USER_GROUP_TABLE . "
192 WHERE group_id = " . $group_id;
193 if ( !($result = $db->sql_query($sql)) )
195 message_die(GENERAL_ERROR, 'Could not select user_group', '', __LINE__, __FILE__, $sql);
198 $rows = $db->sql_fetchrowset($result);
199 for ($i = 0; $i < count($rows); $i++)
201 $sql = "SELECT g.group_id FROM " . AUTH_ACCESS_TABLE . " a, " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
202 WHERE (a.auth_mod = 1) AND (g.group_id = a.group_id) AND (a.group_id = ug.group_id) AND (g.group_id = ug.group_id)
203 AND (ug.user_id = " . intval($rows[$i]['user_id']) . ") AND (ug.group_id <> " . $group_id . ")";
204 if ( !($result = $db->sql_query($sql)) )
206 message_die(GENERAL_ERROR, 'Could not obtain moderator permissions', '', __LINE__, __FILE__, $sql);
209 if ($db->sql_numrows($result) == 0)
211 $sql = "UPDATE " . USERS_TABLE . " SET user_level = " . USER . "
212 WHERE user_level = " . MOD . " AND user_id = " . intval($rows[$i]['user_id']);
214 if ( !$db->sql_query($sql) )
216 message_die(GENERAL_ERROR, 'Could not update moderator permissions', '', __LINE__, __FILE__, $sql);
225 $sql = "DELETE FROM " . GROUPS_TABLE . "
226 WHERE group_id = " . $group_id;
227 if ( !$db->sql_query($sql) )
229 message_die(GENERAL_ERROR, 'Could not update group', '', __LINE__, __FILE__, $sql);
232 $sql = "DELETE FROM " . USER_GROUP_TABLE . "
233 WHERE group_id = " . $group_id;
234 if ( !$db->sql_query($sql) )
236 message_die(GENERAL_ERROR, 'Could not update user_group', '', __LINE__, __FILE__, $sql);
239 $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
240 WHERE group_id = " . $group_id;
241 if ( !$db->sql_query($sql) )
243 message_die(GENERAL_ERROR, 'Could not update auth_access', '', __LINE__, __FILE__, $sql);
246 $message = $lang['Deleted_group'] . '<br /><br />' . sprintf($lang['Click_return_groupsadmin'], '<a href="' . append_sid("admin_groups.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
248 message_die(GENERAL_MESSAGE, $message);
252 $group_type = isset($HTTP_POST_VARS['group_type']) ? intval($HTTP_POST_VARS['group_type']) : GROUP_OPEN;
253 $group_name = isset($HTTP_POST_VARS['group_name']) ? trim($HTTP_POST_VARS['group_name']) : '';
254 $group_description = isset($HTTP_POST_VARS['group_description']) ? trim($HTTP_POST_VARS['group_description']) : '';
255 $group_moderator = isset($HTTP_POST_VARS['username']) ? $HTTP_POST_VARS['username'] : '';
256 $delete_old_moderator = isset($HTTP_POST_VARS['delete_old_moderator']) ? true : false;
258 if ( $group_name == '' )
260 message_die(GENERAL_MESSAGE, $lang['No_group_name']);
262 else if ( $group_moderator == '' )
264 message_die(GENERAL_MESSAGE, $lang['No_group_moderator']);
267 $this_userdata = get_userdata($group_moderator, true);
268 $group_moderator = $this_userdata['user_id'];
270 if ( !$group_moderator )
272 message_die(GENERAL_MESSAGE, $lang['No_group_moderator']);
275 if( $mode == "editgroup" )
278 FROM " . GROUPS_TABLE . "
279 WHERE group_single_user <> " . TRUE . "
280 AND group_id = " . $group_id;
281 if ( !($result = $db->sql_query($sql)) )
283 message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
286 if( !($group_info = $db->sql_fetchrow($result)) )
288 message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
291 if ( $group_info['group_moderator'] != $group_moderator )
293 if ( $delete_old_moderator )
295 $sql = "DELETE FROM " . USER_GROUP_TABLE . "
296 WHERE user_id = " . $group_info['group_moderator'] . "
297 AND group_id = " . $group_id;
298 if ( !$db->sql_query($sql) )
300 message_die(GENERAL_ERROR, 'Could not update group moderator', '', __LINE__, __FILE__, $sql);
304 $sql = "SELECT user_id
305 FROM " . USER_GROUP_TABLE . "
306 WHERE user_id = $group_moderator
307 AND group_id = $group_id";
308 if ( !($result = $db->sql_query($sql)) )
310 message_die(GENERAL_ERROR, 'Failed to obtain current group moderator info', '', __LINE__, __FILE__, $sql);
313 if ( !($row = $db->sql_fetchrow($result)) )
315 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
316 VALUES (" . $group_id . ", " . $group_moderator . ", 0)";
317 if ( !$db->sql_query($sql) )
319 message_die(GENERAL_ERROR, 'Could not update group moderator', '', __LINE__, __FILE__, $sql);
324 $sql = "UPDATE " . GROUPS_TABLE . "
325 SET group_type = $group_type, group_name = '" . str_replace("\'", "''", $group_name) . "', group_description = '" . str_replace("\'", "''", $group_description) . "', group_moderator = $group_moderator
326 WHERE group_id = $group_id";
327 if ( !$db->sql_query($sql) )
329 message_die(GENERAL_ERROR, 'Could not update group', '', __LINE__, __FILE__, $sql);
332 $message = $lang['Updated_group'] . '<br /><br />' . sprintf($lang['Click_return_groupsadmin'], '<a href="' . append_sid("admin_groups.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');;
334 message_die(GENERAL_MESSAGE, $message);
336 else if( $mode == 'newgroup' )
338 $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user)
339 VALUES ($group_type, '" . str_replace("\'", "''", $group_name) . "', '" . str_replace("\'", "''", $group_description) . "', $group_moderator, '0')";
340 if ( !$db->sql_query($sql) )
342 message_die(GENERAL_ERROR, 'Could not insert new group', '', __LINE__, __FILE__, $sql);
344 $new_group_id = $db->sql_nextid();
346 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
347 VALUES ($new_group_id, $group_moderator, 0)";
348 if ( !$db->sql_query($sql) )
350 message_die(GENERAL_ERROR, 'Could not insert new user-group info', '', __LINE__, __FILE__, $sql);
353 $message = $lang['Added_new_group'] . '<br /><br />' . sprintf($lang['Click_return_groupsadmin'], '<a href="' . append_sid("admin_groups.$phpEx") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');;
355 message_die(GENERAL_MESSAGE, $message);
360 message_die(GENERAL_MESSAGE, $lang['No_group_action']);
366 $sql = "SELECT group_id, group_name
367 FROM " . GROUPS_TABLE . "
368 WHERE group_single_user <> " . TRUE . "
369 ORDER BY group_name";
370 if ( !($result = $db->sql_query($sql)) )
372 message_die(GENERAL_ERROR, 'Could not obtain group list', '', __LINE__, __FILE__, $sql);
376 if ( $row = $db->sql_fetchrow($result) )
378 $select_list .= '<select name="' . POST_GROUPS_URL . '">';
381 $select_list .= '<option value="' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
383 while ( $row = $db->sql_fetchrow($result) );
384 $select_list .= '</select>';
387 $template->set_filenames(array(
388 'body' => 'admin/group_select_body.tpl')
391 $template->assign_vars(array(
392 'L_GROUP_TITLE' => $lang['Group_administration'],
393 'L_GROUP_EXPLAIN' => $lang['Group_admin_explain'],
394 'L_GROUP_SELECT' => $lang['Select_group'],
395 'L_LOOK_UP' => $lang['Look_up_group'],
396 'L_CREATE_NEW_GROUP' => $lang['New_group'],
398 'S_GROUP_ACTION' => append_sid("admin_groups.$phpEx"),
399 'S_GROUP_SELECT' => $select_list)
402 if ( $select_list != '' )
404 $template->assign_block_vars('select_box', array());
407 $template->pparse('body');
410 include('./page_footer_admin.'.$phpEx);