<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();

if(!CModule::IncludeModule("webservice") || !CModule::IncludeModule("iblock"))
	return;

// наш новый класс наследуется от базового IWebService
class CAddNewsWS extends IWebService
{
	function AddNews($NAME, $DATE, $PREVIEW_TEXT, $DETAIL_TEXT, $KEYWORDS, $SOURCE)
	{
		$iblock_permission = CIBlock::GetPermission(33);
		if ($iblock_permission < "W")
		{
			$GLOBALS["USER"]->RequiredHTTPAuthBasic();
			return new CSOAPFault('Server Error', 'Unable to authorize user.');
		}

		$arFields = Array(
				"IBLOCK_ID"=>33, // инфоблок "Новости магазина"
				"NAME"=>$NAME,
				"DATE_ACTIVE_FROM"=>$DATE,
				"PREVIEW_TEXT"=>$PREVIEW_TEXT,
				"DETAIL_TEXT"=>$DETAIL_TEXT,
				"PROPERTY_VALUES" => Array(
					"KEYWORDS"=>$KEYWORDS,
					"SOURCE"=>$SOURCE,
					)
			);
		$ib_element = new CIBlockElement();
		$result = $ib_element->Add($arFields);
		if($result>0)
			return Array("id"=>$result);

		return new CSOAPFault( 'Server Error', 'Error: '.$ib_element->LAST_ERROR );

	}

	// метод GetWebServiceDesc возвращает описание сервиса и его методов
	function GetWebServiceDesc()
	{
		$wsdesc = new CWebServiceDesc();
		$wsdesc->wsname = "bitrix.webservice.addnews";
		$wsdesc->wsclassname = "CAddNewsWS";
		$wsdesc->wsdlauto = true;
		$wsdesc->wsendpoint = CWebService::GetDefaultEndpoint();
		$wsdesc->wstargetns = CWebService::GetDefaultTargetNS();

		$wsdesc->classTypes = array();
		$wsdesc->structTypes = Array();

		$wsdesc->classes = array(
			"CAddNewsWS"=> array(
				"AddNews" => array(
					"type"		=> "public",
					"input"		=> array(
						"NAME" => array("varType" => "string"),
						"DATE" => array("varType" => "string"),
						"PREVIEW_TEXT" => array("varType" => "string"),
						"DETAIL_TEXT" => array("varType" => "string"),
						"KEYWORDS" => array("varType" => "string"),
						"SOURCE" => array("varType" => "string"),
						),
					"output"	=> array(
						"id" => array("varType" => "integer")
					),
					"httpauth" => "Y"
				),
			)
		);

		return $wsdesc;
	}
}

$arParams["WEBSERVICE_NAME"] = "bitrix.webservice.addnews";
$arParams["WEBSERVICE_CLASS"] = "CAddNewsWS";
$arParams["WEBSERVICE_MODULE"] = "";

// передаем в компонент описание веб-сервиса
$APPLICATION->IncludeComponent(
	"bitrix:webservice.server",
	"",
	$arParams
	);

die();
?>
