Your IP : 3.149.228.10


Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/local/tools/
Upload File :
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/local/tools/ajax.php

<?php
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");

if (!check_bitrix_sessid())
	die();

error_reporting(E_ERROR && ~E_WARNING);
ini_set('display_errors', '1');


class AjaxHandler
{
	public function processRequest($request)
	{
		try{
			$action = $request["action"];
			
			if (empty($action))
				throw new \Exception("Action not set");
			
			if (!method_exists($this, $action))
				throw new \Exception("Unknown action");
			
			$data = &$request["data"];
			
			$data = call_user_func(array($this, $action), $data);
			$success = true;
		}
		catch (\Exception $e)
		{
			$success = false;
			$data = array("message" => $e->getMessage(), "trace" => $e->getTrace());
		}
		
		return array("success" => $success, "data" => $data);
	}
	
	protected function getBasket()
	{
		\Bitrix\Main\Loader::includeModule("sale");
		$dbBasketItems = \CSaleBasket::GetList(
			[],
			[
				"FUSER_ID" => \CSaleBasket::GetBasketUserID(),
				"LID" => SITE_ID,
				"ORDER_ID" => "NULL"
			],
			false,
			false,
			[
				"ID",
				"NAME",
				"PRODUCT_ID"
			]
		);
		
		$arResult = [];
		while ($basket = $dbBasketItems->fetch())
			$arResult[] = $basket;
		
		return $arResult;
	}
}

$handler = new AjaxHandler();
$response = $handler->processRequest($_REQUEST);

$GLOBALS["APPLICATION"]->RestartBuffer();
echo json_encode($response);
die();