<?php 
if (!defined('IDIR')) { die; }
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin
|| # ---------------------------------------------------------------- # ||
|| # All PHP code in this file is ©2000-2010 Jelsoft Enterprises Ltd. # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbsupport.org/forum/index.php | http://www.vbsupport.org/forum/index.php # ||
|| #################################################################### ||
\*======================================================================*/
/**
* wbb3_001
*
* @package 		ImpEx.wbb3
* @version		$Revision: $
* @author		Jerry Hutchings <jerry.hutchings@vbulletin.com>
* @checkedout	$Name$
* @date 		$Date: $
* @copyright 	http://www.vbsupport.org/forum/index.php
*
*/

class wbb3_001 extends wbb3_000
{
	function wbb3_001(&$displayobject)
	{
		$this->_modulestring = $displayobject->phrases['check_update_db'];
	}

	function init(&$sessionobject, &$displayobject, &$Db_target, &$Db_source)
	{
		$displayobject->update_basic('title', $displayobject->phrases['get_db_info']);
		$displayobject->update_html($displayobject->do_form_header('index','001'));
		$displayobject->update_html($displayobject->make_table_header($displayobject->phrases['get_db_info']));
		$displayobject->update_html($displayobject->make_hidden_code('database','working'));

		$displayobject->update_html($displayobject->make_description($displayobject->phrases['check_tables']));

		$displayobject->update_html($displayobject->make_input_code('The table prefix for the installed wBB3 forum', 'forum_prefix', 'wbb1_1_'));
		$displayobject->update_html($displayobject->do_form_footer($displayobject->phrases['check_update_db'],''));
		$sessionobject->add_session_var(substr(get_class($this) , -3) . '_objects_done', '0');
		$sessionobject->add_session_var(substr(get_class($this) , -3) . '_objects_failed', '0');
	}

	function resume(&$sessionobject, &$displayobject, &$Db_target, &$Db_source)
	{
		if (!$sessionobject->get_session_var('sourceexists'))
		{
			$displayobject->display_error($displayobject->phrases['sourceexists_is_false']);
			exit;
		}

		// Setup some working variables
		$displayobject->update_basic('displaymodules','FALSE');
		$target_db_type 		= $sessionobject->get_session_var('targetdatabasetype');
		$target_table_prefix 	= $sessionobject->get_session_var('targettableprefix');
		$source_db_type			= $sessionobject->get_session_var('sourcedatabasetype');
		$source_table_prefix 	= $sessionobject->get_session_var('sourcetableprefix');

		$class_num        = substr(get_class($this) , -3);

		if(!$sessionobject->get_session_var($class_num . '_start'))
		{
			$sessionobject->timing($class_num, 'start' ,$sessionobject->get_session_var('autosubmit'));
		}


		$displayobject->update_basic('title',$displayobject->phrases['altering_tables']);
		$displayobject->display_now("<h4>{$displayobject->phrases['altering_tables']}</h4>");
		$displayobject->display_now($displayobject->phrases['alter_desc_1']);
		$displayobject->display_now($displayobject->phrases['alter_desc_2']);
		$displayobject->display_now($displayobject->phrases['alter_desc_3']);
		$displayobject->display_now($displayobject->phrases['alter_desc_4']);

	/*	
		// Jig the tables we want, then do it every time in the function ....... ugh .....
		$jiggy = array('board', 'board_hidden_to_user', 'board_last_post', 'board_moderator', 'board_structure', 'board_subscription',
		'board_to_group', 'board_to_user', 'board_visit', 'post', 'post_cache', 'post_hash', 'post_report', 'thread',
		'thread_announcement', 'thread_rating', 'thread_similar', 'thread_subscription', 'thread_visit', 'user');
		
		foreach ($jiggy AS $tablename)
		{
			$this->_valid_tables[] = $forum_prefix.$tablename;
			unset($this->_valid_tables[$source_table_prefix.$tablename]);	
		}
*/
		// Add an importids now
		foreach ($this->_import_ids as $id => $table_array)
		{
			foreach ($table_array as $tablename => $column)
			{
				if ($this->add_import_id($Db_target, $target_db_type, $target_table_prefix, $tablename, $column))
				{
					$displayobject->display_now("\n<br /><b>$tablename</b> - $column <i>{$displayobject->phrases['completed']}</i>");
				}
				else
				{
					$sessionobject->add_error($Db_target, 'fatal', $class_num, 0, $displayobject->phrases['table_alter_fail'], $displayobject->phrases['table_alter_fail_rem']);
					exit;
				}
			}
		}

		// Add the importpostid indexs
		$this->add_index($Db_target, $target_db_type, $target_table_prefix, 'user');
		$this->add_index($Db_target, $target_db_type, $target_table_prefix, 'post');
		#$this->add_index($Db_target, $target_db_type, $target_table_prefix, 'thread');

		if($sessionobject->get_session_var('added_default_unknown_group') != 'yup')
		{
			$try = new ImpExData($Db_target, $sessionobject, 'usergroup');
			$try->set_value('mandatory', 'importusergroupid',		'69');
			$try->set_value('nonmandatory', 'title',				"Active {$displayobject->phrases['imported']} {$displayobject->phrases['users']}");
			$try->import_usergroup($Db_target, $target_db_type, $target_table_prefix);
			$sessionobject->add_session_var('added_default_unknown_group', 'yup');
			unset($try);


			$sessionobject->add_session_var('added_default_unknown_group', 'yup');
			unset($try);
		}

		// Check the database connection
		$result = $this->check_database($Db_source, $source_db_type, $source_table_prefix, $sessionobject->get_session_var('sourceexists'));

		$displayobject->display_now($result['text']);

		if ($result['code'])
		{
			$sessionobject->timing($class_num, 'stop', $sessionobject->get_session_var('autosubmit'));
			$sessionobject->remove_session_var($class_num . '_start');

			$displayobject->update_html($displayobject->module_finished($this->_modulestring,
				$sessionobject->return_stats($class_num, '_time_taken'),
				$sessionobject->return_stats($class_num, '_objects_done'),
				$sessionobject->return_stats($class_num,'_objects_failed')
			));

			$sessionobject->add_session_var($class_num . '_objects_done',intval($sessionobject->get_session_var($class_num . '_objects_done')) + 1 );
			$sessionobject->set_session_var(substr(get_class($this), -3), 'FINISHED');
			$sessionobject->set_session_var('module','000');
			$displayobject->update_basic('displaymodules','FALSE');
			$displayobject->update_html($displayobject->print_redirect_001('index.php',$sessionobject->get_session_var('pagespeed')));
		}
		else
		{
			$sessionobject->add_session_var($class_num . '_objects_failed',intval($sessionobject->get_session_var($class_num . '_objects_failed')) + 1 );
			$sessionobject->add_error($Db_target, 'fatal', $class_num, 0, $displayobject->phrases['table_check_error'], $displayobject->phrases['check_db_permissions']);

			$displayobject->update_html($displayobject->make_description("{$displayobject->phrases['failed']} {$displayobject->phrases['check_db_permissions']}"));
			$sessionobject->set_session_var('001','FAILED');
			$sessionobject->set_session_var('module','000');
			$displayobject->update_html($displayobject->print_redirect_001('index.php',$sessionobject->get_session_var('pagespeed')));
		}
	}
}
/*======================================================================*\
|| ####################################################################
|| # NulleD By - FintMax
|| # CVS: $RCSfile$ - $Revision: $
|| ####################################################################
\*======================================================================*/
?>
