<?php
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма экспорта данных о товарах.
 *
 * Файл: /admin/shop/action/export_items_catalog_form.php
 *
 * @author Hostmake LLC
 * @version 5.x
 */
$DataBase = & singleton('DataBase');
$datetime = & singleton('DateClass');
$shop = & singleton('shop');

$form_params = array();
$form_params['title'] = $GLOBALS['MSG_shops']['export_shop'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';

$admin_forms_fields = new admin_forms_fields();

$shop_shops_id = to_int($_REQUEST['shop_shops_id']);

$shop_groups_parent_id = to_int($_REQUEST['shop_groups_parent_id']);

$row = $shop->GetShop($shop_shops_id);

$path_array = $shop->GetShopPathArray($shop_groups_parent_id, false);


// Преобразуем идентификаторы групп в ссылки на группы.
$new_path_array = array();

$new_path_array[0]['name'] = $GLOBALS['MSG_shops']['header_admin__list_forms'];
$new_path_array[0]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', ' ', 54, 'load_data');
$new_path_array[0]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', ' ', 54, 'load_data');

$new_path_array[1]['name'] = $row['shop_shops_name'];
$new_path_array[1]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=0&shop_shops_id=$shop_shops_id", 65, 'load_data');
$new_path_array[1]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=0&shop_shops_id=$shop_shops_id", 65, 'load_data');

if ($path_array)
{
	foreach ($path_array as $key => $value)
	{
		$new_path_array[] = array (
		'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
		'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
		'name' => $value);
	}
}

$new_path_array[] = array("name" => $GLOBALS['MSG_shops']['export_shop'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&action=export&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data'),
"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&action=export&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data')
);

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

// Параметры.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab']);

// Тип выгружаемого файла
$arr = array(
0 => $GLOBALS['MSG_shops']['export_price_list_file_type1'], 
1 => $GLOBALS['MSG_shops']['export_price_list_file_type2'],
2 => $GLOBALS['MSG_shops']['export_price_list_file_type3_import'],
3 => $GLOBALS['MSG_shops']['export_price_list_file_type3_offers']
);

$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'export_type';
$params['caption'] = $GLOBALS['MSG_shops']['export_file_type'];
$params['type'] = 13; // радиокнопки
$params['value'] = 1;
$params['options']['count'] = count($arr);
$params['options']['labels'] = $arr;
$params['options']['input_text'] = -1;
$params['options']['ext_name'] = array(0 => 1, 1 => 0, 2 => 2, 3=>3);
$params['options']['onclick'] = 'SetViewImport(%ext_name%)';
$params['options']['index'] = array(0 => 0, 1 => 1, 2 => 2, 3=>3);
$params['div_attributes']['style'] = 'font-weight: bold';
$admin_forms_fields->AddField($params);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Поле с указанием разделителя, при выбори типа экспорта "CommerceML" должно скрываться
$arr = array(0 => $GLOBALS['MSG_shops']['import_price_list_separator1'],
1 => $GLOBALS['MSG_shops']['import_price_list_separator2'],
2 => $GLOBALS['MSG_shops']['import_price_list_separator4']);
$params = array();
$params['tab_id'] = $tab_id;
$params['div_id'] = 'export_price_separator';
$params['name'] = 'export_price_separator';
$params['caption'] = $GLOBALS['MSG_shops']['import_price_list_separator'];
$params['type'] = 13; // радиокнопки
$params['value'] = 1;
$params['options']['count'] = count($arr);
$params['options']['labels'] = $arr;
$params['options']['input_text'] = 1;
$params['options']['index'] = array(0 => 0, 1 => 1, 2 => 2);
$params['separator'] = '';
$admin_forms_fields->AddField($params);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Кодировка
$arr = array(
	'Windows-1251' => 'Windows-1251',
	'UTF-8' => 'UTF-8');
$params = array();
$params['tab_id'] = $tab_id;
$params['div_id'] = 'export_price_encoding';
$params['name'] = 'export_price_encoding';
$params['caption'] = $GLOBALS['MSG_shops']['price_list_encoding'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['div_attributes']['style'] = 'width: 400px';
$admin_forms_fields->AddField($params);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Заполнение формы "Родительская группа для загрузки товаров"
$aCache = GetShopGroups($shop_shops_id);
$arr = array($GLOBALS['MSG_shops']['load_parent_group']);
$arr = GetShopGroupsCreateOption($arr, $aCache, 0);
unset($aCache);

// Родительская группа для загрузки товаров
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_groups_parent_id';
$params['caption'] = $GLOBALS['MSG_shops']['import_price_list_parent_group'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = $shop_groups_parent_id;
$params['div_attributes']['style'] = 'width: 400px';
$admin_forms_fields->AddField($params);

$arr = array();
$shop->CacheGoupsIdTree[$shop_shops_id] = array();

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Флаг необходимости экспортировать дополнительные свойства товаров
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'export_external_properties_allow_items';
$params['caption'] = $GLOBALS['MSG_shops']['export_external_properties_allow_items'];
$params['type'] = 1; // checkbox
$params['value'] = 1;
$admin_forms_fields->AddField($params);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Флаг необходимости экспортировать дополнительные свойства групп
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'export_external_properties_allow_groups';
$params['caption'] = $GLOBALS['MSG_shops']['export_external_properties_allow_groups'];
$params['type'] = 1; // checkbox
$params['value'] = 1;
$admin_forms_fields->AddField($params);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Флаг необходимости экспортировать модификации товаров
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'export_modifications_allow';
$params['caption'] = $GLOBALS['MSG_shops']['export_modifications_allow'];
$params['type'] = 1; // checkbox
$params['value'] = 1;
$admin_forms_fields->AddField($params);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_shops_id';
$params['caption'] = '';
$params['type'] = 4; // hidden.
$params['value'] = $shop_shops_id;
$admin_forms_fields->AddField($params);

$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'action';
$params['caption'] = '';
$params['type'] = 4; // hidden.
$params['value'] = 'do_export';
$admin_forms_fields->AddField($params);

$params = array();
$params['name'] = 'export_items';
$params['caption'] = $GLOBALS['MSG_shops']['export_items_catalog'];
$params['attributes']['type'] = 'submit';
$admin_forms_fields->AddButton($params);

// Отображение формы.
$admin_forms_fields->ShowForm();

// Функция скрытия/отображения полей
?>
<script language="JavaScript">
function SetViewImport(param)
{
	if(param == 0 || param == 2  || param == 3)
	{
		document.getElementById("export_price_separator").style.display = "none";
		document.getElementById("export_price_encoding").style.display = "none";
	}
	else
	{
		document.getElementById("export_price_separator").style.display = "";
		document.getElementById("export_price_encoding").style.display = "";
	}
}
SetViewImport(1);
</script>
<?php

?>