(file) Return to admin_ranks.php CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / phpBB2 / admin

  1 rizwank 1.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.3 2002/11/28 00:11:39 psotfx Exp $
 10              *
 11              ***************************************************************************/
 12             
 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              ***************************************************************************/
 21             
 22 rizwank 1.1 define('IN_PHPBB', 1);
 23             
 24             if( !empty($setmodules) )
 25             {
 26             	$file = basename(__FILE__);
 27             	$module['Users']['Ranks'] = "$file";
 28             	return;
 29             }
 30             
 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);
 37             
 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             }
 42             else 
 43 rizwank 1.1 {
 44             	//
 45             	// These could be entered via a form button
 46             	//
 47             	if( isset($HTTP_POST_VARS['add']) )
 48             	{
 49             		$mode = "add";
 50             	}
 51             	else if( isset($HTTP_POST_VARS['save']) )
 52             	{
 53             		$mode = "save";
 54             	}
 55             	else
 56             	{
 57             		$mode = "";
 58             	}
 59             }
 60             
 61             
 62             if( $mode != "" )
 63             {
 64 rizwank 1.1 	if( $mode == "edit" || $mode == "add" )
 65             	{
 66             		//
 67             		// They want to add a new rank, show the form.
 68             		//
 69             		$rank_id = ( isset($HTTP_GET_VARS['id']) ) ? intval($HTTP_GET_VARS['id']) : 0;
 70             		
 71             		$s_hidden_fields = "";
 72             		
 73             		if( $mode == "edit" )
 74             		{
 75             			if( empty($rank_id) )
 76             			{
 77             				message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
 78             			}
 79             
 80             			$sql = "SELECT * FROM " . RANKS_TABLE . "
 81             				WHERE rank_id = $rank_id";
 82             			if(!$result = $db->sql_query($sql))
 83             			{
 84             				message_die(GENERAL_ERROR, "Couldn't obtain rank data", "", __LINE__, __FILE__, $sql);
 85 rizwank 1.1 			}
 86             			
 87             			$rank_info = $db->sql_fetchrow($result);
 88             			$s_hidden_fields .= '<input type="hidden" name="id" value="' . $rank_id . '" />';
 89             
 90             		}
 91             		else
 92             		{
 93             			$rank_info['rank_special'] = 0;
 94             		}
 95             
 96             		$s_hidden_fields .= '<input type="hidden" name="mode" value="save" />';
 97             
 98             		$rank_is_special = ( $rank_info['rank_special'] ) ? "checked=\"checked\"" : "";
 99             		$rank_is_not_special = ( !$rank_info['rank_special'] ) ? "checked=\"checked\"" : "";
100             		
101             		$template->set_filenames(array(
102             			"body" => "admin/ranks_edit_body.tpl")
103             		);
104             
105             		$template->assign_vars(array(
106 rizwank 1.1 			"RANK" => $rank_info['rank_title'],
107             			"SPECIAL_RANK" => $rank_is_special,
108             			"NOT_SPECIAL_RANK" => $rank_is_not_special,
109             			"MINIMUM" => ( $rank_is_special ) ? "" : $rank_info['rank_min'],
110             			"IMAGE" => ( $rank_info['rank_image'] != "" ) ? $rank_info['rank_image'] : "",
111             			"IMAGE_DISPLAY" => ( $rank_info['rank_image'] != "" ) ? '<img src="../' . $rank_info['rank_image'] . '" />' : "",
112             			
113             			"L_RANKS_TITLE" => $lang['Ranks_title'],
114             			"L_RANKS_TEXT" => $lang['Ranks_explain'],
115             			"L_RANK_TITLE" => $lang['Rank_title'],
116             			"L_RANK_SPECIAL" => $lang['Rank_special'],
117             			"L_RANK_MINIMUM" => $lang['Rank_minimum'],
118             			"L_RANK_IMAGE" => $lang['Rank_image'],
119             			"L_RANK_IMAGE_EXPLAIN" => $lang['Rank_image_explain'],
120             			"L_SUBMIT" => $lang['Submit'],
121             			"L_RESET" => $lang['Reset'],
122             			"L_YES" => $lang['Yes'],
123             			"L_NO" => $lang['No'],
124             			
125             			"S_RANK_ACTION" => append_sid("admin_ranks.$phpEx"),
126             			"S_HIDDEN_FIELDS" => $s_hidden_fields)
127 rizwank 1.1 		);
128             		
129             	}
130             	else if( $mode == "save" )
131             	{
132             		//
133             		// Ok, they sent us our info, let's update it.
134             		//
135             		
136             		$rank_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : 0;
137             		$rank_title = ( isset($HTTP_POST_VARS['title']) ) ? trim($HTTP_POST_VARS['title']) : "";
138             		$special_rank = ( $HTTP_POST_VARS['special_rank'] == 1 ) ? TRUE : 0;
139             		$min_posts = ( isset($HTTP_POST_VARS['min_posts']) ) ? intval($HTTP_POST_VARS['min_posts']) : -1;
140             		$rank_image = ( (isset($HTTP_POST_VARS['rank_image'])) ) ? trim($HTTP_POST_VARS['rank_image']) : "";
141             
142             		if( $rank_title == "" )
143             		{
144             			message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
145             		}
146             
147             		if( $special_rank == 1 )
148 rizwank 1.1 		{
149             			$max_posts = -1;
150             			$min_posts = -1;
151             		}
152             
153             		//
154             		// The rank image has to be a jpg, gif or png
155             		//
156             		if($rank_image != "")
157             		{
158             			if ( !preg_match("/(\.gif|\.png|\.jpg)$/is", $rank_image))
159             			{
160             				$rank_image = "";
161             			}
162             		}
163             
164             		if ($rank_id)
165             		{
166             			if (!$special_rank)
167             			{
168             				$sql = "UPDATE " . USERS_TABLE . " 
169 rizwank 1.1 					SET user_rank = 0 
170             					WHERE user_rank = $rank_id";
171             
172             				if( !$result = $db->sql_query($sql) ) 
173             				{
174             					message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
175             				}
176             			}
177             			$sql = "UPDATE " . RANKS_TABLE . "
178             				SET rank_title = '" . str_replace("\'", "''", $rank_title) . "', rank_special = $special_rank, rank_min = $min_posts, rank_image = '" . str_replace("\'", "''", $rank_image) . "'
179             				WHERE rank_id = $rank_id";
180             
181             			$message = $lang['Rank_updated'];
182             		}
183             		else
184             		{
185             			$sql = "INSERT INTO " . RANKS_TABLE . " (rank_title, rank_special, rank_min, rank_image)
186             				VALUES ('" . str_replace("\'", "''", $rank_title) . "', $special_rank, $min_posts, '" . str_replace("\'", "''", $rank_image) . "')";
187             
188             			$message = $lang['Rank_added'];
189             		}
190 rizwank 1.1 		
191             		if( !$result = $db->sql_query($sql) )
192             		{
193             			message_die(GENERAL_ERROR, "Couldn't update/insert into ranks table", "", __LINE__, __FILE__, $sql);
194             		}
195             
196             		$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>");
197             
198             		message_die(GENERAL_MESSAGE, $message);
199             
200             	}
201             	else if( $mode == "delete" )
202             	{
203             		//
204             		// Ok, they want to delete their rank
205             		//
206             		
207             		if( isset($HTTP_POST_VARS['id']) || isset($HTTP_GET_VARS['id']) )
208             		{
209             			$rank_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : intval($HTTP_GET_VARS['id']);
210             		}
211 rizwank 1.1 		else
212             		{
213             			$rank_id = 0;
214             		}
215             		
216             		if( $rank_id )
217             		{
218             			$sql = "DELETE FROM " . RANKS_TABLE . "
219             				WHERE rank_id = $rank_id";
220             			
221             			if( !$result = $db->sql_query($sql) )
222             			{
223             				message_die(GENERAL_ERROR, "Couldn't delete rank data", "", __LINE__, __FILE__, $sql);
224             			}
225             			
226             			$sql = "UPDATE " . USERS_TABLE . " 
227             				SET user_rank = 0 
228             				WHERE user_rank = $rank_id";
229             
230             			if( !$result = $db->sql_query($sql) ) 
231             			{
232 rizwank 1.1 				message_die(GENERAL_ERROR, $lang['No_update_ranks'], "", __LINE__, __FILE__, $sql);
233             			}
234             
235             			$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>");
236             
237             			message_die(GENERAL_MESSAGE, $message);
238             
239             		}
240             		else
241             		{
242             			message_die(GENERAL_MESSAGE, $lang['Must_select_rank']);
243             		}
244             	}
245             	else
246             	{
247             		//
248             		// They didn't feel like giving us any information. Oh, too bad, we'll just display the
249             		// list then...
250             		//
251             		$template->set_filenames(array(
252             			"body" => "admin/ranks_list_body.tpl")
253 rizwank 1.1 		);
254             		
255             		$sql = "SELECT * FROM " . RANKS_TABLE . "
256             			ORDER BY rank_min, rank_title";
257             		if( !$result = $db->sql_query($sql) )
258             		{
259             			message_die(GENERAL_ERROR, "Couldn't obtain ranks data", "", __LINE__, __FILE__, $sql);
260             		}
261             		
262             		$rank_rows = $db->sql_fetchrowset($result);
263             		$rank_count = count($rank_rows);
264             		
265             		$template->assign_vars(array(
266             			"L_RANKS_TITLE" => $lang['Ranks_title'],
267             			"L_RANKS_TEXT" => $lang['Ranks_explain'],
268             			"L_RANK" => $lang['Rank_title'],
269             			"L_RANK_MINIMUM" => $lang['Rank_minimum'],
270             			"L_SPECIAL_RANK" => $lang['Special_rank'],
271             			"L_EDIT" => $lang['Edit'],
272             			"L_DELETE" => $lang['Delete'],
273             			"L_ADD_RANK" => $lang['Add_new_rank'],
274 rizwank 1.1 			"L_ACTION" => $lang['Action'],
275             			
276             			"S_RANKS_ACTION" => append_sid("admin_ranks.$phpEx"))
277             		);
278             		
279             		for( $i = 0; $i < $rank_count; $i++)
280             		{
281             			$rank = $rank_rows[$i]['rank_title'];
282             			$special_rank = $rank_rows[$i]['rank_special'];
283             			$rank_id = $rank_rows[$i]['rank_id'];
284             			$rank_min = $rank_rows[$i]['rank_min'];
285             
286             			if($special_rank)
287             			{
288             				$rank_min = $rank_max = "-";
289             			}
290             			
291             			$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
292             			$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
293             	
294             			$template->assign_block_vars("ranks", array(
295 rizwank 1.1 				"ROW_COLOR" => "#" . $row_color,
296             				"ROW_CLASS" => $row_class,
297             				"RANK" => $rank,
298             				"RANK_MIN" => $rank_min,
299             
300             				"SPECIAL_RANK" => ( $special_rank == 1 ) ? $lang['Yes'] : $lang['No'],
301             
302             				"U_RANK_EDIT" => append_sid("admin_ranks.$phpEx?mode=edit&amp;id=$rank_id"),
303             				"U_RANK_DELETE" => append_sid("admin_ranks.$phpEx?mode=delete&amp;id=$rank_id"))
304             			);
305             		}
306             	}
307             }
308             else
309             {
310             	//
311             	// Show the default page
312             	//
313             	$template->set_filenames(array(
314             		"body" => "admin/ranks_list_body.tpl")
315             	);
316 rizwank 1.1 	
317             	$sql = "SELECT * FROM " . RANKS_TABLE . "
318             		ORDER BY rank_min ASC, rank_special ASC";
319             	if( !$result = $db->sql_query($sql) )
320             	{
321             		message_die(GENERAL_ERROR, "Couldn't obtain ranks data", "", __LINE__, __FILE__, $sql);
322             	}
323             	$rank_count = $db->sql_numrows($result);
324             
325             	$rank_rows = $db->sql_fetchrowset($result);
326             	
327             	$template->assign_vars(array(
328             		"L_RANKS_TITLE" => $lang['Ranks_title'],
329             		"L_RANKS_TEXT" => $lang['Ranks_explain'],
330             		"L_RANK" => $lang['Rank_title'],
331             		"L_RANK_MINIMUM" => $lang['Rank_minimum'],
332             		"L_SPECIAL_RANK" => $lang['Rank_special'],
333             		"L_EDIT" => $lang['Edit'],
334             		"L_DELETE" => $lang['Delete'],
335             		"L_ADD_RANK" => $lang['Add_new_rank'],
336             		"L_ACTION" => $lang['Action'],
337 rizwank 1.1 		
338             		"S_RANKS_ACTION" => append_sid("admin_ranks.$phpEx"))
339             	);
340             	
341             	for($i = 0; $i < $rank_count; $i++)
342             	{
343             		$rank = $rank_rows[$i]['rank_title'];
344             		$special_rank = $rank_rows[$i]['rank_special'];
345             		$rank_id = $rank_rows[$i]['rank_id'];
346             		$rank_min = $rank_rows[$i]['rank_min'];
347             		
348             		if( $special_rank == 1 )
349             		{
350             			$rank_min = $rank_max = "-";
351             		}
352             
353             		$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
354             		$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
355             
356             		$rank_is_special = ( $special_rank ) ? $lang['Yes'] : $lang['No'];
357             		
358 rizwank 1.1 		$template->assign_block_vars("ranks", array(
359             			"ROW_COLOR" => "#" . $row_color,
360             			"ROW_CLASS" => $row_class,
361             			"RANK" => $rank,
362             			"SPECIAL_RANK" => $rank_is_special,
363             			"RANK_MIN" => $rank_min,
364             
365             			"U_RANK_EDIT" => append_sid("admin_ranks.$phpEx?mode=edit&amp;id=$rank_id"),
366             			"U_RANK_DELETE" => append_sid("admin_ranks.$phpEx?mode=delete&amp;id=$rank_id"))
367             		);
368             	}
369             }
370             
371             $template->pparse("body");
372             
373             include('./page_footer_admin.'.$phpEx);
374             
375             ?>

Rizwan Kassim
Powered by
ViewCVS 0.9.2