<?
define("PUBLIC_AJAX_MODE", true);
define("NO_KEEP_STATISTIC", "Y");
define("NO_AGENT_STATISTIC","Y");
define("NO_AGENT_CHECK", true);
define("DisableEventsCheck", true);
/************** CACHE **********************************************/

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
$arVoteList = array(
	"ID" => $_REQUEST["ID"],
	"request_id" => $_REQUEST["request_id"],
	"items" => array()
);

$_REQUEST["ID"] = is_array($_REQUEST["ID"]) ? $_REQUEST["ID"] : !empty($_REQUEST["ID"]) ? explode(",", $_REQUEST["ID"]) : array();
$_REQUEST["URL_TEMPLATE"] = (!empty($_REQUEST["URL_TEMPLATE"]) ? $_REQUEST["URL_TEMPLATE"] : '/company/personal/user/#USER_ID#/');
$_REQUEST["NAME_TEMPLATE"] = (!empty($_REQUEST["NAME_TEMPLATE"]) ? $_REQUEST["NAME_TEMPLATE"] : CSite::GetNameFormat(false));

if (!empty($_REQUEST["ID"]) && check_bitrix_sessid())
{
	$arParams["CACHE_TIME"] = 600;
	global $CACHE_MANAGER;
	$cache = new CPHPCache();

	$cache_id = "vote_users_".serialize(array($_REQUEST["ID"], $_REQUEST["NAME_TEMPLATE"], $_REQUEST["URL_TEMPLATE"]));
	$cache_path = $CACHE_MANAGER->GetCompCachePath(CComponentEngine::MakeComponentPath("voting.current"));
	$arUsers = (($arParams["CACHE_TIME"] > 0 && $cache->InitCache($arParams["CACHE_TIME"], $cache_id, $cache_path)) ?
		$cache->GetVars() : array());

	if (!is_array($arUsers) || empty($arUsers))
	{
		$db_res = CUser::GetList(
			($by = "ID"),
			($order = "ASC"),
			array("ID" => implode("|", $_REQUEST["ID"])),
			array("FIELDS" => array("ID", "NAME", "LAST_NAME", "SECOND_NAME", "LOGIN", "PERSONAL_PHOTO"))
		);

		while ($res = $db_res->Fetch())
		{
			if (array_key_exists("PERSONAL_PHOTO", $res))
			{
				$arFileTmp = CFile::ResizeImageGet(
					$res["PERSONAL_PHOTO"],
					array("width" => 21, "height" => 21),
					BX_RESIZE_IMAGE_EXACT,
					false
				);
				$res["PHOTO"] = CFile::ShowImage($arFileTmp["src"], 21, 21, "border=0");
			}
			$res["FULL_NAME"] = CUser::FormatName($_REQUEST["NAME_TEMPLATE"], $res);
			$res["URL"] = CUtil::JSEscape(CComponentEngine::MakePathFromTemplate($_REQUEST["URL_TEMPLATE"], array("UID" => $res["ID"], "user_id" => $res["ID"], "USER_ID" => $res["ID"])));
			$arUsers[$res["ID"]] = $res;
		}

		if ($arParams["CACHE_TIME"] > 0):
			$cache->StartDataCache($arParams["CACHE_TIME"], $cache_id, $cache_path);
			$cache->EndDataCache($arUsers);
		endif;
	}

$arVoteList["items"] = $arUsers;
}

$APPLICATION->RestartBuffer();
Header('Content-Type: application/x-javascript; charset='.LANG_CHARSET);
echo CUtil::PhpToJsObject($arVoteList);
die();
?>