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

$user_access = new user_access();

$form_params = array();
$form_params['title'] = $users_type_id == 0 ? $GLOBALS['MSG_user_access']['ua_add_user_type_form_title'] : $GLOBALS['MSG_user_access']['ua_edit_user_type_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/users_access/users_access.php';
$form_params['form_attribs']['name'] = 'EditAddUsersType';

$admin_forms_fields = new admin_forms_fields();

$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/users_access/users_access.php', '', 7, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/users_access/users_access.php', '', 7, 'load_data'),
'name' => $GLOBALS['MSG_user_access']['ua_link_users_types']);

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

$admin_forms_fields->admin_forms_fields($form_params);

$users_type_row = false;

if ($users_type_id)
{
	$users_type_row = $user_access->GetUserType($users_type_id);
	$site_id = to_int($users_type_row['site_id']);
}
else 
{
	$site_id = CURRENT_SITE;
}

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

// Название группы.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'users_type_name';
$param['caption'] = $GLOBALS['MSG_user_access']['ua_add_edit_user_type_form_name'] ;
$param['type'] = 0; // Поле ввода.

if ($users_type_row)
{
	$param['value'] = to_str($users_type_row['users_type_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'] = 'users_type_comment';
$param['caption'] = $GLOBALS['MSG_user_access']['ua_add_edit_user_type_form_comment'] ;
$param['type'] = 0; // Поле ввода.
$param['format']['maxlen']['value'] = 255;

if ($users_type_row)
{
	$param['value'] = to_str($users_type_row['users_type_comment']);
}

$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_user_access']['siteusers_parent_site_id'];
$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'] = 'users_type_root_dir';
$param['caption'] = $GLOBALS['MSG_user_access']['ua_add_edit_user_type_form_root_dir'];
$param['type'] = 0; // Поле ввода.
$param['format']['maxlen']['value'] = 255;

if ($users_type_row)
{
	$param['value'] = to_str($users_type_row['users_type_root_dir']);
}
else 
{
	$param['value'] = '/';
}

$admin_forms_fields->AddField($param);

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

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