demo_wsclient_actioncomm.php-NORUN 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_actioncomm.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_actioncomm.php';
  27. //$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with /
  28. $WS_METHOD_GET = 'getActionComm';
  29. $WS_METHOD_CREATE = 'createActionComm';
  30. $WS_METHOD_GET_C_LIST = 'getListActionCommType';
  31. $ns='http://www.dolibarr.org/ns/';
  32. //Chosse action to do
  33. //$action='get';
  34. //$action='getlist';
  35. $action='create';
  36. // Set the WebService URL
  37. dol_syslog("Create nusoap_actioncomm for URL=".$WS_DOL_URL);
  38. $soapclient = new nusoap_client($WS_DOL_URL);
  39. if ($soapclient)
  40. {
  41. $soapclient->soap_defencoding='UTF-8';
  42. $soapclient->decodeUTF8(false);
  43. }
  44. // Call the WebService method and store its result in $result.
  45. $authentication=array(
  46. 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
  47. 'sourceapplication'=>'DEMO',
  48. 'login'=>'admin',
  49. 'password'=>'changeme',
  50. 'entity'=>'1');
  51. // Test URL
  52. if ($action=='get')
  53. {
  54. $WS_METHOD=$WS_METHOD_GET;
  55. $parameters = array('authentication'=>$authentication,'id'=>1);
  56. dol_syslog("Call method ".$WS_METHOD_GET);
  57. $result = $soapclient->call($WS_METHOD_GET,$parameters,$ns,'');
  58. if (! $result)
  59. {
  60. print $soapclient->error_str;
  61. print "<br>\n\n";
  62. print $soapclient->request;
  63. print "<br>\n\n";
  64. print $soapclient->response;
  65. exit;
  66. }
  67. }
  68. // Test URL
  69. if ($action=='getlist')
  70. {
  71. $WS_METHOD=$WS_METHOD_GET_C_LIST;
  72. $parameters = array('authentication'=>$authentication);
  73. dol_syslog("Call method ".$WS_METHOD_GET_C_LIST);
  74. $result = $soapclient->call($WS_METHOD_GET_C_LIST,$parameters,$ns,'');
  75. if (! $result)
  76. {
  77. print $soapclient->error_str;
  78. print "<br>\n\n";
  79. print $soapclient->request;
  80. print "<br>\n\n";
  81. print $soapclient->response;
  82. exit;
  83. }
  84. }
  85. // Test URL
  86. if ($action=='create')
  87. {
  88. $WS_METHOD=$WS_METHOD_CREATE;
  89. $new=array(
  90. 'datep'=>dol_mktime(13, 30, 00, 12, 16, 2012),
  91. 'datef'=>dol_mktime(15, 30, 00, 12, 16, 2012),
  92. 'type_code'=>'AC_RDV',
  93. 'socid'=>'1',
  94. 'projectid'=>'',
  95. 'note'=>'This is note',
  96. 'contactid'=>'',
  97. 'userownerod'=>'1',
  98. 'label'=>'Ceci est les titre de l\'envenement',
  99. 'percentage'=>'100',
  100. 'location'=>'Location1'
  101. );
  102. $parameters = array('authentication'=>$authentication,'actioncomm'=>$new);
  103. dol_syslog("Call method ".$WS_METHOD_CREATE);
  104. $result = $soapclient->call($WS_METHOD_CREATE,$parameters,$ns,'');
  105. if (! $result)
  106. {
  107. print $soapclient->error_str;
  108. print "<br>\n\n";
  109. print $soapclient->request;
  110. print "<br>\n\n";
  111. print $soapclient->response;
  112. exit;
  113. }
  114. }
  115. /*
  116. * View
  117. */
  118. header("Content-type: text/html; charset=utf8");
  119. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
  120. echo '<html>'."\n";
  121. echo '<head>';
  122. echo '<title>WebService Test: '.$WS_METHOD.'</title>';
  123. echo '</head>'."\n";
  124. echo '<body>'."\n";
  125. echo 'NUSOAP_PATH='.NUSOAP_PATH.'<br>';
  126. echo "<h2>Request:</h2>";
  127. echo '<h4>Function</h4>';
  128. echo $WS_METHOD;
  129. echo '<h4>SOAP Message</h4>';
  130. echo '<pre>' . htmlspecialchars($soapclient->request, ENT_QUOTES) . '</pre>';
  131. echo '<hr>';
  132. echo "<h2>Response:</h2>";
  133. echo '<h4>Result</h4>';
  134. echo '<pre>';
  135. print_r($result);
  136. echo '</pre>';
  137. echo '<h4>SOAP Message</h4>';
  138. echo '<pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '</pre>';
  139. echo '</body>'."\n";
  140. echo '</html>'."\n";
  141. ?>