<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования магазинов.
 * 
 * Файл: /admin/shop/action/form_edit_add_shops.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$form_params = array();
$form_params['title'] = $shops_id==0?$GLOBALS['MSG_shops']['shops_add_form_title']:$GLOBALS['MSG_shops']['shops_edit_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddShop';

$admin_forms_fields = new admin_forms_fields();

/* Идентификатор текущего сайта */
$site_id = CURRENT_SITE;

$shop = & singleton('shop');

$kernel = & singleton('kernel');

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

// Передаем в массив для констурктора хлебные крошки
$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

$current_dir_id = to_int($_REQUEST['shop_dir_parent_id']);

// Редактирование сведений о магазине
if ($shops_id != 0 && $shops_id != -1)
{
	$type = 1;
	$result = $shop->GetShop($shops_id);
	$shop_shops_name = $result['shop_shops_name'];
	
	$shop_shops_description = $result['shop_shops_description'];
	$shop_currency_id = $result['shop_currency_id'];
	$shop_company_id = $result['shop_company_id'];
	$shop_shops_yandex_market_name = $result['shop_shops_yandex_market_name'];
	$shop_yandex_market_sales_notes_default = $result['shop_yandex_market_sales_notes_default'];
	$shop_image_small_max_width = $result['shop_image_small_max_width'];
	$shop_image_big_max_width = $result['shop_image_big_max_width'];
	$shop_image_small_max_height = $result['shop_image_small_max_height'];
	$shop_image_big_max_height = $result['shop_image_big_max_height'];
	$shop_image_small_max_width_group = $result['shop_image_small_max_width_group'];
	$shop_image_big_max_width_group = $result['shop_image_big_max_width_group'];
	$shop_image_small_max_height_group = $result['shop_image_small_max_height_group'];
	$shop_image_big_max_height_group = $result['shop_image_big_max_height_group'];
	$structure_id = $result['structure_id'];
	$shop_access = $result['shop_shops_access'];
	$shop_order_status_id = $result['shop_order_status_id'];
	$shop_country_id = $result['shop_country_id'];
	$shop_shops_send_order_mail_user = $result['shop_shops_send_order_mail_user'];
	$shop_shops_admin_mail = $result['shop_shops_admin_mail'];
	$shop_sort_order_field = $result['shop_sort_order_field'];
	$shop_sort_order_type = $result['shop_sort_order_type'];
	$shop_group_sort_order_field = $result['shop_group_sort_order_field'];
	$shop_mesures_id = $result['shop_mesures_id'];
	$shop_group_sort_order_type = $result['shop_group_sort_order_type'];
	$users_id = $result['users_id'];
	$shop_shops_send_order_mail_admin = $result['shop_shops_send_order_mail_admin'];
	$shop_comment_active = $result['shop_comment_active'];
	$shop_watermark_file = $result['shop_watermark_file'];
	$shop_watermark_default_use_big = $result['shop_watermark_default_use_big'];
	$shop_watermark_default_use_small = $result['shop_watermark_default_use_small'];
	$shop_watermark_default_position_x = $result['shop_watermark_default_position_x'];
	$shop_watermark_default_position_y = $result['shop_watermark_default_position_y'];
	$shop_items_on_page = $result['shop_items_on_page'];
	$shop_shops_guid = $result['shop_shops_guid'];
	$shop_shops_url_type = $result['shop_shops_url_type'];
	$shop_format_date = $result['shop_format_date'];
	$shop_format_datetime = $result['shop_format_datetime'];
	$shop_typograph_item_by_default = $result['shop_typograph_item_by_default'];
	$shop_typograph_group_by_default = $result['shop_typograph_group_by_default'];
	$shop_shops_apply_tags_automatic = $result['shop_shops_apply_tags_automatic'];
	$shop_shops_writeoff_payed_items = $result['shop_shops_writeoff_payed_items'];
	$shop_shops_apply_keywords_automatic = $result['shop_shops_apply_keywords_automatic'];
	$shop_shops_file_name_conversion = $result['shop_shops_file_name_conversion'];
	$shop_shops_attach_eitem = $result['shop_shops_attach_eitem'];
	$shop_shops_default_save_proportions = $result['shop_shops_default_save_proportions'];
}
// Добавление сведения о магазине
else
{
	$shop_format_datetime = '%d.%m.%Y %H:%M:%S';
	$shop_format_date = '%d.%m.%Y';
	$shop_shops_name = '';
	$shop_shops_description = '';
	$shop_shops_yandex_market_name = '';
	$shop_yandex_market_sales_notes_default = '';
	$shop_shops_send_order_mail_admin = 0;
	$shop_mesures_id = 0;
	$shop_currency_id = 0;
	$shop_order_status_id = 0;
	$shop_image_small_max_width = 100;
	$shop_image_big_max_width = 800;
	$shop_image_small_max_height = 100;
	$shop_image_big_max_height = 800;
	$shop_image_small_max_width_group = 100;
	$shop_image_big_max_width_group = 800;
	$shop_image_small_max_height_group = 100;
	$shop_image_big_max_height_group = 800;
	$shop_country_id = 0;
	$shop_company_id = 0;
	$structure_id = 0;
	$shop_access = -1;
	$shop_shops_send_order_mail_user = 0;
	$shop_shops_admin_mail = '';
	$shop_sort_order_field = 0;
	$shop_sort_order_type = 0;
	$shop_group_sort_order_field = 0;
	$shop_group_sort_order_type = 0;
	$shop_comment_active = 0;
	$shop_watermark_file = '';
	$shop_watermark_default_use_big = 0;
	$shop_watermark_default_use_small = 0;
	$shop_watermark_default_position_x = '50%';
	$shop_watermark_default_position_y = '100%';
	$shop_items_on_page = 10;
	$shop_shops_guid = $kernel->Guid();
	$shop_shops_url_type = 0;
	$shop_typograph_item_by_default = 1;
	$shop_typograph_group_by_default = 1;
	$shop_shops_apply_tags_automatic = 1;
	$shop_shops_writeoff_payed_items = 0;
	$shop_shops_apply_keywords_automatic = 1;
	$shop_shops_file_name_conversion = 1;
	$shop_shops_attach_eitem = 1;
	$shop_shops_default_save_proportions = 1;
}

// Определим ID макета по структуре
$structure = & singleton('Structure');
$structure_row = $structure->GetStructureItem(to_int($result['structure_id']));
$template_id = to_int($structure_row['templates_id']);

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

// Имя магазина
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_name';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_shops_name;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['attributes']['class'] = 'large';

$admin_forms_fields->AddField($param);

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

// Список разделов интернет-магазинов
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'current_shop_dir_id';
$param['caption'] = $GLOBALS['MSG_shops']['shop_dir_add_form_group'];
$param['type'] = 2; // Выпадающий список.
$param['value'] = $current_dir_id;

$items = array ();
$mas = array ();

$param_dirs = array();
$param_dirs['shop_dir_parent_id'] = 0;
$param_dirs['site_id'] = CURRENT_SITE;

$mas = $shop->GetShopsDirs($param_dirs);

$items[0] = '..';
$count_dirs = count($mas);

for ($i = 0; $i < $count_dirs; $i++)
{
    $items[$mas[$i]['shop_dir_id']] = $mas[$i]['separator'].$mas[$i]['shop_dir_name'];
}

$param['items'] = $items;

$param['div_attributes']['style'] = '';
$param['attributes']['style'] = 'width: 320px; float: left;';
$param['apply_filter'] = true;

$admin_forms_fields->AddField($param);

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

// Описание магазина
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_description';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_description'];
$param['template'] = $template_id; // ID шаблона
$param['type'] = 7; // Визуальный редактор
$param['value'] = $shop_shops_description;
//$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Заполняем список поля "узел структуры"
$arr = array();
$arr[0] = ' ... ';
$Structure = & singleton('Structure');
$result_structure = $Structure->GetStructure("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",$site_id,0,-1,0);
if (count($result_structure)>0)
{
	foreach ($result_structure as $key => $value)
	{
		$arr[$value['structure_id']] = $value['name_with_separator'];
	}
}

