Exemple #1
0
 public function GetCredit()
 {
     $client = new nusoap_client($this->wsdl_link, 'wsdl');
     $client->decodeUTF8(false);
     $result = $client->call('accountInfo', array('username' => $this->username, 'password' => $this->password));
     return (int) $result['balance'];
 }
 /**
  * testWSOtherGetVersions
  *
  * @return int
  */
 public function testWSOtherGetVersions()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $WS_DOL_URL = DOL_MAIN_URL_ROOT . '/webservices/server_other.php';
     $WS_METHOD = 'getVersions';
     $ns = 'http://www.dolibarr.org/ns/';
     // Set the WebService URL
     print __METHOD__ . " create nusoap_client for URL=" . $WS_DOL_URL . "\n";
     $soapclient = new nusoap_client($WS_DOL_URL);
     if ($soapclient) {
         $soapclient->soap_defencoding = 'UTF-8';
         $soapclient->decodeUTF8(false);
     }
     // Call the WebService method and store its result in $result.
     $authentication = array('dolibarrkey' => $conf->global->WEBSERVICES_KEY, 'sourceapplication' => 'DEMO', 'login' => 'admin', 'password' => 'admin', 'entity' => '');
     // Test URL
     $result = '';
     $parameters = array('authentication' => $authentication);
     print __METHOD__ . " call method " . $WS_METHOD . "\n";
     try {
         $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
     } catch (SoapFault $exception) {
         echo $exception;
         $result = 0;
     }
     if (!empty($result['faultstring'])) {
         print $result['faultstring'] . "\n";
         $result = 0;
     }
     if (!$result) {
         //var_dump($soapclient);
         print $soapclient->error_str;
         print "\n<br>\n";
         print $soapclient->request;
         print "\n<br>\n";
         print $soapclient->response;
         print "\n";
     }
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('OK', $result['result']['result_code']);
     // Test method that does not exists
     $WS_METHOD = 'methodthatdoesnotexists';
     $result = '';
     $parameters = array('authentication' => $authentication);
     print __METHOD__ . " call method " . $WS_METHOD . "\n";
     try {
         $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
     } catch (SoapFault $exception) {
         echo $exception;
         $result = 0;
     }
     if (!$result || !empty($result['faultstring'])) {
         //var_dump($soapclient);
         print $soapclient->error_str;
         print "\n<br>\n";
         print $soapclient->request;
         print "\n<br>\n";
         print $soapclient->response;
         print "\n";
     }
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals("SOAP-ENV:Client: Operation 'methodthatdoesnotexists' is not defined in the WSDL for this service", $soapclient->error_str);
     return $result;
 }
 /**
  *	Handles the processing of this updater
  *
  *  @return	int					 <0 if KO, 0 if OK but no global variable found, >0 if OK
  */
 function process()
 {
     global $langs, $user;
     $langs->load("errors");
     $this->error = null;
     $this->checkParameters();
     //Try to load the target global variable and abort if fails
     if ($this->fk_variable < 1) {
         $this->error = $langs->trans("ErrorGlobalVariableUpdater5");
         return 0;
     }
     $price_globals = new PriceGlobalVariable($this->db);
     $res = $price_globals->fetch($this->fk_variable);
     if ($res < 1) {
         $this->error = $langs->trans("ErrorGlobalVariableUpdater5");
         return 0;
     }
     //Process depending of type
     if ($this->type == 0 || $this->type == 1) {
         //Get and check if required parameters are present
         $parameters = json_decode($this->parameters, true);
         if (!isset($parameters)) {
             $this->error = $langs->trans("ErrorGlobalVariableUpdater1", $this->parameters);
             return -1;
         }
         $url = $parameters['URL'];
         if (!isset($url)) {
             $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'URL');
             return -1;
         }
         $value = $parameters['VALUE'];
         if (!isset($value)) {
             $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'VALUE');
             return -1;
         }
         $result = "";
         if ($this->type == 0) {
             //CURL client
             $handle = curl_init();
             curl_setopt_array($handle, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5, CURLOPT_POST => false, CURLOPT_HEADER => false));
             $result = curl_exec($handle);
             $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
             if (!isset($result)) {
                 $this->error = $langs->trans("ErrorGlobalVariableUpdater0", "empty response");
                 return -1;
             }
             if ($code !== 200) {
                 $this->error = $langs->trans("ErrorGlobalVariableUpdater0", $code);
                 return -1;
             }
             //Decode returned response
             $result = json_decode($result, true);
         } elseif ($this->type == 1) {
             $ns = $parameters['NS'];
             if (!isset($ns)) {
                 $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'NS');
                 return -1;
             }
             $method = $parameters['METHOD'];
             if (!isset($method)) {
                 $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'METHOD');
                 return -1;
             }
             $data = $parameters['DATA'];
             if (!isset($data)) {
                 $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'DATA');
                 return -1;
             }
             //SOAP client
             require_once NUSOAP_PATH . '/nusoap.php';
             $soap_client = new nusoap_client($url);
             $soap_client->soap_defencoding = 'UTF-8';
             $soap_client->decodeUTF8(false);
             $result = $soap_client->call($method, $data, $ns, '');
             //Check if result is a error
             if ($result === false) {
                 $this->error = $langs->trans("ErrorGlobalVariableUpdater4", $soap_client->error_str);
                 return -1;
             }
         }
         //Explode value and walk for each key in value array to get the relevant key
         $value = explode(',', $value);
         foreach ($value as $key) {
             $result = $result[$key];
         }
         if (!isset($result)) {
             $this->error = $langs->trans("ErrorGlobalVariableUpdater3");
             return -1;
         }
         //Save data to global and update it
         $price_globals->value = $result;
         $price_globals->update($user);
     }
     return 1;
 }
