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

$form_params = array();
$form_params['title'] = $edit_type_of_delivery==0?$GLOBALS['MSG_shops']['type_of_delivery_add_form_title']:$GLOBALS['MSG_shops']['type_of_delivery_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'] = 'EditAddTypeOfDelivery';

$admin_forms_fields = new admin_forms_fields();

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

$shop = & singleton('shop');

$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_type_of_delivery_link'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 77, 'load_data'),
"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 77, 'load_data')
);
$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

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

	$result = $shop->GetTypeOfDelivery($edit_type_of_delivery);

	$shop_type_of_delivery_name = to_str($result['shop_type_of_delivery_name']);
	
	$shop_type_of_delivery_description = to_str($result['shop_type_of_delivery_description']);
	
	$shop_type_of_delivery_image = to_str($result['shop_type_of_delivery_image']);
	
	$users_id = to_int($result['users_id']);
	
	$shop_type_of_delivery_order = $result['shop_type_of_delivery_order'];
}
// Добавление производителя
else
{
	$shop_type_of_delivery_name = '';
	
	$shop_type_of_delivery_description = '';
	
	$shop_type_of_delivery_image = '';
	
	$users_id = false;
	
	$shop_type_of_delivery_order = '';
}

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


// Название типа доставки
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'type_of_delivery_name';
$params['caption'] = $GLOBALS['MSG_shops']['type_of_delivery_name'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_type_of_delivery_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);

// Порядок сортировки
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_type_of_delivery_order';
$params['caption'] = $GLOBALS['MSG_shops']['shop_type_of_delivery_order_field'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_type_of_delivery_order;
$admin_forms_fields->AddField($params);

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

// Описание типа доставки
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'type_of_delivery_description';
$params['caption'] = $GLOBALS['MSG_shops']['type_of_delivery_description'];
$params['type'] = 5; // Текстовое поле
$params['value'] = $shop_type_of_delivery_description;
$params['attributes']['rows'] = 10;

$admin_forms_fields->AddField($params);

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

// Изображение
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'type_of_delivery_image';
$params['caption'] = $GLOBALS['MSG_shops']['type_of_delivery_image'];
$params['type'] = 9; // Текстовое поле
$params['value'] = $shop_type_of_delivery_image;

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

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

$admin_forms_fields->AddField($params);

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

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


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

// Кнопка "Сохранить".
$param = array();
$param['name'] = 'save_type_of_delivery';
$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_type_of_delivery';
$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']).", 'load_data', " . to_int($admin_forms_fields->form_params['current_page']) . ", " . to_int($admin_forms_fields->form_params['on_page']) . " )";
$params['attributes']['type'] = 'submit';
$admin_forms_fields->AddButton($params);

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