// Узел структуры
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'structure_id';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_path'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $structure_id;

$admin_forms_fields->AddField($param);

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

// Группа доступа
$param = array();

$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_access';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_add_form_access'];
$param['type'] = 2; // Выпадающий список.
$param['value'] = $shop_access;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';

$items = array();

if (class_exists('SiteUsers'))
{
	$site_users = & singleton('SiteUsers');
	$param_site_users_group['order_field'] = 'site_users_group_name';
	$result = $site_users->SelectSiteUsersGroups($param_site_users_group);
	$count_site_users_groups = mysql_num_rows($result);
}
else
{
	$count_site_users_groups = 0;
}

for ($i = -2; $i < $count_site_users_groups - 1; $i++)
{
	switch ($i)
	{
		case -2:
			{
				$option_text = $GLOBALS['MSG_shops']['shop_users_group_all'];
				$option_value = 0;
				break;
			}
		default:
			{
				$row = mysql_fetch_assoc($result);
				$option_text = $row["site_users_group_name"];
				$option_value = $row["site_users_group_id"];
			}
	}

	$items[$option_value] = $option_text;
}

$param['items'] = $items;

$admin_forms_fields->AddField($param);

// Заполняем список поля "Организация"
$arr = array();

$result_company = $shop->GetAllCompanies();

