<?php

Class Curl
{
  function xmlToArray($xmlInput, $bodyXpath=null) {
      $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $xmlInput);
      try{
        $xmlTest = new SimpleXMLElement($response);
        $body = $xmlTest -> xpath('soapBody');
        return $simpleXml = json_decode(json_encode((array) $body), true)[0];
      }
      //catch exception
        catch(Exception $e) {
          return false;
        }
      

  }

  function xmlParse($curl_send_alarm){
    return json_decode(json_encode(simplexml_load_string(strtr($curl_send_alarm, array(' xmlns:'=>' ')))), true);
  }

  function curl_send($xml, $action)
  {
          //$soapUrl = "https://webdemo.monitorsoft.com/SentinelXS/SentinelXS.asmx";
          $soapUrl = "https://sentinel.orbisprotect.com/SentinelXS/SentinelXS.asmx";
       $headers = array(
                   "POST  HTTP/1.1",
                   "Content-type: text/xml;charset=\"utf-8\"",
                   "SOAPAction: ".$action,
                   "Content-length: ".strlen($xml),
                   "Accept: text/xml"
               ); //SOAPAction: your op URL
       $ch = curl_init();

   					curl_setopt($ch, CURLOPT_URL, $soapUrl);
   					curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   					curl_setopt($ch, CURLOPT_TIMEOUT, 10);
   					curl_setopt($ch, CURLOPT_POST, true);
   					curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); // the SOAP request
   					curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

   			return $response123 = curl_exec($ch);

  }
}

 ?>
