5
* @version $Id: acp_ranks.php,v 1.18 2007/10/14 10:07:52 kellanved Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
26
function main($id, $mode)
28
global $db, $user, $auth, $template, $cache;
29
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
31
$user->add_lang('acp/posting');
33
// Set up general vars
34
$action = request_var('action', '');
35
$action = (isset($_POST['add'])) ? 'add' : $action;
36
$action = (isset($_POST['save'])) ? 'save' : $action;
37
$rank_id = request_var('id', 0);
39
$this->tpl_name = 'acp_ranks';
40
$this->page_title = 'ACP_MANAGE_RANKS';
42
$form_name = 'acp_prune';
43
add_form_key($form_name);
49
if (!check_form_key($form_name))
51
trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
53
$rank_title = utf8_normalize_nfc(request_var('title', '', true));
54
$special_rank = request_var('special_rank', 0);
55
$min_posts = ($special_rank) ? 0 : request_var('min_posts', 0);
56
$rank_image = request_var('rank_image', '');
58
// The rank image has to be a jpg, gif or png
59
if ($rank_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $rank_image))
66
trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
70
'rank_title' => $rank_title,
71
'rank_special' => $special_rank,
72
'rank_min' => $min_posts,
73
'rank_image' => htmlspecialchars_decode($rank_image)
78
$sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id";
79
$message = $user->lang['RANK_UPDATED'];
81
add_log('admin', 'LOG_RANK_UPDATED', $rank_title);
85
$sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
86
$message = $user->lang['RANK_ADDED'];
88
add_log('admin', 'LOG_RANK_ADDED', $rank_title);
92
$cache->destroy('_ranks');
94
trigger_error($message . adm_back_link($this->u_action));
102
trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING);
105
if (confirm_box(true))
107
$sql = 'SELECT rank_title
108
FROM ' . RANKS_TABLE . '
109
WHERE rank_id = ' . $rank_id;
110
$result = $db->sql_query($sql);
111
$rank_title = (string) $db->sql_fetchfield('rank_title');
112
$db->sql_freeresult($result);
114
$sql = 'DELETE FROM ' . RANKS_TABLE . "
115
WHERE rank_id = $rank_id";
116
$db->sql_query($sql);
118
$sql = 'UPDATE ' . USERS_TABLE . "
120
WHERE user_rank = $rank_id";
121
$db->sql_query($sql);
123
$cache->destroy('_ranks');
125
add_log('admin', 'LOG_RANK_REMOVED', $rank_title);
129
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
132
'rank_id' => $rank_id,
133
'action' => 'delete',
142
$data = $ranks = $existing_imgs = array();
145
FROM ' . RANKS_TABLE . '
146
ORDER BY rank_min ASC, rank_special ASC';
147
$result = $db->sql_query($sql);
149
while ($row = $db->sql_fetchrow($result))
151
$existing_imgs[] = $row['rank_image'];
153
if ($action == 'edit' && $rank_id == $row['rank_id'])
158
$db->sql_freeresult($result);
160
$imglist = filelist($phpbb_root_path . $config['ranks_path'], '');
161
$edit_img = $filename_list = '';
163
foreach ($imglist as $path => $img_ary)
167
foreach ($img_ary as $img)
171
if (!in_array($img, $existing_imgs) || $action == 'edit')
173
if ($ranks && $img == $ranks['rank_image'])
175
$selected = ' selected="selected"';
183
if (strlen($img) > 255)
188
$filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>';
193
$filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list;
194
unset($existing_imgs, $imglist);
196
$template->assign_vars(array(
198
'U_BACK' => $this->u_action,
199
'RANKS_PATH' => $phpbb_root_path . $config['ranks_path'],
200
'U_ACTION' => $this->u_action . '&id=' . $rank_id,
202
'RANK_TITLE' => (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '',
203
'S_FILENAME_LIST' => $filename_list,
204
'RANK_IMAGE' => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif',
205
'S_SPECIAL_RANK' => (!isset($ranks['rank_special']) || $ranks['rank_special']) ? true : false,
206
'MIN_POSTS' => (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0)
215
$template->assign_vars(array(
216
'U_ACTION' => $this->u_action)
220
FROM ' . RANKS_TABLE . '
221
ORDER BY rank_special DESC, rank_min ASC, rank_title ASC';
222
$result = $db->sql_query($sql);
224
while ($row = $db->sql_fetchrow($result))
226
$template->assign_block_vars('ranks', array(
227
'S_RANK_IMAGE' => ($row['rank_image']) ? true : false,
228
'S_SPECIAL_RANK' => ($row['rank_special']) ? true : false,
230
'RANK_IMAGE' => $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'],
231
'RANK_TITLE' => $row['rank_title'],
232
'MIN_POSTS' => $row['rank_min'],
234
'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['rank_id'],
235
'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['rank_id'])
238
$db->sql_freeresult($result);
b'\\ No newline at end of file'