<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования меню.
 * 
 * Файл: /admin/structure/action/form_edit_add_menu.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
if (!isset($menu_id))
{
	$menu_id = to_int($_REQUEST['menu_id']);
}

$admin_forms_fields = new admin_forms_fields();

$structure = & singleton('Structure');
$form_params = array();
$form_params['title'] = $menu_id == 0 ? $GLOBALS['MSG_menu']['menu_add_title'] : $GLOBALS['MSG_menu']['menu_edit_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/structure/structure.php';
$form_params['form_attribs']['name'] = 'EditAddMenu';
$menu = & singleton('menu');

$path_array = $structure->GetStructurePathArray($structure_parent_id, false);

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

$new_path_array[0]['name'] = $GLOBALS['MSG_structure']['parent_dir'];
$new_path_array[0]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/structure/structure.php', "&action=show&structure_parent_id=0", 82, 'load_data');
$new_path_array[0]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/structure/structure.php', "&action=show&structure_parent_id=0", 82, 'load_data');

$new_path_array[1]['name'] = $GLOBALS['MSG_structure']['menu_item_site'];
$new_path_array[1]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/structure/structure.php', '', 87, 'load_data');
$new_path_array[1]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/structure/structure.php', '', 87, 'load_data');

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

// Редактирование меню
if ($menu_id)
{
	$type = 1;

	$row = $menu->SelectMenu($menu_id);

	$menu_name = $row['menu_name'];
	
	$menu_order = $row['menu_order'];
	
	$site_id = $row['site_id'];
}
// Добавление меню
else
{
	$menu_name = '';
	
	$menu_order = 0;
	
	$site_id = CURRENT_SITE;
}

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

// Название меню
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'menu_name';
$param['caption'] = $GLOBALS['MSG_menu']['menu_show_name'];
$param['type'] = 0; // Поле ввода.
$param['attributes']['class'] = 'large';
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['value'] = $menu_name;

$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_menu']['menu_show_site'];
$param['type'] = 2; // Выпадающий список.
$param['items'] = $sites_array;
$param['value'] = $site_id;
$admin_forms_fields->AddField($param);

// Порядок сортировки
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'menu_order';
$param['caption'] = $GLOBALS['MSG_menu']['menu_order'];
$param['type'] = 0; // Поле ввода.
$param['format']['lib']['value'] = 'integer';
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 11;
$param['value'] = $menu_order;

$admin_forms_fields->AddField($param);

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

	$admin_forms_fields->AddField($param);
}

// Кнопка "Сохранить".
$param = array();
$param['name'] = 'save_menu';
$param['caption'] = $GLOBALS['MSG_structure']['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_menu';
$param['caption'] = $GLOBALS['MSG_structure']['apply'];
$param['image'] = '/admin/images/add.gif';
$param['attributes']['type'] = 'submit';
$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']) . " )";
$admin_forms_fields->AddButton($param);

// Отображение формы.
$admin_forms_fields->ShowForm();

?>