]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - examples/SoapTestPortal.php
Release 6.5.0
[Github/sugarcrm.git] / examples / SoapTestPortal.php
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
38 $portal_name ='';
39 $portal_password = '';
40 $user_name ='';
41 $user_password = '';
42 foreach($_POST as $name=>$value){
43                 $$name = $value;
44 }
45 echo <<<EOQ
46 <form name='test' method='POST'>
47 <table width ='800'><tr>
48 <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>
49 <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>
50 </tr>
51 <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>
52 <tr>
53 <td>CONTACT NAME:</td><td><input type='text' name='user_name' value='$user_name'></td>
54 </tr>
55 <tr><td><input type='submit' value='Submit'></td></tr>
56 </table>
57 </form>
58
59
60 EOQ;
61
62 if(!empty($portal_name)){
63 $portal_password = md5($portal_password);
64 require_once('../include/nusoap/nusoap.php');  //must also have the nusoap code on the ClientSide.
65 $soapclient = new nusoapclient('http://localhost/sugarcrm/soap.php');  //define the SOAP Client an
66 //application_name is the client application connecting to sugar CRM for example mambo
67 echo '<b>LOGIN:</b><BR>';
68 $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'));
69 echo '<b>HERE IS ERRORS:</b><BR>';
70 echo $soapclient->error_str;
71
72 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
73 echo $soapclient->response;
74 echo '<BR><BR>';
75 echo $soapclient->responseHeaders;
76
77 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
78 echo print_r($result);
79 $session = $result['id'];
80 echo '<br><br><b>GET CASES:</b><BR>';
81 $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')));
82 echo '<b>HERE IS ERRORS:</b><BR>';
83 echo $soapclient->error_str;
84
85 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
86 echo $soapclient->response;
87
88 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
89 echo print_r($result);
90 $case_id = $result['entry_list'][0]['id'];
91
92 echo '<br><br><b>GET Case fields:</b><BR>';
93 $result = $soapclient->call('portal_get_module_fields',array('session'=>$session , 'module_name'=>'Cases'));
94 echo '<b>HERE IS ERRORS:</b><BR>';
95 echo $soapclient->error_str;
96
97 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
98 echo $soapclient->response;
99
100 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
101 echo print_r($result);
102
103 echo '<br><br><b>CREATE Case:</b><BR>';
104 $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'))));
105 echo '<b>HERE IS ERRORS:</b><BR>';
106 echo $soapclient->error_str;
107
108 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
109 echo $soapclient->response;
110
111 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
112 echo print_r($result);
113
114 $case_id = $result['id'];
115 echo '<br><br><b>CREATE Note:</b><BR>';
116 $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'))));
117 echo '<b>HERE IS ERRORS:</b><BR>';
118 echo $soapclient->error_str;
119
120 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
121 echo $soapclient->response;
122
123 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
124 echo print_r($result);
125 $note_id = $result['id'];
126 echo '<br><br><b>ATTACH A FILE:</b><BR>';
127 $file = base64_encode('this would be the contents of your file');
128 $result = $soapclient->call('portal_set_note_attachment',array('session'=>$session, 'note_attachment'=>array('id'=>$note_id, 'filename'=>'an attached file', 'file'=>$file)));
129 echo '<b>HERE IS ERRORS:</b><BR>';
130 echo $soapclient->error_str;
131
132 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
133 echo $soapclient->response;
134
135 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
136 echo print_r($result);
137
138 echo '<br><br><b>ATTACH NOTE TO THE CASE:</b><BR>';
139
140 $result = $soapclient->call('portal_relate_note_to_module',array('session'=>$session, 'note_id'=>$note_id, 'module_name'=>'Cases', 'module_id'=>$case_id));
141 echo '<b>HERE IS ERRORS:</b><BR>';
142 echo $soapclient->error_str;
143
144 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
145 echo $soapclient->response;
146
147 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
148 echo print_r($result);
149
150 echo '<br><br><b>GET NOTES RELATED TO A CASE:</b><BR>';
151 $result = $soapclient->call('portal_get_related_notes',array('session'=>$session , 'module_name'=>'Cases', 'module_id'=>$case_id, 'select_fields'=>array('name', 'description', 'filename')));
152 echo '<b>HERE IS ERRORS:</b><BR>';
153 echo $soapclient->error_str;
154
155 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
156 echo $soapclient->response;
157
158 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
159 echo print_r($result);
160 $note_id = $result['entry_list'][0]['id'];
161
162 echo '<br><br><b>GET ATTACHMENT TO A NOTE:</b><BR>';
163 $result = $soapclient->call('portal_get_note_attachment',array('session'=>$session , 'id'=>$note_id));
164 echo '<b>HERE IS ERRORS:</b><BR>';
165 echo $soapclient->error_str;
166
167 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
168 echo $soapclient->response;
169
170 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
171 echo print_r($result);
172
173 echo '<br>It Reads:' . base64_decode($result['note_attachment']['file']);
174
175 echo '<br><br><b>LOGOUT:</b><BR>';
176 $result = $soapclient->call('portal_logout',array('session'=>$session));
177 echo '<b>HERE IS ERRORS:</b><BR>';
178 echo $soapclient->error_str;
179
180 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
181 echo $soapclient->response;
182
183 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
184 echo print_r($result);
185
186
187 echo '<b>LOG BACK IN:</b><BR>';
188 $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'));
189 echo '<b>HERE IS ERRORS:</b><BR>';
190 echo $soapclient->error_str;
191
192 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
193 echo $soapclient->response;
194
195 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
196 echo print_r($result);
197 $session = $result['id'];
198
199
200 echo '<br><br><b>GET CASES:</b><BR>';
201 $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')));
202 echo '<b>HERE IS ERRORS:</b><BR>';
203 echo $soapclient->error_str;
204
205 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
206 echo $soapclient->response;
207
208 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
209 echo print_r($result);
210 $case_id = $result['entry_list'][0]['id'];
211 //FOR AUTHENTICATION YOU MUST DO A LOOK UP OF CASES BEFORE YOU TRY TO GET A NOTE RELATED TO A CASE
212 echo '<br><br><b>GET NOTES RELATED TO A CASE:</b><BR>';
213 $result = $soapclient->call('portal_get_related_notes',array('session'=>$session , 'module_name'=>'Cases', 'module_id'=>$case_id, 'select_fields'=>array('name', 'description', 'filename')));
214 echo '<b>HERE IS ERRORS:</b><BR>';
215 echo $soapclient->error_str;
216
217 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
218 echo $soapclient->response;
219
220 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
221 echo print_r($result);
222 $note_id = $result['entry_list'][0]['id'];
223
224 echo '<br><br><b>GET ATTACHMENT TO A NOTE:</b><BR>';
225 $result = $soapclient->call('portal_get_note_attachment',array('session'=>$session , 'id'=>$note_id));
226 echo '<b>HERE IS ERRORS:</b><BR>';
227 echo $soapclient->error_str;
228
229 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
230 echo $soapclient->response;
231
232 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
233 echo print_r($result);
234 //does not have accesss to this case
235 $case_id = 'bf90ee6f-c7fa-520c-f4b4-4212a55eb969';
236 echo '<br><br><b>GET NOTES RELATED TO A CASE NOT RELATED TO THE LOGGED IN CONTACT:</b><BR>';
237 $result = $soapclient->call('portal_get_related_notes',array('session'=>$session , 'module_name'=>'Cases', 'module_id'=>$case_id, 'select_fields'=>array('name', 'description')));
238 echo '<b>HERE IS ERRORS:</b><BR>';
239 echo $soapclient->error_str;
240
241 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
242 echo $soapclient->response;
243
244 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
245 echo print_r($result);
246 $note_id = $result['entry_list'][0]['id'];
247
248
249
250 echo '<br><br><b>LOGOUT:</b><BR>';
251 $result = $soapclient->call('portal_logout',array('session'=>$session));
252 echo '<b>HERE IS ERRORS:</b><BR>';
253 echo $soapclient->error_str;
254
255 echo '<BR><BR><b>HERE IS RESPONSE:</b><BR>';
256 echo $soapclient->response;
257
258 echo '<BR><BR><b>HERE IS RESULT:</b><BR>';
259 echo print_r($result);
260
261 }
262 ?>