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

$form_params['title'] = ($edit_ip == 0)
? $GLOBALS['MSG_ip']['ip_add_form_title']
: $GLOBALS['MSG_ip']['ip_edit_form_title'];

$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/ip/ip.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';
$form_params['form_attribs']['name'] = 'EditAddIP';

$ip = new ip();

$admin_forms_fields = new admin_forms_fields();

$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/ip/ip.php', '', 25, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/ip/ip.php', '', 25, 'load_data'),
'name' => $GLOBALS['MSG_ip']['add_ip_link']);

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

$admin_forms_fields->admin_forms_fields($form_params);

// Редактирование адреса
if ($edit_ip)
{
	$row = $ip->GetIp($edit_ip);

	if ($row)
	{
		$ip_comment = to_str($row['ip_comment']);
		$ip_ip = to_str($row['ip_ip']);
		$deny_access = to_int($row['ip_deny_access']);
		$off_stat = to_int($row['ip_no_statistic']);
	}
}
// Добавление адреса
else
{
	$ip_ip = '';
	$deny_access = 0;
	$off_stat = 0;
	$ip_comment = '';
}

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

// адрес
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'ip_ip';
$param['caption'] = $GLOBALS['MSG_ip']['add_ip_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $ip_ip;
$param['attributes']['class'] = 'large';
$param['format']['minlen']['value'] = 1;
$param['format']['lib']['value'] = 'ip';
$param['format']['lib']['message'] = $GLOBALS['MSG_ip']['invalid_ip'];

$admin_forms_fields->AddField($param);

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

// заблокировать
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'ip_deny_access';
$param['caption'] = $GLOBALS['MSG_ip']['ip_show_deny_access'];
$param['type'] = 1; // checkbox
$param['value'] = $deny_access;

$admin_forms_fields->AddField($param);

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

// не учитывать в статистике
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'ip_no_statistic';
$param['caption'] = $GLOBALS['MSG_ip']['ip_show_no_statistic'];
$param['type'] = 1; // checkbox
$param['value'] = $off_stat;

$admin_forms_fields->AddField($param);

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

// комментарий адреса
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'ip_comment';
$param['caption'] = $GLOBALS['MSG_ip']['ip_show_comment'];
$param['type'] = 5; // Поле ввода.
$param['attributes']['cols'] = 40;
$param['attributes']['rows'] = 5;
$param['value'] = $ip_comment;

$admin_forms_fields->AddField($param);

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

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