demo_wsclient_thirdparty.php-NORUN 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/webservices/demo_wsclient_thirdparty.php
  20. * \brief Demo page to make a client call to Dolibarr WebServices "server_other"
  21. */
  22. // This is to make Dolibarr working with Plesk
  23. set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
  24. require_once '../master.inc.php';
  25. require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
  26. $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
  27. //$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with /
  28. $WS_METHOD_GETTHIRDSPARTY = 'getThirdParty';
  29. $WS_METHOD_CREATETHIRDSPARTY = 'createThirdParty';
  30. $WS_METHOD_UPDATETHIRDSPARTY = 'updateThirdParty';
  31. $WS_METHOD_GETTHIRDSPARTYLIST = 'getListOfThirdParties';
  32. $ns='http://www.dolibarr.org/ns/';
  33. //Chosse action to do
  34. //$action='get';
  35. //$action='create';
  36. //$action='update';
  37. $action='getList';
  38. // Set the WebService URL
  39. dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
  40. $soapclient = new nusoap_client($WS_DOL_URL);
  41. if ($soapclient)
  42. {
  43. $soapclient->soap_defencoding='UTF-8';
  44. $soapclient->decodeUTF8(false);
  45. }
  46. // Call the WebService method and store its result in $result.
  47. $authentication=array(
  48. 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
  49. 'sourceapplication'=>'DEMO',
  50. 'login'=>'admin',
  51. 'password'=>'changeme',
  52. 'entity'=>'');
  53. // Test URL
  54. if ($action=='get')
  55. {
  56. $parameters = array('authentication'=>$authentication,'id'=>1,'name'=>'','ref_ext'=>'');
  57. dol_syslog("Call method ".$WS_METHOD_GETTHIRDSPARTY);
  58. $result = $soapclient->call($WS_METHOD_GETTHIRDSPARTY,$parameters,$ns,'');
  59. if (! $result)
  60. {
  61. print $soapclient->error_str;
  62. print "<br>\n\n";
  63. print $soapclient->request;
  64. print "<br>\n\n";
  65. print $soapclient->response;
  66. exit;
  67. }
  68. }
  69. // Test URL
  70. if ($action=='getList')
  71. {
  72. $filterthirdparty=array('category'=>'3');
  73. $parameters = array('authentication'=>$authentication,$filterthirdparty);
  74. dol_syslog("Call method ".$WS_METHOD_GETTHIRDSPARTYLIST);
  75. $result = $soapclient->call($WS_METHOD_GETTHIRDSPARTYLIST,$parameters,$ns,'');
  76. if (! $result)
  77. {
  78. print $soapclient->error_str;
  79. print "<br>\n\n";
  80. print $soapclient->request;
  81. print "<br>\n\n";
  82. print $soapclient->response;
  83. exit;
  84. }
  85. }
  86. // Test URL
  87. if ($action=='create')
  88. {
  89. $newthirdparty=array(
  90. 'ref'=>'Test WS Create Client',
  91. 'ref_ext'=>'WS0001',
  92. 'fk_user_author'=>'1',
  93. 'status'=>'1',
  94. 'client'=>'1',
  95. 'supplier'=>'0',
  96. 'address'=>'Adresse customer',
  97. 'zip'=>'75000',
  98. 'town'=>'Paris',
  99. 'country_id'=>'1',//France
  100. 'customer_code'=>'-1',//Generate code regarding module configuration
  101. 'supplier_code'=>'0',
  102. 'phone'=>'0141414141',
  103. 'fax'=>'0121212121',
  104. 'email'=>'webtest1@test.fr',
  105. 'url'=>' www.test.fr',
  106. 'profid1'=>'1111111',
  107. 'profid2'=>'222222',
  108. 'profid3'=>'333333',
  109. 'profid4'=>'44444',
  110. 'profid5'=>'55555',
  111. 'profid6'=>'66666',
  112. 'capital'=>'3000',
  113. 'vat_used'=>'0',
  114. 'vat_number'=>''
  115. //,'options_attr1'=>'Attr1 balbal', //Extra field exemple where field code is attr1
  116. //'options_attr2'=>'Attr2 balbal' //Extra field exemple where field code is attr2
  117. );
  118. $parameters = array('authentication'=>$authentication,'thirdparty'=>$newthirdparty);
  119. dol_syslog("Call method ".$WS_METHOD_CREATETHIRDSPARTY);
  120. $result = $soapclient->call($WS_METHOD_CREATETHIRDSPARTY,$parameters,$ns,'');
  121. if (! $result)
  122. {
  123. print $soapclient->error_str;
  124. print "<br>\n\n";
  125. print $soapclient->request;
  126. print "<br>\n\n";
  127. print $soapclient->response;
  128. exit;
  129. }
  130. }
  131. // Test URL
  132. if ($action=='update')
  133. {
  134. $thirdparty=array(
  135. 'id'=>'1',
  136. 'ref'=>'Test WS Create Client',
  137. 'ref_ext'=>'WS0001',
  138. 'fk_user_mod'=>'1',
  139. 'status'=>'1',
  140. 'client'=>'1',
  141. 'supplier'=>'0',
  142. 'address'=>'Adresse customer',
  143. 'zip'=>'75000',
  144. 'town'=>'Paris',
  145. 'country_id'=>'1',//France
  146. 'customer_code'=>'-1',//Generate code regarding module configuration
  147. 'supplier_code'=>'0',
  148. 'phone'=>'0141414141',
  149. 'fax'=>'0121212121',
  150. 'email'=>'webtest1@test.fr',
  151. 'url'=>' www.test.fr',
  152. 'profid1'=>'1111111',
  153. 'profid2'=>'222222',
  154. 'profid3'=>'333333',
  155. 'profid4'=>'44444',
  156. 'profid5'=>'55555',
  157. 'profid6'=>'66666',
  158. 'capital'=>'3000',
  159. 'vat_used'=>'0',
  160. 'vat_number'=>''
  161. //,'options_attr1'=>'Attr1 balbal', //Extra field exemple where field code is attr1
  162. //'options_attr2'=>'Attr2 balbal' //Extra field exemple where field code is attr2
  163. );
  164. $parameters = array('authentication'=>$authentication,'thirdparty'=>$thirdparty);
  165. dol_syslog("Call method ".$WS_METHOD_UPDATETHIRDSPARTY);
  166. $result = $soapclient->call($WS_METHOD_UPDATETHIRDSPARTY,$parameters,$ns,'');
  167. if (! $result)
  168. {
  169. print $soapclient->error_str;
  170. print "<br>\n\n";
  171. print $soapclient->request;
  172. print "<br>\n\n";
  173. print $soapclient->response;
  174. exit;
  175. }
  176. }
  177. /*
  178. * View
  179. */
  180. header("Content-type: text/html; charset=utf8");
  181. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
  182. echo '<html>'."\n";
  183. echo '<head>';
  184. echo '<title>WebService Test: '.$WS_METHOD.'</title>';
  185. echo '</head>'."\n";
  186. echo '<body>'."\n";
  187. echo 'NUSOAP_PATH='.NUSOAP_PATH.'<br>';
  188. echo "<h2>Request:</h2>";
  189. echo '<h4>Function</h4>';
  190. echo $WS_METHOD;
  191. echo '<h4>SOAP Message</h4>';
  192. echo '<pre>' . htmlspecialchars($soapclient->request, ENT_QUOTES) . '</pre>';
  193. echo '<hr>';
  194. echo "<h2>Response:</h2>";
  195. echo '<h4>Result</h4>';
  196. echo '<pre>';
  197. print_r($result);
  198. echo '</pre>';
  199. echo '<h4>SOAP Message</h4>';
  200. echo '<pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '</pre>';
  201. echo '</body>'."\n";
  202. echo '</html>'."\n";
  203. ?>