Example #1
0
    /**
     * soapRequest
     *
     * make a SOAP request to Zimbra server, returns the XML
     *
     * @since		version 1.0
     * @param	string $body body of page
     * @param	boolean $header
     * @param	boolean $footer
     * @return	string $response
     */
    protected function soapRequest($body, $header = false, $connecting = false)
    {
        $this->error = $this->error_code = null;
        if (!$connecting && !$this->_connected) {
            throw new Exception('zimbra.class: soapRequest called without a connection to Zimbra server');
        }
        if ($header == false) {
            $header = '<context xmlns="urn:zimbra">
	<authToken>' . $this->auth_token . '</authToken>
	<sessionId id="' . $this->session_id . '">' . $this->session_id . '</sessionId>
</context>';
        }
        $soap_message = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
	<soap:Header>' . $header . '</soap:Header>
	<soap:Body>' . $body . '</soap:Body>
</soap:Envelope>';
        $this->message(sprintf('%s SOAP message: %s', get_class($this), PSU::xmlpp($soap_message, true)));
        curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $soap_message);
        if (!($response = curl_exec($this->_curl))) {
            $this->error = sprintf('%s ERROR: curl_exec - (%s) %s', get_class($this), curl_errno($this->_curl), curl_error($this->_curl));
            if ($this->debug) {
                echo '<hr>';
            }
            return false;
        } elseif (strpos($response, '<soap:Body><soap:Fault>') !== false) {
            $this->error_code = $this->extractErrorCode($response);
            $this->error = sprintf('%s ERROR: %s: %s', get_class($this), $this->error_code, PSU::xmlpp($response, true));
            $this->message($this->error);
            if ($this->debug) {
                echo '<hr>';
            }
            return false;
        }
        $this->message(sprintf('%s SOAP response: %s', get_class($this), PSU::xmlpp($response, true)));
        if ($this->debug) {
            echo '<hr>';
        }
        $this->_num_soap_calls++;
        return $response;
    }