Exemple #4
0
 $ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $ws_user);
 $result_user = $soapclient_user->call("getUser", $ws_parameters, $ws_ns, '');
 $user_status_code = $result_user["result"]["result_code"];
 if ($user_status_code == "OK") {
     //Fill the variables
     $ws_entity = $result_user["user"]["entity"];
     $ws_authentication['entity'] = $ws_entity;
     $ws_thirdparty = $result_user["user"]["fk_thirdparty"];
     if (empty($ws_thirdparty)) {
         setEventMessages($langs->trans("RemoteUserMissingAssociatedSoc"), null, 'errors');
         $error_occurred = true;
     } else {
         //Create SOAP client and connect it to product/service
         $soapclient_product = new nusoap_client($ws_url . "/webservices/server_productorservice.php");
         $soapclient_product->soap_defencoding = 'UTF-8';
         $soapclient_product->decodeUTF8(false);
         // Iterate each line and get the reference that uses the supplier of that product/service
         $i = 0;
         foreach ($object->lines as $line) {
             $i = $i + 1;
             $ref_supplier = $line->ref_supplier;
             $line_id = $i . "º) " . $line->product_ref . ": ";
             if (empty($ref_supplier)) {
                 continue;
             }
             $ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $ref_supplier);
             $result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, '');
             if (!$result_product) {
                 setEventMessages($line_id . $langs->trans("SOAPError") . " " . $soapclient_product->error_str . " - " . $soapclient_product->response, null, 'errors');
                 $error_occurred = true;
                 break;
$ns='http://www.dolibarr.org/ns/';


// Set the WebService URL
dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
$soapclient1 = new nusoap_client($WS_DOL_URL);
if ($soapclient1)
{
	$soapclient1->soap_defencoding='UTF-8';
	$soapclient1->decodeUTF8(false);
}
$soapclient2 = new nusoap_client($WS_DOL_URL);
if ($soapclient2)
{
    $soapclient2->soap_defencoding='UTF-8';
	$soapclient2->decodeUTF8(false);
}

// Call the WebService method and store its result in $result.
$authentication=array(
    'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
    'sourceapplication'=>'DEMO',
    'login'=>'admin',
    'password'=>'changeme',
    'entity'=>'');


// Test url 1
if ($WS_METHOD1)
{
    $parameters = array('authentication'=>$authentication,'id'=>1,'ref'=>'');
    /**
     * testWSVersion
     *
     * @return int
     */
    public function testWSGetVersions()
    {
    	global $conf,$user,$langs,$db;
		$conf=$this->savconf;
		$user=$this->savuser;
		$langs=$this->savlangs;
		$db=$this->savdb;

        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_other.php';
        //$WS_DOL_URL = 'http://localhost:8080/';   // If not a page, should end with /
        $WS_METHOD  = 'getVersions';
        $ns='http://www.dolibarr.org/ns/';


        // Set the WebService URL
        print __METHOD__."Create nusoap_client for URL=".$WS_DOL_URL."\n";
        $soapclient = new nusoap_client($WS_DOL_URL);
        if ($soapclient)
        {
            $soapclient->soap_defencoding='UTF-8';
            $soapclient->decodeUTF8(false);
        }

        // Call the WebService method and store its result in $result.
        $authentication=array(
            'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
            'sourceapplication'=>'DEMO',
            'login'=>'admin',
            'password'=>'admin',
            'entity'=>'');

        // Test URL
        if ($WS_METHOD)
        {
            $parameters = array('authentication'=>$authentication);
            print __METHOD__."Call method ".$WS_METHOD."\n";
            $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
            if (! $result)
            {
                //var_dump($soapclient);
                //print_r($soapclient);
                print $soapclient->error_str;
                print "<br>\n\n";
                print $soapclient->request;
                print "<br>\n\n";
                print $soapclient->response;
                exit;
            }
        }

        print __METHOD__." result=".$result."\n";
        $this->assertEquals('OK',$result['result']['result_code']);

		return $result;
    }
 /**
  * testWSProductsDeleteProductOrService
  *
  * @param   int $id     Id of product or service
  * @return  int         0
  *
  * @depends testWSProductsGetProductOrService
  */
 public function testWSProductsDeleteProductOrService($id)
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $WS_DOL_URL = DOL_MAIN_URL_ROOT . '/webservices/server_productorservice.php';
     $WS_METHOD = 'deleteProductOrService';
     $ns = 'http://www.dolibarr.org/ns/';
     // Set the WebService URL
     print __METHOD__ . " create nusoap_client for URL=" . $WS_DOL_URL . "\n";
     $soapclient = new nusoap_client($WS_DOL_URL);
     if ($soapclient) {
         $soapclient->soap_defencoding = 'UTF-8';
         $soapclient->decodeUTF8(false);
     }
     // Call the WebService method and store its result in $result.
     $authentication = array('dolibarrkey' => $conf->global->WEBSERVICES_KEY, 'sourceapplication' => 'DEMO', 'login' => 'admin', 'password' => 'admin', 'entity' => '');
     // Test URL
     $result = '';
     $parameters = array('authentication' => $authentication, 'listofid' => $id);
     print __METHOD__ . " call method " . $WS_METHOD . "\n";
     try {
         $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
     } catch (SoapFault $exception) {
         echo $exception;
         $result = 0;
     }
     if (!$result || !empty($result['faultstring']) || $result['result']['result_code'] != 'OK') {
         //var_dump($soapclient);
         print $soapclient->error_str;
         print "\n<br>\n";
         print $soapclient->request;
         print "\n<br>\n";
         print $soapclient->response;
         print "\n";
     }
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('OK', $result['result']['result_code']);
     return 0;
 }
<?php

/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
*
 ********************************************************************************/
require_once "PortalConfig.php";
require_once 'nusoap/lib/nusoap.php';
global $Server_Path;
global $client;
$client = new nusoap_client($Server_Path . "/vtigerservice.php?service=customerportal", false, $proxy_host, $proxy_port, $proxy_username, $proxy_password, 0, 100);
//We have to overwrite the character set which was set in nusoap/lib/nusoap.php file (line 87)
$client->soap_defencoding = $default_charset;
// SalesPlatform.ru begin
$client->decodeUTF8(false);
// SalesPlatform.ru end
 /**
  *
  */
 function getClientSoap($service, $wsdl_mode)
 {
     //$service = self::OTHER_ENDPOINT;
     $wsdl_mode = '';
     $urlService = $this->wpdoli_settings_url . $service;
     try {
         $soap_client = new nusoap_client($urlService);
         if ($soap_client) {
             $soap_client->soap_defencoding = 'UTF-8';
             $soap_client->decodeUTF8(false);
         }
     } catch (SoapFault $exception) {
         $this->logger->add('wpdoli', $exception->getMessage());
         $this->errors[] = __('The webservice is not available. Please check the URL.' . $urlService, 'wpdoli');
         //$this->display_errors();
         // Do nothing.
         return -1;
     }
     return $soap_client;
 }