(file) Return to admin_groups.php CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / phpBB2 / admin

  1 rizwank 1.1 <?php
  2             /***************************************************************************
  3              *                             admin_groups.php
  4              *                            -------------------
  5              *   begin                : Saturday, Feb 13, 2001
  6              *   copyright            : (C) 2001 The phpBB Group
  7              *   email                : support@phpbb.com
  8              *
  9              *   $Id: admin_groups.php,v 1.25.2.5 2002/07/31 19:14:46 dougk_ff7 Exp $
 10              *
 11              *
 12              ***************************************************************************/
 13             
 14             /***************************************************************************
 15              *
 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.
 20              *
 21              ***************************************************************************/
 22 rizwank 1.1 
 23             define('IN_PHPBB', 1);
 24             
 25             if ( !empty($setmodules) )
 26             {
 27             	$filename = basename(__FILE__);
 28             	$module['Groups']['Manage'] = $filename;
 29             
 30             	return;
 31             }
 32             
 33             //
 34             // Load default header
 35             //
 36             $phpbb_root_path = './../';
 37             require($phpbb_root_path . 'extension.inc');
 38             require('./pagestart.' . $phpEx);
 39             
 40             if ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) || isset($HTTP_GET_VARS[POST_GROUPS_URL]) )
 41             {
 42             	$group_id = ( isset($HTTP_POST_VARS[POST_GROUPS_URL]) ) ? intval($HTTP_POST_VARS[POST_GROUPS_URL]) : intval($HTTP_GET_VARS[POST_GROUPS_URL]);
 43 rizwank 1.1 }
 44             else
 45             {
 46             	$group_id = '';
 47             }
 48             
 49             if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
 50             {
 51             	$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
 52             }
 53             else
 54             {
 55             	$mode = '';
 56             }
 57             
 58             if ( isset($HTTP_POST_VARS['edit']) || isset($HTTP_POST_VARS['new']) )
 59             {
 60             	//
 61             	// Ok they are editing a group or creating a new group
 62             	//
 63             	$template->set_filenames(array(
 64 rizwank 1.1 		'body' => 'admin/group_edit_body.tpl')
 65             	);
 66             
 67             	if ( isset($HTTP_POST_VARS['edit']) )
 68             	{
 69             		//
 70             		// They're editing. Grab the vars.
 71             		//
 72             		$sql = "SELECT *
 73             			FROM " . GROUPS_TABLE . "
 74             			WHERE group_single_user <> " . TRUE . "
 75             			AND group_id = $group_id";
 76             		if ( !($result = $db->sql_query($sql)) )
 77             		{
 78             			message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
 79             		}
 80             
 81             		if ( !($group_info = $db->sql_fetchrow($result)) )
 82             		{
 83             			message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
 84             		}
 85 rizwank 1.1 
 86             		$mode = 'editgroup';
 87             		$template->assign_block_vars('group_edit', array());
 88             
 89             	}
 90             	else if ( isset($HTTP_POST_VARS['new']) )
 91             	{
 92             		$group_info = array (
 93             			'group_name' => '',
 94             			'group_description' => '',
 95             			'group_moderator' => '',
 96             			'group_type' => GROUP_OPEN);
 97             		$group_open = ' checked="checked"';
 98             
 99             		$mode = 'newgroup';
100             
101             	}
102             
103             	//
104             	// Ok, now we know everything about them, let's show the page.
105             	//
106 rizwank 1.1 	$sql = "SELECT user_id, username
107             		FROM " . USERS_TABLE . "
108             		WHERE user_id <> " . ANONYMOUS . "
109             		ORDER BY username";
110             	if ( !($result = $db->sql_query($sql)) )
111             	{
112             		message_die(GENERAL_ERROR, 'Could not obtain user info for moderator list', '', __LINE__, __FILE__, $sql);
113             	}
114             
115             	while ( $row = $db->sql_fetchrow($result) )
116             	{
117             		if ( $row['user_id'] == $group_info['group_moderator'] ) 
118             		{
119             			$group_moderator = $row['username'];
120             		}
121             	}
122             
123             	$group_open = ( $group_info['group_type'] == GROUP_OPEN ) ? ' checked="checked"' : '';
124             	$group_closed = ( $group_info['group_type'] == GROUP_CLOSED ) ? ' checked="checked"' : '';
125             	$group_hidden = ( $group_info['group_type'] == GROUP_HIDDEN ) ? ' checked="checked"' : '';
126             
127 rizwank 1.1 	$s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_GROUPS_URL . '" value="' . $group_id . '" />';
128             
129             	$template->assign_vars(array(
130             		'GROUP_NAME' => $group_info['group_name'],
131             		'GROUP_DESCRIPTION' => $group_info['group_description'], 
132             		'GROUP_MODERATOR' => $group_moderator, 
133             
134             		'L_GROUP_TITLE' => $lang['Group_administration'],
135             		'L_GROUP_EDIT_DELETE' => ( isset($HTTP_POST_VARS['new']) ) ? $lang['New_group'] : $lang['Edit_group'], 
136             		'L_GROUP_NAME' => $lang['group_name'],
137             		'L_GROUP_DESCRIPTION' => $lang['group_description'],
138             		'L_GROUP_MODERATOR' => $lang['group_moderator'], 
139             		'L_FIND_USERNAME' => $lang['Find_username'], 
140             		'L_GROUP_STATUS' => $lang['group_status'],
141             		'L_GROUP_OPEN' => $lang['group_open'],
142             		'L_GROUP_CLOSED' => $lang['group_closed'],
143             		'L_GROUP_HIDDEN' => $lang['group_hidden'],
144             		'L_GROUP_DELETE' => $lang['group_delete'],
145             		'L_GROUP_DELETE_CHECK' => $lang['group_delete_check'],
146             		'L_SUBMIT' => $lang['Submit'],
147             		'L_RESET' => $lang['Reset'],
148 rizwank 1.1 		'L_DELETE_MODERATOR' => $lang['delete_group_moderator'],
149             		'L_DELETE_MODERATOR_EXPLAIN' => $lang['delete_moderator_explain'],
150             		'L_YES' => $lang['Yes'],
151             
152             		'U_SEARCH_USER' => append_sid("../search.$phpEx?mode=searchuser"), 
153             
154             		'S_GROUP_OPEN_TYPE' => GROUP_OPEN,
155             		'S_GROUP_CLOSED_TYPE' => GROUP_CLOSED,
156             		'S_GROUP_HIDDEN_TYPE' => GROUP_HIDDEN,
157             		'S_GROUP_OPEN_CHECKED' => $group_open,
158             		'S_GROUP_CLOSED_CHECKED' => $group_closed,
159             		'S_GROUP_HIDDEN_CHECKED' => $group_hidden,
160             		'S_GROUP_ACTION' => append_sid("admin_groups.$phpEx"),
161             		'S_HIDDEN_FIELDS' => $s_hidden_fields)
162             	);
163             
164             	$template->pparse('body');
165             
166             }
167             else if ( isset($HTTP_POST_VARS['group_update']) )
168             {
169 rizwank 1.1 	//
170             	// Ok, they are submitting a group, let's save the data based on if it's new or editing
171             	//
172             	if ( isset($HTTP_POST_VARS['group_delete']) )
173             	{
174             		$sql = "DELETE FROM " . GROUPS_TABLE . "
175             			WHERE group_id = " . $group_id;
176             		if ( !$db->sql_query($sql) )
177             		{
178             			message_die(GENERAL_ERROR, 'Could not update group', '', __LINE__, __FILE__, $sql);
179             		}
180             
181             		$sql = "DELETE FROM " . USER_GROUP_TABLE . "
182             			WHERE group_id = " . $group_id;
183             		if ( !$db->sql_query($sql) )
184             		{
185             			message_die(GENERAL_ERROR, 'Could not update user_group', '', __LINE__, __FILE__, $sql);
186             		}
187             
188             		$sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
189             			WHERE group_id = " . $group_id;
190 rizwank 1.1 		if ( !$db->sql_query($sql) )
191             		{
192             			message_die(GENERAL_ERROR, 'Could not update auth_access', '', __LINE__, __FILE__, $sql);
193             		}
194             
195             		$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>');
196             
197             		message_die(GENERAL_MESSAGE, $message);
198             	}
199             	else
200             	{
201             		$group_type = isset($HTTP_POST_VARS['group_type']) ? intval($HTTP_POST_VARS['group_type']) : GROUP_OPEN;
202             		$group_name = isset($HTTP_POST_VARS['group_name']) ? trim($HTTP_POST_VARS['group_name']) : '';
203             		$group_description = isset($HTTP_POST_VARS['group_description']) ? trim($HTTP_POST_VARS['group_description']) : '';
204             		$group_moderator = isset($HTTP_POST_VARS['username']) ? $HTTP_POST_VARS['username'] : '';
205             		$delete_old_moderator = isset($HTTP_POST_VARS['delete_old_moderator']) ? true : false;
206             
207             		if ( $group_name == '' )
208             		{
209             			message_die(GENERAL_MESSAGE, $lang['No_group_name']);
210             		}
211 rizwank 1.1 		else if ( $group_moderator == '' )
212             		{
213             			message_die(GENERAL_MESSAGE, $lang['No_group_moderator']);
214             		}
215             		
216             		$this_userdata = get_userdata($group_moderator);
217             		$group_moderator = $this_userdata['user_id'];
218             
219             		if ( !$group_moderator )
220             		{
221             			message_die(GENERAL_MESSAGE, $lang['No_group_moderator']);
222             		}
223             				
224             		if( $mode == "editgroup" )
225             		{
226             			$sql = "SELECT *
227             				FROM " . GROUPS_TABLE . "
228             				WHERE group_single_user <> " . TRUE . "
229             				AND group_id = " . $group_id;
230             			if ( !($result = $db->sql_query($sql)) )
231             			{
232 rizwank 1.1 				message_die(GENERAL_ERROR, 'Error getting group information', '', __LINE__, __FILE__, $sql);
233             			}
234             
235             			if( !($group_info = $db->sql_fetchrow($result)) )
236             			{
237             				message_die(GENERAL_MESSAGE, $lang['Group_not_exist']);
238             			}
239             		
240             			if ( $group_info['group_moderator'] != $group_moderator )
241             			{
242             				if ( $delete_old_moderator )
243             				{
244             					$sql = "DELETE FROM " . USER_GROUP_TABLE . "
245             						WHERE user_id = " . $group_info['group_moderator'] . " 
246             							AND group_id = " . $group_id;
247             					if ( !$db->sql_query($sql) )
248             					{
249             						message_die(GENERAL_ERROR, 'Could not update group moderator', '', __LINE__, __FILE__, $sql);
250             					}
251             				}
252             
253 rizwank 1.1 				$sql = "SELECT user_id 
254             					FROM " . USER_GROUP_TABLE . " 
255             					WHERE user_id = $group_moderator 
256             						AND group_id = $group_id";
257             				if ( !($result = $db->sql_query($sql)) )
258             				{
259             					message_die(GENERAL_ERROR, 'Failed to obtain current group moderator info', '', __LINE__, __FILE__, $sql);
260             				}
261             
262             				if ( !($row = $db->sql_fetchrow($result)) )
263             				{
264             					$sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
265             						VALUES (" . $group_id . ", " . $group_moderator . ", 0)";
266             					if ( !$db->sql_query($sql) )
267             					{
268             						message_die(GENERAL_ERROR, 'Could not update group moderator', '', __LINE__, __FILE__, $sql);
269             					}
270             				}
271             			}
272             
273             			$sql = "UPDATE " . GROUPS_TABLE . "
274 rizwank 1.1 				SET group_type = $group_type, group_name = '" . str_replace("\'", "''", $group_name) . "', group_description = '" . str_replace("\'", "''", $group_description) . "', group_moderator = $group_moderator 
275             				WHERE group_id = $group_id";
276             			if ( !$db->sql_query($sql) )
277             			{
278             				message_die(GENERAL_ERROR, 'Could not update group', '', __LINE__, __FILE__, $sql);
279             			}
280             	
281             			$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>');;
282             
283             			message_die(GENERAL_MESSAGE, $message);
284             		}
285             		else if( $mode == 'newgroup' )
286             		{
287             			$sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user) 
288             				VALUES ($group_type, '" . str_replace("\'", "''", $group_name) . "', '" . str_replace("\'", "''", $group_description) . "', $group_moderator,	'0')";
289             			if ( !$db->sql_query($sql) )
290             			{
291             				message_die(GENERAL_ERROR, 'Could not insert new group', '', __LINE__, __FILE__, $sql);
292             			}
293             			$new_group_id = $db->sql_nextid();
294             
295 rizwank 1.1 			$sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
296             				VALUES ($new_group_id, $group_moderator, 0)";
297             			if ( !$db->sql_query($sql) )
298             			{
299             				message_die(GENERAL_ERROR, 'Could not insert new user-group info', '', __LINE__, __FILE__, $sql);
300             			}
301             			
302             			$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>');;
303             
304             			message_die(GENERAL_MESSAGE, $message);
305             
306             		}
307             		else
308             		{
309             			message_die(GENERAL_MESSAGE, $lang['No_group_action']);
310             		}
311             	}
312             }
313             else
314             {
315             	$sql = "SELECT group_id, group_name
316 rizwank 1.1 		FROM " . GROUPS_TABLE . "
317             		WHERE group_single_user <> " . TRUE . "
318             		ORDER BY group_name";
319             	if ( !($result = $db->sql_query($sql)) )
320             	{
321             		message_die(GENERAL_ERROR, 'Could not obtain group list', '', __LINE__, __FILE__, $sql);
322             	}
323             
324             	$select_list = '';
325             	if ( $row = $db->sql_fetchrow($result) )
326             	{
327             		$select_list .= '<select name="' . POST_GROUPS_URL . '">';
328             		do
329             		{
330             			$select_list .= '<option value="' . $row['group_id'] . '">' . $row['group_name'] . '</option>';
331             		}
332             		while ( $row = $db->sql_fetchrow($result) );
333             		$select_list .= '</select>';
334             	}
335             
336             	$template->set_filenames(array(
337 rizwank 1.1 		'body' => 'admin/group_select_body.tpl')
338             	);
339             
340             	$template->assign_vars(array(
341             		'L_GROUP_TITLE' => $lang['Group_administration'],
342             		'L_GROUP_EXPLAIN' => $lang['Group_admin_explain'],
343             		'L_GROUP_SELECT' => $lang['Select_group'],
344             		'L_LOOK_UP' => $lang['Look_up_group'],
345             		'L_CREATE_NEW_GROUP' => $lang['New_group'],
346             
347             		'S_GROUP_ACTION' => append_sid("admin_groups.$phpEx"),
348             		'S_GROUP_SELECT' => $select_list)
349             	);
350             
351             	if ( $select_list != '' )
352             	{
353             		$template->assign_block_vars('select_box', array());
354             	}
355             
356             	$template->pparse('body');
357             }
358 rizwank 1.1 
359             include('./page_footer_admin.'.$phpEx);
360             
361             ?>

Rizwan Kassim
Powered by
ViewCVS 0.9.2