<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добавления/редактирования домена сайта.
 * 
 * Файл: /admin/site/action/add_edit_domen_form.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$site = & singleton ('site');

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

// Редактирование модуля
if ($site_alias_id)
{
	$type = 1;
	$result =$site->GetAliasById($site_alias_id);	
	$site_id = to_int($result['site_id']);
	$alias_name = trim(to_str($result['alias_name']));
	$alias_current = to_int($result['alias_current']);
}
// Добавление модуля
else
{
	$site_id = to_int($_REQUEST['site_id']);
	$alias_name = '';
	$alias_current = 0;
}

$result = $site->GetSite($site_id);

$form_params = array();

$form_params['title'] = $site_alias_id == 0 ? $GLOBALS['MSG_site']['site_add_domen_form_title'] : $GLOBALS['MSG_site']['site_edit_domen_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/site/site.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';
$form_params['form_attribs']['name'] = 'EditAddDomain';

$DataBase = & singleton('DataBase');

$admin_forms_fields = new admin_forms_fields();

$form_params['path_array'][] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/site/site.php', '&site_id=0', 42, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/site/site.php', '&site_id=0', 42, 'load_data'),
'name' => $GLOBALS['MSG_site']['site_link_sites']);

$form_params['path_array'][] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/site/site.php', "&site_id=$site_id&action=show_alias", 43, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/site/site.php', "&site_id=$site_id&action=show_alias", 43, 'load_data'),
'name' => sprintf($GLOBALS['MSG_site']['site_link_site_name'], $result['site_name']));

$admin_forms_fields->admin_forms_fields($form_params);

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

// название домена
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'alias_name';
$param['caption'] = $GLOBALS['MSG_site']['site_add_edit_domen_form_name'];
$param['type'] = 0; // textbox
$param['attributes']['class'] = 'large';
$param['attributes']['size'] = 50;
$param['value'] = $alias_name;
$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'] = 'alias_current';
$param['caption'] = $GLOBALS['MSG_site']['site_add_edit_domen_form_current'];
$param['type'] = 1; // checkbox
$param['value'] = $alias_current;

$admin_forms_fields->AddField($param);

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

	$admin_forms_fields->AddField($param);
}

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

$admin_forms_fields->AddField($param);

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