<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2008 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Ajax загрузчик формы списка содержимого определенного магазина.
 * 
 * Файл: /admin/shop/action/load_data.php
 * 
 * @author Hostmake LLC
 * @version 5.2
 */
function LoadAjaxData(&$admin_forms)
{
	$on_page = $admin_forms->GetOnPageCount();

	$page = to_int($_REQUEST['limit']);

	$begin = ($page == 0) ? 0 : ($page - 1) * $on_page;

	$param = array();

	$param['limit']['all'] = array('begin' => $begin, 'count' => $on_page);

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

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

	$DataBase = & singleton('DataBase');

	$shop = & singleton('shop');

	$row = $shop->GetShop($shop_shops_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->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data');
	$new_path_array[0]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data');

	$new_path_array[1]['name'] = $row['shop_shops_name'];
	$new_path_array[1]['link'] = $admin_forms->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->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->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
			'onclick' =>  $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
			'name' => $value);
		}
	}

	$param['path_array'] = $new_path_array;


	// Запрос для выборки каталогов магазина
	$param['data'][] = "SELECT *, shop_groups_id AS keyfield, shop_groups_name AS name,
		shop_groups_indexation AS indexing, shop_groups_order AS orderr
		FROM `shop_groups_table`
		WHERE `shop_groups_parent_id` = '$shop_groups_parent_id'
		AND `shop_shops_id` = '$shop_shops_id'
		{FILTER_STRING} {ORDER_STRING} {LIMIT}";


	// Количество групп
	$count_groups = "SELECT count(shop_groups_id) as count
	FROM `shop_groups_table`
	WHERE `shop_shops_id`= '$shop_shops_id'
	AND `shop_groups_parent_id` = '$shop_groups_parent_id'
	{FILTER_STRING}";	
	
	// Запрос для выборки элементов магазина
	$param['data'][] = "SELECT *, shop_items_catalog_item_id AS keyfield,
	shop_items_catalog_name AS name, shop_items_catalog_marking AS articul,
	shop_items_catalog_weight AS ves, shop_items_catalog_rest AS ostatok,
	shop_items_catalog_order AS orderr, shop_items_catalog_price AS price,
	shop_items_catalog_is_active AS activity,
	shop_items_catalog_indexation AS indexing,
	shop_items_catalog_item_id AS addons,
	shop_items_catalog_type
	FROM `shop_items_catalog_table`
	WHERE `shop_groups_id` = '$shop_groups_parent_id'
	AND `shop_shops_id` = '$shop_shops_id'
	AND `shop_items_catalog_modification_id`=0
	{FILTER_STRING} {ORDER_STRING} {LIMIT}";

	$count = "SELECT count(*) AS count
	FROM `shop_items_catalog_table` 
	WHERE `shop_groups_id` = '$shop_groups_parent_id' 
	AND `shop_shops_id` = '$shop_shops_id' 
	AND `shop_items_catalog_modification_id`=0
	{FILTER_STRING}";

	// Формируем верхнее меню.
	$k = 0;

	$menu[$k]['name'] = $GLOBALS['MSG_shops']['links_items'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	$p = 0;
	$sub_menu = array();
	$sub_menu[$p]['name'] = $GLOBALS['MSG_shops']['add_group_link1'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallTrigerSingleAction('edit_item', 'check_1_0', 65, 0, 0);
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallTrigerSingleAction('edit_item', 'check_1_0', 65, 0, 0);
	$sub_menu[$p]['icon'] = '/admin/images/page_add.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['items_catalog_add_form_comment_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&all_comments_this_shop=1", 66, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&all_comments_this_shop=1", 66, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/comments.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['shops_add_form_link_properties'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 67, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 67, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/page_gear.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['properties_item_for_groups_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_id=$shop_groups_parent_id&shop_groups_parent_id=$shop_groups_parent_id", 71, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_id=$shop_groups_parent_id&shop_groups_parent_id=$shop_groups_parent_id", 71, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/folder_page_gear.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['change_prices_for_shop_group'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&action=change_prices&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&action=change_prices&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/service.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['import_price_list_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&action=import_price_list&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&action=import_price_list&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/import.gif';

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['export_shop'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&action=export&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&action=export&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/export.gif';

	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	//	$menu = array();
	$menu[++$k]['name'] = $GLOBALS['MSG_shops']['links_groups'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	//	$p = 0;
	$sub_menu = array();
	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['add_group_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallTrigerSingleAction('edit_item', 'check_0_0', 65, 0, 0);
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallTrigerSingleAction('edit_item', 'check_0_0', 65, 0, 0);
	$sub_menu[$p]['icon'] = '/admin/images/folder_add.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['shops_add_form_link_properties_for_group'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&action=add_external_property_group&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 135, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&action=add_external_property_group&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 135, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/folder_gear.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;


	$menu[++$k]['name'] = $GLOBALS['MSG_shops']['shops_link_orders'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	$sub_menu = array();
	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['shops_add_form_link_orders'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id", 75, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id", 75, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/order.gif';

	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;
	$menu[++$k]['name'] = $GLOBALS['MSG_shops']['show_delivery_on'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	$sub_menu = array();
	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['show_type_of_delivery_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 77, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 77, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/type_of_delivery.gif';

	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	// Формируем заголовок меню
	$menu[++$k]['name'] = $GLOBALS['MSG_shops']['show_sds_link'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	// Формируем новый массив элементов подменю
	$sub_menu = array();
	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['show_prices_title'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 68, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 68, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/prices.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['show_producers_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 69, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 69, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/company.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['show_sellers_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 70, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 70, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/company.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;


	// Формируем заголовок меню
	$menu[++$k]['name'] = $GLOBALS['MSG_shops']['shop_menu_title'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	$sub_menu = array();

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['show_discount_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 72, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 72, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/money.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['order_discount_show_title'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 73, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 73, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/money.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['coupon_group_link'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 74, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 74, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/money.gif';
	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	if (class_exists('SiteUsers'))
	{
		// Формируем заголовок меню
		$menu[++$k]['name'] = $GLOBALS['MSG_shops']['affiliate_menu_title'];
		$menu[$k]['link'] = '';
		$menu[$k]['icon'] = '';

		$sub_menu = array();
		$sub_menu[++$p]['name'] = $GLOBALS['MSG_shops']['affiliate_menu_title'];
		$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "", 166, 'load_data');
		$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "", 166, 'load_data');
		$sub_menu[$p]['icon'] = '/admin/images/money.gif';
		// Добавляем подэлементы.
		$menu[$k]['sub_items'] = $sub_menu;
	}
	// Формируем массив меню.
	$menu_array = array();
	$menu_array[] = $menu;

	// Для первого набора данных общее количство не указываем, т.к. передаем все элементы,
	// для второго набора данных указываем в виде запроса.
	$param['total_count'][] = $count_groups;
	$param['total_count'][] = $count;

	// Перекрываем настойки для поля из первого набора данных.
	// Поле с названием делаем ссылкой.
	$param['field_params'][0]['name']['admin_forms_field_type'] = 4; // Ссылка.
	$param['field_params'][0]['name']['admin_forms_field_link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id={keyfield}", 65, 'load_data');
	$param['field_params'][0]['name']['admin_forms_field_onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id={keyfield}", 65, 'load_data');

	// В поле с картинкой отображаем значек папки.
	$param['field_params'][0]['type']['admin_forms_field_image'] = "=/admin/images/folder.gif";
	$param['field_params'][1]['type']['admin_forms_field_image'] = "=/admin/images/page.gif";

	// Активность
	///
	$param['field_params'][0]['activity']['admin_forms_field_type'] = 0;

	///
	$param['field_params'][1]['activity']['admin_forms_field_type'] = 7;// картинка-ссылка
	$param['field_params'][1]['activity']['admin_forms_field_link'] = $admin_forms->GetHtmlCallTrigerSingleAction('active', 'check_1_{keyfield}', 65, 0, 0);
	$param['field_params'][1]['activity']['admin_forms_field_onclick'] = $admin_forms->GetOnClickCallTrigerSingleAction('active', 'check_1_{keyfield}', 65, 0, 0);
	$param['field_params'][1]['activity']['admin_forms_field_alt'] = "0=".$GLOBALS['MSG_shops']['catalog_is_active']
	. "\n1=".$GLOBALS['MSG_shops']['catalog_is_active'];
	$param['field_params'][1]['activity']['admin_forms_field_title'] = "0=".$GLOBALS['MSG_shops']['catalog_is_active']
	. "\n1=".$GLOBALS['MSG_shops']['catalog_is_active'];


	// Сопутствующие товары
	$param['field_params'][1]['addonses']['admin_forms_field_type'] = 7;// картинка-ссылка
	$param['field_params'][1]['addonses']['admin_forms_field_link'] =  $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_item_id={keyfield}", 79, 'load_data');
	$param['field_params'][1]['addonses']['admin_forms_field_onclick'] =  $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_item_id={keyfield}", 79, 'load_data');
	$param['field_params'][1]['addonses']['admin_forms_field_image']="=/admin/images/tying_products.gif";
	$param['field_params'][1]['addonses']['admin_forms_field_alt'] = "=".$GLOBALS['MSG_shops']['show_tying_products_menu'];
	$param['field_params'][1]['addonses']['admin_forms_field_title'] = "=".$GLOBALS['MSG_shops']['show_tying_products_menu'];

	// Скидки
	$param['field_params'][1]['easy']['admin_forms_field_type'] = 7;// картинка-ссылка
	$param['field_params'][1]['easy']['admin_forms_field_link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_item_id={keyfield}", 72, 'load_data');
	$param['field_params'][1]['easy']['admin_forms_field_onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_item_id={keyfield}", 72, 'load_data');
	$param['field_params'][1]['easy']['admin_forms_field_image'] = "=/admin/images/money.gif";
	$param['field_params'][1]['easy']['admin_forms_field_alt'] = "=".$GLOBALS['MSG_shops']['show_groups_discount'];
	$param['field_params'][1]['easy']['admin_forms_field_title'] = "=".$GLOBALS['MSG_shops']['show_groups_discount'];

	// Отзывы
	$param['field_params'][1]['voices']['admin_forms_field_type'] = 7;// картинка-ссылка
	$param['field_params'][1]['voices']['admin_forms_field_link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&sort_catalog_item_id={keyfield}", 66, 'load_data');
	$param['field_params'][1]['voices']['admin_forms_field_onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&sort_catalog_item_id={keyfield}", 66, 'load_data');
	$param['field_params'][1]['voices']['admin_forms_field_image']="=/admin/images/comments.gif";
	$param['field_params'][1]['voices']['admin_forms_field_alt'] = "=".$GLOBALS['MSG_shops']['show_groups_comment'];
	$param['field_params'][1]['voices']['admin_forms_field_title'] = "=".$GLOBALS['MSG_shops']['show_groups_comment'];

	// Модификации
	$param['field_params'][1]['mods']['admin_forms_field_type'] = 7;// картинка-ссылка
	$param['field_params'][1]['mods']['admin_forms_field_link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_modification_id={keyfield}", 81, 'load_data');
	$param['field_params'][1]['mods']['admin_forms_field_onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_modification_id={keyfield}", 81, 'load_data');
	$param['field_params'][1]['mods']['admin_forms_field_image']="=/admin/images/modifications.gif";
	$param['field_params'][1]['mods']['admin_forms_field_alt'] = "=".$GLOBALS['MSG_shops']['modifications'];
	$param['field_params'][1]['mods']['admin_forms_field_title'] = "=".$GLOBALS['MSG_shops']['modifications'];


	// Формируем функцию обратного вызова
	$param['field_params'][0]['shop_items_catalog_type']['admin_forms_field_type'] = 0;
	$param['field_params'][1]['shop_items_catalog_type']['callback_function'] = 'callback_function_shop_items_catalog_type';


	function callback_function_shop_items_catalog_type($field_value, $value, $row)
	{
		// Получаем данные для передачи в новую форму
		$shop_shops_id = to_int($_REQUEST['shop_shops_id']);

		// Идентификатор товара
		$item_id = to_int($row['keyfield']);

		$item_name = to_str($row['name']);

		// Текущий каталог товаров
		$shop_groups_parent_id = to_int($_REQUEST['shop_groups_parent_id']);

		$admin_forms = new admin_forms();

		if ($value == 1)
		{
		?>
		<a 
		href="<?php echo $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$shop_groups_parent_id&shop_shops_id=$shop_shops_id&item_id=$item_id", 132, 'load_data')?>"
		onclick="<?php echo $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$shop_groups_parent_id&shop_shops_id=$shop_shops_id&item_id=$item_id", 132, 'load_data')?>"
		><img alt="Электронный товар '<?php echo $item_name?>'" title="Электронный товар '<?php echo $item_name?>'" src="/admin/images/table.gif" /></a>
		<?php 
		}
		else
		{
			?>&mdash;<?php
		}
	}

	$param['current_page'] = $page;
	$param['on_page'] = $on_page;
	$param['menus'] = $menu_array;

	$param['title'] = $row['shop_shops_name'];

	return $param;
}

/**
 * Необязательная функция для определения реального имени столбца по псевдониму.
 *
 * @param string $field_name
 * @param integer $dataset_id
 * @return boolean
 */
function ResolveFieldName(&$field_name, $dataset_id)
{
	switch ($dataset_id)
	{
		case 0: // Список каталогов документов.
		{
			switch ($field_name)
			{
				case 'keyfield':
					{
						$field_name = 'shop_groups_id';
						break;
					}
				case 'name':
					{
						$field_name = 'shop_groups_name';
						break;
					}
				case 'indexing':
					{
						$field_name = 'shop_groups_indexation';
						break;
					}
				case 'orderr':
					{
						$field_name = 'shop_groups_order';
						break;
					}
				case 'articul':
					{
						$field_name = '';
						break;
					}
				case 'ves':
					{
						$field_name = '';
						break;
					}
				case 'ostatok':
					{
						$field_name = '';
						break;
					}
				case 'price':
					{
						$field_name = '';
						break;
					}
				default:
					{
						$field_name = '';
						break;
					}
			}
			break;
		}
		case 1: // Список документов.
		{
			switch ($field_name)
			{
				case 'keyfield':
					{
						$field_name = 'shop_items_catalog_item_id';
						break;
					}
				case 'name':
					{
						$field_name = 'shop_items_catalog_name';
						break;
					}
				case 'articul':
					{
						$field_name = 'shop_items_catalog_marking';
						break;
					}
				case 'ves':
					{
						$field_name = 'shop_items_catalog_weight';
						break;
					}
				case 'ostatok':
					{
						$field_name = 'shop_items_catalog_rest';
						break;
					}
				case 'orderr':
					{
						$field_name = 'shop_items_catalog_order';
						break;
					}
				case 'price':
					{
						$field_name = 'shop_items_catalog_price';
						break;
					}
				case 'activity':
					{
						$field_name = 'shop_items_catalog_is_active';
						break;
					}
				case 'indexing':
					{
						$field_name = 'shop_items_catalog_indexation';
						break;
					}
				case 'addons':
					{
						$field_name = 'shop_items_catalog_item_id';
						break;
					}
				default:
					{
						$field_name = '';
						break;
					}
			}
			break;
		}
	}
	return true;
}
/**
 * функция для удаления элемента
 *
 * @param array $param
 */
function delete_item(&$param)
{
	ob_start();

	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$DataBase = & singleton('DataBase');

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

		$shop = & singleton('shop');

		$count = 0;

		// Удаление элемента
		if (isset($param['data'][1]))
		{
			foreach ($param['data'][1] as $key => $value)
			{
				// Определяем режим доступа пользователя и принадлежит ли объект пользователю
				$user_access = new user_access();

				$shop = & singleton('shop');

				// Определяем информацию об объекте
				$object_row = $shop->GetItem($key, array('cache_off' => true));

				if ($object_row)
				{
					$object_user_id = $object_row['users_id'];
				}
				else
				{
					$object_user_id = 0;
				}

				if ($user_access->IssetUserAccessForObject($object_user_id))
				{
					if (!$shop->DeleteItem($key))
					{
						$flag_success = false;
					}
					else
					{
						$count++;

						$flag_success = true;
					}
				}
				else
				{
					$user_access->MessageOnlyOwn();

					$flag_success = false;
				}

			}

			if ($flag_success)
			{
				if ($count == 1)
				{
					show_message($GLOBALS['MSG_shops']['items_catalog_success_delete']);
				}
				else
				{
					show_message($GLOBALS['MSG_shops']['items_catalogs_success_delete']);
				}
			}
		}
		// Удаление каталога элементов
		if (isset($param['data'][0]))
		{
			foreach ($param['data'][0] as $key => $value)
			{
				// Определяем режим доступа пользователя и принадлежит ли объект пользователю
				$user_access = new user_access();

				$shop = & singleton('shop');

				// Определяем информацию об объекте
				$object_row = $shop->GetGroup($key, array('cache_off' => true));

				if ($object_row)
				{
					$object_user_id = $object_row['users_id'];
				}
				else
				{
					$object_user_id = 0;
				}

				if ($user_access->IssetUserAccessForObject($object_user_id))
				{
					if (!$shop->DeleteGroup($key))
					{
						$flag_success = false;
					}
					else
					{
						$count++;

						$flag_success = true;
					}
				}
				else
				{
					$user_access->MessageOnlyOwn();

					$flag_success = false;
				}

			}

			if ($flag_success)
			{
				if ($count == 1)
				{
					show_message($GLOBALS['MSG_shops']['groups_success_delete']);
				}
				else
				{
					show_message($GLOBALS['MSG_shops']['groups_success_deletes']);
				}
			}
		}
	}

	$error = ob_get_clean();
	$param['error'] = $error;
}

/**
 * Добавление/редактирование элементов/каталогов магазина
 *
 * @param array $param
 * @return boolean
 */
function edit_item(&$param)
{
	ob_start();

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

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

	if (isset($param['data']))
	{
		if (isset($param['data'][0]))
		{
			foreach ($param['data'][0] as $key => $value)
			{
				// Определяем режим доступа пользователя и принадлежит ли объект пользователю
				$user_access = new user_access();

				$shop = & singleton('shop');

				// Определяем информацию об объекте
				$object_row = $shop->GetGroup($key, array('cache_off' => true));

				if ($object_row)
				{
					$object_user_id = $object_row['users_id'];
				}
				else
				{
					$object_user_id = 0;
				}

				if ($user_access->IssetUserAccessForObject($object_user_id))
				{
					$id = $key;

					include(CMS_FOLDER.'admin/shop/action/form_edit_add_groups.php');
					// Устанавливаем <title> для страницы
					$param['title'] = ($id == 0)
					? $GLOBALS['MSG_shops']['groups_add_form_title']
					: $GLOBALS['MSG_shops']['groups_edit_form_title'];
				}
				else
				{
					$user_access->MessageOnlyOwn();
					$param['error'] = ob_get_clean();
					return ;
				}
			}

		}
		if (isset($param['data'][1]))
		{
			foreach ($param['data'][1] as $id => $value)
			{
				// Определяем режим доступа пользователя и принадлежит ли объект пользователю
				$user_access = new user_access();

				$shop = & singleton('shop');

				// Определяем информацию об объекте
				$object_row = $shop->GetItem($id, array('cache_off' => true));

				if ($object_row)
				{
					$object_user_id = $object_row['users_id'];
				}
				else
				{
					$object_user_id = 0;
				}

				if ($user_access->IssetUserAccessForObject($object_user_id))
				{
					include(CMS_FOLDER.'admin/shop/action/form_edit_add_items_catalog.php');

					// Устанавливаем <title> для страницы
					$param['title'] = ($id == 0)
					? $GLOBALS['MSG_shops']['items_catalog_add_form_title']
					: $GLOBALS['MSG_shops']['items_catalog_edit_form_title'];
				}
				else
				{
					$user_access->MessageOnlyOwn();
					$param['error'] = ob_get_clean();
					return ;
				}
			}
		}
	}

	$param['result'] = ob_get_clean();
	return true;
}

/**
 * Применить изменения
 *
 * @param array $param
 */
function apply_changes(&$param)
{
	ob_start();
	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$shop_groups_parent_id = to_int($_REQUEST['shop_groups_parent_id']);

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

		$params = array();

		$shop = & singleton('shop');

		$DataBase = & singleton('DataBase');

		if (isset($param['data']))
		{
			// редактирование директории
			foreach ($param['data'] AS $key => $val)
			{
				foreach ($val AS $id => $value)
				{
					$id = intval($id);

					// редактирвание порядка сортировки у товара
					if (isset($param['data'][1]))
					{
						// Определяем режим доступа пользователя и принадлежит ли объект пользователю
						$user_access = new user_access();

						$shop = & singleton('shop');

						// Определяем информацию об объекте
						$object_row = $shop->GetItem($id, array('cache_off' => true));

						if ($object_row)
						{
							$object_user_id = $object_row['users_id'];
						}
						else
						{
							$object_user_id = 0;
						}

						if ($user_access->IssetUserAccessForObject($object_user_id))
						{
							$order = to_int($value['orderr']);

							$query = "UPDATE `shop_items_catalog_table` SET `shop_items_catalog_order` = '$order'
					WHERE `shop_items_catalog_item_id` = '$id'";

							$DataBase->query($query);
						}
						else
						{
							$user_access->MessageOnlyOwn();
							$param['error'] = ob_get_clean();
							return ;
						}
					}// редактирование порядка сортировки у каталога
					if (isset($param['data'][0]))
					{
						// Определяем режим доступа пользователя и принадлежит ли объект пользователю
						$user_access = new user_access();

						$shop = & singleton('shop');

						// Определяем информацию об объекте
						$object_row = $shop->GetGroup($id);

						if ($object_row)
						{
							$object_user_id = $object_row['users_id'];
						}
						else
						{
							$object_user_id = 0;
						}

						if ($user_access->IssetUserAccessForObject($object_user_id))
						{
							$order = to_int($value['orderr']);

							$query = "UPDATE `shop_groups_table` SET `shop_groups_order` = '$order' WHERE `shop_groups_id` = '$id'";

							$DataBase->query($query);
						}
						else
						{
							$user_access->MessageOnlyOwn();
							$param['error'] = ob_get_clean();
							return ;
						}
					}
				}
			}
		}
	}
	$error = ob_get_clean();

	$param['error'] = $error;
}

// Копирование товара
function copy_item(&$param)
{
	ob_start();
	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$shop = & singleton('shop');

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

		$kernel = & singleton('kernel');

		$DataBase = & singleton('DataBase');

		if (isset($param['data']))
		{
			if (isset($param['data'][1]))
			{
				foreach ($param['data'][1] as $key => $value)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					$shop = & singleton('shop');

					// Определяем информацию об объекте
					$object_row = $shop->GetItem($key);

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						$shop->CopyItem($key);
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}
		}
	}
	$error = ob_get_clean();

	$param['error'] = $error;
}

/**
 * Изменение статуса активности
 *
 * @param array $param
 */
function active(&$param)
{
	ob_start();
	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$DataBase = & singleton('DataBase');
		if (isset($param['data']))
		{
			if (isset($param['data'][1]))
			{
				foreach ($param['data'][1] as $key => $value)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					$shop = & singleton('shop');

					// Определяем информацию об объекте
					$object_row = $shop->GetItem($key);

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						$key = to_int($key);

						$query = "UPDATE `shop_items_catalog_table`
				SET `shop_items_catalog_is_active` = 1 - `shop_items_catalog_is_active`
				WHERE `shop_items_catalog_item_id` = '$key'";

						$ret = $DataBase->query($query);
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}
		}
	}
	$error = ob_get_clean();

	$param['error'] = $error;
}

/**
 * Изменение статуса индексации
 *
 * @param array $param
 */
function index(&$param)
{
	ob_start();
	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$DataBase = & singleton('DataBase');
		if (isset($param['data']))
		{
			if (isset($param['data'][1]))
			{
				foreach ($param['data'][1] as $key => $value)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					$shop = & singleton('shop');

					// Определяем информацию об объекте
					$object_row = $shop->GetItem($key);

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						$key = to_int($key);

						$query = "UPDATE `shop_items_catalog_table` SET `shop_items_catalog_indexation` = 1 - `shop_items_catalog_indexation` WHERE `shop_items_catalog_item_id` = '$key'";

						$ret = $DataBase->query($query);
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}
			if (isset($param['data'][0]))
			{
				foreach ($param['data'][0] as $key => $value)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					$shop = & singleton('shop');

					// Определяем информацию об объекте
					$object_row = $shop->GetGroup($key);

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						$key = to_int($key);

						$query = "UPDATE `shop_groups_table` SET `shop_groups_indexation` = 1 - `shop_groups_indexation` WHERE `shop_groups_id` = '$key'";

						$ret = $DataBase->query($query);
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}
		}
	}
	$error = ob_get_clean();

	$param['error'] = $error;
}
?>