<?php
/**
* @version	$Id: install.php 16516 2017-01-20 14:12:22Z alex $
* @package	In-Commerce
* @copyright	Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license	Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
$module_folder = 'modules/in-commerce';

if ( !defined('IS_INSTALL') ) {
	// separate module install
	define('IS_INSTALL', 1);
	define('ADMIN', 1);
	define('FULL_PATH', realpath(dirname(__FILE__) . '/../..'));

	include_once(FULL_PATH . '/core/kernel/startup.php');
	require_once FULL_PATH . '/core/install/install_toolkit.php';

	$constants_file = FULL_PATH . '/' . $module_folder . '/constants.php';

	if ( file_exists($constants_file) ) {
		require_once $constants_file;
	}

	$toolkit = new kInstallToolkit();
}
else {
	// install, using installation wizard
	/** @var kInstallToolkit $toolkit */
	$toolkit =& $this->toolkit;
}

$application =& kApplication::Instance();
$application->Init();

if ( $application->RecallVar('user_id') != USER_ROOT ) {
	die('restricted access!');
}

$category =& $toolkit->createModuleCategory('Products', 'Product Catalog', '#in-commerce/section_design#', 'in-commerce/img/menu_products.gif');

$toolkit->RunSQL('/' . $module_folder . '/install/install_schema.sql');
$toolkit->RunSQL('/' . $module_folder . '/install/install_data.sql', '{ProductCatId}', $category->GetID());
$toolkit->ImportLanguage('/' . $module_folder . '/install/english', isset($constants_file));

$toolkit->SetModuleRootCategory(basename($module_folder), $category->GetID());

$toolkit->linkCustomFields(basename($module_folder), 'p', 11); // to create Custom Fields for Products
$toolkit->linkCustomFields('KERNEL', 'u', 6); // to create shipping related Custom Fields for Users
$toolkit->linkCustomFields('KERNEL', 'c', 1); // to create ItemTemplate custom field
$toolkit->setModuleItemTemplate($category, 'p', '#in-commerce/item_design#');

$toolkit->finalizeModuleInstall($module_folder, true);
