PageRenderTime 66ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/SugarCE-6.5.4/SugarCE-Full-6.5.4/examples/SoapTestPortal.php

https://bitbucket.org/blakeball/test-repository
PHP | 262 lines | 171 code | 54 blank | 37 comment | 3 complexity | c74c4add1729e57d3e7914804ecfd174 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM Community Edition is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. $portal_name ='';
  38. $portal_password = '';
  39. $user_name ='';
  40. $user_password = '';
  41. foreach($_POST as $name=>$value){
  42. $$name = $value;
  43. }
  44. echo <<<EOQ
  45. <form name='test' method='POST'>
  46. <table width ='800'><tr>
  47. <tr><th colspan='6'>Enter SugarCRM Portal User Information (to configure this login to SugarCRM as an admin and go the administration panel then select a user from user management)</th></tr>
  48. <td >PORTAL NAME:</td><td><input type='text' name='portal_name' value='$portal_name'></td><td>PORTAL PASSWORD:</td><td><input type='password' name='portal_password' value='$portal_password'></td>
  49. </tr>
  50. <tr><th colspan='6'>Enter SugarCRM Portal Contact Information (to configure this login to SugarCRM as an admin and edit a contact. You will see Portal Information at the bottom of the Contact EditView Panel)</th></tr>
  51. <tr>
  52. <td>CONTACT NAME:</td><td><input type='text' name='user_name' value='$user_name'></td>
  53. </tr>
  54. <tr><td><input type='submit' value='Submit'></td></tr>
  55. </table>
  56. </form>
  57. EOQ;
  58. if(!empty($portal_name)){
  59. $portal_password = md5($portal_password);
  60. require_once('../include/nusoap/nusoap.php'); //must also have the nusoap code on the ClientSide.
  61. $soapclient = new nusoapclient('http://localhost/sugarcrm/soap.php'); //define the SOAP Client an
  62. //application_name is the client application connecting to sugar CRM for example mambo
  63. echo '<b>LOGIN:</b><BR>';
  64. $result = $soapclient->call('portal_login',array('portal_auth'=>array('user_name'=>$portal_name,'password'=>$portal_password, 'version'=>'.01'),'user_name'=>$user_name, 'application_name'=>'SoapTestPortal'));
  65. echo '<b>HERE IS ERRORS:</b><BR>';
  66. echo $soapclient->error_str;
  67. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  68. echo $soapclient->response;
  69. echo '<BR><BR>';
  70. echo $soapclient->responseHeaders;
  71. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  72. echo print_r($result);
  73. $session = $result['id'];
  74. echo '<br><br><b>GET CASES:</b><BR>';
  75. $result = $soapclient->call('portal_get_entry_list',array('session'=>$session , 'module_name'=>'Cases','where'=>"date_entered > '".date($GLOBALS['timedate']->dbDayFormat) ."'", 'order_by'=>'', 'select_fields'=>array('name', 'description', 'priority', 'status')));
  76. echo '<b>HERE IS ERRORS:</b><BR>';
  77. echo $soapclient->error_str;
  78. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  79. echo $soapclient->response;
  80. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  81. echo print_r($result);
  82. $case_id = $result['entry_list'][0]['id'];
  83. echo '<br><br><b>GET Case fields:</b><BR>';
  84. $result = $soapclient->call('portal_get_module_fields',array('session'=>$session , 'module_name'=>'Cases'));
  85. echo '<b>HERE IS ERRORS:</b><BR>';
  86. echo $soapclient->error_str;
  87. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  88. echo $soapclient->response;
  89. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  90. echo print_r($result);
  91. echo '<br><br><b>CREATE Case:</b><BR>';
  92. $result = $soapclient->call('portal_set_entry',array('session'=>$session , 'module_name'=>'Cases', 'name_value_list'=>array(array('name'=>'name', 'value'=>'a case'), array('name'=>'description', 'value'=>'A case created through webservices'))));
  93. echo '<b>HERE IS ERRORS:</b><BR>';
  94. echo $soapclient->error_str;
  95. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  96. echo $soapclient->response;
  97. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  98. echo print_r($result);
  99. $case_id = $result['id'];
  100. echo '<br><br><b>CREATE Note:</b><BR>';
  101. $result = $soapclient->call('portal_set_entry',array('session'=>$session , 'module_name'=>'Notes', 'name_value_list'=>array(array('name'=>'name', 'value'=>'a note attached to a case'), array('name'=>'description', 'value'=>'A note created through webservices'))));
  102. echo '<b>HERE IS ERRORS:</b><BR>';
  103. echo $soapclient->error_str;
  104. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  105. echo $soapclient->response;
  106. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  107. echo print_r($result);
  108. $note_id = $result['id'];
  109. echo '<br><br><b>ATTACH A FILE:</b><BR>';
  110. $file = base64_encode('this would be the contents of your file');
  111. $result = $soapclient->call('portal_set_note_attachment',array('session'=>$session, 'note_attachment'=>array('id'=>$note_id, 'filename'=>'an attached file', 'file'=>$file)));
  112. echo '<b>HERE IS ERRORS:</b><BR>';
  113. echo $soapclient->error_str;
  114. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  115. echo $soapclient->response;
  116. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  117. echo print_r($result);
  118. echo '<br><br><b>ATTACH NOTE TO THE CASE:</b><BR>';
  119. $result = $soapclient->call('portal_relate_note_to_module',array('session'=>$session, 'note_id'=>$note_id, 'module_name'=>'Cases', 'module_id'=>$case_id));
  120. echo '<b>HERE IS ERRORS:</b><BR>';
  121. echo $soapclient->error_str;
  122. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  123. echo $soapclient->response;
  124. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  125. echo print_r($result);
  126. echo '<br><br><b>GET NOTES RELATED TO A CASE:</b><BR>';
  127. $result = $soapclient->call('portal_get_related_notes',array('session'=>$session , 'module_name'=>'Cases', 'module_id'=>$case_id, 'select_fields'=>array('name', 'description', 'filename')));
  128. echo '<b>HERE IS ERRORS:</b><BR>';
  129. echo $soapclient->error_str;
  130. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  131. echo $soapclient->response;
  132. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  133. echo print_r($result);
  134. $note_id = $result['entry_list'][0]['id'];
  135. echo '<br><br><b>GET ATTACHMENT TO A NOTE:</b><BR>';
  136. $result = $soapclient->call('portal_get_note_attachment',array('session'=>$session , 'id'=>$note_id));
  137. echo '<b>HERE IS ERRORS:</b><BR>';
  138. echo $soapclient->error_str;
  139. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  140. echo $soapclient->response;
  141. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  142. echo print_r($result);
  143. echo '<br>It Reads:' . base64_decode($result['note_attachment']['file']);
  144. echo '<br><br><b>LOGOUT:</b><BR>';
  145. $result = $soapclient->call('portal_logout',array('session'=>$session));
  146. echo '<b>HERE IS ERRORS:</b><BR>';
  147. echo $soapclient->error_str;
  148. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  149. echo $soapclient->response;
  150. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  151. echo print_r($result);
  152. echo '<b>LOG BACK IN:</b><BR>';
  153. $result = $soapclient->call('portal_login',array('portal_auth'=>array('user_name'=>$portal_name,'password'=>$portal_password, 'version'=>'.01'),'user_name'=>$user_name, 'application_name'=>'SoapTestPortal'));
  154. echo '<b>HERE IS ERRORS:</b><BR>';
  155. echo $soapclient->error_str;
  156. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  157. echo $soapclient->response;
  158. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  159. echo print_r($result);
  160. $session = $result['id'];
  161. echo '<br><br><b>GET CASES:</b><BR>';
  162. $result = $soapclient->call('portal_get_entry_list',array('session'=>$session , 'module_name'=>'Cases','where'=>"date_entered > '".date($GLOBALS['timedate']->dbDayFormat) ."'", 'order_by'=>'', 'select_fields'=>array('name', 'description', 'priority', 'status')));
  163. echo '<b>HERE IS ERRORS:</b><BR>';
  164. echo $soapclient->error_str;
  165. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  166. echo $soapclient->response;
  167. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  168. echo print_r($result);
  169. $case_id = $result['entry_list'][0]['id'];
  170. //FOR AUTHENTICATION YOU MUST DO A LOOK UP OF CASES BEFORE YOU TRY TO GET A NOTE RELATED TO A CASE
  171. echo '<br><br><b>GET NOTES RELATED TO A CASE:</b><BR>';
  172. $result = $soapclient->call('portal_get_related_notes',array('session'=>$session , 'module_name'=>'Cases', 'module_id'=>$case_id, 'select_fields'=>array('name', 'description', 'filename')));
  173. echo '<b>HERE IS ERRORS:</b><BR>';
  174. echo $soapclient->error_str;
  175. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  176. echo $soapclient->response;
  177. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  178. echo print_r($result);
  179. $note_id = $result['entry_list'][0]['id'];
  180. echo '<br><br><b>GET ATTACHMENT TO A NOTE:</b><BR>';
  181. $result = $soapclient->call('portal_get_note_attachment',array('session'=>$session , 'id'=>$note_id));
  182. echo '<b>HERE IS ERRORS:</b><BR>';
  183. echo $soapclient->error_str;
  184. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  185. echo $soapclient->response;
  186. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  187. echo print_r($result);
  188. //does not have accesss to this case
  189. $case_id = 'bf90ee6f-c7fa-520c-f4b4-4212a55eb969';
  190. echo '<br><br><b>GET NOTES RELATED TO A CASE NOT RELATED TO THE LOGGED IN CONTACT:</b><BR>';
  191. $result = $soapclient->call('portal_get_related_notes',array('session'=>$session , 'module_name'=>'Cases', 'module_id'=>$case_id, 'select_fields'=>array('name', 'description')));
  192. echo '<b>HERE IS ERRORS:</b><BR>';
  193. echo $soapclient->error_str;
  194. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  195. echo $soapclient->response;
  196. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  197. echo print_r($result);
  198. $note_id = $result['entry_list'][0]['id'];
  199. echo '<br><br><b>LOGOUT:</b><BR>';
  200. $result = $soapclient->call('portal_logout',array('session'=>$session));
  201. echo '<b>HERE IS ERRORS:</b><BR>';
  202. echo $soapclient->error_str;
  203. echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
  204. echo $soapclient->response;
  205. echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
  206. echo print_r($result);
  207. }
  208. ?>