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

$admin_forms_fields = new admin_forms_fields();

$templates = new templates();

// Формируем "хлебные крошки"
$path_array = $templates->GetTemplatePathArray($templates_group_parent_id);

$new_path_array = array();

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

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

$admin_forms_fields->admin_forms_fields($form_params);

$admin_forms = & singleton('admin_forms');

$template_group_row = $templates->GetTemplatesGroup($templates_group_id);

$site_id = $template_group_row['site_id'];

if ($site_id == 0) 
{
	$site_id = CURRENT_SITE;
}

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

// Название группы макетов
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'templates_group_name';
$param['caption'] = $GLOBALS['MSG_templates']['templates_group_form_name'];
$param['type'] = 0; // Поле ввода.

if ($template_group_row)
{
	$param['value'] = to_str($template_group_row['templates_group_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'] = 'edit_templates_group_parent_id';
$param['caption'] = $GLOBALS['MSG_templates']['templates_group_form_parent'];
$param['type'] = 2; // Выпадающий список.

if ($template_group_row)
{
	$value = to_int($template_group_row['templates_group_parent_id']);
}
else
{
	$value = $templates_group_parent_id;
}

$param['value'] = $value;

$items = array();

$items[0] = '&hellip;';

$tree = $templates->GetTemplateDirTree(0, "&nbsp;&nbsp;", to_int($template_group_row['templates_group_id']));

if ($tree)
{
	foreach ($tree as $key => $value)
	{
		$items[$value[0]] = $value[1];
	}
}

$param['items'] = $items;

$admin_forms_fields->AddField($param);

$sites_array = array();

// Получаем список доступных сайтов
$site = & singleton ('site');

// Получаем данные о пользователе
$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_templates']['templates_site'];
$param['type'] = 2; // Выпадающий список.
$param['items'] = $sites_array;
$param['value'] = $site_id;
$admin_forms_fields->AddField($param);

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

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


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


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