if ($result_company)
{
	while ($row = mysql_fetch_assoc($result_company))
	{
		$arr[$row['shop_company_id']] = $row['shop_company_name'];
	}
}

// Компания
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_company_id';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_company'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_company_id;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

// Заполняем список поля "Валюта по умолчанию"
$arr = array();

$arr[0] = ' ... ';

$result_currency = $shop->GetAllCurrency();

$count_currency = 0;

if ($result_currency)
{
	$count_currency = mysql_numrows($result_currency);
}
/* Кол-во валют больше 0 - выводим список валют */
if ($count_currency>0)
{
	for ($i=0;$i<$count_currency;$i++)
	{
		$row = mysql_fetch_assoc($result_currency);
		$arr[$row['shop_currency_id']] = $row['shop_currency_name'];
	}
}

// Валюта по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_currency_id';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_default_currency'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_currency_id;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

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

// Заполняем список поля "Страна по умолчанию"
$arr = array();

$arr[0] = ' ... ';

$result_countries = $shop->GetAllCountries();

$count_countries = 0;

if ($result_countries)
{
	$count_countries = mysql_numrows($result_countries);
}

/* Проверяем наличие стран */
if ($count_countries>0)
{
	for ($i = 0; $i < $count_countries; $i++)
	{
		$row = mysql_fetch_assoc($result_countries);
		$arr[$row['shop_country_id']] = $row['shop_country_name'];
	}
}

// Страна по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_country_id';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_default_country'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_country_id;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

// Заполняем список поля "Статус заказа по умолчанию"
$arr = array();
$arr[0] = ' ... ';
$result_order_status = $shop->GetAllOrderStatus();
$count_order_status = 0;
if ($result_order_status)
{
	$count_order_status = mysql_numrows($result_order_status);
}

/* Количество больше 0, выводим статусы заказов */
if ($count_order_status > 0)
{
	for ($i = 0; $i < $count_order_status; $i++)
	{
		$row = mysql_fetch_assoc($result_order_status);
		$arr[$row['shop_order_status_id']] = $row['shop_order_status_name'];
	}
}

// Статус заказа по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_order_status_id';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_default_order_status'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_order_status_id;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

// Заполняем список поля "Единица измерения веса товара"
$arr = array();

$arr[0] = ' ... ';

