<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добавления/редактирования поискового запроса.
 * 
 * Файл: /admin/seo/action/form_edit_add_query.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$form_params = array();

$form_params['title'] = $edit_query_id == 0
? $GLOBALS['MSG_seo']['query_add_form_title']
: $GLOBALS['MSG_seo']['query_edit_form_title'];

//Метод отправки данных
$form_params['form_attribs']['method'] = 'post';

//Адрес всех обработчиков модуля – главный файл формы
$form_params['form_attribs']['action'] = '/admin/seo/seo.php';

//Метод отправки данных
$form_params['form_attribs']['name'] = 'EditAddQuery';

$admin_forms_fields = new admin_forms_fields();

//Хлебные крошки
$form_params['path_array'] = array(
array('link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/seo/seo.php', '', 141, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/seo/seo.php', '', 141, 'load_data'),
'name' => $GLOBALS['MSG_seo']['header_admin_characteristic_forms']),
array('link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/seo/seo.php', '', 142, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/seo/seo.php', '', 142, 'load_data'),
'name' => $GLOBALS['MSG_seo']['menu_search_query']));

$admin_forms_fields->admin_forms_fields($form_params);

$row = false;

$seo = new Seo();

// Редактировние GetQuery
if ($edit_query_id)
{
	$row = $seo->GetQuery($edit_query_id);
	$site_id = $row['site_id'];
	$users_id = $row['users_id'];
	$seo_search_query_id = $row['seo_search_query_id'];
	$seo_search_query_value = $row['seo_search_query_value'];
}
// Добавление
else
{
	$site_id = CURRENT_SITE;
	$seo_search_query_value = '';
	$users_id = 0;
}

// Параметры.

$tab_id = $admin_forms_fields->AddTab('');

// Запрос
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'seo_search_query_value';
$param['caption'] = $GLOBALS['MSG_seo']['seo_add_edit_query_caption_search_value'];
$param['value'] = $seo_search_query_value;
$param['attributes']['class'] = 'large';
$param['format']['minlen']['value'] = 1;

if ($edit_query_id)
{
	$param['type'] = 0; // Поле ввода.
}
else
{
	$param['type'] = 5; // Textarea.
	$param['attributes'] = array();
	$param['attributes']['rows'] = 7;
}

$admin_forms_fields->AddField($param);

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

if(to_int($row['seo_search_query_id']))
{
	// Добавляем скрытое поле с идентификатором сущности, т.к. идет редактирование.
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'seo_search_query_id';
	$param['type'] = 4; // Скрытое поле.
	$param['value'] = to_int($row['seo_search_query_id']);
	$admin_forms_fields->AddField($param);
}

// Добавляем скрытое поле с сайта.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'site_id';
$param['type'] = 4; // Скрытое поле.
$param['value'] = $site_id;
$admin_forms_fields->AddField($param);

// Кнопка "Сохранить".
$param = array();
$param['name'] = 'save_query';
$param['caption'] = $GLOBALS['MSG_seo']['save_button_name'];
$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_query';
$param['caption'] = $GLOBALS['MSG_seo']['apply_button_name'];
$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();
?>