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.4 2004/03/25 15:57:20 acydburn 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 define('IN_PHPBB', 1);
24 if( !empty($setmodules) )
26 $file = basename(__FILE__);
27 $module['Users']['Ranks'] = "$file";
32 // Let's set the root dir for phpBB
34 $phpbb_root_path = "./../";
35 require($phpbb_root_path . 'extension.inc');
36 require('./pagestart.' . $phpEx);
38 if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
40 $mode = ($HTTP_GET_VARS['mode']) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
41 $mode = htmlspecialchars($mode);
46 // These could be entered via a form button
48 if( isset($HTTP_POST_VARS['add']) )
52 else if( isset($HTTP_POST_VARS['save']) )
65 if( $mode == "edit" || $mode == "add" )
68 // They want to add a new rank, show the form.
70 $rank_id = ( isset($HTTP_GET_VARS['id']) ) ? intval($HTTP_GET_VARS['id']) : 0;
72 $s_hidden_fields = "";
78 message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
81 $sql = "SELECT * FROM " . RANKS_TABLE . "
82 WHERE rank_id = $rank_id";
83 if(!$result = $db->sql_query($sql))
85 message_die(GENERAL_ERROR, "Couldn't obtain rank data", "", __LINE__, __FILE__, $sql);
88 $rank_info = $db->sql_fetchrow($result);
89 $s_hidden_fields .= '<input type="hidden" name="id" value="' . $rank_id . '" />';
94 $rank_info['rank_special'] = 0;
97 $s_hidden_fields .= '<input type="hidden" name="mode" value="save" />';
99 $rank_is_special = ( $rank_info['rank_special'] ) ? "checked=\"checked\"" : "";
100 $rank_is_not_special = ( !$rank_info['rank_special'] ) ? "checked=\"checked\"" : "";
102 $template->set_filenames(array(
103 "body" => "admin/ranks_edit_body.tpl")
106 $template->assign_vars(array(
107 "RANK" => $rank_info['rank_title'],
108 "SPECIAL_RANK" => $rank_is_special,
109 "NOT_SPECIAL_RANK" => $rank_is_not_special,
110 "MINIMUM" => ( $rank_is_special ) ? "" : $rank_info['rank_min'],
111 "IMAGE" => ( $rank_info['rank_image'] != "" ) ? $rank_info['rank_image'] : "",
112 "IMAGE_DISPLAY" => ( $rank_info['rank_image'] != "" ) ? '<img src="../' . $rank_info['rank_image'] . '" />' : "",
114 "L_RANKS_TITLE" => $lang['Ranks_title'],
115 "L_RANKS_TEXT" => $lang['Ranks_explain'],
116 "L_RANK_TITLE" => $lang['Rank_title'],
117 "L_RANK_SPECIAL" => $lang['Rank_special'],
118 "L_RANK_MINIMUM" => $lang['Rank_minimum'],
119 "L_RANK_IMAGE" => $lang['Rank_image'],
120 "L_RANK_IMAGE_EXPLAIN" => $lang['Rank_image_explain'],
121 "L_SUBMIT" => $lang['Submit'],
122 "L_RESET" => $lang['Reset'],
123 "L_YES" => $lang['Yes'],
124 "L_NO" => $lang['No'],
126 "S_RANK_ACTION" => append_sid("admin_ranks.$phpEx"),
127 "S_HIDDEN_FIELDS" => $s_hidden_fields)
131 else if( $mode == "save" )
134 // Ok, they sent us our info, let's update it.
137 $rank_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : 0;
138 $rank_title = ( isset($HTTP_POST_VARS['title']) ) ? trim($HTTP_POST_VARS['title']) : "";
139 $special_rank = ( $HTTP_POST_VARS['special_rank'] == 1 ) ? TRUE : 0;
140 $min_posts = ( isset($HTTP_POST_VARS['min_posts']) ) ? intval($HTTP_POST_VARS['min_posts']) : -1;
141 $rank_image = ( (isset($HTTP_POST_VARS['rank_image'])) ) ? trim($HTTP_POST_VARS['rank_image']) : "";
143 if( $rank_title == "" )
145 message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
148 if( $special_rank == 1 )
155 // The rank image has to be a jpg, gif or png
157 if($rank_image != "")
159 if ( !preg_match("/(\.gif|\.png|\.jpg)$/is", $rank_image))
169 $sql = "UPDATE " . USERS_TABLE . "
171 WHERE user_rank = $rank_id";
173 if( !$result = $db->sql_query($sql) )
175 message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
178 $sql = "UPDATE " . RANKS_TABLE . "
179 SET rank_title = '" . str_replace("\'", "''", $rank_title) . "', rank_special = $special_rank, rank_min = $min_posts, rank_image = '" . str_replace("\'", "''", $rank_image) . "'
180 WHERE rank_id = $rank_id";
182 $message = $lang['Rank_updated'];
186 $sql = "INSERT INTO " . RANKS_TABLE . " (rank_title, rank_special, rank_min, rank_image)
187 VALUES ('" . str_replace("\'", "''", $rank_title) . "', $special_rank, $min_posts, '" . str_replace("\'", "''", $rank_image) . "')";
189 $message = $lang['Rank_added'];
192 if( !$result = $db->sql_query($sql) )
194 message_die(GENERAL_ERROR, "Couldn't update/insert into ranks table", "", __LINE__, __FILE__, $sql);
197 $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>");
199 message_die(GENERAL_MESSAGE, $message);
202 else if( $mode == "delete" )
205 // Ok, they want to delete their rank
208 if( isset($HTTP_POST_VARS['id']) || isset($HTTP_GET_VARS['id']) )
210 $rank_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : intval($HTTP_GET_VARS['id']);
219 $sql = "DELETE FROM " . RANKS_TABLE . "
220 WHERE rank_id = $rank_id";
222 if( !$result = $db->sql_query($sql) )
224 message_die(GENERAL_ERROR, "Couldn't delete rank data", "", __LINE__, __FILE__, $sql);
227 $sql = "UPDATE " . USERS_TABLE . "
229 WHERE user_rank = $rank_id";
231 if( !$result = $db->sql_query($sql) )
233 message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
236 $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>");
238 message_die(GENERAL_MESSAGE, $message);
243 message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
249 // They didn't feel like giving us any information. Oh, too bad, we'll just display the
252 $template->set_filenames(array(
253 "body" => "admin/ranks_list_body.tpl")
256 $sql = "SELECT * FROM " . RANKS_TABLE . "
257 ORDER BY rank_min, rank_title";
258 if( !$result = $db->sql_query($sql) )
260 message_die(GENERAL_ERROR, "Couldn't obtain ranks data", "", __LINE__, __FILE__, $sql);
263 $rank_rows = $db->sql_fetchrowset($result);
264 $rank_count = count($rank_rows);
266 $template->assign_vars(array(
267 "L_RANKS_TITLE" => $lang['Ranks_title'],
268 "L_RANKS_TEXT" => $lang['Ranks_explain'],
269 "L_RANK" => $lang['Rank_title'],
270 "L_RANK_MINIMUM" => $lang['Rank_minimum'],
271 "L_SPECIAL_RANK" => $lang['Special_rank'],
272 "L_EDIT" => $lang['Edit'],
273 "L_DELETE" => $lang['Delete'],
274 "L_ADD_RANK" => $lang['Add_new_rank'],
275 "L_ACTION" => $lang['Action'],
277 "S_RANKS_ACTION" => append_sid("admin_ranks.$phpEx"))
280 for( $i = 0; $i < $rank_count; $i++)
282 $rank = $rank_rows[$i]['rank_title'];
283 $special_rank = $rank_rows[$i]['rank_special'];
284 $rank_id = $rank_rows[$i]['rank_id'];
285 $rank_min = $rank_rows[$i]['rank_min'];
289 $rank_min = $rank_max = "-";
292 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
293 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
295 $template->assign_block_vars("ranks", array(
296 "ROW_COLOR" => "#" . $row_color,
297 "ROW_CLASS" => $row_class,
299 "RANK_MIN" => $rank_min,
301 "SPECIAL_RANK" => ( $special_rank == 1 ) ? $lang['Yes'] : $lang['No'],
303 "U_RANK_EDIT" => append_sid("admin_ranks.$phpEx?mode=edit&id=$rank_id"),
304 "U_RANK_DELETE" => append_sid("admin_ranks.$phpEx?mode=delete&id=$rank_id"))
312 // Show the default page
314 $template->set_filenames(array(
315 "body" => "admin/ranks_list_body.tpl")
318 $sql = "SELECT * FROM " . RANKS_TABLE . "
319 ORDER BY rank_min ASC, rank_special ASC";
320 if( !$result = $db->sql_query($sql) )
322 message_die(GENERAL_ERROR, "Couldn't obtain ranks data", "", __LINE__, __FILE__, $sql);
324 $rank_count = $db->sql_numrows($result);
326 $rank_rows = $db->sql_fetchrowset($result);
328 $template->assign_vars(array(
329 "L_RANKS_TITLE" => $lang['Ranks_title'],
330 "L_RANKS_TEXT" => $lang['Ranks_explain'],
331 "L_RANK" => $lang['Rank_title'],
332 "L_RANK_MINIMUM" => $lang['Rank_minimum'],
333 "L_SPECIAL_RANK" => $lang['Rank_special'],
334 "L_EDIT" => $lang['Edit'],
335 "L_DELETE" => $lang['Delete'],
336 "L_ADD_RANK" => $lang['Add_new_rank'],
337 "L_ACTION" => $lang['Action'],
339 "S_RANKS_ACTION" => append_sid("admin_ranks.$phpEx"))
342 for($i = 0; $i < $rank_count; $i++)
344 $rank = $rank_rows[$i]['rank_title'];
345 $special_rank = $rank_rows[$i]['rank_special'];
346 $rank_id = $rank_rows[$i]['rank_id'];
347 $rank_min = $rank_rows[$i]['rank_min'];
349 if( $special_rank == 1 )
351 $rank_min = $rank_max = "-";
354 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
355 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
357 $rank_is_special = ( $special_rank ) ? $lang['Yes'] : $lang['No'];
359 $template->assign_block_vars("ranks", array(
360 "ROW_COLOR" => "#" . $row_color,
361 "ROW_CLASS" => $row_class,
363 "SPECIAL_RANK" => $rank_is_special,
364 "RANK_MIN" => $rank_min,
366 "U_RANK_EDIT" => append_sid("admin_ranks.$phpEx?mode=edit&id=$rank_id"),
367 "U_RANK_DELETE" => append_sid("admin_ranks.$phpEx?mode=delete&id=$rank_id"))
372 $template->pparse("body");
374 include('./page_footer_admin.'.$phpEx);