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

$form_params = array();
$form_params['title'] = $edit_system_of_pay==0?$GLOBALS['MSG_shops']['system_of_pay_add_form_title']:$GLOBALS['MSG_shops']['system_of_pay_add_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddSystemOfPay';

$admin_forms_fields = new admin_forms_fields();

$shop = & singleton('shop');

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

$row = $shop->GetShop($shop_shops_id);

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

$new_path_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']);

$new_path_array[] = array(
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '', 65, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 65, 'load_data'),
'name' => $row['shop_shops_name']);

$path_array = $shop->GetShopPathArray($shop_groups_parent_id, false);

if ($path_array)
{
	foreach ($path_array as $key => $value)
	{
		$new_path_array[] = array (
			'link' =>  $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
			'onclick' =>  $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
			'name' => $value);
	}
}

$new_path_array[] = array("name" => $GLOBALS['MSG_shops']['system_of_pays'],
	"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 57, 'load_data'),
	"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 57, 'load_data')
	);

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

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

if ($edit_system_of_pay)
{
	$type = 1;
	$result = $shop->GetSystemOfPay($edit_system_of_pay);
	$shop_currency_id = $result['shop_currency_id'];
	$shop_system_of_pay_name = $result['shop_system_of_pay_name'];
	$shop_system_of_pay_description = $result['shop_system_of_pay_description'];
	$shop_system_of_pay_is_active = $result['shop_system_of_pay_is_active'];
	$shop_system_of_pay_order = $result['shop_system_of_pay_order'];
	$shop_shops_id_param = $result['shop_shops_id'];
}
else
{
	$shop_currency_id = 0;
	$shop_system_of_pay_name = '';
	$shop_system_of_pay_description = '';
	$shop_system_of_pay_is_active = 1;
	$system_of_pay_handler = '';
	$shop_system_of_pay_order = 0;
	$shop_shops_id_param = $shop_shops_id;
}

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

// Название платежной системы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'system_of_pay_name';
$param['caption'] = $GLOBALS['MSG_shops']['system_of_pay_add_form_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_system_of_pay_name;
$param['attributes']['class'] = 'large';
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

$shops_array = array();

// Получаем список магазинов
$shops_res = $shop->GetAllShops(CURRENT_SITE);

if($shops_res)
{
	while($shops_row = mysql_fetch_assoc($shops_res))
	{
		$shops_array[$shops_row['shop_shops_id']] = $shops_row['shop_shops_name'];
	}
}

// Магазин, которому принадлежит платежная система
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_id_param';
$param['caption'] = $GLOBALS['MSG_shops']['parent_shop_id'];
$param['type'] = 2; // listbox
$param['items'] = $shops_array;
$param['value'] = $shop_shops_id_param;
$param['attributes']['style'] = 'width: 320px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// Валюта
$arr = array();
$result = $shop->GetAllCurrency();
while ($row = mysql_fetch_assoc($result))
{
	$arr[$row['shop_currency_id']] = $row['shop_currency_name'];
}

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'system_of_pay_currency';
$param['caption'] = $GLOBALS['MSG_shops']['system_of_pay_currency'];
$param['type'] = 2; // listbox
$param['items'] = $arr;
$param['value'] = $shop_currency_id;
$param['attributes']['style'] = 'width: 110px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// Порядок сортировки системы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_system_of_pay_order';
$param['caption'] = $GLOBALS['MSG_shops']['system_of_pay_order'];
$param['type'] = 0; // поле ввода
$param['value'] = $shop_system_of_pay_order;
$param['attributes']['style'] = 'width: 110px;';
$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'] = 'system_of_pay_description';
$param['caption'] = $GLOBALS['MSG_shops']['system_of_pay_add_form_description'];
$param['type'] = 5; // textarea
$param['value'] = $shop_system_of_pay_description;
//$param['format']['minlen']['value'] = 1;
$admin_forms_fields->AddField($param);

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

// Активность
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'system_of_pay_is_active';
$param['caption'] = $GLOBALS['MSG_shops']['system_of_pay_add_form_is_active'];
$param['type'] = 1; // checkbox
$param['value'] = $shop_system_of_pay_is_active;
$admin_forms_fields->AddField($param);

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

// Получаем данные обработчика
$File = new File();
$system_of_pay_handler = $File->GetFileContent(CMS_FOLDER."hostcmsfiles/shop/pay/handler".$edit_system_of_pay.'.php');

// Обработчик платежной системы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'system_of_pay_handler';
$param['caption'] = $GLOBALS['MSG_shops']['system_of_pay_add_form_handler'];
$param['type'] = 5; // textarea
$param['value'] = $system_of_pay_handler;
$param['attributes'] = array();
$param['attributes']['rows'] = 20;
$param['attributes']['style'] = 'height: 400px; width: 100%';
$param['attributes']['class'] = 'codepress php';
$admin_forms_fields->AddField($param);

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

// CodePress для textarea
$admin_forms_fields->AddExternalHtml('<script type="text/javascript">CodePressAction("load");</script>');

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

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


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