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

$shop = & singleton('shop');

$admin_forms_fields = new admin_forms_fields();

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

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


// Получаем информацию о пользователе сайта
if (class_exists('SiteUsers'))
{
	$SiteUser = & singleton('SiteUsers');

	$site_users_row = $SiteUser->GetSiteUser($site_users_id, array('cache_off' => true));

	$site_users_login = $site_users_row['site_users_login'];
}
else
{
	$site_users_login = '';
}

// Получаем информацию о магазине
$shop = & singleton('shop');

$shop_row = $shop->GetShop($shop_shops_id, array('cache_off' => true));

$shop_name = $shop_row['shop_shops_name'];

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

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

array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '&site_users_id='.$site_users_id, 133, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '&site_users_id='.$site_users_id, 133, 'load_data'),
'name' => sprintf($GLOBALS['MSG_shops']['users_account_table'], $site_users_login)
),

array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '&site_users_id='.$site_users_id.'&shop_shops_id='.$shop_shops_id, 134, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '&site_users_id='.$site_users_id.'&shop_shops_id='.$shop_shops_id, 134, 'load_data'),
'name' => sprintf($GLOBALS['MSG_shops']['transaction_user_account'], $site_users_login, $shop_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']);

$shop = new shop();

if ($transaction_id == 0)
{
	$shop_site_users_account_description = '';

	$shop_site_users_account_active = 1;

	$shop_site_users_account_datetime = date("d.m.Y H:i:s");

	$shop_site_users_account_sum = '0.00';

	$shop_currency_ids = 0;

	$shop_order_id = 0;
	
	$shop_site_users_account_type = 0;
}
else
{
	$res = $shop->GetSiteUserAccountTransaction($transaction_id);

	$shop_site_users_account_description = $res['shop_site_users_account_description'];

	$shop_site_users_account_active = $res['shop_site_users_account_active'];

	$shop_site_users_account_datetime = $DateTime->datetime_format($res['shop_site_users_account_datetime']);

	$shop_site_users_account_sum = $res['shop_site_users_account_sum'];

	$shop_currency_ids = $res['shop_currency_id'];

	$shop_order_id = $res['shop_order_id'];
	
	$shop_site_users_account_type = $res['shop_site_users_account_type'];
}


// Получаем идентификатор валют
$shop_currency_id = to_int($_REQUEST['shop_currency_id']);

// Описание транзакции
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_site_users_account_description';
$param['caption'] = $GLOBALS['MSG_shops']['transaction_description'];
$param['type'] = 5; // Текстовое поле.
$param['value'] = $shop_site_users_account_description;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['attributes']['rows'] = 5;
$param['attributes']['class'] = 'large';

$admin_forms_fields->AddField($param);

// Активность транзакции
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_site_users_account_active';
$param['caption'] = $GLOBALS['MSG_shops']['transaction_active'];
$param['type'] = 1; // Флажок
$param['value'] = $shop_site_users_account_active;

$admin_forms_fields->AddField($param);


// ДатаВремя транзакции
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_site_users_account_datetime';
$param['caption'] = $GLOBALS['MSG_shops']['transaction_datetime'];
$param['type'] = 11; // ДатаВремя
$param['value'] = $shop_site_users_account_datetime;

$admin_forms_fields->AddField($param);


// Сумма транзакции
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_site_users_account_sum';
$param['caption'] = $GLOBALS['MSG_shops']['transaction_sum'];
$param['type'] = 0; // Поле ввода
$param['value'] = $shop_site_users_account_sum;
$param['format']['lib']['value'] = 'decimal';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_decimal'];
$param['format']['maxlen']['value'] = 255;
$param['attributes']['style'] = 'width: 75px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);


// Получаем список валют
$arr = array();

$arr[0] = ' ... ';

$currency = $shop->GetAllCurrency();

while ($row = mysql_fetch_assoc($currency))
{
	$arr[$row['shop_currency_id']] = $row['shop_currency_name'];
}

// Список валют
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_currency_id';
$param['caption'] = '&nbsp;';
$param['type'] = 2; // groupbox
$param['items'] = $arr;
$param['value'] = $shop_currency_ids;
$param['attributes']['style'] = 'width: 100px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

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

// Идентификатор заказа
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_order_id';
$param['caption'] = $GLOBALS['MSG_shops']['transaction_order_id'];
$param['type'] = 0; // текстовое поле
$param['items'] = $arr;
$param['value'] = $shop_order_id;
$param['format']['lib']['value'] = 'integer';
$param['attributes']['style'] = 'width: 75px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

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

$arr = array(0 => $GLOBALS['MSG_shops']['shop_site_users_account_type_typical'],
1 => $GLOBALS['MSG_shops']['shop_site_users_account_type_bonus']);
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_site_users_account_type';
$param['caption'] = $GLOBALS['MSG_shops']['shop_site_users_account_type'];
$param['type'] = 13; // радиокнопки
$param['value'] = $shop_site_users_account_type;
$param['options']['count'] = 2;
$param['options']['labels'] = $arr;
$param['options']['input_text'] = -1;
$param['options']['index'] = array(0 => 0, 1 => 1);
$param['options']['ext_name'] = array(0 => 0, 1 => 1);
$param['options']['onclick'] = 'SetViewImport(%ext_name%)';
$param['separator'] = '';
$admin_forms_fields->AddField($param);


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


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

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

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

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