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

$form_params = array();
$form_params['title'] = $city_area_id==0?$GLOBALS['MSG_shops']['add_city_area_tytle']:$GLOBALS['MSG_shops']['edit_city_area_tytle'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddCityArea';

$shop = & singleton('shop');

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

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

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

$admin_forms_fields = new admin_forms_fields();

$DataBase = & singleton('DataBase');

$rows = $shop->GetLocation($shop_location_id);

$row = $shop->GetCountry($shop_country_id);

$country_row = $shop->GetCountry($shop_country_id);

$row_city = $shop->GetCity($shop_city_id);

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

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

$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_country_id=$shop_country_id", 59, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_country_id=$shop_country_id", 59, 'load_data'),
'name' => $GLOBALS['MSG_shops']['show_location_title'].' "'.$row['shop_country_name'].'"');

$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_country_id=$shop_country_id&shop_location_id=$shop_location_id", 60, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_country_id=$shop_country_id&shop_location_id=$shop_location_id", 60, 'load_data'),
'name' => $GLOBALS['MSG_shops']['show_city_title'].' "'.$rows['shop_location_name'].'"');

$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_country_id=$shop_country_id&shop_location_id=$shop_location_id&shop_city_id=$shop_city_id", 61, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_country_id=$shop_country_id&shop_location_id=$shop_location_id&shop_city_id=$shop_city_id", 61, 'load_data'),
'name' => $GLOBALS['MSG_shops']['show_city_area_title'].' "'.$row_city['shop_city_name'].'"');

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

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

// Редактировние района города
if ($city_area_id)
{
	$type = 1;
				
	// Выбираем района города по его идентификатору
	$row = $shop->GetCityArea($city_area_id);
		
	$shop_city_area_name = $row['shop_city_area_name'];

	$shop_city_area_order = $row['shop_city_area_order'];
}
// Добавление района города
else
{
	$shop_city_area_order = 0;
	$shop_city_area_name = '';
}

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

// Название района города
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'city_area_name';
$param['caption'] = $GLOBALS['MSG_shops']['add_city_area_form_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_city_area_name;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['attributes']['class'] = 'large';

$admin_forms_fields->AddField($param);

// Порядок сортировки района города
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_city_area_order';
$param['caption'] = $GLOBALS['MSG_shops']['show_producers_order'];
$param['type'] = 0; // Поле ввода.
$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['value'] = $shop_city_area_order;

$admin_forms_fields->AddField($param);

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

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

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

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

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

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

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