]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/admin_ranks.php
bd6eb0501feb0c7ac14da2d77de5cd57a765f540
[www.vanrenterghem.biz.git] / phpBB2_old / admin / admin_ranks.php
1 <?php
2 /***************************************************************************
3  *                              admin_ranks.php
4  *                            -------------------
5  *   begin                : Thursday, Jul 12, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: admin_ranks.php,v 1.13.2.4 2004/03/25 15:57:20 acydburn Exp $
10  *
11  ***************************************************************************/
13 /***************************************************************************
14  *
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.
19  *
20  ***************************************************************************/
22 define('IN_PHPBB', 1);
24 if( !empty($setmodules) )
25 {
26         $file = basename(__FILE__);
27         $module['Users']['Ranks'] = "$file";
28         return;
29 }
31 //
32 // Let's set the root dir for phpBB
33 //
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']) )
39 {
40         $mode = ($HTTP_GET_VARS['mode']) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
41         $mode = htmlspecialchars($mode);
42 }
43 else 
44 {
45         //
46         // These could be entered via a form button
47         //
48         if( isset($HTTP_POST_VARS['add']) )
49         {
50                 $mode = "add";
51         }
52         else if( isset($HTTP_POST_VARS['save']) )
53         {
54                 $mode = "save";
55         }
56         else
57         {
58                 $mode = "";
59         }
60 }
63 if( $mode != "" )
64 {
65         if( $mode == "edit" || $mode == "add" )
66         {
67                 //
68                 // They want to add a new rank, show the form.
69                 //
70                 $rank_id = ( isset($HTTP_GET_VARS['id']) ) ? intval($HTTP_GET_VARS['id']) : 0;
71                 
72                 $s_hidden_fields = "";
73                 
74                 if( $mode == "edit" )
75                 {
76                         if( empty($rank_id) )
77                         {
78                                 message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
79                         }
81                         $sql = "SELECT * FROM " . RANKS_TABLE . "
82                                 WHERE rank_id = $rank_id";
83                         if(!$result = $db->sql_query($sql))
84                         {
85                                 message_die(GENERAL_ERROR, "Couldn't obtain rank data", "", __LINE__, __FILE__, $sql);
86                         }
87                         
88                         $rank_info = $db->sql_fetchrow($result);
89                         $s_hidden_fields .= '<input type="hidden" name="id" value="' . $rank_id . '" />';
91                 }
92                 else
93                 {
94                         $rank_info['rank_special'] = 0;
95                 }
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\"" : "";
101                 
102                 $template->set_filenames(array(
103                         "body" => "admin/ranks_edit_body.tpl")
104                 );
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'] . '" />' : "",
113                         
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'],
125                         
126                         "S_RANK_ACTION" => append_sid("admin_ranks.$phpEx"),
127                         "S_HIDDEN_FIELDS" => $s_hidden_fields)
128                 );
129                 
130         }
131         else if( $mode == "save" )
132         {
133                 //
134                 // Ok, they sent us our info, let's update it.
135                 //
136                 
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 == "" )
144                 {
145                         message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
146                 }
148                 if( $special_rank == 1 )
149                 {
150                         $max_posts = -1;
151                         $min_posts = -1;
152                 }
154                 //
155                 // The rank image has to be a jpg, gif or png
156                 //
157                 if($rank_image != "")
158                 {
159                         if ( !preg_match("/(\.gif|\.png|\.jpg)$/is", $rank_image))
160                         {
161                                 $rank_image = "";
162                         }
163                 }
165                 if ($rank_id)
166                 {
167                         if (!$special_rank)
168                         {
169                                 $sql = "UPDATE " . USERS_TABLE . " 
170                                         SET user_rank = 0 
171                                         WHERE user_rank = $rank_id";
173                                 if( !$result = $db->sql_query($sql) ) 
174                                 {
175                                         message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
176                                 }
177                         }
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'];
183                 }
184                 else
185                 {
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'];
190                 }
191                 
192                 if( !$result = $db->sql_query($sql) )
193                 {
194                         message_die(GENERAL_ERROR, "Couldn't update/insert into ranks table", "", __LINE__, __FILE__, $sql);
195                 }
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);
201         }
202         else if( $mode == "delete" )
203         {
204                 //
205                 // Ok, they want to delete their rank
206                 //
207                 
208                 if( isset($HTTP_POST_VARS['id']) || isset($HTTP_GET_VARS['id']) )
209                 {
210                         $rank_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : intval($HTTP_GET_VARS['id']);
211                 }
212                 else
213                 {
214                         $rank_id = 0;
215                 }
216                 
217                 if( $rank_id )
218                 {
219                         $sql = "DELETE FROM " . RANKS_TABLE . "
220                                 WHERE rank_id = $rank_id";
221                         
222                         if( !$result = $db->sql_query($sql) )
223                         {
224                                 message_die(GENERAL_ERROR, "Couldn't delete rank data", "", __LINE__, __FILE__, $sql);
225                         }
226                         
227                         $sql = "UPDATE " . USERS_TABLE . " 
228                                 SET user_rank = 0 
229                                 WHERE user_rank = $rank_id";
231                         if( !$result = $db->sql_query($sql) ) 
232                         {
233                                 message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
234                         }
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);
240                 }
241                 else
242                 {
243                         message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
244                 }
245         }
246         else
247         {
248                 //
249                 // They didn't feel like giving us any information. Oh, too bad, we'll just display the
250                 // list then...
251                 //
252                 $template->set_filenames(array(
253                         "body" => "admin/ranks_list_body.tpl")
254                 );
255                 
256                 $sql = "SELECT * FROM " . RANKS_TABLE . "
257                         ORDER BY rank_min, rank_title";
258                 if( !$result = $db->sql_query($sql) )
259                 {
260                         message_die(GENERAL_ERROR, "Couldn't obtain ranks data", "", __LINE__, __FILE__, $sql);
261                 }
262                 
263                 $rank_rows = $db->sql_fetchrowset($result);
264                 $rank_count = count($rank_rows);
265                 
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'],
276                         
277                         "S_RANKS_ACTION" => append_sid("admin_ranks.$phpEx"))
278                 );
279                 
280                 for( $i = 0; $i < $rank_count; $i++)
281                 {
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'];
287                         if($special_rank)
288                         {
289                                 $rank_min = $rank_max = "-";
290                         }
291                         
292                         $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
293                         $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
294         
295                         $template->assign_block_vars("ranks", array(
296                                 "ROW_COLOR" => "#" . $row_color,
297                                 "ROW_CLASS" => $row_class,
298                                 "RANK" => $rank,
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&amp;id=$rank_id"),
304                                 "U_RANK_DELETE" => append_sid("admin_ranks.$phpEx?mode=delete&amp;id=$rank_id"))
305                         );
306                 }
307         }
309 else
311         //
312         // Show the default page
313         //
314         $template->set_filenames(array(
315                 "body" => "admin/ranks_list_body.tpl")
316         );
317         
318         $sql = "SELECT * FROM " . RANKS_TABLE . "
319                 ORDER BY rank_min ASC, rank_special ASC";
320         if( !$result = $db->sql_query($sql) )
321         {
322                 message_die(GENERAL_ERROR, "Couldn't obtain ranks data", "", __LINE__, __FILE__, $sql);
323         }
324         $rank_count = $db->sql_numrows($result);
326         $rank_rows = $db->sql_fetchrowset($result);
327         
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'],
338                 
339                 "S_RANKS_ACTION" => append_sid("admin_ranks.$phpEx"))
340         );
341         
342         for($i = 0; $i < $rank_count; $i++)
343         {
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'];
348                 
349                 if( $special_rank == 1 )
350                 {
351                         $rank_min = $rank_max = "-";
352                 }
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'];
358                 
359                 $template->assign_block_vars("ranks", array(
360                         "ROW_COLOR" => "#" . $row_color,
361                         "ROW_CLASS" => $row_class,
362                         "RANK" => $rank,
363                         "SPECIAL_RANK" => $rank_is_special,
364                         "RANK_MIN" => $rank_min,
366                         "U_RANK_EDIT" => append_sid("admin_ranks.$phpEx?mode=edit&amp;id=$rank_id"),
367                         "U_RANK_DELETE" => append_sid("admin_ranks.$phpEx?mode=delete&amp;id=$rank_id"))
368                 );
369         }
372 $template->pparse("body");
374 include('./page_footer_admin.'.$phpEx);
376 ?>