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

$admin_forms_fields = new admin_forms_fields();

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

$documents = new documents();

$path_array = $documents->GetDocumentsPathArray($documents_dir_parent_id);

if (count($path_array) > 0)
{
	// Преобразуем идентификаторы групп в ссылки на группы.
	if ($path_array)
	{
		foreach ($path_array as $key => $value)
		{
			$new_path_array[] = array (
			'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax($admin_forms_fields->AAction, "&documents_dir_parent_id={$value}", 9, 'load_data'),
			'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax($admin_forms_fields->AAction, "&documents_dir_parent_id={$value}", 9, 'load_data'),
			'name' => $key);
		}
	}
}

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

$row = false;

if ($document_dir_id)
{
	$row = $documents->GetDocumentDir($document_dir_id);
	
	$site_id = $row['site_id'];
}
else 
{
	$site_id = CURRENT_SITE;
}

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

// Количество элементов на страницу.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'documents_dir_name';
$param['caption'] = $GLOBALS['MSG_documents']['documents_add_edit_dir_form_name'];
$param['type'] = 0; // Поле ввода.

if ($row)
{
	$param['value'] = to_str($row['documents_dir_name']);
}

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

$admin_forms_fields->AddField($param);

$sites_array = array();

$site = & singleton ('site');

$sites_array = array();

// Получаем данные о пользователе
$UserAccess = new user_access();
$user_row = $UserAccess->GetUserByName($_SESSION['valid_user']);

// Выбираем доступные сайты
$res = $site->SelectSites(array('users_type_id' => to_int($user_row['users_type_id'])));

while ($rows = mysql_fetch_assoc($res))
{
	$sites_array[$rows['site_id']] = $rows['site_name'];
}

// Список сайтов.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'site_id';
$param['caption'] = $GLOBALS['MSG_documents']['documents_site'];
$param['type'] = 2; // Выпадающий список.
$param['items'] = $sites_array;
$param['value'] = $site_id;
$admin_forms_fields->AddField($param);

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

// Родительская группа.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'documents_dir_parent_id2';
$param['caption'] = $GLOBALS['MSG_documents']['documents_add_edit_dir_form_dir_name'];
$param['type'] = 2; // Выпадающий список.

if ($row)
{
	$value = to_int($row['documents_dir_parent_id']);
}
else
{
	$value = $documents_dir_parent_id;
}
$param['value'] = $value;

$items = array();
$items[0] = '&hellip;';

$tree = $documents->GetDocumentsDirTree(0, "&nbsp;&nbsp;", to_int($row['documents_dir_id']));

if ($tree)
{
	foreach ($tree as $key => $value)
	{
		$items[$value[0]] = $value[1];
	}
}
$param['items'] = $items;
$admin_forms_fields->AddField($param);

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

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