Register
phpBB.com Wiki · Home Projects Help

root / trunk / phpBB / adm / index.php

1 3646 psotfx
<?php
2 8146 acydburn
/**
3 5114 acydburn
*
4 5114 acydburn
* @package acp
5 5114 acydburn
* @version $Id$
6 8146 acydburn
* @copyright (c) 2005 phpBB Group
7 8146 acydburn
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 5114 acydburn
*
9 5114 acydburn
*/
10 3646 psotfx
11 5114 acydburn
/**
12 5114 acydburn
*/
13 7218 acydburn
define('IN_PHPBB', true);
14 7218 acydburn
define('ADMIN_START', true);
15 5357 acydburn
define('NEED_SID', true);
16 5357 acydburn
17 3646 psotfx
// Include files
18 8572 acydburn
if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './../');
19 8572 acydburn
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
20 8607 Kellanved
if (!defined('PHPBB_ADMIN_PATH')) define('PHPBB_ADMIN_PATH', './');
21 8607 Kellanved
22 8572 acydburn
include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
23 8572 acydburn
require(PHPBB_ROOT_PATH . 'includes/functions_admin.' . PHP_EXT);
24 8572 acydburn
require(PHPBB_ROOT_PATH . 'includes/functions_module.' . PHP_EXT);
25 3646 psotfx
26 5357 acydburn
// Start session management
27 5357 acydburn
$user->session_begin();
28 5357 acydburn
$auth->acl($user->data);
29 5357 acydburn
$user->setup('acp/common');
30 5357 acydburn
// End session management
31 5357 acydburn
32 5357 acydburn
// Have they authenticated (again) as an admin for this session?
33 8587 Kellanved
if ($user->data['user_id'] != ANONYMOUS &&  (!isset($user->data['session_admin']) || !$user->data['session_admin']))
34 5357 acydburn
{
35 5357 acydburn
	login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
36 5357 acydburn
}
37 8587 Kellanved
else if ($user->data['user_id'] == ANONYMOUS)
38 8587 Kellanved
{
39 8587 Kellanved
	login_box('');
40 8587 Kellanved
}
41 5357 acydburn
42 5357 acydburn
// Is user any type of admin? No, then stop here, each script needs to
43 5357 acydburn
// check specific permissions but this is a catchall
44 3646 psotfx
if (!$auth->acl_get('a_'))
45 3646 psotfx
{
46 7919 kellanved
	trigger_error('NO_ADMIN');
47 3646 psotfx
}
48 3646 psotfx
49 5603 acydburn
// We define the admin variables now, because the user is now able to use the admin related features...
50 5558 acydburn
define('IN_ADMIN', true);
51 5558 acydburn
52 5357 acydburn
// Some oft used variables
53 8579 vic
$safe_mode		= (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) === 'on') ? true : false;
54 8294 kellanved
$file_uploads	= (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_uploads')) === 'on') ? true : false;
55 5357 acydburn
$module_id		= request_var('i', '');
56 5357 acydburn
$mode			= request_var('mode', '');
57 4429 psotfx
58 5357 acydburn
// Set custom template for admin area
59 8572 acydburn
$template->set_custom_template(PHPBB_ADMIN_PATH . 'style', 'admin');
60 8572 acydburn
$template->assign_var('T_TEMPLATE_PATH', PHPBB_ADMIN_PATH . 'style');
61 6015 acydburn
62 5357 acydburn
// Instantiate new module
63 5357 acydburn
$module = new p_master();
64 3646 psotfx
65 5357 acydburn
// Instantiate module system and generate list of available modules
66 5357 acydburn
$module->list_modules('acp');
67 3646 psotfx
68 5357 acydburn
// Select the active module
69 5357 acydburn
$module->set_active($module_id, $mode);
70 3646 psotfx
71 5357 acydburn
// Assign data to the template engine for the list of modules
72 5357 acydburn
// We do this before loading the active module for correct menu display in trigger_error
73 8652 aptx
$module->assign_tpl_vars(append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT));
74 3646 psotfx
75 5357 acydburn
// Load and execute the relevant module
76 5357 acydburn
$module->load_active();
77 3646 psotfx
78 5357 acydburn
// Generate the page
79 5357 acydburn
adm_page_header($module->get_page_title());
80 3646 psotfx
81 5357 acydburn
$template->set_filenames(array(
82 8277 acydburn
	'body' => $module->get_tpl_name(),
83 8277 acydburn
));
84 3646 psotfx
85 5357 acydburn
adm_page_footer();
86 3646 psotfx
87 6015 acydburn
/**
88 6015 acydburn
* Header for acp pages
89 6015 acydburn
*/
90 5357 acydburn
function adm_page_header($page_title)
91 5357 acydburn
{
92 9242 acydburn
	global $db, $user, $template;
93 8572 acydburn
	global $SID, $_SID;
94 3646 psotfx
95 5357 acydburn
	if (defined('HEADER_INC'))
96 3646 psotfx
	{
97 5357 acydburn
		return;
98 5357 acydburn
	}
99 6015 acydburn
100 5357 acydburn
	define('HEADER_INC', true);
101 5357 acydburn
102 5357 acydburn
	// gzip_compression
103 9242 acydburn
	if (phpbb::$config['gzip_compress'])
104 5357 acydburn
	{
105 6073 acydburn
		if (@extension_loaded('zlib') && !headers_sent())
106 3646 psotfx
		{
107 5357 acydburn
			ob_start('ob_gzhandler');
108 5357 acydburn
		}
109 5357 acydburn
	}
110 3646 psotfx
111 5357 acydburn
	$template->assign_vars(array(
112 5357 acydburn
		'PAGE_TITLE'			=> $page_title,
113 8587 Kellanved
		'USERNAME'				=> ($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '',
114 6015 acydburn
115 6015 acydburn
		'SID'					=> $SID,
116 6015 acydburn
		'_SID'					=> $_SID,
117 6015 acydburn
		'SESSION_ID'			=> $user->session_id,
118 8572 acydburn
		'ROOT_PATH'				=> PHPBB_ADMIN_PATH,
119 3646 psotfx
120 8572 acydburn
		'U_LOGOUT'				=> append_sid('ucp', 'mode=logout'),
121 8587 Kellanved
		'U_ADM_LOGOUT'			=> append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, 'action=admlogout'),
122 8572 acydburn
		'U_ADM_INDEX'			=> append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT),
123 8572 acydburn
		'U_INDEX'				=> append_sid('index'),
124 3646 psotfx
125 8587 Kellanved
		'S_USER_ADMIN'			=> $user->data['session_admin'],
126 8587 Kellanved
		'S_USER_LOGGED_IN'		=> ($user->data['user_id'] != ANONYMOUS && !$user->data['is_bot']),
127 8587 Kellanved
128 8572 acydburn
		'T_IMAGES_PATH'			=> PHPBB_ROOT_PATH . 'images/',
129 9242 acydburn
		'T_SMILIES_PATH'		=> PHPBB_ROOT_PATH . phpbb::$config['smilies_path'] . '/',
130 9242 acydburn
		'T_AVATAR_PATH'			=> PHPBB_ROOT_PATH . phpbb::$config['avatar_path'] . '/',
131 9242 acydburn
		'T_AVATAR_GALLERY_PATH'	=> PHPBB_ROOT_PATH . phpbb::$config['avatar_gallery_path'] . '/',
132 9242 acydburn
		'T_ICONS_PATH'			=> PHPBB_ROOT_PATH . phpbb::$config['icons_path'] . '/',
133 9242 acydburn
		'T_RANKS_PATH'			=> PHPBB_ROOT_PATH . phpbb::$config['ranks_path'] . '/',
134 9242 acydburn
		'T_UPLOAD_PATH'			=> PHPBB_ROOT_PATH . phpbb::$config['upload_path'] . '/',
135 6055 acydburn
136 8572 acydburn
		'ICON_MOVE_UP'				=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_up.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
137 8572 acydburn
		'ICON_MOVE_UP_DISABLED'		=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_up_disabled.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
138 8572 acydburn
		'ICON_MOVE_DOWN'			=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_down.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',
139 9230 acydburn
		'ICON_MOVE_DOWN_DISABLED'	=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_down_disabled.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',
140 8572 acydburn
		'ICON_EDIT'					=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_edit.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
141 8572 acydburn
		'ICON_EDIT_DISABLED'		=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_edit_disabled.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
142 8572 acydburn
		'ICON_DELETE'				=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_delete.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
143 8572 acydburn
		'ICON_DELETE_DISABLED'		=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_delete_disabled.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
144 8572 acydburn
		'ICON_SYNC'					=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_sync.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
145 8572 acydburn
		'ICON_SYNC_DISABLED'		=> '<img src="' . PHPBB_ADMIN_PATH . 'images/icon_sync_disabled.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
146 6073 acydburn
147 6468 grahamje
		'S_USER_LANG'			=> $user->lang['USER_LANG'],
148 6015 acydburn
		'S_CONTENT_DIRECTION'	=> $user->lang['DIRECTION'],
149 6380 naderman
		'S_CONTENT_ENCODING'	=> 'UTF-8',
150 7954 acydburn
		'S_CONTENT_FLOW_BEGIN'	=> ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
151 7954 acydburn
		'S_CONTENT_FLOW_END'	=> ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
152 6905 acydburn
	));