$result_mesures = $shop->GetAllMesures();
$count_mesures = 0;
if ($result_mesures)
{
	$count_mesures = mysql_numrows($result_mesures);
}
/* В цикле выводим элементы списка */
for ($i=0;$i<$count_mesures;$i++)
{
	$row = mysql_fetch_assoc($result_mesures);
	$arr[$row['shop_mesures_id']] = $row['shop_mesures_name'];
}

// Единица измерения веса товара
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_mesures_id';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_mesures'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_mesures_id;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

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


// E-mail куратора магазина
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_admin_mail';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_admin_mail'];
$param['type'] = 0; // Поле ввода
$param['value'] = $shop_shops_admin_mail;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

// Число элементов на странице
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_items_on_page';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_items_on_page'];
$param['type'] = 0; // Поле ввода
$param['format']['lib']['value'] = 'integer';
$param['value'] = $shop_items_on_page;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

$arr_of_elements = array(0 => $GLOBALS['MSG_shops']['shop_shops_url_type_element_0'], 1 => $GLOBALS['MSG_shops']['shop_shops_url_type_element_1']);

// Число элементов на странице
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_url_type';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_url_type'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr_of_elements; // Выпадающий список
$param['value'] = $shop_shops_url_type;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 190px';
$admin_forms_fields->AddField($param);

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

// Отправлять письмо с информацией о поступившем заказе администратору
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_send_order_mail_admin';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_send_order_mail_admin'];
$param['type'] = 1; // Флажок
$param['items'] = $arr;
$param['value'] = $shop_shops_send_order_mail_admin;

$admin_forms_fields->AddField($param);

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

// Отправлять письмо с информацией об оформленном заказе пользователю
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_send_order_mail_user';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_send_order_mail_user'];
$param['type'] = 1; // Флажок
$param['items'] = $arr;
$param['value'] = $shop_shops_send_order_mail_user;

$admin_forms_fields->AddField($param);

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

// Отправлять электроный товар в письме  с информацией об оформленном заказе пользователю как вложение
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_attach_eitem';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_attach_file_eitem'];
$param['type'] = 1; // Флажок
$param['value'] = $shop_shops_attach_eitem;

$admin_forms_fields->AddField($param);

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

// Постмодерировать отзывы на товары
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_comment_active';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_comment_active'];
$param['type'] = 1; // Флажок
$param['items'] = $arr;
$param['value'] = $shop_comment_active;

$admin_forms_fields->AddField($param);

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

// Автоматически применять keywords
$param = array();
$param['tab_id'] = $tab_id;
$param['type'] = 1;
$param['name'] = 'shop_shops_apply_keywords_automatic';
$param['html_id'] = 'id_shops_apply_keywords_automatic';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_apply_keywords_automatic'];
$param['value'] = to_int($shop_shops_apply_keywords_automatic);

$admin_forms_fields->AddField($param);

// Автоматически применять тэги
$param = array();
$param['tab_id'] = $tab_id;
$param['type'] = 1;
$param['name'] = 'shop_shops_apply_tags_automatic';
$param['html_id'] = 'id_shops_apply_tags_automatic';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_apply_tags_automatic'];
$param['value'] = to_int($shop_shops_apply_tags_automatic);

$admin_forms_fields->AddField($param);

// Списывать товары при оплате
$param = array();
$param['tab_id'] = $tab_id;
$param['type'] = 1;
$param['name'] = 'shop_shops_writeoff_payed_items';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_writeoff_payed_items'];
$param['value'] = to_int($shop_shops_writeoff_payed_items);

$admin_forms_fields->AddField($param);

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

// Изменять названия загружаемых файлов
$param = array();
$param['tab_id'] = $tab_id;
$param['type'] = 1;
$param['name'] = 'shop_shops_file_name_conversion';
$param['html_id'] = 'id_add_form_file_name_conversion';
$param['caption'] = $GLOBALS['MSG_shops']['shop_shops_add_form_file_name_conversion'];
$param['value'] = to_int($shop_shops_file_name_conversion);

