Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- header("Content-Type: application/json;charset=utf-8");
- $result = array();
- $contentType = isset($_SERVER["CONTENT_TYPE"])?trim($_SERVER["CONTENT_TYPE"]):'';
- if(strcasecmp($contentType, 'application/json') == 0){
- $content = trim(file_get_contents("php://input"));
- $data = json_decode($content, true);
- if(is_array($data)){
- if(isset($_SERVER['PHP_AUTH_USER'])){
- $login = $_SERVER['PHP_AUTH_USER'];
- $pass = $_SERVER['PHP_AUTH_PW'];
- }elseif(isset($_SERVER['HTTP_AUTHORIZATION'])){
- if(strpos(strtolower($_SERVER['HTTP_AUTHORIZATION']), 'basic') === 0){
- list($login, $pass) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
- }
- }elseif(isset($_SERVER['REMOTE_USER'])){
- if(strpos(strtolower($_SERVER['REMOTE_USER']), 'basic') === 0){
- list($login, $pass) = explode(':', base64_decode(substr($_SERVER['REMOTE_USER'], 6)));
- }
- }
- require_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/prolog_before.php");
- $rsUser = new CUser;
- $authResult = $rsUser->Login($login, $pass);
- if($authResult === true){
- \Bitrix\Main\Loader::includeModule("iblock");
- $result = array();
- $arrLabs = array();
- foreach($data["services"] as $findLabs){
- $arrLabs[] = $findLabs["serv_id"];
- }
- if($arrLabs){
- $result["services"] = array();
- $rsElements = CIBlockElement::GetList(
- array(),
- array(
- "IBLOCK_ID" => GEMOTEST_IBLOCK_ID_CATALOG,
- "=PROPERTY_CODE_LAB" => $arrLabs,
- "ACTIVE" => "Y",
- ),
- false,
- false,
- array("PROPERTY_CODE_LAB", "DETAIL_PAGE_URL")
- );
- while($element = $rsElements->GetNext()){
- $result["services"][] = array(
- "serv_id" => $element["PROPERTY_CODE_LAB_VALUE"],
- "serv_url" => "https://".$_SERVER["HTTP_HOST"].$element["DETAIL_PAGE_URL"],
- );
- }
- }
- }else{
- $result = array("error" => "Error auth");
- }
- }else{
- $result = array("error" => "Empty request");
- }
- }else{
- $result = array("error" => "Error content type");
- }
- echo json_encode($result);
Add Comment
Please, Sign In to add comment