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

$form_params = array();
$form_params['title'] = $seller_id==0?$GLOBALS['MSG_shops']['form_sellers_add_title']:$GLOBALS['MSG_shops']['form_sellers_edit_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddSeller';

$shop_shops_id = to_int($_REQUEST['shop_shops_id']);
$shop = & singleton('shop');
$shop_groups_parent_id = to_int($_REQUEST['shop_groups_parent_id']);

$DataBase = & singleton('DataBase');
$structure = & singleton('Structure');

$admin_forms_fields = new admin_forms_fields();

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

$shop_structure_id = $row['structure_id'];

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

// Преобразуем идентификаторы групп в ссылки на группы.
$new_path_array = array();
$new_path_array[0]['name'] = $GLOBALS['MSG_shops']['header_admin__list_forms'];
$new_path_array[0]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data');
$new_path_array[0]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data');

$new_path_array[1]['name'] = $row['shop_shops_name'];
$new_path_array[1]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=0&shop_shops_id=$shop_shops_id", 65, 'load_data');
$new_path_array[1]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=0&shop_shops_id=$shop_shops_id", 65, 'load_data');

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']['show_sellers_link'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id", 70, 'load_data'),
"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id", 70, 'load_data')
);

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

// Редактировние производителя
if ($seller_id)
{
	$type = 1;

	$result = $shop->GetSeller($seller_id);

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

	$shop_sallers_name = $result['shop_sallers_name'];

	$shop_sallers_comment = $result['shop_sallers_comment'];
	
	$shop_sallers_image = $result['shop_sallers_image'];
	$shop_sallers_small_image = $result['shop_sallers_small_image'];
	
	$shop_watermark_default_position_x = $row['shop_watermark_default_position_x'];
	$shop_watermark_default_position_y = $row['shop_watermark_default_position_y'];
	
	$shop_sallers_image_big_max_width = $row['shop_image_big_max_width'];
	$shop_sallers_image_big_max_height = $row['shop_image_big_max_height'];
	$shop_sallers_image_small_max_width = $row['shop_image_small_max_width'];
	$shop_sallers_image_small_max_height = $row['shop_image_small_max_height'];
	

	$shop_sallers_contact_person = htmlspecialchars($result['shop_sallers_contact_person']);

	$shop_sallers_address = htmlspecialchars($result['shop_sallers_address']);

	$shop_sallers_phone = htmlspecialchars($result['shop_sallers_phone']);

	$shop_sallers_fax = htmlspecialchars($result['shop_sallers_fax']);

	$shop_sallers_http = htmlspecialchars($result['shop_sallers_http']);

	$shop_sallers_email = htmlspecialchars($result['shop_sallers_email']);

	$shop_sallers_inn = htmlspecialchars($result['shop_sallers_inn']);

	$users_id = to_int($result['users_id']);

	$shop_shops_id2 = to_int($result['shop_shops_id']);
	
	$site_users_id = to_int($result['site_users_id']);
}
// Добавление производителя
else
{
	$shop_shops_id = to_int($_REQUEST['shop_shops_id']);

	$shop_sallers_name = '';

	$shop_sallers_comment = '';
	
	$shop_sallers_image = '';
	$shop_sallers_small_image = '';
	
	$shop_watermark_default_position_x = $row['shop_watermark_default_position_x'];
	$shop_watermark_default_position_y = $row['shop_watermark_default_position_y'];
	
	$shop_sallers_image_big_max_width = $row['shop_image_big_max_width'];
	$shop_sallers_image_big_max_height = $row['shop_image_big_max_height'];
	$shop_sallers_image_small_max_width = $row['shop_image_small_max_width'];
	$shop_sallers_image_small_max_height = $row['shop_image_small_max_height'];
	

	$shop_sallers_contact_person = '';

	$shop_sallers_address = '';

	$shop_sallers_phone = '';

	$shop_sallers_fax = '';

	$shop_sallers_http = '';

	$shop_sallers_email = '';

	$shop_sallers_inn = '';

	$users_id = false;
	
	$site_users_id = 0;

	$shop_shops_id2 = $shop_shops_id;
}

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

