<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добавления/редактирования раздела XSL-шаблонов.
 * 
 * Файл: /admin/xsl/action/form_edit_add_xsl_dir.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$form_params = array();
$form_params['title'] = $xsl_dir_id == 0 ? $GLOBALS['MSG_xsl']['XSL_add_dir_form_title'] : $GLOBALS['MSG_xsl']['XSL_edit_dir_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/xsl/xsl.php';
$form_params['form_attribs']['name'] = 'EditAddXslDir';

$admin_forms_fields = new admin_forms_fields();

$xsl = new xsl();

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

$xsl->GetMasXslGroupPath($xsl_dir_parent_id, $xsl_dir_parent_id);

$path_array =  $xsl->mas_xsl_group_path[$xsl_dir_parent_id];

$new_path_array = array();

if (count($path_array) > 0)
{
	// Меняем порядок следования элементов в массиве на обратный
	$path_array = array_reverse($path_array, true);

	if ($path_array)
	{
		foreach ($path_array as $key => $value)
		{
			$new_path_array[] = array (
			'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/xsl/xsl.php', "&xsl_dir_parent_id=$key", 22, 'load_data'),
			'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/xsl/xsl.php', "&xsl_dir_parent_id=$key", 22, 'load_data'),
			'name' => $value['xsl_dir_name']);
		}
	}
}

// Передаем в массив для констурктора хлебные крошки
$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

// Редактирование раздела XSL
if ($xsl_dir_id)
{
	$result = $xsl->select_xsl_dir($xsl_dir_id);
	
	$row_xsl_dir = mysql_fetch_assoc($result);
	
	$xsl_dir_name = $row_xsl_dir["xsl_dir_name"];
	$xsl_dir_order = $row_xsl_dir["xsl_dir_order"];
}
// Добавление раздела XSL
else
{
	$xsl_dir_name = '';
	$xsl_dir_order = 0;
}

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

// Название раздела XSL.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'xsl_dir_name';
$param['caption'] = $GLOBALS['MSG_xsl']["XSL_add_edit_dir_form_name"];
$param['type'] = 0; // Поле ввода.
$param['attributes'] = array();
$param['attributes']['class'] = 'large';
$param['value'] = $xsl_dir_name;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Структура каталогов XSL.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'edit_xsl_dir_parent_id';
$param['caption'] = $GLOBALS['MSG_xsl']["XSL_add_edit_dir_form_dir_name"];
$param['type'] = 2; // Выпадающий список.

if ($xsl_dir_id)
{
	$value =$row_xsl_dir["xsl_dir_parent_id"];
}
{
	$value = $xsl_dir_parent_id;
}

$param['value'] = $value;

$items = array();

$mas = array();

// Формируем дерево разделов XSL-шаблонов
$mas = $xsl->fill_xsl_dir(0, "&nbsp;&nbsp;");

$mas_count = count($mas);

$items[0] = "..";

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

$param['items'] = $items;

$admin_forms_fields->AddField($param);

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

// Порядковый номер.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'xsl_dir_order';
$param['caption'] = $GLOBALS['MSG_xsl']['XSL_add_edit_dir_form_order'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $xsl_dir_order;

$admin_forms_fields->AddField($param);

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

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'xsl_dir_parent_id';
$param['type'] = 4; // Скрытое поле.
$param['value'] = $xsl_dir_parent_id;
$admin_forms_fields->AddField($param);

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

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