<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2008 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма для загрузки прайс-листов (2 из 2) csv.
 * 
 * Файл: /admin/shop/action/import_price_list_load_form_step_two_csv.php
 * 
 * @author Hostmake LLC
 * @version 5.2
 */
// Открываем файл для импорта
if ($fp = @fopen($floadfile, 'rb'))
{
	// Читаем и разбираем первую строку файла
	$row_field = fgetcsv($fp, 3000, $import_price_separator_value, $import_price_stop_value);
	
	// Закрываем файл
	fclose($fp);
}

// Запоминаем количество элементов (количество полей)
$count_field = count($row_field);

// Максимальное время выполнения
$import_price_max_time = to_int($_REQUEST['import_price_max_time']);

$form_params = array();
$form_params['title'] = $GLOBALS['MSG_shops']['import_price_list_link'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';

$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']);

$shop = & singleton('shop');
$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']['import_price_list_title'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&action=import_price_list&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=import_price_list&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']);

// Заполняем необходимые массивы данных для формировния компонента
$array_of_data = array(0 => $GLOBALS['MSG_shops']['!download'],
1 => $GLOBALS['MSG_shops']['groups_id'],
2 => $GLOBALS['MSG_shops']['name_groups'],
3 => $GLOBALS['MSG_shops']['groups_path'],
4 => $GLOBALS['MSG_shops']['groups_description'],
5 => $GLOBALS['MSG_shops']['currency_id'],
6 => $GLOBALS['MSG_shops']['tax_id'],
7 => $GLOBALS['MSG_shops']['producers_id'],
8 => $GLOBALS['MSG_shops']['producers_name'],

9 => $GLOBALS['MSG_shops']['sellers_id'], 
10 => $GLOBALS['MSG_shops']['sellers_name'],

11 => $GLOBALS['MSG_shops']['mesures_id'],
12 => $GLOBALS['MSG_shops']['mesures_value'],
13 => $GLOBALS['MSG_shops']['item_id'],
14 => $GLOBALS['MSG_shops']['catalog_value'],
15 => $GLOBALS['MSG_shops']['catalog_marking'],

16 => $GLOBALS['MSG_shops']['catalog_date'],

17 => $GLOBALS['MSG_shops']['catalog_description'],
18 => $GLOBALS['MSG_shops']['catalog_text'],

19 => $GLOBALS['MSG_shops']['catalog_image'],
20 => $GLOBALS['MSG_shops']['catalog_small_image'],

21 => $GLOBALS['MSG_shops']['catalog_label'],

22 => $GLOBALS['MSG_shops']['catalog_weight'],
23 => $GLOBALS['MSG_shops']['catalog_rest'],
24 => $GLOBALS['MSG_shops']['catalog_price'],
25 => $GLOBALS['MSG_shops']['catalog_is_active'],
26 => $GLOBALS['MSG_shops']['catalog_order'],
27 => $GLOBALS['MSG_shops']['catalog_path'],
28 => $GLOBALS['MSG_shops']['catalog_seo_title'],
29 => $GLOBALS['MSG_shops']['catalog_seo_description'],
30 => $GLOBALS['MSG_shops']['catalog_seo_keywords'],
31 => $GLOBALS['MSG_shops']['catalog_indexation'],
32 => $GLOBALS['MSG_shops']['export_yandex_market'],
33 => $GLOBALS['MSG_shops']['yandex_market_base_price'],
34 => $GLOBALS['MSG_shops']['yandex_market_card_of_models'],
35 => $GLOBALS['MSG_shops']['item_parent_mark'],

36 => $GLOBALS['MSG_shops']['eitem_import_plain_text'],
37 => $GLOBALS['MSG_shops']['eitem_import_file']
);

$array_of_color = array(0 => '#999999',
1 => '#4E8400',
2 => '#4E8400',
3 => '#4E8400',
4 => '#4E8400',
5 => '#E39600',
6 => '#555555',
7 => '#7D00AC',
8 => '#7D00AC',

9 => '#0F10DE',
10 => '#0F10DE',

11 => '#BAAB00',
12 => '#BAAB00',
13 => '#0085B1',
14 => '#0085B1',
15 => '#0085B1',

16 => '#0085B1',

17 => '#0085B1',
18 => '#0085B1',
19 => '#0085B1',

20 => '#0085B1',

21 => '#0085B1',
22 => '#0085B1',
23 => '#0085B1',
24 => '#0085B1',
25 => '#0085B1',
26 => '#0085B1',
27 => '#0085B1',
28 => '#0085B1',
29 => '#0085B1',
30 => '#0085B1',
31 => '#0085B1',
32 => '#0085B1',
33 => '#0085B1',
34 => '#0085B1',
35 => '#0085B1',
36 => '#0085B1',
37 => '#0085B1'
);

