2 /***************************************************************************
5 * begin : Thursday, Jul 12, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_ranks.php,v 1.13.2.8 2006/04/13 09:56:48 grahamje Exp $
11 ***************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 ***************************************************************************/
22 if( !empty($setmodules) )
24 $file = basename(__FILE__);
25 $module['Users']['Ranks'] = $file;
29 define('IN_PHPBB', 1);
32 // Let's set the root dir for phpBB
34 $phpbb_root_path = "./../";
35 require($phpbb_root_path . 'extension.inc');
37 $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? true : false;
38 $no_page_header = $cancel;
40 require('./pagestart.' . $phpEx);
44 redirect('admin/' . append_sid("admin_ranks.$phpEx", true));
47 if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
49 $mode = (isset($HTTP_GET_VARS['mode'])) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
50 $mode = htmlspecialchars($mode);
55 // These could be entered via a form button
57 if( isset($HTTP_POST_VARS['add']) )
61 else if( isset($HTTP_POST_VARS['save']) )
71 // Restrict mode input to valid options
72 $mode = ( in_array($mode, array('add', 'edit', 'save', 'delete')) ) ? $mode : '';
76 if( $mode == "edit" || $mode == "add" )
79 // They want to add a new rank, show the form.
81 $rank_id = ( isset($HTTP_GET_VARS['id']) ) ? intval($HTTP_GET_VARS['id']) : 0;
83 $s_hidden_fields = "";
89 message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
92 $sql = "SELECT * FROM " . RANKS_TABLE . "
93 WHERE rank_id = $rank_id";
94 if(!$result = $db->sql_query($sql))
96 message_die(GENERAL_ERROR, "Couldn't obtain rank data", "", __LINE__, __FILE__, $sql);
99 $rank_info = $db->sql_fetchrow($result);
100 $s_hidden_fields .= '<input type="hidden" name="id" value="' . $rank_id . '" />';
105 $rank_info['rank_special'] = 0;
108 $s_hidden_fields .= '<input type="hidden" name="mode" value="save" />';
110 $rank_is_special = ( $rank_info['rank_special'] ) ? "checked=\"checked\"" : "";
111 $rank_is_not_special = ( !$rank_info['rank_special'] ) ? "checked=\"checked\"" : "";
113 $template->set_filenames(array(
114 "body" => "admin/ranks_edit_body.tpl")
117 $template->assign_vars(array(
118 "RANK" => $rank_info['rank_title'],
119 "SPECIAL_RANK" => $rank_is_special,
120 "NOT_SPECIAL_RANK" => $rank_is_not_special,
121 "MINIMUM" => ( $rank_is_special ) ? "" : $rank_info['rank_min'],
122 "IMAGE" => ( $rank_info['rank_image'] != "" ) ? $rank_info['rank_image'] : "",
123 "IMAGE_DISPLAY" => ( $rank_info['rank_image'] != "" ) ? '<img src="../' . $rank_info['rank_image'] . '" />' : "",
125 "L_RANKS_TITLE" => $lang['Ranks_title'],
126 "L_RANKS_TEXT" => $lang['Ranks_explain'],
127 "L_RANK_TITLE" => $lang['Rank_title'],
128 "L_RANK_SPECIAL" => $lang['Rank_special'],
129 "L_RANK_MINIMUM" => $lang['Rank_minimum'],
130 "L_RANK_IMAGE" => $lang['Rank_image'],
131 "L_RANK_IMAGE_EXPLAIN" => $lang['Rank_image_explain'],
132 "L_SUBMIT" => $lang['Submit'],
133 "L_RESET" => $lang['Reset'],
134 "L_YES" => $lang['Yes'],
135 "L_NO" => $lang['No'],
137 "S_RANK_ACTION" => append_sid("admin_ranks.$phpEx"),
138 "S_HIDDEN_FIELDS" => $s_hidden_fields)
142 else if( $mode == "save" )
145 // Ok, they sent us our info, let's update it.
148 $rank_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : 0;
149 $rank_title = ( isset($HTTP_POST_VARS['title']) ) ? trim($HTTP_POST_VARS['title']) : "";
150 $special_rank = ( $HTTP_POST_VARS['special_rank'] == 1 ) ? TRUE : 0;
151 $min_posts = ( isset($HTTP_POST_VARS['min_posts']) ) ? intval($HTTP_POST_VARS['min_posts']) : -1;
152 $rank_image = ( (isset($HTTP_POST_VARS['rank_image'])) ) ? trim($HTTP_POST_VARS['rank_image']) : "";
154 if( $rank_title == "" )
156 message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
159 if( $special_rank == 1 )
166 // The rank image has to be a jpg, gif or png
168 if($rank_image != "")
170 if ( !preg_match("/(\.gif|\.png|\.jpg)$/is", $rank_image))
180 $sql = "UPDATE " . USERS_TABLE . "
182 WHERE user_rank = $rank_id";
184 if( !$result = $db->sql_query($sql) )
186 message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
189 $sql = "UPDATE " . RANKS_TABLE . "
190 SET rank_title = '" . str_replace("\'", "''", $rank_title) . "', rank_special = $special_rank, rank_min = $min_posts, rank_image = '" . str_replace("\'", "''", $rank_image) . "'
191 WHERE rank_id = $rank_id";
193 $message = $lang['Rank_updated'];
197 $sql = "INSERT INTO " . RANKS_TABLE . " (rank_title, rank_special, rank_min, rank_image)
198 VALUES ('" . str_replace("\'", "''", $rank_title) . "', $special_rank, $min_posts, '" . str_replace("\'", "''", $rank_image) . "')";
200 $message = $lang['Rank_added'];
203 if( !$result = $db->sql_query($sql) )
205 message_die(GENERAL_ERROR, "Couldn't update/insert into ranks table", "", __LINE__, __FILE__, $sql);
208 $message .= "<br /><br />" . sprintf($lang['Click_return_rankadmin'], "<a href=\"" . append_sid("admin_ranks.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
210 message_die(GENERAL_MESSAGE, $message);
213 else if( $mode == "delete" )
216 // Ok, they want to delete their rank
219 if( isset($HTTP_POST_VARS['id']) || isset($HTTP_GET_VARS['id']) )
221 $rank_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : intval($HTTP_GET_VARS['id']);
228 $confirm = isset($HTTP_POST_VARS['confirm']);
230 if( $rank_id && $confirm )
232 $sql = "DELETE FROM " . RANKS_TABLE . "
233 WHERE rank_id = $rank_id";
235 if( !$result = $db->sql_query($sql) )
237 message_die(GENERAL_ERROR, "Couldn't delete rank data", "", __LINE__, __FILE__, $sql);
240 $sql = "UPDATE " . USERS_TABLE . "
242 WHERE user_rank = $rank_id";
244 if( !$result = $db->sql_query($sql) )
246 message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
249 $message = $lang['Rank_removed'] . "<br /><br />" . sprintf($lang['Click_return_rankadmin'], "<a href=\"" . append_sid("admin_ranks.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
251 message_die(GENERAL_MESSAGE, $message);
254 elseif( $rank_id && !$confirm)
256 // Present the confirmation screen to the user
257 $template->set_filenames(array(
258 'body' => 'admin/confirm_body.tpl')
261 $hidden_fields = '<input type="hidden" name="mode" value="delete" /><input type="hidden" name="id" value="' . $rank_id . '" />';
263 $template->assign_vars(array(
264 'MESSAGE_TITLE' => $lang['Confirm'],
265 'MESSAGE_TEXT' => $lang['Confirm_delete_rank'],
267 'L_YES' => $lang['Yes'],
268 'L_NO' => $lang['No'],
270 'S_CONFIRM_ACTION' => append_sid("admin_ranks.$phpEx"),
271 'S_HIDDEN_FIELDS' => $hidden_fields)
276 message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
280 $template->pparse("body");
282 include('./page_footer_admin.'.$phpEx);
286 // Show the default page
288 $template->set_filenames(array(
289 "body" => "admin/ranks_list_body.tpl")
292 $sql = "SELECT * FROM " . RANKS_TABLE . "
293 ORDER BY rank_min ASC, rank_special ASC";
294 if( !$result = $db->sql_query($sql) )
296 message_die(GENERAL_ERROR, "Couldn't obtain ranks data", "", __LINE__, __FILE__, $sql);
298 $rank_count = $db->sql_numrows($result);
300 $rank_rows = $db->sql_fetchrowset($result);
302 $template->assign_vars(array(
303 "L_RANKS_TITLE" => $lang['Ranks_title'],
304 "L_RANKS_TEXT" => $lang['Ranks_explain'],
305 "L_RANK" => $lang['Rank_title'],
306 "L_RANK_MINIMUM" => $lang['Rank_minimum'],
307 "L_SPECIAL_RANK" => $lang['Rank_special'],
308 "L_EDIT" => $lang['Edit'],
309 "L_DELETE" => $lang['Delete'],
310 "L_ADD_RANK" => $lang['Add_new_rank'],
311 "L_ACTION" => $lang['Action'],
313 "S_RANKS_ACTION" => append_sid("admin_ranks.$phpEx"))
316 for($i = 0; $i < $rank_count; $i++)
318 $rank = $rank_rows[$i]['rank_title'];
319 $special_rank = $rank_rows[$i]['rank_special'];
320 $rank_id = $rank_rows[$i]['rank_id'];
321 $rank_min = $rank_rows[$i]['rank_min'];
323 if( $special_rank == 1 )
325 $rank_min = $rank_max = "-";
328 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
329 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
331 $rank_is_special = ( $special_rank ) ? $lang['Yes'] : $lang['No'];
333 $template->assign_block_vars("ranks", array(
334 "ROW_COLOR" => "#" . $row_color,
335 "ROW_CLASS" => $row_class,
337 "SPECIAL_RANK" => $rank_is_special,
338 "RANK_MIN" => $rank_min,
340 "U_RANK_EDIT" => append_sid("admin_ranks.$phpEx?mode=edit&id=$rank_id"),
341 "U_RANK_DELETE" => append_sid("admin_ranks.$phpEx?mode=delete&id=$rank_id"))
345 $template->pparse("body");
347 include('./page_footer_admin.'.$phpEx);