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

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

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