$array_of_values = array(0 => '',
1 => 'shop_groups_id',
2 => 'shop_groups_value',
3 => 'shop_groups_path',
4 => 'shop_groups_description',
5 => 'shop_currency_id',
6 => 'shop_tax_id',
7 => 'shop_producers_list_id',
8 => 'shop_producers_list_value',

9 => 'shop_shop_sallers_id',
10 => 'shop_sallers_name',

11 => 'shop_mesures_id',
12 => 'shop_mesures_value',
13 => 'shop_items_catalog_item_id',
14 => 'shop_items_catalog_name',
15 => 'shop_items_catalog_marking',

16 => 'shop_shop_items_catalog_date_time',

17 => 'shop_items_catalog_description',
18 => 'shop_items_catalog_text',

19 => 'shop_items_catalog_image',
20 => 'shop_items_catalog_small_image',

21 => 'shop_items_catalog_label',

22 => 'shop_items_catalog_weight',
23 => 'shop_items_catalog_rest',
24 => 'shop_items_catalog_price',
25 => 'shop_items_catalog_is_active',
26 => 'shop_items_catalog_order',
27 => 'shop_items_catalog_path',
28 => 'shop_items_catalog_seo_title',
29 => 'shop_items_catalog_seo_description',
30 => 'shop_items_catalog_seo_keywords',
31 => 'shop_items_catalog_indexation',
32 => 'shop_shop_items_catalog_yandex_market_allow',
33 => 'shop_shop_items_catalog_yandex_market_bid',
34 => 'shop_shop_items_catalog_yandex_market_cid',
35 => 'shop_item_parent_mark',

36 => 'shop_eitems_text',
37 => 'shop_eitems_file'
);

// Выбираем дополнительные свойства для товара
$result = $shop->GetAllListProperties($shop_shops_id);
$count = mysql_num_rows($result);

for ($i = 0; $i < $count; $i++)
{
	$row = mysql_fetch_assoc($result);
	$array_of_data[] = $row['shop_list_of_properties_name'];
	$array_of_values[] = 'prop-'.$row['shop_list_of_properties_id'];
	$array_of_color[] = '#7FB8D6';
}

// Выбираем возможные цены для товара
$result = $shop->GetAllPricesForShop($shop_shops_id);

if ($result) 
{
	$count = mysql_num_rows($result);
}
else 
{
	$count = 0;
}


for ($i = 0; $i < $count; $i++)
{
	$row = mysql_fetch_assoc($result);
	$array_of_data[] = $row['shop_list_of_prices_name'];
	$array_of_values[] = 'price-'.$row['shop_list_of_prices_id'];
	$array_of_color[] = '#B03434';
}

// импортируемые поля
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'field';
$param['caption'] = $GLOBALS['MSG_shops']['import_price_list_import_param'];
$param['type'] = 14; // Выпадающие списки
$param['options']['count'] = count($row_field);
$param['options']['data_array'] = $array_of_data;
$param['options']['color_array'] = $array_of_color;
$param['options']['labels_array'] = $row_field;
$param['options']['values_array'] = $array_of_values;
$admin_forms_fields->AddField($param);

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

/////////////////
$import_price_action_items = to_int($_REQUEST['import_price_action_items']);

$import_price_action_delete_image = (isset($_REQUEST['import_price_action_delete_image']) === false?0:1);

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

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

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

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

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

$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'] = 'import_price_name_field_f';
$params['caption'] = '';
$params['type'] = 4; // hidden.
$params['value'] = $import_price_name_field_f;
$admin_forms_fields->AddField($params);

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

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

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

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


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

// Кнопка "Применить".
$params = array();
$params['name'] = 'import_data';
$params['caption'] = $GLOBALS['MSG_shops']['import_price_list_button_load'];
$params['attributes']['onclick'] = "return doSendForm('/admin/shop/shop.php', '&action=import_data', this, 0)";
$admin_forms_fields->AddButton($params);

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