Blame Extras/phpBB/3.0.4/includes/acp/acp_ranks.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package acp
4c79b5
* @version $Id: acp_ranks.php 8479 2008-03-29 00:22:48Z naderman $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* @package acp
4c79b5
*/
4c79b5
class acp_ranks
4c79b5
{
4c79b5
	var $u_action;
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $db, $user, $auth, $template, $cache;
4c79b5
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
4c79b5
4c79b5
		$user->add_lang('acp/posting');
4c79b5
4c79b5
		// Set up general vars
4c79b5
		$action = request_var('action', '');
4c79b5
		$action = (isset($_POST['add'])) ? 'add' : $action;
4c79b5
		$action = (isset($_POST['save'])) ? 'save' : $action;
4c79b5
		$rank_id = request_var('id', 0);
4c79b5
4c79b5
		$this->tpl_name = 'acp_ranks';
4c79b5
		$this->page_title = 'ACP_MANAGE_RANKS';
4c79b5
4c79b5
		$form_name = 'acp_prune';
4c79b5
		add_form_key($form_name);
4c79b5
4c79b5
		switch ($action)
4c79b5
		{
4c79b5
			case 'save':
4c79b5
4c79b5
				if (!check_form_key($form_name))
4c79b5
				{
4c79b5
					trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
				$rank_title = utf8_normalize_nfc(request_var('title', '', true));
4c79b5
				$special_rank = request_var('special_rank', 0);
4c79b5
				$min_posts = ($special_rank) ? 0 : request_var('min_posts', 0);
4c79b5
				$rank_image = request_var('rank_image', '');
4c79b5
4c79b5
				// The rank image has to be a jpg, gif or png
4c79b5
				if ($rank_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $rank_image))
4c79b5
				{
4c79b5
					$rank_image = '';
4c79b5
				}
4c79b5
4c79b5
				if (!$rank_title)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$sql_ary = array(
4c79b5
					'rank_title'		=> $rank_title,
4c79b5
					'rank_special'		=> $special_rank,
4c79b5
					'rank_min'			=> $min_posts,
4c79b5
					'rank_image'		=> htmlspecialchars_decode($rank_image)
4c79b5
				);
4c79b5
				
4c79b5
				if ($rank_id)
4c79b5
				{
4c79b5
					$sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id";
4c79b5
					$message = $user->lang['RANK_UPDATED'];
4c79b5
4c79b5
					add_log('admin', 'LOG_RANK_UPDATED', $rank_title);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
4c79b5
					$message = $user->lang['RANK_ADDED'];
4c79b5
4c79b5
					add_log('admin', 'LOG_RANK_ADDED', $rank_title);
4c79b5
				}
4c79b5
				$db->sql_query($sql);
4c79b5
4c79b5
				$cache->destroy('_ranks');
4c79b5
4c79b5
				trigger_error($message . adm_back_link($this->u_action));
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'delete':
4c79b5
4c79b5
				if (!$rank_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (confirm_box(true))
4c79b5
				{
4c79b5
					$sql = 'SELECT rank_title
4c79b5
						FROM ' . RANKS_TABLE . '
4c79b5
						WHERE rank_id = ' . $rank_id;
4c79b5
					$result = $db->sql_query($sql);
4c79b5
					$rank_title = (string) $db->sql_fetchfield('rank_title');
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					$sql = 'DELETE FROM ' . RANKS_TABLE . "
4c79b5
						WHERE rank_id = $rank_id";
4c79b5
					$db->sql_query($sql);
4c79b5
4c79b5
					$sql = 'UPDATE ' . USERS_TABLE . "
4c79b5
						SET user_rank = 0
4c79b5
						WHERE user_rank = $rank_id";
4c79b5
					$db->sql_query($sql);
4c79b5
4c79b5
					$cache->destroy('_ranks');
4c79b5
4c79b5
					add_log('admin', 'LOG_RANK_REMOVED', $rank_title);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
						'i'			=> $id,
4c79b5
						'mode'		=> $mode,
4c79b5
						'rank_id'	=> $rank_id,
4c79b5
						'action'	=> 'delete',
4c79b5
					)));
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'edit':
4c79b5
			case 'add':
4c79b5
4c79b5
				$data = $ranks = $existing_imgs = array();
4c79b5
				
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . RANKS_TABLE . '
4c79b5
					ORDER BY rank_min ASC, rank_special ASC';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$existing_imgs[] = $row['rank_image'];
4c79b5
4c79b5
					if ($action == 'edit' && $rank_id == $row['rank_id'])
4c79b5
					{
4c79b5
						$ranks = $row;
4c79b5
					}
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$imglist = filelist($phpbb_root_path . $config['ranks_path'], '');
4c79b5
				$edit_img = $filename_list = '';
4c79b5
4c79b5
				foreach ($imglist as $path => $img_ary)
4c79b5
				{
4c79b5
					sort($img_ary);
4c79b5
4c79b5
					foreach ($img_ary as $img)
4c79b5
					{
4c79b5
						$img = $path . $img;
4c79b5
4c79b5
						if (!in_array($img, $existing_imgs) || $action == 'edit')
4c79b5
						{
4c79b5
							if ($ranks && $img == $ranks['rank_image'])
4c79b5
							{
4c79b5
								$selected = ' selected="selected"';
4c79b5
								$edit_img = $img;
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								$selected = '';
4c79b5
							}
4c79b5
4c79b5
							if (strlen($img) > 255)
4c79b5
							{
4c79b5
								continue;
4c79b5
							}
4c79b5
4c79b5
							$filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>';
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list;
4c79b5
				unset($existing_imgs, $imglist);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_EDIT'			=> true,
4c79b5
					'U_BACK'			=> $this->u_action,
4c79b5
					'RANKS_PATH'		=> $phpbb_root_path . $config['ranks_path'],
4c79b5
					'U_ACTION'			=> $this->u_action . '&id=' . $rank_id,
4c79b5
4c79b5
					'RANK_TITLE'		=> (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '',
4c79b5
					'S_FILENAME_LIST'	=> $filename_list,
4c79b5
					'RANK_IMAGE'		=> ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif',
4c79b5
					'S_SPECIAL_RANK'	=> (!isset($ranks['rank_special']) || $ranks['rank_special']) ? true : false,
4c79b5
					'MIN_POSTS'			=> (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0)
4c79b5
				);
4c79b5
						
4c79b5
4c79b5
				return;
4c79b5
4c79b5
			break;
4c79b5
		}
4c79b5
	
4c79b5
		$template->assign_vars(array(
4c79b5
			'U_ACTION'		=> $this->u_action)
4c79b5
		);
4c79b5
4c79b5
		$sql = 'SELECT *
4c79b5
			FROM ' . RANKS_TABLE . '
4c79b5
			ORDER BY rank_special DESC, rank_min ASC, rank_title ASC';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$template->assign_block_vars('ranks', array(
4c79b5
				'S_RANK_IMAGE'		=> ($row['rank_image']) ? true : false,
4c79b5
				'S_SPECIAL_RANK'	=> ($row['rank_special']) ? true : false,
4c79b5
4c79b5
				'RANK_IMAGE'		=> $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'],
4c79b5
				'RANK_TITLE'		=> $row['rank_title'],
4c79b5
				'MIN_POSTS'			=> $row['rank_min'],
4c79b5
4c79b5
				'U_EDIT'			=> $this->u_action . '&action=edit&id=' . $row['rank_id'],
4c79b5
				'U_DELETE'			=> $this->u_action . '&action=delete&id=' . $row['rank_id'])
4c79b5
			);	
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>