Blame Identity/Webenv/App/phpBB/3.0.4/adm/index.php

f2e824
f2e824
/**
f2e824
*
f2e824
* @package acp
f2e824
* @version $Id: index.php 8591 2008-06-04 11:40:53Z Kellanved $
f2e824
* @copyright (c) 2005 phpBB Group
f2e824
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
f2e824
*
f2e824
*/
f2e824
f2e824
/**
f2e824
*/
f2e824
define('IN_PHPBB', true);
f2e824
define('ADMIN_START', true);
f2e824
define('NEED_SID', true);
f2e824
f2e824
// Include files
f2e824
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
f2e824
$phpEx = substr(strrchr(__FILE__, '.'), 1);
f2e824
require($phpbb_root_path . 'common.' . $phpEx);
f2e824
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
f2e824
require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
f2e824
f2e824
// Start session management
f2e824
$user->session_begin();
f2e824
$auth->acl($user->data);
f2e824
$user->setup('acp/common');
f2e824
// End session management
f2e824
f2e824
// Have they authenticated (again) as an admin for this session?
f2e824
if (!isset($user->data['session_admin']) || !$user->data['session_admin'])
f2e824
{
f2e824
	login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
f2e824
}
f2e824
f2e824
// Is user any type of admin? No, then stop here, each script needs to
f2e824
// check specific permissions but this is a catchall
f2e824
if (!$auth->acl_get('a_'))
f2e824
{
f2e824
	trigger_error('NO_ADMIN');
f2e824
}
f2e824
f2e824
// We define the admin variables now, because the user is now able to use the admin related features...
f2e824
define('IN_ADMIN', true);
f2e824
$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
f2e824
f2e824
// Some oft used variables
f2e824
$safe_mode		= (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) === 'on') ? true : false;
f2e824
$file_uploads	= (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_uploads')) === 'on') ? true : false;
f2e824
$module_id		= request_var('i', '');
f2e824
$mode			= request_var('mode', '');
f2e824
f2e824
// Set custom template for admin area
f2e824
$template->set_custom_template($phpbb_admin_path . 'style', 'admin');
f2e824
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
f2e824
f2e824
// the acp template is never stored in the database
f2e824
$user->theme['template_storedb'] = false;
f2e824
f2e824
// Instantiate new module
f2e824
$module = new p_master();
f2e824
f2e824
// Instantiate module system and generate list of available modules
f2e824
$module->list_modules('acp');
f2e824
f2e824
// Select the active module
f2e824
$module->set_active($module_id, $mode);
f2e824
f2e824
// Assign data to the template engine for the list of modules
f2e824
// We do this before loading the active module for correct menu display in trigger_error
f2e824
$module->assign_tpl_vars(append_sid("{$phpbb_admin_path}index.$phpEx"));
f2e824
f2e824
// Load and execute the relevant module
f2e824
$module->load_active();
f2e824
f2e824
// Generate the page
f2e824
adm_page_header($module->get_page_title());
f2e824
f2e824
$template->set_filenames(array(
f2e824
	'body' => $module->get_tpl_name(),
f2e824
));
f2e824
f2e824
adm_page_footer();
f2e824
f2e824
/**
f2e824
* Header for acp pages
f2e824
*/
f2e824
function adm_page_header($page_title)
f2e824
{
f2e824
	global $config, $db, $user, $template;
f2e824
	global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
f2e824
f2e824
	if (defined('HEADER_INC'))
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	define('HEADER_INC', true);
f2e824
f2e824
	// gzip_compression
f2e824
	if ($config['gzip_compress'])
f2e824
	{
f2e824
		if (@extension_loaded('zlib') && !headers_sent())
f2e824
		{
f2e824
			ob_start('ob_gzhandler');
f2e824
		}
f2e824
	}
f2e824
f2e824
	$template->assign_vars(array(
f2e824
		'PAGE_TITLE'			=> $page_title,
f2e824
		'USERNAME'				=> $user->data['username'],
f2e824
f2e824
		'SID'					=> $SID,
f2e824
		'_SID'					=> $_SID,
f2e824
		'SESSION_ID'			=> $user->session_id,
f2e824
		'ROOT_PATH'				=> $phpbb_admin_path,
f2e824
f2e824
		'U_LOGOUT'				=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'),
f2e824
		'U_ADM_LOGOUT'			=> append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'),
f2e824
		'U_ADM_INDEX'			=> append_sid("{$phpbb_admin_path}index.$phpEx"),
f2e824
		'U_INDEX'				=> append_sid("{$phpbb_root_path}index.$phpEx"),
f2e824
f2e824
		'T_IMAGES_PATH'			=> "{$phpbb_root_path}images/",
f2e824
		'T_SMILIES_PATH'		=> "{$phpbb_root_path}{$config['smilies_path']}/",
f2e824
		'T_AVATAR_PATH'			=> "{$phpbb_root_path}{$config['avatar_path']}/",
f2e824
		'T_AVATAR_GALLERY_PATH'	=> "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
f2e824
		'T_ICONS_PATH'			=> "{$phpbb_root_path}{$config['icons_path']}/",
f2e824
		'T_RANKS_PATH'			=> "{$phpbb_root_path}{$config['ranks_path']}/",
f2e824
		'T_UPLOAD_PATH'			=> "{$phpbb_root_path}{$config['upload_path']}/",
f2e824
f2e824
		'ICON_MOVE_UP'				=> '' . $user->lang['MOVE_UP'] . '',
f2e824
		'ICON_MOVE_UP_DISABLED'		=> '' . $user->lang['MOVE_UP'] . '',
f2e824
		'ICON_MOVE_DOWN'			=> '' . $user->lang['MOVE_DOWN'] . '',
f2e824
		'ICON_MOVE_DOWN_DISABLED'	=> '' . $user->lang['MOVE_DOWN'] . '',		
f2e824
		'ICON_EDIT'					=> '' . $user->lang['EDIT'] . '',
f2e824
		'ICON_EDIT_DISABLED'		=> '' . $user->lang['EDIT'] . '',
f2e824
		'ICON_DELETE'				=> '' . $user->lang['DELETE'] . '',
f2e824
		'ICON_DELETE_DISABLED'		=> '' . $user->lang['DELETE'] . '',
f2e824
		'ICON_SYNC'					=> '' . $user->lang['RESYNC'] . '',
f2e824
		'ICON_SYNC_DISABLED'		=> '' . $user->lang['RESYNC'] . '',
f2e824
f2e824
		'S_USER_LANG'			=> $user->lang['USER_LANG'],
f2e824
		'S_CONTENT_DIRECTION'	=> $user->lang['DIRECTION'],
f2e824
		'S_CONTENT_ENCODING'	=> 'UTF-8',
f2e824
		'S_CONTENT_FLOW_BEGIN'	=> ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
f2e824
		'S_CONTENT_FLOW_END'	=> ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
f2e824
	));
f2e824
f2e824
	// application/xhtml+xml not used because of IE
f2e824
	header('Content-type: text/html; charset=UTF-8');
f2e824
f2e824
	header('Cache-Control: private, no-cache="set-cookie"');
f2e824
	header('Expires: 0');
f2e824
	header('Pragma: no-cache');
f2e824
f2e824
	return;
f2e824
}
f2e824
f2e824
/**
f2e824
* Page footer for acp pages
f2e824
*/
f2e824
function adm_page_footer($copyright_html = true)
f2e824
{
f2e824
	global $db, $config, $template, $user, $auth, $cache;
f2e824
	global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
f2e824
f2e824
	// Output page creation time
f2e824
	if (defined('DEBUG'))
f2e824
	{
f2e824
		$mtime = explode(' ', microtime());
f2e824
		$totaltime = $mtime[0] + $mtime[1] - $starttime;
f2e824
f2e824
		if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report'))
f2e824
		{
f2e824
			$db->sql_report('display');
f2e824
		}
f2e824
f2e824
		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
f2e824
f2e824
		if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
f2e824
		{
f2e824
			if (function_exists('memory_get_usage'))
f2e824
			{
f2e824
				if ($memory_usage = memory_get_usage())
f2e824
				{
f2e824
					global $base_memory_usage;
f2e824
					$memory_usage -= $base_memory_usage;
f2e824
					$memory_usage = get_formatted_filesize($memory_usage);
f2e824
f2e824
					$debug_output .= ' | Memory Usage: ' . $memory_usage;
f2e824
				}
f2e824
			}
f2e824
f2e824
			$debug_output .= ' | Explain';
f2e824
		}
f2e824
	}
f2e824
f2e824
	$template->assign_vars(array(
f2e824
		'DEBUG_OUTPUT'		=> (defined('DEBUG')) ? $debug_output : '',
f2e824
		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
f2e824
		'S_COPYRIGHT_HTML'	=> $copyright_html,
f2e824
		'VERSION'			=> $config['version'])
f2e824
	);
f2e824
f2e824
	$template->display('body');
f2e824
f2e824
	garbage_collection();
f2e824
	exit_handler();
f2e824
}
f2e824
f2e824
/**
f2e824
* Generate back link for acp pages
f2e824
*/
f2e824
function adm_back_link($u_action)
f2e824
{
f2e824
	global $user;
f2e824
	return '

« ' . $user->lang['BACK_TO_PREV'] . '';
f2e824
}
f2e824
f2e824
/**
f2e824
* Build select field options in acp pages
f2e824
*/
f2e824
function build_select($option_ary, $option_default = false)
f2e824
{
f2e824
	global $user;
f2e824
f2e824
	$html = '';
f2e824
	foreach ($option_ary as $value => $title)
f2e824
	{
f2e824
		$selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
f2e824
		$html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
f2e824
	}
f2e824
f2e824
	return $html;
f2e824
}
f2e824
f2e824
/**
f2e824
* Build radio fields in acp pages
f2e824
*/
f2e824
function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false)
f2e824
{
f2e824
	global $user;
f2e824
f2e824
	$html = '';
f2e824
	$id_assigned = false;
f2e824
	foreach ($input_ary as $value => $title)
f2e824
	{
f2e824
		$selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
f2e824
		$html .= '<label><input type="radio" name="' . $name . '"' . (($id && !$id_assigned) ? ' id="' . $id . '"' : '') . ' value="' . $value . '"' . $selected . (($key) ? ' accesskey="' . $key . '"' : '') . ' class="radio" /> ' . $user->lang[$title] . '</label>';
f2e824
		$id_assigned = true;
f2e824
	}
f2e824
f2e824
	return $html;
f2e824
}
f2e824
f2e824
/**
f2e824
* Build configuration template for acp configuration pages
f2e824
*/
f2e824
function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
f2e824
{
f2e824
	global $user, $module;
f2e824
f2e824
	$tpl = '';
f2e824
	$name = 'config[' . $config_key . ']';
f2e824
f2e824
	switch ($tpl_type[0])
f2e824
	{
f2e824
		case 'text':
f2e824
		case 'password':
f2e824
			$size = (int) $tpl_type[1];
f2e824
			$maxlength = (int) $tpl_type[2];
f2e824
f2e824
			$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new[$config_key] . '" />';
f2e824
		break;
f2e824
f2e824
		case 'dimension':
f2e824
			$size = (int) $tpl_type[1];
f2e824
			$maxlength = (int) $tpl_type[2];
f2e824
f2e824
			$tpl = '<input id="' . $key . '" type="text"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="config[' . $config_key . '_width]" value="' . $new[$config_key . '_width'] . '" /> x <input type="text"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="config[' . $config_key . '_height]" value="' . $new[$config_key . '_height'] . '" />';
f2e824
		break;
f2e824
f2e824
		case 'textarea':
f2e824
			$rows = (int) $tpl_type[1];
f2e824
			$cols = (int) $tpl_type[2];
f2e824
f2e824
			$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new[$config_key] . '</textarea>';
f2e824
		break;
f2e824
f2e824
		case 'radio':
f2e824
			$key_yes	= ($new[$config_key]) ? ' checked="checked"' : '';
f2e824
			$key_no		= (!$new[$config_key]) ? ' checked="checked"' : '';
f2e824
f2e824
			$tpl_type_cond = explode('_', $tpl_type[1]);
f2e824
			$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
f2e824
f2e824
			$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
f2e824
			$tpl_yes = '<label><input type="radio" id="' . $key . '" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $user->lang['YES'] : $user->lang['ENABLED']) . '</label>';
f2e824
f2e824
			$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
f2e824
		break;
f2e824
f2e824
		case 'select':
f2e824
		case 'custom':
f2e824
			
f2e824
			$return = '';
f2e824
f2e824
			if (isset($vars['method']))
f2e824
			{
f2e824
				$call = array($module->module, $vars['method']);
f2e824
			}
f2e824
			else if (isset($vars['function']))
f2e824
			{
f2e824
				$call = $vars['function'];
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				break;
f2e824
			}
f2e824
f2e824
			if (isset($vars['params']))
f2e824
			{
f2e824
				$args = array();
f2e824
				foreach ($vars['params'] as $value)
f2e824
				{
f2e824
					switch ($value)
f2e824
					{
f2e824
						case '{CONFIG_VALUE}':
f2e824
							$value = $new[$config_key];
f2e824
						break;
f2e824
f2e824
						case '{KEY}':
f2e824
							$value = $key;
f2e824
						break;
f2e824
					}
f2e824
f2e824
					$args[] = $value;
f2e824
				}
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$args = array($new[$config_key], $key);
f2e824
			}
f2e824
			
f2e824
			$return = call_user_func_array($call, $args);
f2e824
f2e824
			if ($tpl_type[0] == 'select')
f2e824
			{
f2e824
				$tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$tpl = $return;
f2e824
			}
f2e824
f2e824
		break;
f2e824
f2e824
		default:
f2e824
		break;
f2e824
	}
f2e824
f2e824
	if (isset($vars['append']))
f2e824
	{
f2e824
		$tpl .= $vars['append'];
f2e824
	}
f2e824
f2e824
	return $tpl;
f2e824
}
f2e824
f2e824
/**
f2e824
* Going through a config array and validate values, writing errors to $error. The validation method  accepts parameters separated by ':' for string and int.
f2e824
* The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required.
f2e824
*/
f2e824
function validate_config_vars($config_vars, &$cfg_array, &$error)
f2e824
{
f2e824
	global $phpbb_root_path, $user;
f2e824
	$type	= 0;
f2e824
	$min	= 1;
f2e824
	$max	= 2;
f2e824
	
f2e824
	foreach ($config_vars as $config_name => $config_definition)
f2e824
	{
f2e824
		if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
f2e824
		{
f2e824
			continue;
f2e824
		}
f2e824
	
f2e824
		if (!isset($config_definition['validate']))
f2e824
		{
f2e824
			continue;
f2e824
		}
f2e824
		
f2e824
		$validator = explode(':', $config_definition['validate']);
f2e824
f2e824
		// Validate a bit. ;) (0 = type, 1 = min, 2= max)
f2e824
		switch ($validator[$type])
f2e824
		{
f2e824
			case 'string':
f2e824
				$length = strlen($cfg_array[$config_name]);
f2e824
f2e824
				// the column is a VARCHAR
f2e824
				$validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
f2e824
f2e824
				if (isset($validator[$min]) && $length < $validator[$min])
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]);
f2e824
				}
