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

if (!isset($admin_forms_id))
{
	$admin_forms_id = to_int($_REQUEST['admin_forms_edit_id']);
	//$admin_forms_id = to_int($_REQUEST['admin_forms_id']);
}

$form_params = array();
$form_name = '';

if ($admin_forms_id)
{
	$form_row = $admin_forms->GetAdminForm($admin_forms_id);

	if ($form_row)
	{
		$form_word_row = $admin_forms->GetAdminFormsWord(to_int($form_row['admin_words_id']));
	}
	$form_name = to_str($form_word_row['name']);
}

$form_params['title'] = $admin_forms_events_id == 0
? $GLOBALS['MSG_admin_forms']['form_add_forms_event_title']
: sprintf($GLOBALS['MSG_admin_forms']['form_edit_forms_event_title'], $form_name);

$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/admin_forms/admin_forms.php';
$form_params['form_attribs']['name'] = 'EditAddAdminFormEvent';

$admin_forms_fields = & singleton('admin_forms_fields');

$form_row = $admin_forms->GetAdminForm($admin_forms_id);

if ($form_row)
{
	$form_word_row = $admin_forms->GetAdminFormsWord(to_int($form_row['admin_words_id']));
}

// Формируем "хлебные крошки"
$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/admin_forms/admin_forms.php', '', 1, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/admin_forms/admin_forms.php', '', 1, 'load_data'),
'name' => $GLOBALS['MSG_admin_forms']['show_form_fields_menu_admin_forms']);

$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/admin_forms/admin_forms.php', "&admin_forms_edit_id=$admin_forms_id", 4, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/admin_forms/admin_forms.php', "&admin_forms_edit_id=$admin_forms_id", 4, 'load_data'),
'name' => sprintf($GLOBALS['MSG_admin_forms']['form_event_menu_admin_form_events'], to_str($form_word_row['name'])));

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

if ($admin_forms_events_id)
{
	$event_row = $admin_forms->GetAdminFormsEvent($admin_forms_events_id);
}
else
{
	$event_row = false;
}

// Закладка с названием/описанием.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_admin_forms']['form_forms_event_tab_1']);

// Извлекаем информацию о названии и описание на всех языках.
$languages = $admin_forms->GetAllLanguages();

if ($languages)
{
	foreach ($languages as $lng)
	{
		$name = '';
		$description = '';

		if ($event_row)
		{
			$word = $admin_forms->GetAdminFormsWord(to_int($event_row['admin_words_id']), $lng['admin_language_id']);
			
			if ($word)
			{
				$name = to_str($word['name']);
				$description = to_str($word['description']);
			}
		}

		// Название формы.
		$param = array();
		$param['tab_id'] = $tab_id;
		$param['name'] = 'admin_forms_word_name_lng_' . $lng['admin_language_id'];
		$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_lng_name'] . ' (' . $lng['admin_language_short_name'] . ')';
		$param['type'] = 0; // Поле ввода.
		$param['value'] = $name;
		$param['attributes']['class'] = 'large';
		$param['format']['minlen']['value'] = 1;
		$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'] = 'admin_forms_word_description_lng_' . $lng['admin_language_id'];
		$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_lng_description'] .' (' . $lng['admin_language_short_name'] . ')';
		$param['type'] = 5; // Textarea.
		$param['value'] = $description;
		$param['attributes'] = array();
		$param['attributes']['rows'] = 7;
		$param['attributes']['style'] = 'width: 100%;';
		$admin_forms_fields->AddField($param);
	}
}

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

// Закладка с параметрами.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_admin_forms']['form_forms_event_tab_2']);

// Название функции.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'admin_forms_events_function';
$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_function'];
$param['type'] = 0; // Поле ввода.

if ($event_row)
{
	$param['value'] = to_str($event_row['admin_forms_events_function']);
}

$admin_forms_fields->AddField($param);

// Порядок сортировки.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'admin_forms_events_order';
$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_order'];
$param['type'] = 0; // Поле ввода.

if ($event_row)
{
	$param['value'] = to_str($event_row['admin_forms_events_order']);
}

$admin_forms_fields->AddField($param);

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

// Изображение.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'admin_forms_events_picture';
$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_picture'];
$param['type'] = 0; // Поле ввода.

if ($event_row)
{
	$param['value'] = to_str($event_row['admin_forms_events_picture']);
}

$admin_forms_fields->AddField($param);

// Набор данных.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'admin_forms_events_dataset_id';
$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_dataset_id'];
$param['type'] = 0; // Поле ввода.

if ($event_row)
{
	$param['value'] = to_str($event_row['admin_forms_events_dataset_id']);
}
else 
{
	$param['value'] = -1;
}

$admin_forms_fields->AddField($param);

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

// Отображать в списке действий.
$param = array();
$param['tab_id'] = $tab_id;
$param['type'] = 1; // Checkbox.
$param['name'] = 'admin_forms_events_show_button';
$param['html_id'] = 'id_admin_forms_events_show_button';
$param['value'] = to_int($event_row['admin_forms_events_show_button']);
$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_show_button'];

$admin_forms_fields->AddField($param);

// Отображать в списке групповых операций.
$param = array();
$param['tab_id'] = $tab_id;
$param['type'] = 1; // Checkbox.
$param['name'] = 'admin_forms_events_group_operation';
$param['html_id'] = 'id_admin_forms_events_group_operation';
$param['value'] = to_int($event_row['admin_forms_events_group_operation']);
$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_group_operation'];

$admin_forms_fields->AddField($param);

// Запрашивать подтверждение перед выполнением дейтсвия.
$param = array();
$param['tab_id'] = $tab_id;
$param['type'] = 1;
$param['name'] = 'admin_forms_events_ask';
$param['html_id'] = 'id_admin_forms_events_ask';
$param['value'] = to_int($event_row['admin_forms_events_ask']);
$param['caption'] = $GLOBALS['MSG_admin_forms']['form_forms_event_ask'];

$admin_forms_fields->AddField($param);

// Отобразить список событий формы.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'action';
$param['type'] = 4; // Скрытое поле.
$param['value'] = 'show_admin_form_events';
$admin_forms_fields->AddField($param);

// Добавляем скрытое поле с идентификатором формы, которой принадлежит событие.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'admin_forms_edit_id';
$param['type'] = 4; // Сркытое поле.
$param['value'] = to_int($_REQUEST['admin_forms_edit_id']);
$admin_forms_fields->AddField($param);

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

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