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

$datetime = & singleton('DateClass');

$form_params = array();
$form_params['title'] = $edit_order==0?$GLOBALS['MSG_shops']['order_add_form_title']:$GLOBALS['MSG_shops']['order_edit_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddOrder';

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

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

// Редактировние оформленного заказа
if ($edit_order)
{
	$type = 1;

	$result = $shop->GetOrder($edit_order);

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

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

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

	$shop_city_area_id = to_int($result['shop_city_area_id']);

	$shop_cond_of_delivery_id = to_int($result['shop_cond_of_delivery_id']);

	$shop_order_delivery_price = to_float($result['shop_order_delivery_price']);

	$site_users_id = to_int($result['site_users_id']);

	$shop_order_users_name = to_str($result['shop_order_users_name']);

	$shop_order_users_surname = to_str($result['shop_order_users_surname']);

	$shop_order_users_patronymic = to_str($result['shop_order_users_patronymic']);

	$shop_order_users_email = to_str($result['shop_order_users_email']);

	$shop_order_users_company = to_str($result['shop_order_users_company']);

	$shop_order_users_fax = to_str($result['shop_order_users_fax']);

	$shop_order_status_id = to_int($result['shop_order_status_id']);

	$shop_currency_id = to_int($result['shop_currency_id']);

	$shop_system_of_pay_id = to_int($result['shop_system_of_pay_id']);

	$shop_order_date_time =  $datetime->datetime_format(date($result['shop_order_date_time']));

	$shop_order_sum = $shop->GetOrderSum($edit_order);

	$shop_order_status_of_pay = to_int($result['shop_order_status_of_pay']);

	$shop_order_date_of_pay = $datetime->datetime_format(date($result['shop_order_date_of_pay']));

	$shop_order_address = to_str($result['shop_order_address']);

	$shop_order_index = to_int($result['shop_order_index']);

	$shop_order_phone = to_str($result['shop_order_phone']);

	$shop_order_description = to_str($result['shop_order_description']);

	$shop_order_system_information = to_str($result['shop_order_system_information']);

	$shop_order_cancel = to_int($result['shop_order_cancel']);

	$users_id = to_int($result['users_id']);

	$order_cancel_status = to_int($result['shop_order_cancel']);

	$shop_order_account_number = to_str($result['shop_order_account_number']);
}
// Добавление оформленного заказа
else
{
	$shop_location_id = 0;

	$shop_country_id = 0;

	$shop_city_id = 0;

	$shop_city_area_id = 0;

	$shop_cond_of_delivery_id = 0;

	$shop_order_delivery_price = '';

	$site_users_id = 0;

	$shop_order_users_name = '';

	$shop_order_users_surname = '';

	$shop_order_users_patronymic = '';

	$shop_order_users_email = '';

	$shop_order_users_company = '';

	$shop_order_users_fax = '';

	$shop_order_status_id = 0;

	$shop_currency_id = 0;

	$shop_system_of_pay_id = 0;

	$shop_order_date_time = date("d.m.Y H:i:s");

	$shop_order_sum = '';

	$shop_order_status_of_pay = 0;

	$shop_order_date_of_pay = date("d.m.Y H:i:s");

	$shop_order_address = '';

	$shop_order_index = '';

	$shop_order_phone = '';

	$shop_order_description = '';

	$shop_order_system_information = '';

	$shop_order_cancel = 0;

	$users_id = false;

	$order_cancel_status = 0;

	$shop_order_account_number = '';
}

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

// Номер оформленного заказа
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_order_account_number';
$params['caption'] = $GLOBALS['MSG_shops']['show_order_number'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_account_number;
$params['attributes']['class'] = 'large';
//	$params['format']['lib']['value'] = 'integer';
//	$params['format']['lib']['message'] = 'Указаны недопустимые символы (разрешенный диапазон символов 0-9)';
$params['format']['minlen']['value'] = 0;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Дата и время когда был сделан заказ
$params = array();
$params['tab_id'] = $tab_id;
$params['html_id'] = 'order_date_time';
$params['name'] = 'order_date_time';
$params['caption'] = $GLOBALS['MSG_shops']['order_date_time'];
$params['type'] = 11; // Дата-время
$params['value'] = $shop_order_date_time;

$admin_forms_fields->AddField($params);

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

// Идентификатор пользователя (заказчика)
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'site_users_id';
$params['caption'] = $GLOBALS['MSG_shops']['add_site_users'];
$params['type'] = 0; // Поле ввода
$params['value'] = $site_users_id;
$params['format']['lib']['value'] = 'integer';
$params['format']['lib']['message'] = 'Указаны недопустимые символы (разрешенный диапазон символов 0-9)';
$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'] = 'order_sum';
$params['caption'] = $GLOBALS['MSG_shops']['cond_of_delivery_add_form_price_order'];
$params['attributes']['readonly'] = '';
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_sum;
$params['attributes']['style'] = 'width: 75px;';
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

// Заполняем данными поле "Валюта"
$arr = array();
$arr[0] = ' ... ';
$row = $shop->GetAllCurrency();

while ($res = mysql_fetch_assoc($row))
{
	$arr[$res['shop_currency_id']] = $res['shop_currency_name'];
}

// Валюта, в которой будет оплачиваться заказ
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'currency_id';
$params['caption'] = $GLOBALS['MSG_shops']['order_currency'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = $shop_currency_id;
$params['attributes']['style'] = 'width: 75px;';
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

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

// Запоняем поле "Страна"
$arr = array();
$arr[0] = ' ... ';

$res = $shop->GetAllCountries();

if ($res)
{
	while ($row = mysql_fetch_assoc($res))
	{
		$arr[$row['shop_country_id']] = $row['shop_country_name'];
	}
}

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

// Страна
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'country_id';
$params['caption'] = $GLOBALS['MSG_shops']['order_add_form_country'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['attributes']['onchange'] = "doSetLocation(this.options[this.selectedIndex].value)";
$params['value'] = $shop_country_id;
$admin_forms_fields->AddField($params);

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

// Заполняем поле "Область"
$arr = array();
$arr[0] = ' ... ';

// Расположения заполняем только тогда, когда страна указана
if ($shop_country_id)
{
	$res = $shop->GetAllLocation($shop_country_id);

	if ($res)
	{
		while ($row = mysql_fetch_assoc($res))
		{
			$arr[$row['shop_location_id']] = $row['shop_location_name'];
		}
	}
}

// Область
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'location_id';
$params['caption'] = $GLOBALS['MSG_shops']['order_add_form_location'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['attributes']['onchange'] = "doSetCity(this.options[this.selectedIndex].value)";
$params['value'] = $shop_location_id;
$admin_forms_fields->AddField($params);

// Заполняем поле "Город"
$arr = array();
$arr[0] = ' ... ';

// Города заполняем только тогда, когда расположение указано
if ($shop_location_id)
{
	$res = $shop->GetAllCity($shop_location_id);

	if ($res)
	{
		while ($row = mysql_fetch_assoc($res))
		{
			$arr[$row['shop_city_id']] = $row['shop_city_name'];
		}
	}
}

// Город
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'city_id';
$params['caption'] = $GLOBALS['MSG_shops']['order_add_form_city'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['attributes']['onchange'] = "doSetCityArea(this.options[this.selectedIndex].value)";
$params['value'] = $shop_city_id;
$admin_forms_fields->AddField($params);

// Заполняем поле "Район"
$arr = array();
$arr[0] = ' ... ';

// Города заполняем только тогда, когда расположение указано
if ($shop_city_id)
{
	$res = $shop->GetAllCityArea($shop_city_id);

	if ($res)
	{
		while ($row = mysql_fetch_assoc($res))
		{
			$arr[$row['shop_city_area_id']] = $row['shop_city_area_name'];
		}
	}
}

// Район города
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'city_area_id';
$params['caption'] = $GLOBALS['MSG_shops']['order_add_form_city_area'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = $shop_city_area_id;
$admin_forms_fields->AddField($params);

// Адрес
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'order_address';
$params['caption'] = $GLOBALS['MSG_shops']['order_address'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_address;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Индекс
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'order_index';
$params['caption'] = $GLOBALS['MSG_shops']['order_index'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_index;
$params['format']['lib']['value'] = 'integer';
$params['format']['lib']['message'] = 'Указаны недопустимые символы (разрешенный диапазон символов 0-9)';
$params['format']['maxlen']['value'] = 11;
$admin_forms_fields->AddField($params);

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

// Телефон
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'order_phone';
$params['caption'] = $GLOBALS['MSG_shops']['order_phone'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_phone;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Факс
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'shop_order_users_fax';
$params['caption'] = $GLOBALS['MSG_shops']['form_order_fax'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_users_fax;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// E-mail заказчика
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'shop_order_users_email';
$params['caption'] = $GLOBALS['MSG_shops']['form_order_email'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_users_email;
$params['format']['lib']['value'] = 'email';
$admin_forms_fields->AddField($params);

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

// Статус оплаты
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'order_status_of_pay';
$params['caption'] = $GLOBALS['MSG_shops']['order_status_of_pay'];
$params['type'] = 1; // Флажок
$params['value'] = $shop_order_status_of_pay;
$admin_forms_fields->AddField($params);

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

// Статус отмены заказа
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'order_cancel_status';
$params['caption'] = $GLOBALS['MSG_shops']['cancel_status'];
$params['type'] = 1; // Флажок
$params['value'] = $order_cancel_status;
$admin_forms_fields->AddField($params);

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


// Заполнение поля "Статус заказа"
$arr = array();
$arr[0] = ' ... ';
$row = $shop->GetAllOrderStatus();

while ($res = mysql_fetch_assoc($row))
{
	$arr[$res['shop_order_status_id']] = $res['shop_order_status_name'];
}

// Статус заказа
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_order_status_id';
$params['caption'] = $GLOBALS['MSG_shops']['show_order_status'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = $shop_order_status_id;
$admin_forms_fields->AddField($params);

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

// Дата и время когда был оплачен заказ
$params = array();
$params['tab_id'] = $tab_id;
$params['html_id'] = 'order_date_of_pay';
$params['name'] = 'order_date_of_pay';
$params['caption'] = $GLOBALS['MSG_shops']['order_date_of_pay'];
$params['type'] = 11; // Дата-время
$params['value'] = $shop_order_date_of_pay;
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

// Заполняем поле "Платежная система"
$arr = array();
$arr[0] = ' ... ';
$row = $shop->GetAllSystemOfPay();

while ($res = mysql_fetch_assoc($row))
{
	$arr[$res['shop_system_of_pay_id']] = $res['shop_system_of_pay_name'];
}

// Платежная система
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'system_of_pay';
$params['caption'] = $GLOBALS['MSG_shops']['system_of_pay'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = $shop_system_of_pay_id;
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

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

// Заполняем форму "Типы доставок"
$arr = array();
$arr[0] = ' ... ';
$row = $shop->GetAllTypeOfDelivery($shop_shops_id);

while ($res = mysql_fetch_assoc($row))
{
	$arr[$res['shop_type_of_delivery_id']] = $res['shop_type_of_delivery_name'];
}

// Тип доставки явно не хранится в базе, поэтому извлечем его ID из условия доставки
$cond_of_delivery_row = $shop->GetCondOfDelivery($shop_cond_of_delivery_id);

// типы доставки
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_type_of_delivery_id';
$params['caption'] = $GLOBALS['MSG_shops']['type_of_delivery'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = to_int($cond_of_delivery_row['shop_type_of_delivery_id']);
$params['attributes']['onchange'] = 'setCondition(this)';
$admin_forms_fields->AddField($params);

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

// Заполняем форму "Условия доставки"
$arr = array();
$sysp = array();
$arr[0] = ' ... ';
$sysp['type_of_delivery_id'] = 0;
$row = $shop->GetAllCondOfDelivery();

// Условия доставки
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_cond_of_delivery_id';
$params['caption'] = $GLOBALS['MSG_shops']['cond_of_delivery'];
$params['type'] = 2; // Выпадающий список
$params['value'] = $shop_cond_of_delivery_id;

$type_of_delivery_data = $shop->GetAllTypeOfDelivery($shop_shops_id);

// Количество типов доставки
$count_of = $DataBase->get_count_row();

$source_code = '';

$itog = "";

// Получаем условие доставки для каждого типа доставки
for ($i = 0; $i < $count_of; $i++)
{
	$row = mysql_fetch_assoc($type_of_delivery_data);

	$id = $row['shop_type_of_delivery_id'];

	// Получаем список условий доставки для текущего типа доставки
	$param_delivery['type_of_delivery_id'] = $id;

	$cond_of_delivery_data = $shop->GetAllCondOfDelivery($param_delivery);

	$count_fo = mysql_num_rows($cond_of_delivery_data);

	$extend = "";

	$base = "\n type_id[\"$id\"] = [";

	// Дописываем информацию в скрипт:
	for ($j = 0; $j < $count_fo; $j++)
	{
		$row2 = mysql_fetch_assoc($cond_of_delivery_data);

		// Если тип доставки текущий - пишем в список, который выводится сразу при редактировании. Дальше этот список меняется
		if (to_int($cond_of_delivery_row['shop_type_of_delivery_id']) == $row2['shop_type_of_delivery_id'])
		{
			$params['items'][$row2['shop_cond_of_delivery_id']] = $row2['shop_cond_of_delivery_name'];
		}

		$id2 = $row2['shop_cond_of_delivery_id'];

		$name2 = $row2['shop_cond_of_delivery_name'];

		if ($j <> ($count_fo - 1))
		{
			$temp = "{value:\"$id2\", text:\"$name2\"},";
		}
		else
		{
			$temp = "{value:\"$id2\", text:\"$name2\"}";
		}

		if ($count_fo <> 0)
		{
			$extend .= $temp;
		}
		else
		{
			$extend = '';
		}
	}

	$spec = ']; ';

	if ($i == ($count_of - 1))
	{
		$spec = '';
	}

	if ($extend == '')
	{
		$base .= "{value:\"0\", text:\" ... \"}";

		$itog .= $base.$spec;
	}
	else
	{
		$base .= $extend;

		$itog .= $base.$spec;
	}
}

$itog .= '];';

// Формируем JavaScript код для выборки элементов
$js_code = '<script>

var type_id =  Object(); '.$itog.'

function setCondition(chooser)
{
    var contChooser = chooser.form.elements["shop_cond_of_delivery_id"];
    // обнуляем список
    contChooser.options.length = 0;
    // получаем value для массива type_id
    var choice = chooser.options[chooser.selectedIndex].value;
    var db = type_id[choice];
    // вставляем первый элемент
    contChooser.options[0] = new Option(" ... ", "", true, false);
    if (choice != "" && choice != 0)
    {
        for (var i = 0; i < db.length; i++)
        {
            contChooser.options[i + 1] = new Option(db[i].text, db[i].value);
        }
    }
}
</script>';

$admin_forms_fields->AddField($params);

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

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

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

$admin_forms_fields->AddField($params);

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

// Информация о заказе
$params = array();
$params['tab_id'] = $tab3_id;
$params['name'] = 'shop_order_system_information';
$params['caption'] = $GLOBALS['MSG_shops']['form_order_system_information'];
$params['type'] = 5; // Текстовое поле
$params['value'] = $shop_order_system_information;
$params['attributes']['rows'] = 10;

$admin_forms_fields->AddField($params);

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

// Фамилия заказчика
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'shop_order_users_surname';
$params['caption'] = $GLOBALS['MSG_shops']['form_order_surname'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_users_surname;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Имя заказчика
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'shop_order_users_name';
$params['caption'] = $GLOBALS['MSG_shops']['form_order_name'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_users_name;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Отчество заказчика
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'shop_order_users_patronymic';
$params['caption'] = $GLOBALS['MSG_shops']['form_order_patronymic'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_users_patronymic;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Компания
$params = array();
$params['tab_id'] = $tab2_id;
$params['name'] = 'shop_order_users_company';
$params['caption'] = $GLOBALS['MSG_shops']['form_order_company'];
$params['type'] = 0; // Поле ввода
$params['value'] = $shop_order_users_company;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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



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


$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'action';
$params['caption'] = '';
$params['type'] = 4; // hidden.
$params['value'] = 'show_order';
$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_order';
$param['caption'] = $GLOBALS['MSG_shops']['save'];
$param['attributes']['onclick'] = "return doSendForm('{$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_order';
$params['caption'] = $GLOBALS['MSG_shops']['apply'];
$params['image'] = '/admin/images/add.gif';
$params['attributes']['onclick'] = "return doSendForm('{$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);

ob_start();
?>
<script type="text/javascript">
location_select_id = "field_id_11";
city_select_id = "field_id_12";
cityarea_select_id = "field_id_13";
</script>
<?php

$js_code .= ob_get_clean();

$admin_forms_fields->SetExternalHtml($js_code);

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