<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования производителей.
 * 
 * Файл: /admin/shop/action/form_edit_add_producer.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
if (isset($id)) 
{
	$edit_producer = $id;
}
else 
{
	$edit_producer = 0;
}

$form_params = array();
$form_params['title'] = $edit_producer == 0
? $GLOBALS['MSG_shops']['producer_add_form_title']
: $GLOBALS['MSG_shops']['producer_edit_form_title'];

$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';
$form_params['form_attribs']['name'] = 'EditAddProducer';

$admin_forms_fields = new admin_forms_fields();

$shop = & singleton('shop');

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

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

$DataBase = & singleton('DataBase');

$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']['show_producers_title'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id", 69, 'load_data'),
"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id", 69, 'load_data')
);

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

// Атрибуты максимального изображения берутся ВСЕГДА из настроек магазина
$shop_image_big_max_width = $row['shop_image_big_max_width'];
$shop_image_big_max_height = $row['shop_image_big_max_height'];
	
// Атрибуты максимального изображения берутся ВСЕГДА из настроек магазина
$shop_image_small_max_width = $row['shop_image_small_max_width'];
$shop_image_small_max_height = $row['shop_image_small_max_height'];

// Редактировние производителя
if ($edit_producer)
{
	$type = 1;

	$result = $shop->GetProducer($edit_producer);
	
	$shop_producers_list_id = to_int($result['shop_producers_list_id']);
	
	$shop_producers_list_name = $result['shop_producers_list_name'];
	
	$shop_producers_list_description = $result['shop_producers_list_description'];
	
	$shop_producers_list_image = $result['shop_producers_list_image'];
	
	$shop_producers_list_small_image = $result['shop_producers_list_small_image'];
	
	$shop_producers_list_order = to_int($result['shop_producers_list_order']);
	
	$shop_producers_list_path = $result['shop_producers_list_path'];
	
	$users_id = to_int($result['users_id']);
	
	$shop_producers_list_address = $result['shop_producers_list_address'];
	
	$shop_producers_list_phone = $result['shop_producers_list_phone'];
	
	$shop_producers_list_fax = $result['shop_producers_list_fax'];
	
	$shop_producers_list_site = $result['shop_producers_list_site'];
	
	$shop_producers_list_email = $result['shop_producers_list_email'];
	
	$shop_producers_list_inn = $result['shop_producers_list_inn'];
	
	$shop_producers_list_kpp = $result['shop_producers_list_kpp'];
	
	$shop_producers_list_ogrn = $result['shop_producers_list_ogrn'];
	
	$shop_producers_list_okpo = $result['shop_producers_list_okpo'];
	
	$shop_producers_list_okved = $result['shop_producers_list_okved'];
	
	$shop_producers_list_bik = $result['shop_producers_list_bik'];
	
	$shop_producers_list_account = $result['shop_producers_list_account'];
	
	$shop_producers_list_corr_account = $result['shop_producers_list_corr_account'];
	
	$shop_producers_list_bank_name = $result['shop_producers_list_bank_name'];
	
	$shop_producers_list_bank_address = $result['shop_producers_list_bank_address'];

	$shop_producers_list_seo_title = $result['shop_producers_list_seo_title'];

	$shop_producers_list_seo_description = $result['shop_producers_list_seo_description'];

	$shop_producers_list_seo_keywords = $result['shop_producers_list_seo_keywords'];
}
// Добавление производителя
else
{
	$shop_shops_id = to_int($_REQUEST['shop_shops_id']);

	$users_id = false;
	
	$shop_producers_list_id = 0;
	
	$shop_producers_list_name = '';
	
	$shop_producers_list_description = '';
	
	$shop_producers_list_image = '';
	
	$shop_producers_list_order = 0;
	
	$shop_producers_list_path = '';
	
	$shop_producers_list_address = '';
	
	$shop_producers_list_phone = '';
	
	$shop_producers_list_fax = '';
	
	$shop_producers_list_site = '';
	
	$shop_producers_list_email = '';
	
	$shop_producers_list_inn = '';
	
	$shop_producers_list_kpp = '';
	
	$shop_producers_list_ogrn = '';
	
	$shop_producers_list_okpo = '';
	
	$shop_producers_list_okved = '';
	
	$shop_producers_list_bik = '';
	
	$shop_producers_list_account = '';
	
	$shop_producers_list_corr_account = '';
	
	$shop_producers_list_bank_name = '';
	
	$shop_producers_list_bank_address = '';

	$shop_producers_list_seo_title = '';

	$shop_producers_list_seo_description = '';

	$shop_producers_list_seo_keywords = '';
	
	$shop_producers_list_small_image = '';
}

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

// Контактные данные.
$tabContacts_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab4_producer']);

// Банковские реквизиты
$tabBankData_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab3_producer']);


$params = array();
$params['tab_id'] = $tabContacts_id;
$params['name'] = 'shop_producers_list_address';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_address'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_address;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabContacts_id;
$params['name'] = 'shop_producers_list_phone';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_phone'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_phone;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabContacts_id;
$params['name'] = 'shop_producers_list_fax';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_fax'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_fax;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabContacts_id;
$params['name'] = 'shop_producers_list_site';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_site'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_site;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabContacts_id;
$params['name'] = 'shop_producers_list_email';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_email'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_email;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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