$admin_forms_fields->AddField($param);

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

// Форматы
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab_formats']);

// Максимальная ширина малого изображения
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_small_max_width';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_small_max_width'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_small_max_width;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// Максималная высота малого изображения
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_small_max_height';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_small_max_height'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_small_max_height;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// Максималная ширина большого изображения
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_big_max_width';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_big_max_width'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_big_max_width;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// Максималная высота большого изображения
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_big_max_height';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_big_max_height'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_big_max_height;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// ######################
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_small_max_width_group';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_small_max_width_group'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_small_max_width_group;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// ######################
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_small_max_height_group';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_small_max_height_group'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_small_max_height_group;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// ###########################
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_big_max_width_group';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_big_max_width_group'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_big_max_width_group;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// ############################
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_image_big_max_height_group';
$param['caption'] = $GLOBALS['MSG_shops']['shops_form_image_big_max_height_group'];
$param['type'] = 0; // Текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_image_big_max_height_group;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 5;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// Формат даты
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_format_date';
$param['caption'] = $GLOBALS['MSG_shops']['shop_add_form_format_date'];
$param['type'] = 0; // Поле ввода.
$param['value'] = to_str($shop_format_date);
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// Формат даты/времени
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_format_datetime';
$param['caption'] = $GLOBALS['MSG_shops']['shop_add_form_format_datetime'];
$param['type'] = 0; // Поле ввода.
$param['value'] = to_str($shop_format_datetime);
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// Типографировать по умолчанию товары
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_typograph_item_by_default';
$param['caption'] = $GLOBALS['MSG_shops']['shop_typograph_item_by_default'];
$param['type'] = 1; // Флажок.
$param['value'] = $shop_typograph_item_by_default;
$admin_forms_fields->AddField($param);

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

// Типографировать по умолчанию группы товаров
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_typograph_group_by_default';
$param['caption'] = $GLOBALS['MSG_shops']['shop_typograph_group_by_default'];
$param['type'] = 1; // Флажок.
$param['value'] = $shop_typograph_group_by_default;
$admin_forms_fields->AddField($param);

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

// Экспорт.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab2_sort']);

// Поле название магазина для Yandex.Market'а
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_yandex_market_name';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_yandex_name'];
$param['type'] = 0; // Поле ввода
$param['value'] = $shop_shops_yandex_market_name;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// GUID
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_guid';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_guid_name'];
$param['type'] = 0; // Поле ввода
$param['value'] = $shop_shops_guid;
$param['format']['maxlen']['value'] = 100;
$admin_forms_fields->AddField($param);

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

// Поле значения по умолчанию для тега <sales_notes>
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_yandex_market_sales_notes_default';
$param['caption'] = $GLOBALS['MSG_shops']['shops_add_form_yandex_sales_notes_default'];
$param['type'] = 0; // Поле ввода
$param['value'] = $shop_yandex_market_sales_notes_default;
$param['format']['maxlen']['value'] = 50;
$admin_forms_fields->AddField($param);

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

// Водяной знак.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab2_watermark']);

// Поле загрузки изображения
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_watermark_file';
$param['caption'] = $GLOBALS['MSG_shops']['shop_form_watermark_file'];
$param['type'] = 9; // file
$param['value'] = $shop_watermark_file;

// Параметры
$param['options'] = array();

$param['options']['make_small_image_from_big_show'] = 0; // отображать ли checkbox с подписью "Создать малое изображение из большого" (1 -  отображать (по умолчанию), 0 - не отображать);
$param['options']['make_small_image_from_big_checked'] = 0; // вид отображения checkbox'а с подписью "Создать малое изображение из большого" выбранным (1 -  отображать выбранным (по умолчанию), 0 - невыбранным);

$param['options']['load_small_image_show'] = 0; //- отображать ли поле загрузки малого изображения (1 -  отображать (по умолчанию), 0 - не отображать);

