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

$form_params = array();
$form_params['title'] = $shop_company_id==0?$GLOBALS['MSG_shops']['company_form_add_title']:$GLOBALS['MSG_shops']['company_form_edit_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddCompany';

$shop = & singleton('shop');

$admin_forms_fields = new admin_forms_fields();

$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', '', 64, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 64, 'load_data'),
'name' => $GLOBALS['MSG_shops']['company_show_title2']);

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

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

// Редактировние сведений об организации
if ($shop_company_id)
{
	$type = 1;

	$result = $shop->GetCompany($shop_company_id);

	$shop_company_name = $result['shop_company_name'];
	
	$shop_company_description = $result['shop_company_description'];
	
	$shop_company_inn = $result['shop_company_inn'];
	
	$shop_company_kpp = $result['shop_company_kpp'];
	
	$shop_company_ogrn = $result['shop_company_ogrn'];
	
	$shop_company_okpo = $result['shop_company_okpo'];
	
	$shop_company_okved = $result['shop_company_okved'];
	
	$shop_company_bik = $result['shop_company_bik'];
	
	$shop_company_account = $result['shop_company_account'];
	
	$shop_company_corr_account = $result['shop_company_corr_account'];
	
	$shop_company_bank_name = $result['shop_company_bank_name'];
	
	$shop_company_bank_address =$result['shop_company_bank_address'];
	
	$shop_company_fio = $result['shop_company_fio'];
	
	$shop_company_accountant_fio = $result['shop_company_accountant_fio'];
	
	$shop_company_address = $result['shop_company_address'];
	
	$shop_company_phone = $result['shop_company_phone'];
	
	$shop_company_fax = $result['shop_company_fax'];
	
	$shop_company_site = $result['shop_company_site'];
	
	$shop_company_email = $result['shop_company_email'];
	
	$shop_company_guid = $result['shop_company_guid'];
}
// Добавление сведений об организации
else
{
	$shop_company_name = '';
	
	$shop_company_description = '';
	
	$shop_company_inn = '';
	
	$shop_company_kpp = '';
	
	$shop_company_ogrn = '';
	
	$shop_company_okpo = '';
	
	$shop_company_okved = '';
	
	$shop_company_bik = '';
	
	$shop_company_account = '';
	
	$shop_company_corr_account = '';
	
	$shop_company_bank_name = '';
	
	$shop_company_bank_address = '';
	
	$shop_company_fio = '';
	
	$shop_company_accountant_fio = '';
	
	$shop_company_address = '';
	
	$shop_company_phone = '';
	
	$shop_company_fax = '';
	
	$shop_company_site = '';
	
	$shop_company_email = '';
	
	$shop_company_guid = '';
}

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

// Название организации
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_company_name';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_name;
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['attributes']['class'] = 'large';

$admin_forms_fields->AddField($param);

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

// Описание организации

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_company_description';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_description'];
$param['template'] = 0; // ID шаблона
$param['type'] = 7; // Поле ввода (textarea)
$param['value'] = $shop_company_description;

$admin_forms_fields->AddField($param);

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

// Руководство.
$tab2_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab2_company']);

// ФИО генерального директора
$param = array();
$param['tab_id'] = $tab2_id;
$param['name'] = 'shop_company_fio';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_fio'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_fio;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// ФИО главного бухгалтера
$param = array();
$param['tab_id'] = $tab2_id;
$param['name'] = 'shop_company_accountant_fio';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_accountant_fio'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_accountant_fio;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

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

// Адрес
$param = array();
$param['tab_id'] = $tab4_id;
$param['name'] = 'shop_company_address';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_address'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_address;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Телефон
$param = array();
$param['tab_id'] = $tab4_id;
$param['name'] = 'shop_company_phone';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_phone'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_phone;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Факс
$param = array();
$param['tab_id'] = $tab4_id;
$param['name'] = 'shop_company_fax';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_fax'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_fax;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Сайт
$param = array();
$param['tab_id'] = $tab4_id;
$param['name'] = 'shop_company_site';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_site'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_site;
//$param['format']['maxlen']['value'] = 255;
//$param['format']['lib']['value'] = 'url';
//$param['format']['lib']['message'] = 255;
$admin_forms_fields->AddField($param);

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

// E-mail
$param = array();
$param['tab_id'] = $tab4_id;
$param['name'] = 'shop_company_email';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_email'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_email;
//$param['format']['maxlen']['value'] = 255;
//$param['format']['lib']['value'] = 'email';
$admin_forms_fields->AddField($param);

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

$tab3_id = $admin_forms_fields->AddTab($GLOBALS['MSG_shops']['tab3_company']);

// ИНН 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_inn';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_inn'];
$param['type'] = 0; // Поле ввода.
$param['format']['maxlen']['value'] = 12;
$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$param['value'] = $shop_company_inn;

$admin_forms_fields->AddField($param);

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

// КПП 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_kpp';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_kpp'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_kpp;
$param['format']['maxlen']['value'] = 9;
$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$admin_forms_fields->AddField($param);

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

// ОГРН 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_ogrn';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_ogrn'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_ogrn;
$param['format']['maxlen']['value'] = 20;
$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$admin_forms_fields->AddField($param);

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


// ОКПО 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_okpo';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_okpo'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_okpo;
$param['format']['maxlen']['value'] = 10;
$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$admin_forms_fields->AddField($param);

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


// ОКВЭД 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_okved';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_okved'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_okved;
$param['format']['maxlen']['value'] = 50;
$admin_forms_fields->AddField($param);

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

// БИК 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_bik';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_bik'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_bik;
$param['format']['maxlen']['value'] = 10;
//$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$admin_forms_fields->AddField($param);

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

// Номер счета 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_account';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_account'];
$param['type'] = 0; // Поле ввода.
$param['format']['maxlen']['value'] = 20;
$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$param['value'] = $shop_company_account;

$admin_forms_fields->AddField($param);

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

// Номер корр. счета 
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_corr_account';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_corr_account'];
$param['type'] = 0; // Поле ввода.
$param['format']['maxlen']['value'] = 20;
$param['format']['lib']['value'] = 'integer';
$param['format']['lib']['message'] = $GLOBALS['MSG_shops']['show_invalid_characters_integer'];
$param['value'] = $shop_company_corr_account;

$admin_forms_fields->AddField($param);

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

// Название банка
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_bank_name';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_bank_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_bank_name;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

// Адрес банка
$param = array();
$param['tab_id'] = $tab3_id;
$param['name'] = 'shop_company_bank_address';
$param['caption'] = $GLOBALS['MSG_shops']['company_form_bank_address'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_company_bank_address;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

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

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

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

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

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