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

if (!isset($lib_dir_parent_id))
{
	$lib_dir_parent_id = 0;
}

$form_params = array();
$form_params['title'] = $lib_id == 0 ? $GLOBALS['MSG_lib']['lib_form_title_add'] : $GLOBALS['MSG_lib']['lib_form_title_edit'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/lib/lib.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';
$form_params['form_attribs']['name'] = 'EditAddLib';

$lib = new lib();

$path_array = $lib->GetLibPathArray($lib_dir_parent_id);
$path = $lib->path_array;

$admin_forms_fields = new admin_forms_fields();

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

$form_params['path_array'][0]['name'] = $GLOBALS['MSG_lib']['menu'];

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

// Редактирование адреса
if ($lib_id)
{
	$type = 1;
	$result = $lib->GetLib($lib_id);
	$lib_name = $result['lib_name'];
	$lib_description = $result['lib_description'];
	$lib_module = $result['lib_module'];
	$lib_module_config = $result['lib_module_config'];
}
// Добавление адреса
else
{
	$lib_name = '';
	$lib_description = '';
	$lib_module = '';
	$lib_module_config = '';
}

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

$mas = array();

$mas = $lib->GetLibDirTree(0, "&nbsp;&nbsp;");

$array[0] = ' ... ';

$values_arr[0] = 0;

$mas_count = count($mas);

for ($i=0; $i < $mas_count; $i++)
{
	$array[$mas[$i][0]] = $mas[$i][1];
}

// название
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'lib_name';
$param['caption'] = $GLOBALS['MSG_lib']['lib_form_name'];
$param['type'] = 0; // textbox
$param['value'] = $lib_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'] = 'lib_dir_parent_id';
$param['caption'] = $GLOBALS['MSG_lib']['lib_form_parent_dir'];
$param['type'] = 2; // выпадающий список
$param['items'] = $array;
$param['value'] = $lib_dir_parent_id;
$admin_forms_fields->AddField($param);

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

// описание
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'lib_description';
$param['caption'] = $GLOBALS['MSG_lib']['lib_form_description'];
$param['type'] = 5; // textarea
$param['attributes']['cols'] = 140;
$param['attributes']['rows'] = 6;
$param['value'] = $lib_description;
$admin_forms_fields->AddField($param);

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

$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_lib']['lib_php_code']);

//PHP-код страницы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'lib_module';
$param['caption'] = $GLOBALS['MSG_lib']['lib_form_module'];
$param['type'] = 5; // Поле ввода.
$param['attributes']['cols'] = 140;
$param['attributes']['rows'] = 20;
$param['value'] = $lib_module;
$param['attributes']['style'] = 'height: 400px; width: 100%';
$param['attributes']['class'] = 'codepress php';
$admin_forms_fields->AddField($param);

$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_lib']['lib_php_code_config']);

// настройки страницы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'lib_module_config';
$param['caption'] = $GLOBALS['MSG_lib']['lib_form_module_config'];
$param['type'] = 5; // Поле ввода.
$param['attributes']['cols'] = 140;
$param['attributes']['rows'] = 20;
$param['value'] = $lib_module_config;
$param['attributes']['style'] = 'height: 400px; width: 100%';
$param['attributes']['class'] = 'codepress php';
$admin_forms_fields->AddField($param);

// CodePress для textarea
$admin_forms_fields->AddExternalHtml('<script type="text/javascript">CodePressAction("load");</script>');

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'lib_dir_id';
$param['caption'] = '';
$param['type'] = 4; // hidden.
$param['value'] = $lib_dir_parent_id;

$admin_forms_fields->AddField($param);

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

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