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

d6e8d8
d6e8d8
/**
d6e8d8
*
d6e8d8
* @package install
d6e8d8
* @version $Id: install_convert.php 8814 2008-09-04 12:01:47Z acydburn $
d6e8d8
* @copyright (c) 2006 phpBB Group
d6e8d8
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
d6e8d8
*
d6e8d8
*/
d6e8d8
d6e8d8
/**
d6e8d8
*/
d6e8d8
d6e8d8
if (!defined('IN_INSTALL'))
d6e8d8
{
d6e8d8
	// Someone has tried to access the file direct. This is not a good idea, so exit
d6e8d8
	exit;
d6e8d8
}
d6e8d8
d6e8d8
if (!empty($setmodules))
d6e8d8
{
d6e8d8
	$module[] = array(
d6e8d8
		'module_type'		=> 'install',
d6e8d8
		'module_title'		=> 'CONVERT',
d6e8d8
		'module_filename'	=> substr(basename(__FILE__), 0, -strlen($phpEx)-1),
d6e8d8
		'module_order'		=> 20,
d6e8d8
		'module_subs'		=> '',
d6e8d8
		'module_stages'		=> array('INTRO', 'SETTINGS', 'IN_PROGRESS', 'FINAL'),
d6e8d8
		'module_reqs'		=> ''
d6e8d8
	);
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Class holding all convertor-specific details.
d6e8d8
* @package install
d6e8d8
*/
d6e8d8
class convert
d6e8d8
{
d6e8d8
	var $options = array();
d6e8d8
d6e8d8
	var $convertor_tag = '';
d6e8d8
	var $src_dbms = '';
d6e8d8
	var $src_dbhost = '';
d6e8d8
	var $src_dbport = '';
d6e8d8
	var $src_dbuser = '';
d6e8d8
	var $src_dbpasswd = '';
d6e8d8
	var $src_dbname = '';
d6e8d8
	var $src_table_prefix = '';
d6e8d8
d6e8d8
	var $convertor_data = array();
d6e8d8
	var $tables = array();
d6e8d8
	var $config_schema = array();
d6e8d8
	var $convertor = array();
d6e8d8
	var $src_truncate_statement = 'DELETE FROM ';
d6e8d8
	var $truncate_statement = 'DELETE FROM ';
d6e8d8
d6e8d8
	var $fulltext_search;
d6e8d8
d6e8d8
	// Batch size, can be adjusted by the conversion file
d6e8d8
	// For big boards a value of 6000 seems to be optimal
d6e8d8
	var $batch_size = 2000;
d6e8d8
	// Number of rows to be inserted at once (extended insert) if supported
d6e8d8
	// For installations having enough memory a value of 60 may be good.
d6e8d8
	var $num_wait_rows = 20;
d6e8d8
d6e8d8
	// Mysqls internal recoding engine messing up with our (better) functions? We at least support more encodings than mysql so should use it in favor.
d6e8d8
	var $mysql_convert = false;
d6e8d8
d6e8d8
	var $p_master;
d6e8d8
d6e8d8
	function convert(&$p_master)
d6e8d8
	{
d6e8d8
		$this->p_master = &$p_master;
d6e8d8
	}
d6e8d8
}
d6e8d8
d6e8d8
/**
d6e8d8
* Convert class for conversions
d6e8d8
* @package install
d6e8d8
*/
d6e8d8
class install_convert extends module
d6e8d8
{
d6e8d8
	/**
d6e8d8
	* Variables used while converting, they are accessible from the global variable $convert
d6e8d8
	*/
d6e8d8
	function install_convert(&$p_master)
d6e8d8
	{
d6e8d8
		$this->p_master = &$p_master;
d6e8d8
	}
d6e8d8
d6e8d8
	function main($mode, $sub)
d6e8d8
	{
d6e8d8
		global $lang, $template, $phpbb_root_path, $phpEx, $cache, $config, $language, $table_prefix;
d6e8d8
		global $convert;
d6e8d8
d6e8d8
		$this->tpl_name = 'install_convert';
d6e8d8
		$this->mode = $mode;
d6e8d8
d6e8d8
		$convert = new convert($this->p_master);
d6e8d8
d6e8d8
		switch ($sub)
d6e8d8
		{
d6e8d8
			case 'intro':
d6e8d8
				// Try opening config file
d6e8d8
				// @todo If phpBB is not installed, we need to do a cut-down installation here
d6e8d8
				// For now, we redirect to the installation script instead
d6e8d8
				if (@file_exists($phpbb_root_path . 'config.' . $phpEx))
d6e8d8
				{
d6e8d8
					include($phpbb_root_path . 'config.' . $phpEx);
d6e8d8
				}
d6e8d8
d6e8d8
				if (!defined('PHPBB_INSTALLED'))
d6e8d8
				{
d6e8d8
					$template->assign_vars(array(
d6e8d8
						'S_NOT_INSTALLED'		=> true,
d6e8d8
						'TITLE'					=> $lang['BOARD_NOT_INSTALLED'],
d6e8d8
						'BODY'					=> sprintf($lang['BOARD_NOT_INSTALLED_EXPLAIN'], append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=install&language=' . $language)),
d6e8d8
					));
d6e8d8
d6e8d8
					return;
d6e8d8
				}
d6e8d8
d6e8d8
				require($phpbb_root_path . 'config.' . $phpEx);
d6e8d8
				require($phpbb_root_path . 'includes/constants.' . $phpEx);
d6e8d8
				require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
d6e8d8
				require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
d6e8d8
d6e8d8
				$db = new $sql_db();
d6e8d8
				$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
d6e8d8
				unset($dbpasswd);
d6e8d8
d6e8d8
				// We need to fill the config to let internal functions correctly work
d6e8d8
				$sql = 'SELECT *
d6e8d8
					FROM ' . CONFIG_TABLE;
d6e8d8
				$result = $db->sql_query($sql);
d6e8d8
d6e8d8
				$config = array();
d6e8d8
				while ($row = $db->sql_fetchrow($result))
d6e8d8
				{
d6e8d8
					$config[$row['config_name']] = $row['config_value'];
d6e8d8
				}
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				// Detect if there is already a conversion in progress at this point and offer to resume
d6e8d8
				// It's quite possible that the user will get disconnected during a large conversion so they need to be able to resume it
d6e8d8
				$new_conversion = request_var('new_conv', 0);
d6e8d8
d6e8d8
				if ($new_conversion)
d6e8d8
				{
d6e8d8
					$config['convert_progress'] = '';
d6e8d8
					$config['convert_db_server'] = '';
d6e8d8
					$config['convert_db_user'] = '';
d6e8d8
					$db->sql_query('DELETE FROM ' . CONFIG_TABLE . "
d6e8d8
						WHERE config_name = 'convert_progress'
d6e8d8
							OR config_name = 'convert_db_server'
d6e8d8
							OR config_name = 'convert_db_user'"
d6e8d8
					);
d6e8d8
				}
d6e8d8
d6e8d8
				// Let's see if there is a conversion in the works...
d6e8d8
				$options = array();
d6e8d8
				if (!empty($config['convert_progress']) && !empty($config['convert_db_server']) && !empty($config['convert_db_user']) && !empty($config['convert_options']))
d6e8d8
				{
d6e8d8
					$options = unserialize($config['convert_progress']);
d6e8d8
					$options = array_merge($options, unserialize($config['convert_db_server']), unserialize($config['convert_db_user']), unserialize($config['convert_options']));
d6e8d8
				}
d6e8d8
d6e8d8
				// This information should have already been checked once, but do it again for safety
d6e8d8
				if (!empty($options) && !empty($options['tag']) &&
d6e8d8
					isset($options['dbms']) &&
d6e8d8
					isset($options['dbhost']) &&
d6e8d8
					isset($options['dbport']) &&
d6e8d8
					isset($options['dbuser']) &&
d6e8d8
					isset($options['dbpasswd']) &&
d6e8d8
					isset($options['dbname']) &&
d6e8d8
					isset($options['table_prefix']))
d6e8d8
				{
d6e8d8
					$this->page_title = $lang['CONTINUE_CONVERT'];
d6e8d8
d6e8d8
					$template->assign_vars(array(
d6e8d8
						'TITLE'			=> $lang['CONTINUE_CONVERT'],
d6e8d8
						'BODY'			=> $lang['CONTINUE_CONVERT_BODY'],
d6e8d8
						'L_NEW'			=> $lang['CONVERT_NEW_CONVERSION'],
d6e8d8
						'L_CONTINUE'	=> $lang['CONTINUE_OLD_CONVERSION'],
d6e8d8
						'S_CONTINUE'	=> true,
d6e8d8
d6e8d8
						'U_NEW_ACTION'		=> $this->p_master->module_url . "?mode={$this->mode}&sub=intro&new_conv=1&language=$language",
d6e8d8
						'U_CONTINUE_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag={$options['tag']}{$options['step']}&language=$language",
d6e8d8
					));
d6e8d8
d6e8d8
					return;
d6e8d8
				}
d6e8d8
d6e8d8
				$this->list_convertors($sub);
d6e8d8
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'settings':
d6e8d8
				$this->get_convert_settings($sub);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'in_progress':
d6e8d8
				$this->convert_data($sub);
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'final':
d6e8d8
				$this->page_title = $lang['CONVERT_COMPLETE'];
d6e8d8
d6e8d8
				$template->assign_vars(array(
d6e8d8
					'TITLE'		=> $lang['CONVERT_COMPLETE'],
d6e8d8
					'BODY'		=> $lang['CONVERT_COMPLETE_EXPLAIN'],
d6e8d8
				));
d6e8d8
d6e8d8
				// If we reached this step (conversion completed) we want to purge the cache and log the user out.
d6e8d8
				// This is for making sure the session get not screwed due to the 3.0.x users table being completely new.
d6e8d8
				$cache->purge();
d6e8d8
d6e8d8
				require($phpbb_root_path . 'config.' . $phpEx);
d6e8d8
				require($phpbb_root_path . 'includes/constants.' . $phpEx);
d6e8d8
				require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
d6e8d8
				require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
d6e8d8
d6e8d8
				$db = new $sql_db();
d6e8d8
				$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
d6e8d8
				unset($dbpasswd);
d6e8d8
d6e8d8
				$sql = 'SELECT config_value
d6e8d8
					FROM ' . CONFIG_TABLE . '
d6e8d8
					WHERE config_name = \'search_type\'';
d6e8d8
				$result = $db->sql_query($sql);
d6e8d8
d6e8d8
				if ($db->sql_fetchfield('config_value') != 'fulltext_mysql')
d6e8d8
				{
d6e8d8
					$template->assign_vars(array(
d6e8d8
						'S_ERROR_BOX'	=> true,
d6e8d8
						'ERROR_TITLE'	=> $lang['SEARCH_INDEX_UNCONVERTED'],
d6e8d8
						'ERROR_MSG'		=> $lang['SEARCH_INDEX_UNCONVERTED_EXPLAIN'],
d6e8d8
					));
d6e8d8
				}
d6e8d8
d6e8d8
				switch ($db->sql_layer)
d6e8d8
				{
d6e8d8
					case 'sqlite':
d6e8d8
					case 'firebird':
d6e8d8
						$db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE);
d6e8d8
						$db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
d6e8d8
					break;
d6e8d8
d6e8d8
					default:
d6e8d8
						$db->sql_query('TRUNCATE TABLE ' . SESSIONS_KEYS_TABLE);
d6e8d8
						$db->sql_query('TRUNCATE TABLE ' . SESSIONS_TABLE);
d6e8d8
					break;
d6e8d8
				}
d6e8d8
d6e8d8
			break;
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Generate a list of all available conversion modules
d6e8d8
	*/
d6e8d8
	function list_convertors($sub)
d6e8d8
	{
d6e8d8
		global $lang, $language, $template, $phpbb_root_path, $phpEx;
d6e8d8
d6e8d8
		$this->page_title = $lang['SUB_INTRO'];
d6e8d8
d6e8d8
		$template->assign_vars(array(
d6e8d8
			'TITLE'		=> $lang['CONVERT_INTRO'],
d6e8d8
			'BODY'		=> $lang['CONVERT_INTRO_BODY'],
d6e8d8
d6e8d8
			'L_AUTHOR'					=> $lang['AUTHOR'],
d6e8d8
			'L_AVAILABLE_CONVERTORS'	=> $lang['AVAILABLE_CONVERTORS'],
d6e8d8
			'L_CONVERT'					=> $lang['CONVERT'],
d6e8d8
			'L_NO_CONVERTORS'			=> $lang['NO_CONVERTORS'],
d6e8d8
			'L_OPTIONS'					=> $lang['CONVERT_OPTIONS'],
d6e8d8
			'L_SOFTWARE'				=> $lang['SOFTWARE'],
d6e8d8
			'L_VERSION'					=> $lang['VERSION'],
d6e8d8
d6e8d8
			'S_LIST'	=> true,
d6e8d8
		));
d6e8d8
d6e8d8
		$convertors = $sort = array();
d6e8d8
		$get_info = true;
d6e8d8
d6e8d8
		$handle = @opendir('./convertors/');
d6e8d8
d6e8d8
		if (!$handle)
d6e8d8
		{
d6e8d8
			$this->error('Unable to access the convertors directory', __LINE__, __FILE__);
d6e8d8
		}
d6e8d8
d6e8d8
		while ($entry = readdir($handle))
d6e8d8
		{
d6e8d8
			if (preg_match('/^convert_([a-z0-9_]+).' . $phpEx . '$/i', $entry, $m))
d6e8d8
			{
d6e8d8
				include('./convertors/' . $entry);
d6e8d8
				if (isset($convertor_data))
d6e8d8
				{
d6e8d8
					$sort[strtolower($convertor_data['forum_name'])] = sizeof($convertors);
d6e8d8
d6e8d8
					$convertors[] = array(
d6e8d8
						'tag'			=>	$m[1],
d6e8d8
						'forum_name'	=>	$convertor_data['forum_name'],
d6e8d8
						'version'		=>	$convertor_data['version'],
d6e8d8
						'dbms'			=>	$convertor_data['dbms'],
d6e8d8
						'dbhost'		=>	$convertor_data['dbhost'],
d6e8d8
						'dbport'		=>	$convertor_data['dbport'],
d6e8d8
						'dbuser'		=>	$convertor_data['dbuser'],
d6e8d8
						'dbpasswd'		=>	$convertor_data['dbpasswd'],
d6e8d8
						'dbname'		=>	$convertor_data['dbname'],
d6e8d8
						'table_prefix'	=>	$convertor_data['table_prefix'],
d6e8d8
						'author'		=>	$convertor_data['author']
d6e8d8
					);
d6e8d8
				}
d6e8d8
				unset($convertor_data);
d6e8d8
			}
d6e8d8
		}
d6e8d8
		closedir($handle);
d6e8d8
d6e8d8
		@ksort($sort);
d6e8d8
d6e8d8
		foreach ($sort as $void => $index)
d6e8d8
		{
d6e8d8
			$template->assign_block_vars('convertors', array(
d6e8d8
				'AUTHOR'	=> $convertors[$index]['author'],
d6e8d8
				'SOFTWARE'	=> $convertors[$index]['forum_name'],
d6e8d8
				'VERSION'	=> $convertors[$index]['version'],
d6e8d8
d6e8d8
				'U_CONVERT'	=> $this->p_master->module_url . "?mode={$this->mode}&language=$language&sub=settings&tag=" . $convertors[$index]['tag'],
d6e8d8
			));
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	*/
d6e8d8
	function get_convert_settings($sub)
d6e8d8
	{
d6e8d8
		global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache;
d6e8d8
d6e8d8
		require($phpbb_root_path . 'config.' . $phpEx);
d6e8d8
		require($phpbb_root_path . 'includes/constants.' . $phpEx);
d6e8d8
		require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
d6e8d8
		require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
d6e8d8
d6e8d8
		$db = new $sql_db();
d6e8d8
		$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
d6e8d8
		unset($dbpasswd);
d6e8d8
d6e8d8
		$this->page_title = $lang['STAGE_SETTINGS'];
d6e8d8
d6e8d8
		// We need to fill the config to let internal functions correctly work
d6e8d8
		$sql = 'SELECT *
d6e8d8
			FROM ' . CONFIG_TABLE;
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
d6e8d8
		$config = array();
d6e8d8
		while ($row = $db->sql_fetchrow($result))
d6e8d8
		{
d6e8d8
			$config[$row['config_name']] = $row['config_value'];
d6e8d8
		}
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		$convertor_tag = request_var('tag', '');
d6e8d8
d6e8d8
		if (empty($convertor_tag))
d6e8d8
		{
d6e8d8
			$this->p_master->error($lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__);
d6e8d8
		}
d6e8d8
		$get_info = true;
d6e8d8
d6e8d8
		// check security implications of direct inclusion
d6e8d8
		$convertor_tag = basename($convertor_tag);
d6e8d8
		if (!file_exists('./convertors/convert_' . $convertor_tag . '.' . $phpEx))
d6e8d8
		{
d6e8d8
			$this->p_master->error($lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__);
d6e8d8
		}
d6e8d8
d6e8d8
		include('./convertors/convert_' . $convertor_tag . '.' . $phpEx);
d6e8d8
d6e8d8
		// The test_file is a file that should be present in the location of the old board.
d6e8d8
		if (!isset($test_file))
d6e8d8
		{
d6e8d8
			$this->p_master->error($lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
d6e8d8
		}
d6e8d8
d6e8d8
		$submit = (isset($_POST['submit'])) ? true : false;
d6e8d8
d6e8d8
		$src_dbms			= request_var('src_dbms', $convertor_data['dbms']);
d6e8d8
		$src_dbhost			= request_var('src_dbhost', $convertor_data['dbhost']);
d6e8d8
		$src_dbport			= request_var('src_dbport', $convertor_data['dbport']);
d6e8d8
		$src_dbuser			= request_var('src_dbuser', $convertor_data['dbuser']);
d6e8d8
		$src_dbpasswd		= request_var('src_dbpasswd', $convertor_data['dbpasswd']);
d6e8d8
		$src_dbname			= request_var('src_dbname', $convertor_data['dbname']);
d6e8d8
		$src_table_prefix	= request_var('src_table_prefix', $convertor_data['table_prefix']);
d6e8d8
		$forum_path			= request_var('forum_path', $convertor_data['forum_path']);
d6e8d8
		$refresh			= request_var('refresh', 1);
d6e8d8
d6e8d8
		// Default URL of the old board
d6e8d8
		// @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
d6e8d8
		//		-> We should convert old urls to the new relative urls format
d6e8d8
		// $src_url = request_var('src_url', 'Not in use at the moment');
d6e8d8
d6e8d8
		// strip trailing slash from old forum path
d6e8d8
		$forum_path = (strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/') ? substr($forum_path, 0, -1) : $forum_path;
d6e8d8
d6e8d8
		$error = array();
d6e8d8
		if ($submit)
d6e8d8
		{
d6e8d8
			if (!@file_exists('./../' . $forum_path . '/' . $test_file))
d6e8d8
			{
d6e8d8
				$error[] = sprintf($lang['COULD_NOT_FIND_PATH'], $forum_path);
d6e8d8
			}
d6e8d8
d6e8d8
			$connect_test = false;
d6e8d8
			$available_dbms = get_available_dbms(false, true, true);
d6e8d8
d6e8d8
			if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE'])
d6e8d8
			{
d6e8d8
				$error['db'][] = $lang['INST_ERR_NO_DB'];
d6e8d8
				$connect_test = false;
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{
d6e8d8
				$connect_test = connect_check_db(true, $error, $available_dbms[$src_dbms], $src_table_prefix, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, true, ($src_dbms == $dbms) ? false : true, false);
d6e8d8
			}
d6e8d8
d6e8d8
			// The forum prefix of the old and the new forum can only be the same if two different databases are used.
d6e8d8
			if ($src_table_prefix == $table_prefix && $src_dbms == $dbms && $src_dbhost == $dbhost && $src_dbport == $dbport && $src_dbname == $dbname)
d6e8d8
			{
d6e8d8
				$error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix);
d6e8d8
			}
d6e8d8
d6e8d8
			// Check table prefix
d6e8d8
			if (!sizeof($error))
d6e8d8
			{
d6e8d8
				// initiate database connection to old db if old and new db differ
d6e8d8
				global $src_db, $same_db;
d6e8d8
				$src_db = $same_db = false;
d6e8d8
d6e8d8
				if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser)
d6e8d8
				{
d6e8d8
					$sql_db = 'dbal_' . $src_dbms;
d6e8d8
					$src_db = new $sql_db();
d6e8d8
					$src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
d6e8d8
					$same_db = false;
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					$src_db = $db;
d6e8d8
					$same_db = true;
d6e8d8
				}
d6e8d8
d6e8d8
				$src_db->sql_return_on_error(true);
d6e8d8
				$db->sql_return_on_error(true);
d6e8d8
d6e8d8
				// Try to select one row from the first table to see if the prefix is OK
d6e8d8
				$result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
d6e8d8
d6e8d8
				if (!$result)
d6e8d8
				{
d6e8d8
					$prefixes = array();
d6e8d8
d6e8d8
					$tables_existing = get_tables($src_db);
d6e8d8
					$tables_existing = array_map('strtolower', $tables_existing);
d6e8d8
					foreach ($tables_existing as $table_name)
d6e8d8
					{
d6e8d8
						compare_table($tables, $table_name, $prefixes);
d6e8d8
					}
d6e8d8
					unset($tables_existing);
d6e8d8
d6e8d8
					foreach ($prefixes as $prefix => $count)
d6e8d8
					{
d6e8d8
						if ($count >= sizeof($tables))
d6e8d8
						{
d6e8d8
							$possible_prefix = $prefix;
d6e8d8
							break;
d6e8d8
						}
d6e8d8
					}
d6e8d8
d6e8d8
					$msg = '';
d6e8d8
					if (!empty($convertor_data['table_prefix']))
d6e8d8
					{
d6e8d8
						$msg .= sprintf($lang['DEFAULT_PREFIX_IS'], $convertor_data['forum_name'], $convertor_data['table_prefix']);
d6e8d8
					}
d6e8d8
d6e8d8
					if (!empty($possible_prefix))
d6e8d8
					{
d6e8d8
						$msg .= '
';
d6e8d8
						$msg .= ($possible_prefix == '*') ? $lang['BLANK_PREFIX_FOUND'] : sprintf($lang['PREFIX_FOUND'], $possible_prefix);
d6e8d8
						$src_table_prefix = ($possible_prefix == '*') ? '' : $possible_prefix;
d6e8d8
					}
d6e8d8
d6e8d8
					$error[] = $msg;
d6e8d8
				}
d6e8d8
				$src_db->sql_freeresult($result);
d6e8d8
				$src_db->sql_return_on_error(false);
d6e8d8
			}
d6e8d8
d6e8d8
			if (!sizeof($error))
d6e8d8
			{
d6e8d8
				// Save convertor Status
d6e8d8
				set_config('convert_progress', serialize(array(
d6e8d8
					'step'			=> '',
d6e8d8
					'table_prefix'	=> $src_table_prefix,
d6e8d8
					'tag'			=> $convertor_tag,
d6e8d8
				)), true);
d6e8d8
				set_config('convert_db_server', serialize(array(
d6e8d8
					'dbms'			=> $src_dbms,
d6e8d8
					'dbhost'		=> $src_dbhost,
d6e8d8
					'dbport'		=> $src_dbport,
d6e8d8
					'dbname'		=> $src_dbname,
d6e8d8
				)), true);
d6e8d8
				set_config('convert_db_user', serialize(array(
d6e8d8
					'dbuser'		=> $src_dbuser,
d6e8d8
					'dbpasswd'		=> $src_dbpasswd,
d6e8d8
				)), true);
d6e8d8
d6e8d8
				// Save options
d6e8d8
				set_config('convert_options', serialize(array('forum_path' => './../' . $forum_path, 'refresh' => $refresh)), true);
d6e8d8
d6e8d8
				$template->assign_block_vars('checks', array(
d6e8d8
					'TITLE'		=> $lang['VERIFY_OPTIONS'],
d6e8d8
					'RESULT'	=> $lang['CONVERT_SETTINGS_VERIFIED'],
d6e8d8
				));
d6e8d8
d6e8d8
				$template->assign_vars(array(
d6e8d8
					'L_SUBMIT'	=> $lang['BEGIN_CONVERT'],
d6e8d8
//					'S_HIDDEN'	=> $s_hidden_fields,
d6e8d8
					'U_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag=$convertor_tag&language=$language",
d6e8d8
				));
d6e8d8
d6e8d8
				return;
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{
d6e8d8
				$template->assign_block_vars('checks', array(
d6e8d8
					'TITLE'		=> $lang['VERIFY_OPTIONS'],
d6e8d8
					'RESULT'	=> '' . implode('
', $error) . '
',
d6e8d8
				));
d6e8d8
			}
d6e8d8
		} // end submit
d6e8d8
d6e8d8
		foreach ($this->convert_options as $config_key => $vars)
d6e8d8
		{
d6e8d8
			if (!is_array($vars) && strpos($config_key, 'legend') === false)
d6e8d8
			{
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			if (strpos($config_key, 'legend') !== false)
d6e8d8
			{
d6e8d8
				$template->assign_block_vars('options', array(
d6e8d8
					'S_LEGEND'		=> true,
d6e8d8
					'LEGEND'		=> $lang[$vars])
d6e8d8
				);
d6e8d8
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			$options = isset($vars['options']) ? $vars['options'] : '';
d6e8d8
d6e8d8
			$template->assign_block_vars('options', array(
d6e8d8
				'KEY'			=> $config_key,
d6e8d8
				'TITLE'			=> $lang[$vars['lang']],
d6e8d8
				'S_EXPLAIN'		=> $vars['explain'],
d6e8d8
				'S_LEGEND'		=> false,
d6e8d8
				'TITLE_EXPLAIN'	=> ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
d6e8d8
				'CONTENT'		=> $this->p_master->input_field($config_key, $vars['type'], $$config_key, $options),
d6e8d8
				)
d6e8d8
			);
d6e8d8
		}
d6e8d8
d6e8d8
		$template->assign_vars(array(
d6e8d8
			'TITLE'		=> $lang['STAGE_SETTINGS'],
d6e8d8
			'BODY'		=> $lang['CONV_OPTIONS_BODY'],
d6e8d8
			'L_SUBMIT'	=> $lang['BEGIN_CONVERT'],
d6e8d8
			'U_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&sub=settings&tag=$convertor_tag&language=$language",
d6e8d8
		));
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* The function which does the actual work (or dispatches it to the relevant places)
d6e8d8
	*/
d6e8d8
	function convert_data($sub)
d6e8d8
	{
d6e8d8
		global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache;
d6e8d8
		global $convert, $convert_row, $message_parser, $skip_rows, $language;
d6e8d8
d6e8d8
		require($phpbb_root_path . 'config.' . $phpEx);
d6e8d8
		require($phpbb_root_path . 'includes/constants.' . $phpEx);
d6e8d8
		require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
d6e8d8
		require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
d6e8d8
d6e8d8
		$db = new $sql_db();
d6e8d8
		$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
d6e8d8
		unset($dbpasswd);
d6e8d8
d6e8d8
		$sql = 'SELECT *
d6e8d8
			FROM ' . CONFIG_TABLE;
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
d6e8d8
		$config = array();
d6e8d8
		while ($row = $db->sql_fetchrow($result))
d6e8d8
		{
d6e8d8
			$config[$row['config_name']] = $row['config_value'];
d6e8d8
		}
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		// Override a couple of config variables for the duration
d6e8d8
		$config['max_quote_depth'] = 0;
d6e8d8
d6e8d8
		// @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues
d6e8d8
		$config['max_post_chars'] = 0;
d6e8d8
d6e8d8
		// Set up a user as well. We _should_ have enough of a database here at this point to do this
d6e8d8
		// and it helps for any core code we call
d6e8d8
		$user->session_begin();
d6e8d8
		$user->page = $user->extract_current_page($phpbb_root_path);
d6e8d8
d6e8d8
		// This is a little bit of a fudge, but it allows the language entries to be available to the
d6e8d8
		// core code without us loading them again
d6e8d8
		$user->lang = &$lang;
d6e8d8
d6e8d8
		$this->page_title = $user->lang['STAGE_IN_PROGRESS'];
d6e8d8
d6e8d8
		$convert->options = array();
d6e8d8
		if (isset($config['convert_progress']))
d6e8d8
		{
d6e8d8
			$convert->options = unserialize($config['convert_progress']);
d6e8d8
			$convert->options = array_merge($convert->options, unserialize($config['convert_db_server']), unserialize($config['convert_db_user']), unserialize($config['convert_options']));
d6e8d8
		}
d6e8d8
d6e8d8
		// This information should have already been checked once, but do it again for safety
d6e8d8
		if (empty($convert->options) || empty($convert->options['tag']) ||
d6e8d8
			!isset($convert->options['dbms']) ||
d6e8d8
			!isset($convert->options['dbhost']) ||
d6e8d8
			!isset($convert->options['dbport']) ||
d6e8d8
			!isset($convert->options['dbuser']) ||
d6e8d8
			!isset($convert->options['dbpasswd']) ||
d6e8d8
			!isset($convert->options['dbname']) ||
d6e8d8
			!isset($convert->options['table_prefix']))
d6e8d8
		{
d6e8d8
			$this->p_master->error($user->lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__);
d6e8d8
		}
d6e8d8
d6e8d8
		// Make some short variables accessible, for easier referencing
d6e8d8
		$convert->convertor_tag = basename($convert->options['tag']);
d6e8d8
		$convert->src_dbms = $convert->options['dbms'];
d6e8d8
		$convert->src_dbhost = $convert->options['dbhost'];
d6e8d8
		$convert->src_dbport = $convert->options['dbport'];
d6e8d8
		$convert->src_dbuser = $convert->options['dbuser'];
d6e8d8
		$convert->src_dbpasswd = $convert->options['dbpasswd'];
d6e8d8
		$convert->src_dbname = $convert->options['dbname'];
d6e8d8
		$convert->src_table_prefix = $convert->options['table_prefix'];
d6e8d8
d6e8d8
		// initiate database connection to old db if old and new db differ
d6e8d8
		global $src_db, $same_db;
d6e8d8
		$src_db = $same_db = null;
d6e8d8
		if ($convert->src_dbms != $dbms || $convert->src_dbhost != $dbhost || $convert->src_dbport != $dbport || $convert->src_dbname != $dbname || $convert->src_dbuser != $dbuser)
d6e8d8
		{
d6e8d8
			if ($convert->src_dbms != $dbms)
d6e8d8
			{
d6e8d8
				require($phpbb_root_path . 'includes/db/' . $convert->src_dbms . '.' . $phpEx);
d6e8d8
			}
d6e8d8
			$sql_db = 'dbal_' . $convert->src_dbms;
d6e8d8
			$src_db = new $sql_db();
d6e8d8
			$src_db->sql_connect($convert->src_dbhost, $convert->src_dbuser, htmlspecialchars_decode($convert->src_dbpasswd), $convert->src_dbname, $convert->src_dbport, false, true);
d6e8d8
			$same_db = false;
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			$src_db = $db;
d6e8d8
			$same_db = true;
d6e8d8
		}
d6e8d8
d6e8d8
		$convert->mysql_convert = false;
d6e8d8
		switch ($src_db->sql_layer)
d6e8d8
		{
d6e8d8
			case 'sqlite':
d6e8d8
			case 'firebird':
d6e8d8
				$convert->src_truncate_statement = 'DELETE FROM ';
d6e8d8
			break;
d6e8d8
d6e8d8
			// Thanks MySQL, for silently converting...
d6e8d8
			case 'mysql':
d6e8d8
			case 'mysql4':
d6e8d8
				if (version_compare($src_db->sql_server_info(true), '4.1.3', '>='))
d6e8d8
				{
d6e8d8
					$convert->mysql_convert = true;
d6e8d8
				}
d6e8d8
				$convert->src_truncate_statement = 'TRUNCATE TABLE ';
d6e8d8
			break;
d6e8d8
d6e8d8
			case 'mysqli':
d6e8d8
				$convert->mysql_convert = true;
d6e8d8
				$convert->src_truncate_statement = 'TRUNCATE TABLE ';
d6e8d8
			break;
d6e8d8
d6e8d8
			default:
d6e8d8
				$convert->src_truncate_statement = 'TRUNCATE TABLE ';
d6e8d8
			break;
d6e8d8
		}
d6e8d8
d6e8d8
		if ($convert->mysql_convert && !$same_db)
d6e8d8
		{
d6e8d8
			$src_db->sql_query("SET NAMES 'binary'");
d6e8d8
		}
d6e8d8
d6e8d8
		switch ($db->sql_layer)
d6e8d8
		{
d6e8d8
			case 'sqlite':
d6e8d8
			case 'firebird':
d6e8d8
				$convert->truncate_statement = 'DELETE FROM ';
d6e8d8
			break;
d6e8d8
d6e8d8
			default:
d6e8d8
				$convert->truncate_statement = 'TRUNCATE TABLE ';
d6e8d8
			break;
d6e8d8
		}
d6e8d8
d6e8d8
		$get_info = false;
d6e8d8
d6e8d8
		// check security implications of direct inclusion
d6e8d8
		if (!file_exists('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx))
d6e8d8
		{
d6e8d8
			$this->p_master->error($user->lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__);
d6e8d8
		}
d6e8d8
d6e8d8
		if (file_exists('./convertors/functions_' . $convert->convertor_tag . '.' . $phpEx))
d6e8d8
		{
d6e8d8
			include('./convertors/functions_' . $convert->convertor_tag . '.' . $phpEx);
d6e8d8
		}
d6e8d8
d6e8d8
		$get_info = true;
d6e8d8
		include('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx);
d6e8d8
d6e8d8
		// Map some variables...
d6e8d8
		$convert->convertor_data = $convertor_data;
d6e8d8
		$convert->tables = $tables;
d6e8d8
		$convert->config_schema = $config_schema;
d6e8d8
d6e8d8
		// Now include the real data
d6e8d8
		$get_info = false;
d6e8d8
		include('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx);
d6e8d8
d6e8d8
		$convert->convertor_data = $convertor_data;
d6e8d8
		$convert->tables = $tables;
d6e8d8
		$convert->config_schema = $config_schema;
d6e8d8
		$convert->convertor = $convertor;
d6e8d8
d6e8d8
		// The test_file is a file that should be present in the location of the old board.
d6e8d8
		if (!file_exists($convert->options['forum_path'] . '/' . $test_file))
d6e8d8
		{
d6e8d8
			$this->p_master->error(sprintf($user->lang['COULD_NOT_FIND_PATH'], $convert->options['forum_path']), __LINE__, __FILE__);
d6e8d8
		}
d6e8d8
d6e8d8
		$search_type = basename(trim($config['search_type']));
d6e8d8
d6e8d8
		// For conversions we are a bit less strict and set to a search backend we know exist...
d6e8d8
		if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
d6e8d8
		{
d6e8d8
			$search_type = 'fulltext_native';
d6e8d8
			set_config('search_type', $search_type);
d6e8d8
		}
d6e8d8
d6e8d8
		if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
d6e8d8
		{
d6e8d8
			trigger_error('NO_SUCH_SEARCH_MODULE');
d6e8d8
		}
d6e8d8
d6e8d8
		require($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx);
d6e8d8
d6e8d8
		$error = false;
d6e8d8
		$convert->fulltext_search = new $search_type($error);
d6e8d8
d6e8d8
		if ($error)
d6e8d8
		{
d6e8d8
			trigger_error($error);
d6e8d8
		}
d6e8d8
d6e8d8
		include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
d6e8d8
		$message_parser = new parse_message();
d6e8d8
d6e8d8
		$jump = request_var('jump', 0);
d6e8d8
		$final_jump = request_var('final_jump', 0);
d6e8d8
		$sync_batch = request_var('sync_batch', -1);
d6e8d8
		$last_statement = request_var('last', 0);
d6e8d8
d6e8d8
		// We are running sync...
d6e8d8
		if ($sync_batch >= 0)
d6e8d8
		{
d6e8d8
			$this->sync_forums($sync_batch);
d6e8d8
			return;
d6e8d8
		}
d6e8d8
d6e8d8
		if ($jump)
d6e8d8
		{
d6e8d8
			$this->jump($jump, $last_statement);
d6e8d8
			return;
d6e8d8
		}
d6e8d8
d6e8d8
		if ($final_jump)
d6e8d8
		{
d6e8d8
			$this->final_jump($final_jump);
d6e8d8
			return;
d6e8d8
		}
d6e8d8
d6e8d8
		$current_table = request_var('current_table', 0);
d6e8d8
		$old_current_table = min(-1, $current_table - 1);
d6e8d8
		$skip_rows = request_var('skip_rows', 0);
d6e8d8
d6e8d8
		if (!$current_table && !$skip_rows)
d6e8d8
		{
d6e8d8
			if (empty($_REQUEST['confirm']))
d6e8d8
			{
d6e8d8
				// If avatars / ranks / smilies folders are specified make sure they are writable
d6e8d8
				$bad_folders = array();
d6e8d8
d6e8d8
				$local_paths = array(
d6e8d8
					'avatar_path'			=> path($config['avatar_path']),
d6e8d8
					'avatar_gallery_path'	=> path($config['avatar_gallery_path']),
d6e8d8
					'icons_path'			=> path($config['icons_path']),
d6e8d8
					'ranks_path'			=> path($config['ranks_path']),
d6e8d8
					'smilies_path'			=> path($config['smilies_path'])
d6e8d8
				);
d6e8d8
d6e8d8
				foreach ($local_paths as $folder => $local_path)
d6e8d8
				{
d6e8d8
					if (isset($convert->convertor[$folder]))
d6e8d8
					{
d6e8d8
						if (empty($convert->convertor['test_file']))
d6e8d8
						{
d6e8d8
							// test_file is mandantory at the moment so this should never be reached, but just in case...
d6e8d8
							$this->p_master->error($user->lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
d6e8d8
						}
d6e8d8
d6e8d8
						if (!$local_path || !@is_writable($phpbb_root_path . $local_path))
d6e8d8
						{
d6e8d8
							if (!$local_path)
d6e8d8
							{
d6e8d8
								$bad_folders[] = sprintf($user->lang['CONFIG_PHPBB_EMPTY'], $folder);
d6e8d8
							}
d6e8d8
							else
d6e8d8
							{
d6e8d8
								$bad_folders[] = $local_path;
d6e8d8
							}
d6e8d8
						}
d6e8d8
					}
d6e8d8
				}
d6e8d8
d6e8d8
				if (sizeof($bad_folders))
d6e8d8
				{
d6e8d8
					$msg = (sizeof($bad_folders) == 1) ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE'];
d6e8d8
					sort($bad_folders);
d6e8d8
					$this->p_master->error(sprintf($msg, implode('
', $bad_folders)), __LINE__, __FILE__, true);
d6e8d8
d6e8d8
					$template->assign_vars(array(
d6e8d8
						'L_SUBMIT'	=> $user->lang['INSTALL_TEST'],
d6e8d8
						'U_ACTION'	=> $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag={$convert->convertor_tag}&language=$language",
d6e8d8
					));
d6e8d8
					return;
d6e8d8
				}
d6e8d8
d6e8d8
				// Grab all the tables used in convertor
d6e8d8
				$missing_tables = $tables_list = $aliases = array();
d6e8d8
d6e8d8
				foreach ($convert->convertor['schema'] as $schema)
d6e8d8
				{
d6e8d8
					// Skip those not used (because of addons/plugins not detected)
d6e8d8
					if (!$schema['target'])
d6e8d8
					{
d6e8d8
						continue;
d6e8d8
					}
d6e8d8
d6e8d8
					foreach ($schema as $key => $val)
d6e8d8
					{
d6e8d8
						// we're dealing with an array like:
d6e8d8
						// array('forum_status',			'forums.forum_status',				'is_item_locked')
d6e8d8
						if (is_int($key) && !empty($val[1]))
d6e8d8
						{
d6e8d8
							$temp_data = $val[1];
d6e8d8
							if (!is_array($temp_data))
d6e8d8
							{
d6e8d8
								$temp_data = array($temp_data);
d6e8d8
							}
d6e8d8
d6e8d8
							foreach ($temp_data as $val)
d6e8d8
							{
d6e8d8
								if (preg_match('/([a-z0-9_]+)\.([a-z0-9_]+)\)* ?A?S? ?([a-z0-9_]*?)\.?([a-z0-9_]*)$/i', $val, $m))
d6e8d8
								{
d6e8d8
									$table = $convert->src_table_prefix . $m[1];
d6e8d8
									$tables_list[$table] = $table;
d6e8d8
d6e8d8
									if (!empty($m[3]))
d6e8d8
									{
d6e8d8
										$aliases[] = $convert->src_table_prefix . $m[3];
d6e8d8
									}
d6e8d8
								}
d6e8d8
							}
d6e8d8
						}
d6e8d8
						// 'left_join'		=> 'topics LEFT JOIN vote_desc ON topics.topic_id = vote_desc.topic_id AND topics.topic_vote = 1'
d6e8d8
						else if ($key == 'left_join')
d6e8d8
						{
d6e8d8
							// Convert the value if it wasn't an array already.
d6e8d8
							if (!is_array($val))
d6e8d8
							{
d6e8d8
								$val = array($val);
d6e8d8
							}
d6e8d8
d6e8d8
							for ($j = 0; $j < sizeof($val); ++$j)
d6e8d8
							{
d6e8d8
								if (preg_match('/LEFT JOIN ([a-z0-9_]+) AS ([a-z0-9_]+)/i', $val[$j], $m))
d6e8d8
								{
d6e8d8
									$table = $convert->src_table_prefix . $m[1];
d6e8d8
									$tables_list[$table] = $table;
d6e8d8
d6e8d8
									if (!empty($m[2]))
d6e8d8
									{
d6e8d8
										$aliases[] = $convert->src_table_prefix . $m[2];
d6e8d8
									}
d6e8d8
								}
d6e8d8
							}
d6e8d8
						}
d6e8d8
					}
d6e8d8
				}
d6e8d8
d6e8d8
				// Remove aliased tables from $tables_list
d6e8d8
				foreach ($aliases as $alias)
d6e8d8
				{
d6e8d8
					unset($tables_list[$alias]);
d6e8d8
				}
d6e8d8
d6e8d8
				// Check if the tables that we need exist
d6e8d8
				$src_db->sql_return_on_error(true);
d6e8d8
				foreach ($tables_list as $table => $null)
d6e8d8
				{
d6e8d8
					$sql = 'SELECT 1 FROM ' . $table;
d6e8d8
					$_result = $src_db->sql_query_limit($sql, 1);
d6e8d8
d6e8d8
					if (!$_result)
d6e8d8
					{
d6e8d8
						$missing_tables[] = $table;
d6e8d8
					}
d6e8d8
					$src_db->sql_freeresult($_result);
d6e8d8
				}
d6e8d8
				$src_db->sql_return_on_error(false);
d6e8d8
d6e8d8
				// Throw an error if some tables are missing
d6e8d8
				// We used to do some guessing here, but since we have a suggestion of possible values earlier, I don't see it adding anything here to do it again
d6e8d8
d6e8d8
				if (sizeof($missing_tables) == sizeof($tables_list))
d6e8d8
				{
d6e8d8
					$this->p_master->error($user->lang['NO_TABLES_FOUND'] . ' ' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__);
d6e8d8
				}
d6e8d8
				else if (sizeof($missing_tables))
d6e8d8
				{
d6e8d8
					$this->p_master->error(sprintf($user->lang['TABLES_MISSING'], implode(', ', $missing_tables)) . '

' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__);
d6e8d8
				}
d6e8d8
d6e8d8
				$url = $this->save_convert_progress('&confirm=1');
d6e8d8
				$msg = $user->lang['PRE_CONVERT_COMPLETE'];
d6e8d8
d6e8d8
				if ($convert->convertor_data['author_notes'])
d6e8d8
				{
d6e8d8
					$msg .= '

' . sprintf($user->lang['AUTHOR_NOTES'], $convert->convertor_data['author_notes']);

d6e8d8
				}
d6e8d8
d6e8d8
				$template->assign_vars(array(
d6e8d8
					'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
d6e8d8
					'L_MESSAGE'		=> $msg,
d6e8d8
					'U_ACTION'		=> $url,
d6e8d8
				));
d6e8d8
d6e8d8
				return;
d6e8d8
			} // if (empty($_REQUEST['confirm']))
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'S_LEGEND'		=> true,
d6e8d8
				'LEGEND'		=> $user->lang['STARTING_CONVERT'],
d6e8d8
			));
d6e8d8
d6e8d8
			// Convert the config table and load the settings of the old board
d6e8d8
			if (!empty($convert->config_schema))
d6e8d8
			{
d6e8d8
				restore_config($convert->config_schema);
d6e8d8
d6e8d8
				// Override a couple of config variables for the duration
d6e8d8
				$config['max_quote_depth'] = 0;
d6e8d8
d6e8d8
				// @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues
d6e8d8
				$config['max_post_chars'] = 0;
d6e8d8
			}
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'TITLE'		=> $user->lang['CONFIG_CONVERT'],
d6e8d8
				'RESULT'	=> $user->lang['DONE'],
d6e8d8
			));
d6e8d8
d6e8d8
			// Now process queries and execute functions that have to be executed prior to the conversion
d6e8d8
			if (!empty($convert->convertor['execute_first']))
d6e8d8
			{
d6e8d8
				eval($convert->convertor['execute_first']);
d6e8d8
			}
d6e8d8
d6e8d8
			if (!empty($convert->convertor['query_first']))
d6e8d8
			{
d6e8d8
				if (!is_array($convert->convertor['query_first']))
d6e8d8
				{
d6e8d8
					$convert->convertor['query_first'] = array('target', array($convert->convertor['query_first']));
d6e8d8
				}
d6e8d8
				else if (!is_array($convert->convertor['query_first'][0]))
d6e8d8
				{
d6e8d8
					$convert->convertor['query_first'] = array(array($convert->convertor['query_first'][0], $convert->convertor['query_first'][1]));
d6e8d8
				}
d6e8d8
d6e8d8
				foreach ($convert->convertor['query_first'] as $query_first)
d6e8d8
				{
d6e8d8
					if ($query_first[0] == 'src')
d6e8d8
					{
d6e8d8
						if ($convert->mysql_convert && $same_db)
d6e8d8
						{
d6e8d8
							$src_db->sql_query("SET NAMES 'binary'");
d6e8d8
						}
d6e8d8
d6e8d8
						$src_db->sql_query($query_first[1]);
d6e8d8
d6e8d8
						if ($convert->mysql_convert && $same_db)
d6e8d8
						{
d6e8d8
							$src_db->sql_query("SET NAMES 'utf8'");
d6e8d8
						}
d6e8d8
					}
d6e8d8
					else
d6e8d8
					{
d6e8d8
						$db->sql_query($query_first[1]);
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'TITLE'		=> $user->lang['PREPROCESS_STEP'],
d6e8d8
				'RESULT'	=> $user->lang['DONE'],
d6e8d8
			));
d6e8d8
		} // if (!$current_table && !$skip_rows)
d6e8d8
d6e8d8
		$template->assign_block_vars('checks', array(
d6e8d8
			'S_LEGEND'		=> true,
d6e8d8
			'LEGEND'		=> $user->lang['FILLING_TABLES'],
d6e8d8
		));
d6e8d8
d6e8d8
		// This loop takes one target table and processes it
d6e8d8
		while ($current_table < sizeof($convert->convertor['schema']))
d6e8d8
		{
d6e8d8
			$schema = $convert->convertor['schema'][$current_table];
d6e8d8
d6e8d8
			// The target table isn't set, this can be because a module (for example the attachement mod) is taking care of this.
d6e8d8
			if (empty($schema['target']))
d6e8d8
			{
d6e8d8
				$current_table++;
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'TITLE'	=> sprintf($user->lang['FILLING_TABLE'], $schema['target']),
d6e8d8
			));
d6e8d8
d6e8d8
			// This is only the case when we first start working on the tables.
d6e8d8
			if (!$skip_rows)
d6e8d8
			{
d6e8d8
				// process execute_first and query_first for this table...
d6e8d8
				if (!empty($schema['execute_first']))
d6e8d8
				{
d6e8d8
					eval($schema['execute_first']);
d6e8d8
				}
d6e8d8
d6e8d8
				if (!empty($schema['query_first']))
d6e8d8
				{
d6e8d8
					if (!is_array($schema['query_first']))
d6e8d8
					{
d6e8d8
						$schema['query_first'] = array('target', array($schema['query_first']));
d6e8d8
					}
d6e8d8
					else if (!is_array($schema['query_first'][0]))
d6e8d8
					{
d6e8d8
						$schema['query_first'] = array(array($schema['query_first'][0], $schema['query_first'][1]));
d6e8d8
					}
d6e8d8
d6e8d8
					foreach ($schema['query_first'] as $query_first)
d6e8d8
					{
d6e8d8
						if ($query_first[0] == 'src')
d6e8d8
						{
d6e8d8
							if ($convert->mysql_convert && $same_db)
d6e8d8
							{
d6e8d8
								$src_db->sql_query("SET NAMES 'binary'");
d6e8d8
							}
d6e8d8
							$src_db->sql_query($query_first[1]);
d6e8d8
							if ($convert->mysql_convert && $same_db)
d6e8d8
							{
d6e8d8
								$src_db->sql_query("SET NAMES 'utf8'");
d6e8d8
							}
d6e8d8
						}
d6e8d8
						else
d6e8d8
						{
d6e8d8
							$db->sql_query($query_first[1]);
d6e8d8
						}
d6e8d8
					}
d6e8d8
				}
d6e8d8
d6e8d8
				if (!empty($schema['autoincrement']))
d6e8d8
				{
d6e8d8
					switch ($db->sql_layer)
d6e8d8
					{
d6e8d8
						case 'postgres':
d6e8d8
							$db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));');
d6e8d8
						break;
d6e8d8
d6e8d8
						case 'oracle':
d6e8d8
							$result = $db->sql_query('SELECT MAX(' . $schema['autoincrement'] . ') as max_id FROM ' . $schema['target']);
d6e8d8
							$row = $db->sql_fetchrow($result);
d6e8d8
							$db->sql_freeresult($result);
d6e8d8
d6e8d8
							$largest_id = (int) $row['max_id'];
d6e8d8
d6e8d8
							if ($largest_id)
d6e8d8
							{
d6e8d8
								$db->sql_query('DROP SEQUENCE ' . $schema['target'] . '_seq');
d6e8d8
								$db->sql_query('CREATE SEQUENCE ' . $schema['target'] . '_seq START WITH ' . ($largest_id + 1));
d6e8d8
							}
d6e8d8
						break;
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			// Process execute_always for this table
d6e8d8
			// This is for code which needs to be executed on every pass of this table if
d6e8d8
			// it gets split because of time restrictions
d6e8d8
			if (!empty($schema['execute_always']))
d6e8d8
			{
d6e8d8
				eval($schema['execute_always']);
d6e8d8
			}
d6e8d8
d6e8d8
			//
d6e8d8
			// Set up some variables
d6e8d8
			//
d6e8d8
			// $waiting_rows	holds rows for multirows insertion (MySQL only)
d6e8d8
			// $src_tables		holds unique tables with aliases to select from
d6e8d8
			// $src_fields		will quickly refer source fields (or aliases) corresponding to the current index
d6e8d8
			// $select_fields	holds the names of the fields to retrieve
d6e8d8
			//
d6e8d8
d6e8d8
			$sql_data = array(
d6e8d8
				'source_fields'		=> array(),
d6e8d8
				'target_fields'		=> array(),
d6e8d8
				'source_tables'		=> array(),
d6e8d8
				'select_fields'		=> array(),
d6e8d8
			);
d6e8d8
d6e8d8
			// This statement is building the keys for later insertion.
d6e8d8
			$insert_query = $this->build_insert_query($schema, $sql_data, $current_table);
d6e8d8
d6e8d8
			// If no source table is affected, we skip the table
d6e8d8
			if (empty($sql_data['source_tables']))
d6e8d8
			{
d6e8d8
				$skip_rows = 0;
d6e8d8
				$current_table++;
d6e8d8
				continue;
d6e8d8
			}
d6e8d8
d6e8d8
			$distinct = (!empty($schema['distinct'])) ? 'DISTINCT ' : '';
d6e8d8
d6e8d8
			$sql = 'SELECT ' . $distinct . implode(', ', $sql_data['select_fields']) . " \nFROM " . implode(', ', $sql_data['source_tables']);
d6e8d8
d6e8d8
			// Where
d6e8d8
			$sql .= (!empty($schema['where'])) ? "\nWHERE (" . $schema['where'] . ')' : '';
d6e8d8
d6e8d8
			// Group By
d6e8d8
			if (!empty($schema['group_by']))
d6e8d8
			{
d6e8d8
				$schema['group_by'] = array($schema['group_by']);
d6e8d8
				foreach ($sql_data['select_fields'] as $select)
d6e8d8
				{
d6e8d8
					$alias = strpos(strtolower($select), ' as ');
d6e8d8
					$select = ($alias) ? substr($select, 0, $alias) : $select;
d6e8d8
					if (!in_array($select, $schema['group_by']))
d6e8d8
					{
d6e8d8
						$schema['group_by'][] = $select;
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
			$sql .= (!empty($schema['group_by'])) ? "\nGROUP BY " . implode(', ', $schema['group_by']) : '';
d6e8d8
d6e8d8
			// Having
d6e8d8
			$sql .= (!empty($schema['having'])) ? "\nHAVING " . $schema['having'] : '';
d6e8d8
d6e8d8
			// Order By
d6e8d8
			if (empty($schema['order_by']) && !empty($schema['primary']))
d6e8d8
			{
d6e8d8
				$schema['order_by'] = $schema['primary'];
d6e8d8
			}
d6e8d8
			$sql .= (!empty($schema['order_by'])) ? "\nORDER BY " . $schema['order_by'] : '';
d6e8d8
d6e8d8
			// Counting basically holds the amount of rows processed.
d6e8d8
			$counting = -1;
d6e8d8
			$batch_time = 0;
d6e8d8
d6e8d8
			while ($counting === -1 || ($counting >= $convert->batch_size && still_on_time()))
d6e8d8
			{
d6e8d8
				$old_current_table = $current_table;
d6e8d8
d6e8d8
				$rows = '';
d6e8d8
				$waiting_rows = array();
d6e8d8
d6e8d8
				if (!empty($batch_time))
d6e8d8
				{
d6e8d8
					$mtime = explode(' ', microtime());
d6e8d8
					$mtime = $mtime[0] + $mtime[1];
d6e8d8
					$rows = ceil($counting/($mtime - $batch_time)) . " rows/s ($counting rows) | ";
d6e8d8
				}
d6e8d8
d6e8d8
				$template->assign_block_vars('checks', array(
d6e8d8
					'TITLE'		=> "skip_rows = $skip_rows",
d6e8d8
					'RESULT'	=> $rows . ((defined('DEBUG_EXTRA') && function_exists('memory_get_usage')) ? ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] : ''),
d6e8d8
				));
d6e8d8
d6e8d8
				$mtime = explode(' ', microtime());
d6e8d8
				$batch_time = $mtime[0] + $mtime[1];
d6e8d8
d6e8d8
				if ($convert->mysql_convert && $same_db)
d6e8d8
				{
d6e8d8
					$src_db->sql_query("SET NAMES 'binary'");
d6e8d8
				}
d6e8d8
d6e8d8
				// Take skip rows into account and only fetch batch_size amount of rows
d6e8d8
				$___result = $src_db->sql_query_limit($sql, $convert->batch_size, $skip_rows);
d6e8d8
d6e8d8
				if ($convert->mysql_convert && $same_db)
d6e8d8
				{
d6e8d8
					$src_db->sql_query("SET NAMES 'utf8'");
d6e8d8
				}
d6e8d8
d6e8d8
				// This loop processes each row
d6e8d8
				$counting = 0;
d6e8d8
d6e8d8
				$convert->row = $convert_row = array();
d6e8d8
d6e8d8
				if (!empty($schema['autoincrement']))
d6e8d8
				{
d6e8d8
					switch ($db->sql_layer)
d6e8d8
					{
d6e8d8
						case 'mssql':
d6e8d8
						case 'mssql_odbc':
d6e8d8
							$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' ON');
d6e8d8
						break;
d6e8d8
					}
d6e8d8
				}
d6e8d8
d6e8d8
				// Now handle the rows until time is over or no more rows to process...
d6e8d8
				while ($counting === 0 || still_on_time())
d6e8d8
				{
d6e8d8
					$convert_row = $src_db->sql_fetchrow($___result);
d6e8d8
d6e8d8
					if (!$convert_row)
d6e8d8
					{
d6e8d8
						// move to the next batch or table
d6e8d8
						break;
d6e8d8
					}
d6e8d8
d6e8d8
					// With this we are able to always save the last state
d6e8d8
					$convert->row = $convert_row;
d6e8d8
d6e8d8
					// Increment the counting variable, it stores the number of rows we have processed
d6e8d8
					$counting++;
d6e8d8
d6e8d8
					$insert_values = array();
d6e8d8
d6e8d8
					$sql_flag = $this->process_row($schema, $sql_data, $insert_values);
d6e8d8
d6e8d8
					if ($sql_flag === true)
d6e8d8
					{
d6e8d8
						switch ($db->sql_layer)
d6e8d8
						{
d6e8d8
							// If MySQL, we'll wait to have num_wait_rows rows to submit at once
d6e8d8
							case 'mysql':
d6e8d8
							case 'mysql4':
d6e8d8
							case 'mysqli':
d6e8d8
								$waiting_rows[] = '(' . implode(', ', $insert_values) . ')';
d6e8d8
d6e8d8
								if (sizeof($waiting_rows) >= $convert->num_wait_rows)
d6e8d8
								{
d6e8d8
									$errored = false;
d6e8d8
d6e8d8
									$db->sql_return_on_error(true);
d6e8d8
d6e8d8
									if (!$db->sql_query($insert_query . implode(', ', $waiting_rows)))
d6e8d8
									{
d6e8d8
										$errored = true;
d6e8d8
									}
d6e8d8
									$db->sql_return_on_error(false);
d6e8d8
d6e8d8
									if ($errored)
d6e8d8
									{
d6e8d8
										$db->sql_return_on_error(true);
d6e8d8
d6e8d8
										// Because it errored out we will try to insert the rows one by one... most of the time this
d6e8d8
										// is caused by duplicate entries - but we also do not want to miss one...
d6e8d8
										foreach ($waiting_rows as $waiting_sql)
d6e8d8
										{
d6e8d8
											if (!$db->sql_query($insert_query . $waiting_sql))
d6e8d8
											{
d6e8d8
												$this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_query . $waiting_sql) . '

' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true);
d6e8d8
											}
d6e8d8
										}
d6e8d8
d6e8d8
										$db->sql_return_on_error(false);
d6e8d8
									}
d6e8d8
d6e8d8
									$waiting_rows = array();
d6e8d8
								}
d6e8d8
d6e8d8
							break;
d6e8d8
d6e8d8
							default:
d6e8d8
								$insert_sql = $insert_query . '(' . implode(', ', $insert_values) . ')';
d6e8d8
d6e8d8
								$db->sql_return_on_error(true);
d6e8d8
d6e8d8
								if (!$db->sql_query($insert_sql))
d6e8d8
								{
d6e8d8
									$this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_sql) . '

' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true);
d6e8d8
								}
d6e8d8
								$db->sql_return_on_error(false);
d6e8d8
d6e8d8
								$waiting_rows = array();
d6e8d8
d6e8d8
							break;
d6e8d8
						}
d6e8d8
					}
d6e8d8
d6e8d8
					$skip_rows++;
d6e8d8
				}
d6e8d8
				$src_db->sql_freeresult($___result);
d6e8d8
d6e8d8
				// We might still have some rows waiting
d6e8d8
				if (sizeof($waiting_rows))
d6e8d8
				{
d6e8d8
					$errored = false;
d6e8d8
					$db->sql_return_on_error(true);
d6e8d8
d6e8d8
					if (!$db->sql_query($insert_query . implode(', ', $waiting_rows)))
d6e8d8
					{
d6e8d8
						$errored = true;
d6e8d8
					}
d6e8d8
					$db->sql_return_on_error(false);
d6e8d8
d6e8d8
					if ($errored)
d6e8d8
					{
d6e8d8
						$db->sql_return_on_error(true);
d6e8d8
d6e8d8
						// Because it errored out we will try to insert the rows one by one... most of the time this
d6e8d8
						// is caused by duplicate entries - but we also do not want to miss one...
d6e8d8
						foreach ($waiting_rows as $waiting_sql)
d6e8d8
						{
d6e8d8
							$db->sql_query($insert_query . $waiting_sql);
d6e8d8
							$this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_query . $waiting_sql) . '

' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true);
d6e8d8
						}
d6e8d8
d6e8d8
						$db->sql_return_on_error(false);
d6e8d8
					}
d6e8d8
d6e8d8
					$waiting_rows = array();
d6e8d8
				}
d6e8d8
d6e8d8
				if (!empty($schema['autoincrement']))
d6e8d8
				{
d6e8d8
					switch ($db->sql_layer)
d6e8d8
					{
d6e8d8
						case 'mssql':
d6e8d8
						case 'mssql_odbc':
d6e8d8
							$db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' OFF');
d6e8d8
						break;
d6e8d8
d6e8d8
						case 'postgres':
d6e8d8
							$db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));');
d6e8d8
						break;
d6e8d8
d6e8d8
						case 'oracle':
d6e8d8
							$result = $db->sql_query('SELECT MAX(' . $schema['autoincrement'] . ') as max_id FROM ' . $schema['target']);
d6e8d8
							$row = $db->sql_fetchrow($result);
d6e8d8
							$db->sql_freeresult($result);
d6e8d8
d6e8d8
							$largest_id = (int) $row['max_id'];
d6e8d8
d6e8d8
							if ($largest_id)
d6e8d8
							{
d6e8d8
								$db->sql_query('DROP SEQUENCE ' . $schema['target'] . '_seq');
d6e8d8
								$db->sql_query('CREATE SEQUENCE ' . $schema['target'] . '_seq START WITH ' . ($largest_id + 1));
d6e8d8
							}
d6e8d8
						break;
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			// When we reach this point, either the current table has been processed or we're running out of time.
d6e8d8
			if (still_on_time() && $counting < $convert->batch_size/* && !defined('DEBUG_EXTRA')*/)
d6e8d8
			{
d6e8d8
				$skip_rows = 0;
d6e8d8
				$current_table++;
d6e8d8
			}
d6e8d8
			else
d6e8d8
			{/*
d6e8d8
				if (still_on_time() && $counting < $convert->batch_size)
d6e8d8
				{
d6e8d8
					$skip_rows = 0;
d6e8d8
					$current_table++;
d6e8d8
				}*/
d6e8d8
d6e8d8
				// Looks like we ran out of time.
d6e8d8
				$url = $this->save_convert_progress('&current_table=' . $current_table . '&skip_rows=' . $skip_rows);
d6e8d8
d6e8d8
				$current_table++;
d6e8d8
//				$percentage = ($skip_rows == 0) ? 0 : floor(100 / ($total_rows / $skip_rows));
d6e8d8
d6e8d8
				$msg = sprintf($user->lang['STEP_PERCENT_COMPLETED'], $current_table, sizeof($convert->convertor['schema']));
d6e8d8
d6e8d8
				$template->assign_vars(array(
d6e8d8
					'L_MESSAGE'		=> $msg,
d6e8d8
					'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
d6e8d8
					'U_ACTION'		=> $url,
d6e8d8
				));
d6e8d8
d6e8d8
				$this->meta_refresh($url);
d6e8d8
				return;
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		// Process execute_last then we'll be done
d6e8d8
		$url = $this->save_convert_progress('&jump=1');
d6e8d8
d6e8d8
		$template->assign_vars(array(
d6e8d8
			'L_SUBMIT'		=> $user->lang['FINAL_STEP'],
d6e8d8
			'U_ACTION'		=> $url,
d6e8d8
		));
d6e8d8
d6e8d8
		$this->meta_refresh($url);
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Sync function being executed at the middle, some functions need to be executed after a successful sync.
d6e8d8
	*/
d6e8d8
	function sync_forums($sync_batch)
d6e8d8
	{
d6e8d8
		global $template, $user, $db, $phpbb_root_path, $phpEx, $config, $cache;
d6e8d8
		global $convert;
d6e8d8
d6e8d8
		$template->assign_block_vars('checks', array(
d6e8d8
			'S_LEGEND'	=> true,
d6e8d8
			'LEGEND'	=> $user->lang['SYNC_TOPICS'],
d6e8d8
		));
d6e8d8
d6e8d8
		$batch_size = $convert->batch_size;
d6e8d8
d6e8d8
		$sql = 'SELECT MIN(topic_id) as min_value, MAX(topic_id) AS max_value
d6e8d8
			FROM ' . TOPICS_TABLE;
d6e8d8
		$result = $db->sql_query($sql);
d6e8d8
		$row = $db->sql_fetchrow($result);
d6e8d8
		$db->sql_freeresult($result);
d6e8d8
d6e8d8
		// Set values of minimum/maximum primary value for this table.
d6e8d8
		$primary_min = $row['min_value'];
d6e8d8
		$primary_max = $row['max_value'];
d6e8d8
d6e8d8
		if ($sync_batch == 0)
d6e8d8
		{
d6e8d8
			$sync_batch = (int) $primary_min;
d6e8d8
		}
d6e8d8
d6e8d8
		if ($sync_batch == 0)
d6e8d8
		{
d6e8d8
			$sync_batch = 1;
d6e8d8
		}
d6e8d8
d6e8d8
		// Fetch a batch of rows, process and insert them.
d6e8d8
		while ($sync_batch <= $primary_max && still_on_time())
d6e8d8
		{
d6e8d8
			$end = ($sync_batch + $batch_size - 1);
d6e8d8
d6e8d8
			// Sync all topics in batch mode...
d6e8d8
			sync('topic_approved', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, false);
d6e8d8
			sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true);
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'TITLE'		=> sprintf($user->lang['SYNC_TOPIC_ID'], $sync_batch, ($sync_batch + $batch_size)) . ((defined('DEBUG_EXTRA') && function_exists('memory_get_usage')) ? ' [' . ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] . ']' : ''),
d6e8d8
				'RESULT'	=> $user->lang['DONE'],
d6e8d8
			));
d6e8d8
d6e8d8
			$sync_batch += $batch_size;
d6e8d8
		}
d6e8d8
d6e8d8
		if ($sync_batch >= $primary_max)
d6e8d8
		{
d6e8d8
			$url = $this->save_convert_progress('&final_jump=1');
d6e8d8
d6e8d8
			$template->assign_vars(array(
d6e8d8
				'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
d6e8d8
				'U_ACTION'		=> $url,
d6e8d8
			));
d6e8d8
d6e8d8
			$this->meta_refresh($url);
d6e8d8
			return;
d6e8d8
		}
d6e8d8
		else
d6e8d8
		{
d6e8d8
			$sync_batch--;
d6e8d8
		}
d6e8d8
d6e8d8
		$url = $this->save_convert_progress('&sync_batch=' . $sync_batch);
d6e8d8
d6e8d8
		$template->assign_vars(array(
d6e8d8
			'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
d6e8d8
			'U_ACTION'		=> $url,
d6e8d8
		));
d6e8d8
d6e8d8
		$this->meta_refresh($url);
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Save the convertor status
d6e8d8
	*/
d6e8d8
	function save_convert_progress($step)
d6e8d8
	{
d6e8d8
		global $convert, $language;
d6e8d8
d6e8d8
		// Save convertor Status
d6e8d8
		set_config('convert_progress', serialize(array(
d6e8d8
			'step'			=> $step,
d6e8d8
			'table_prefix'	=> $convert->src_table_prefix,
d6e8d8
			'tag'			=> $convert->convertor_tag,
d6e8d8
		)), true);
d6e8d8
d6e8d8
		set_config('convert_db_server', serialize(array(
d6e8d8
			'dbms'			=> $convert->src_dbms,
d6e8d8
			'dbhost'		=> $convert->src_dbhost,
d6e8d8
			'dbport'		=> $convert->src_dbport,
d6e8d8
			'dbname'		=> $convert->src_dbname,
d6e8d8
		)), true);
d6e8d8
d6e8d8
		set_config('convert_db_user', serialize(array(
d6e8d8
			'dbuser'		=> $convert->src_dbuser,
d6e8d8
			'dbpasswd'		=> $convert->src_dbpasswd,
d6e8d8
		)), true);
d6e8d8
d6e8d8
		return $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag={$convert->convertor_tag}$step&language=$language";
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Finish conversion, the last function to be called.
d6e8d8
	*/
d6e8d8
	function finish_conversion()
d6e8d8
	{
d6e8d8
		global $db, $phpbb_root_path, $convert, $config, $language, $user, $template;
d6e8d8
d6e8d8
		$db->sql_query('DELETE FROM ' . CONFIG_TABLE . "
d6e8d8
			WHERE config_name = 'convert_progress'
d6e8d8
				OR config_name = 'convert_options'
d6e8d8
				OR config_name = 'convert_db_server'
d6e8d8
				OR config_name = 'convert_db_user'");
d6e8d8
		$db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
d6e8d8
d6e8d8
		@unlink($phpbb_root_path . 'cache/data_global.php');
d6e8d8
		cache_moderators();
d6e8d8
d6e8d8
		// And finally, add a note to the log
d6e8d8
		add_log('admin', 'LOG_INSTALL_CONVERTED', $convert->convertor_data['forum_name'], $config['version']);
d6e8d8
d6e8d8
		$url = $this->p_master->module_url . "?mode={$this->mode}&sub=final&language=$language";
d6e8d8
d6e8d8
		$template->assign_vars(array(
d6e8d8
			'L_SUBMIT'		=> $user->lang['FINAL_STEP'],
d6e8d8
			'U_ACTION'		=> $url,
d6e8d8
		));
d6e8d8
d6e8d8
		$this->meta_refresh($url);
d6e8d8
		return;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* This function marks the steps after syncing
d6e8d8
	*/
d6e8d8
	function final_jump($final_jump)
d6e8d8
	{
d6e8d8
		global $template, $user, $src_db, $same_db, $db, $phpbb_root_path, $phpEx, $config, $cache;
d6e8d8
		global $convert;
d6e8d8
d6e8d8
		$template->assign_block_vars('checks', array(
d6e8d8
			'S_LEGEND'	=> true,
d6e8d8
			'LEGEND'	=> $user->lang['PROCESS_LAST'],
d6e8d8
		));
d6e8d8
d6e8d8
		if ($final_jump == 1)
d6e8d8
		{
d6e8d8
			$db->sql_return_on_error(true);
d6e8d8
d6e8d8
			update_topics_posted();
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'TITLE'		=> $user->lang['UPDATE_TOPICS_POSTED'],
d6e8d8
				'RESULT'	=> $user->lang['DONE'],
d6e8d8
			));
d6e8d8
d6e8d8
			if ($db->sql_error_triggered)
d6e8d8
			{
d6e8d8
				$template->assign_vars(array(
d6e8d8
					'S_ERROR_BOX'	=> true,
d6e8d8
					'ERROR_TITLE'	=> $user->lang['UPDATE_TOPICS_POSTED'],
d6e8d8
					'ERROR_MSG'		=> $user->lang['UPDATE_TOPICS_POSTED_ERR'],
d6e8d8
				));
d6e8d8
			}
d6e8d8
			$db->sql_return_on_error(false);
d6e8d8
d6e8d8
			$this->finish_conversion();
d6e8d8
			return;
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* This function marks the steps before syncing (jump=1)
d6e8d8
	*/
d6e8d8
	function jump($jump, $last_statement)
d6e8d8
	{
d6e8d8
		global $template, $user, $src_db, $same_db, $db, $phpbb_root_path, $phpEx, $config, $cache;
d6e8d8
		global $convert;
d6e8d8
d6e8d8
		$template->assign_block_vars('checks', array(
d6e8d8
			'S_LEGEND'	=> true,
d6e8d8
			'LEGEND'	=> $user->lang['PROCESS_LAST'],
d6e8d8
		));
d6e8d8
d6e8d8
		if ($jump == 1)
d6e8d8
		{
d6e8d8
			// Execute 'last' statements/queries
d6e8d8
			if (!empty($convert->convertor['execute_last']))
d6e8d8
			{
d6e8d8
				if (!is_array($convert->convertor['execute_last']))
d6e8d8
				{
d6e8d8
					eval($convert->convertor['execute_last']);
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					while ($last_statement < sizeof($convert->convertor['execute_last']))
d6e8d8
					{
d6e8d8
						eval($convert->convertor['execute_last'][$last_statement]);
d6e8d8
d6e8d8
						$template->assign_block_vars('checks', array(
d6e8d8
							'TITLE'		=> $convert->convertor['execute_last'][$last_statement],
d6e8d8
							'RESULT'	=> $user->lang['DONE'],
d6e8d8
						));
d6e8d8
d6e8d8
						$last_statement++;
d6e8d8
						$url = $this->save_convert_progress('&jump=1&last=' . $last_statement);
d6e8d8
d6e8d8
						$percentage = ($last_statement == 0) ? 0 : floor(100 / (sizeof($convert->convertor['execute_last']) / $last_statement));
d6e8d8
						$msg = sprintf($user->lang['STEP_PERCENT_COMPLETED'], $last_statement, sizeof($convert->convertor['execute_last']), $percentage);
d6e8d8
d6e8d8
						$template->assign_vars(array(
d6e8d8
							'L_SUBMIT'		=> $user->lang['CONTINUE_LAST'],
d6e8d8
							'L_MESSAGE'		=> $msg,
d6e8d8
							'U_ACTION'		=> $url,
d6e8d8
						));
d6e8d8
d6e8d8
						$this->meta_refresh($url);
d6e8d8
						return;
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			if (!empty($convert->convertor['query_last']))
d6e8d8
			{
d6e8d8
				if (!is_array($convert->convertor['query_last']))
d6e8d8
				{
d6e8d8
					$convert->convertor['query_last'] = array('target', array($convert->convertor['query_last']));
d6e8d8
				}
d6e8d8
				else if (!is_array($convert->convertor['query_last'][0]))
d6e8d8
				{
d6e8d8
					$convert->convertor['query_last'] = array(array($convert->convertor['query_last'][0], $convert->convertor['query_last'][1]));
d6e8d8
				}
d6e8d8
d6e8d8
				foreach ($convert->convertor['query_last'] as $query_last)
d6e8d8
				{
d6e8d8
					if ($query_last[0] == 'src')
d6e8d8
					{
d6e8d8
						if ($convert->mysql_convert && $same_db)
d6e8d8
						{
d6e8d8
							$src_db->sql_query("SET NAMES 'binary'");
d6e8d8
						}
d6e8d8
d6e8d8
						$src_db->sql_query($query_last[1]);
d6e8d8
d6e8d8
						if ($convert->mysql_convert && $same_db)
d6e8d8
						{
d6e8d8
							$src_db->sql_query("SET NAMES 'utf8'");
d6e8d8
						}
d6e8d8
					}
d6e8d8
					else
d6e8d8
					{
d6e8d8
						$db->sql_query($query_last[1]);
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			// Sanity check
d6e8d8
			$db->sql_return_on_error(false);
d6e8d8
			$src_db->sql_return_on_error(false);
d6e8d8
d6e8d8
			fix_empty_primary_groups();
d6e8d8
d6e8d8
			if (!isset($config['board_startdate']))
d6e8d8
			{
d6e8d8
				$sql = 'SELECT MIN(user_regdate) AS board_startdate
d6e8d8
					FROM ' . USERS_TABLE;
d6e8d8
				$result = $db->sql_query($sql);
d6e8d8
				$row = $db->sql_fetchrow($result);
d6e8d8
				$db->sql_freeresult($result);
d6e8d8
d6e8d8
				if (($row['board_startdate'] < $config['board_startdate'] && $row['board_startdate'] > 0) || !isset($config['board_startdate']))
d6e8d8
				{
d6e8d8
					set_config('board_startdate', $row['board_startdate']);
d6e8d8
					$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_regdate = ' . $row['board_startdate'] . ' WHERE user_id = ' . ANONYMOUS);
d6e8d8
				}
d6e8d8
			}
d6e8d8
d6e8d8
			update_dynamic_config();
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'TITLE'		=> $user->lang['CLEAN_VERIFY'],
d6e8d8
				'RESULT'	=> $user->lang['DONE'],
d6e8d8
			));
d6e8d8
d6e8d8
			$url = $this->save_convert_progress('&jump=2');
d6e8d8
d6e8d8
			$template->assign_vars(array(
d6e8d8
				'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
d6e8d8
				'U_ACTION'		=> $url,
d6e8d8
			));
d6e8d8
d6e8d8
			$this->meta_refresh($url);
d6e8d8
			return;
d6e8d8
		}
d6e8d8
d6e8d8
		if ($jump == 2)
d6e8d8
		{
d6e8d8
			$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_permissions = ''");
d6e8d8
d6e8d8
			// TODO: sync() is likely going to bomb out on forums with a considerable amount of topics.
d6e8d8
			// TODO: the sync function is able to handle FROM-TO values, we should use them here (batch processing)
d6e8d8
			sync('forum', '', '', false, true);
d6e8d8
			$cache->destroy('sql', FORUMS_TABLE);
d6e8d8
d6e8d8
			$template->assign_block_vars('checks', array(
d6e8d8
				'TITLE'		=> $user->lang['SYNC_FORUMS'],
d6e8d8
				'RESULT'	=> $user->lang['DONE'],
d6e8d8
			));
d6e8d8
d6e8d8
			// Continue with synchronizing the forums...
d6e8d8
			$url = $this->save_convert_progress('&sync_batch=0');
d6e8d8
d6e8d8
			$template->assign_vars(array(
d6e8d8
				'L_SUBMIT'		=> $user->lang['CONTINUE_CONVERT'],
d6e8d8
				'U_ACTION'		=> $url,
d6e8d8
			));
d6e8d8
d6e8d8
			$this->meta_refresh($url);
d6e8d8
			return;
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	function build_insert_query(&$schema, &$sql_data, $current_table)
d6e8d8
	{
d6e8d8
		global $db, $user;
d6e8d8
		global $convert;
d6e8d8
d6e8d8
		// Can we use IGNORE with this DBMS?
d6e8d8
		$sql_ignore = (strpos($db->sql_layer, 'mysql') === 0 && !defined('DEBUG_EXTRA')) ? 'IGNORE ' : '';
d6e8d8
		$insert_query = 'INSERT ' . $sql_ignore . 'INTO ' . $schema['target'] . ' (';
d6e8d8
d6e8d8
		$aliases = array();
d6e8d8
d6e8d8
		$sql_data = array(
d6e8d8
			'source_fields'		=> array(),
d6e8d8
			'target_fields'		=> array(),
d6e8d8
			'source_tables'		=> array(),
d6e8d8
			'select_fields'		=> array(),
d6e8d8
		);
d6e8d8
d6e8d8
		foreach ($schema as $key => $val)
d6e8d8
		{
d6e8d8
			// Example: array('group_name',				'extension_groups.group_name',		'htmlspecialchars'),
d6e8d8
			if (is_int($key))
d6e8d8
			{
d6e8d8
				if (!empty($val[0]))
d6e8d8
				{
d6e8d8
					// Target fields
d6e8d8
					$sql_data['target_fields'][$val[0]] = $key;
d6e8d8
					$insert_query .= $val[0] . ', ';
d6e8d8
				}
d6e8d8
d6e8d8
				if (!is_array($val[1]))
d6e8d8
				{
d6e8d8
					$val[1] = array($val[1]);
d6e8d8
				}
d6e8d8
d6e8d8
				foreach ($val[1] as $valkey => $value_1)
d6e8d8
				{
d6e8d8
					// This should cover about any case:
d6e8d8
					//
d6e8d8
					// table.field					=> SELECT table.field				FROM table
d6e8d8
					// table.field AS alias			=> SELECT table.field	AS alias	FROM table
d6e8d8
					// table.field AS table2.alias	=> SELECT table2.field	AS alias	FROM table table2
d6e8d8
					// table.field AS table2.field	=> SELECT table2.field				FROM table table2
d6e8d8
					//
d6e8d8
					if (preg_match('/^([a-z0-9_]+)\.([a-z0-9_]+)( +AS +(([a-z0-9_]+?)\.)?([a-z0-9_]+))?$/i', $value_1, $m))
d6e8d8
					{
d6e8d8
						// There is 'AS ...' in the field names
d6e8d8
						if (!empty($m[3]))
d6e8d8
						{
d6e8d8
							$value_1 = ($m[2] == $m[6]) ? $m[1] . '.' . $m[2] : $m[1] . '.' . $m[2] . ' AS ' . $m[6];
d6e8d8
d6e8d8
							// Table alias: store it then replace the source table with it
d6e8d8
							if (!empty($m[5]) && $m[5] != $m[1])
d6e8d8
							{
d6e8d8
								$aliases[$m[5]] = $m[1];
d6e8d8
								$value_1 = str_replace($m[1] . '.' . $m[2], $m[5] . '.' . $m[2], $value_1);
d6e8d8
							}
d6e8d8
						}
d6e8d8
						else
d6e8d8
						{
d6e8d8
							// No table alias
d6e8d8
							$sql_data['source_tables'][$m[1]] = (empty($convert->src_table_prefix)) ? $m[1] : $convert->src_table_prefix . $m[1] . ' ' . $m[1];
d6e8d8
						}
d6e8d8
d6e8d8
						$sql_data['select_fields'][$value_1] = $value_1;
d6e8d8
						$sql_data['source_fields'][$key][$valkey] = (!empty($m[6])) ? $m[6] : $m[2];
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
			else if ($key == 'where' || $key == 'group_by' || $key == 'order_by' || $key == 'having')
d6e8d8
			{
d6e8d8
				if (@preg_match_all('/([a-z0-9_]+)\.([a-z0-9_]+)/i', $val, $m))
d6e8d8
				{
d6e8d8
					foreach ($m[1] as $value)
d6e8d8
					{
d6e8d8
						$sql_data['source_tables'][$value] = (empty($convert->src_table_prefix)) ? $value : $convert->src_table_prefix . $value . ' ' . $value;
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		// Add the aliases to the list of tables
d6e8d8
		foreach ($aliases as $alias => $table)
d6e8d8
		{
d6e8d8
			$sql_data['source_tables'][$alias] = $convert->src_table_prefix . $table . ' ' . $alias;
d6e8d8
		}
d6e8d8
d6e8d8
		// 'left_join'		=> 'forums LEFT JOIN forum_prune ON forums.forum_id = forum_prune.forum_id',
d6e8d8
		if (!empty($schema['left_join']))
d6e8d8
		{
d6e8d8
			if (!is_array($schema['left_join']))
d6e8d8
			{
d6e8d8
				$schema['left_join'] = array($schema['left_join']);
d6e8d8
			}
d6e8d8
d6e8d8
			foreach ($schema['left_join'] as $left_join)
d6e8d8
			{
d6e8d8
				// This won't handle concatened LEFT JOINs
d6e8d8
				if (!preg_match('/([a-z0-9_]+) LEFT JOIN ([a-z0-9_]+) A?S? ?([a-z0-9_]*?) ?(ON|USING)(.*)/i', $left_join, $m))
d6e8d8
				{
d6e8d8
					$this->p_master->error(sprintf($user->lang['NOT_UNDERSTAND'], 'LEFT JOIN', $left_join, $current_table, $schema['target']), __LINE__, __FILE__);
d6e8d8
				}
d6e8d8
d6e8d8
				if (!empty($aliases[$m[2]]))
d6e8d8
				{
d6e8d8
					if (!empty($m[3]))
d6e8d8
					{
d6e8d8
						$this->p_master->error(sprintf($user->lang['NAMING_CONFLICT'], $m[2], $m[3], $schema['left_join']), __LINE__, __FILE__);
d6e8d8
					}
d6e8d8
d6e8d8
					$m[2] = $aliases[$m[2]];
d6e8d8
					$m[3] = $m[2];
d6e8d8
				}
d6e8d8
d6e8d8
				$right_table = $convert->src_table_prefix . $m[2];
d6e8d8
				if (!empty($m[3]))
d6e8d8
				{
d6e8d8
					unset($sql_data['source_tables'][$m[3]]);
d6e8d8
				}
d6e8d8
				else if ($m[2] != $m[1])
d6e8d8
				{
d6e8d8
					unset($sql_data['source_tables'][$m[2]]);
d6e8d8
				}
d6e8d8
d6e8d8
				if (strpos($sql_data['source_tables'][$m[1]], "\nLEFT JOIN") !== false)
d6e8d8
				{
d6e8d8
					$sql_data['source_tables'][$m[1]] = '(' . $sql_data['source_tables'][$m[1]] . ")\nLEFT JOIN $right_table";
d6e8d8
				}
d6e8d8
				else
d6e8d8
				{
d6e8d8
					$sql_data['source_tables'][$m[1]] .= "\nLEFT JOIN $right_table";
d6e8d8
				}
d6e8d8
d6e8d8
				if (!empty($m[3]))
d6e8d8
				{
d6e8d8
					unset($sql_data['source_tables'][$m[3]]);
d6e8d8
					$sql_data['source_tables'][$m[1]] .= ' AS ' . $m[3];
d6e8d8
				}
d6e8d8
				else if (!empty($convert->src_table_prefix))
d6e8d8
				{
d6e8d8
					$sql_data['source_tables'][$m[1]] .= ' AS ' . $m[2];
d6e8d8
				}
d6e8d8
				$sql_data['source_tables'][$m[1]] .= ' ' . $m[4] . $m[5];
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		// Remove ", " from the end of the insert query
d6e8d8
		$insert_query = substr($insert_query, 0, -2) . ') VALUES ';
d6e8d8
d6e8d8
		return $insert_query;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Function for processing the currently handled row
d6e8d8
	*/
d6e8d8
	function process_row(&$schema, &$sql_data, &$insert_values)
d6e8d8
	{
d6e8d8
		global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache;
d6e8d8
		global $convert, $convert_row;
d6e8d8
d6e8d8
		$sql_flag = false;
d6e8d8
d6e8d8
		foreach ($schema as $key => $fields)
d6e8d8
		{
d6e8d8
			// We are only interested in the lines with:
d6e8d8
			// array('comment', 'attachments_desc.comment', 'htmlspecialchars'),
d6e8d8
			if (is_int($key))
d6e8d8
			{
d6e8d8
				if (!is_array($fields[1]))
d6e8d8
				{
d6e8d8
					$fields[1] = array($fields[1]);
d6e8d8
				}
d6e8d8
d6e8d8
				$firstkey_set = false;
d6e8d8
				$firstkey = 0;
d6e8d8
d6e8d8
				foreach ($fields[1] as $inner_key => $inner_value)
d6e8d8
				{
d6e8d8
					if (!$firstkey_set)
d6e8d8
					{
d6e8d8
						$firstkey = $inner_key;
d6e8d8
						$firstkey_set = true;
d6e8d8
					}
d6e8d8
d6e8d8
					$src_field = isset($sql_data['source_fields'][$key][$inner_key]) ? $sql_data['source_fields'][$key][$inner_key] : '';
d6e8d8
d6e8d8
					if (!empty($src_field))
d6e8d8
					{
d6e8d8
						$fields[1][$inner_key] = $convert->row[$src_field];
d6e8d8
					}
d6e8d8
				}
d6e8d8
d6e8d8
				if (!empty($fields[0]))
d6e8d8
				{
d6e8d8
					// We have a target field, if we haven't set $sql_flag yet it will be set to TRUE.
d6e8d8
					// If a function has already set it to FALSE it won't change it.
d6e8d8
					if ($sql_flag === false)
d6e8d8
					{
d6e8d8
						$sql_flag = true;
d6e8d8
					}
d6e8d8
d6e8d8
					// No function assigned?
d6e8d8
					if (empty($fields[2]))
d6e8d8
					{
d6e8d8
						$value = $fields[1][$firstkey];
d6e8d8
					}
d6e8d8
					else if (is_array($fields[2]))
d6e8d8
					{
d6e8d8
						// Execute complex function/eval/typecast
d6e8d8
						$value = $fields[1];
d6e8d8
d6e8d8
						foreach ($fields[2] as $type => $execution)
d6e8d8
						{
d6e8d8
							if (strpos($type, 'typecast') === 0)
d6e8d8
							{
d6e8d8
								if (!is_array($value))
d6e8d8
								{
d6e8d8
									$value = array($value);
d6e8d8
								}
d6e8d8
								$value = $value[0];
d6e8d8
								settype($value, $execution);
d6e8d8
							}
d6e8d8
							else if (strpos($type, 'function') === 0)
d6e8d8
							{
d6e8d8
								if (!is_array($value))
d6e8d8
								{
d6e8d8
									$value = array($value);
d6e8d8
								}
d6e8d8
d6e8d8
								$value = call_user_func_array($execution, $value);
d6e8d8
							}
d6e8d8
							else if (strpos($type, 'execute') === 0)
d6e8d8
							{
d6e8d8
								if (!is_array($value))
d6e8d8
								{
d6e8d8
									$value = array($value);
d6e8d8
								}
d6e8d8
d6e8d8
								$execution = str_replace('{RESULT}', '$value', $execution);
d6e8d8
								$execution = str_replace('{VALUE}', '$value', $execution);
d6e8d8
								eval($execution);
d6e8d8
							}
d6e8d8
						}
d6e8d8
					}
d6e8d8
					else
d6e8d8
					{
d6e8d8
						$value = call_user_func_array($fields[2], $fields[1]);
d6e8d8
					}
d6e8d8
d6e8d8
					if (is_null($value))
d6e8d8
					{
d6e8d8
						$value = '';
d6e8d8
					}
d6e8d8
d6e8d8
					$insert_values[] = $db->_sql_validate_value($value);
d6e8d8
				}
d6e8d8
				else if (!empty($fields[2]))
d6e8d8
				{
d6e8d8
					if (is_array($fields[2]))
d6e8d8
					{
d6e8d8
						// Execute complex function/eval/typecast
d6e8d8
						$value = '';
d6e8d8
d6e8d8
						foreach ($fields[2] as $type => $execution)
d6e8d8
						{
d6e8d8
							if (strpos($type, 'typecast') === 0)
d6e8d8
							{
d6e8d8
								$value = settype($value, $execution);
d6e8d8
							}
d6e8d8
							else if (strpos($type, 'function') === 0)
d6e8d8
							{
d6e8d8
								if (!is_array($value))
d6e8d8
								{
d6e8d8
									$value = array($value);
d6e8d8
								}
d6e8d8
d6e8d8
								$value = call_user_func_array($execution, $value);
d6e8d8
							}
d6e8d8
							else if (strpos($type, 'execute') === 0)
d6e8d8
							{
d6e8d8
								if (!is_array($value))
d6e8d8
								{
d6e8d8
									$value = array($value);
d6e8d8
								}
d6e8d8
d6e8d8
								$execution = str_replace('{RESULT}', '$value', $execution);
d6e8d8
								$execution = str_replace('{VALUE}', '$value', $execution);
d6e8d8
								eval($execution);
d6e8d8
							}
d6e8d8
						}
d6e8d8
					}
d6e8d8
					else
d6e8d8
					{
d6e8d8
						call_user_func_array($fields[2], $fields[1]);
d6e8d8
					}
d6e8d8
				}
d6e8d8
			}
d6e8d8
		}
d6e8d8
d6e8d8
		return $sql_flag;
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* Own meta refresh function to be able to change the global time used
d6e8d8
	*/
d6e8d8
	function meta_refresh($url)
d6e8d8
	{
d6e8d8
		global $convert, $template;
d6e8d8
d6e8d8
		if ($convert->options['refresh'])
d6e8d8
		{
d6e8d8
			// Because we should not rely on correct settings, we simply use the relative path here directly.
d6e8d8
			$template->assign_vars(array(
d6e8d8
				'S_REFRESH'	=> true,
d6e8d8
				'META'		=> '<meta http-equiv="refresh" content="5;url=' . $url . '" />')
d6e8d8
			);
d6e8d8
		}
d6e8d8
	}
d6e8d8
d6e8d8
	/**
d6e8d8
	* The information below will be used to build the input fields presented to the user
d6e8d8
	*/
d6e8d8
	var $convert_options = array(
d6e8d8
		'legend1'			=> 'SPECIFY_OPTIONS',
d6e8d8
		'src_dbms'			=> array('lang' => 'DBMS',			'type' => 'select', 'options' => 'dbms_select(\'{VALUE}\', true)', 'explain' => false),
d6e8d8
		'src_dbhost'		=> array('lang' => 'DB_HOST',		'type' => 'text:25:100', 'explain' => true),
d6e8d8
		'src_dbport'		=> array('lang' => 'DB_PORT',		'type' => 'text:25:100', 'explain' => true),
d6e8d8
		'src_dbname'		=> array('lang' => 'DB_NAME',		'type' => 'text:25:100', 'explain' => false),
d6e8d8
		'src_dbuser'		=> array('lang' => 'DB_USERNAME',	'type' => 'text:25:100', 'explain' => false),
d6e8d8
		'src_dbpasswd'		=> array('lang' => 'DB_PASSWORD',	'type' => 'password:25:100', 'explain' => false),
d6e8d8
		'src_table_prefix'	=> array('lang' => 'TABLE_PREFIX',	'type' => 'text:25:100', 'explain' => false),
d6e8d8
		//'src_url'			=> array('lang' => 'FORUM_ADDRESS',	'type' => 'text:50:100', 'explain' => true),
d6e8d8
		'forum_path'		=> array('lang' => 'FORUM_PATH',	'type' => 'text:25:100', 'explain' => true),
d6e8d8
		'refresh'			=> array('lang' => 'REFRESH_PAGE',	'type' => 'radio:yes_no', 'explain' => true),
d6e8d8
	);
d6e8d8
}
d6e8d8
d6e8d8
?>