f2e824
				else if (isset($validator[$max]) && $length > $validator[2])
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]);
f2e824
				}
f2e824
			break;
f2e824
f2e824
			case 'bool':
f2e824
				$cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
f2e824
			break;
f2e824
f2e824
			case 'int':
f2e824
				$cfg_array[$config_name] = (int) $cfg_array[$config_name];
f2e824
f2e824
				if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min])
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]);
f2e824
				}
f2e824
				else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max])
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]);
f2e824
				}
f2e824
			break;
f2e824
f2e824
			// Absolute path
f2e824
			case 'script_path':
f2e824
				if (!$cfg_array[$config_name])
f2e824
				{
f2e824
					break;
f2e824
				}
f2e824
f2e824
				$destination = str_replace('\\', '/', $cfg_array[$config_name]);
f2e824
f2e824
				if ($destination !== '/')
f2e824
				{
f2e824
					// Adjust destination path (no trailing slash)
f2e824
					if (substr($destination, -1, 1) == '/')
f2e824
					{
f2e824
						$destination = substr($destination, 0, -1);
f2e824
					}
f2e824
f2e824
					$destination = str_replace(array('../', './'), '', $destination);
f2e824
f2e824
					if ($destination[0] != '/')
f2e824
					{
f2e824
						$destination = '/' . $destination;
f2e824
					}
f2e824
				}
