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-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('soap/SoapHelperFunctions.php');
40 require_once('soap/SoapTypes.php');
43 require_once('soap/SoapPortalHelper.php');
48 /*************************************************************************************
50 THIS IS FOR PORTAL USERS
53 *************************************************************************************/
55 this authenticates a user as a portal user and returns the session id or it returns false otherwise;
59 array('portal_auth'=>'tns:user_auth','user_name'=>'xsd:string', 'application_name'=>'xsd:string'),
60 array('return'=>'tns:set_entry_result'),
63 function portal_login($portal_auth, $user_name, $application_name){
64 $error = new SoapError();
65 $contact = new Contact();
66 $result = login_user($portal_auth);
68 if($result == 'fail' || $result == 'sessions_exceeded'){
69 if($result == 'sessions_exceeded') {
70 $error->set_error('sessions_exceeded');
73 $error->set_error('no_portal');
75 return array('id'=>-1, 'error'=>$error->get_soap_array());
79 if($user_name == 'lead'){
81 $_SESSION['is_valid_session']= true;
82 $_SESSION['ip_address'] = query_client_ip();
83 $_SESSION['portal_id'] = $current_user->id;
84 $_SESSION['type'] = 'lead';
86 return array('id'=>session_id(), 'error'=>$error->get_soap_array());
87 }else if($user_name == 'portal'){
89 $_SESSION['is_valid_session']= true;
90 $_SESSION['ip_address'] = query_client_ip();
91 $_SESSION['portal_id'] = $current_user->id;
92 $_SESSION['type'] = 'portal';
93 $GLOBALS['log']->debug("Saving new session");
95 return array('id'=>session_id(), 'error'=>$error->get_soap_array());
97 $contact = $contact->retrieve_by_string_fields(array('portal_name'=>$user_name, 'portal_active'=>'1', 'deleted'=>0) );
100 $_SESSION['is_valid_session']= true;
101 $_SESSION['ip_address'] = query_client_ip();
102 $_SESSION['user_id'] = $contact->id;
103 $_SESSION['portal_id'] = $current_user->id;
105 $_SESSION['type'] = 'contact';
106 $_SESSION['assigned_user_id'] = $contact->assigned_user_id;
108 build_relationship_tree($contact);
109 return array('id'=>session_id(), 'error'=>$error->get_soap_array());
112 $error->set_error('invalid_login');
113 return array('id'=>-1, 'error'=>$error->get_soap_array());
117 this validates the session and starts the session;
119 function portal_validate_authenticated($session_id){
120 $old_error_reporting = error_reporting(0);
121 session_id($session_id);
123 // This little construct checks to see if the session validated
124 if(session_start()) {
125 $valid_session = true;
127 if(!empty($_SESSION['is_valid_session']) && $_SESSION['ip_address'] == query_client_ip() && $valid_session != null && ($_SESSION['type'] == 'contact' || $_SESSION['type'] == 'lead' || $_SESSION['type'] == 'portal')){
128 global $current_user;
129 $current_user = new User();
130 $current_user->retrieve($_SESSION['portal_id']);
132 error_reporting($old_error_reporting);
137 $GLOBALS['log']->fatal('SECURITY: The session ID is invalid');
138 error_reporting($old_error_reporting);
145 array('session'=>'xsd:string'),
146 array('return'=>'tns:error_value'),
148 function portal_logout($session){
149 $error = new SoapError();
150 if(portal_validate_authenticated($session)){
152 return $error->get_soap_array();
154 $error->set_error('invalid_session');
155 return $error->get_soap_array();
159 'portal_get_sugar_id',
160 array('session'=>'xsd:string'),
161 array('return'=>'tns:set_entry_result'),
163 function portal_get_sugar_id($session){
164 $error = new SoapError();
165 if(portal_validate_authenticated($session)){
166 return array('id'=>$_SESSION['portal_id'], 'error'=>$error->get_soap_array());
168 $error->set_error('invalid_session');
169 return array('id'=>-1, 'error'=>$error->get_soap_array());
174 'portal_get_sugar_contact_id',
175 array('session'=>'xsd:string'),
176 array('return'=>'tns:set_entry_result'),
178 function portal_get_sugar_contact_id($session){
179 $error = new SoapError();
180 if(portal_validate_authenticated($session)){
181 return array('id'=>$_SESSION['user_id'], 'error'=>$error->get_soap_array());
183 $error->set_error('invalid_session');
184 return array('id'=>-1, 'error'=>$error->get_soap_array());
190 'portal_get_entry_list',
191 array('session'=>'xsd:string', 'module_name'=>'xsd:string','where'=>'xsd:string', 'order_by'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
192 array('return'=>'tns:get_entry_list_result'),
195 function portal_get_entry_list($session, $module_name,$where, $order_by, $select_fields){
196 return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, 0, "");
200 * Acts like a normal get_entry_list except it will build the where clause based on the name_value pairs passed
201 * Here we assume 'AND'
204 'portal_get_entry_list_filter',
205 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'),
206 array('return'=>'tns:get_entry_list_result'),
210 function portal_get_entry_list_filter($session, $module_name, $order_by, $select_fields, $row_offset, $limit, $filter){
211 global $beanList, $beanFiles, $portal_modules;
212 $error = new SoapError();
213 if(! portal_validate_authenticated($session)){
214 $error->set_error('invalid_session');
215 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
217 if($_SESSION['type'] == 'lead'){
218 $error->set_error('no_access');
219 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
221 if(empty($beanList[$module_name])){
222 $error->set_error('no_module');
223 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
226 //build the where clause
229 if($module_name == 'Cases'){
230 $sugar = new aCase();
231 }else if($module_name == 'Contacts'){
232 $sugar = new Contact();
233 }else if($module_name == 'Accounts'){
234 $sugar = new Account();
235 } else if($module_name == 'Bugs'){
237 } else if($module_name == 'KBDocuments' || $module_name == 'FAQ') {
238 $sugar = new KBDocument();
240 $error->set_error('no_module_support');
241 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
245 if(isset($filter) && is_array($filter)){
247 foreach($filter as $nvOp){
248 $name = $nvOp['name'];
249 $value = $nvOp['value'];
250 $value_array = $nvOp['value_array'];
251 $operator = $nvOp['operator'];
252 //do nothing if all three values are not set
253 if(isset($name) && (isset($value) || isset($value_array)) && isset($operator)){
257 if(isset($sugar->field_defs[$name])){
258 // MFH - Added Support For Custom Fields in Searches
259 $cstm = isset($sugar->field_defs[$name]['source']) && $sugar->field_defs[$name]['source'] == 'custom_fields' ? '_cstm' : '';
261 $where .= "$sugar->table_name$cstm.$name $operator ";
262 if($sugar->field_defs['name']['type'] == 'datetime'){
263 $where .= db_convert("'$value'", 'datetime');
267 foreach($value_array as $v) {
268 $tmp[] = $GLOBALS['db']->quote($v);
270 $where .= "('" . implode("', '", $tmp) . "')";
272 $where .= "'".$GLOBALS['db']->quote($value)."'";
279 return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit);
281 $error->set_error('no_module_support');
282 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
289 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'id'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
290 array('return'=>'tns:get_entry_result'),
293 function portal_get_entry($session, $module_name, $id,$select_fields ){
294 global $beanList, $beanFiles;
295 $error = new SoapError();
297 if(!portal_validate_authenticated($session)){
298 $error->set_error('invalid_session');
299 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
302 //set the working module
303 set_module_in(array('list'=>array($id=>$id), 'in'=>'('.$id.')'), $module_name);
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());
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());
314 if(empty($_SESSION['viewable'][$module_name][$id])){
315 $error->set_error('no_access');
316 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
319 $class_name = $beanList[$module_name];
320 require_once($beanFiles[$class_name]);
321 $seed = new $class_name();
322 $seed->retrieve($id);
323 if($module_name == 'KBDocuments') {
324 $body = $seed->get_kbdoc_body($id);
325 $seed->description = $body;
328 $output_list = Array();
329 $output_list[] = get_return_value($seed, $module_name);
331 //$output_list[0]['name_value_list']['description'] = array('name'=>'description', 'value'=>$seed->description);
332 //$output_list = filter_return_list($output_list, $select_fields, $module_name);
333 $field_list = array();
334 if(empty($field_list)){
335 $field_list = get_field_list($seed, true);
337 $output_list = filter_return_list($output_list, $select_fields, $module_name);
338 $field_list = filter_field_list($field_list,$select_fields, $module_name);
340 return array('field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
346 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'name_value_list'=>'tns:name_value_list'),
347 array('return'=>'tns:set_entry_result'),
350 function portal_set_entry($session,$module_name, $name_value_list){
351 global $beanList, $beanFiles, $valid_modules_for_contact;
353 $error = new SoapError();
354 if(!portal_validate_authenticated($session)){
355 $error->set_error('invalid_session');
356 return array('id'=>-1, 'error'=>$error->get_soap_array());
358 if(empty($beanList[$module_name])){
359 $error->set_error('no_module');
360 return array('id'=>-1, 'error'=>$error->get_soap_array());
362 if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
363 $error->set_error('no_access');
364 return array('id'=>-1, 'error'=>$error->get_soap_array());
367 if($_SESSION['type'] == 'contact' && !key_exists($module_name, $valid_modules_for_contact) ){
368 $error->set_error('no_access');
369 return array('id'=>-1, 'error'=>$error->get_soap_array());
373 $class_name = $beanList[$module_name];
374 require_once($beanFiles[$class_name]);
375 $seed = new $class_name();
377 $values_set = array();
379 foreach($name_value_list as $value){
380 if($value['name'] == 'id' && !empty($value['value'])) {
381 $seed->disable_row_level_security = true;
382 $seed->retrieve($value['value']);
386 $values_set[$value['name']] = $value['value'];
387 $seed->$value['name'] = $value['value'];
390 // If it was an update, we have to set the values again
392 foreach($name_value_list as $value){
393 $seed->$value['name'] = $value['value'];
397 if(!isset($_SESSION['viewable'][$module_name])){
398 $_SESSION['viewable'][$module_name] = array();
402 if(isset($_SESSION['assigned_user_id']) && (!key_exists('assigned_user_id', $values_set) || empty($values_set['assigned_user_id']))){
403 $seed->assigned_user_id = $_SESSION['assigned_user_id'];
405 if(isset($_SESSION['account_id']) && (!key_exists('account_id', $values_set) || empty($values_set['account_id']))){
406 $seed->account_id = $_SESSION['account_id'];
408 $seed->portal_flag = 1;
409 $seed->portal_viewable = true;
412 set_module_in(array('in'=>"('$id')", 'list'=>array($id)), $module_name);
413 if($_SESSION['type'] == 'contact' && $module_name != 'Contacts' && !$is_update){
414 if($module_name == 'Notes'){
415 $seed->contact_id = $_SESSION['user_id'];
416 if(isset( $_SESSION['account_id'])){
417 $seed->parent_type = 'Accounts';
418 $seed->parent_id = $_SESSION['account_id'];
423 $seed->contact_id = $_SESSION['user_id'];
425 if(isset( $_SESSION['account_id'])){
426 $seed->account_id = $_SESSION['account_id'];
429 $seed->save_relationship_changes(false);
432 return array('id'=>$id, 'error'=>$error->get_soap_array());
443 'portal_set_note_attachment',
444 array('session'=>'xsd:string','note'=>'tns:note_attachment'),
445 array('return'=>'tns:set_entry_result'),
448 function portal_set_note_attachment($session,$note)
450 $error = new SoapError();
451 if(!portal_validate_authenticated($session)){
452 $error->set_error('invalid_session');
453 return array('id'=>'-1', 'error'=>$error->get_soap_array());
455 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note['id']])){
456 $error->set_error('no_access');
457 return array('id'=>-1, 'error'=>$error->get_soap_array());
459 require_once('modules/Notes/NoteSoap.php');
460 $ns = new NoteSoap();
461 $id = $ns->saveFile($note, true);
462 return array('id'=>$id, 'error'=>$error->get_soap_array());
467 'portal_remove_note_attachment',
468 array('session'=>'xsd:string', 'id'=>'xsd:string'),
469 array('return'=>'tns:error_value'),
472 function portal_remove_note_attachment($session, $id)
474 $error = new SoapError();
475 if(! portal_validate_authenticated($session)){
476 $error->set_error('invalid_session');
477 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
479 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
480 $error->set_error('no_access');
481 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
485 $focus->retrieve($id);
486 $result = $focus->deleteAttachment();
488 return $error->get_soap_array();
492 'portal_get_note_attachment',
493 array('session'=>'xsd:string', 'id'=>'xsd:string'),
494 array('return'=>'tns:return_note_attachment'),
497 function portal_get_note_attachment($session,$id)
500 $error = new SoapError();
501 if(! portal_validate_authenticated($session)){
502 $error->set_error('invalid_session');
503 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
505 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
506 $error->set_error('no_access');
507 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
509 $current_user = $seed_user;
512 $note->retrieve($id);
513 require_once('modules/Notes/NoteSoap.php');
514 $ns = new NoteSoap();
515 if(!isset($note->filename)){
516 $note->filename = '';
518 $file= $ns->retrieveFile($id,$note->filename);
520 $error->set_error('no_file');
524 return array('note_attachment'=>array('id'=>$id, 'filename'=>$note->filename, 'file'=>$file), 'error'=>$error->get_soap_array());
528 'portal_relate_note_to_module',
529 array('session'=>'xsd:string', 'note_id'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string'),
530 array('return'=>'tns:error_value'),
533 function portal_relate_note_to_module($session,$note_id, $module_name, $module_id){
534 global $beanList, $beanFiles, $current_user;
535 $error = new SoapError();
536 if(! portal_validate_authenticated($session)){
537 $error->set_error('invalid_session');
538 return $error->get_soap_array();
540 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note_id]) || !isset($_SESSION['viewable'][$module_name][$module_id])){
541 $error->set_error('no_access');
542 return $error->get_soap_array();
544 if(empty($beanList[$module_name])){
545 $error->set_error('no_module');
546 return $error->get_soap_array();
549 $class_name = $beanList[$module_name];
550 require_once($beanFiles[$class_name]);
552 $seed = new $class_name();
553 $seed->retrieve($module_id);
554 if($module_name == 'Cases' || $module_name == 'Bugs') {
555 $seed->note_id = $note_id;
558 $error->set_error('no_module_support');
559 $error->description .= ': '. $module_name;
561 return $error->get_soap_array();
565 'portal_get_related_notes',
566 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'order_by'=>'xsd:string'),
567 array('return'=>'tns:get_entry_result'),
570 function portal_get_related_notes($session,$module_name, $module_id, $select_fields, $order_by){
571 global $beanList, $beanFiles;
572 $error = new SoapError();
573 if(! portal_validate_authenticated($session)){
574 $error->set_error('invalid_session');
575 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
577 if($_SESSION['type'] == 'lead' ){
578 $error->set_error('no_access');
579 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
581 if(empty($beanList[$module_name])){
582 $error->set_error('no_module');
583 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
585 if(empty($_SESSION['viewable'][$module_name][$module_id])){
586 $error->set_error('no_access');
587 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
590 if($module_name =='Contacts'){
591 if($_SESSION['user_id'] != $module_id){
592 $error->set_error('no_access');
593 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
595 $list = get_notes_in_contacts("('$module_id')", $order_by);
597 $list = get_notes_in_module("('$module_id')", $module_name, $order_by);
602 $output_list = Array();
603 $field_list = Array();
604 foreach($list as $value)
606 $output_list[] = get_return_value($value, 'Notes');
607 $_SESSION['viewable']['Notes'][$value->id] = $value->id;
608 if(empty($field_list)){
609 $field_list = get_field_list($value, true);
612 $output_list = filter_return_list($output_list, $select_fields, $module_name);
613 $field_list = filter_field_list($field_list,$select_fields, $module_name);
616 return array('result_count'=>sizeof($output_list), 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
620 'portal_get_related_list',
621 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'),
622 array('return'=>'tns:get_entry_result'),
625 function portal_get_related_list($session, $module_name, $rel_module, $module_id, $select_fields, $order_by, $offset, $limit){
626 global $beanList, $beanFiles;
627 $error = new SoapError();
628 if(! portal_validate_authenticated($session)){
629 $error->set_error('invalid_session');
630 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
632 if($_SESSION['type'] == 'lead' ){
633 $error->set_error('no_access');
634 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
636 if(empty($beanList[$module_name])){
637 $error->set_error('no_module');
638 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
640 if(empty($_SESSION['viewable'][$module_name][$module_id])){
641 $error->set_error('no_access');
642 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
645 $list = get_related_in_module("('$module_id')", $module_name, $rel_module, $order_by, $offset, $limit);
647 $output_list = Array();
648 $field_list = Array();
649 foreach($list as $value)
651 $output_list[] = get_return_value($value, $rel_module);
652 $_SESSION['viewable'][$rel_module][$value->id] = $value->id;
653 if(empty($field_list)){
654 $field_list = get_field_list($value, true);
657 $output_list = filter_return_list($output_list, $select_fields, $module_name);
658 $field_list = filter_field_list($field_list,$select_fields, $module_name);
661 return array('result_count'=>$list['result_count'], 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
665 'portal_get_module_fields',
666 array('session'=>'xsd:string', 'module_name'=>'xsd:string'),
667 array('return'=>'tns:module_fields'),
670 function portal_get_module_fields($session, $module_name){
671 global $beanList, $beanFiles, $portal_modules, $valid_modules_for_contact;
672 $error = new SoapError();
673 $module_fields = array();
674 if(! portal_validate_authenticated($session)){
675 $error->set_error('invalid_session');
676 $error->description .=$session;
677 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
679 if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
680 $error->set_error('no_access');
681 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
684 if(empty($beanList[$module_name])){
685 $error->set_error('no_module');
686 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
689 if(($_SESSION['type'] == 'portal'||$_SESSION['type'] == 'contact') && !key_exists($module_name, $valid_modules_for_contact)){
690 $error->set_error('no_module');
691 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
694 $class_name = $beanList[$module_name];
695 require_once($beanFiles[$class_name]);
696 $seed = new $class_name();
697 $seed->fill_in_additional_detail_fields();
698 $returnFields = get_return_module_fields($seed, $module_name, $error->get_soap_array(), true);
699 if(is_subclass_of($seed, 'Person')) {
700 $returnFields['module_fields']['email1'] = array('name'=>'email1', 'type'=>'email', 'required'=>0, 'label'=>translate('LBL_EMAIL_ADDRESS', $seed->module_dir));
701 $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());
704 return $returnFields;
707 'portal_get_subscription_lists',
708 array('session'=>'xsd:string'),
709 array('return'=>'tns:get_subscription_lists_result'),
712 function portal_get_subscription_lists($session){
713 global $beanList, $beanFiles;
715 $error = new SoapError();
716 if(! portal_validate_authenticated($session)){
717 $error->set_error('invalid_session');
718 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
721 require_once('modules/Campaigns/utils.php');
723 $contact = new Contact();
724 $contact->retrieve($_SESSION['user_id']);
726 if(!empty($contact->id)) {
727 $result = get_subscription_lists_keyed($contact, true);
731 $return_results = array('unsubscribed' => array(), 'subscribed' => array());
733 foreach($result['unsubscribed'] as $newsletter_name => $data) {
734 $return_results['unsubscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
735 'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
736 'frequency' => $data['frequency']);
738 foreach($result['subscribed'] as $newsletter_name => $data) {
739 $return_results['subscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
740 'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
741 'frequency' => $data['frequency']);
744 return array('unsubscribed'=>$return_results['unsubscribed'], 'subscribed' => $return_results['subscribed'], 'error'=>$error->get_soap_array());
748 'portal_set_newsletters',
749 array('session'=>'xsd:string', 'subscribe_ids' => 'tns:select_fields', 'unsubscribe_ids' => 'tns:select_fields'),
750 array('return'=>'tns:error_value'),
753 function portal_set_newsletters($session, $subscribe_ids, $unsubscribe_ids){
754 global $beanList, $beanFiles;
756 $error = new SoapError();
757 if(! portal_validate_authenticated($session)){
758 $error->set_error('invalid_session');
759 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
762 require_once('modules/Campaigns/utils.php');
764 $contact = new Contact();
765 $contact->retrieve($_SESSION['user_id']);
767 if(!empty($contact->id)) {
768 foreach($subscribe_ids as $campaign_id) {
769 subscribe($campaign_id, null, $contact, true);
771 foreach($unsubscribe_ids as $campaign_id) {
772 unsubscribe($campaign_id, $contact);
776 return $error->get_soap_array();