<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования значений аффилиата.
 * 
 * Файл: /admin/shop/action/form_edit_add_affiliate_values.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$form_params = array();
$form_params['title'] = ($affiliate_values_id == 0)?$GLOBALS['MSG_shops']['add_affiliate_value']:$GLOBALS['MSG_shops']['edit_affiliate_value'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'AddAffiliateValue';

$shop = & singleton('shop');

$admin_forms_fields = new admin_forms_fields();

$affiliate_plans_id = to_int($_REQUEST['affiliate_plans_id']);

// Получаем имя партнерской программы
$affiliate_plans_row = $affiliate->GetAffiliatePlans($affiliate_plans_id);

$new_path_array = array(
array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data'),
'name' => $GLOBALS['MSG_shops']['header_admin__list_forms']),

array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '', 162, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 162, 'load_data'),
'name' => $GLOBALS['MSG_shops']['affiliate_form_title']),

array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '', 164, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 164, 'load_data'),
'name' => sprintf($GLOBALS['MSG_shops']['affiliate_values_form_title'], $affiliate_plans_row['affiliate_plans_name'])));


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

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

$DateTime = new DateClass();

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

if ($affiliate_values_id)
{
	$row = $affiliate->GetAffiliateValues($affiliate_values_id);

	$affiliate_plans_id_base = $row['affiliate_plans_id'];

	$affiliate_values_inner_level = $row['affiliate_values_inner_level'];

	$affiliate_values_percent = $row['affiliate_values_percent'];

	$affiliate_values_value = $row['affiliate_values_value'];

	$affiliate_values_type = $row['affiliate_values_type'];
}
else
{
	$affiliate_plans_id_base = $affiliate_plans_id;

	$affiliate_values_inner_level = 1;

	$affiliate_values_percent = 0;

	$affiliate_values_value = 0;

	$affiliate_values_type = 0;
}

// Уровень вложенности
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'affiliate_values_inner_level';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_affiliate_values_inner_level'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $affiliate_values_inner_level;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 11;
$param['attributes']['class'] = 'large';
$param['div_attributes']['style'] = 'width: 100px; float: left';

$admin_forms_fields->AddField($param);

// Процент, учитываемый при просчете комиссии
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'affiliate_values_percent';
$param['div_id'] = 'affiliate_values_percent_id';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_affiliate_values_percent'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $affiliate_values_percent;
$param['format']['lib']['value'] = 'decimal';
$param['attributes']['class'] = 'large';
$param['div_attributes']['style'] = 'width: 100px; float: left; margin-left: 10px;';

if ($affiliate_values_type)
{
	$param['div_attributes']['style'] .= "display: none;";
}

$admin_forms_fields->AddField($param);

// Фиксированная сумма, учитываемая при просчете комиссии
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'affiliate_values_value';
$param['div_id'] = 'affiliate_values_value_id';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_affiliate_values_value'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $affiliate_values_value;
$param['format']['lib']['value'] = 'decimal';
$param['attributes']['class'] = 'large';
$param['div_attributes']['style'] = 'width: 100px; float: left; margin-left: 10px;';

if (!$affiliate_values_type)
{
	$param['div_attributes']['style'] .= "display: none;";
}

$admin_forms_fields->AddField($param);

// Тип комиссии (0 - процент, 1 - фиксированная сумма)
$arr = array(
0 => $GLOBALS['MSG_shops']['form_edit_affiliate_values_type_percent'], 
1 => $GLOBALS['MSG_shops']['form_edit_affiliate_values_type_summ']);

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'affiliate_values_type';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_affiliate_values_type'];
$param['type'] = 13; // радиокнопки
$param['value'] = $affiliate_values_type;
$param['options']['count'] = 2;
$param['options']['labels'] = $arr;
$param['options']['input_text'] = -1;
$param['options']['index'] = array(0 => 0, 1 => 1);
$param['options']['onclick'] = 'SetViewField(%index%)';
$param['div_attributes']['style'] = 'float: left; margin-left: 10px;';
$admin_forms_fields->AddField($param);

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

// Получаем список всех партнерских программ
$affiliate_plans_res = $affiliate->GetAllAffiliatePlans(array(), CURRENT_SITE);

$affiliate_plans_array = array(0 => ' ... ');

if ($affiliate_plans_res)
{
	while ($affiliate_plans_row = mysql_fetch_assoc($affiliate_plans_res))
	{
		$affiliate_plans_array[$affiliate_plans_row['affiliate_plans_id']] = $affiliate_plans_row['affiliate_plans_name'];
	}
}

// Партнерка, которой принадлежит уровень
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'affiliate_plans_id_base';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_affiliate_plans_id'];
$param['type'] = 2; // Выпадающий список
$param['value'] = $affiliate_plans_id_base;
$param['items'] = $affiliate_plans_array;

$admin_forms_fields->AddField($param);

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

if ($affiliate_values_id)
{
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'affiliate_values_id';
	$param['caption'] = '';
	$param['type'] = 4; // hidden.
	$param['value'] = $affiliate_values_id;
	$admin_forms_fields->AddField($param);
}

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