//////
$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_inn';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_inn'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_inn;
$params['format']['maxlen']['value'] = 12;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_kpp';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_kpp'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_kpp;
$params['format']['maxlen']['value'] = 9;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_ogrn';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_ogrn'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_ogrn;
$params['format']['maxlen']['value'] = 20;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_okpo';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_okpo'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_okpo;
$params['format']['maxlen']['value'] = 10;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_okved';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_okved'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_okved;
$params['format']['maxlen']['value'] = 50;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_bik';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_bik'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_bik;
$params['format']['maxlen']['value'] = 10;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_account';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_account'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_account;
$params['format']['maxlen']['value'] = 20;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_corr_account';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_corr_account'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_corr_account;
$params['format']['maxlen']['value'] = 20;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_bank_name';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_bank_name'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_bank_name;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

$params = array();
$params['tab_id'] = $tabBankData_id;
$params['name'] = 'shop_producers_list_bank_address';
$params['caption'] = $GLOBALS['MSG_shops']['producer_form_bank_address'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_bank_address;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Название
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'producer_name';
$params['caption'] = $GLOBALS['MSG_shops']['producer_name'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_name;
$params['attributes']['class'] = 'large';
$params['format']['minlen']['value'] = 1;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Получаем данные о магазине

$shop = new shop();

$shop_info = $shop->GetShop($shop_shops_id, array('cache_off'=>true));

$structure = & singleton('Structure');
$structure_row = $structure->GetStructureItem(to_int($shop_info['structure_id']));
$template_id = to_int($structure_row['templates_id']);

// Описание
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'producer_description';
$params['caption'] = $GLOBALS['MSG_shops']['producer_description'];
$params['type'] = 7; // Визуальный редактор.
$params['template'] = $template_id;

$params['value'] = $shop_producers_list_description;

$admin_forms_fields->AddField($params);

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

// Изображение производителя
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'producer_image';
$params['caption'] = $GLOBALS['MSG_shops']['producer_image'];
$params['type'] = 9; // Файл.
//$params['value'] = $shop_producers_list_image;

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

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

$params['options']['load_small_image_caption'] = $GLOBALS['MSG_shops']['producer_small_image'];

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

$params['options']['used_watermark_big_image_show'] = 0;
$params['options']['used_watermark_small_image_show'] = 0;

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

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

if ($shop_producers_list_image != '')
{
	$params['options']['big_image_path'] = '/' . UPLOADDIR . 'shop_' . $shop_shops_id . '/producers/' . rawurlencode($shop_producers_list_image); // адрес большого загруженного изображения
	$params['options']['href_delete_big_image'] = "javascript:void(0)";
	// Значение для onclick
	$params['options']['onclick_delete_big_image'] = "sendRequest('/admin/shop/shop.php?action=shop_producer_image_delete&item_id=$edit_producer&shop_shops_id=$shop_shops_id', 'get', callback_function_exec_from_return); return false;";
}
else
{
	$params['options']['big_image_path'] = '';
}


if ($shop_producers_list_small_image != '')
{
	$params['options']['small_image_path'] = '/' . UPLOADDIR . 'shop_' . $shop_shops_id . '/producers/' . rawurlencode($shop_producers_list_small_image); // адрес большого загруженного изображения
	$params['options']['href_delete_small_image'] = "javascript:void(0)";
	// Значение для onclick
	$params['options']['onclick_delete_small_image'] = "sendRequest('/admin/shop/shop.php?action=shop_producer_small_image_delete&item_id=$edit_producer&shop_shops_id=$shop_shops_id', 'get', callback_function_exec_from_return); return false;";
}
else
{
	$params['options']['small_image_path'] = '';
}

$admin_forms_fields->AddField($params);

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

// Порядок сортировки
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'producer_order';
$params['caption'] = $GLOBALS['MSG_shops']['producer_order'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_order;
$params['format']['lib']['value'] = 'integer';
$params['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$params['format']['minlen']['value'] = 1;
$params['format']['maxlen']['value'] = 11;
$admin_forms_fields->AddField($params);

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

// Путь
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'producer_path';
$params['caption'] = $GLOBALS['MSG_shops']['producer_path'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_producers_list_path;
$params['format']['lib']['value'] = 'path';
$params['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_path'];
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// передеам скрытое поле с идентификатором адреса если он есть
if ($edit_producer)
{
	$params = array();
	$params['tab_id'] = $tab_id;
	$params['name'] = 'edit_producer';
	$params['caption'] = '';
	$params['type'] = 4; // hidden.
	$params['value'] = $edit_producer;
	$admin_forms_fields->AddField($params);
}

// Разделитель.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab_seo']);

// Заголовок
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_producers_list_seo_title';
$param['caption'] = $GLOBALS['MSG_shops']['producer_add_form_seo_title'];
$param['type'] = 0; // textbox
$param['value'] = $shop_producers_list_seo_title;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Описание
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_producers_list_seo_description';
$param['caption'] = $GLOBALS['MSG_shops']['producer_add_form_seo_description'];
$param['type'] = 0; // textbox
$param['value'] = $shop_producers_list_seo_description;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Ключевые слова
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_producers_list_seo_keywords';
$param['caption'] = $GLOBALS['MSG_shops']['producer_add_form_seo_keywords'];
$param['type'] = 0; // textbox
$param['value'] = $shop_producers_list_seo_keywords;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_groups_parent_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'] = 'action';
$params['caption'] = '';
$params['type'] = 4; // hidden.
$params['value'] = 'show_producers';
$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);

// Кнопка "Сохранить".
$param = array();
$param['name'] = 'save_producer';
$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);

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

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