$param['options']['load_small_image_caption'] = $GLOBALS['MSG_shops']['shop_add_form_small_image']; // Заголовок поля загрузки малого изображения


$param['options']['image_big_max_width'] = $shop_image_big_max_width; // значение максимальной ширины большого изображения;
$param['options']['image_big_max_height'] = $shop_image_big_max_height; // значение максимальной высоты большого изображения;

$param['options']['image_small_max_width'] = $shop_image_small_max_width; // значение максимальной ширины малого изображения;
$param['options']['image_small_max_height'] = $shop_image_small_max_height; // значение максимальной высоты малого изображения;

$param['options']['used_watermark_big_image_show'] = 0; // отображать ли checkbox с подписью "Наложить водяной знак на большое изображение" (1 -  отображать (по умолчанию), 0 - не отображать);
$param['options']['used_watermark_big_image_checked'] = 0; // вид ображения checkbox'а с подписью "Наложить водяной знак на большое изображение" (1 -  отображать выбранным (по умолчанию), 0 - невыбранным);

$param['options']['watermark_position_x'] = $shop_watermark_default_position_x; //значение поля ввода с подписью "По оси X"
$param['options']['watermark_position_y'] = $shop_watermark_default_position_y; // значение поля ввода с подписью "По оси Y"

$param['options']['show_big_image_params'] = 0;

$param['options']['used_watermark_small_image_show'] = 0; //  отображать ли checkbox с подписью "Наложить водяной знак на малое изображение" (1 -  отображать (по умолчанию), 0 - не отображать);
$param['options']['used_watermark_small_image_checked'] = 0; // вид ображения checkbox'а с подписью "Наложить водяной знак на малое изображение" (1 -  отображать выбранным (по умолчанию), 0 - невыбранным);

if ($shop_watermark_file != '')
{
	$param['options']['big_image_path'] = '/'.UPLOADDIR.'shop_'.$shops_id.'/watermarks/'.rawurlencode($shop_watermark_file); // адрес большого загруженного изображения
	$param['options']['href_delete_big_image'] = "/admin/shop/shop.php?action=delete_information_item_big_image&item_id=$shops_id";
	// Значение для onclick
	$param['options']['onclick_delete_big_image'] = "sendRequest('{$param['options']['href_delete_big_image']}', 'get', callback_function_exec_from_return); return false;";
}
else
{
	$param['options']['big_image_path'] = '';
	$param['options']['href_delete_big_image'] = "";
	// Значение для onclick
	$param['options']['onclick_delete_big_image'] = "";
}

$admin_forms_fields->AddField($param);

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

// Сохранять пропорции изображения по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_default_save_proportions';
$param['caption'] = $GLOBALS['MSG_shops']['tab2_save_proportions'];
$param['type'] = 1; // Флажок
$param['value'] = $shop_shops_default_save_proportions;

$admin_forms_fields->AddField($param);

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

// Использовать файл Watermark по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_watermark_default_use_big';
$param['caption'] = $GLOBALS['MSG_shops']['shop_form_watermark_default_use_big'];
$param['type'] = 1; // Флажок
$param['value'] = $shop_watermark_default_use_big;

$admin_forms_fields->AddField($param);

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

// Использовать файл Watermark для малых изображений по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_watermark_default_use_small';
$param['caption'] = $GLOBALS['MSG_shops']['shop_form_watermark_default_use_small'];
$param['type'] = 1; // Флажок
$param['value'] = $shop_watermark_default_use_small;

$admin_forms_fields->AddField($param);

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

// Позиция водяного знака по оси Х по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_watermark_default_position_x';
$param['caption'] = $GLOBALS['MSG_shops']['default_x_position'];
$param['type'] = 0; // Поле ввода
$param['value'] = $shop_watermark_default_position_x;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// Позиция водяного знака по оси Y по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_watermark_default_position_y';
$param['caption'] = $GLOBALS['MSG_shops']['default_y_position'];
$param['type'] = 0; // Поле ввода
$param['value'] = $shop_watermark_default_position_y;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// Сортировка.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab_sort']);

