<?php
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добавления/редактирования статуса документов.
 * 
 * Файл: /admin/documents/action/form_edit_add_documents_status.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$form_params = array();
$form_params['title'] = ($documents_status_id == 0)
? $GLOBALS['MSG_documents']['documents_status_add_form_title']
: $GLOBALS['MSG_documents']['documents_status_edit_form_title'];

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

$admin_forms_fields = new admin_forms_fields($form_params);

// Массив для хранения "хлебных крошек"
$path_array = array();

$documents = new documents();

$path_array[0] = array (
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax($admin_forms_fields->AAction, "&documents_dir_parent_id=0", 9, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax($admin_forms_fields->AAction, "&documents_dir_parent_id=0", 9, 'load_data'),
'name' => $GLOBALS['MSG_documents']['documents_link']);

$path_array[1] = array (
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax($admin_forms_fields->AAction, '', 124, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax($admin_forms_fields->AAction, '', 124, 'load_data'),
'name' => $GLOBALS['MSG_documents']['documents_add_status_link']);

$form_params['path_array'] = $path_array;

$admin_forms_fields->admin_forms_fields($form_params);

// Извлекаем информацию о документе.
$documents_status_row = false;

if ($documents_status_id)
{
	// Получаем информацию о статусе документов
	$documents_status_resource = $documents->select_status($documents_status_id);

	$site_id = $documents_status_resource['site_id'];
	
	if ($documents_status_resource)
	{
		$documents_status_row = mysql_fetch_assoc($documents_status_resource);
	}
	else
	{
		show_error_message($GLOBALS['MSG_documents']['error_documents_status_id']);
		return false;
	}
}
else 
{
	$site_id =CURRENT_SITE;
}

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

// Название статуса документов.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'documents_status_name';
$param['caption'] = $GLOBALS['MSG_documents']['documents_status_name'];
$param['type'] = 0; // Поле ввода.
if ($documents_status_id)
{
	$param['value'] = to_str($documents_status_row['documents_status_name']);
}
$param['attributes']['class'] = 'large';

$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;

$admin_forms_fields->AddField($param);


// Содержимое документа.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'documents_status_description';
$param['caption'] = $GLOBALS['MSG_documents']['documents_status_description'];
$param['type'] = 5; // Визуальный редактор.
$param['attributes']['rows'] = 5;

if ($documents_status_id)
{
	$param['value'] = to_str($documents_status_row['documents_status_description']);
}

$param['template'] = to_int($version_row['templates_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);

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

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