// Название или имя продавца
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_sallers_name';
$params['caption'] = $GLOBALS['MSG_shops']['form_sellers_name'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_sallers_name;
$params['attributes']['class'] = 'large';
$params['format']['minlen']['value'] = 1;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

$sites_array = array();

$site = & singleton ('site');

// Получаем данные о пользователе
$UserAccess = new user_access();
$user_row = $UserAccess->GetUserByName($_SESSION['valid_user']);

// Выбираем доступные сайты
$res = $site->SelectSites(array('users_type_id' => to_int($user_row['users_type_id'])));

while ($rows = mysql_fetch_assoc($res))
{
	$data = $shop->GetAllShops($rows['site_id']);

	while ($row = mysql_fetch_assoc($data))
	{
		$sites_array[$row['shop_shops_id']] = $rows['site_name'].' - '.$row['shop_shops_name'];
	}
}

// Список сайтов.
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_shops_id2';
$param['caption'] = $GLOBALS['MSG_shops']['parent_site_info'];
$param['type'] = 2; // Выпадающий список.
$param['items'] = $sites_array;
$param['value'] = $shop_shops_id2;
$admin_forms_fields->AddField($param);

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

// Пользователь сайта
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'site_users_id';
$params['caption'] = $GLOBALS['MSG_shops']['seller_site_user'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $site_users_id;
$params['format']['maxlen']['value'] = 11;
$params['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 250px;';
$admin_forms_fields->AddField($params);

// Если указан ID пользователя и есть модуль "Пользователи сайта"
if (!empty($site_users_id) && class_exists('SiteUsers'))
{
	$SiteUsers = & singleton('SiteUsers');
	$site_user_row = $SiteUsers->GetSiteUser($site_users_id);

	if ($site_user_row)
	{
		ob_start();
		?><div class="large item_div item_div_as_is" style="width: 150px"><img src="/admin/images/new_window.gif" /> <a href="<?php echo "/admin/Site_users/Site_users.php?admin_forms_id=30&operation=edit_user&check_0_{$site_user_row['site_users_id']}=1"?>" target="_blank"><?php echo $site_user_row['site_users_login']?></a></div><?php

		$site_users_link = ob_get_clean();

		// Ссылка на пользователя
		$param = array();
		$param['tab_id'] = $tab_id;
		$param['name'] = 'site_users_id_link';
		$param['caption'] = '&nbsp;';
		$param['type'] = 15; // Как есть
		$param['value'] = $site_users_link;
		$admin_forms_fields->AddField($param);
	}
}

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


// Определим ID макета по структуре
$structure_row = $structure->GetStructureItem($shop_structure_id);
$template_id = to_int($structure_row['templates_id']);

// Комментарий
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_sallers_comment';
$params['caption'] = $GLOBALS['MSG_shops']['form_sellers_description'];
$param['template'] = $template_id; // ID шаблона
$params['type'] = 7; // Поле ввода.
$params['value'] = $shop_sallers_comment;
$admin_forms_fields->AddField($params);

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


$param['options'] = array();

// Изображение группы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_sallers_image';
$param['caption'] = $GLOBALS['MSG_shops']['seller_image'];
$param['type'] = 9; // file

// Параметры
$param['options']['make_small_image_from_big_show'] = 1; // отображать ли checkbox с подписью "Создать малое изображение из большого" (1 -  отображать (по умолчанию), 0 - не отображать);
$param['options']['make_small_image_from_big_checked'] = 1; // вид отображения checkbox'а с подписью "Создать малое изображение из большого" выбранным (1 -  отображать выбранным (по умолчанию), 0 - невыбранным);

$param['options']['load_small_image_caption'] = $GLOBALS['MSG_shops']['seller_small_image'];

$param['options']['load_small_image_show'] = 1; //- отображать ли поле загрузки малого изображения (1 -  отображать (по умолчанию), 0 - не отображать);

$param['options']['image_big_max_width'] = $shop_sallers_image_big_max_width; // значение максимальной ширины большого изображения;
$param['options']['image_big_max_height'] = $shop_sallers_image_big_max_height; // значение максимальной высоты большого изображения;

$param['options']['image_small_max_width'] = $shop_sallers_image_small_max_width; // значение максимальной ширины малого изображения;
$param['options']['image_small_max_height'] = $shop_sallers_image_small_max_height; // значение максимальной высоты малого изображения;

$param['options']['used_watermark_big_image_show'] = 1; // отображать ли checkbox с подписью "Наложить водяной знак на большое изображение" (1 -  отображать (по умолчанию), 0 - не отображать);
$param['options']['used_watermark_big_image_checked'] = to_int($res_s['shop_watermark_default_use_big']); // вид ображения checkbox'а с подписью "Наложить водяной знак на большое изображение" (1 -  отображать выбранным (по умолчанию), 0 - невыбранным);

$param['options']['watermark_position_x'] = $shop_watermark_default_position_x; //значение поля ввода с подписью "По оси X"
$param['options']['watermark_position_y'] = $shop_watermark_default_position_y; // значение поля ввода с подписью "По оси Y"

$param['options']['used_watermark_small_image_show'] = 1; //  отображать ли checkbox с подписью "Наложить водяной знак на малое изображение" (1 -  отображать (по умолчанию), 0 - не отображать);
$param['options']['used_watermark_small_image_checked'] = to_int($res_s['shop_watermark_default_use_small']); // вид ображения checkbox'а с подписью "Наложить водяной знак на малое изображение" (1 -  отображать выбранным (по умолчанию), 0 - невыбранным);

if (isset($shop_sallers_image) && $shop_sallers_image != '')
{
	$param['options']['big_image_path'] = '/' . UPLOADDIR . 'shop_' . $shop_shops_id . '/sellers/' . rawurlencode($shop_sallers_image); // адрес большого загруженного изображения
	$param['options']['href_delete_big_image'] = "javascript:void(0)";
	// Значение для onclick
	$param['options']['onclick_delete_big_image'] = "sendRequest('/admin/shop/shop.php?action=delete_shop_seller_big_image&seller_id=$seller_id&shop_shops_id=$shop_shops_id', 'get', callback_function_exec_from_return); return false;";
}
else
{
	$param['options']['big_image_path'] = '';
}

if (isset($shop_sallers_small_image) && $shop_sallers_small_image != '')
{	
	$param['options']['small_image_path'] = '/' . UPLOADDIR . 'shop_' . $shop_shops_id . '/sellers/' . rawurlencode($shop_sallers_small_image); // адрес малого загруженного изображения
	$param['options']['href_delete_small_image'] = "javascript:void(0)";
	// Значение для onclick
	$param['options']['onclick_delete_small_image'] = "sendRequest('/admin/shop/shop.php?action=delete_shop_seller_small_image&seller_id=$seller_id&shop_shops_id=$shop_shops_id', 'get', callback_function_exec_from_return); return false;";
}
else
{
	$param['options']['small_image_path'] = '';
}

$admin_forms_fields->AddField($param);

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


// Контактное лицо
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_sallers_contact_person';
$params['caption'] = $GLOBALS['MSG_shops']['form_sellers_contact_person'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_sallers_contact_person;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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


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

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


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

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


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

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

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

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

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

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

// ИНН
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_sallers_inn';
$params['caption'] = $GLOBALS['MSG_shops']['form_sellers_inn'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_sallers_inn;
//$params['format']['lib']['value'] = 'integer';
//$params['format']['lib']['message'] = 'Указаны недопустимые символы (разрешенный диапазон символов 0-9)';
$params['format']['maxlen']['value'] = 32;
$admin_forms_fields->AddField($params);

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

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

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

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

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

// Кнопка "Применить".
$params = array();
$params['name'] = 'add_sellers';
$params['caption'] = $GLOBALS['MSG_shops']['apply'];
$params['image'] = '/admin/images/add.gif';
$params['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '{$admin_forms_fields->AAction}', '{$admin_forms_fields->AAdditionalParams}', this, ".to_int($_REQUEST['admin_forms_id']).")";
$params['attributes']['type'] = 'submit';
$admin_forms_fields->AddButton($params);

// Отображение формы.
$admin_forms_fields->ShowForm();
?>