f2e824
f2e824
				$cfg_array[$config_name] = trim($destination);
f2e824
f2e824
			break;
f2e824
f2e824
			// Absolute path
f2e824
			case 'lang':
f2e824
				if (!$cfg_array[$config_name])
f2e824
				{
f2e824
					break;
f2e824
				}
f2e824
f2e824
				$cfg_array[$config_name] = basename($cfg_array[$config_name]);
f2e824
f2e824
				if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/'))
f2e824
				{
f2e824
					$error[] = $user->lang['WRONG_DATA_LANG'];
f2e824
				}
f2e824
			break;
f2e824
f2e824
			// Relative path (appended $phpbb_root_path)
f2e824
			case 'rpath':
f2e824
			case 'rwpath':
f2e824
				if (!$cfg_array[$config_name])
f2e824
				{
f2e824
					break;
f2e824
				}
f2e824
f2e824
				$destination = $cfg_array[$config_name];
f2e824
f2e824
				// Adjust destination path (no trailing slash)
f2e824
				if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
f2e824
				{
f2e824
					$destination = substr($destination, 0, -1);
f2e824
				}
f2e824
f2e824
				$destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
f2e824
				if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
f2e824
				{
f2e824
					$destination = '';
f2e824
				}
f2e824
f2e824
				$cfg_array[$config_name] = trim($destination);
