PageRenderTime 31ms CodeModel.GetById 2ms app.highlight 23ms RepoModel.GetById 2ms app.codeStats 0ms

/upload/admin/admin_groups.php

http://torrentpier2.googlecode.com/
PHP | 186 lines | 150 code | 27 blank | 9 comment | 28 complexity | b64af79356f6da36f35b8796758992c2 MD5 | raw file
  1<?php
  2
  3// ACP Header - START
  4if (!empty($setmodules))
  5{
  6	$module['Groups']['Manage'] = basename(__FILE__);
  7	return;
  8}
  9require('./pagestart.php');
 10// ACP Header - END
 11
 12require(INC_DIR .'functions_group.php');
 13
 14$group_id = isset($_REQUEST[POST_GROUPS_URL]) ? intval($_REQUEST[POST_GROUPS_URL]) : 0;
 15$mode     = isset($_REQUEST['mode']) ? strval($_REQUEST['mode']) : '';
 16
 17attachment_quota_settings('group', isset($_POST['group_update']), $mode);
 18
 19if (!empty($_POST['edit']) || !empty($_POST['new']))
 20{
 21	if (!empty($_POST['edit']))
 22	{
 23		if (!$row = get_group_data($group_id))
 24		{
 25			bb_die($lang['GROUP_NOT_EXIST']);
 26		}
 27		$group_info = array(
 28			'group_name'        => $row['group_name'],
 29			'group_description' => $row['group_description'],
 30			'group_moderator'   => $row['group_moderator'],
 31			'group_mod_name'    => $row['moderator_name'],
 32			'group_type'        => $row['group_type'],
 33		);
 34		$mode = 'editgroup';
 35		$template->assign_block_vars('group_edit', array());
 36	}
 37	else if (!empty($_POST['new']))
 38	{
 39		$group_info = array(
 40			'group_name'        => '',
 41			'group_description' => '',
 42			'group_moderator'   => '',
 43			'group_mod_name'    => '',
 44			'group_type'        => GROUP_OPEN,
 45		);
 46		$mode = 'newgroup';
 47	}
 48
 49	// Ok, now we know everything about them, let's show the page.
 50	$s_hidden_fields = '
 51		<input type="hidden" name="mode" value="'. $mode .'" />
 52		<input type="hidden" name="'. POST_GROUPS_URL .'" value="'. $group_id .'" />
 53	';
 54
 55	$template->assign_vars(array(
 56		'TPL_EDIT_GROUP'         => true,
 57
 58		'GROUP_NAME'             => stripslashes(htmlspecialchars($group_info['group_name'])),
 59		'GROUP_DESCRIPTION'      => stripslashes(htmlspecialchars($group_info['group_description'])),
 60		'GROUP_MODERATOR'        => replace_quote($group_info['group_mod_name']),
 61		'T_GROUP_EDIT_DELETE'    => ($mode == 'newgroup') ? $lang['CREATE_NEW_GROUP'] : $lang['EDIT_GROUP'],
 62		'U_SEARCH_USER'          => BB_ROOT ."search.php?mode=searchuser",
 63		'S_GROUP_OPEN_TYPE'      => GROUP_OPEN,
 64		'S_GROUP_CLOSED_TYPE'    => GROUP_CLOSED,
 65		'S_GROUP_HIDDEN_TYPE'    => GROUP_HIDDEN,
 66		'S_GROUP_OPEN_CHECKED'   => ($group_info['group_type'] == GROUP_OPEN) ? HTML_CHECKED : '',
 67		'S_GROUP_CLOSED_CHECKED' => ($group_info['group_type'] == GROUP_CLOSED) ? HTML_CHECKED : '',
 68		'S_GROUP_HIDDEN_CHECKED' => ($group_info['group_type'] == GROUP_HIDDEN ) ? HTML_CHECKED : '',
 69		'S_GROUP_ACTION'         => "admin_groups.php",
 70		'S_HIDDEN_FIELDS'        => $s_hidden_fields,
 71	));
 72}
 73else if (!empty($_POST['group_update']))
 74{
 75	if (!empty($_POST['group_delete']))
 76	{
 77		if (!$group_info = get_group_data($group_id))
 78		{
 79			bb_die($lang['GROUP_NOT_EXIST']);
 80		}
 81		// Delete Group
 82		delete_group($group_id);
 83
 84		$message = $lang['DELETED_GROUP'] .'<br /><br />';
 85		$message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '<a href="admin_groups.php">', '</a>') .'<br /><br />';
 86		$message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>');
 87
 88		bb_die($message);
 89	}
 90	else
 91	{
 92		$group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN;
 93		$group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : '';
 94		$group_desc = isset($_POST['group_description']) ? trim($_POST['group_description']) : '';
 95
 96		$group_moderator = isset($_POST['username']) ? $_POST['username'] : '';
 97
 98		if ($group_name === '')
 99		{
100			bb_die($lang['NO_GROUP_NAME']);
101		}
102		else if ($group_moderator === '')
103		{
104			bb_die($lang['NO_GROUP_MODERATOR']);
105		}
106		$this_userdata = get_userdata($group_moderator, true);
107
108		if (!$group_moderator = $this_userdata['user_id'])
109		{
110			bb_die($lang['NO_GROUP_MODERATOR']);
111		}
112
113		$sql_ary = array(
114			'group_type'        => (int) $group_type,
115			'group_name'        => (string) $group_name,
116			'group_description' => (string) $group_desc,
117			'group_moderator'   => (int) $group_moderator,
118			'group_single_user' => 0,
119		);
120
121		if ($mode == "editgroup")
122		{
123			if (!$group_info = get_group_data($group_id))
124			{
125				bb_die($lang['GROUP_NOT_EXIST']);
126			}
127
128			if ($group_info['group_moderator'] != $group_moderator)
129			{
130				// Create user_group for new group's moderator
131				add_user_into_group($group_id, $group_moderator);
132                $sql_ary['group_time']  = TIMENOW;
133
134				// Delete old moderator's user_group
135				if (isset($_POST['delete_old_moderator']))
136				{
137					delete_user_group($group_id, $group_info['group_moderator']);
138				}
139			}
140
141			$sql_args = DB()->build_array('UPDATE', $sql_ary);
142
143			// Update group's data
144			DB()->query("UPDATE ". BB_GROUPS ." SET $sql_args WHERE group_id = $group_id");
145
146			$message = $lang['UPDATED_GROUP'] .'<br /><br />';
147			$message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '<a href="admin_groups.php">', '</a>') .'<br /><br />';
148			$message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>');
149
150			bb_die($message);
151		}
152		else if ($mode == 'newgroup')
153		{
154			$sql_ary['group_time']  = TIMENOW;
155			$sql_args = DB()->build_array('INSERT', $sql_ary);
156
157			// Create new group
158			DB()->query("INSERT INTO ". BB_GROUPS ." $sql_args");
159			$new_group_id = DB()->sql_nextid();
160
161			// Create user_group for group's moderator
162			add_user_into_group($new_group_id, $group_moderator);
163
164			$message = $lang['ADDED_NEW_GROUP'] .'<br /><br />';
165			$message .= sprintf($lang['CLICK_RETURN_GROUPSADMIN'], '<a href="admin_groups.php">', '</a>') .'<br /><br />';
166			$message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>');
167
168			bb_die($message);
169		}
170		else
171		{
172			bb_die($lang['NO_GROUP_ACTION']);
173		}
174	}
175}
176else
177{
178	$template->assign_vars(array(
179		'TPL_GROUP_SELECT' => true,
180
181		'S_GROUP_ACTION'   => "admin_groups.php",
182		'S_GROUP_SELECT'   => stripslashes(get_select('groups')),
183	));
184}
185
186print_page('admin_groups.tpl', 'admin');