// Заполняем список поля "Поле сортировки товара"
$mas_field_sort = array($GLOBALS['MSG_shops']['sort_by_date'],
$GLOBALS['MSG_shops']['sort_by_name'],
$GLOBALS['MSG_shops']['sort_by_order']);

$arr = array();

$count = count($mas_field_sort);

for ($i = 0; $i < $count; $i++)
{
	$arr[$i] = $mas_field_sort[$i];
}

// Поле сортировки товара
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_sort_order_field';
$param['caption'] = $GLOBALS['MSG_shops']['sort_field_title'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_sort_order_field;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// Заполняем список поля "Направление сортировки товара"
$arr = array();

$arr[0] = $GLOBALS['MSG_shops']['sort_to_increase'];
$arr[1] = $GLOBALS['MSG_shops']['sort_to_decrease'];

// Направление сортировки товара
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_sort_order_type';
$param['caption'] = $GLOBALS['MSG_shops']['sort_order_type'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_sort_order_type;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// Заполняем список поля "Поле сортировки групп"
$arr = array();
$mas_field_sort = array(
$GLOBALS['MSG_shops']['sort_by_name'],
$GLOBALS['MSG_shops']['sort_by_order']);

$count = count($mas_field_sort);

for ($i = 0; $i < $count; $i++)
{
	$arr[$i] = $mas_field_sort[$i];
}

// Поле сортировки групп
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_group_sort_order_field';
$param['caption'] = $GLOBALS['MSG_shops']['sort_field_group_title'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_group_sort_order_field;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

// Заполняем список поля "Направление сортировки групп"
$arr = array();

$arr[0] = $GLOBALS['MSG_shops']['sort_to_increase'];
$arr[1] = $GLOBALS['MSG_shops']['sort_to_decrease'];

// Направление сортировки групп
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_group_sort_order_type';
$param['caption'] = $GLOBALS['MSG_shops']['sort_order_group_type'];
$param['type'] = 2; // Выпадающий список
$param['items'] = $arr;
$param['value'] = $shop_group_sort_order_type;
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 300px';
$admin_forms_fields->AddField($param);

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

// Добавляем скрытое поле с идентификатором родительского раздела
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_dir_parent_id';
$param['type'] = 4; // Скрытое поле.
$param['value'] = $current_dir_id;
$admin_forms_fields->AddField($param);


// передеам скрытое поле с идентификатором адреса если он есть
if ($shops_id != 0 && $shops_id != -1)
{
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'shops_id';
	$param['caption'] = '';
	$param['type'] = 4; // hidden.
	$param['value'] = $shops_id;
	$admin_forms_fields->AddField($param);
}
$test = to_int($_REQUEST['admin_forms_id']);

// Кнопка "Сохранить".
$param = array();
$param['name'] = 'save_shop';
$param['caption'] = $GLOBALS['MSG_shops']['save'];
$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '{$admin_forms_fields->AAction}', '{$admin_forms_fields->AAdditionalParams}', this, ".to_int($_REQUEST['admin_forms_id']).", 'load_data', " . to_int($admin_forms_fields->form_params['current_page']) . ", " . to_int($admin_forms_fields->form_params['on_page']) . " )";
$param['attributes']['type'] = 'button';
$admin_forms_fields->AddButton($param);

// Кнопка "Применить".
$param = array();
$param['name'] = 'add_shop';
$param['caption'] = $GLOBALS['MSG_shops']['apply'];
$param['image'] = '/admin/images/add.gif';
$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '{$admin_forms_fields->AAction}', '{$admin_forms_fields->AAdditionalParams}', this, ".to_int($_REQUEST['admin_forms_id']).", 'load_data', " . to_int($admin_forms_fields->form_params['current_page']) . ", " . to_int($admin_forms_fields->form_params['on_page']) . " )";
$param['attributes']['type'] = 'submit';
$admin_forms_fields->AddButton($param);

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