<?php

header("Content-Type: text/html; charset=UTF-8");

define('INSTALL_FOLDER', dirname(__FILE__) . DIRECTORY_SEPARATOR);

@ini_set('display_errors', 1);
@error_reporting(E_ALL);

@set_time_limit(9000);
//ini_set('memory_limit', '64M');
ini_set('max_execution_time', '9000');

if (isset($_POST['hostcms']['action']) && ($_POST['hostcms']['action'] == 'step_6' || $_POST['hostcms']['action'] == 'step_7' || $_POST['hostcms']['action'] == 'step_8' || $_POST['hostcms']['action'] == 'step_9'))
{
	require_once('../bootstrap.php');
}
else
{
	/* Решение проблемы trict Standards: Implicit cloning object of class 'kernel' because of 'zend.ze1_compatibility_mode' */
	if (version_compare(PHP_VERSION, '5.3', '<'))
	{
		ini_set('zend.ze1_compatibility_mode', 0);
	}

	define('HOSTCMS', TRUE);
	define('DEFAULT_LNG', 'ru');
	// rtrim fix IIS bug with trailing slash
	define('CMS_FOLDER', rtrim(realpath(dirname(__FILE__) . '/../'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
	require_once(CMS_FOLDER . 'modules/core/core.php');

	Core::setModulesPath();
	Core::registerCallbackFunction();
	Core::$config = Core_Config::instance();
	Core::mainConfig();

	mb_internal_encoding('UTF-8');
}

!defined('TMP_DIR') && define('TMP_DIR', 'hostcmsfiles/tmp/');

$lng = strtolower(htmlspecialchars(
	substr(Core_Array::get($_SERVER, 'HTTP_ACCEPT_LANGUAGE'), 0, 2)
));

(isset($_REQUEST[session_name()]) || isset($_COOKIE[session_name()])) && !isset($_SESSION) && @session_start();

ob_start();

if (!is_null(Core_Array::getGet('skinName')))
{
	$skinName = Core_Array::getGet('skinName');

	$aConfig = Core_Config::instance()->get('skin_config');
	if (isset($aConfig[$skinName]))
	{
		Core::$mainConfig['skin'] = $_SESSION['skin'] = $skinName;
	}
	else
	{
		throw new Core_Exception('Skin does not allow.');
	}
}
elseif(isset($_SESSION['skin']))
{
	Core::$mainConfig['skin'] = $_SESSION['skin'];
}

$aInstallConfig = Core_Config::instance()->get('install_config');
$aLng = Core_Array::get($aInstallConfig, 'lng', array());

if (isset($aLng[$lng]))
{
	// Устанавливаем полученный язык
	Core_I18n::instance()->setLng($lng);
	Core_Skin::instance()->setLng($lng);
}

$oAdmin_Answer = Core_Skin::instance()->answer();

$openWindow = TRUE;

$formSettings = Core_Array::getPost('hostcms', array())
	+ array(
		'action' => NULL,
		'window' => 'id_content',
	);

$windowId = Core_Str::escapeJavascriptVariable($formSettings['window']);

$lng_value = Core_Array::getPost('lng_value');
if (isset($aLng[$lng_value]))
{
	!isset($_SESSION) && @session_start();
	$_SESSION['LNG_INSTALL'] = $lng_value;
}

$lngName = isset($_SESSION['LNG_INSTALL']) ? $_SESSION['LNG_INSTALL'] : DEFAULT_LNG;
Core_I18n::instance()->setLng($lngName);

// Минимальные требования к системе
define('PHP_version', '5.2.2');
define('MySQL_version', '5.0.0');
define('GD_version', '2.0');
define('PCRE_version', '7.0');
define('JSON', Core::_('install.constant_on'));
define('MbString', Core::_('install.constant_on'));
define('SimpleXML', Core::_('install.constant_on'));
define('Iconv', Core::_('install.constant_on'));
define('XSLT', Core::_('install.supported'));
define('Data_limit', '2'); // Mb
define('TIME_limit', '30'); // Sec
define('DISC_space', '30'); // Mb
define('RAM_space', '32M');
define('SAFE_MODE', Core::_('install.constant_off'));
define('REGISTER_GLOBALS', Core::_('install.constant_off'));
define('MAGIC_QUOTES_GPC', Core::_('install.constant_off'));
define('DUMP_file', 'dump_41.sql');
define('LICENCE_file', 'licence.txt');
define('FILE_MODE', 644); // Права на доступ к файлам
define('DIR_MODE', 755); // Права на доступ к директориям
define('CHMOD_FILE', octdec(FILE_MODE));
define('CHMOD', octdec(DIR_MODE));

$Site_Controller_Template = Site_Controller_Template::instance()
	->templatePath(CMS_FOLDER . TMP_DIR)
	->chmodFile(octdec(FILE_MODE))
	->server('http://www.hostcms.ru');

// Step 0: Set language
if (!is_null(Core_Array::getPost('step_0')))
{
	// Show step 1
	Core_Skin::instance()->setMode('step_1');
	$title = Core::_('Install.step_1');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();

	echo Core::_('install.attention_message4');
	?>
	<form method="post" action="index.php" id="install">
		<?php
		Core::factory('Admin_Form_Entity_Button')
			->name('process')
			->type('submit')
			->value(Core::_('install.next'))
			->class('applyButton')
			->onclick(
				"$.adminSendForm({buttonObject: this,action: 'step_2',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
			)
			->execute();
		?>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_2')
{
	// Show step 2
	Core_Skin::instance()->setMode('step_2');
	$title = Core::_('Install.step_2');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();

	?><form method="post" action="index.php" id="install">
		<div style="height: 300px; width: 100%; overflow: auto; border: 1px solid #E1E1E1; padding: 5px"><?php echo nl2br(Core_File::read(LICENCE_file))?></div>

		<p><label><input type="checkbox" name="license_agree" value="on" onclick="$('#applyButton').toggleDisabled()"><?php echo Core::_('install.license_agreement')?></label></p>

		<?php
		Core::factory('Admin_Form_Entity_Button')
			->name('process')
			->type('submit')
			->value(Core::_('install.next'))
			->class('applyButton')
			->id('applyButton')
			->disabled('disabled')
			->onclick(
				"$.adminSendForm({buttonObject: this,action: 'step_3',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
			)
			->execute();
		?>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_3')
{
	// Show step 3
	Core_Skin::instance()->setMode('step_3');
	$title = Core::_('Install.step_3');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();

	/*if (isset($_POST['step2']) && !isset($_POST['license_agree']))
	{
		?><div id="error_message"><?php echo Core::_('install.license_agreement_error')?></div><?php
	}*/
	?><form method="post" action="index.php" id="install">
	<table width="100%" cellpadding="2" cellspacing="2" class="admin_table">
		<tr class="admin_table_title">
			<td width="350"><strong><?php echo Core::_('install.table_field_param')?></strong></td>
			<td width="140"><strong><?php echo Core::_('install.table_field_need')?></strong></td>
			<td width="140"><strong><?php echo Core::_('install.table_field_thereis')?></strong></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_php_version')?></td>
			<td><?php echo PHP_version?></td>
			<td><?php
			$php = phpversion();
			$php = $php ? $php : Core::_('install.undefined');
			?> <?php showbullet(version_compare(phpversion(), PHP_version, ">=") ? 0 : 2, $php)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_gd_version')?></td>
			<td><?php echo GD_version?></td>
			<td><?php
			$gd = Core_Image::instance('gd')->getVersion();
			$gd = $gd ? $gd : Core::_('install.undefined');
			?> <?php showbullet(version_compare($gd, GD_version, ">=") ? 0 : 2, $gd)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_pcre_version')?></td>
			<td><?php echo PCRE_version?></td>
			<td><?php
			$pcre = Core::getPcreVersion();
			$pcre = $pcre ? $pcre : Core::_('install.undefined');
			?> <?php showbullet(version_compare($pcre, PCRE_version, ">=") ? 0 : 2, $pcre)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_mbstring')?></td>
			<td><?php echo MbString?></td>
			<td><?php
			$mb = function_exists('mb_internal_encoding')
				? Core::_('install.constant_on')
				: Core::_('install.constant_off');
			?> <?php showbullet(function_exists('mb_internal_encoding') ? 0 : 2, $mb)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_json')?></td>
			<td><?php echo JSON?></td>
			<td><?php
			$mb = function_exists('json_encode')
				? Core::_('install.constant_on')
				: Core::_('install.constant_off');
			?> <?php showbullet(function_exists('json_encode') ? 0 : 2, $mb)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_simplexml')?></td>
			<td><?php echo SimpleXML?></td>
			<td><?php
			$SimpleXML = function_exists('simplexml_load_string')
				? Core::_('install.constant_on')
				: Core::_('install.constant_off');
			?> <?php showbullet(function_exists('simplexml_load_string') ? 0 : 2, $SimpleXML)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_iconv')?></td>
			<td><?php echo Iconv?></td>
			<td><?php
			$iconv = function_exists('iconv')
				? Core::_('install.constant_on')
				: Core::_('install.constant_off');
			?> <?php showbullet(function_exists('iconv') ? 0 : 2, $iconv)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_xslt_support')?></td>
			<td><?php echo XSLT?></td>
			<td><?php
			$xslt = (function_exists('xslt_create')
			|| function_exists('domxml_xslt_stylesheet')
			|| (class_exists('DomDocument') && class_exists('XsltProcessor')))
				? XSLT
				: Core::_('install.unsupported');
			?> <?php showbullet(($xslt == XSLT) ? 0 : 2, $xslt)?></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_maximum_upload_data_size')?></td>
			<td><?php echo Data_limit?>М</td>
			<td><?php
			$d_l = ini_get('post_max_size')
			? ini_get('post_max_size')
			: Core::_('install.undefined');
			?> <?php showbullet(($d_l != Core::_('install.undefined') && version_compare($d_l, Data_limit, ">=")) ? 0 : 2, $d_l)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_maximum_execution_time')?></td>
			<td><?php echo TIME_limit . " " . Core::_('install.seconds')?></td>
			<td><?php
			$t_l = ini_get('max_execution_time')
			? ini_get('max_execution_time')
			: Core::_('install.undefined');
			?> <?php showbullet(($t_l != Core::_('install.undefined') && $t_l >= TIME_limit) ? 0 : 2,
				($t_l != Core::_('install.undefined'))
					? $t_l . " " . Core::_('install.seconds')
					: $t_l)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_disc_space')?></td>
			<td><?php echo DISC_space . Core::_('install.megabytes')?></td>
			<td><?php
			$d_s = @disk_free_space($_SERVER['DOCUMENT_ROOT']);
			$d_s = $d_s ? round($d_s / 1024 / 1024, 2)
			: Core::_('install.undefined');
			?> <?php showbullet(($d_s != Core::_('install.undefined') && $d_s >= DISC_space)
			? 0 : 2,
			($d_s != Core::_('install.undefined'))
			? $d_s.Core::_('install.megabytes') : $d_s)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_ram_space')?></td>
			<td><?php echo RAM_space?></td>
			<td><?php
			$r_s = ini_get('memory_limit')
			? ini_get('memory_limit')
			: Core::_('install.undefined');
			?> <?php showbullet(($r_s != Core::_('install.undefined')
				&& Core_Str::convertSizeToBytes($r_s) >= Core_Str::convertSizeToBytes(RAM_space))
			? 0
			: (($r_s != Core::_('install.undefined')) ? 2 : 1), $r_s)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_safe_mode')?></td>
			<td><?php echo SAFE_MODE?></td>
			<td><?php
			$s_m = (ini_get('safe_mode') == 1)
			? Core::_('install.constant_on')
			: Core::_('install.constant_off');
			?> <?php showbullet(($s_m == SAFE_MODE) ? 0 : 1, $s_m)?></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_register_globals')?></td>
			<td><?php echo REGISTER_GLOBALS?></td>
			<td><?php
			$r_g = (ini_get('register_globals') == 1)
			? Core::_('install.constant_on')
			: Core::_('install.constant_off');
			?> <?php showbullet(($r_g == REGISTER_GLOBALS)
				? 0
				: 1, $r_g)?></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.table_field_magic_quotes_gpc')?></td>
			<td><?php echo MAGIC_QUOTES_GPC?></td>
			<td><?php
			$m_q = (ini_get('magic_quotes_gpc') == 1 || ini_get('magic_quotes_runtime') == 1 || ini_get('magic_quotes_sybase') == 1)
			? Core::_('install.constant_on')
			: Core::_('install.constant_off');
			?> <?php showbullet(($m_q == MAGIC_QUOTES_GPC)
			? 0
			: 1, $m_q)?></td>
		</tr>
	</table>

	<p><?php showbullet(0, Core::_('install.parameter_corresponds'))?> <?php showbullet(1, Core::_('install.parameter_not_corresponds_but_it_is_safe'))?>
		<?php showbullet(2, Core::_('install.parameter_not_corresponds'))?></p>

	<?php
	Core::factory('Admin_Form_Entity_Button')
		->name('process')
		->type('submit')
		->value(Core::_('install.next'))
		->class('applyButton')
		->onclick(
			"$.adminSendForm({buttonObject: this,action: 'step_4',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
		)
		->execute();
	?>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_4')
{
	// Show step 4
	Core_Skin::instance()->setMode('step_4');
	$title = Core::_('Install.step_4');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();

	?><form method="post" action="index.php" id="install">
	<table border="0" cellspacing="2" cellpadding="2" class="admin_table">
		<tr class="admin_table_title">
			<td colspan="2"><?php echo Core::_('install.access_parameter')?></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.file_access')?></td>
			<td><input type="text" name="file_mode" size="3"
				value="<?php echo FILE_MODE?>"> <small><?php echo Core::_('install.example', FILE_MODE)?></small>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.directory_access')?></td>
			<td><input type="text" name="dir_mode" size="3"
				value="<?php echo DIR_MODE?>"> <small><?php echo Core::_('install.example', DIR_MODE)?></small>
			</td>
		</tr>
		<tr class="admin_table_title">
			<td colspan="2"><?php echo Core::_('install.database_params')?></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.mysql_server')?></td>
			<td><input type="text" name="host" size="30" value=""> <br />
			<small><?php echo Core::_('install.example', 'localhost')?></small></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.database_login')?></td>
			<td><input type="text" name="user" size="30" value=""></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.database_pass')?></td>
			<td><input type="password" name="password" size="30" value=""></td>
		</tr>
		<tr class="row">
			<td align="left" valign="top"><?php echo Core::_('install.database_mysql')?></td>
			<td valign="top"><input type="text" name="database" size="30" value="">
			</td>
		</tr>
		<tr class="row">
			<td align="left" valign="top"><?php echo Core::_('install.create_database')?></td>
			<td valign="top"><input id="create_base_id" type="checkbox"
				class="input_not_border" name="create_database" value="on"> <label
				for="create_base_id"><?php echo Core::_('install.create_database_flag')?></label></td>
		</tr>
		<tr class="row">
			<td align="left" valign="top"><?php echo Core::_('install.clear_database')?></td>
			<td valign="top"><input id="clear_database_id" type="checkbox"
				class="input_not_border" name="clear_database" value="on"> <label
				for="clear_database_id"><?php echo Core::_('install.yes')?></label>
			<div id="error_message"><?php echo Core::_('install.clear_database_caution')?></div>
			</td>
		</tr>
	</table>
	<p>
	<?php
	Core::factory('Admin_Form_Entity_Button')
		->name('process')
		->type('submit')
		->value(Core::_('install.next'))
		->class('applyButton')
		->onclick(
			"$.adminSendForm({buttonObject: this,action: 'step_5',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
		)
		->execute();
	?>
	</p>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_5')
{
	// Show step 5
	Core_Skin::instance()->setMode('step_5');
	$title = Core::_('Install.step_5');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();

	// Если передано значение прав доступа к файлам
	$file_mode = octdec(Core_Array::getRequest('file_mode', FILE_MODE));
	$dir_mode = octdec(Core_Array::getRequest('dir_mode', DIR_MODE));

	// Устанавливаем права
	setChmod(CMS_FOLDER, $file_mode, $dir_mode);

	$sConfigPath = CMS_FOLDER . 'modules/core/config/database.php';

	/*$configContent = Core_File::read($sConfigPath);
	$configContent = str_replace(
		array(
			"defined('DB_HOST') ? DB_HOST : NULL",
			"defined('DB_USER_NAME') ? DB_USER_NAME : NULL",
			"defined('DB_PASSWORD') ? DB_PASSWORD : NULL",
			"defined('DB_NAME') ? DB_NAME : NULL",
		), array(
			"'" . addslashes($_POST['host']) . "'",
			"'" . addslashes($_POST['user']) . "'",
			"'" . addslashes($_POST['password']) . "'",
			"'" . addslashes($_POST['database']) . "'",
		), $configContent
	);*/

	$host = trim(Core_Array::getPost('host'));
	$user = trim(Core_Array::getPost('user'));
	$password = trim(Core_Array::getPost('password'));
	$database = trim(Core_Array::getPost('database'));

	$configContent = "<?php

return array (
	'default' => array (
		'driver' => 'mysql',
		'host' => '" . addslashes($host) . "',
		'username' => '" . addslashes($user) . "',
		'password' => '" . addslashes($password) . "',
		'database' => '" . addslashes($database) . "'
	)
);";

	try
	{
		$flag = Core_File::write($sConfigPath, $configContent, $file_mode);
	}
	catch (Exception $e)
	{
		$flag = FALSE;
		Core_Message::show($e->getMessage(), 'error');
	}

	?><form method="post" action="index.php">
	<table border="0" cellspacing="2" cellpadding="2" class="admin_table">
		<tr class="admin_table_title">
			<td width="220"><?php echo Core::_('install.action')?></td>
			<td><?php echo Core::_('install.result')?></td>
			<td><?php echo Core::_('install.comment')?></td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.store_database_params')?></td>
			<td><?php showbullet($flag ? 0 : 2, $flag ? Core::_('install.success') : Core::_('install.error'))?></td>
			<td><?php echo $flag ? '' : Core::_('install.not_enough_rights_error', $sConfigPath)?>
			</td>
		</tr>
		<tr class="row">
			<td><?php echo Core::_('install.database_connection')?></td>
			<td><?php
			$Core_DataBase = new Core_DataBase_Mysql(array(
				'host' => $host,
				'username' => $user,
				'password' => $password,
				'database' => NULL
			));

			try
			{
				$Core_DataBase->connect();
				$connect_db = TRUE;
			}
			catch (Exception $e)
			{
				$connect_db = FALSE;
			}

			$flag = $flag && $connect_db;
			?> <?php showbullet($connect_db ? 0 : 2, $connect_db
			? Core::_('install.success')
			: Core::_('install.sql_error', mysql_errno(), mysql_error()))?>

			<td><?php echo $connect_db ? '' : Core::_('install.database_connection_check_params')?>
			</td>
		</tr>
		<?php

		if (isset($_POST['create_database']) && $_POST['create_database'] == 'on')
		{
		?>
		<tr class="row">
			<td><?php echo Core::_('install.database_creation')?></td>
			<td><?php
			try
			{
				$Core_DataBase->setQueryType(99)->query(
					'CREATE DATABASE IF NOT EXISTS ' . $Core_DataBase->quoteColumnName($database)
				);
				$create_db = TRUE;
			}
			catch (Exception $e)
			{
				$create_db = FALSE;
			}

			$flag = $flag && $create_db;
			?> <?php showbullet($create_db ? 0 : 2, $create_db ? Core::_('install.success') : Core::_('install.sql_error', mysql_errno(), mysql_error()))?>

			<td><?php echo $create_db ? '' : Core::_('install.attention_message')?>
			</td>
		</tr>
		<?php
		}
		?>
		<tr class="row">
			<td><?php echo Core::_('install.database_selection')?></td>
			<td><?php
			try
			{
				$Core_DataBase->selectDb($database);
				$select_db = TRUE;
			}
			catch (Exception $e)
			{
				$select_db = FALSE;
			}

			$flag = $flag && $select_db;
			?> <?php showbullet($select_db ? 0 : 2, $select_db
				? Core::_('install.success')
				: Core::_('install.sql_error', mysql_errno(), mysql_error())
			)?>
			</td>
			<td><?php echo ($select_db) ? '' : Core::_('install.database_selection_access_denied')?>
			</td>
		</tr>
		<?php
		// Очистка базы
		if (isset($_POST['clear_database']))
		{
			?><tr class="row">
			<td><?php echo Core::_('install.database_clearing')?></td>
			<td><?php

			//Удаление всех таблиц текущего соединения
			try
			{
				$aTables = $Core_DataBase->getTables();
				foreach ($aTables as $sTable) {
					$Core_DataBase->setQueryType(6)->query('DROP TABLE ' . $Core_DataBase->quoteColumnName($sTable));
				}
				$e_b = true;
			}
			catch (Exception $e)
			{
				Core_Message::show($e->getMessage(), 'error');
				$e_b = false;
			}

			?> <?php showbullet($e_b ? 0 : 2, $e_b
				? Core::_('install.success')
				: Core::_('install.error'))?>
			</td>
			<td></td>
			</tr>
			<?php
		}

		if ($select_db)
		{
		?>
		<tr class="row">
			<td><?php echo Core::_('install.sql_dump_loading')?></td>
			<td><?php
				try
				{
					$dumpfile = Core_File::read(DUMP_file);

					$e_b = Sql_Controller::instance()->execute($dumpfile);
					$flag = $flag && $e_b;
				}
				catch (Exception $e) {
					$flag = FALSE;
					Core_Message::show($e->getMessage(), 'error');
				}
				?> <?php showbullet($e_b ? 0 : 2, $e_b
					? Core::_('install.success')
					: Core::_('install.sql_dump_loading_error', mysql_get_client_info()))?>
			</td>
			<td></td>
		</tr>
		<?php
		}
		/*?>
		<tr class="row">
			<td><?php echo Core::_('install.domen_installing')?></td>
			<td><?php

			$domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);

			if ($select_db)
			{
				$e_b = @mysql_query("UPDATE `site_alias_table` SET `alias_name` = '*.".mysql_escape_string($domain)."'");
				showbullet($e_b ? 0 : 2,
				$e_b
					? Core::_('install.success')
					: Core::_('install.sql_error', mysql_errno(), mysql_error()));
			}
			?>
			</td>
			<td></td>
		</tr>
		<?php */
		if ($select_db)
		{
		?><tr class="row">
			<td><?php echo Core::_('install.lng_installing')?></td>
			<td><?php
				$e_b = FALSE;
				try
				{
					$oConstant = Core_Entity::factory('Constant')->getByName('DEFAULT_LNG');

					if ($oConstant)
					{
						$oConstant->value = $lngName;
						$oConstant->save();
						$e_b = TRUE;
					}
				}
				catch (Exception $e) {
					Core_Message::show($e->getMessage(), 'error');
				}

				showbullet($e_b ? 0 : 2, $e_b ? Core::_('install.success') : Core::_('install.sql_error', mysql_errno(), mysql_error()));
			?>
			</td>
			<td></td>
		</tr><?php
		}
		?>
	</table>
	<p>
	<?php
	if ($flag)
	{
		Core::factory('Admin_Form_Entity_Button')
			->name('process')
			->type('submit')
			->value(Core::_('install.next'))
			->class('applyButton')
			->onclick(
				"$.adminSendForm({buttonObject: this,action: 'step_6',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
			)
			->execute();
	}
	else
	{
		Core::factory('Admin_Form_Entity_Button')
			->name('process')
			->type('submit')
			->value(Core::_('install.back'))
			->class('saveButton')
			->onclick(
				"$.adminSendForm({buttonObject: this,action: 'step_4',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
			)
			->execute();
	}
	?>
	</p>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_6')
{
	// Show step 6
	Core_Skin::instance()->setMode('step_6');
	$title = Core::_('Install.step_6');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();
	?><form method="post" action="index.php"><?php

	try
	{
		$oXml = $Site_Controller_Template->loadTemplatesXml();
		?>
		<div id="gallery">
			<?php
			$aGroups = $oXml->children();

			$iKeyGroup = 0;
			// цикл по дереву group
			foreach ($aGroups as $oGroup)
			{
				// если в группе есть шаблоны
				if ($oGroup->templates) {
					$iKeyTemplate = 0;
					// цикл по дереву template
					foreach ($oGroup->templates->template as $oTemplate)
					{
						if (strlen(trim((string)$oTemplate->template_file6)))
						{
							$small_width = (string)$oTemplate->template_preview['width'];
							$small_height = 200 + 40;
							// вывод информации о шаблоне
							?>
							<div class="site_template_block">
							<div class="bord_img" style="width: <?php echo $small_width?>px; height:<?php echo $small_height?>px;">

								<a href="<?php echo $Site_Controller_Template->server . trim((string)$oTemplate->template_full_preview)?>" target="_blank">
								<img src="<?php echo $Site_Controller_Template->server . trim((string)$oTemplate->template_preview)?>" width="<?php echo $small_width?>" />
								</a>

								<div class="bottom">
									<input style="float: left" type="radio" <?php if($iKeyTemplate == 0 && $iKeyGroup == 0) {echo 'checked="checked"';} ?> name="template_id" id="template_<?php echo (string)$oTemplate['id']?>" value="<?php echo (string)$oTemplate['id']?>" />

									<label for="template_<?php echo (string)$oTemplate['id']?>" style="margin-left: 5px; float: left">
										<b><?php echo (string)$oTemplate->template_name?></b>
										<br />
										<span><?php echo (string)$oGroup->group_name?></span>
									</label>
								</div>
							</div>
							</div>
							<?php
						}
						$iKeyTemplate++;
					}
				}

				$iKeyGroup++;

				// Для HostCMS-6 доступен только основной макет
				//break;
			}
		?>
		</div>

		<div style="clear: both"></div>
		<?php
	}
	catch (Exception $e)
	{
		Core_Message::show($e->getMessage(), 'error');
	}

	Core::factory('Admin_Form_Entity_Button')
		->name('process')
		->type('submit')
		->value(Core::_('install.next'))
		->class('applyButton')
		->onclick(
			"$.adminSendForm({buttonObject: this,action: 'step_7',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
		)
		->execute();
	?>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_7')
{
	// Show step 7
	Core_Skin::instance()->setMode('step_7');
	$title = Core::_('Install.step_7');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();
	?><form method="post" action="index.php"><?php

	try
	{
		$oXml = $Site_Controller_Template->loadTemplatesXml();

		$iTemplateId = intval(Core_Array::getPost('template_id'));
		$Templates = $oXml->xpath("//group/templates/template[@id='{$iTemplateId}']");

		if (isset($Templates[0]))
		{
			// у выбранного шаблона есть цветовые схемы
			if (count($Templates[0]->template_types->template_type) > 0)
			{
				?>
				<div id="gallery">
				<?php
				// цикл по цветовым схемам
				foreach ($Templates[0]->template_types as $iKeyTemplateType => $oTemplateType)
				{
					$small_width = (string)$oTemplateType->template_type_full_preview['width'];
					$small_height = 200 + 40;

					?><div class="bord_img" style="width: <?php echo $small_width?>px; height:<?php echo $small_height?>px;">

					<a href="<?php echo $Site_Controller_Template->server . trim((string)$oTemplateType->template_type_full_preview)?>">
					<img src="<?php echo $Site_Controller_Template->server . trim((string)$oTemplateType->template_type_preview)?>"
					width="<?php echo $small_width?>" />
					</a>

					<div style="position: absolute; width: 100%; bottom: 5px;">
						<input style="float: left;" type="radio" <?php echo ($iKeyTemplateType == 0) ? 'checked="checked"' : ''?> name="template_id" id="template_<?php echo (string)$oTemplateType['id']?>" value="<?php echo (string)$oTemplateType['id']?>" />

						<label for="template_<?php echo (string)$oTemplateType['id']?>" style="margin-left: 5px; float: left">
							<b><?php echo (string)$oTemplateType->template_type_name?></b>
						</label>
						</div>
					</div>
					<?php
				}
				?>
				</div>
				<?php
			}
		}
		else
		{
			Core_Message::show(Core::_('install.templates_dont_exist'), 'error');
		}
		?>
		<input type="hidden" name="template_id" value="<?php echo $iTemplateId ?>" />
		<div style="clear: both"></div>
		<?php
	}
	catch (Exception $e)
	{
		Core_Message::show($e->getMessage(), 'error');
	}

	Core::factory('Admin_Form_Entity_Button')
		->name('process')
		->type('submit')
		->value(Core::_('install.back'))
		->class('saveButton')
		->onclick(
			"$.adminSendForm({buttonObject: this,action: 'step_6',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
		)
		->execute();

	Core::factory('Admin_Form_Entity_Button')
		->name('process')
		->type('submit')
		->value(Core::_('install.next'))
		->class('applyButton')
		->onclick(
			"$.adminSendForm({buttonObject: this,action: 'step_8',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
		)
		->execute();
	?>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_8')
{
	// Show step 8
	Core_Skin::instance()->setMode('step_8');
	$title = Core::_('Install.step_8');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();

	?><form method="post" action="index.php"><?php

	try
	{
		$oXml = $Site_Controller_Template->loadTemplatesXml();

		$iTemplateId = intval(Core_Array::getPost('template_id'));
		$iTemplateTypeId = intval(Core_Array::getPost('template_type_id'));

		$Templates = $oXml->xpath("//group/templates/template[@id='{$iTemplateId}']");

		if (isset($Templates[0]))
		{
			$Template = $Templates[0];

			// ссылка на макет файла
			$sTemplateFile = (string)$Template->template_file6;

			try
			{
				$driverName = Site_Controller_Template::getDriverName();

				$Core_Http = Core_Http::instance($driverName)
					->url($Site_Controller_Template->server . $sTemplateFile)
					->port(80)
					->timeout(30)
					->execute();

				$sFileContents = $Core_Http->getBody();
			}
			catch (Exception $e)
			{
				Core_Message::show($e->getMessage(), 'error');
				$sFileContents = NULL;
			}

			// название архива макета
			$aTemplateFileUrl = explode('/', $Site_Controller_Template->server . $sTemplateFile);
			$sTemplateFileName = end($aTemplateFileUrl);

			// путь к локальному архиву макета
			$sTemplateFileUrl = $Site_Controller_Template->templatePath . $sTemplateFileName;

			try
			{
				// запись в файл данных макета
				if (Core_File::write($sTemplateFileUrl, $sFileContents, octdec(FILE_MODE)))
				{
					// распаковка архива макета
					$Core_Tar = new Core_Tar($sTemplateFileUrl);
					$Core_Tar->extractModify($Site_Controller_Template->templatePath, $Site_Controller_Template->templatePath);
				}
				else
				{
					Core_Message::show(Core::_('install.write_error', $sTemplateFileUrl), 'error');
				}
			}
			catch (Exception $e)
			{
				$flag = FALSE;
				Core_Message::show($e->getMessage(), 'error');
			}

			// Массив из файла template.xml
			$oTemplateContentXml = $Site_Controller_Template->loadSelectedTemplateXml();

			if($oTemplateContentXml)
			{
				$aXmlFields = $oTemplateContentXml->xpath("fields/field");

				if (count($aXmlFields))
				{
					?><p><?php echo Core::_('install.template_data_information')?></p>
					<table border="0" cellspacing="2" cellpadding="2" class="admin_table">
					<tr class="admin_table_title">
						<td><?php echo Core::_('install.table_field_param')?></td>
						<td><?php echo Core::_('install.table_field_value')?></td>
					</tr>
					<?php

					$aFields = $Site_Controller_Template->getFields($aXmlFields);

					foreach ($aFields as $aFieldsValue)
					{
						$sFieldName = htmlspecialchars($aFieldsValue['Name']);
						$sFieldValue = htmlspecialchars($aFieldsValue['Value']);
						$sFieldMacros = htmlspecialchars($aFieldsValue['Macros']);
						$sFieldExtension = htmlspecialchars($aFieldsValue['Extension']);
						$sFieldMaxWidth = intval($aFieldsValue['MaxWidth']);
						$sFieldMaxHeight = intval($aFieldsValue['MaxHeight']);
						$sFieldListValue = $aFieldsValue['ListValue'];
						$iFieldType = intval($aFieldsValue['Type']);

						// Название поля
						?><tr class="row">
							<td><?php echo $sFieldName?></td>
							<td><?php

						switch ($iFieldType)
						{
							case 0: // текст
								?>
								<input type="text" size="50" name="<?php echo $sFieldMacros?>" value="<?php echo $sFieldValue?>" />
								<?php
								break;
							case 1: // список
								?>
								<select name="<?php echo $sFieldMacros?>">
								<?php
								if (count($sFieldListValue) > 0)
								{
									foreach ($sFieldListValue as $option_key => $option_value)
									{
									?>
									<option value="<?php echo $option_key?>"><?php echo $option_value?></option>
									<?php
									}
								}
								?>
								</select>
								<?php
								break;
							case 2: // файл
								?>
								<input type="file" size="50" name="<?php echo $sFieldMacros?>" value="<?php echo $sFieldValue?>" />
								<?php
								if (trim($sFieldExtension) != '')
								{
									// Разрешенные расширения файла
									?><br /><?php echo Core::_('install.allowed_extension', $sFieldExtension)?><?php
								}

								if ($sFieldMaxWidth > 0 && $sFieldMaxHeight > 0)
								{
									// Максимальный размер файла
									?><br /><?php echo Core::_('install.max_file_size', $sFieldMaxWidth, $sFieldMaxHeight)?><?php
								}

								break;
							case 3: // большое текстовое поле
								?>
								<textarea name="<?php echo $sFieldMacros?>" rows="5" cols="47"><?php echo $sFieldValue?></textarea>
								<?php
								break;
						}
						?></td>
						</tr>
						<?php
					}
					?></table><?php
				}
				else
				{
					?><p><?php echo Core::_('install.empty_settings')?></p><?php
				}
			}
			else
			{
				Core_Message::show(Core::_('install.file_not_found', 'template.xml'), 'error');
			}
		}
		?>
		<input type="hidden" name="template_id" value="<?php echo $iTemplateId ?>" />
		<input type="hidden" name="template_type_id" value="<?php echo $iTemplateTypeId ?>" />

		<?php
	}
	catch (Exception $e)
	{
		Core_Message::show($e->getMessage(), 'error');
	}

	Core::factory('Admin_Form_Entity_Button')
		->name('process')
		->type('submit')
		->value(Core::_('install.next'))
		->class('applyButton')
		->onclick(
			"$.adminSendForm({buttonObject: this,action: 'step_9',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
		)
		->execute();
	?>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'step_9')
{
	// Show step 9
	Core_Skin::instance()->setMode('step_9');
	$title = Core::_('Install.step_9');

	Core::factory('Admin_Form_Entity_Title')
		->name($title)
		->execute();

	$iTemplateId = Core_Array::getPost('template_id');
	$iTemplateTypeId = Core_Array::getPost('template_type_id');

	// Копируем файлы из ./template/ в папку системы
	if (is_dir($Site_Controller_Template->templatePath . 'template'))
	{
		try
		{
			Core_File::copyDir($Site_Controller_Template->templatePath . 'template', CMS_FOLDER);
			Core_Message::show(Core::_('install.template_files_copy_success'));
		}
		catch (Exception $e)
		{
			Core_Message::show($e->getMessage(), 'error');
			Core_Message::show(Core::_('install.template_files_copy_error'), 'error');
		}
	}

	try
	{
		if (is_file($Site_Controller_Template->templatePath . 'template.php'))
		{
			// Замены в макете
			$aReplace = array();

			// Массив из файла template.xml
			$oTemplateContentXml = $Site_Controller_Template->loadSelectedTemplateXml();

			if ($oTemplateContentXml)
			{
				$aXmlFields = $oTemplateContentXml->xpath("fields/field");

				if (count($aXmlFields))
				{
					$aFields = $Site_Controller_Template->getFields($aXmlFields);

					// цикл по дереву 'fields'
					foreach ($aFields as $aFieldsValue)
					{
						$sFieldName = $aFieldsValue['Name'];
						$sFieldMacros = $aFieldsValue['Macros'];
						$iFieldType = $aFieldsValue['Type'];

						// Файл
						if ($iFieldType == 2)
						{
							if (isset($_FILES[$sFieldMacros]['tmp_name'])
							&& is_file($_FILES[$sFieldMacros]['tmp_name'])
							&& $_FILES[$sFieldMacros]['size'] > 0)
							{
								$sFieldPath = $aFieldsValue['Path'];
								$sFieldExtension = $aFieldsValue['Extension'];

								$sExt = Core_File::getExtension($_FILES[$sFieldMacros]['name']);
								$aAllowedExt = explode(',', $sFieldExtension);

								if (strlen(trim($sFieldExtension)) == 0 || in_array($sExt, $aAllowedExt))
								{
									if (!move_uploaded_file($_FILES[$sFieldMacros]['tmp_name'], CMS_FOLDER . $sFieldPath))
									{
										Core_Message::show(Core::_('install.file_copy_error', $sFieldPath), 'error');
									}
								}
								else
								{
									Core_Message::show(Core::_('install.file_disabled_extension', $sFieldName), 'error');
								}
							}
						}
						// Остальные типы полей
						else
						{
							$aReplace["%{$sFieldMacros}%"] = $_REQUEST[$sFieldMacros];
						}
					}
				}
			}

			include($Site_Controller_Template->templatePath . 'template.php');
			Core_Message::show(Core::_('install.template_install_success'));
		}
		else
		{
			Core_Message::show(Core::_('install.file_not_found', 'template.php'), 'error');
		}
	}
	catch (Exception $e)
	{
		Core_Message::show($e->getMessage(), 'error');
		Core_Message::show(Core::_('install.template_files_copy_error'), 'error');
	}

	$domain = "*." . str_replace('www.', '', $_SERVER['HTTP_HOST']);

	foreach (array('*.hostcms5', $domain) as $sDomain)
	{
		$oSite_Alias = Core_Entity::factory('Site_Alias')->getByName($sDomain);
		if ($oSite_Alias)
		{
			$oSite_Alias->delete();
		}
	}

	$oSites = Core_Entity::factory('Site');
	$oSites->queryBuilder()
		->clearOrderBy()
		->orderBy('id', 'DESC')
		->limit(1);

	$aSites = $oSites->findAll();

	// Есть дополнительный сайт
	if ($aSites[0] && $aSites[0]->id != 1)
	{
		$site_id = $aSites[0]->id;

		$oSite = Core_Entity::factory('Site', 1);
		$oSite->active = 0;
		$oSite->sorting = 999;
		$oSite->save();

		// Переносим группу пользователей новому сайту
		$oUser_Group = Core_Entity::factory('User_Group', 1);
		$aSites[0]->add($oUser_Group);
	}
	else
	{
		$site_id = 1;
	}

	$oSite_Alias = Core_Entity::factory('Site_Alias');
	$oSite_Alias->name = $domain;
	$oSite_Alias->current = 1;

	Core_Entity::factory('Site', $site_id)->add($oSite_Alias);

	// Генерируем соль, устанавливаем новый пароль
	$password = 'admin';

	try
	{
		$salt = Core_Password::get(8);
		Core_File::write(CMS_FOLDER . 'modules/core/config/hash.php', "<?php

return array (
	'salt' => '{$salt}',
	'hash' => 'sha1',
);");

		// Change password
		$oUser = Core_Entity::factory('User')->getByLogin('admin');

		if ($oUser)
		{
			$oUser->password = Core_Hash::instance()->hash($password);
			$oUser->save();
		}
	}
	catch (Exception $e){}

	//Core_Message::show(Core::_('install.sql_error', mysql_errno(), mysql_error()), 'error');

	echo Core::_('install.attention_complete_install');
	?><form method="post" action="index.php">
	<p>
	<?php
	Core::factory('Admin_Form_Entity_Button')
		->name('process')
		->type('submit')
		->value(Core::_('install.start'))
		->class('applyButton')
		->onclick(
			"$.adminSendForm({buttonObject: this,action: 'start',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
		)
		->execute();
	?>
	</p>
	</form>
	<?php
}
elseif ($formSettings['action'] == 'start')
{
	$title = '';

	try
	{
		Core_File::deleteDir(INSTALL_FOLDER);
		/*header('Location: ../');
		exit();*/
		?><script type="text/javascript">
		document.location = '/';
		</script><?php
	}
	catch (Exception $e)
	{
		Core_Message::show($e->getMessage(), 'error');

		// Try again
		?><form method="post" action="index.php">
		<p>
		<?php
		Core::factory('Admin_Form_Entity_Button')
			->name('process')
			->type('submit')
			->value(Core::_('install.start'))
			->class('applyButton')
			->onclick(
				"$.adminSendForm({buttonObject: this,action: 'start',operation: '',additionalParams: '',limit: '10',current: '1',sortingFieldId: '',sortingDirection: '',windowId: '{$windowId}'}); return false"
			)
			->execute();
		?>
		</p>
		</form>
		<?php
	}
}
else // Show step 0
{
	$title = Core::_('Install.step_0');
	Core_Skin::instance()->setMode('install')->changeLanguage();
	$openWindow = FALSE;
}

$oAdmin_Answer
	->ajax(Core_Array::getRequest('_', FALSE))
	->openWindow($openWindow)
	->windowSettings(array(
		'Minimize' => false,
		'Maximize' => false,
		'Close' => false
	))
	->addTaskbar(FALSE)
	->content(ob_get_clean())
	->title($title)
	->execute();

/**
 * Устанавливает рекурсивно права на директории и файлы
 *
 * @param string $path
 * @param string $filemode
 * @param string $dirmode
 */
function setChmod($path, $filemode, $dirmode)
{
	// Файл
	if (!is_dir($path))
	{
		return @chmod($path, $filemode);
	}

	if (!is_link($path))
	{
		$dh = @opendir($path);

		if ($dh)
		{
			while ($file = readdir($dh))
			{
				if ($file != '.' && $file != '..') {
					$fullpath = $path. '/' . $file;
					if (!is_dir($fullpath))
					{
						@chmod($fullpath, $filemode);
					}
					else
					{
						@chmod($fullpath, $dirmode);
						setChmod($fullpath, $filemode, $dirmode);
					}
				}
			}

			closedir($dh);
		}
	}
	return @chmod($path, $dirmode);
}

function showbullet($level, $text)
{
	$level = intval($level);

	switch ($level)
	{
		case 2:
			$img = 'bullet_red.gif';
		break;
		case 1:
			$img = 'bullet_orange.gif';
		break;
		case 0:
			$img = 'bullet_green.gif';
		break;
		default:
			$img = 'bullet_black.gif';
		break;
	}
	?><div style="background: url('images/<?php echo $img?>') no-repeat 0px 50%; padding-left: 15px"><?php echo $text?></div><?php
}

function MacroReplace($str, $aReplace)
{
	return Site_Controller_Template::instance()->macroReplace($str, $aReplace);
}

function LoadFile($filename, $aReplace = array())
{
	Site_Controller_Template::instance()->loadFile($filename, $aReplace);
}

/**
 * Заменяет макросы в уже существующем файле
 *
 *  @param $filename путь к файлу
 *  @param $aReplace массив замен
 */
function ReplaceFile($filename, $aReplace = array())
{
	Site_Controller_Template::instance()->replaceFile($filename, $aReplace);
}

/**
 * Копирование изображений для ИЭ
 *
 * @param $is_item_id - идентификатор нового созданого ИЭ
 * @param $copy_is_id - идентификатор копирумой ИС
 * @param $copy_item_id - идентификатор копируемого ИЭ
 */
function MoveInfItemImage($is_item_id, $copy_is_id, $copy_item_id)
{
	$SiteTemplate = & singleton ('SiteTemplate');
	return $SiteTemplate->MoveInfItemImage($is_item_id, $copy_is_id, $copy_item_id);
}

/**
 * Копирование изображений для доп. свойств ИЭ
 *
 * @param $is_item_id - Идентификатор нового ИЭ
 * @param $is_item_property_id - Идентификатор нового доп. свойства типа "Файл"
 * @param $copy_is_id - Идентификатор копирумой ИС
 * @param $copy_is_item_id - Идентификатор копируемого ИЭ
 * @param $copy_is_item_property_value_id - Идентификатор значения доп. свойства типа "Файл" копируемого ИЭ
 */
function MoveInfItemPropertyImage($is_item_id, $is_item_property_id, $copy_is_id, $copy_is_item_id, $copy_is_item_property_value_id)
{
	$SiteTemplate = & singleton ('SiteTemplate');
	return $SiteTemplate->MoveInfItemPropertyImage($is_item_id, $is_item_property_id, $copy_is_id, $copy_is_item_id, $copy_is_item_property_value_id);
}

/**
 * Копирование изображений для ИГ
 *
 * @param $is_group_id - идентификатор новой созданной ИГ
 * @param $copy_is_id - идентификатор копирумой ИС
 * @param $copy_group_id - идентификатор копируемой ИГ
 */
function MoveInfGroupImage($is_group_id, $copy_is_id, $copy_group_id)
{
	$SiteTemplate = & singleton ('SiteTemplate');
	return $SiteTemplate->MoveInfGroupImage($is_group_id, $copy_is_id, $copy_group_id);
}

/**
 * Копирование значения доп. свойства типа "Файл" узла структуры
 *
 * @param $structure_id - Идентификатор нового созданого узла структуры
 * @param $structure_property_image_id - Идентификатор нового созданного доп. свойства
 * @param $copy_site_id - Идентификатор сайта, которому принадлежит копируемая структура
 * @param $copy_structure_id - Идентификатор копируемого узла структуры
 * @param $copy_structure_property_value_id - Идентификатор значения доп. свойства, значение которого копируется
 */
function MoveStructureItemPropertyImage($structure_id, $structure_property_image_id, $copy_site_id, $copy_structure_id, $copy_structure_property_value_id)
{
	$SiteTemplate = & singleton ('SiteTemplate');
	return $SiteTemplate->MoveStructureItemPropertyImage($structure_id, $structure_property_image_id, $copy_site_id, $copy_structure_id, $copy_structure_property_value_id);
}

/**
 * Копирование изображений для группы товаров
 *
 * @param $shop_group_id - идентификатор новой созданной группы магазина
 * @param $copy_shop_id - идентификатор копирумого магазина
 * @param $copy_group_id - идентификатор копируемой группы товаров
 */
function MoveShopGroupImage($shop_group_id, $copy_shop_id, $copy_group_id)
{
	$SiteTemplate = & singleton ('SiteTemplate');
	return $SiteTemplate->MoveShopGroupImage($shop_group_id, $copy_shop_id, $copy_group_id);
}

/**
 * Копирование изображений для товара
 *
 * @param $shop_item_id - Идентификатор нового созданого товара
 * @param $copy_shop_id - Идентификатор копирумого магазина
 * @param $copy_shop_item_id - Идентификатор копируемого товара
 */
function MoveShopItemImage($shop_item_id, $copy_shop_id, $copy_shop_item_id)
{
	$SiteTemplate = & singleton ('SiteTemplate');
	return $SiteTemplate->MoveShopItemImage($shop_item_id, $copy_shop_id, $copy_shop_item_id);
}

/**
 * Копирование изображений для доп. свойств товара
 *
 * @param $shop_item_id - Идентификатор нового созданого товара
 * @param $copy_shop_id - Идентификатор копирумого магазина
 * @param $copy_shop_item_id - Идентификатор копируемого товара
 * @param $copy_shop_item_property_id - Идентификатор доп. свойства типа "Файл" копируемого товара
 */
function MoveShopItemPropertyImage($shop_item_id, $shop_item_property_id, $copy_shop_id, $copy_shop_item_id, $copy_shop_item_property_id)
{
	$SiteTemplate = & singleton ('SiteTemplate');
	return $SiteTemplate->MoveShopItemPropertyImage($shop_item_id, $shop_item_property_id, $copy_shop_id, $copy_shop_item_id, $copy_shop_item_property_id);
}