153 3646 psotfx
154 6816 acydburn
	// application/xhtml+xml not used because of IE
155 6816 acydburn
	header('Content-type: text/html; charset=UTF-8');
156 6816 acydburn
157 6114 acydburn
	header('Cache-Control: private, no-cache="set-cookie"');
158 5357 acydburn
	header('Expires: 0');
159 5357 acydburn
	header('Pragma: no-cache');
160 3646 psotfx
161 5357 acydburn
	return;
162 3646 psotfx
}
163 5357 acydburn
164 6015 acydburn
/**
165 6015 acydburn
* Page footer for acp pages
166 6015 acydburn
*/
167 5357 acydburn
function adm_page_footer($copyright_html = true)
168 3646 psotfx
{
169 9242 acydburn
	global $db, $template, $user, $auth;
170 8572 acydburn
	global $starttime;
171 4583 psotfx
172 5357 acydburn
	// Output page creation time
173 5357 acydburn
	if (defined('DEBUG'))
174 3646 psotfx
	{
175 5357 acydburn
		$mtime = explode(' ', microtime());
176 5357 acydburn
		$totaltime = $mtime[0] + $mtime[1] - $starttime;
177 5357 acydburn
178 9230 acydburn
		if (phpbb_request::variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report'))
179 3646 psotfx
		{
180 5357 acydburn
			$db->sql_report('display');
181 5357 acydburn
		}
182 3646 psotfx
183 9242 acydburn
		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . ((phpbb::$config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
184 3646 psotfx
185 5357 acydburn
		if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
186 5357 acydburn
		{
187 5357 acydburn
			if (function_exists('memory_get_usage'))
188 5357 acydburn
			{
189 5357 acydburn
				if ($memory_usage = memory_get_usage())
190 4618 psotfx
				{
191 5357 acydburn
					global $base_memory_usage;
192 5357 acydburn
					$memory_usage -= $base_memory_usage;
193 8391 acydburn
					$memory_usage = get_formatted_filesize($memory_usage);
194 5200 acydburn
195 5357 acydburn
					$debug_output .= ' | Memory Usage: ' . $memory_usage;
196 5152 acydburn
				}
197 5357 acydburn
			}
198 5152 acydburn
199 5902 acydburn
			$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
200 5357 acydburn
		}
201 5357 acydburn
	}
202 4583 psotfx
203 5357 acydburn
	$template->assign_vars(array(
204 5357 acydburn
		'DEBUG_OUTPUT'		=> (defined('DEBUG')) ? $debug_output : '',
205 6584 acydburn
		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
206 5357 acydburn
		'S_COPYRIGHT_HTML'	=> $copyright_html,
207 9242 acydburn
		'VERSION'			=> phpbb::$config['version'])
208 5357 acydburn
	);
209 3720 psotfx
210 5357 acydburn
	$template->display('body');
211 3720 psotfx
212 6149 acydburn
	garbage_collection();
213 8072 acydburn
	exit_handler();
214 5357 acydburn
}
215 4583 psotfx
216 6015 acydburn
/**
217 6015 acydburn
* Generate back link for acp pages
218 6015 acydburn
*/
219 5357 acydburn
function adm_back_link($u_action)
220 5357 acydburn
{
221 5986 naderman
	global $user;
222 5986 naderman
	return '<br /><br /><a href="' . $u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>';
223 5357 acydburn
}
224 4583 psotfx
225 6015 acydburn
/**
226 6015 acydburn
* Build select field options in acp pages
227 6015 acydburn
*/
228 5357 acydburn
function build_select($option_ary, $option_default = false)
229 5357 acydburn
{
230 5357 acydburn
	global $user;
231 3720 psotfx
232 5357 acydburn
	$html = '';
233 5357 acydburn
	foreach ($option_ary as $value => $title)
234 5357 acydburn
	{
235 5357 acydburn
		$selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
236 5357 acydburn
		$html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
237 5357 acydburn
	}
238 3720 psotfx
239 5357 acydburn
	return $html;
240 5357 acydburn
}
241 3720 psotfx
242 6015 acydburn
/**
243 6015 acydburn
* Build radio fields in acp pages
244 6015 acydburn
*/
245 5357 acydburn
function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false)
246 5357 acydburn
{
247 5357 acydburn
	global $user;
248 3720 psotfx
249 5357 acydburn
	$html = '';
250 5357 acydburn
	$id_assigned = false;
251 5357 acydburn
	foreach ($input_ary as $value => $title)
252 5357 acydburn
	{
253 5357 acydburn
		$selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
254 7464 acydburn
		$html .= '<label><input type="radio" name="' . $name . '"' . (($id && !$id_assigned) ? ' id="' . $id . '"' : '') . ' value="' . $value . '"' . $selected . (($key) ? ' accesskey="' . $key . '"' : '') . ' class="radio" /> ' . $user->lang[$title] . '</label>';
255 5357 acydburn
		$id_assigned = true;
256 5357 acydburn
	}
257 4583 psotfx
258 5357 acydburn
	return $html;
259 5357 acydburn
}
260 4583 psotfx
261 6015 acydburn
/**
262 6015 acydburn
* Build configuration template for acp configuration pages
263 6015 acydburn
*/
264 5357 acydburn
function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
265 5357 acydburn
{
266 5357 acydburn
	global $user, $module;
267 5090 bartvb
268 5357 acydburn
	$tpl = '';
269 5357 acydburn
	$name = 'config[' . $config_key . ']';
270 4618 psotfx
271 5357 acydburn
	switch ($tpl_type[0])
272 3646 psotfx
	{
273 5357 acydburn
		case 'text':
274 5357 acydburn
		case 'password':
275 5357 acydburn
			$size = (int) $tpl_type[1];
276 5357 acydburn
			$maxlength = (int) $tpl_type[2];
277 3646 psotfx
278 5357 acydburn
			$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new[$config_key] . '" />';
279 6015 acydburn
		break;
280 3708 psotfx
281 5357 acydburn
		case 'dimension':
282 5357 acydburn
			$size = (int) $tpl_type[1];
283 5357 acydburn
			$maxlength = (int) $tpl_type[2];
284 3708 psotfx
285 8092 acydburn
			$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'] . '" />';
286 6015 acydburn
		break;
287 3708 psotfx
288 5357 acydburn
		case 'textarea':
289 5357 acydburn
			$rows = (int) $tpl_type[1];
290 5357 acydburn
			$cols = (int) $tpl_type[2];
291 3708 psotfx
292 5357 acydburn
			$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new[$config_key] . '</textarea>';
293 6015 acydburn
		break;
294 3708 psotfx
295 5357 acydburn
		case 'radio':
296 5357 acydburn
			$key_yes	= ($new[$config_key]) ? ' checked="checked"' : '';
297 5357 acydburn
			$key_no		= (!$new[$config_key]) ? ' checked="checked"' : '';
298 3708 psotfx
299 5357 acydburn
			$tpl_type_cond = explode('_', $tpl_type[1]);
300 5357 acydburn
			$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
301 3646 psotfx
302 7464 acydburn
			$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
303 7464 acydburn
			$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>';
304 4618 psotfx
305 7464 acydburn
			$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
306 6015 acydburn
		break;
307 4618 psotfx
308 5357 acydburn
		case 'select':
309 5357 acydburn
		case 'custom':
310 9230 acydburn
311 5357 acydburn
			$return = '';
312 5040 acydburn
313 5357 acydburn
			if (isset($vars['method']))
314 5040 acydburn
			{
315 5357 acydburn
				$call = array($module->module, $vars['method']);
316 5040 acydburn
			}
317 5357 acydburn
			else if (isset($vars['function']))
318 5040 acydburn
			{
319 5357 acydburn
				$call = $vars['function'];
320 5114 acydburn
			}
321 5114 acydburn
			else
322 5114 acydburn
			{
323 5357 acydburn
				break;
324 5040 acydburn
			}
325 6015 acydburn
326 5357 acydburn
			if (isset($vars['params']))
327 4618 psotfx
			{
328 5357 acydburn
				$args = array();
329 5357 acydburn
				foreach ($vars['params'] as $value)
330 3646 psotfx
				{
331 5357 acydburn
					switch ($value)
332 3646 psotfx
					{
333 5357 acydburn
						case '{CONFIG_VALUE}':
334 5357 acydburn
							$value = $new[$config_key];
335 5357 acydburn
						break;
336 5357 acydburn
337 5357 acydburn
						case '{KEY}':
338 5357 acydburn
							$value = $key;
339 5357 acydburn
						break;
340 3646 psotfx
					}
341 5357 acydburn
342 5357 acydburn
					$args[] = $value;
343 3646 psotfx
				}
344 3646 psotfx
			}
345 3646 psotfx
			else
346 3646 psotfx
			{
347 5357 acydburn
				$args = array($new[$config_key], $key);
348 3646 psotfx
			}
349 9230 acydburn
350 5357 acydburn
			$return = call_user_func_array($call, $args);
351 3646 psotfx
352 5357 acydburn
			if ($tpl_type[0] == 'select')
353 3646 psotfx
			{
354 5357 acydburn
				$tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';
355 3646 psotfx
			}
356 5357 acydburn
			else
357 3720 psotfx
			{
358 5357 acydburn
				$tpl = $return;
359 3720 psotfx
			}
360 3720 psotfx
361 6015 acydburn
		break;
362 3646 psotfx
363 5357 acydburn
		default:
364 6015 acydburn
		break;
365 3646 psotfx
	}
366 3646 psotfx
367 5357 acydburn
	if (isset($vars['append']))
368 3800 ludovic_arnaud
	{
369 5357 acydburn
		$tpl .= $vars['append'];
370 3800 ludovic_arnaud
	}
371 6015 acydburn
372 5357 acydburn
	return $tpl;
373 3646 psotfx
}
374 3646 psotfx
375 6367 acydburn
/**
376 8411 Kellanved
* Going through a config array and validate values, writing errors to $error. The validation method  accepts parameters separated by ':' for string and int.
377 8411 Kellanved
* 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.
378 6367 acydburn
*/
379 6367 acydburn
function validate_config_vars($config_vars, &$cfg_array, &$error)
380 6367 acydburn
{
381 8572 acydburn
	global $user;
382 8572 acydburn
383 8411 Kellanved
	$type	= 0;
384 8411 Kellanved
	$min	= 1;
385 8411 Kellanved
	$max	= 2;
386 9230 acydburn
387 6367 acydburn
	foreach ($config_vars as $config_name => $config_definition)
388 6367 acydburn
	{
389 6367 acydburn
		if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
390 6367 acydburn
		{
391 6367 acydburn
			continue;
392 6367 acydburn
		}
393 9230 acydburn
394 6367 acydburn
		if (!isset($config_definition['validate']))
395 6367 acydburn
		{
396 6367 acydburn
			continue;
397 6367 acydburn
		}
398 9230 acydburn
399 8411 Kellanved
		$validator = explode(':', $config_definition['validate']);
400 8431 acydburn
401 8411 Kellanved
		// Validate a bit. ;) (0 = type, 1 = min, 2= max)
402 8411 Kellanved
		switch ($validator[$type])
403 6367 acydburn
		{
404 8411 Kellanved
			case 'string':
405 8411 Kellanved
				$length = strlen($cfg_array[$config_name]);
406 8431 acydburn
407 8411 Kellanved
				// the column is a VARCHAR
408 8411 Kellanved
				$validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
409 8431 acydburn
410 8411 Kellanved
				if (isset($validator[$min]) && $length < $validator[$min])
411 8411 Kellanved
				{
412 8411 Kellanved
					$error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]);
413 8411 Kellanved
				}
414 8411 Kellanved
				else if (isset($validator[$max]) && $length > $validator[2])
415 8411 Kellanved
				{
416 8411 Kellanved
					$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]);
417 8411 Kellanved
				}
418 8411 Kellanved
			break;
419 8431 acydburn
420 6367 acydburn
			case 'bool':
421 6367 acydburn
				$cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
422 6367 acydburn
			break;
423 6367 acydburn
424 6367 acydburn
			case 'int':
425 6367 acydburn
				$cfg_array[$config_name] = (int) $cfg_array[$config_name];
426 8431 acydburn
427 8411 Kellanved
				if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min])
428 8411 Kellanved
				{
429 8411 Kellanved
					$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]);
430 8411 Kella