indvdum@0: session_begin();
indvdum@0: $auth->acl($user->data);
indvdum@0: $user->setup('acp/common');
indvdum@0: // End session management
indvdum@0:
indvdum@0: // Have they authenticated (again) as an admin for this session?
indvdum@0: if (!isset($user->data['session_admin']) || !$user->data['session_admin'])
indvdum@0: {
indvdum@0: login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
indvdum@0: }
indvdum@0:
indvdum@0: // Is user any type of admin? No, then stop here, each script needs to
indvdum@0: // check specific permissions but this is a catchall
indvdum@0: if (!$auth->acl_get('a_'))
indvdum@0: {
indvdum@0: trigger_error('NO_ADMIN');
indvdum@0: }
indvdum@0:
indvdum@0: // We define the admin variables now, because the user is now able to use the admin related features...
indvdum@0: define('IN_ADMIN', true);
indvdum@0: $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
indvdum@0:
indvdum@0: // Some oft used variables
indvdum@0: $safe_mode = (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) === 'on') ? true : false;
indvdum@0: $file_uploads = (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_uploads')) === 'on') ? true : false;
indvdum@0: $module_id = request_var('i', '');
indvdum@0: $mode = request_var('mode', '');
indvdum@0:
indvdum@0: // Set custom template for admin area
indvdum@0: $template->set_custom_template($phpbb_admin_path . 'style', 'admin');
indvdum@0: $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
indvdum@0:
indvdum@0: // the acp template is never stored in the database
indvdum@0: $user->theme['template_storedb'] = false;
indvdum@0:
indvdum@0: // Instantiate new module
indvdum@0: $module = new p_master();
indvdum@0:
indvdum@0: // Instantiate module system and generate list of available modules
indvdum@0: $module->list_modules('acp');
indvdum@0:
indvdum@0: // Select the active module
indvdum@0: $module->set_active($module_id, $mode);
indvdum@0:
indvdum@0: // Assign data to the template engine for the list of modules
indvdum@0: // We do this before loading the active module for correct menu display in trigger_error
indvdum@0: $module->assign_tpl_vars(append_sid("{$phpbb_admin_path}index.$phpEx"));
indvdum@0:
indvdum@0: // Load and execute the relevant module
indvdum@0: $module->load_active();
indvdum@0:
indvdum@0: // Generate the page
indvdum@0: adm_page_header($module->get_page_title());
indvdum@0:
indvdum@0: $template->set_filenames(array(
indvdum@0: 'body' => $module->get_tpl_name(),
indvdum@0: ));
indvdum@0:
indvdum@0: adm_page_footer();
indvdum@0:
indvdum@0: /**
indvdum@0: * Header for acp pages
indvdum@0: */
indvdum@0: function adm_page_header($page_title)
indvdum@0: {
indvdum@0: global $config, $db, $user, $template;
indvdum@0: global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
indvdum@0:
indvdum@0: if (defined('HEADER_INC'))
indvdum@0: {
indvdum@0: return;
indvdum@0: }
indvdum@0:
indvdum@0: define('HEADER_INC', true);
indvdum@0:
indvdum@0: // gzip_compression
indvdum@0: if ($config['gzip_compress'])
indvdum@0: {
indvdum@0: if (@extension_loaded('zlib') && !headers_sent())
indvdum@0: {
indvdum@0: ob_start('ob_gzhandler');
indvdum@0: }
indvdum@0: }
indvdum@0:
indvdum@0: $template->assign_vars(array(
indvdum@0: 'PAGE_TITLE' => $page_title,
indvdum@0: 'USERNAME' => $user->data['username'],
indvdum@0:
indvdum@0: 'SID' => $SID,
indvdum@0: '_SID' => $_SID,
indvdum@0: 'SESSION_ID' => $user->session_id,
indvdum@0: 'ROOT_PATH' => $phpbb_admin_path,
indvdum@0:
indvdum@0: 'U_LOGOUT' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'),
indvdum@0: 'U_ADM_LOGOUT' => append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'),
indvdum@0: 'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"),
indvdum@0: 'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"),
indvdum@0:
indvdum@0: 'T_IMAGES_PATH' => "{$phpbb_root_path}images/",
indvdum@0: 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/",
indvdum@0: 'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/",
indvdum@0: 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
indvdum@0: 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/",
indvdum@0: 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/",
indvdum@0: 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/",
indvdum@0:
indvdum@0: 'ICON_MOVE_UP' => '
',
indvdum@0: 'ICON_MOVE_UP_DISABLED' => '
',
indvdum@0: 'ICON_MOVE_DOWN' => '
',
indvdum@0: 'ICON_MOVE_DOWN_DISABLED' => '
',
indvdum@0: 'ICON_EDIT' => '
',
indvdum@0: 'ICON_EDIT_DISABLED' => '
',
indvdum@0: 'ICON_DELETE' => '
',
indvdum@0: 'ICON_DELETE_DISABLED' => '
',
indvdum@0: 'ICON_SYNC' => '
',
indvdum@0: 'ICON_SYNC_DISABLED' => '
',
indvdum@0:
indvdum@0: 'S_USER_LANG' => $user->lang['USER_LANG'],
indvdum@0: 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'],
indvdum@0: 'S_CONTENT_ENCODING' => 'UTF-8',
indvdum@0: 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
indvdum@0: 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
indvdum@0: ));
indvdum@0:
indvdum@0: // application/xhtml+xml not used because of IE
indvdum@0: header('Content-type: text/html; charset=UTF-8');
indvdum@0:
indvdum@0: header('Cache-Control: private, no-cache="set-cookie"');
indvdum@0: header('Expires: 0');
indvdum@0: header('Pragma: no-cache');
indvdum@0:
indvdum@0: return;
indvdum@0: }
indvdum@0:
indvdum@0: /**
indvdum@0: * Page footer for acp pages
indvdum@0: */
indvdum@0: function adm_page_footer($copyright_html = true)
indvdum@0: {
indvdum@0: global $db, $config, $template, $user, $auth, $cache;
indvdum@0: global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
indvdum@0:
indvdum@0: // Output page creation time
indvdum@0: if (defined('DEBUG'))
indvdum@0: {
indvdum@0: $mtime = explode(' ', microtime());
indvdum@0: $totaltime = $mtime[0] + $mtime[1] - $starttime;
indvdum@0:
indvdum@0: if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report'))
indvdum@0: {
indvdum@0: $db->sql_report('display');
indvdum@0: }
indvdum@0:
indvdum@0: $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
indvdum@0:
indvdum@0: if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
indvdum@0: {
indvdum@0: if (function_exists('memory_get_usage'))
indvdum@0: {
indvdum@0: if ($memory_usage = memory_get_usage())
indvdum@0: {
indvdum@0: global $base_memory_usage;
indvdum@0: $memory_usage -= $base_memory_usage;
indvdum@0: $memory_usage = get_formatted_filesize($memory_usage);
indvdum@0:
indvdum@0: $debug_output .= ' | Memory Usage: ' . $memory_usage;
indvdum@0: }
indvdum@0: }
indvdum@0:
indvdum@0: $debug_output .= ' | Explain';
indvdum@0: }
indvdum@0: }
indvdum@0:
indvdum@0: $template->assign_vars(array(
indvdum@0: 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '',
indvdum@0: 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
indvdum@0: 'S_COPYRIGHT_HTML' => $copyright_html,
indvdum@0: 'VERSION' => $config['version'])
indvdum@0: );
indvdum@0:
indvdum@0: $template->display('body');
indvdum@0:
indvdum@0: garbage_collection();
indvdum@0: exit_handler();
indvdum@0: }
indvdum@0:
indvdum@0: /**
indvdum@0: * Generate back link for acp pages
indvdum@0: */
indvdum@0: function adm_back_link($u_action)
indvdum@0: {
indvdum@0: global $user;
indvdum@0: return '
« ' . $user->lang['BACK_TO_PREV'] . '';
indvdum@0: }
indvdum@0:
indvdum@0: /**
indvdum@0: * Build select field options in acp pages
indvdum@0: */
indvdum@0: function build_select($option_ary, $option_default = false)
indvdum@0: {
indvdum@0: global $user;
indvdum@0:
indvdum@0: $html = '';
indvdum@0: foreach ($option_ary as $value => $title)
indvdum@0: {
indvdum@0: $selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
indvdum@0: $html .= '';
indvdum@0: }
indvdum@0:
indvdum@0: return $html;
indvdum@0: }
indvdum@0:
indvdum@0: /**
indvdum@0: * Build radio fields in acp pages
indvdum@0: */
indvdum@0: function h_radio($name, $input_ary, $input_default = false, $id = false, $key = false, $separator = '')
indvdum@0: {
indvdum@0: global $user;
indvdum@0:
indvdum@0: $html = '';
indvdum@0: $id_assigned = false;
indvdum@0: foreach ($input_ary as $value => $title)
indvdum@0: {
indvdum@0: $selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
indvdum@0: $html .= '' . $separator;
indvdum@0: $id_assigned = true;
indvdum@0: }
indvdum@0:
indvdum@0: return $html;
indvdum@0: }
indvdum@0:
indvdum@0: /**
indvdum@0: * Build configuration template for acp configuration pages
indvdum@0: */
indvdum@0: function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
indvdum@0: {
indvdum@0: global $user, $module;
indvdum@0:
indvdum@0: $tpl = '';
indvdum@0: $name = 'config[' . $config_key . ']';
indvdum@0:
indvdum@0: // Make sure there is no notice printed out for non-existent config options (we simply set them)
indvdum@0: if (!isset($new[$config_key]))
indvdum@0: {
indvdum@0: $new[$config_key] = '';
indvdum@0: }
indvdum@0:
indvdum@0: switch ($tpl_type[0])
indvdum@0: {
indvdum@0: case 'text':
indvdum@0: case 'password':
indvdum@0: $size = (int) $tpl_type[1];
indvdum@0: $maxlength = (int) $tpl_type[2];
indvdum@0:
indvdum@0: $tpl = '';
indvdum@0: break;
indvdum@0:
indvdum@0: case 'dimension':
indvdum@0: $size = (int) $tpl_type[1];
indvdum@0: $maxlength = (int) $tpl_type[2];
indvdum@0:
indvdum@0: $tpl = ' x ';
indvdum@0: break;
indvdum@0:
indvdum@0: case 'textarea':
indvdum@0: $rows = (int) $tpl_type[1];
indvdum@0: $cols = (int) $tpl_type[2];
indvdum@0:
indvdum@0: $tpl = '';
indvdum@0: break;
indvdum@0:
indvdum@0: case 'radio':
indvdum@0: $key_yes = ($new[$config_key]) ? ' checked="checked"' : '';
indvdum@0: $key_no = (!$new[$config_key]) ? ' checked="checked"' : '';
indvdum@0:
indvdum@0: $tpl_type_cond = explode('_', $tpl_type[1]);
indvdum@0: $type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
indvdum@0:
indvdum@0: $tpl_no = '';
indvdum@0: $tpl_yes = '';
indvdum@0:
indvdum@0: $tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
indvdum@0: break;
indvdum@0:
indvdum@0: case 'select':
indvdum@0: case 'custom':
indvdum@0:
indvdum@0: $return = '';
indvdum@0:
indvdum@0: if (isset($vars['method']))
indvdum@0: {
indvdum@0: $call = array($module->module, $vars['method']);
indvdum@0: }
indvdum@0: else if (isset($vars['function']))
indvdum@0: {
indvdum@0: $call = $vars['function'];
indvdum@0: }
indvdum@0: else
indvdum@0: {
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: if (isset($vars['params']))
indvdum@0: {
indvdum@0: $args = array();
indvdum@0: foreach ($vars['params'] as $value)
indvdum@0: {
indvdum@0: switch ($value)
indvdum@0: {
indvdum@0: case '{CONFIG_VALUE}':
indvdum@0: $value = $new[$config_key];
indvdum@0: break;
indvdum@0:
indvdum@0: case '{KEY}':
indvdum@0: $value = $key;
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: $args[] = $value;
indvdum@0: }
indvdum@0: }
indvdum@0: else
indvdum@0: {
indvdum@0: $args = array($new[$config_key], $key);
indvdum@0: }
indvdum@0:
indvdum@0: $return = call_user_func_array($call, $args);
indvdum@0:
indvdum@0: if ($tpl_type[0] == 'select')
indvdum@0: {
indvdum@0: $tpl = '';
indvdum@0: }
indvdum@0: else
indvdum@0: {
indvdum@0: $tpl = $return;
indvdum@0: }
indvdum@0:
indvdum@0: break;
indvdum@0:
indvdum@0: default:
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: if (isset($vars['append']))
indvdum@0: {
indvdum@0: $tpl .= $vars['append'];
indvdum@0: }
indvdum@0:
indvdum@0: return $tpl;
indvdum@0: }
indvdum@0:
indvdum@0: /**
indvdum@0: * Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int.
indvdum@0: * 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.
indvdum@0: */
indvdum@0: function validate_config_vars($config_vars, &$cfg_array, &$error)
indvdum@0: {
indvdum@0: global $phpbb_root_path, $user;
indvdum@0: $type = 0;
indvdum@0: $min = 1;
indvdum@0: $max = 2;
indvdum@0:
indvdum@0: foreach ($config_vars as $config_name => $config_definition)
indvdum@0: {
indvdum@0: if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
indvdum@0: {
indvdum@0: continue;
indvdum@0: }
indvdum@0:
indvdum@0: if (!isset($config_definition['validate']))
indvdum@0: {
indvdum@0: continue;
indvdum@0: }
indvdum@0:
indvdum@0: $validator = explode(':', $config_definition['validate']);
indvdum@0:
indvdum@0: // Validate a bit. ;) (0 = type, 1 = min, 2= max)
indvdum@0: switch ($validator[$type])
indvdum@0: {
indvdum@0: case 'string':
indvdum@0: $length = utf8_strlen($cfg_array[$config_name]);
indvdum@0:
indvdum@0: // the column is a VARCHAR
indvdum@0: $validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
indvdum@0:
indvdum@0: if (isset($validator[$min]) && $length < $validator[$min])
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]);
indvdum@0: }
indvdum@0: else if (isset($validator[$max]) && $length > $validator[2])
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]);
indvdum@0: }
indvdum@0: break;
indvdum@0:
indvdum@0: case 'bool':
indvdum@0: $cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
indvdum@0: break;
indvdum@0:
indvdum@0: case 'int':
indvdum@0: $cfg_array[$config_name] = (int) $cfg_array[$config_name];
indvdum@0:
indvdum@0: if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min])
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]);
indvdum@0: }
indvdum@0: else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max])
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]);
indvdum@0: }
indvdum@0:
indvdum@0: if (strpos($config_name, '_max') !== false)
indvdum@0: {
indvdum@0: // Min/max pairs of settings should ensure that min <= max
indvdum@0: // Replace _max with _min to find the name of the minimum
indvdum@0: // corresponding configuration variable
indvdum@0: $min_name = str_replace('_max', '_min', $config_name);
indvdum@0:
indvdum@0: if (isset($cfg_array[$min_name]) && is_numeric($cfg_array[$min_name]) && $cfg_array[$config_name] < $cfg_array[$min_name])
indvdum@0: {
indvdum@0: // A minimum value exists and the maximum value is less than it
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], (int) $cfg_array[$min_name]);
indvdum@0: }
indvdum@0: }
indvdum@0: break;
indvdum@0:
indvdum@0: // Absolute path
indvdum@0: case 'script_path':
indvdum@0: if (!$cfg_array[$config_name])
indvdum@0: {
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: $destination = str_replace('\\', '/', $cfg_array[$config_name]);
indvdum@0:
indvdum@0: if ($destination !== '/')
indvdum@0: {
indvdum@0: // Adjust destination path (no trailing slash)
indvdum@0: if (substr($destination, -1, 1) == '/')
indvdum@0: {
indvdum@0: $destination = substr($destination, 0, -1);
indvdum@0: }
indvdum@0:
indvdum@0: $destination = str_replace(array('../', './'), '', $destination);
indvdum@0:
indvdum@0: if ($destination[0] != '/')
indvdum@0: {
indvdum@0: $destination = '/' . $destination;
indvdum@0: }
indvdum@0: }
indvdum@0:
indvdum@0: $cfg_array[$config_name] = trim($destination);
indvdum@0:
indvdum@0: break;
indvdum@0:
indvdum@0: // Absolute path
indvdum@0: case 'lang':
indvdum@0: if (!$cfg_array[$config_name])
indvdum@0: {
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: $cfg_array[$config_name] = basename($cfg_array[$config_name]);
indvdum@0:
indvdum@0: if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/'))
indvdum@0: {
indvdum@0: $error[] = $user->lang['WRONG_DATA_LANG'];
indvdum@0: }
indvdum@0: break;
indvdum@0:
indvdum@0: // Relative path (appended $phpbb_root_path)
indvdum@0: case 'rpath':
indvdum@0: case 'rwpath':
indvdum@0: if (!$cfg_array[$config_name])
indvdum@0: {
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: $destination = $cfg_array[$config_name];
indvdum@0:
indvdum@0: // Adjust destination path (no trailing slash)
indvdum@0: if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
indvdum@0: {
indvdum@0: $destination = substr($destination, 0, -1);
indvdum@0: }
indvdum@0:
indvdum@0: $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
indvdum@0: if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
indvdum@0: {
indvdum@0: $destination = '';
indvdum@0: }
indvdum@0:
indvdum@0: $cfg_array[$config_name] = trim($destination);
indvdum@0:
indvdum@0: // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...
indvdum@0: case 'path':
indvdum@0: case 'wpath':
indvdum@0:
indvdum@0: if (!$cfg_array[$config_name])
indvdum@0: {
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: $cfg_array[$config_name] = trim($cfg_array[$config_name]);
indvdum@0:
indvdum@0: // Make sure no NUL byte is present...
indvdum@0: if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false)
indvdum@0: {
indvdum@0: $cfg_array[$config_name] = '';
indvdum@0: break;
indvdum@0: }
indvdum@0:
indvdum@0: if (!file_exists($phpbb_root_path . $cfg_array[$config_name]))
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);
indvdum@0: }
indvdum@0:
indvdum@0: if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name]))
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);
indvdum@0: }
indvdum@0:
indvdum@0: // Check if the path is writable
indvdum@0: if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath')
indvdum@0: {
indvdum@0: if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !phpbb_is_writable($phpbb_root_path . $cfg_array[$config_name]))
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);
indvdum@0: }
indvdum@0: }
indvdum@0:
indvdum@0: break;
indvdum@0: }
indvdum@0: }
indvdum@0:
indvdum@0: return;
indvdum@0: }
indvdum@0:
indvdum@0: /**
indvdum@0: * Checks whatever or not a variable is OK for use in the Database
indvdum@0: * param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))'
indvdum@0: * param mixed $error The error array
indvdum@0: */
indvdum@0: function validate_range($value_ary, &$error)
indvdum@0: {
indvdum@0: global $user;
indvdum@0:
indvdum@0: $column_types = array(
indvdum@0: 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1),
indvdum@0: 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535),
indvdum@0: 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff),
indvdum@0: // Do not use (int) 0x80000000 - it evaluates to different
indvdum@0: // values on 32-bit and 64-bit systems.
indvdum@0: // Apparently -2147483648 is a float on 32-bit systems,
indvdum@0: // despite fitting in an int, thus explicit cast is needed.
indvdum@0: 'INT' => array('php_type' => 'int', 'min' => (int) -2147483648, 'max' => (int) 0x7fffffff),
indvdum@0: 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127),
indvdum@0:
indvdum@0: 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255),
indvdum@0: );
indvdum@0: foreach ($value_ary as $value)
indvdum@0: {
indvdum@0: $column = explode(':', $value['column_type']);
indvdum@0: $max = $min = 0;
indvdum@0: $type = 0;
indvdum@0: if (!isset($column_types[$column[0]]))
indvdum@0: {
indvdum@0: continue;
indvdum@0: }
indvdum@0: else
indvdum@0: {
indvdum@0: $type = $column_types[$column[0]];
indvdum@0: }
indvdum@0:
indvdum@0: switch ($type['php_type'])
indvdum@0: {
indvdum@0: case 'string' :
indvdum@0: $max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max'];
indvdum@0: if (utf8_strlen($value['value']) > $max)
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max);
indvdum@0: }
indvdum@0: break;
indvdum@0:
indvdum@0: case 'int':
indvdum@0: $min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min'];
indvdum@0: $max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max'];
indvdum@0: if ($value['value'] < $min)
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min);
indvdum@0: }
indvdum@0: else if ($value['value'] > $max)
indvdum@0: {
indvdum@0: $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max);
indvdum@0: }
indvdum@0: break;
indvdum@0: }
indvdum@0: }
indvdum@0: }
indvdum@0:
indvdum@0: ?>