f2e824
f2e824
			// Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...
f2e824
			case 'path':
f2e824
			case 'wpath':
f2e824
f2e824
				if (!$cfg_array[$config_name])
f2e824
				{
f2e824
					break;
f2e824
				}
f2e824
f2e824
				$cfg_array[$config_name] = trim($cfg_array[$config_name]);
f2e824
f2e824
				// Make sure no NUL byte is present...
f2e824
				if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false)
f2e824
				{
f2e824
					$cfg_array[$config_name] = '';
f2e824
					break;
f2e824
				}
f2e824
f2e824
				if (!file_exists($phpbb_root_path . $cfg_array[$config_name]))
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);
f2e824
				}
f2e824
f2e824
				if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name]))
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);
f2e824
				}
f2e824
f2e824
				// Check if the path is writable
f2e824
				if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath')
f2e824
				{
f2e824
					if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !@is_writable($phpbb_root_path . $cfg_array[$config_name]))
f2e824
					{
f2e824
						$error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);
f2e824
					}
f2e824
				}
f2e824
f2e824
			break;
f2e824
		}
f2e824
	}
f2e824
f2e824
	return;
f2e824
}
f2e824
f2e824
/**
f2e824
* Checks whatever or not a variable is OK for use in the Database
f2e824
* param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))'
f2e824
* param mixed $error The error array
f2e824
*/
f2e824
function validate_range($value_ary, &$error)
f2e824
{
f2e824
	global $user;
f2e824
	
f2e824
	$column_types = array(
f2e824
		'BOOL'	=> array('php_type' => 'int', 		'min' => 0, 				'max' => 1),
f2e824
		'USINT'	=> array('php_type' => 'int',		'min' => 0, 				'max' => 65535),
f2e824
		'UINT'	=> array('php_type' => 'int', 		'min' => 0, 				'max' => (int) 0x7fffffff),
f2e824
		'INT'	=> array('php_type' => 'int', 		'min' => (int) 0x80000000, 	'max' => (int) 0x7fffffff),
f2e824
		'TINT'	=> array('php_type' => 'int',		'min' => -128,				'max' => 127),
f2e824
		
f2e824
		'VCHAR'	=> array('php_type' => 'string', 	'min' => 0, 				'max' => 255),
f2e824
	);
f2e824
	foreach ($value_ary as $value)
f2e824
	{
f2e824
		$column = explode(':', $value['column_type']);
f2e824
		$max = $min = 0;
f2e824
		$type = 0;
f2e824
		if (!isset($column_types[$column[0]]))
f2e824
		{
f2e824
			continue;
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$type = $column_types[$column[0]];
f2e824
		}
f2e824
f2e824
		switch ($type['php_type'])
f2e824
		{
f2e824
			case 'string' :
f2e824
				$max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max'];
f2e824
				if (strlen($value['value']) > $max)
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max);
f2e824
				}
f2e824
			break;
f2e824
f2e824
			case 'int': 
f2e824
				$min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min'];
f2e824
				$max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max'];
f2e824
				if ($value['value'] < $min)
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min);
f2e824
				}
f2e824
				else if ($value['value'] > $max)
f2e824
				{
f2e824
					$error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max);
f2e824
				}
f2e824
			break;
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
?>