Blame Identity/Models/Html/phpBB/3.0.4/install/database_update.php

d6e8d8
d6e8d8
/**
d6e8d8
*
d6e8d8
* @package install
d6e8d8
* @version $Id: database_update.php 9187 2008-12-12 14:47:03Z acydburn $
d6e8d8
* @copyright (c) 2006 phpBB Group
d6e8d8
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
d6e8d8
*
d6e8d8
*/
d6e8d8
d6e8d8
$updates_to_version = '3.0.4';
d6e8d8
d6e8d8
// Return if we "just include it" to find out for which version the database update is responsible for
d6e8d8
if (defined('IN_PHPBB') && defined('IN_INSTALL'))
d6e8d8
{
d6e8d8
	return;
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
*/
d6e8d8
define('IN_PHPBB', true);
d6e8d8
define('IN_INSTALL', true);
d6e8d8
d6e8d8
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
d6e8d8
$phpEx = substr(strrchr(__FILE__, '.'), 1);
d6e8d8
d6e8d8
// Report all errors, except notices
d6e8d8
//error_reporting(E_ALL ^ E_NOTICE);
d6e8d8
error_reporting(E_ALL);
d6e8d8
d6e8d8
@set_time_limit(0);
d6e8d8
d6e8d8
// Include essential scripts
d6e8d8
include($phpbb_root_path . 'config.' . $phpEx);
d6e8d8
d6e8d8
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
d6e8d8
{
d6e8d8
	die("Please read: INSTALL.html before attempting to update.");
d6e8d8
}
d6e8d8
d6e8d8
// Load Extensions
d6e8d8
if (!empty($load_extensions))
d6e8d8
{
d6e8d8
	$load_extensions = explode(',', $load_extensions);
d6e8d8
d6e8d8
	foreach ($load_extensions as $extension)
d6e8d8
	{
d6e8d8
		@dl(trim($extension));
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
// Include files
d6e8d8
require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
d6e8d8
require($phpbb_root_path . 'includes/cache.' . $phpEx);
d6e8d8
require($phpbb_root_path . 'includes/template.' . $phpEx);
d6e8d8
require($phpbb_root_path . 'includes/session.' . $phpEx);
d6e8d8
require($phpbb_root_path . 'includes/auth.' . $phpEx);
d6e8d8
d6e8d8
require($phpbb_root_path . 'includes/functions.' . $phpEx);
d6e8d8
d6e8d8
if (file_exists($phpbb_root_path . 'includes/functions_content.' . $phpEx))
d6e8d8
{
d6e8d8
	require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
d6e8d8
}
d6e8d8
d6e8d8
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
d6e8d8
require($phpbb_root_path . 'includes/constants.' . $phpEx);
d6e8d8
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
d6e8d8
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
d6e8d8
d6e8d8
// If we are on PHP >= 6.0.0 we do not need some code
d6e8d8
if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
d6e8d8
{
d6e8d8
	/**
d6e8d8
	* @ignore
d6e8d8
	*/
d6e8d8
	define('STRIP', false);
d6e8d8
}
d6e8d8
else
d6e8d8
{
d6e8d8
	@set_magic_quotes_runtime(0);
d6e8d8
	define('STRIP', (get_magic_quotes_gpc()) ? true : false);
d6e8d8
}
d6e8d8
d6e8d8
$user = new user();
d6e8d8
$cache = new cache();
d6e8d8
$db = new $sql_db();
d6e8d8
d6e8d8
// Add own hook handler, if present. :o
d6e8d8
if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
d6e8d8
{
d6e8d8
	require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
d6e8d8
	$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
d6e8d8
d6e8d8
	foreach ($cache->obtain_hooks() as $hook)
d6e8d8
	{
d6e8d8
		@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
d6e8d8
	}
d6e8d8
}
d6e8d8
else
d6e8d8
{
d6e8d8
	$phpbb_hook = false;
d6e8d8
}
d6e8d8
d6e8d8
// Connect to DB
d6e8d8
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
d6e8d8
d6e8d8
// We do not need this any longer, unset for safety purposes
d6e8d8
unset($dbpasswd);
d6e8d8
d6e8d8
$user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
d6e8d8
d6e8d8
$sql = "SELECT config_value
d6e8d8
	FROM " . CONFIG_TABLE . "
d6e8d8
	WHERE config_name = 'default_lang'";
d6e8d8
$result = $db->sql_query($sql);
d6e8d8
$row = $db->sql_fetchrow($result);
d6e8d8
$db->sql_freeresult($result);
d6e8d8
d6e8d8
$language = basename(request_var('language', ''));
d6e8d8
d6e8d8
if (!$language)
d6e8d8
{
d6e8d8
	$language = $row['config_value'];
d6e8d8
}
d6e8d8
d6e8d8
if (!file_exists($phpbb_root_path . 'language/' . $language))
d6e8d8
{
d6e8d8
	die('No language found!');
d6e8d8
}
d6e8d8
d6e8d8
// And finally, load the relevant language files
d6e8d8
include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
d6e8d8
include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
d6e8d8
include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
d6e8d8
d6e8d8
// Set PHP error handler to ours
d6e8d8
//set_error_handler('msg_handler');
d6e8d8
d6e8d8
// Define some variables for the database update
d6e8d8
$inline_update = (request_var('type', 0)) ? true : false;
d6e8d8
d6e8d8
// Database column types mapping
d6e8d8
$dbms_type_map = array(
d6e8d8
	'mysql_41'	=> array(
d6e8d8
		'INT:'		=> 'int(%d)',
d6e8d8
		'BINT'		=> 'bigint(20)',
d6e8d8
		'UINT'		=> 'mediumint(8) UNSIGNED',
d6e8d8
		'UINT:'		=> 'int(%d) UNSIGNED',
d6e8d8
		'TINT:'		=> 'tinyint(%d)',
d6e8d8
		'USINT'		=> 'smallint(4) UNSIGNED',
d6e8d8
		'BOOL'		=> 'tinyint(1) UNSIGNED',
d6e8d8
		'VCHAR'		=> 'varchar(255)',
d6e8d8
		'VCHAR:'	=> 'varchar(%d)',
d6e8d8
		'CHAR:'		=> 'char(%d)',
d6e8d8
		'XSTEXT'	=> 'text',
d6e8d8
		'XSTEXT_UNI'=> 'varchar(100)',
d6e8d8
		'STEXT'		=> 'text',
d6e8d8
		'STEXT_UNI'	=> 'varchar(255)',
d6e8d8
		'TEXT'		=> 'text',
d6e8d8
		'TEXT_UNI'	=> 'text',
d6e8d8
		'MTEXT'		=> 'mediumtext',
d6e8d8
		'MTEXT_UNI'	=> 'mediumtext',
d6e8d8
		'TIMESTAMP'	=> 'int(11) UNSIGNED',
d6e8d8
		'DECIMAL'	=> 'decimal(5,2)',
d6e8d8
		'VCHAR_UNI'	=> 'varchar(255)',
d6e8d8
		'VCHAR_UNI:'=> 'varchar(%d)',
d6e8d8
		'VCHAR_CI'	=> 'varchar(255)',
d6e8d8
		'VARBINARY'	=> 'varbinary(255)',
d6e8d8
	),
d6e8d8
d6e8d8
	'mysql_40'	=> array(
d6e8d8
		'INT:'		=> 'int(%d)',
d6e8d8
		'BINT'		=> 'bigint(20)',
d6e8d8
		'UINT'		=> 'mediumint(8) UNSIGNED',
d6e8d8
		'UINT:'		=> 'int(%d) UNSIGNED',
d6e8d8
		'TINT:'		=> 'tinyint(%d)',
d6e8d8
		'USINT'		=> 'smallint(4) UNSIGNED',
d6e8d8
		'BOOL'		=> 'tinyint(1) UNSIGNED',
d6e8d8
		'VCHAR'		=> 'varbinary(255)',
d6e8d8
		'VCHAR:'	=> 'varbinary(%d)',
d6e8d8
		'CHAR:'		=> 'binary(%d)',
d6e8d8
		'XSTEXT'	=> 'blob',
d6e8d8
		'XSTEXT_UNI'=> 'blob',
d6e8d8
		'STEXT'		=> 'blob',
d6e8d8
		'STEXT_UNI'	=> 'blob',
d6e8d8
		'TEXT'		=> 'blob',
d6e8d8
		'TEXT_UNI'	=> 'blob',
d6e8d8
		'MTEXT'		=> 'mediumblob',
d6e8d8
		'MTEXT_UNI'	=> 'mediumblob',
d6e8d8
		'TIMESTAMP'	=> 'int(11) UNSIGNED',
d6e8d8
		'DECIMAL'	=> 'decimal(5,2)',
d6e8d8
		'VCHAR_UNI'	=> 'blob',
d6e8d8
		'VCHAR_UNI:'=> array('varbinary(%d)', 'limit' => array('mult', 3, 255, 'blob')),
d6e8d8
		'VCHAR_CI'	=> 'blob',
d6e8d8
		'VARBINARY'	=> 'varbinary(255)',
d6e8d8
	),
d6e8d8
d6e8d8
	'firebird'	=> array(
d6e8d8
		'INT:'		=> 'INTEGER',
d6e8d8
		'BINT'		=> 'DOUBLE PRECISION',
d6e8d8
		'UINT'		=> 'INTEGER',
d6e8d8
		'UINT:'		=> 'INTEGER',
d6e8d8
		'TINT:'		=> 'INTEGER',
d6e8d8
		'USINT'		=> 'INTEGER',
d6e8d8
		'BOOL'		=> 'INTEGER',
d6e8d8
		'VCHAR'		=> 'VARCHAR(255) CHARACTER SET NONE',
d6e8d8
		'VCHAR:'	=> 'VARCHAR(%d) CHARACTER SET NONE',
d6e8d8
		'CHAR:'		=> 'CHAR(%d) CHARACTER SET NONE',
d6e8d8
		'XSTEXT'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
d6e8d8
		'STEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
d6e8d8
		'TEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
d6e8d8
		'MTEXT'		=> 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
d6e8d8
		'XSTEXT_UNI'=> 'VARCHAR(100) CHARACTER SET UTF8',
d6e8d8
		'STEXT_UNI'	=> 'VARCHAR(255) CHARACTER SET UTF8',
d6e8d8
		'TEXT_UNI'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8',
d6e8d8
		'MTEXT_UNI'	=> 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8',
d6e8d8
		'TIMESTAMP'	=> 'INTEGER',
d6e8d8
		'DECIMAL'	=> 'DOUBLE PRECISION',
d6e8d8
		'VCHAR_UNI'	=> 'VARCHAR(255) CHARACTER SET UTF8',
d6e8d8
		'VCHAR_UNI:'=> 'VARCHAR(%d) CHARACTER SET UTF8',
d6e8d8
		'VCHAR_CI'	=> 'VARCHAR(255) CHARACTER SET UTF8',
d6e8d8
		'VARBINARY'	=> 'CHAR(255) CHARACTER SET NONE',
d6e8d8
	),
d6e8d8
d6e8d8
	'mssql'		=> array(
d6e8d8
		'INT:'		=> '[int]',
d6e8d8
		'BINT'		=> '[float]',
d6e8d8
		'UINT'		=> '[int]',
d6e8d8
		'UINT:'		=> '[int]',
d6e8d8
		'TINT:'		=> '[int]',
d6e8d8
		'USINT'		=> '[int]',
d6e8d8
		'BOOL'		=> '[int]',
d6e8d8
		'VCHAR'		=> '[varchar] (255)',
d6e8d8
		'VCHAR:'	=> '[varchar] (%d)',
d6e8d8
		'CHAR:'		=> '[char] (%d)',
d6e8d8
		'XSTEXT'	=> '[varchar] (1000)',
d6e8d8
		'STEXT'		=> '[varchar] (3000)',
d6e8d8
		'TEXT'		=> '[varchar] (8000)',
d6e8d8
		'MTEXT'		=> '[text]',
d6e8d8
		'XSTEXT_UNI'=> '[varchar] (100)',
d6e8d8
		'STEXT_UNI'	=> '[varchar] (255)',
d6e8d8
		'TEXT_UNI'	=> '[varchar] (4000)',
d6e8d8
		'MTEXT_UNI'	=> '[text]',
d6e8d8
		'TIMESTAMP'	=> '[int]',
d6e8d8
		'DECIMAL'	=> '[float]',
d6e8d8
		'VCHAR_UNI'	=> '[varchar] (255)',
d6e8d8
		'VCHAR_UNI:'=> '[varchar] (%d)',
d6e8d8
		'VCHAR_CI'	=> '[varchar] (255)',
d6e8d8
		'VARBINARY'	=> '[varchar] (255)',
d6e8d8
	),
d6e8d8
d6e8d8
	'oracle'	=> array(
d6e8d8
		'INT:'		=> 'number(%d)',
d6e8d8
		'BINT'		=> 'number(20)',
d6e8d8
		'UINT'		=> 'number(8)',
d6e8d8
		'UINT:'		=> 'number(%d)',
d6e8d8
		'TINT:'		=> 'number(%d)',
d6e8d8
		'USINT'		=> 'number(4)',
d6e8d8
		'BOOL'		=> 'number(1)',
d6e8d8
		'VCHAR'		=> 'varchar2(255)',
d6e8d8
		'VCHAR:'	=> 'varchar2(%d)',
d6e8d8
		'CHAR:'		=> 'char(%d)',
d6e8d8
		'XSTEXT'	=> 'varchar2(1000)',
d6e8d8
		'STEXT'		=> 'varchar2(3000)',
d6e8d8
		'TEXT'		=> 'clob',
d6e8d8
		'MTEXT'		=> 'clob',
d6e8d8
		'XSTEXT_UNI'=> 'varchar2(300)',
d6e8d8
		'STEXT_UNI'	=> 'varchar2(765)',
d6e8d8
		'TEXT_UNI'	=> 'clob',
d6e8d8
		'MTEXT_UNI'	=> 'clob',
d6e8d8
		'TIMESTAMP'	=> 'number(11)',
d6e8d8
		'DECIMAL'	=> 'number(5, 2)',
d6e8d8
		'VCHAR_UNI'	=> 'varchar2(765)',
d6e8d8
		'VCHAR_UNI:'=> array('varchar2(%d)', 'limit' => array('mult', 3, 765, 'clob')),
d6e8d8
		'VCHAR_CI'	=> 'varchar2(255)',
d6e8d8
		'VARBINARY'	=> 'raw(255)',
d6e8d8
	),
d6e8d8
d6e8d8
	'sqlite'	=> array(
d6e8d8
		'INT:'		=> 'int(%d)',
d6e8d8
		'BINT'		=> 'bigint(20)',
d6e8d8
		'UINT'		=> 'INTEGER UNSIGNED', //'mediumint(8) UNSIGNED',
d6e8d8
		'UINT:'		=> 'INTEGER UNSIGNED', // 'int(%d) UNSIGNED',
d6e8d8
		'TINT:'		=> 'tinyint(%d)',
d6e8d8
		'USINT'		=> 'INTEGER UNSIGNED', //'mediumint(4) UNSIGNED',
d6e8d8
		'BOOL'		=> 'INTEGER UNSIGNED', //'tinyint(1) UNSIGNED',
d6e8d8
		'VCHAR'		=> 'varchar(255)',
d6e8d8
		'VCHAR:'	=> 'varchar(%d)',
d6e8d8
		'CHAR:'		=> 'char(%d)',
d6e8d8
		'XSTEXT'	=> 'text(65535)',
d6e8d8
		'STEXT'		=> 'text(65535)',
d6e8d8
		'TEXT'		=> 'text(65535)',
d6e8d8
		'MTEXT'		=> 'mediumtext(16777215)',
d6e8d8
		'XSTEXT_UNI'=> 'text(65535)',
d6e8d8
		'STEXT_UNI'	=> 'text(65535)',
d6e8d8
		'TEXT_UNI'	=> 'text(65535)',
d6e8d8
		'MTEXT_UNI'	=> 'mediumtext(16777215)',
d6e8d8
		'TIMESTAMP'	=> 'INTEGER UNSIGNED', //'int(11) UNSIGNED',
d6e8d8
		'DECIMAL'	=> 'decimal(5,2)',
d6e8d8
		'VCHAR_UNI'	=> 'varchar(255)',
d6e8d8
		'VCHAR_UNI:'=> 'varchar(%d)',
d6e8d8
		'VCHAR_CI'	=> 'varchar(255)',
d6e8d8
		'VARBINARY'	=> 'blob',
d6e8d8
	),
d6e8d8
d6e8d8
	'postgres'	=> array(
d6e8d8
		'INT:'		=> 'INT4',
d6e8d8
		'BINT'		=> 'INT8',
d6e8d8
		'UINT'		=> 'INT4', // unsigned
d6e8d8
		'UINT:'		=> 'INT4', // unsigned
d6e8d8
		'USINT'		=> 'INT2', // unsigned
d6e8d8
		'BOOL'		=> 'INT2', // unsigned
d6e8d8
		'TINT:'		=> 'INT2',
d6e8d8
		'VCHAR'		=> 'varchar(255)',
d6e8d8
		'VCHAR:'	=> 'varchar(%d)',
d6e8d8
		'CHAR:'		=> 'char(%d)',
d6e8d8
		'XSTEXT'	=> 'varchar(1000)',
d6e8d8
		'STEXT'		=> 'varchar(3000)',
d6e8d8
		'TEXT'		=> 'varchar(8000)',
d6e8d8
		'MTEXT'		=> 'TEXT',
d6e8d8
		'XSTEXT_UNI'=> 'varchar(100)',
d6e8d8
		'STEXT_UNI'	=> 'varchar(255)',
d6e8d8
		'TEXT_UNI'	=> 'varchar(4000)',
d6e8d8
		'MTEXT_UNI'	=> 'TEXT',
d6e8d8
		'TIMESTAMP'	=> 'INT4', // unsigned
d6e8d8
		'DECIMAL'	=> 'decimal(5,2)',
d6e8d8
		'VCHAR_UNI'	=> 'varchar(255)',
d6e8d8
		'VCHAR_UNI:'=> 'varchar(%d)',
d6e8d8
		'VCHAR_CI'	=> 'varchar_ci',
d6e8d8
		'VARBINARY'	=> 'bytea',
d6e8d8
	),
d6e8d8
);
d6e8d8
d6e8d8
// A list of types being unsigned for better reference in some db's
d6e8d8
$unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP');
d6e8d8
d6e8d8
// Only an example, but also commented out
d6e8d8
$database_update_info = array(
d6e8d8
	// Changes from 3.0.RC2 to the next version
d6e8d8
	'3.0.RC2'			=> array(
d6e8d8
		// Change the following columns
d6e8d8
		'change_columns'		=> array(
d6e8d8
			BANLIST_TABLE	=> array(
d6e8d8
				'ban_reason'		=> array('VCHAR_UNI', ''),
d6e8d8
				'ban_give_reason'	=> array('VCHAR_UNI', ''),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// Changes from 3.0.RC3 to the next version
d6e8d8
	'3.0.RC3'			=> array(
d6e8d8
		// Change the following columns
d6e8d8
		'change_columns'		=> array(
d6e8d8
			BANLIST_TABLE				=> array(
d6e8d8
				'ban_reason'		=> array('VCHAR_UNI', ''),
d6e8d8
				'ban_give_reason'	=> array('VCHAR_UNI', ''),
d6e8d8
			),
d6e8d8
			STYLES_TABLE				=> array(
d6e8d8
				'style_id'			=> array('USINT', 0),
d6e8d8
				'template_id'		=> array('USINT', 0),
d6e8d8
				'theme_id'			=> array('USINT', 0),
d6e8d8
				'imageset_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_TEMPLATE_TABLE		=> array(
d6e8d8
				'template_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_TEMPLATE_DATA_TABLE	=> array(
d6e8d8
				'template_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_THEME_TABLE			=> array(
d6e8d8
				'theme_id'			=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_IMAGESET_TABLE		=> array(
d6e8d8
				'imageset_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_IMAGESET_DATA_TABLE	=> array(
d6e8d8
				'imageset_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			USERS_TABLE	=> array(
d6e8d8
				'user_style'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			FORUMS_TABLE				=> array(
d6e8d8
				'forum_style'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			GROUPS_TABLE			=> array(
d6e8d8
				'group_avatar_type'		=> array('TINT:2', 0),
d6e8d8
				'group_avatar_width'	=> array('USINT', 0),
d6e8d8
				'group_avatar_height'	=> array('USINT', 0),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// Changes from 3.0.RC4 to the next version
d6e8d8
	'3.0.RC4'			=> array(
d6e8d8
		// Change the following columns
d6e8d8
		'change_columns'		=> array(
d6e8d8
			STYLES_TABLE				=> array(
d6e8d8
				'style_id'			=> array('USINT', NULL, 'auto_increment'),
d6e8d8
				'template_id'		=> array('USINT', 0),
d6e8d8
				'theme_id'			=> array('USINT', 0),
d6e8d8
				'imageset_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_TEMPLATE_TABLE		=> array(
d6e8d8
				'template_id'		=> array('USINT', NULL, 'auto_increment'),
d6e8d8
			),
d6e8d8
			STYLES_TEMPLATE_DATA_TABLE	=> array(
d6e8d8
				'template_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_THEME_TABLE			=> array(
d6e8d8
				'theme_id'			=> array('USINT', NULL, 'auto_increment'),
d6e8d8
			),
d6e8d8
			STYLES_IMAGESET_TABLE		=> array(
d6e8d8
				'imageset_id'		=> array('USINT', NULL, 'auto_increment'),
d6e8d8
			),
d6e8d8
			STYLES_IMAGESET_DATA_TABLE	=> array(
d6e8d8
				'imageset_id'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			USERS_TABLE	=> array(
d6e8d8
				'user_style'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			FORUMS_TABLE				=> array(
d6e8d8
				'forum_style'		=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			GROUPS_TABLE			=> array(
d6e8d8
				'group_avatar_width'	=> array('USINT', 0),
d6e8d8
				'group_avatar_height'	=> array('USINT', 0),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// Changes from 3.0.RC5 to the next version
d6e8d8
	'3.0.RC5'			=> array(
d6e8d8
		// Add the following columns
d6e8d8
		'add_columns'		=> array(
d6e8d8
			USERS_TABLE	=> array(
d6e8d8
				'user_form_salt'	=> array('VCHAR_UNI:32', ''),
d6e8d8
			),
d6e8d8
		),
d6e8d8
		// Change the following columns
d6e8d8
		'change_columns'		=> array(
d6e8d8
			POSTS_TABLE				=> array(
d6e8d8
				'bbcode_uid'			=> array('VCHAR:8', ''),
d6e8d8
			),
d6e8d8
			PRIVMSGS_TABLE		=> array(
d6e8d8
				'bbcode_uid'			=> array('VCHAR:8', ''),
d6e8d8
			),
d6e8d8
			USERS_TABLE			=> array(
d6e8d8
				'user_sig_bbcode_uid'	=> array('VCHAR:8', ''),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// Changes from 3.0.RC6 to the next version
d6e8d8
	'3.0.RC6'			=> array(
d6e8d8
		// Change the following columns
d6e8d8
		'change_columns'		=> array(
d6e8d8
			FORUMS_TABLE				=> array(
d6e8d8
				'forum_desc_uid'		=> array('VCHAR:8', ''),
d6e8d8
				'forum_rules_uid'		=> array('VCHAR:8', ''),
d6e8d8
			),
d6e8d8
			GROUPS_TABLE		=> array(
d6e8d8
				'group_desc_uid'		=> array('VCHAR:8', ''),
d6e8d8
			),
d6e8d8
			USERS_TABLE			=> array(
d6e8d8
				'user_newpasswd'			=> array('VCHAR_UNI:40', ''),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// Changes from 3.0.RC8 to the next version
d6e8d8
	'3.0.RC8'			=> array(
d6e8d8
		// Change the following columns
d6e8d8
		'change_columns'		=> array(
d6e8d8
			USERS_TABLE			=> array(
d6e8d8
				'user_new_privmsg'			=> array('INT:4', 0),
d6e8d8
				'user_unread_privmsg'		=> array('INT:4', 0),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// Changes from 3.0.0 to the next version
d6e8d8
	'3.0.0'			=> array(
d6e8d8
		// Add the following columns
d6e8d8
		'add_columns'		=> array(
d6e8d8
			FORUMS_TABLE			=> array(
d6e8d8
				'display_subforum_list'		=> array('BOOL', 1),
d6e8d8
			),
d6e8d8
			SESSIONS_TABLE			=> array(
d6e8d8
				'session_forum_id'		=> array('UINT', 0),
d6e8d8
			),
d6e8d8
		),
d6e8d8
		'add_index'		=> array(
d6e8d8
			SESSIONS_TABLE			=> array(
d6e8d8
				'session_forum_id'		=> array('session_forum_id'),
d6e8d8
			),
d6e8d8
			GROUPS_TABLE			=> array(
d6e8d8
				'group_legend_name'		=> array('group_legend', 'group_name'),
d6e8d8
			),
d6e8d8
		),
d6e8d8
		'drop_keys'		=> array(
d6e8d8
			GROUPS_TABLE			=> array('group_legend'),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// No changes from 3.0.1-RC1 to 3.0.1
d6e8d8
	'3.0.1-RC1'		=> array(),
d6e8d8
	// No changes from 3.0.1 to 3.0.2-RC1
d6e8d8
	'3.0.1'			=> array(),
d6e8d8
	// Changes from 3.0.2-RC1 to 3.0.2-RC2
d6e8d8
	'3.0.2-RC1'		=> array(
d6e8d8
		'change_columns'	=> array(
d6e8d8
			DRAFTS_TABLE			=> array(
d6e8d8
				'draft_subject'		=> array('STEXT_UNI', ''),
d6e8d8
			),
d6e8d8
			FORUMS_TABLE	=> array(
d6e8d8
				'forum_last_post_subject' => array('STEXT_UNI', ''),
d6e8d8
			),
d6e8d8
			POSTS_TABLE		=> array(
d6e8d8
				'post_subject'			=> array('STEXT_UNI', '', 'true_sort'),
d6e8d8
			),
d6e8d8
			PRIVMSGS_TABLE	=> array(
d6e8d8
				'message_subject'		=> array('STEXT_UNI', ''),
d6e8d8
			),
d6e8d8
			TOPICS_TABLE	=> array(
d6e8d8
				'topic_title'				=> array('STEXT_UNI', '', 'true_sort'),
d6e8d8
				'topic_last_post_subject'	=> array('STEXT_UNI', ''),
d6e8d8
			),
d6e8d8
		),
d6e8d8
		'drop_keys'		=> array(
d6e8d8
			SESSIONS_TABLE			=> array('session_forum_id'),
d6e8d8
		),
d6e8d8
		'add_index'		=> array(
d6e8d8
			SESSIONS_TABLE			=> array(
d6e8d8
				'session_fid'		=> array('session_forum_id'),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
	// No changes from 3.0.2-RC2 to 3.0.2
d6e8d8
	'3.0.2-RC2'		=> array(),
d6e8d8
d6e8d8
	// Changes from 3.0.2 to 3.0.3-RC1
d6e8d8
	'3.0.2'			=> array(
d6e8d8
		// Add the following columns
d6e8d8
		'add_columns'		=> array(
d6e8d8
			STYLES_TEMPLATE_TABLE			=> array(
d6e8d8
				'template_inherits_id'		=> array('UINT:4', 0),
d6e8d8
				'template_inherit_path'		=> array('VCHAR', ''),
d6e8d8
			),
d6e8d8
			GROUPS_TABLE					=> array(
d6e8d8
				'group_max_recipients'		=> array('UINT', 0),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
d6e8d8
	// No changes from 3.0.3-RC1 to 3.0.3
d6e8d8
	'3.0.3-RC1'		=> array(),
d6e8d8
d6e8d8
	// Changes from 3.0.3 to 3.0.4-RC1
d6e8d8
	'3.0.3'			=> array(
d6e8d8
		'add_columns'		=> array(
d6e8d8
			PROFILE_FIELDS_TABLE			=> array(
d6e8d8
				'field_show_profile'		=> array('BOOL', 0),
d6e8d8
			),
d6e8d8
		),
d6e8d8
		'change_columns'	=> array(
d6e8d8
			STYLES_TABLE				=> array(
d6e8d8
				'style_id'				=> array('UINT', NULL, 'auto_increment'),
d6e8d8
				'template_id'			=> array('UINT', 0),
d6e8d8
				'theme_id'				=> array('UINT', 0),
d6e8d8
				'imageset_id'			=> array('UINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_IMAGESET_TABLE		=> array(
d6e8d8
				'imageset_id'				=> array('UINT', NULL, 'auto_increment'),
d6e8d8
			),
d6e8d8
			STYLES_IMAGESET_DATA_TABLE	=> array(
d6e8d8
				'image_id'				=> array('UINT', NULL, 'auto_increment'),
d6e8d8
				'imageset_id'			=> array('UINT', 0),
d6e8d8
			),
d6e8d8
			STYLES_THEME_TABLE			=> array(
d6e8d8
				'theme_id'				=> array('UINT', NULL, 'auto_increment'),
d6e8d8
			),
d6e8d8
			STYLES_TEMPLATE_TABLE		=> array(
d6e8d8
				'template_id'			=> array('UINT', NULL, 'auto_increment'),
d6e8d8
			),
d6e8d8
			STYLES_TEMPLATE_DATA_TABLE	=> array(
d6e8d8
				'template_id'			=> array('UINT', 0),
d6e8d8
			),
d6e8d8
			FORUMS_TABLE				=> array(
d6e8d8
				'forum_style'			=> array('USINT', 0),
d6e8d8
			),
d6e8d8
			USERS_TABLE					=> array(
d6e8d8
				'user_style'			=> array('UINT', 0),
d6e8d8
			),
d6e8d8
		),
d6e8d8
	),
d6e8d8
d6e8d8
	// Changes from 3.0.4-RC1 to 3.0.4
d6e8d8
	'3.0.4-RC1'		=> array(),
d6e8d8
);
d6e8d8
d6e8d8
// Determine mapping database type
d6e8d8
switch ($db->sql_layer)
d6e8d8
{
d6e8d8
	case 'mysql':
d6e8d8
		$map_dbms = 'mysql_40';
d6e8d8
	break;
d6e8d8
d6e8d8
	case 'mysql4':
d6e8d8
		if (version_compare($db->sql_server_info(true), '4.1.3', '>='))
d6e8d8
		{
d6e8d8
			$map_dbms = 'mysql_41';
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			$map_dbms = 'mysql_40';
d6e8d8
		}
d6e8d8
	break;
d6e8d8
d6e8d8
	case 'mysqli':
d6e8d8
		$map_dbms = 'mysql_41';
d6e8d8
	break;
d6e8d8
d6e8d8
	case 'mssql':
d6e8d8
	case 'mssql_odbc':
d6e8d8
		$map_dbms = 'mssql';
d6e8d8
	break;
d6e8d8
d6e8d8
	default:
d6e8d8
		$map_dbms = $db->sql_layer;
d6e8d8
	break;
d6e8d8
}
d6e8d8
d6e8d8
$error_ary = array();
d6e8d8
$errored = false;
d6e8d8
d6e8d8
header('Content-type: text/html; charset=UTF-8');
d6e8d8
d6e8d8
?>
d6e8d8
d6e8d8
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>" xml:lang="<?php echo $lang['USER_LANG']; ?>">
d6e8d8
<head>
d6e8d8
d6e8d8
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
d6e8d8
<meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" />
d6e8d8
<meta http-equiv="content-style-type" content="text/css" />
d6e8d8
<meta http-equiv="imagetoolbar" content="no" />
d6e8d8
d6e8d8
<title></title>
d6e8d8
d6e8d8
<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
d6e8d8
d6e8d8
</head>
d6e8d8
d6e8d8
<body>
d6e8d8
d6e8d8
	
d6e8d8
d6e8d8
	
d6e8d8
		
d6e8d8
		
d6e8d8
			
d6e8d8
				
d6e8d8
					
d6e8d8
d6e8d8
	

d6e8d8
d6e8d8
	
d6e8d8
d6e8d8
	

:: sql_layer; ?>

d6e8d8
d6e8d8
d6e8d8
// To let set_config() calls succeed, we need to make the config array available globally
d6e8d8
$config = array();
d6e8d8
$sql = 'SELECT *
d6e8d8
	FROM ' . CONFIG_TABLE;
d6e8d8
$result = $db->sql_query($sql);
d6e8d8
d6e8d8
while ($row = $db->sql_fetchrow($result))
d6e8d8
{
d6e8d8
	$config[$row['config_name']] = $row['config_value'];
d6e8d8
}
d6e8d8
$db->sql_freeresult($result);
d6e8d8
d6e8d8
/*if ($debug_from_version !== false)
d6e8d8
{
d6e8d8
	$config['version'] = $debug_from_version;
d6e8d8
}*/
d6e8d8
d6e8d8
echo $lang['PREVIOUS_VERSION'] . ' :: ' . $config['version'] . '
';
d6e8d8
echo $lang['UPDATED_VERSION'] . ' :: ' . $updates_to_version . '

';
d6e8d8
d6e8d8
$current_version = str_replace('rc', 'RC', strtolower($config['version']));
d6e8d8
$latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
d6e8d8
$orig_version = $config['version'];
d6e8d8
d6e8d8
// If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
d6e8d8
if ($inline_update)
d6e8d8
{
d6e8d8
	if ($current_version !== $latest_version)
d6e8d8
	{
d6e8d8
		set_config('version_update_from', $orig_version);
d6e8d8
	}
d6e8d8
}
d6e8d8
else
d6e8d8
{
d6e8d8
	// If not called from the update script, we will actually remove the traces
d6e8d8
	$db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
d6e8d8
}
d6e8d8
d6e8d8
// Checks/Operations that have to be completed prior to starting the update itself
d6e8d8
$exit = false;
d6e8d8
if (version_compare($current_version, '3.0.RC8', '<=')) /* && $debug_from_version === false) */
d6e8d8
{
d6e8d8
	// Define missing language entries...
d6e8d8
	if (!isset($lang['CLEANING_USERNAMES']))
d6e8d8
	{
d6e8d8
		$lang = array_merge($lang, array(
d6e8d8
			'CLEANING_USERNAMES'		=> 'Cleaning usernames',
d6e8d8
			'LONG_SCRIPT_EXECUTION'		=> 'Please note that this can take a while... Please do not stop the script.',
d6e8d8
			'CHANGE_CLEAN_NAMES'		=> 'The method used to make sure a username is not used by multiple users has been changed. There are some users which have the same name when compared with the new method. You have to delete or rename these users to make sure that each name is only used by one user before you can proceed.',
d6e8d8
			'USER_ACTIVE'				=> 'Active user',
d6e8d8
			'USER_INACTIVE'				=> 'Inactive user',
d6e8d8
			'BOT'						=> 'Spider/Robot',
d6e8d8
			'UPDATE_REQUIRES_FILE'		=> 'The updater requires that the following file is present: %s',
d6e8d8
d6e8d8
			'DELETE_USER_REMOVE'		=> 'Delete user and remove posts',
d6e8d8
			'DELETE_USER_RETAIN'		=> 'Delete user but keep posts',
d6e8d8
			'EDIT_USERNAME'				=> 'Edit username',
d6e8d8
			'KEEP_OLD_NAME'				=> 'Keep username',
d6e8d8
			'NEW_USERNAME'				=> 'New username',
d6e8d8
		));
d6e8d8
	}
d6e8d8
?>
d6e8d8
	

d6e8d8
d6e8d8
	

d6e8d8
d6e8d8
	
d6e8d8
d6e8d8
d6e8d8
	flush();
d6e8d8
d6e8d8
	$submit			= (isset($_POST['resolve_conflicts'])) ? true : false;
d6e8d8
	$modify_users	= request_var('modify_users', array(0 => ''));
d6e8d8
	$new_usernames	= request_var('new_usernames', array(0 => ''), true);
d6e8d8
d6e8d8
	// We need this file if someone wants to edit usernames.
d6e8d8
	include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
d6e8d8
d6e8d8
	if (!class_exists('utf_new_normalizer'))
d6e8d8
	{
d6e8d8
		if (!file_exists($phpbb_root_path . 'install/data/new_normalizer.' . $phpEx))
d6e8d8
		{
d6e8d8
			global $lang;
d6e8d8
			trigger_error(sprintf($lang['UPDATE_REQUIRES_FILE'], $phpbb_root_path . 'install/data/new_normalizer.' . $phpEx), E_USER_ERROR);
d6e8d8
		}
d6e8d8
		include($phpbb_root_path . 'install/data/new_normalizer.' . $phpEx);
d6e8d8
	}
d6e8d8
d6e8d8
	// the admin decided to change some usernames
d6e8d8
	if (sizeof($modify_users) && $submit)
d6e8d8
	{
d6e8d8
		$sql = 'SELECT user_id, username, user_type
d6e8d8
			FROM ' . USERS_TABLE . '
d6e8d8
			WHERE ' . $db->sql_in_set('user_id', array_keys($modify_users));
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
d6e8d8
		$users = 0;
d6e8d8
		while ($row = $db->sql_fetchrow($result))
d6e8d8
		{
d6e8d8
			$users++;
d6e8d8
			$user_id = (int) $row['user_id'];
d6e8d8
d6e8d8
			if (isset($modify_users[$user_id]))
d6e8d8
			{
d6e8d8
				$row['action'] = $modify_users[$user_id];
d6e8d8
				$modify_users[$user_id] = $row;
d6e8d8
			}
d6e8d8
		}
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		// only if all ids really existed
d6e8d8
		if (sizeof($modify_users) == $users)
d6e8d8
		{
d6e8d8
			$user->data['user_id'] = ANONYMOUS;
d6e8d8
			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
d6e8d8
			foreach ($modify_users as $user_id => $row)
d6e8d8
			{
d6e8d8
				switch ($row['action'])
d6e8d8
				{
d6e8d8
					case 'edit':
d6e8d8
						if (isset($new_usernames[$user_id]))
d6e8d8
						{
d6e8d8
							$data = array('username' => utf8_new_normalize_nfc($new_usernames[$user_id]));
d6e8d8
							// Need to update config, forum, topic, posting, messages, etc.
d6e8d8
							if ($data['username'] != $row['username'])
d6e8d8
							{
d6e8d8
								$check_ary = array('username' => array(
d6e8d8
									array('string', false, $config['min_name_chars'], $config['max_name_chars']),
d6e8d8
									array('username'),
d6e8d8
								));
d6e8d8
								// need a little trick for this to work properly
d6e8d8
								$user->data['username_clean'] = utf8_clean_string($data['username']) . 'a';
d6e8d8
								$errors = validate_data($data, $check_ary);
d6e8d8
d6e8d8
								if ($errors)
d6e8d8
								{
d6e8d8
									include($phpbb_root_path . 'language/' . $language . '/ucp.' . $phpEx);
d6e8d8
									echo '
';
d6e8d8
									foreach ($errors as $error)
d6e8d8
									{
d6e8d8
										echo '

' . $lang[$error] . '

';
d6e8d8
									}
d6e8d8
									echo '';
d6e8d8
								}
d6e8d8
d6e8d8
								if (!$errors)
d6e8d8
								{
d6e8d8
									$sql = 'UPDATE ' . USERS_TABLE . '
d6e8d8
										SET ' . $db->sql_build_array('UPDATE', array(
d6e8d8
												'username' => $data['username'],
d6e8d8
												'username_clean' => utf8_clean_string($data['username'])
d6e8d8
											)) . '
d6e8d8
										WHERE user_id = ' . $user_id;
d6e8d8
									$db->sql_query($sql);
d6e8d8
d6e8d8
									add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $row['username'], $data['username']);
d6e8d8
									user_update_name($row['username'], $data['username']);
d6e8d8
								}
d6e8d8
							}
d6e8d8
						}
d6e8d8
					break;
d6e8d8
d6e8d8
					case 'delete_retain':
d6e8d8
					case 'delete_remove':
d6e8d8
						if ($user_id != ANONYMOUS && $row['user_type'] != USER_FOUNDER)
d6e8d8
						{
d6e8d8
							user_delete(substr($row['action'], 7), $user_id, $row['username']);
d6e8d8
							add_log('admin', 'LOG_USER_DELETED', $row['username']);
d6e8d8
						}
d6e8d8
					break;
d6e8d8
				}
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
?>
d6e8d8
d6e8d8
	

d6e8d8
	

::

d6e8d8
d6e8d8
d6e8d8
	flush();
d6e8d8
d6e8d8
	// after RC3 a different utf8_clean_string function is used, this requires that
d6e8d8
	// the unique column username_clean is recalculated, during this recalculation
d6e8d8
	// duplicates might be created. Since the column has to be unique such usernames
d6e8d8
	// must not exist. We need identify them and let the admin decide what to do
d6e8d8
	// about them.
d6e8d8
	// After RC8 this was changed again, but this time only usernames containing spaces
d6e8d8
	// are affected.
d6e8d8
	$sql_where = (version_compare($current_version, '3.0.RC4', '<=')) ? '' : "WHERE username_clean LIKE '% %'";
d6e8d8
	$sql = 'SELECT user_id, username, username_clean
d6e8d8
		FROM ' . USERS_TABLE . "
d6e8d8
		$sql_where
d6e8d8
		ORDER BY user_id ASC";
d6e8d8
	$result = $db->sql_query($sql);
d6e8d8
d6e8d8
	$colliding_users = $found_names = array();
d6e8d8
	$echos = 0;
d6e8d8
d6e8d8
	while ($row = $db->sql_fetchrow($result))
d6e8d8
	{
d6e8d8
		// Calculate the new clean name. If it differs from the old one we need
d6e8d8
		// to make sure there is no collision
d6e8d8
		$clean_name = utf8_new_clean_string($row['username']);
d6e8d8
d6e8d8
		if ($clean_name != $row['username_clean'])
d6e8d8
		{
d6e8d8
			// Check if there would be a collission, if not put it up for changing
d6e8d8
			$user_id = (int) $row['user_id'];
d6e8d8
d6e8d8
			// If this clean name was not the result of another user already ...
d6e8d8
			if (!isset($found_names[$clean_name]))
d6e8d8
			{
d6e8d8
				// then we need to figure out whether there are any other users
d6e8d8
				// who already had this clean name with the old version
d6e8d8
				$sql = 'SELECT user_id, username
d6e8d8
					FROM ' . USERS_TABLE . '
d6e8d8
					WHERE username_clean = \'' . $db->sql_escape($clean_name) . '\'';
d6e8d8
				$result2 = $db->sql_query($sql);
d6e8d8
d6e8d8
				$user_ids = array($user_id);
d6e8d8
				while ($row = $db->sql_fetchrow($result2))
d6e8d8
				{
d6e8d8
					// For not trimmed entries this could happen, yes. ;)
d6e8d8
					if ($row['user_id'] == $user_id)
d6e8d8
					{
d6e8d8
						continue;
d6e8d8
					}
d6e8d8
d6e8d8
					// Make sure this clean name will still be the same with the
d6e8d8
					// new function. If it is, then we have to add it to the list
d6e8d8
					// of user ids for this clean name
d6e8d8
					if (utf8_new_clean_string($row['username']) == $clean_name)
d6e8d8
					{
d6e8d8
						$user_ids[] = (int) $row['user_id'];
d6e8d8
					}
d6e8d8
				}
d6e8d8
				$db->sql_freeresult($result2);
d6e8d8
d6e8d8
				// if we already found a collision save it
d6e8d8
				if (sizeof($user_ids) > 1)
d6e8d8
				{
d6e8d8
					$colliding_users[$clean_name] = $user_ids;
d6e8d8
					$found_names[$clean_name] = true;
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					// otherwise just mark this name as found
d6e8d8
					$found_names[$clean_name] = $user_id;
d6e8d8
				}
d6e8d8
			}
d6e8d8
			// Else, if we already found the username
d6e8d8
			else
d6e8d8
			{
d6e8d8
				// If the value in the found_names lookup table is only true ...
d6e8d8
				if ($found_names[$clean_name] === true)
d6e8d8
				{
d6e8d8
					// then the actual data was already added to $colliding_users
d6e8d8
					// and we only need to append the user_id
d6e8d8
					$colliding_users[$clean_name][] = $user_id;
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					// otherwise it still keeps the first user_id for this name
d6e8d8
					// and we need to move the data to $colliding_users, and set
d6e8d8
					// the value in the found_names lookup table to true, so
d6e8d8
					// following users will directly be appended to $colliding_users
d6e8d8
					$colliding_users[$clean_name] = array($found_names[$clean_name], $user_id);
d6e8d8
					$found_names[$clean_name] = true;
d6e8d8
				}
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		if (($echos % 1000) == 0)
d6e8d8
		{
d6e8d8
			echo '.';
d6e8d8
			flush();
d6e8d8
		}
d6e8d8
		$echos++;
d6e8d8
	}
d6e8d8
	$db->sql_freeresult($result);
d6e8d8
d6e8d8
	_write_result(false, $errored, $error_ary);
d6e8d8
d6e8d8
	// now retrieve all information about the users and let the admin decide what to do
d6e8d8
	if (sizeof($colliding_users))
d6e8d8
	{
d6e8d8
		$exit = true;
d6e8d8
		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
d6e8d8
		include($phpbb_root_path . 'language/' . $language . '/memberlist.' . $phpEx);
d6e8d8
		include($phpbb_root_path . 'language/' . $language . '/acp/users.' . $phpEx);
d6e8d8
d6e8d8
		// link a few things to the correct place so we don't get any problems
d6e8d8
		$user->lang = &$lang;
d6e8d8
		$user->data['user_id'] = ANONYMOUS;
d6e8d8
		$user->date_format = $config['default_dateformat'];
d6e8d8
d6e8d8
		// a little trick to get all user_ids
d6e8d8
		$user_ids = call_user_func_array('array_merge', array_values($colliding_users));
d6e8d8
d6e8d8
		$sql = 'SELECT session_user_id, MAX(session_time) AS session_time
d6e8d8
			FROM ' . SESSIONS_TABLE . '
d6e8d8
			WHERE session_time >= ' . (time() - $config['session_length']) . '
d6e8d8
				AND ' . $db->sql_in_set('session_user_id', $user_ids) . '
d6e8d8
			GROUP BY session_user_id';
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
d6e8d8
		$session_times = array();
d6e8d8
		while ($row = $db->sql_fetchrow($result))
d6e8d8
		{
d6e8d8
			$session_times[$row['session_user_id']] = $row['session_time'];
d6e8d8
		}
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		$sql = 'SELECT *
d6e8d8
			FROM ' . USERS_TABLE . '
d6e8d8
			WHERE ' . $db->sql_in_set('user_id', $user_ids);
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
d6e8d8
		$users = array();
d6e8d8
		while ($row = $db->sql_fetchrow($result))
d6e8d8
		{
d6e8d8
			if (isset($session_times[$row['user_id']]))
d6e8d8
			{
d6e8d8
				$row['session_time'] = $session_times[$row['user_id']];
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{
d6e8d8
				$row['session_time'] = 0;
d6e8d8
			}
d6e8d8
			$users[(int) $row['user_id']] = $row;
d6e8d8
		}
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
		unset($session_times);
d6e8d8
d6e8d8
		// now display a table with all users, some information about them and options
d6e8d8
		// for the admin: keep name, change name (with text input) or delete user
d6e8d8
		$u_action = "database_update.$phpEx?language=$language&type=$inline_update";
d6e8d8
?>
d6e8d8


d6e8d8
d6e8d8

d6e8d8
<form id="change_clean_names" method="post" action="<?php echo $u_action; ?>">
d6e8d8
d6e8d8
d6e8d8
d6e8d8
		foreach ($colliding_users as $clean_name => $user_ids)
d6e8d8
		{
d6e8d8
?>
d6e8d8
	<fieldset class="tabulated">
d6e8d8
		
d6e8d8
			<caption></caption>
d6e8d8
			
d6e8d8
				
d6e8d8
					 
d6e8d8
					
d6e8d8
					
d6e8d8
					
d6e8d8
					
d6e8d8
					
d6e8d8
					
d6e8d8
				
d6e8d8
			
d6e8d8
			
d6e8d8
d6e8d8
			foreach ($user_ids as $i => $user_id)
d6e8d8
			{
d6e8d8
				$row = $users[$user_id];
d6e8d8
d6e8d8
				$rank_title = $rank_img = '';
d6e8d8
				get_user_rank($row['user_rank'], $row['user_posts'], $rank_title, $rank_img, $rank_img_src);
d6e8d8
d6e8d8
				$last_visit = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
d6e8d8
d6e8d8
				$info = '';
d6e8d8
				switch ($row['user_type'])
d6e8d8
				{
d6e8d8
					case USER_INACTIVE:
d6e8d8
						$info .= $lang['USER_INACTIVE'];
d6e8d8
					break;
d6e8d8
d6e8d8
					case USER_IGNORE:
d6e8d8
						$info .= $lang['BOT'];
d6e8d8
					break;
d6e8d8
d6e8d8
					case USER_FOUNDER:
d6e8d8
						$info .= $lang['FOUNDER'];
d6e8d8
					break;
d6e8d8
d6e8d8
					default:
d6e8d8
						$info .= $lang['USER_ACTIVE'];
d6e8d8
				}
d6e8d8
d6e8d8
				if ($user_id == ANONYMOUS)
d6e8d8
				{
d6e8d8
					$info = $lang['GUEST'];
d6e8d8
				}
d6e8d8
?>
d6e8d8
				
d6e8d8
					
d6e8d8
						
d6e8d8
						
d6e8d8
					
d6e8d8
					
d6e8d8
					
d6e8d8
					format_date($row['user_regdate']) ?>
d6e8d8
					format_date($last_visit); ?> 
d6e8d8
					
d6e8d8
						<label><input type="radio" class="radio" id="keep_user_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="keep" checked="checked" /> </label>
d6e8d8
						<label><input type="radio" class="radio" id="edit_user_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="edit" /> </label>
d6e8d8
d6e8d8
				// some users must not be deleted
d6e8d8
				if ($user_id != ANONYMOUS && $row['user_type'] != USER_FOUNDER)
d6e8d8
				{
d6e8d8
?>
d6e8d8
						<label><input type="radio" class="radio" id="delete_user_retain_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="delete_retain" /> </label>
d6e8d8
						<label><input type="radio" class="radio" id="delete_user_remove_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="delete_remove" /> </label>
d6e8d8
d6e8d8
				}
d6e8d8
?>
d6e8d8
					
d6e8d8
					
d6e8d8
						<input id="new_username_<?php echo $user_id; ?>" type="text" name="new_usernames[<?php echo $user_id; ?>]" value="<?php echo $row['username']; ?>" />
d6e8d8
					
d6e8d8
				
d6e8d8
d6e8d8
			}
d6e8d8
?>
d6e8d8
			
d6e8d8
		
d6e8d8
	</fieldset>
d6e8d8
d6e8d8
		}
d6e8d8
?>
d6e8d8
		

d6e8d8
			<input class="button2" id="resolve_conflicts" type="submit" name="resolve_conflicts" value="<?php echo $lang['SUBMIT']; ?>" />
d6e8d8
		

d6e8d8
	</form>
d6e8d8
d6e8d8
	}
d6e8d8
	else if (sizeof($found_names))
d6e8d8
	{
d6e8d8
		$sql = 'SELECT user_id, username, username_clean
d6e8d8
			FROM ' . USERS_TABLE . '
d6e8d8
			WHERE ' . $db->sql_in_set('user_id', array_values($found_names));
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
d6e8d8
		$found_names = array();
d6e8d8
		while ($row = $db->sql_fetchrow($result))
d6e8d8
		{
d6e8d8
			$clean_name = utf8_new_clean_string($row['username']);
d6e8d8
d6e8d8
			if ($clean_name != $row['username_clean'])
d6e8d8
			{
d6e8d8
				$user_id = (int) $row['user_id'];
d6e8d8
				$found_names[$user_id] = $clean_name;
d6e8d8
d6e8d8
				// impossible unique clean name
d6e8d8
				$sql = 'UPDATE ' . USERS_TABLE . "
d6e8d8
					SET username_clean = '  {$user_id}'
d6e8d8
					WHERE user_id = {$user_id}";
d6e8d8
				$db->sql_query($sql);
d6e8d8
			}
d6e8d8
		}
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		foreach ($found_names as $user_id => $clean_name)
d6e8d8
		{
d6e8d8
			$sql = 'UPDATE ' . USERS_TABLE . '
d6e8d8
				SET username_clean = \'' . $db->sql_escape($clean_name) . '\'
d6e8d8
				WHERE user_id = ' . $user_id;
d6e8d8
			$db->sql_query($sql);
d6e8d8
		}
d6e8d8
	}
d6e8d8
	unset($found_names);
d6e8d8
	unset($colliding_users);
d6e8d8
}
d6e8d8
d6e8d8
if ($exit)
d6e8d8
{
d6e8d8
?>
d6e8d8
d6e8d8
					
d6e8d8
				
d6e8d8
			
d6e8d8
		
d6e8d8
		
d6e8d8
	
d6e8d8
d6e8d8
	
d6e8d8
		Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
d6e8d8
	
d6e8d8
d6e8d8
d6e8d8
</body>
d6e8d8
</html>
d6e8d8
d6e8d8
d6e8d8
	if (function_exists('exit_handler'))
d6e8d8
	{
d6e8d8
		exit_handler();
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
// Schema updates
d6e8d8
?>
d6e8d8
	

d6e8d8
d6e8d8
	

d6e8d8
d6e8d8
	
d6e8d8
	

::

d6e8d8
d6e8d8
d6e8d8
d6e8d8
flush();
d6e8d8
d6e8d8
// We go through the schema changes from the lowest to the highest version
d6e8d8
// We try to also include versions 'in-between'...
d6e8d8
$no_updates = true;
d6e8d8
$versions = array_keys($database_update_info);
d6e8d8
for ($i = 0; $i < sizeof($versions); $i++)
d6e8d8
{
d6e8d8
	$version = $versions[$i];
d6e8d8
	$schema_changes = $database_update_info[$version];
d6e8d8
d6e8d8
	$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
d6e8d8
d6e8d8
	// If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
d6e8d8
	if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
d6e8d8
	{
d6e8d8
		continue;
d6e8d8
	}
d6e8d8
d6e8d8
/*	if ($debug_from_version !== false)
d6e8d8
	{
d6e8d8
		// Applying update schema for version array with key '$version'
d6e8d8
		// for version '$version' to '$next_version'
d6e8d8
		continue;
d6e8d8
	}*/
d6e8d8
d6e8d8
	if (!sizeof($schema_changes))
d6e8d8
	{
d6e8d8
		continue;
d6e8d8
	}
d6e8d8
d6e8d8
	$no_updates = false;
d6e8d8
d6e8d8
	// Change columns?
d6e8d8
	if (!empty($schema_changes['change_columns']))
d6e8d8
	{
d6e8d8
		foreach ($schema_changes['change_columns'] as $table => $columns)
d6e8d8
		{
d6e8d8
			foreach ($columns as $column_name => $column_data)
d6e8d8
			{
d6e8d8
				sql_column_change($map_dbms, $table, $column_name, $column_data);
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	// Add columns?
d6e8d8
	if (!empty($schema_changes['add_columns']))
d6e8d8
	{
d6e8d8
		foreach ($schema_changes['add_columns'] as $table => $columns)
d6e8d8
		{
d6e8d8
			foreach ($columns as $column_name => $column_data)
d6e8d8
			{
d6e8d8
				// Only add the column if it does not exist yet
d6e8d8
				if (!column_exists($map_dbms, $table, $column_name))
d6e8d8
				{
d6e8d8
					sql_column_add($map_dbms, $table, $column_name, $column_data);
d6e8d8
				}
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	// Remove keys?
d6e8d8
	if (!empty($schema_changes['drop_keys']))
d6e8d8
	{
d6e8d8
		foreach ($schema_changes['drop_keys'] as $table => $indexes)
d6e8d8
		{
d6e8d8
			foreach ($indexes as $index_name)
d6e8d8
			{
d6e8d8
				sql_index_drop($map_dbms, $index_name, $table);
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	// Drop columns?
d6e8d8
	if (!empty($schema_changes['drop_columns']))
d6e8d8
	{
d6e8d8
		foreach ($schema_changes['drop_columns'] as $table => $columns)
d6e8d8
		{
d6e8d8
			foreach ($columns as $column)
d6e8d8
			{
d6e8d8
				sql_column_remove($map_dbms, $table, $column);
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	// Add primary keys?
d6e8d8
	if (!empty($schema_changes['add_primary_keys']))
d6e8d8
	{
d6e8d8
		foreach ($schema_changes['add_primary_keys'] as $table => $columns)
d6e8d8
		{
d6e8d8
			sql_create_primary_key($map_dbms, $table, $columns);
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	// Add unqiue indexes?
d6e8d8
	if (!empty($schema_changes['add_unique_index']))
d6e8d8
	{
d6e8d8
		foreach ($schema_changes['add_unique_index'] as $table => $index_array)
d6e8d8
		{
d6e8d8
			foreach ($index_array as $index_name => $column)
d6e8d8
			{
d6e8d8
				sql_create_unique_index($map_dbms, $index_name, $table, $column);
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	// Add indexes?
d6e8d8
	if (!empty($schema_changes['add_index']))
d6e8d8
	{
d6e8d8
		foreach ($schema_changes['add_index'] as $table => $index_array)
d6e8d8
		{
d6e8d8
			foreach ($index_array as $index_name => $column)
d6e8d8
			{
d6e8d8
				sql_create_index($map_dbms, $index_name, $table, $column);
d6e8d8
			}
d6e8d8
		}
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
_write_result($no_updates, $errored, $error_ary);
d6e8d8
d6e8d8
// Data updates
d6e8d8
$error_ary = array();
d6e8d8
$errored = $no_updates = false;
d6e8d8
d6e8d8
?>
d6e8d8
d6e8d8


d6e8d8

d6e8d8

d6e8d8

::

d6e8d8
d6e8d8
d6e8d8
d6e8d8
flush();
d6e8d8
d6e8d8
$no_updates = true;
d6e8d8
$versions = array_keys($database_update_info);
d6e8d8
d6e8d8
// some code magic
d6e8d8
for ($i = 0; $i < sizeof($versions); $i++)
d6e8d8
{
d6e8d8
	$version = $versions[$i];
d6e8d8
	$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
d6e8d8
d6e8d8
	// If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
d6e8d8
	if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
d6e8d8
	{
d6e8d8
		continue;
d6e8d8
	}
d6e8d8
d6e8d8
/*	if ($debug_from_version !== false)
d6e8d8
	{
d6e8d8
		// Applying update schema for version array with key '$version'
d6e8d8
		// for version '$version' to '$next_version'
d6e8d8
		continue;
d6e8d8
	}*/
d6e8d8
d6e8d8
	change_database_data($no_updates, $version);
d6e8d8
}
d6e8d8
d6e8d8
_write_result($no_updates, $errored, $error_ary);
d6e8d8
d6e8d8
$error_ary = array();
d6e8d8
$errored = $no_updates = false;
d6e8d8
d6e8d8
?>
d6e8d8
d6e8d8


d6e8d8

d6e8d8

d6e8d8

::

d6e8d8
d6e8d8
d6e8d8
d6e8d8
flush();
d6e8d8
d6e8d8
//if ($debug_from_version === false)
d6e8d8
// {
d6e8d8
d6e8d8
// update the version
d6e8d8
$sql = "UPDATE " . CONFIG_TABLE . "
d6e8d8
	SET config_value = '$updates_to_version'
d6e8d8
	WHERE config_name = 'version'";
d6e8d8
_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
// Reset permissions
d6e8d8
$sql = 'UPDATE ' . USERS_TABLE . "
d6e8d8
	SET user_permissions = '',
d6e8d8
		user_perm_from = 0";
d6e8d8
_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
// }
d6e8d8
d6e8d8
/* Optimize/vacuum analyze the tables where appropriate
d6e8d8
// this should be done for each version in future along with
d6e8d8
// the version number update
d6e8d8
switch ($db->sql_layer)
d6e8d8
{
d6e8d8
	case 'mysql':
d6e8d8
	case 'mysqli':
d6e8d8
	case 'mysql4':
d6e8d8
		$sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'sessions_keys' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
d6e8d8
		_sql($sql, $errored, $error_ary);
d6e8d8
	break;
d6e8d8
d6e8d8
	case 'postgresql':
d6e8d8
		_sql("VACUUM ANALYZE", $errored, $error_ary);
d6e8d8
	break;
d6e8d8
}
d6e8d8
*/
d6e8d8
d6e8d8
_write_result($no_updates, $errored, $error_ary);
d6e8d8
d6e8d8
?>
d6e8d8
d6e8d8

d6e8d8

d6e8d8
d6e8d8

d6e8d8
d6e8d8
d6e8d8
d6e8d8
if (!$inline_update)
d6e8d8
{
d6e8d8
	// Purge the cache...
d6e8d8
	$cache->purge();
d6e8d8
?>
d6e8d8
d6e8d8
	

d6e8d8
d6e8d8
	

d6e8d8
d6e8d8
d6e8d8
}
d6e8d8
else
d6e8d8
{
d6e8d8
?>
d6e8d8
d6e8d8
	

d6e8d8
d6e8d8
	

" class="button1">

d6e8d8
d6e8d8
d6e8d8
}
d6e8d8
d6e8d8
// Add database update to log
d6e8d8
add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
d6e8d8
d6e8d8
// Now we purge the session table as well as all cache files
d6e8d8
$cache->purge();
d6e8d8
d6e8d8
?>
d6e8d8
d6e8d8
					
d6e8d8
				
d6e8d8
			
d6e8d8
		
d6e8d8
		
d6e8d8
	
d6e8d8
d6e8d8
	
d6e8d8
		Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
d6e8d8
	
d6e8d8
d6e8d8
d6e8d8
</body>
d6e8d8
</html>
d6e8d8
d6e8d8
d6e8d8
d6e8d8
garbage_collection();
d6e8d8
d6e8d8
if (function_exists('exit_handler'))
d6e8d8
{
d6e8d8
	exit_handler();
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Function where all data changes are executed
d6e8d8
*/
d6e8d8
function change_database_data(&$no_updates, $version)
d6e8d8
{
d6e8d8
	global $db, $map_dbms, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
d6e8d8
d6e8d8
	switch ($version)
d6e8d8
	{
d6e8d8
		case '3.0.RC2':
d6e8d8
d6e8d8
			$smileys = array();
d6e8d8
d6e8d8
			$sql = 'SELECT smiley_id, code
d6e8d8
				FROM ' . SMILIES_TABLE;
d6e8d8
			$result = $db->sql_query($sql);
d6e8d8
d6e8d8
			while ($row = $db->sql_fetchrow($result))
d6e8d8
			{
d6e8d8
				$smileys[$row['smiley_id']] = $row['code'];
d6e8d8
			}
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			foreach ($smileys as $id => $code)
d6e8d8
			{
d6e8d8
				// 2.0 only entitized lt and gt; We need to do something about double quotes.
d6e8d8
				if (strchr($code, '"') === false)
d6e8d8
				{
d6e8d8
					continue;
d6e8d8
				}
d6e8d8
d6e8d8
				$new_code = str_replace('&', '&', $code);
d6e8d8
				$new_code = str_replace('<', '<', $new_code);
d6e8d8
				$new_code = str_replace('>', '>', $new_code);
d6e8d8
				$new_code = utf8_htmlspecialchars($new_code);
d6e8d8
d6e8d8
				$sql = 'UPDATE ' . SMILIES_TABLE . '
d6e8d8
					SET code = \'' . $db->sql_escape($new_code) . '\'
d6e8d8
					WHERE smiley_id = ' . (int) $id;
d6e8d8
				$db->sql_query($sql);
d6e8d8
			}
d6e8d8
d6e8d8
			$index_list = sql_list_index($map_dbms, ACL_ROLES_DATA_TABLE);
d6e8d8
d6e8d8
			if (in_array('ath_opt_id', $index_list))
d6e8d8
			{
d6e8d8
				sql_index_drop($map_dbms, 'ath_opt_id', ACL_ROLES_DATA_TABLE);
d6e8d8
				sql_create_index($map_dbms, 'ath_op_id', ACL_ROLES_DATA_TABLE, array('auth_option_id'));
d6e8d8
			}
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		case '3.0.RC3':
d6e8d8
d6e8d8
			if ($map_dbms === 'postgres')
d6e8d8
			{
d6e8d8
				$sql = "SELECT SETVAL('" . FORUMS_TABLE . "_seq',(select case when max(forum_id)>0 then max(forum_id)+1 else 1 end from " . FORUMS_TABLE . '));';
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
			}
d6e8d8
d6e8d8
			// we check for:
d6e8d8
			// ath_opt_id
d6e8d8
			// ath_op_id
d6e8d8
			// ACL_ROLES_DATA_TABLE_ath_opt_id
d6e8d8
			// we want ACL_ROLES_DATA_TABLE_ath_op_id
d6e8d8
d6e8d8
			$table_index_fix = array(
d6e8d8
				ACL_ROLES_DATA_TABLE => array(
d6e8d8
					'ath_opt_id'							=> 'ath_op_id',
d6e8d8
					'ath_op_id'								=> 'ath_op_id',
d6e8d8
					ACL_ROLES_DATA_TABLE . '_ath_opt_id'	=> 'ath_op_id'
d6e8d8
				),
d6e8d8
				STYLES_IMAGESET_DATA_TABLE => array(
d6e8d8
					'i_id'									=> 'i_d',
d6e8d8
					'i_d'									=> 'i_d',
d6e8d8
					STYLES_IMAGESET_DATA_TABLE . '_i_id'	=> 'i_d'
d6e8d8
				)
d6e8d8
			);
d6e8d8
d6e8d8
			// we need to create some indicies...
d6e8d8
			$needed_creation = array();
d6e8d8
d6e8d8
			foreach ($table_index_fix as $table_name => $index_info)
d6e8d8
			{
d6e8d8
				$index_list = sql_list_fake($map_dbms, $table_name);
d6e8d8
				foreach ($index_info as $bad_index => $good_index)
d6e8d8
				{
d6e8d8
					if (in_array($bad_index, $index_list))
d6e8d8
					{
d6e8d8
						// mysql is actually OK, it won't get a hand in this crud
d6e8d8
						switch ($map_dbms)
d6e8d8
						{
d6e8d8
							// last version, mssql had issues with index removal
d6e8d8
							case 'mssql':
d6e8d8
								$sql = 'DROP INDEX ' . $table_name . '.' . $bad_index;
d6e8d8
								_sql($sql, $errored, $error_ary);
d6e8d8
							break;
d6e8d8
d6e8d8
							// last version, firebird, oracle, postgresql and sqlite all got bad index names
d6e8d8
							// we got kinda lucky, tho: they all support the same syntax
d6e8d8
							case 'firebird':
d6e8d8
							case 'oracle':
d6e8d8
							case 'postgres':
d6e8d8
							case 'sqlite':
d6e8d8
								$sql = 'DROP INDEX ' . $bad_index;
d6e8d8
								_sql($sql, $errored, $error_ary);
d6e8d8
							break;
d6e8d8
						}
d6e8d8
d6e8d8
						// If the good index already exist we do not need to create it again...
d6e8d8
						if (($map_dbms == 'mysql_40' || $map_dbms == 'mysql_41') && $bad_index == $good_index)
d6e8d8
						{
d6e8d8
						}
d6e8d8
						else
d6e8d8
						{
d6e8d8
							$needed_creation[$table_name][$good_index] = 1;
d6e8d8
						}
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$new_index_defs = array('ath_op_id' => array('auth_option_id'), 'i_d' => array('imageset_id'));
d6e8d8
d6e8d8
			foreach ($needed_creation as $bad_table => $index_repair_list)
d6e8d8
			{
d6e8d8
				foreach ($index_repair_list as $new_index => $garbage)
d6e8d8
				{
d6e8d8
					sql_create_index($map_dbms, $new_index, $bad_table, $new_index_defs[$new_index]);
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			// Make sure empty smiley codes do not exist
d6e8d8
			$sql = 'DELETE FROM ' . SMILIES_TABLE . "
d6e8d8
				WHERE code = ''";
d6e8d8
			_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			set_config('allow_birthdays', '1');
d6e8d8
			set_config('cron_lock', '0', true);
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		case '3.0.RC4':
d6e8d8
d6e8d8
			$update_auto_increment = array(
d6e8d8
				STYLES_TABLE				=> 'style_id',
d6e8d8
				STYLES_TEMPLATE_TABLE		=> 'template_id',
d6e8d8
				STYLES_THEME_TABLE			=> 'theme_id',
d6e8d8
				STYLES_IMAGESET_TABLE		=> 'imageset_id'
d6e8d8
			);
d6e8d8
d6e8d8
			$sql = 'SELECT *
d6e8d8
				FROM ' . STYLES_TABLE . '
d6e8d8
				WHERE style_id = 0';
d6e8d8
			$result = _sql($sql, $errored, $error_ary);
d6e8d8
			$bad_style_row = $db->sql_fetchrow($result);
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if ($bad_style_row)
d6e8d8
			{
d6e8d8
				$sql = 'SELECT MAX(style_id) as max_id
d6e8d8
					FROM ' . STYLES_TABLE;
d6e8d8
				$result = _sql($sql, $errored, $error_ary);
d6e8d8
				$row = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				$proper_id = $row['max_id'] + 1;
d6e8d8
d6e8d8
				_sql('UPDATE ' . STYLES_TABLE . " SET style_id = $proper_id WHERE style_id = 0", $errored, $error_ary);
d6e8d8
				_sql('UPDATE ' . FORUMS_TABLE . " SET forum_style = $proper_id WHERE forum_style = 0", $errored, $error_ary);
d6e8d8
				_sql('UPDATE ' . USERS_TABLE . " SET user_style = $proper_id WHERE user_style = 0", $errored, $error_ary);
d6e8d8
d6e8d8
				$sql = 'SELECT config_value
d6e8d8
					FROM ' . CONFIG_TABLE . "
d6e8d8
					WHERE config_name = 'default_style'";
d6e8d8
				$result = _sql($sql, $errored, $error_ary);
d6e8d8
				$style_config = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				if ($style_config['config_value'] === '0')
d6e8d8
				{
d6e8d8
					set_config('default_style', (string) $proper_id);
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$sql = 'SELECT *
d6e8d8
				FROM ' . STYLES_TEMPLATE_TABLE . '
d6e8d8
				WHERE template_id = 0';
d6e8d8
			$result = _sql($sql, $errored, $error_ary);
d6e8d8
			$bad_style_row = $db->sql_fetchrow($result);
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if ($bad_style_row)
d6e8d8
			{
d6e8d8
				$sql = 'SELECT MAX(template_id) as max_id
d6e8d8
					FROM ' . STYLES_TEMPLATE_TABLE;
d6e8d8
				$result = _sql($sql, $errored, $error_ary);
d6e8d8
				$row = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				$proper_id = $row['max_id'] + 1;
d6e8d8
d6e8d8
				_sql('UPDATE ' . STYLES_TABLE . " SET template_id = $proper_id WHERE template_id = 0", $errored, $error_ary);
d6e8d8
			}
d6e8d8
d6e8d8
			$sql = 'SELECT *
d6e8d8
				FROM ' . STYLES_THEME_TABLE . '
d6e8d8
				WHERE theme_id = 0';
d6e8d8
			$result = _sql($sql, $errored, $error_ary);
d6e8d8
			$bad_style_row = $db->sql_fetchrow($result);
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if ($bad_style_row)
d6e8d8
			{
d6e8d8
				$sql = 'SELECT MAX(theme_id) as max_id
d6e8d8
					FROM ' . STYLES_THEME_TABLE;
d6e8d8
				$result = _sql($sql, $errored, $error_ary);
d6e8d8
				$row = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				$proper_id = $row['max_id'] + 1;
d6e8d8
d6e8d8
				_sql('UPDATE ' . STYLES_TABLE . " SET theme_id = $proper_id WHERE theme_id = 0", $errored, $error_ary);
d6e8d8
			}
d6e8d8
d6e8d8
			$sql = 'SELECT *
d6e8d8
				FROM ' . STYLES_IMAGESET_TABLE . '
d6e8d8
				WHERE imageset_id = 0';
d6e8d8
			$result = _sql($sql, $errored, $error_ary);
d6e8d8
			$bad_style_row = $db->sql_fetchrow($result);
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			if ($bad_style_row)
d6e8d8
			{
d6e8d8
				$sql = 'SELECT MAX(imageset_id) as max_id
d6e8d8
					FROM ' . STYLES_IMAGESET_TABLE;
d6e8d8
				$result = _sql($sql, $errored, $error_ary);
d6e8d8
				$row = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				$proper_id = $row['max_id'] + 1;
d6e8d8
d6e8d8
				_sql('UPDATE ' . STYLES_TABLE . " SET imageset_id = $proper_id WHERE imageset_id = 0", $errored, $error_ary);
d6e8d8
				_sql('UPDATE ' . STYLES_IMAGESET_DATA_TABLE . " SET imageset_id = $proper_id WHERE imageset_id = 0", $errored, $error_ary);
d6e8d8
			}
d6e8d8
d6e8d8
			if ($map_dbms == 'mysql_40' || $map_dbms == 'mysql_41')
d6e8d8
			{
d6e8d8
				foreach ($update_auto_increment as $auto_table_name => $auto_column_name)
d6e8d8
				{
d6e8d8
					$sql = "SELECT MAX({$auto_column_name}) as max_id
d6e8d8
						FROM {$auto_table_name}";
d6e8d8
					$result = _sql($sql, $errored, $error_ary);
d6e8d8
					$row = $db->sql_fetchrow($result);
d6e8d8
					$db->sql_freeresult($result);
d6e8d8
d6e8d8
					$max_id = ((int) $row['max_id']) + 1;
d6e8d8
					_sql("ALTER TABLE {$auto_table_name} AUTO_INCREMENT = {$max_id}", $errored, $error_ary);
d6e8d8
				}
d6e8d8
			}
d6e8d8
			else if ($map_dbms == 'postgres')
d6e8d8
			{
d6e8d8
				foreach ($update_auto_increment as $auto_table_name => $auto_column_name)
d6e8d8
				{
d6e8d8
					$sql = "SELECT SETVAL('" . $auto_table_name . "_seq',(select case when max({$auto_column_name})>0 then max({$auto_column_name})+1 else 1 end from " . $auto_table_name . '));';
d6e8d8
					_sql($sql, $errored, $error_ary);
d6e8d8
				}
d6e8d8
d6e8d8
				$sql = 'DROP SEQUENCE ' . STYLES_TEMPLATE_DATA_TABLE . '_seq';
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
			}
d6e8d8
			else if ($map_dbms == 'firebird')
d6e8d8
			{
d6e8d8
				$sql = 'DROP TRIGGER t_' . STYLES_TEMPLATE_DATA_TABLE;
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
				$sql = 'DROP GENERATOR ' . STYLES_TEMPLATE_DATA_TABLE . '_gen';
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
			}
d6e8d8
			else if ($map_dbms == 'oracle')
d6e8d8
			{
d6e8d8
				$sql = 'DROP TRIGGER t_' . STYLES_TEMPLATE_DATA_TABLE;
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
				$sql = 'DROP SEQUENCE ' . STYLES_TEMPLATE_DATA_TABLE . '_seq';
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
			}
d6e8d8
			else if ($map_dbms == 'mssql')
d6e8d8
			{
d6e8d8
				// we use transactions because we need to have a working DB at the end of all of this
d6e8d8
				$db->sql_transaction('begin');
d6e8d8
d6e8d8
				$sql = 'SELECT *
d6e8d8
					FROM ' . STYLES_TEMPLATE_DATA_TABLE;
d6e8d8
				$result = _sql($sql, $errored, $error_ary);
d6e8d8
				$old_style_rows = array();
d6e8d8
				while ($row = $db->sql_fetchrow($result))
d6e8d8
				{
d6e8d8
					$old_style_rows[] = $row;
d6e8d8
				}
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				// death to the table, it is evil!
d6e8d8
				$sql = 'DROP TABLE ' . STYLES_TEMPLATE_DATA_TABLE;
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
				// the table of awesomeness, praise be to it (or something)
d6e8d8
				$sql = 'CREATE TABLE [' . STYLES_TEMPLATE_DATA_TABLE . "] (
d6e8d8
					[template_id] [int] DEFAULT (0) NOT NULL ,
d6e8d8
					[template_filename] [varchar] (100) DEFAULT ('') NOT NULL ,
d6e8d8
					[template_included] [varchar] (8000) DEFAULT ('') NOT NULL ,
d6e8d8
					[template_mtime] [int] DEFAULT (0) NOT NULL ,
d6e8d8
					[template_data] [text] DEFAULT ('') NOT NULL
d6e8d8
				) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]";
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
				// index? index
d6e8d8
				$sql = 'CREATE  INDEX [tid] ON [' . STYLES_TEMPLATE_DATA_TABLE . ']([template_id]) ON [PRIMARY]';
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
				// yet another index
d6e8d8
				$sql = 'CREATE  INDEX [tfn] ON [' . STYLES_TEMPLATE_DATA_TABLE . ']([template_filename]) ON [PRIMARY]';
d6e8d8
				_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
				foreach ($old_style_rows as $return_row)
d6e8d8
				{
d6e8d8
					_sql('INSERT INTO ' . STYLES_TEMPLATE_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $return_row), $errored, $error_ary);
d6e8d8
				}
d6e8d8
d6e8d8
				$db->sql_transaction('commit');
d6e8d8
			}
d6e8d8
d6e8d8
			// Setting this here again because new installations may not have it...
d6e8d8
			set_config('cron_lock', '0', true);
d6e8d8
			set_config('ldap_port', '');
d6e8d8
			set_config('ldap_user_filter', '');
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		case '3.0.RC5':
d6e8d8
d6e8d8
			// In case the user is having the bot mediapartner google "as is", adjust it.
d6e8d8
			$sql = 'UPDATE ' . BOTS_TABLE . "
d6e8d8
				SET bot_agent = '" . $db->sql_escape('Mediapartners-Google') . "'
d6e8d8
				WHERE bot_agent = '" . $db->sql_escape('Mediapartners-Google/') . "'";
d6e8d8
			_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			set_config('form_token_lifetime', '7200');
d6e8d8
			set_config('form_token_mintime', '0');
d6e8d8
			set_config('min_time_reg', '5');
d6e8d8
			set_config('min_time_terms', '2');
d6e8d8
			set_config('form_token_sid_guests', '1');
d6e8d8
d6e8d8
			$db->sql_transaction('begin');
d6e8d8
d6e8d8
			$sql = 'SELECT forum_id, forum_password
d6e8d8
					FROM ' . FORUMS_TABLE;
d6e8d8
			$result = _sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			while ($row = $db->sql_fetchrow($result))
d6e8d8
			{
d6e8d8
				if (!empty($row['forum_password']))
d6e8d8
				{
d6e8d8
					_sql('UPDATE ' . FORUMS_TABLE . " SET forum_password = '" . md5($row['forum_password']) . "' WHERE forum_id = {$row['forum_id']}", $errored, $error_ary);
d6e8d8
				}
d6e8d8
			}
d6e8d8
			$db->sql_freeresult($result);
d6e8d8
d6e8d8
			$db->sql_transaction('commit');
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		case '3.0.0':
d6e8d8
d6e8d8
			$sql = 'UPDATE ' . TOPICS_TABLE . "
d6e8d8
				SET topic_last_view_time = topic_last_post_time
d6e8d8
				WHERE topic_last_view_time = 0";
d6e8d8
			_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			// Update smiley sizes
d6e8d8
			$smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');
d6e8d8
d6e8d8
			foreach ($smileys as $smiley)
d6e8d8
			{
d6e8d8
				if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley))
d6e8d8
				{
d6e8d8
					list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);
d6e8d8
d6e8d8
					$sql = 'UPDATE ' . SMILIES_TABLE . '
d6e8d8
						SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
d6e8d8
						WHERE smiley_url = '" . $db->sql_escape($smiley) . "'";
d6e8d8
d6e8d8
					_sql($sql, $errored, $error_ary);
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		// No changes from 3.0.1-RC1 to 3.0.1
d6e8d8
		case '3.0.1-RC1':
d6e8d8
		break;
d6e8d8
d6e8d8
		// changes from 3.0.1 to 3.0.2-RC1
d6e8d8
		case '3.0.1':
d6e8d8
d6e8d8
			set_config('referer_validation', '1');
d6e8d8
			set_config('check_attachment_content', '1');
d6e8d8
			set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		// No changes from 3.0.2-RC1 to 3.0.2-RC2
d6e8d8
		case '3.0.2-RC1':
d6e8d8
		break;
d6e8d8
d6e8d8
		// No changes from 3.0.2-RC2 to 3.0.2
d6e8d8
		case '3.0.2-RC2':
d6e8d8
		break;
d6e8d8
d6e8d8
		// Changes from 3.0.2 to 3.0.3-RC1
d6e8d8
		case '3.0.2':
d6e8d8
			set_config('enable_queue_trigger', '0');
d6e8d8
			set_config('queue_trigger_posts', '3');
d6e8d8
d6e8d8
			set_config('pm_max_recipients', '0');
d6e8d8
d6e8d8
			// Set maximum number of recipients for the registered users, bots, guests group
d6e8d8
			$sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
d6e8d8
				WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
d6e8d8
			_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			// Not prefilling yet
d6e8d8
			set_config('dbms_version', '');
d6e8d8
d6e8d8
			// Add new permission u_masspm_group and duplicate settings from u_masspm
d6e8d8
			include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
d6e8d8
			$auth_admin = new auth_admin();
d6e8d8
d6e8d8
			// Only add the new permission if it does not already exist
d6e8d8
			if (empty($auth_admin->acl_options['id']['u_masspm_group']))
d6e8d8
			{
d6e8d8
				$auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
d6e8d8
d6e8d8
				// Now the tricky part, filling the permission
d6e8d8
				$old_id = $auth_admin->acl_options['id']['u_masspm'];
d6e8d8
				$new_id = $auth_admin->acl_options['id']['u_masspm_group'];
d6e8d8
d6e8d8
				$tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
d6e8d8
d6e8d8
				foreach ($tables as $table)
d6e8d8
				{
d6e8d8
					$sql = 'SELECT *
d6e8d8
						FROM ' . $table . '
d6e8d8
						WHERE auth_option_id = ' . $old_id;
d6e8d8
					$result = _sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
					$sql_ary = array();
d6e8d8
					while ($row = $db->sql_fetchrow($result))
d6e8d8
					{
d6e8d8
						$row['auth_option_id'] = $new_id;
d6e8d8
						$sql_ary[] = $row;
d6e8d8
					}
d6e8d8
					$db->sql_freeresult($result);
d6e8d8
d6e8d8
					if (sizeof($sql_ary))
d6e8d8
					{
d6e8d8
						$db->sql_multi_insert($table, $sql_ary);
d6e8d8
					}
d6e8d8
				}
d6e8d8
d6e8d8
				// Remove any old permission entries
d6e8d8
				$auth_admin->acl_clear_prefetch();
d6e8d8
			}
d6e8d8
d6e8d8
			/**
d6e8d8
			* Do not resync post counts here. An admin may do this later from the ACP
d6e8d8
			$start = 0;
d6e8d8
			$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
d6e8d8
d6e8d8
			$sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
d6e8d8
			_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			do
d6e8d8
			{
d6e8d8
				$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
d6e8d8
					FROM ' . POSTS_TABLE . '
d6e8d8
					WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
d6e8d8
						AND post_postcount = 1 AND post_approved = 1
d6e8d8
					GROUP BY poster_id';
d6e8d8
				$result = _sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
				if ($row = $db->sql_fetchrow($result))
d6e8d8
				{
d6e8d8
					do
d6e8d8
					{
d6e8d8
						$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
d6e8d8
						_sql($sql, $errored, $error_ary);
d6e8d8
					}
d6e8d8
					while ($row = $db->sql_fetchrow($result));
d6e8d8
d6e8d8
					$start += $step;
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					$start = 0;
d6e8d8
				}
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
			}
d6e8d8
			while ($start);
d6e8d8
			*/
d6e8d8
d6e8d8
			$sql = 'UPDATE ' . MODULES_TABLE . '
d6e8d8
				SET module_auth = \'acl_a_email && cfg_email_enable\'
d6e8d8
				WHERE module_class = \'acp\'
d6e8d8
					AND module_basename = \'email\'';
d6e8d8
			_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		// Changes from 3.0.3-RC1 to 3.0.3
d6e8d8
		case '3.0.3-RC1':
d6e8d8
			$sql = 'UPDATE ' . LOG_TABLE . "
d6e8d8
				SET log_operation = 'LOG_DELETE_TOPIC'
d6e8d8
				WHERE log_operation = 'LOG_TOPIC_DELETED'";
d6e8d8
			_sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		// Changes from 3.0.3 to 3.0.4-RC1
d6e8d8
		case '3.0.3':
d6e8d8
			// Update the Custom Profile Fields based on previous settings to the new format
d6e8d8
			$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
d6e8d8
					FROM ' . PROFILE_FIELDS_TABLE;
d6e8d8
			$result = _sql($sql, $errored, $error_ary);
d6e8d8
d6e8d8
			while ($row = $db->sql_fetchrow($result))
d6e8d8
			{
d6e8d8
				$sql_ary = array(
d6e8d8
					'field_required'	=> 0,
d6e8d8
					'field_show_on_reg'	=> 0,
d6e8d8
					'field_hide'		=> 0,
d6e8d8
					'field_show_profile'=> 0,
d6e8d8
				);
d6e8d8
d6e8d8
				if ($row['field_required'])
d6e8d8
				{
d6e8d8
					$sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
d6e8d8
				}
d6e8d8
				else if ($row['field_show_on_reg'])
d6e8d8
				{
d6e8d8
					$sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
d6e8d8
				}
d6e8d8
				else if ($row['field_hide'])
d6e8d8
				{
d6e8d8
					// Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
d6e8d8
					$sql_ary['field_hide'] = 1;
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					// equivelant to "none", which is the "Display in user control panel" option
d6e8d8
					$sql_ary['field_show_profile'] = 1;
d6e8d8
				}
d6e8d8
d6e8d8
				_sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
d6e8d8
			}
d6e8d8
d6e8d8
			$no_updates = false;
d6e8d8
		break;
d6e8d8
d6e8d8
		// Changes from 3.0.4-RC1 to 3.0.4
d6e8d8
		case '3.0.4-RC1':
d6e8d8
		break;
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Function for triggering an sql statement
d6e8d8
*/
d6e8d8
function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
d6e8d8
{
d6e8d8
	global $db;
d6e8d8
d6e8d8
	if (defined('DEBUG_EXTRA'))
d6e8d8
	{
d6e8d8
		echo "
\n{$sql}\n
";
d6e8d8
	}
d6e8d8
d6e8d8
	$db->sql_return_on_error(true);
d6e8d8
d6e8d8
	$result = $db->sql_query($sql);
d6e8d8
	if ($db->sql_error_triggered)
d6e8d8
	{
d6e8d8
		$errored = true;
d6e8d8
		$error_ary['sql'][] = $db->sql_error_sql;
d6e8d8
		$error_ary['error_code'][] = $db->_sql_error();
d6e8d8
	}
d6e8d8
d6e8d8
	$db->sql_return_on_error(false);
d6e8d8
d6e8d8
	if ($echo_dot)
d6e8d8
	{
d6e8d8
		echo ". \n";
d6e8d8
		flush();
d6e8d8
	}
d6e8d8
d6e8d8
	return $result;
d6e8d8
}
d6e8d8
d6e8d8
function _write_result($no_updates, $errored, $error_ary)
d6e8d8
{
d6e8d8
	global $lang;
d6e8d8
d6e8d8
	if ($no_updates)
d6e8d8
	{
d6e8d8
		echo ' ' . $lang['NO_UPDATES_REQUIRED'] . '

';
d6e8d8
	}
d6e8d8
	else
d6e8d8
	{
d6e8d8
		echo ' ' . $lang['DONE'] . '
' . $lang['RESULT'] . ' :: ';
d6e8d8
d6e8d8
		if ($errored)
d6e8d8
		{
d6e8d8
			echo ' ' . $lang['SOME_QUERIES_FAILED'] . ' 
    ';
d6e8d8
d6e8d8
			for ($i = 0; $i < sizeof($error_ary['sql']); $i++)
d6e8d8
			{
d6e8d8
				echo '
  • ' . $lang['ERROR'] . ' :: ' . htmlspecialchars($error_ary['error_code'][$i]['message']) . '
    ';
  • d6e8d8
    				echo $lang['SQL'] . ' :: ' . htmlspecialchars($error_ary['sql'][$i]) . '

    ';
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			echo ' 

    ' . $lang['SQL_FAILURE_EXPLAIN'] . '

    ';
    d6e8d8
    		}
    d6e8d8
    		else
    d6e8d8
    		{
    d6e8d8
    			echo '' . $lang['NO_ERRORS'] . '

    ';
    d6e8d8
    		}
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    /**
    d6e8d8
    * Check if a specified column exist
    d6e8d8
    */
    d6e8d8
    function column_exists($dbms, $table, $column_name)
    d6e8d8
    {
    d6e8d8
    	global $db;
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = "SHOW COLUMNS
    d6e8d8
    				FROM $table";
    d6e8d8
    			$result = $db->sql_query($sql);
    d6e8d8
    			while ($row = $db->sql_fetchrow($result))
    d6e8d8
    			{
    d6e8d8
    				// lower case just in case
    d6e8d8
    				if (strtolower($row['Field']) == $column_name)
    d6e8d8
    				{
    d6e8d8
    					$db->sql_freeresult($result);
    d6e8d8
    					return true;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    			return false;
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		// PostgreSQL has a way of doing this in a much simpler way but would
    d6e8d8
    		// not allow us to support all versions of PostgreSQL
    d6e8d8
    		case 'postgres':
    d6e8d8
    			$sql = "SELECT a.attname
    d6e8d8
    				FROM pg_class c, pg_attribute a
    d6e8d8
    				WHERE c.relname = '{$table}'
    d6e8d8
    					AND a.attnum > 0
    d6e8d8
    					AND a.attrelid = c.oid";
    d6e8d8
    			$result = $db->sql_query($sql);
    d6e8d8
    			while ($row = $db->sql_fetchrow($result))
    d6e8d8
    			{
    d6e8d8
    				// lower case just in case
    d6e8d8
    				if (strtolower($row['attname']) == $column_name)
    d6e8d8
    				{
    d6e8d8
    					$db->sql_freeresult($result);
    d6e8d8
    					return true;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    			return false;
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		// same deal with PostgreSQL, we must perform more complex operations than
    d6e8d8
    		// we technically could
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = "SELECT c.name
    d6e8d8
    				FROM syscolumns c
    d6e8d8
    				LEFT JOIN sysobjects o ON c.id = o.id
    d6e8d8
    				WHERE o.name = '{$table}'";
    d6e8d8
    			$result = $db->sql_query($sql);
    d6e8d8
    			while ($row = $db->sql_fetchrow($result))
    d6e8d8
    			{
    d6e8d8
    				// lower case just in case
    d6e8d8
    				if (strtolower($row['name']) == $column_name)
    d6e8d8
    				{
    d6e8d8
    					$db->sql_freeresult($result);
    d6e8d8
    					return true;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    			return false;
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'oracle':
    d6e8d8
    			$sql = "SELECT column_name
    d6e8d8
    				FROM user_tab_columns
    d6e8d8
    				WHERE table_name = '{$table}'";
    d6e8d8
    			$result = $db->sql_query($sql);
    d6e8d8
    			while ($row = $db->sql_fetchrow($result))
    d6e8d8
    			{
    d6e8d8
    				// lower case just in case
    d6e8d8
    				if (strtolower($row['column_name']) == $column_name)
    d6e8d8
    				{
    d6e8d8
    					$db->sql_freeresult($result);
    d6e8d8
    					return true;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    			return false;
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'firebird':
    d6e8d8
    			$sql = "SELECT RDB\$FIELD_NAME as FNAME
    d6e8d8
    				FROM RDB\$RELATION_FIELDS
    d6e8d8
    				WHERE RDB\$RELATION_NAME = '{$table}'";
    d6e8d8
    			$result = $db->sql_query($sql);
    d6e8d8
    			while ($row = $db->sql_fetchrow($result))
    d6e8d8
    			{
    d6e8d8
    				// lower case just in case
    d6e8d8
    				if (strtolower($row['fname']) == $column_name)
    d6e8d8
    				{
    d6e8d8
    					$db->sql_freeresult($result);
    d6e8d8
    					return true;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    			return false;
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		// ugh, SQLite
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			$sql = "SELECT sql
    d6e8d8
    				FROM sqlite_master
    d6e8d8
    				WHERE type = 'table'
    d6e8d8
    					AND name = '{$table}'";
    d6e8d8
    			$result = $db->sql_query($sql);
    d6e8d8
    d6e8d8
    			if (!$result)
    d6e8d8
    			{
    d6e8d8
    				return false;
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$row = $db->sql_fetchrow($result);
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    d6e8d8
    			preg_match('#\((.*)\)#s', $row['sql'], $matches);
    d6e8d8
    d6e8d8
    			$cols = trim($matches[1]);
    d6e8d8
    			$col_array = preg_split('/,(?![\s\w]+\))/m', $cols);
    d6e8d8
    d6e8d8
    			foreach ($col_array as $declaration)
    d6e8d8
    			{
    d6e8d8
    				$entities = preg_split('#\s+#', trim($declaration));
    d6e8d8
    				if ($entities[0] == 'PRIMARY')
    d6e8d8
    				{
    d6e8d8
    					continue;
    d6e8d8
    				}
    d6e8d8
    d6e8d8
    				if (strtolower($entities[0]) == $column_name)
    d6e8d8
    				{
    d6e8d8
    					return true;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    			return false;
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    /**
    d6e8d8
    * Function to prepare some column information for better usage
    d6e8d8
    */
    d6e8d8
    function prepare_column_data($dbms, $column_data, $table_name, $column_name)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $unsigned_types;
    d6e8d8
    d6e8d8
    	// Get type
    d6e8d8
    	if (strpos($column_data[0], ':') !== false)
    d6e8d8
    	{
    d6e8d8
    		list($orig_column_type, $column_length) = explode(':', $column_data[0]);
    d6e8d8
    d6e8d8
    		if (!is_array($dbms_type_map[$dbms][$orig_column_type . ':']))
    d6e8d8
    		{
    d6e8d8
    			$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'], $column_length);
    d6e8d8
    		}
    d6e8d8
    		else
    d6e8d8
    		{
    d6e8d8
    			if (isset($dbms_type_map[$dbms][$orig_column_type . ':']['rule']))
    d6e8d8
    			{
    d6e8d8
    				switch ($dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0])
    d6e8d8
    				{
    d6e8d8
    					case 'div':
    d6e8d8
    						$column_length /= $dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1];
    d6e8d8
    						$column_length = ceil($column_length);
    d6e8d8
    						$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length);
    d6e8d8
    					break;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			if (isset($dbms_type_map[$dbms][$orig_column_type . ':']['limit']))
    d6e8d8
    			{
    d6e8d8
    				switch ($dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0])
    d6e8d8
    				{
    d6e8d8
    					case 'mult':
    d6e8d8
    						$column_length *= $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1];
    d6e8d8
    						if ($column_length > $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2])
    d6e8d8
    						{
    d6e8d8
    							$column_type = $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3];
    d6e8d8
    						}
    d6e8d8
    						else
    d6e8d8
    						{
    d6e8d8
    							$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length);
    d6e8d8
    						}
    d6e8d8
    					break;
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    		}
    d6e8d8
    		$orig_column_type .= ':';
    d6e8d8
    	}
    d6e8d8
    	else
    d6e8d8
    	{
    d6e8d8
    		$orig_column_type = $column_data[0];
    d6e8d8
    		$column_type = $dbms_type_map[$dbms][$column_data[0]];
    d6e8d8
    	}
    d6e8d8
    d6e8d8
    	// Adjust default value if db-dependant specified
    d6e8d8
    	if (is_array($column_data[1]))
    d6e8d8
    	{
    d6e8d8
    		$column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default'];
    d6e8d8
    	}
    d6e8d8
    d6e8d8
    	$sql = '';
    d6e8d8
    	$return_array = array();
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'firebird':
    d6e8d8
    			$sql .= " {$column_type} ";
    d6e8d8
    d6e8d8
    			if (!is_null($column_data[1]))
    d6e8d8
    			{
    d6e8d8
    				$sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' ';
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$sql .= 'NOT NULL';
    d6e8d8
    d6e8d8
    			// This is a UNICODE column and thus should be given it's fair share
    d6e8d8
    			if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0]))
    d6e8d8
    			{
    d6e8d8
    				$sql .= ' COLLATE UNICODE';
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql .= " {$column_type} ";
    d6e8d8
    			$sql_default = " {$column_type} ";
    d6e8d8
    d6e8d8
    			// For adding columns we need the default definition
    d6e8d8
    			if (!is_null($column_data[1]))
    d6e8d8
    			{
    d6e8d8
    				// For hexadecimal values do not use single quotes
    d6e8d8
    				if (strpos($column_data[1], '0x') === 0)
    d6e8d8
    				{
    d6e8d8
    					$sql_default .= 'DEFAULT (' . $column_data[1] . ') ';
    d6e8d8
    				}
    d6e8d8
    				else
    d6e8d8
    				{
    d6e8d8
    					$sql_default .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') ';
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$sql .= 'NOT NULL';
    d6e8d8
    			$sql_default .= 'NOT NULL';
    d6e8d8
    d6e8d8
    			$return_array['column_type_sql_default'] = $sql_default;
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql .= " {$column_type} ";
    d6e8d8
    d6e8d8
    			// For hexadecimal values do not use single quotes
    d6e8d8
    			if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob')
    d6e8d8
    			{
    d6e8d8
    				$sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' ";
    d6e8d8
    			}
    d6e8d8
    			$sql .= 'NOT NULL';
    d6e8d8
    d6e8d8
    			if (isset($column_data[2]))
    d6e8d8
    			{
    d6e8d8
    				if ($column_data[2] == 'auto_increment')
    d6e8d8
    				{
    d6e8d8
    					$sql .= ' auto_increment';
    d6e8d8
    				}
    d6e8d8
    				else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort')
    d6e8d8
    				{
    d6e8d8
    					$sql .= ' COLLATE utf8_unicode_ci';
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'oracle':
    d6e8d8
    			$sql .= " {$column_type} ";
    d6e8d8
    			$sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : '';
    d6e8d8
    d6e8d8
    			// In Oracle empty strings ('') are treated as NULL.
    d6e8d8
    			// Therefore in oracle we allow NULL's for all DEFAULT '' entries
    d6e8d8
    			// Oracle does not like setting NOT NULL on a column that is already NOT NULL (this happens only on number fields)
    d6e8d8
    			if (preg_match('/number/i', $column_type))
    d6e8d8
    			{
    d6e8d8
    				$sql .= ($column_data[1] === '') ? '' : 'NOT NULL';
    d6e8d8
    			}
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'postgres':
    d6e8d8
    			$return_array['column_type'] = $column_type;
    d6e8d8
    d6e8d8
    			$sql .= " {$column_type} ";
    d6e8d8
    d6e8d8
    			if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
    d6e8d8
    			{
    d6e8d8
    				$default_val = "nextval('{$table_name}_seq')";
    d6e8d8
    			}
    d6e8d8
    			else if (!is_null($column_data[1]))
    d6e8d8
    			{
    d6e8d8
    				$default_val = "'" . $column_data[1] . "'";
    d6e8d8
    				$return_array['null'] = 'NOT NULL';
    d6e8d8
    				$sql .= 'NOT NULL ';
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$return_array['default'] = $default_val;
    d6e8d8
    d6e8d8
    			$sql .= "DEFAULT {$default_val}";
    d6e8d8
    d6e8d8
    			// Unsigned? Then add a CHECK contraint
    d6e8d8
    			if (in_array($orig_column_type, $unsigned_types))
    d6e8d8
    			{
    d6e8d8
    				$return_array['constraint'] = "CHECK ({$column_name} >= 0)";
    d6e8d8
    				$sql .= " CHECK ({$column_name} >= 0)";
    d6e8d8
    			}
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
    d6e8d8
    			{
    d6e8d8
    				$sql .= ' INTEGER PRIMARY KEY';
    d6e8d8
    			}
    d6e8d8
    			else
    d6e8d8
    			{
    d6e8d8
    				$sql .= ' ' . $column_type;
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$sql .= ' NOT NULL ';
    d6e8d8
    			$sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : '';
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    d6e8d8
    	$return_array['column_type_sql'] = $sql;
    d6e8d8
    d6e8d8
    	return $return_array;
    d6e8d8
    }
    d6e8d8
    d6e8d8
    /**
    d6e8d8
    * Add new column
    d6e8d8
    */
    d6e8d8
    function sql_column_add($dbms, $table_name, $column_name, $column_data)
    d6e8d8
    {
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	$column_data = prepare_column_data($dbms, $column_data, $table_name, $column_name);
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'firebird':
    d6e8d8
    			$sql = 'ALTER TABLE "' . $table_name . '" ADD "' . $column_name . '" ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = 'ALTER TABLE [' . $table_name . '] ADD [' . $column_name . '] ' . $column_data['column_type_sql_default'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = 'ALTER TABLE `' . $table_name . '` ADD COLUMN `' . $column_name . '` ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'oracle':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' ADD ' . $column_name . ' ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'postgres':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' ADD COLUMN "' . $column_name . '" ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			if (version_compare(sqlite_libversion(), '3.0') == -1)
    d6e8d8
    			{
    d6e8d8
    				global $db;
    d6e8d8
    				$sql = "SELECT sql
    d6e8d8
    					FROM sqlite_master
    d6e8d8
    					WHERE type = 'table'
    d6e8d8
    						AND name = '{$table_name}'
    d6e8d8
    					ORDER BY type DESC, name;";
    d6e8d8
    				$result = $db->sql_query($sql);
    d6e8d8
    d6e8d8
    				if (!$result)
    d6e8d8
    				{
    d6e8d8
    					break;
    d6e8d8
    				}
    d6e8d8
    d6e8d8
    				$row = $db->sql_fetchrow($result);
    d6e8d8
    				$db->sql_freeresult($result);
    d6e8d8
    d6e8d8
    				$db->sql_transaction('begin');
    d6e8d8
    d6e8d8
    				// Create a backup table and populate it, destroy the existing one
    d6e8d8
    				$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
    d6e8d8
    				$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
    d6e8d8
    				$db->sql_query('DROP TABLE ' . $table_name);
    d6e8d8
    d6e8d8
    				preg_match('#\((.*)\)#s', $row['sql'], $matches);
    d6e8d8
    d6e8d8
    				$new_table_cols = trim($matches[1]);
    d6e8d8
    				$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
    d6e8d8
    				$column_list = array();
    d6e8d8
    d6e8d8
    				foreach ($old_table_cols as $declaration)
    d6e8d8
    				{
    d6e8d8
    					$entities = preg_split('#\s+#', trim($declaration));
    d6e8d8
    					if ($entities[0] == 'PRIMARY')
    d6e8d8
    					{
    d6e8d8
    						continue;
    d6e8d8
    					}
    d6e8d8
    					$column_list[] = $entities[0];
    d6e8d8
    				}
    d6e8d8
    d6e8d8
    				$columns = implode(',', $column_list);
    d6e8d8
    d6e8d8
    				$new_table_cols = $column_name . ' ' . $column_data['column_type_sql'] . ',' . $new_table_cols;
    d6e8d8
    d6e8d8
    				// create a new table and fill it up. destroy the temp one
    d6e8d8
    				$db->sql_query('CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ');');
    d6e8d8
    				$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
    d6e8d8
    				$db->sql_query('DROP TABLE ' . $table_name . '_temp');
    d6e8d8
    d6e8d8
    				$db->sql_transaction('commit');
    d6e8d8
    			}
    d6e8d8
    			else
    d6e8d8
    			{
    d6e8d8
    				$sql = 'ALTER TABLE ' . $table_name . ' ADD ' . $column_name . ' [' . $column_data['column_type_sql'] . ']';
    d6e8d8
    				_sql($sql, $errored, $error_ary);
    d6e8d8
    			}
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    /**
    d6e8d8
    * Drop column
    d6e8d8
    */
    d6e8d8
    function sql_column_remove($dbms, $table_name, $column_name)
    d6e8d8
    {
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'firebird':
    d6e8d8
    			$sql = 'ALTER TABLE "' . $table_name . '" DROP "' . $column_name . '"';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = 'ALTER TABLE [' . $table_name . '] DROP COLUMN [' . $column_name . ']';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = 'ALTER TABLE `' . $table_name . '` DROP COLUMN `' . $column_name . '`';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'oracle':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' DROP ' . $column_name;
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'postgres':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' DROP COLUMN "' . $column_name . '"';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			if (version_compare(sqlite_libversion(), '3.0') == -1)
    d6e8d8
    			{
    d6e8d8
    				global $db;
    d6e8d8
    				$sql = "SELECT sql
    d6e8d8
    					FROM sqlite_master
    d6e8d8
    					WHERE type = 'table'
    d6e8d8
    						AND name = '{$table_name}'
    d6e8d8
    					ORDER BY type DESC, name;";
    d6e8d8
    				$result = $db->sql_query($sql);
    d6e8d8
    d6e8d8
    				if (!$result)
    d6e8d8
    				{
    d6e8d8
    					break;
    d6e8d8
    				}
    d6e8d8
    d6e8d8
    				$row = $db->sql_fetchrow($result);
    d6e8d8
    				$db->sql_freeresult($result);
    d6e8d8
    d6e8d8
    				$db->sql_transaction('begin');
    d6e8d8
    d6e8d8
    				// Create a backup table and populate it, destroy the existing one
    d6e8d8
    				$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
    d6e8d8
    				$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
    d6e8d8
    				$db->sql_query('DROP TABLE ' . $table_name);
    d6e8d8
    d6e8d8
    				preg_match('#\((.*)\)#s', $row['sql'], $matches);
    d6e8d8
    d6e8d8
    				$new_table_cols = trim($matches[1]);
    d6e8d8
    				$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
    d6e8d8
    				$column_list = array();
    d6e8d8
    d6e8d8
    				foreach ($old_table_cols as $declaration)
    d6e8d8
    				{
    d6e8d8
    					$entities = preg_split('#\s+#', trim($declaration));
    d6e8d8
    					if ($entities[0] == 'PRIMARY' || $entities[0] === $column_name)
    d6e8d8
    					{
    d6e8d8
    						continue;
    d6e8d8
    					}
    d6e8d8
    					$column_list[] = $entities[0];
    d6e8d8
    				}
    d6e8d8
    d6e8d8
    				$columns = implode(',', $column_list);
    d6e8d8
    d6e8d8
    				$new_table_cols = $new_table_cols = preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols);
    d6e8d8
    d6e8d8
    				// create a new table and fill it up. destroy the temp one
    d6e8d8
    				$db->sql_query('CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ');');
    d6e8d8
    				$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
    d6e8d8
    				$db->sql_query('DROP TABLE ' . $table_name . '_temp');
    d6e8d8
    d6e8d8
    				$db->sql_transaction('commit');
    d6e8d8
    			}
    d6e8d8
    			else
    d6e8d8
    			{
    d6e8d8
    				$sql = 'ALTER TABLE ' . $table_name . ' DROP COLUMN ' . $column_name;
    d6e8d8
    				_sql($sql, $errored, $error_ary);
    d6e8d8
    			}
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    function sql_index_drop($dbms, $index_name, $table_name)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $db;
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = 'DROP INDEX ' . $table_name . '.' . $index_name;
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = 'DROP INDEX ' . $index_name . ' ON ' . $table_name;
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'firebird':
    d6e8d8
    		case 'oracle':
    d6e8d8
    		case 'postgres':
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			$sql = 'DROP INDEX ' . $table_name . '_' . $index_name;
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    function sql_create_primary_key($dbms, $table_name, $column)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $db;
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'firebird':
    d6e8d8
    		case 'postgres':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' ADD PRIMARY KEY (' . implode(', ', $column) . ')';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = "ALTER TABLE [{$table_name}] WITH NOCHECK ADD ";
    d6e8d8
    			$sql .= "CONSTRAINT [PK_{$table_name}] PRIMARY KEY  CLUSTERED (";
    d6e8d8
    			$sql .= '[' . implode("],\n\t\t[", $column) . ']';
    d6e8d8
    			$sql .= ') ON [PRIMARY]';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' ADD PRIMARY KEY (' . implode(', ', $column) . ')';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'oracle':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . 'add CONSTRAINT pk_' . $table_name . ' PRIMARY KEY (' . implode(', ', $column) . ')';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			$sql = "SELECT sql
    d6e8d8
    				FROM sqlite_master
    d6e8d8
    				WHERE type = 'table'
    d6e8d8
    					AND name = '{$table_name}'
    d6e8d8
    				ORDER BY type DESC, name;";
    d6e8d8
    			$result = _sql($sql, $errored, $error_ary);
    d6e8d8
    d6e8d8
    			if (!$result)
    d6e8d8
    			{
    d6e8d8
    				break;
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$row = $db->sql_fetchrow($result);
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    d6e8d8
    			$db->sql_transaction('begin');
    d6e8d8
    d6e8d8
    			// Create a backup table and populate it, destroy the existing one
    d6e8d8
    			$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
    d6e8d8
    			$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
    d6e8d8
    			$db->sql_query('DROP TABLE ' . $table_name);
    d6e8d8
    d6e8d8
    			preg_match('#\((.*)\)#s', $row['sql'], $matches);
    d6e8d8
    d6e8d8
    			$new_table_cols = trim($matches[1]);
    d6e8d8
    			$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
    d6e8d8
    			$column_list = array();
    d6e8d8
    d6e8d8
    			foreach ($old_table_cols as $declaration)
    d6e8d8
    			{
    d6e8d8
    				$entities = preg_split('#\s+#', trim($declaration));
    d6e8d8
    				if ($entities[0] == 'PRIMARY')
    d6e8d8
    				{
    d6e8d8
    					continue;
    d6e8d8
    				}
    d6e8d8
    				$column_list[] = $entities[0];
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$columns = implode(',', $column_list);
    d6e8d8
    d6e8d8
    			// create a new table and fill it up. destroy the temp one
    d6e8d8
    			$db->sql_query('CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ', PRIMARY KEY (' . implode(', ', $column) . '));');
    d6e8d8
    			$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
    d6e8d8
    			$db->sql_query('DROP TABLE ' . $table_name . '_temp');
    d6e8d8
    d6e8d8
    			$db->sql_transaction('commit');
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    function sql_create_unique_index($dbms, $index_name, $table_name, $column)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $db;
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'firebird':
    d6e8d8
    		case 'postgres':
    d6e8d8
    		case 'oracle':
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			$sql = 'CREATE UNIQUE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = 'CREATE UNIQUE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = 'CREATE UNIQUE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ') ON [PRIMARY]';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    function sql_create_index($dbms, $index_name, $table_name, $column)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $db;
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'firebird':
    d6e8d8
    		case 'postgres':
    d6e8d8
    		case 'oracle':
    d6e8d8
    		case 'sqlite':
    d6e8d8
    			$sql = 'CREATE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ') ON [PRIMARY]';
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    // List all of the indices that belong to a table,
    d6e8d8
    // does not count:
    d6e8d8
    // * UNIQUE indices
    d6e8d8
    // * PRIMARY keys
    d6e8d8
    function sql_list_index($dbms, $table_name)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $db;
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	$index_array = array();
    d6e8d8
    d6e8d8
    	if ($dbms == 'mssql')
    d6e8d8
    	{
    d6e8d8
    		$sql = "EXEC sp_statistics '$table_name'";
    d6e8d8
    		$result = $db->sql_query($sql);
    d6e8d8
    		while ($row = $db->sql_fetchrow($result))
    d6e8d8
    		{
    d6e8d8
    			if ($row['TYPE'] == 3)
    d6e8d8
    			{
    d6e8d8
    				$index_array[] = $row['INDEX_NAME'];
    d6e8d8
    			}
    d6e8d8
    		}
    d6e8d8
    		$db->sql_freeresult($result);
    d6e8d8
    	}
    d6e8d8
    	else
    d6e8d8
    	{
    d6e8d8
    		switch ($dbms)
    d6e8d8
    		{
    d6e8d8
    			case 'firebird':
    d6e8d8
    				$sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
    d6e8d8
    					FROM RDB\$INDICES
    d6e8d8
    					WHERE RDB\$RELATION_NAME = " . strtoupper($table_name) . "
    d6e8d8
    						AND RDB\$UNIQUE_FLAG IS NULL
    d6e8d8
    						AND RDB\$FOREIGN_KEY IS NULL";
    d6e8d8
    				$col = 'index_name';
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'postgres':
    d6e8d8
    				$sql = "SELECT ic.relname as index_name
    d6e8d8
    					FROM pg_class bc, pg_class ic, pg_index i
    d6e8d8
    					WHERE (bc.oid = i.indrelid)
    d6e8d8
    						AND (ic.oid = i.indexrelid)
    d6e8d8
    						AND (bc.relname = '" . $table_name . "')
    d6e8d8
    						AND (i.indisunique != 't')
    d6e8d8
    						AND (i.indisprimary != 't')";
    d6e8d8
    				$col = 'index_name';
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'mysql_40':
    d6e8d8
    			case 'mysql_41':
    d6e8d8
    				$sql = 'SHOW KEYS
    d6e8d8
    					FROM ' . $table_name;
    d6e8d8
    				$col = 'Key_name';
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'oracle':
    d6e8d8
    				$sql = "SELECT index_name
    d6e8d8
    					FROM user_indexes
    d6e8d8
    					WHERE table_name = '" . $table_name . "'
    d6e8d8
    						AND generated = 'N'";
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'sqlite':
    d6e8d8
    				$sql = "PRAGMA index_info('" . $table_name . "');";
    d6e8d8
    				$col = 'name';
    d6e8d8
    			break;
    d6e8d8
    		}
    d6e8d8
    d6e8d8
    		$result = $db->sql_query($sql);
    d6e8d8
    		while ($row = $db->sql_fetchrow($result))
    d6e8d8
    		{
    d6e8d8
    			if (($dbms == 'mysql_40' || $dbms == 'mysql_41') && !$row['Non_unique'])
    d6e8d8
    			{
    d6e8d8
    				continue;
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			switch ($dbms)
    d6e8d8
    			{
    d6e8d8
    				case 'firebird':
    d6e8d8
    				case 'oracle':
    d6e8d8
    				case 'postgres':
    d6e8d8
    				case 'sqlite':
    d6e8d8
    					$row[$col] = substr($row[$col], strlen($table_name) + 1);
    d6e8d8
    				break;
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$index_array[] = $row[$col];
    d6e8d8
    		}
    d6e8d8
    		$db->sql_freeresult($result);
    d6e8d8
    	}
    d6e8d8
    d6e8d8
    	return array_map('strtolower', $index_array);
    d6e8d8
    }
    d6e8d8
    d6e8d8
    // This is totally fake, never use it
    d6e8d8
    // it exists only to mend bad update functions introduced
    d6e8d8
    // * UNIQUE indices
    d6e8d8
    // * PRIMARY keys
    d6e8d8
    function sql_list_fake($dbms, $table_name)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $db;
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	$index_array = array();
    d6e8d8
    d6e8d8
    	if ($dbms == 'mssql')
    d6e8d8
    	{
    d6e8d8
    		$sql = "EXEC sp_statistics '$table_name'";
    d6e8d8
    		$result = $db->sql_query($sql);
    d6e8d8
    		while ($row = $db->sql_fetchrow($result))
    d6e8d8
    		{
    d6e8d8
    			if ($row['TYPE'] == 3)
    d6e8d8
    			{
    d6e8d8
    				$index_array[] = $row['INDEX_NAME'];
    d6e8d8
    			}
    d6e8d8
    		}
    d6e8d8
    		$db->sql_freeresult($result);
    d6e8d8
    	}
    d6e8d8
    	else
    d6e8d8
    	{
    d6e8d8
    		switch ($dbms)
    d6e8d8
    		{
    d6e8d8
    			case 'firebird':
    d6e8d8
    				$sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
    d6e8d8
    					FROM RDB\$INDICES
    d6e8d8
    					WHERE RDB\$RELATION_NAME = " . strtoupper($table_name) . "
    d6e8d8
    						AND RDB\$UNIQUE_FLAG IS NULL
    d6e8d8
    						AND RDB\$FOREIGN_KEY IS NULL";
    d6e8d8
    				$col = 'index_name';
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'postgres':
    d6e8d8
    				$sql = "SELECT ic.relname as index_name
    d6e8d8
    					FROM pg_class bc, pg_class ic, pg_index i
    d6e8d8
    					WHERE (bc.oid = i.indrelid)
    d6e8d8
    						AND (ic.oid = i.indexrelid)
    d6e8d8
    						AND (bc.relname = '" . $table_name . "')
    d6e8d8
    						AND (i.indisunique != 't')
    d6e8d8
    						AND (i.indisprimary != 't')";
    d6e8d8
    				$col = 'index_name';
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'mysql_40':
    d6e8d8
    			case 'mysql_41':
    d6e8d8
    				$sql = 'SHOW KEYS
    d6e8d8
    					FROM ' . $table_name;
    d6e8d8
    				$col = 'Key_name';
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'oracle':
    d6e8d8
    				$sql = "SELECT index_name
    d6e8d8
    					FROM user_indexes
    d6e8d8
    					WHERE table_name = '" . $table_name . "'
    d6e8d8
    						AND generated = 'N'";
    d6e8d8
    			break;
    d6e8d8
    d6e8d8
    			case 'sqlite':
    d6e8d8
    				$sql = "PRAGMA index_info('" . $table_name . "');";
    d6e8d8
    				$col = 'name';
    d6e8d8
    			break;
    d6e8d8
    		}
    d6e8d8
    d6e8d8
    		$result = $db->sql_query($sql);
    d6e8d8
    		while ($row = $db->sql_fetchrow($result))
    d6e8d8
    		{
    d6e8d8
    			if (($dbms == 'mysql_40' || $dbms == 'mysql_41') && !$row['Non_unique'])
    d6e8d8
    			{
    d6e8d8
    				continue;
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$index_array[] = $row[$col];
    d6e8d8
    		}
    d6e8d8
    		$db->sql_freeresult($result);
    d6e8d8
    	}
    d6e8d8
    d6e8d8
    	return array_map('strtolower', $index_array);
    d6e8d8
    }
    d6e8d8
    d6e8d8
    /**
    d6e8d8
    * Change column type (not name!)
    d6e8d8
    */
    d6e8d8
    function sql_column_change($dbms, $table_name, $column_name, $column_data)
    d6e8d8
    {
    d6e8d8
    	global $dbms_type_map, $db;
    d6e8d8
    	global $errored, $error_ary;
    d6e8d8
    d6e8d8
    	$column_data = prepare_column_data($dbms, $column_data, $table_name, $column_name);
    d6e8d8
    d6e8d8
    	switch ($dbms)
    d6e8d8
    	{
    d6e8d8
    		case 'firebird':
    d6e8d8
    			// Change type...
    d6e8d8
    			$sql = 'ALTER TABLE "' . $table_name . '" ALTER COLUMN "' . $column_name . '" TYPE ' . ' ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mssql':
    d6e8d8
    			$sql = 'ALTER TABLE [' . $table_name . '] ALTER COLUMN [' . $column_name . '] ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'mysql_40':
    d6e8d8
    		case 'mysql_41':
    d6e8d8
    			$sql = 'ALTER TABLE `' . $table_name . '` CHANGE `' . $column_name . '` `' . $column_name . '` ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'oracle':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' MODIFY ' . $column_name . ' ' . $column_data['column_type_sql'];
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'postgres':
    d6e8d8
    			$sql = 'ALTER TABLE ' . $table_name . ' ';
    d6e8d8
    d6e8d8
    			$sql_array = array();
    d6e8d8
    			$sql_array[] = 'ALTER COLUMN ' . $column_name . ' TYPE ' . $column_data['column_type'];
    d6e8d8
    d6e8d8
    			if (isset($column_data['null']))
    d6e8d8
    			{
    d6e8d8
    				if ($column_data['null'] == 'NOT NULL')
    d6e8d8
    				{
    d6e8d8
    					$sql_array[] = 'ALTER COLUMN ' . $column_name . ' SET NOT NULL';
    d6e8d8
    				}
    d6e8d8
    				else if ($column_data['null'] == 'NULL')
    d6e8d8
    				{
    d6e8d8
    					$sql_array[] = 'ALTER COLUMN ' . $column_name . ' DROP NOT NULL';
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			if (isset($column_data['default']))
    d6e8d8
    			{
    d6e8d8
    				$sql_array[] = 'ALTER COLUMN ' . $column_name . ' SET DEFAULT ' . $column_data['default'];
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			// we don't want to double up on constraints if we change different number data types
    d6e8d8
    			if (isset($column_data['constraint']))
    d6e8d8
    			{
    d6e8d8
    				$constraint_sql = "SELECT consrc as constraint_data
    d6e8d8
    							FROM pg_constraint, pg_class bc
    d6e8d8
    							WHERE conrelid = bc.oid
    d6e8d8
    								AND bc.relname = '{$table_name}'
    d6e8d8
    								AND NOT EXISTS (
    d6e8d8
    									SELECT *
    d6e8d8
    										FROM pg_constraint as c, pg_inherits as i
    d6e8d8
    										WHERE i.inhrelid = pg_constraint.conrelid
    d6e8d8
    											AND c.conname = pg_constraint.conname
    d6e8d8
    											AND c.consrc = pg_constraint.consrc
    d6e8d8
    											AND c.conrelid = i.inhparent
    d6e8d8
    								)";
    d6e8d8
    d6e8d8
    				$constraint_exists = false;
    d6e8d8
    d6e8d8
    				$result = $db->sql_query($constraint_sql);
    d6e8d8
    				while ($row = $db->sql_fetchrow($result))
    d6e8d8
    				{
    d6e8d8
    					if (trim($row['constraint_data']) == trim($column_data['constraint']))
    d6e8d8
    					{
    d6e8d8
    						$constraint_exists = true;
    d6e8d8
    						break;
    d6e8d8
    					}
    d6e8d8
    				}
    d6e8d8
    				$db->sql_freeresult($result);
    d6e8d8
    d6e8d8
    				if (!$constraint_exists)
    d6e8d8
    				{
    d6e8d8
    					$sql_array[] = 'ADD ' . $column_data['constraint'];
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$sql .= implode(', ', $sql_array);
    d6e8d8
    d6e8d8
    			_sql($sql, $errored, $error_ary);
    d6e8d8
    		break;
    d6e8d8
    d6e8d8
    		case 'sqlite':
    d6e8d8
    d6e8d8
    			$sql = "SELECT sql
    d6e8d8
    				FROM sqlite_master
    d6e8d8
    				WHERE type = 'table'
    d6e8d8
    					AND name = '{$table_name}'
    d6e8d8
    				ORDER BY type DESC, name;";
    d6e8d8
    			$result = _sql($sql, $errored, $error_ary);
    d6e8d8
    d6e8d8
    			if (!$result)
    d6e8d8
    			{
    d6e8d8
    				break;
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$row = $db->sql_fetchrow($result);
    d6e8d8
    			$db->sql_freeresult($result);
    d6e8d8
    d6e8d8
    			$db->sql_transaction('begin');
    d6e8d8
    d6e8d8
    			// Create a temp table and populate it, destroy the existing one
    d6e8d8
    			$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
    d6e8d8
    			$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
    d6e8d8
    			$db->sql_query('DROP TABLE ' . $table_name);
    d6e8d8
    d6e8d8
    			preg_match('#\((.*)\)#s', $row['sql'], $matches);
    d6e8d8
    d6e8d8
    			$new_table_cols = trim($matches[1]);
    d6e8d8
    			$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
    d6e8d8
    			$column_list = array();
    d6e8d8
    d6e8d8
    			foreach ($old_table_cols as $key => $declaration)
    d6e8d8
    			{
    d6e8d8
    				$entities = preg_split('#\s+#', trim($declaration));
    d6e8d8
    				$column_list[] = $entities[0];
    d6e8d8
    				if ($entities[0] == $column_name)
    d6e8d8
    				{
    d6e8d8
    					$old_table_cols[$key] = $column_name . ' ' . $column_data['column_type_sql'];
    d6e8d8
    				}
    d6e8d8
    			}
    d6e8d8
    d6e8d8
    			$columns = implode(',', $column_list);
    d6e8d8
    d6e8d8
    			// create a new table and fill it up. destroy the temp one
    d6e8d8
    			$db->sql_query('CREATE TABLE ' . $table_name . ' (' . implode(',', $old_table_cols) . ');');
    d6e8d8
    			$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
    d6e8d8
    			$db->sql_query('DROP TABLE ' . $table_name . '_temp');
    d6e8d8
    d6e8d8
    			$db->sql_transaction('commit');
    d6e8d8
    d6e8d8
    		break;
    d6e8d8
    	}
    d6e8d8
    }
    d6e8d8
    d6e8d8
    function utf8_new_clean_string($text)
    d6e8d8
    {
    d6e8d8
    	static $homographs = array();
    d6e8d8
    	static $utf8_case_fold_nfkc = '';
    d6e8d8
    	if (empty($homographs))
    d6e8d8
    	{
    d6e8d8
    		global $phpbb_root_path, $phpEx;
    d6e8d8
    		if (!function_exists('utf8_case_fold_nfkc') || !file_exists($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx))
    d6e8d8
    		{
    d6e8d8
    			if (!file_exists($phpbb_root_path . 'install/data/confusables.' . $phpEx))
    d6e8d8
    			{
    d6e8d8
    				global $lang;
    d6e8d8
    				trigger_error(sprintf($lang['UPDATE_REQUIRES_FILE'], $phpbb_root_path . 'install/data/confusables.' . $phpEx), E_USER_ERROR);
    d6e8d8
    			}
    d6e8d8
    			$homographs = include($phpbb_root_path . 'install/data/confusables.' . $phpEx);
    d6e8d8
    			$utf8_case_fold_nfkc = 'utf8_new_case_fold_nfkc';
    d6e8d8
    		}
    d6e8d8
    		else
    d6e8d8
    		{
    d6e8d8
    			$homographs = include($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx);
    d6e8d8
    			$utf8_case_fold_nfkc = 'utf8_case_fold_nfkc';
    d6e8d8
    		}
    d6e8d8
    	}
    d6e8d8
    d6e8d8
    	$text = $utf8_case_fold_nfkc($text);
    d6e8d8
    	$text = strtr($text, $homographs);
    d6e8d8
    	// Other control characters
    d6e8d8
    	$text = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $text);
    d6e8d8
    d6e8d8
    	$text = preg_replace('# {2,}#', ' ', $text);
    d6e8d8
    d6e8d8
    	// we can use trim here as all the other space characters should have been turned
    d6e8d8
    	// into normal ASCII spaces by now
    d6e8d8
    	return trim($text);
    d6e8d8
    }
    d6e8d8
    d6e8d8
    ?>