Blame Identity/Webenv/phpBB/3.0.4/includes/acp/acp_ranks.php

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