<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Ajax загрузчик формы списка лицевых счетов пользователей.
 * 
 * Файл: /admin/shop/action/load_accounts.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
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'][0] = array('begin' => $begin, 'count' => $on_page);

	$site_users_id = to_int($_REQUEST['site_users_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 = '';
	}

	// Строим хлебные крошки.
	$parray = array(
	array(
	'link' => $admin_forms->GetHtmlCallDoLoadAjax('/admin/Site_users/Site_users.php', '', 28, 'load_data'),
	'onclick' => $admin_forms->GetOnClickCallDoLoadAjax('/admin/Site_users/Site_users.php', '', 28, 'load_data'),
	'name' => $GLOBALS['MSG_site_users']['su_users_link']),

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

	array(
	'link' => $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '&site_users_id='.$site_users_id, 133, 'load_data'),
	'onclick' => $admin_forms->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)
	));

	$param['path_array'] = $parray;

	$site_id = CURRENT_SITE;

	// Выборка нужных записей.
	$param['data'][] = "SELECT *
	FROM shop_shops_table 
	LEFT JOIN shop_currency_table 
	USING(shop_currency_id) 
	WHERE site_id='$site_id'
	{FILTER_STRING} {ORDER_STRING} {LIMIT}";

	// Число нужных записей.
	$count = "SELECT count(*) AS count
	FROM shop_shops_table 
	LEFT JOIN shop_currency_table 
	USING(shop_currency_id) 
	WHERE site_id='$site_id'
	{FILTER_STRING}";

	$param['field_params'][0]['summ']['callback_function'] = 'callback_function_summ';

	// Функция обратного вызова
	function callback_function_summ($field_value, $value, $row)
	{
		$shop = & singleton('shop');

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

		echo $shop->GetSiteUserAccountSum($site_users_id, to_int($row['shop_shops_id']));
	}

	// Переопределяем некоторые выводимые параметры
	$param['field_params'][0]['transactions']['admin_forms_field_link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '&site_users_id='.$site_users_id.'&shop_shops_id={shop_shops_id}', 134, 'load_data');
	$param['field_params'][0]['transactions']['admin_forms_field_onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '&site_users_id='.$site_users_id.'&shop_shops_id={shop_shops_id}', 134, 'load_data');


	$param['total_count'][] = $count;
	$param['current_page'] = $page;
	$param['on_page'] = $on_page;

	$param['title'] = sprintf($GLOBALS['MSG_shops']['users_account_table'], $site_users_login);

	return $param;
}
?>