1 | <?php
|
---|
2 | if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
---|
3 | /*********************************************************************************
|
---|
4 | * SugarCRM is a customer relationship management program developed by
|
---|
5 | * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
|
---|
6 | *
|
---|
7 | * This program is free software; you can redistribute it and/or modify it under
|
---|
8 | * the terms of the GNU 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 General Public License for more
|
---|
17 | * details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU 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 General Public License version 3.
|
---|
30 | *
|
---|
31 | * In accordance with Section 7(b) of the GNU 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 | require_once('soap/SoapHelperFunctions.php');
|
---|
39 | require_once('soap/SoapTypes.php');
|
---|
40 | require_once('modules/Contacts/Contact.php');
|
---|
41 | require_once('modules/Accounts/Account.php');
|
---|
42 | require_once('soap/SoapPortalHelper.php');
|
---|
43 | require_once('include/SugarEmailAddress/SugarEmailAddress.php');
|
---|
44 | require_once('config.php');
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 | /*************************************************************************************
|
---|
52 |
|
---|
53 | THIS IS FOR PORTAL USERS
|
---|
54 |
|
---|
55 |
|
---|
56 | *************************************************************************************/
|
---|
57 | /*
|
---|
58 | this authenticates a user as a portal user and returns the session id or it returns false otherwise;
|
---|
59 | */
|
---|
60 | $server->register(
|
---|
61 | 'portal_login',
|
---|
62 | array('portal_auth'=>'tns:user_auth','user_name'=>'xsd:string', 'application_name'=>'xsd:string'),
|
---|
63 | array('return'=>'tns:set_entry_result'),
|
---|
64 | $NAMESPACE);
|
---|
65 |
|
---|
66 | function portal_login($portal_auth, $user_name, $application_name){
|
---|
67 | $error = new SoapError();
|
---|
68 | $contact = new Contact();
|
---|
69 | $result = login_user($portal_auth);
|
---|
70 |
|
---|
71 | if($result == 'fail' || $result == 'sessions_exceeded'){
|
---|
72 | if($result == 'sessions_exceeded') {
|
---|
73 | $error->set_error('sessions_exceeded');
|
---|
74 | }
|
---|
75 | else {
|
---|
76 | $error->set_error('no_portal');
|
---|
77 | }
|
---|
78 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
79 | }
|
---|
80 | global $current_user;
|
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | if($user_name == 'lead'){
|
---|
86 | session_start();
|
---|
87 | $_SESSION['is_valid_session']= true;
|
---|
88 | $_SESSION['ip_address'] = query_client_ip();
|
---|
89 | $_SESSION['portal_id'] = $current_user->id;
|
---|
90 | $_SESSION['type'] = 'lead';
|
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 | login_success();
|
---|
98 | return array('id'=>session_id(), 'error'=>$error->get_soap_array());
|
---|
99 | }else if($user_name == 'portal'){
|
---|
100 | session_start();
|
---|
101 | $_SESSION['is_valid_session']= true;
|
---|
102 | $_SESSION['ip_address'] = query_client_ip();
|
---|
103 | $_SESSION['portal_id'] = $current_user->id;
|
---|
104 | $_SESSION['type'] = 'portal';
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 | $GLOBALS['log']->debug("Saving new session");
|
---|
112 | login_success();
|
---|
113 | return array('id'=>session_id(), 'error'=>$error->get_soap_array());
|
---|
114 | }else{
|
---|
115 | $contact = $contact->retrieve_by_string_fields(array('portal_name'=>$user_name, 'portal_active'=>'1', 'deleted'=>0) );
|
---|
116 | if($contact != null){
|
---|
117 | session_start();
|
---|
118 | $_SESSION['is_valid_session']= true;
|
---|
119 | $_SESSION['ip_address'] = query_client_ip();
|
---|
120 | $_SESSION['user_id'] = $contact->id;
|
---|
121 | $_SESSION['portal_id'] = $current_user->id;
|
---|
122 |
|
---|
123 | $_SESSION['type'] = 'contact';
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 | $_SESSION['assigned_user_id'] = $contact->assigned_user_id;
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | login_success();
|
---|
135 | build_relationship_tree($contact);
|
---|
136 | return array('id'=>session_id(), 'error'=>$error->get_soap_array());
|
---|
137 | }
|
---|
138 | }
|
---|
139 | $error->set_error('invalid_login');
|
---|
140 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 |
|
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 |
|
---|
186 |
|
---|
187 |
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 | /*
|
---|
196 | this validates the session and starts the session;
|
---|
197 | */
|
---|
198 | function portal_validate_authenticated($session_id){
|
---|
199 | $old_error_reporting = error_reporting(0);
|
---|
200 | session_id($session_id);
|
---|
201 |
|
---|
202 | // This little construct checks to see if the session validated
|
---|
203 | if(session_start()) {
|
---|
204 | $valid_session = true;
|
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 | if(!empty($_SESSION['is_valid_session']) && is_valid_ip_address('ip_address') && $valid_session != null && ($_SESSION['type'] == 'contact' || $_SESSION['type'] == 'lead' || $_SESSION['type'] == 'portal')){
|
---|
209 | global $current_user;
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 |
|
---|
214 | $current_user = new User();
|
---|
215 | $current_user->retrieve($_SESSION['portal_id']);
|
---|
216 | login_success();
|
---|
217 | error_reporting($old_error_reporting);
|
---|
218 | return true;
|
---|
219 | }
|
---|
220 | }
|
---|
221 | session_destroy();
|
---|
222 | error_reporting($old_error_reporting);
|
---|
223 | return false;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | $server->register(
|
---|
228 | 'portal_logout',
|
---|
229 | array('session'=>'xsd:string'),
|
---|
230 | array('return'=>'tns:error_value'),
|
---|
231 | $NAMESPACE);
|
---|
232 | function portal_logout($session){
|
---|
233 | $error = new SoapError();
|
---|
234 | if(portal_validate_authenticated($session)){
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 | session_destroy();
|
---|
240 | return $error->get_soap_array();
|
---|
241 | }
|
---|
242 | $error->set_error('invalid_session');
|
---|
243 | return $error->get_soap_array();
|
---|
244 | }
|
---|
245 |
|
---|
246 | $server->register(
|
---|
247 | 'portal_get_sugar_id',
|
---|
248 | array('session'=>'xsd:string'),
|
---|
249 | array('return'=>'tns:set_entry_result'),
|
---|
250 | $NAMESPACE);
|
---|
251 | function portal_get_sugar_id($session){
|
---|
252 | $error = new SoapError();
|
---|
253 | if(portal_validate_authenticated($session)){
|
---|
254 | return array('id'=>$_SESSION['portal_id'], 'error'=>$error->get_soap_array());
|
---|
255 | }
|
---|
256 | $error->set_error('invalid_session');
|
---|
257 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
258 |
|
---|
259 | }
|
---|
260 |
|
---|
261 | $server->register(
|
---|
262 | 'portal_get_sugar_contact_id',
|
---|
263 | array('session'=>'xsd:string'),
|
---|
264 | array('return'=>'tns:set_entry_result'),
|
---|
265 | $NAMESPACE);
|
---|
266 | function portal_get_sugar_contact_id($session){
|
---|
267 | $error = new SoapError();
|
---|
268 | if(portal_validate_authenticated($session)){
|
---|
269 | return array('id'=>$_SESSION['user_id'], 'error'=>$error->get_soap_array());
|
---|
270 | }
|
---|
271 | $error->set_error('invalid_session');
|
---|
272 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
273 |
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | $server->register(
|
---|
278 | 'portal_get_entry_list',
|
---|
279 | array('session'=>'xsd:string', 'module_name'=>'xsd:string','where'=>'xsd:string', 'order_by'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
|
---|
280 | array('return'=>'tns:get_entry_list_result'),
|
---|
281 | $NAMESPACE);
|
---|
282 |
|
---|
283 | function portal_get_entry_list($session, $module_name,$where, $order_by, $select_fields){
|
---|
284 | return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, 0, "");
|
---|
285 | }
|
---|
286 |
|
---|
287 | /*
|
---|
288 | * Acts like a normal get_entry_list except it will build the where clause based on the name_value pairs passed
|
---|
289 | * Here we assume 'AND'
|
---|
290 | */
|
---|
291 | $server->register(
|
---|
292 | 'portal_get_entry_list_filter',
|
---|
293 | array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'order_by'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'row_offset' => 'xsd:int', 'limit'=>'xsd:int', 'filter' =>'tns:name_value_operator_list'),
|
---|
294 | array('return'=>'tns:get_entry_list_result'),
|
---|
295 | $NAMESPACE);
|
---|
296 |
|
---|
297 |
|
---|
298 | function portal_get_entry_list_filter($session, $module_name, $order_by, $select_fields, $row_offset, $limit, $filter){
|
---|
299 | global $beanList, $beanFiles, $portal_modules;
|
---|
300 | $error = new SoapError();
|
---|
301 | if(! portal_validate_authenticated($session)){
|
---|
302 | $error->set_error('invalid_session');
|
---|
303 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
304 | }
|
---|
305 | if($_SESSION['type'] == 'lead'){
|
---|
306 | $error->set_error('no_access');
|
---|
307 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
308 | }
|
---|
309 | if(empty($beanList[$module_name])){
|
---|
310 | $error->set_error('no_module');
|
---|
311 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
312 | }
|
---|
313 |
|
---|
314 | //build the where clause
|
---|
315 |
|
---|
316 | $sugar = null;
|
---|
317 | if($module_name == 'Cases'){
|
---|
318 | $sugar = new aCase();
|
---|
319 | }else if($module_name == 'Contacts'){
|
---|
320 | $sugar = new Contact();
|
---|
321 | }else if($module_name == 'Accounts'){
|
---|
322 | $sugar = new Account();
|
---|
323 | }else if($module_name == 'Bugs'){
|
---|
324 | $sugar = new Bug();
|
---|
325 | } else if($module_name == 'KBDocuments' || $module_name == 'FAQ') {
|
---|
326 | $sugar = new KBDocument();
|
---|
327 | } else {
|
---|
328 | $error->set_error('no_module_support');
|
---|
329 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
330 | }
|
---|
331 |
|
---|
332 | if($sugar != null){
|
---|
333 | if(isset($filter) && is_array($filter)){
|
---|
334 | $where = "";
|
---|
335 | foreach($filter as $nvOp){
|
---|
336 | $name = $nvOp['name'];
|
---|
337 | $value = $nvOp['value'];
|
---|
338 | $value_array = $nvOp['value_array'];
|
---|
339 | $operator = $nvOp['operator'];
|
---|
340 | //do nothing if all three values are not set
|
---|
341 | if(isset($name) && (isset($value) || isset($value_array)) && isset($operator)){
|
---|
342 | if(!empty($where)){
|
---|
343 | $where .= ' AND ';
|
---|
344 | }
|
---|
345 | if(isset($sugar->field_defs[$name])){
|
---|
346 | // MFH - Added Support For Custom Fields in Searches
|
---|
347 | $cstm = isset($sugar->field_defs[$name]['source']) && $sugar->field_defs[$name]['source'] == 'custom_fields' ? '_cstm' : '';
|
---|
348 |
|
---|
349 | $where .= "$sugar->table_name$cstm.$name $operator ";
|
---|
350 | if($sugar->field_defs['name']['type'] == 'datetime'){
|
---|
351 | $where .= db_convert("'$value'", 'datetime');
|
---|
352 | }else{
|
---|
353 | if(empty($value)) {
|
---|
354 | $tmp = array();
|
---|
355 | foreach($value_array as $v) {
|
---|
356 | $tmp[] = $GLOBALS['db']->quote($v);
|
---|
357 | }
|
---|
358 | $where .= "('" . implode("', '", $tmp) . "')";
|
---|
359 | } else {
|
---|
360 | $where .= "'".$GLOBALS['db']->quote($value)."'";
|
---|
361 | }
|
---|
362 | }
|
---|
363 | }
|
---|
364 | }
|
---|
365 | }
|
---|
366 | }
|
---|
367 | return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit);
|
---|
368 | }else{
|
---|
369 | $error->set_error('no_module_support');
|
---|
370 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 |
|
---|
375 | $server->register(
|
---|
376 | 'portal_get_entry',
|
---|
377 | array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'id'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
|
---|
378 | array('return'=>'tns:get_entry_result'),
|
---|
379 | $NAMESPACE);
|
---|
380 |
|
---|
381 | function portal_get_entry($session, $module_name, $id,$select_fields ){
|
---|
382 | global $beanList, $beanFiles;
|
---|
383 | $error = new SoapError();
|
---|
384 | if(!portal_validate_authenticated($session)){
|
---|
385 | $error->set_error('invalid_session');
|
---|
386 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
387 | }
|
---|
388 | if($_SESSION['type'] == 'lead'){
|
---|
389 | $error->set_error('no_access');
|
---|
390 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
391 | }
|
---|
392 | if(empty($beanList[$module_name])){
|
---|
393 | $error->set_error('no_module');
|
---|
394 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
395 | }
|
---|
396 |
|
---|
397 | if(empty($_SESSION['viewable'][$module_name][$id])){
|
---|
398 | $error->set_error('no_access');
|
---|
399 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
400 | }
|
---|
401 |
|
---|
402 | $class_name = $beanList[$module_name];
|
---|
403 | require_once($beanFiles[$class_name]);
|
---|
404 | $seed = new $class_name();
|
---|
405 |
|
---|
406 |
|
---|
407 |
|
---|
408 | $seed->retrieve($id);
|
---|
409 | if($module_name == 'KBDocuments') {
|
---|
410 | $body = $seed->get_kbdoc_body($id);
|
---|
411 | $seed->description = $body;
|
---|
412 | }
|
---|
413 |
|
---|
414 | $output_list = Array();
|
---|
415 | $output_list[] = get_return_value($seed, $module_name);
|
---|
416 |
|
---|
417 | //$output_list[0]['name_value_list']['description'] = array('name'=>'description', 'value'=>$seed->description);
|
---|
418 | //$output_list = filter_return_list($output_list, $select_fields, $module_name);
|
---|
419 | $field_list = array();
|
---|
420 | if(empty($field_list)){
|
---|
421 | $field_list = get_field_list($seed, true);
|
---|
422 | }
|
---|
423 | $output_list = filter_return_list($output_list, $select_fields, $module_name);
|
---|
424 | $field_list = filter_field_list($field_list,$select_fields, $module_name);
|
---|
425 |
|
---|
426 | return array('field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
|
---|
427 | }
|
---|
428 |
|
---|
429 |
|
---|
430 | $server->register(
|
---|
431 | 'portal_set_entry',
|
---|
432 | array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'name_value_list'=>'tns:name_value_list'),
|
---|
433 | array('return'=>'tns:set_entry_result'),
|
---|
434 | $NAMESPACE);
|
---|
435 |
|
---|
436 | function portal_set_entry($session,$module_name, $name_value_list){
|
---|
437 | global $beanList, $beanFiles, $valid_modules_for_contact;
|
---|
438 |
|
---|
439 | $error = new SoapError();
|
---|
440 | if(!portal_validate_authenticated($session)){
|
---|
441 | $error->set_error('invalid_session');
|
---|
442 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
443 | }
|
---|
444 | if(empty($beanList[$module_name])){
|
---|
445 | $error->set_error('no_module');
|
---|
446 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
447 | }
|
---|
448 | if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
|
---|
449 | $error->set_error('no_access');
|
---|
450 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
451 | }
|
---|
452 |
|
---|
453 | if($_SESSION['type'] == 'contact' && !key_exists($module_name, $valid_modules_for_contact) ){
|
---|
454 | $error->set_error('no_access');
|
---|
455 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
456 | }
|
---|
457 |
|
---|
458 |
|
---|
459 | $class_name = $beanList[$module_name];
|
---|
460 | require_once($beanFiles[$class_name]);
|
---|
461 | $seed = new $class_name();
|
---|
462 | $is_update = false;
|
---|
463 | $values_set = array();
|
---|
464 |
|
---|
465 | foreach($name_value_list as $value){
|
---|
466 | if($value['name'] == 'id' && !empty($value['value'])) {
|
---|
467 | $seed->disable_row_level_security = true;
|
---|
468 | $seed->retrieve($value['value']);
|
---|
469 | $is_update = true;
|
---|
470 | break;
|
---|
471 | }
|
---|
472 | $values_set[$value['name']] = $value['value'];
|
---|
473 | $seed->$value['name'] = $value['value'];
|
---|
474 | }
|
---|
475 |
|
---|
476 | // If it was an update, we have to set the values again
|
---|
477 | if($is_update) {
|
---|
478 | foreach($name_value_list as $value){
|
---|
479 | $seed->$value['name'] = $value['value'];
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | if(!isset($_SESSION['viewable'][$module_name])){
|
---|
484 | $_SESSION['viewable'][$module_name] = array();
|
---|
485 | }
|
---|
486 |
|
---|
487 | if(!$is_update){
|
---|
488 |
|
---|
489 |
|
---|
490 |
|
---|
491 |
|
---|
492 |
|
---|
493 | if(isset($_SESSION['assigned_user_id']) && (!key_exists('assigned_user_id', $values_set) || empty($values_set['assigned_user_id']))){
|
---|
494 | $seed->assigned_user_id = $_SESSION['assigned_user_id'];
|
---|
495 | }
|
---|
496 | if(isset($_SESSION['account_id']) && (!key_exists('account_id', $values_set) || empty($values_set['account_id']))){
|
---|
497 | $seed->account_id = $_SESSION['account_id'];
|
---|
498 | }
|
---|
499 | $seed->portal_flag = 1;
|
---|
500 | $seed->portal_viewable = true;
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 |
|
---|
505 | $id = $seed->save();
|
---|
506 |
|
---|
507 |
|
---|
508 |
|
---|
509 | set_module_in(array('in'=>"('$id')", 'list'=>array($id)), $module_name);
|
---|
510 | if($_SESSION['type'] == 'contact' && $module_name != 'Contacts' && !$is_update){
|
---|
511 | if($module_name == 'Notes'){
|
---|
512 | $seed->contact_id = $_SESSION['user_id'];
|
---|
513 | if(isset( $_SESSION['account_id'])){
|
---|
514 | $seed->parent_type = 'Accounts';
|
---|
515 | $seed->parent_id = $_SESSION['account_id'];
|
---|
516 |
|
---|
517 | }
|
---|
518 | $id = $seed->save();
|
---|
519 | }else{
|
---|
520 | $seed->contact_id = $_SESSION['user_id'];
|
---|
521 |
|
---|
522 | if(isset( $_SESSION['account_id'])){
|
---|
523 | $seed->account_id = $_SESSION['account_id'];
|
---|
524 |
|
---|
525 | }
|
---|
526 | $seed->save_relationship_changes(false);
|
---|
527 | }
|
---|
528 | }
|
---|
529 | return array('id'=>$id, 'error'=>$error->get_soap_array());
|
---|
530 |
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 |
|
---|
535 | /*
|
---|
536 |
|
---|
537 | NOTE SPECIFIC CODE
|
---|
538 | */
|
---|
539 | $server->register(
|
---|
540 | 'portal_set_note_attachment',
|
---|
541 | array('session'=>'xsd:string','note'=>'tns:note_attachment'),
|
---|
542 | array('return'=>'tns:set_entry_result'),
|
---|
543 | $NAMESPACE);
|
---|
544 |
|
---|
545 | function portal_set_note_attachment($session,$note)
|
---|
546 | {
|
---|
547 | $error = new SoapError();
|
---|
548 | if(!portal_validate_authenticated($session)){
|
---|
549 | $error->set_error('invalid_session');
|
---|
550 | return array('id'=>'-1', 'error'=>$error->get_soap_array());
|
---|
551 | }
|
---|
552 | if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note['id']])){
|
---|
553 | $error->set_error('no_access');
|
---|
554 | return array('id'=>-1, 'error'=>$error->get_soap_array());
|
---|
555 | }
|
---|
556 | require_once('modules/Notes/NoteSoap.php');
|
---|
557 | $ns = new NoteSoap();
|
---|
558 | $id = $ns->saveFile($note, true);
|
---|
559 | return array('id'=>$id, 'error'=>$error->get_soap_array());
|
---|
560 |
|
---|
561 | }
|
---|
562 |
|
---|
563 | $server->register(
|
---|
564 | 'portal_remove_note_attachment',
|
---|
565 | array('session'=>'xsd:string', 'id'=>'xsd:string'),
|
---|
566 | array('return'=>'tns:error_value'),
|
---|
567 | $NAMESPACE);
|
---|
568 |
|
---|
569 | function portal_remove_note_attachment($session, $id)
|
---|
570 | {
|
---|
571 | $error = new SoapError();
|
---|
572 | if(! portal_validate_authenticated($session)){
|
---|
573 | $error->set_error('invalid_session');
|
---|
574 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
575 | }
|
---|
576 | if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
|
---|
577 | $error->set_error('no_access');
|
---|
578 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
579 | }
|
---|
580 | require_once('modules/Notes/Note.php');
|
---|
581 | $focus = new Note();
|
---|
582 |
|
---|
583 |
|
---|
584 |
|
---|
585 | $focus->retrieve($id);
|
---|
586 | $result = $focus->deleteAttachment();
|
---|
587 |
|
---|
588 | return $error->get_soap_array();
|
---|
589 | }
|
---|
590 |
|
---|
591 | $server->register(
|
---|
592 | 'portal_get_note_attachment',
|
---|
593 | array('session'=>'xsd:string', 'id'=>'xsd:string'),
|
---|
594 | array('return'=>'tns:return_note_attachment'),
|
---|
595 | $NAMESPACE);
|
---|
596 |
|
---|
597 | function portal_get_note_attachment($session,$id)
|
---|
598 | {
|
---|
599 |
|
---|
600 | $error = new SoapError();
|
---|
601 | if(! portal_validate_authenticated($session)){
|
---|
602 | $error->set_error('invalid_session');
|
---|
603 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
604 | }
|
---|
605 | if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
|
---|
606 | $error->set_error('no_access');
|
---|
607 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
608 | }
|
---|
609 | $current_user = $seed_user;
|
---|
610 | require_once('modules/Notes/Note.php');
|
---|
611 | $note = new Note();
|
---|
612 |
|
---|
613 |
|
---|
614 |
|
---|
615 | $note->retrieve($id);
|
---|
616 | require_once('modules/Notes/NoteSoap.php');
|
---|
617 | $ns = new NoteSoap();
|
---|
618 | if(!isset($note->filename)){
|
---|
619 | $note->filename = '';
|
---|
620 | }
|
---|
621 | $file= $ns->retrieveFile($id,$note->filename);
|
---|
622 | if($file == -1){
|
---|
623 | $error->set_error('no_file');
|
---|
624 | $file = '';
|
---|
625 | }
|
---|
626 |
|
---|
627 | return array('note_attachment'=>array('id'=>$id, 'filename'=>$note->filename, 'file'=>$file), 'error'=>$error->get_soap_array());
|
---|
628 |
|
---|
629 | }
|
---|
630 | $server->register(
|
---|
631 | 'portal_relate_note_to_module',
|
---|
632 | array('session'=>'xsd:string', 'note_id'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string'),
|
---|
633 | array('return'=>'tns:error_value'),
|
---|
634 | $NAMESPACE);
|
---|
635 |
|
---|
636 | function portal_relate_note_to_module($session,$note_id, $module_name, $module_id){
|
---|
637 | global $beanList, $beanFiles, $current_user;
|
---|
638 | $error = new SoapError();
|
---|
639 | if(! portal_validate_authenticated($session)){
|
---|
640 | $error->set_error('invalid_session');
|
---|
641 | return $error->get_soap_array();
|
---|
642 | }
|
---|
643 | if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note_id]) || !isset($_SESSION['viewable'][$module_name][$module_id])){
|
---|
644 | $error->set_error('no_access');
|
---|
645 | return $error->get_soap_array();
|
---|
646 | }
|
---|
647 | if(empty($beanList[$module_name])){
|
---|
648 | $error->set_error('no_module');
|
---|
649 | return $error->get_soap_array();
|
---|
650 | }
|
---|
651 |
|
---|
652 | $class_name = $beanList[$module_name];
|
---|
653 | require_once($beanFiles[$class_name]);
|
---|
654 |
|
---|
655 | $seed = new $class_name();
|
---|
656 |
|
---|
657 |
|
---|
658 |
|
---|
659 | $seed->retrieve($module_id);
|
---|
660 | if($module_name == 'Cases' || $module_name == 'Bugs') {
|
---|
661 | $seed->note_id = $note_id;
|
---|
662 | $seed->save(false);
|
---|
663 | } else {
|
---|
664 | $error->set_error('no_module_support');
|
---|
665 | $error->description .= ': '. $module_name;
|
---|
666 | }
|
---|
667 | return $error->get_soap_array();
|
---|
668 |
|
---|
669 | }
|
---|
670 | $server->register(
|
---|
671 | 'portal_get_related_notes',
|
---|
672 | array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'order_by'=>'xsd:string'),
|
---|
673 | array('return'=>'tns:get_entry_result'),
|
---|
674 | $NAMESPACE);
|
---|
675 |
|
---|
676 | function portal_get_related_notes($session,$module_name, $module_id, $select_fields, $order_by){
|
---|
677 | global $beanList, $beanFiles;
|
---|
678 | $error = new SoapError();
|
---|
679 | if(! portal_validate_authenticated($session)){
|
---|
680 | $error->set_error('invalid_session');
|
---|
681 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
682 | }
|
---|
683 | if($_SESSION['type'] == 'lead' ){
|
---|
684 | $error->set_error('no_access');
|
---|
685 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
686 | }
|
---|
687 | if(empty($beanList[$module_name])){
|
---|
688 | $error->set_error('no_module');
|
---|
689 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
690 | }
|
---|
691 | if(empty($_SESSION['viewable'][$module_name][$module_id])){
|
---|
692 | $error->set_error('no_access');
|
---|
693 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
694 | }
|
---|
695 |
|
---|
696 | if($module_name =='Contacts'){
|
---|
697 | if($_SESSION['user_id'] != $module_id){
|
---|
698 | $error->set_error('no_access');
|
---|
699 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
700 | }
|
---|
701 | $list = get_notes_in_contacts("('$module_id')", $order_by);
|
---|
702 | }else{
|
---|
703 | $list = get_notes_in_module("('$module_id')", $module_name, $order_by);
|
---|
704 | }
|
---|
705 |
|
---|
706 |
|
---|
707 |
|
---|
708 | $output_list = Array();
|
---|
709 | $field_list = Array();
|
---|
710 | foreach($list as $value)
|
---|
711 | {
|
---|
712 | $output_list[] = get_return_value($value, 'Notes');
|
---|
713 | $_SESSION['viewable']['Notes'][$value->id] = $value->id;
|
---|
714 | if(empty($field_list)){
|
---|
715 | $field_list = get_field_list($value, true);
|
---|
716 | }
|
---|
717 | }
|
---|
718 | $output_list = filter_return_list($output_list, $select_fields, $module_name);
|
---|
719 | $field_list = filter_field_list($field_list,$select_fields, $module_name);
|
---|
720 |
|
---|
721 |
|
---|
722 | return array('result_count'=>sizeof($output_list), 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
|
---|
723 | }
|
---|
724 |
|
---|
725 | $server->register(
|
---|
726 | 'portal_get_related_list',
|
---|
727 | array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'rel_module'=>'xsd:string', 'module_id'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'order_by'=>'xsd:string', 'offset' => 'xsd:int', 'limit' => 'xsd:int'),
|
---|
728 | array('return'=>'tns:get_entry_result'),
|
---|
729 | $NAMESPACE);
|
---|
730 |
|
---|
731 | function portal_get_related_list($session, $module_name, $rel_module, $module_id, $select_fields, $order_by, $offset, $limit){
|
---|
732 | global $beanList, $beanFiles;
|
---|
733 | $error = new SoapError();
|
---|
734 | if(! portal_validate_authenticated($session)){
|
---|
735 | $error->set_error('invalid_session');
|
---|
736 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
737 | }
|
---|
738 | if($_SESSION['type'] == 'lead' ){
|
---|
739 | $error->set_error('no_access');
|
---|
740 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
741 | }
|
---|
742 | if(empty($beanList[$module_name])){
|
---|
743 | $error->set_error('no_module');
|
---|
744 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
745 | }
|
---|
746 | if(empty($_SESSION['viewable'][$module_name][$module_id])){
|
---|
747 | $error->set_error('no_access');
|
---|
748 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
749 | }
|
---|
750 |
|
---|
751 | $list = get_related_in_module("('$module_id')", $module_name, $rel_module, $order_by, $offset, $limit);
|
---|
752 |
|
---|
753 | $output_list = Array();
|
---|
754 | $field_list = Array();
|
---|
755 | foreach($list as $value)
|
---|
756 | {
|
---|
757 | $output_list[] = get_return_value($value, $rel_module);
|
---|
758 | $_SESSION['viewable'][$rel_module][$value->id] = $value->id;
|
---|
759 | if(empty($field_list)){
|
---|
760 | $field_list = get_field_list($value, true);
|
---|
761 | }
|
---|
762 | }
|
---|
763 | $output_list = filter_return_list($output_list, $select_fields, $module_name);
|
---|
764 | $field_list = filter_field_list($field_list,$select_fields, $module_name);
|
---|
765 |
|
---|
766 |
|
---|
767 | return array('result_count'=>$list['result_count'], 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
|
---|
768 | }
|
---|
769 |
|
---|
770 | $server->register(
|
---|
771 | 'portal_get_module_fields',
|
---|
772 | array('session'=>'xsd:string', 'module_name'=>'xsd:string'),
|
---|
773 | array('return'=>'tns:module_fields'),
|
---|
774 | $NAMESPACE);
|
---|
775 |
|
---|
776 | function portal_get_module_fields($session, $module_name){
|
---|
777 | global $beanList, $beanFiles, $portal_modules, $valid_modules_for_contact;
|
---|
778 | $error = new SoapError();
|
---|
779 | $module_fields = array();
|
---|
780 | if(! portal_validate_authenticated($session)){
|
---|
781 | $error->set_error('invalid_session');
|
---|
782 | $error->description .=$session;
|
---|
783 | return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
|
---|
784 | }
|
---|
785 | if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
|
---|
786 | $error->set_error('no_access');
|
---|
787 | return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
|
---|
788 | }
|
---|
789 |
|
---|
790 | if(empty($beanList[$module_name])){
|
---|
791 | $error->set_error('no_module');
|
---|
792 | return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
|
---|
793 | }
|
---|
794 |
|
---|
795 | if(($_SESSION['type'] == 'portal'||$_SESSION['type'] == 'contact') && !key_exists($module_name, $valid_modules_for_contact)){
|
---|
796 | $error->set_error('no_module');
|
---|
797 | return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
|
---|
798 | }
|
---|
799 |
|
---|
800 | $class_name = $beanList[$module_name];
|
---|
801 | require_once($beanFiles[$class_name]);
|
---|
802 | $seed = new $class_name();
|
---|
803 | $seed->fill_in_additional_detail_fields();
|
---|
804 | $returnFields = get_return_module_fields($seed, $module_name, $error->get_soap_array(), true);
|
---|
805 | if(is_subclass_of($seed, 'Person')) {
|
---|
806 | $returnFields['module_fields']['email1'] = array('name'=>'email1', 'type'=>'email', 'required'=>0, 'label'=>translate('LBL_EMAIL_ADDRESS', $seed->module_dir));
|
---|
807 | $returnFields['module_fields']['email_opt_out'] = array('name'=>'email_opt_out', 'type'=>'bool', 'required'=>0, 'label'=>translate('LBL_EMAIL_OPT_OUT', $seed->module_dir), 'options'=>array());
|
---|
808 | } //if
|
---|
809 |
|
---|
810 | return $returnFields;
|
---|
811 | }
|
---|
812 |
|
---|
813 | $server->register(
|
---|
814 | 'portal_get_subscription_lists',
|
---|
815 | array('session'=>'xsd:string'),
|
---|
816 | array('return'=>'tns:get_subscription_lists_result'),
|
---|
817 | $NAMESPACE);
|
---|
818 |
|
---|
819 | function portal_get_subscription_lists($session){
|
---|
820 | global $beanList, $beanFiles;
|
---|
821 |
|
---|
822 | $error = new SoapError();
|
---|
823 | if(! portal_validate_authenticated($session)){
|
---|
824 | $error->set_error('invalid_session');
|
---|
825 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
826 | }
|
---|
827 |
|
---|
828 | require_once('modules/Campaigns/utils.php');
|
---|
829 |
|
---|
830 | $contact = new Contact();
|
---|
831 |
|
---|
832 |
|
---|
833 |
|
---|
834 | $contact->retrieve($_SESSION['user_id']);
|
---|
835 |
|
---|
836 | if(!empty($contact->id)) {
|
---|
837 | $result = get_subscription_lists_keyed($contact, true);
|
---|
838 | }
|
---|
839 |
|
---|
840 |
|
---|
841 | $return_results = array('unsubscribed' => array(), 'subscribed' => array());
|
---|
842 |
|
---|
843 | foreach($result['unsubscribed'] as $newsletter_name => $data) {
|
---|
844 | $return_results['unsubscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
|
---|
845 | 'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
|
---|
846 | 'frequency' => $data['frequency']);
|
---|
847 | }
|
---|
848 | foreach($result['subscribed'] as $newsletter_name => $data) {
|
---|
849 | $return_results['subscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
|
---|
850 | 'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
|
---|
851 | 'frequency' => $data['frequency']);
|
---|
852 | }
|
---|
853 |
|
---|
854 | return array('unsubscribed'=>$return_results['unsubscribed'], 'subscribed' => $return_results['subscribed'], 'error'=>$error->get_soap_array());
|
---|
855 | }
|
---|
856 |
|
---|
857 | $server->register(
|
---|
858 | 'portal_set_newsletters',
|
---|
859 | array('session'=>'xsd:string', 'subscribe_ids' => 'tns:select_fields', 'unsubscribe_ids' => 'tns:select_fields'),
|
---|
860 | array('return'=>'tns:error_value'),
|
---|
861 | $NAMESPACE);
|
---|
862 |
|
---|
863 | function portal_set_newsletters($session, $subscribe_ids, $unsubscribe_ids){
|
---|
864 | global $beanList, $beanFiles;
|
---|
865 |
|
---|
866 | $error = new SoapError();
|
---|
867 | if(! portal_validate_authenticated($session)){
|
---|
868 | $error->set_error('invalid_session');
|
---|
869 | return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
|
---|
870 | }
|
---|
871 |
|
---|
872 | require_once('modules/Campaigns/utils.php');
|
---|
873 |
|
---|
874 | $contact = new Contact();
|
---|
875 |
|
---|
876 |
|
---|
877 |
|
---|
878 | $contact->retrieve($_SESSION['user_id']);
|
---|
879 |
|
---|
880 | if(!empty($contact->id)) {
|
---|
881 | foreach($subscribe_ids as $campaign_id) {
|
---|
882 | subscribe($campaign_id, null, $contact, true);
|
---|
883 | }
|
---|
884 | foreach($unsubscribe_ids as $campaign_id) {
|
---|
885 | unsubscribe($campaign_id, $contact);
|
---|
886 | }
|
---|
887 | }
|
---|
888 |
|
---|
889 | return $error->get_soap_array();
|
---|
890 | }
|
---|
891 |
|
---|
892 |
|
---|
893 |
|
---|
894 |
|
---|
895 |
|
---|
896 |
|
---|
897 |
|
---|
898 |
|
---|
899 |
|
---|
900 |
|
---|
901 |
|
---|
902 |
|
---|
903 |
|
---|
904 |
|
---|
905 |
|
---|
906 |
|
---|
907 |
|
---|
908 |
|
---|
909 |
|
---|
910 |
|
---|
911 |
|
---|
912 |
|
---|
913 |
|
---|
914 |
|
---|
915 |
|
---|
916 |
|
---|
917 |
|
---|
918 |
|
---|
919 |
|
---|
920 |
|
---|
921 |
|
---|
922 |
|
---|
923 |
|
---|
924 |
|
---|
925 |
|
---|
926 |
|
---|
927 |
|
---|
928 |
|
---|
929 |
|
---|
930 |
|
---|
931 |
|
---|
932 |
|
---|
933 |
|
---|
934 |
|
---|
935 |
|
---|
936 |
|
---|
937 |
|
---|
938 |
|
---|
939 |
|
---|
940 |
|
---|
941 |
|
---|
942 |
|
---|
943 |
|
---|
944 |
|
---|
945 |
|
---|
946 | ?>
|
---|