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-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;
126 if(!empty($_SESSION['is_valid_session']) && $_SESSION['ip_address'] == query_client_ip() && $valid_session != null && ($_SESSION['type'] == 'contact' || $_SESSION['type'] == 'lead' || $_SESSION['type'] == 'portal')){
127 global $current_user;
128 $current_user = new User();
129 $current_user->retrieve($_SESSION['portal_id']);
131 error_reporting($old_error_reporting);
136 $GLOBALS['log']->fatal('SECURITY: The session ID is invalid');
137 error_reporting($old_error_reporting);
144 array('session'=>'xsd:string'),
145 array('return'=>'tns:error_value'),
147 function portal_logout($session){
148 $error = new SoapError();
149 if(portal_validate_authenticated($session)){
151 return $error->get_soap_array();
153 $error->set_error('invalid_session');
154 return $error->get_soap_array();
158 'portal_get_sugar_id',
159 array('session'=>'xsd:string'),
160 array('return'=>'tns:set_entry_result'),
162 function portal_get_sugar_id($session){
163 $error = new SoapError();
164 if(portal_validate_authenticated($session)){
165 return array('id'=>$_SESSION['portal_id'], 'error'=>$error->get_soap_array());
167 $error->set_error('invalid_session');
168 return array('id'=>-1, 'error'=>$error->get_soap_array());
173 'portal_get_sugar_contact_id',
174 array('session'=>'xsd:string'),
175 array('return'=>'tns:set_entry_result'),
177 function portal_get_sugar_contact_id($session){
178 $error = new SoapError();
179 if(portal_validate_authenticated($session)){
180 return array('id'=>$_SESSION['user_id'], 'error'=>$error->get_soap_array());
182 $error->set_error('invalid_session');
183 return array('id'=>-1, 'error'=>$error->get_soap_array());
189 'portal_get_entry_list',
190 array('session'=>'xsd:string', 'module_name'=>'xsd:string','where'=>'xsd:string', 'order_by'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
191 array('return'=>'tns:get_entry_list_result'),
194 function portal_get_entry_list($session, $module_name,$where, $order_by, $select_fields){
195 return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, 0, "");
199 * Acts like a normal get_entry_list except it will build the where clause based on the name_value pairs passed
200 * Here we assume 'AND'
203 'portal_get_entry_list_filter',
204 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'),
205 array('return'=>'tns:get_entry_list_result'),
209 function portal_get_entry_list_filter($session, $module_name, $order_by, $select_fields, $row_offset, $limit, $filter){
210 global $beanList, $beanFiles, $portal_modules;
211 $error = new SoapError();
212 if(! portal_validate_authenticated($session)){
213 $error->set_error('invalid_session');
214 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
216 if($_SESSION['type'] == 'lead'){
217 $error->set_error('no_access');
218 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
220 if(empty($beanList[$module_name])){
221 $error->set_error('no_module');
222 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
225 //build the where clause
228 if($module_name == 'Cases'){
229 $sugar = new aCase();
230 }else if($module_name == 'Contacts'){
231 $sugar = new Contact();
232 }else if($module_name == 'Accounts'){
233 $sugar = new Account();
234 } else if($module_name == 'Bugs'){
236 } else if($module_name == 'KBDocuments' || $module_name == 'FAQ') {
237 $sugar = new KBDocument();
239 $error->set_error('no_module_support');
240 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
244 if(isset($filter) && is_array($filter)){
246 foreach($filter as $nvOp){
247 $name = $nvOp['name'];
248 $value = $nvOp['value'];
249 $value_array = $nvOp['value_array'];
250 $operator = $nvOp['operator'];
251 //do nothing if all three values are not set
252 if(isset($name) && (isset($value) || isset($value_array)) && isset($operator)){
256 if(isset($sugar->field_defs[$name])){
257 // MFH - Added Support For Custom Fields in Searches
258 $cstm = isset($sugar->field_defs[$name]['source']) && $sugar->field_defs[$name]['source'] == 'custom_fields' ? '_cstm' : '';
260 $where .= "$sugar->table_name$cstm.$name $operator ";
261 if($sugar->field_defs['name']['type'] == 'datetime'){
262 $where .= db_convert("'$value'", 'datetime');
266 foreach($value_array as $v) {
267 $tmp[] = $GLOBALS['db']->quote($v);
269 $where .= "('" . implode("', '", $tmp) . "')";
271 $where .= "'".$GLOBALS['db']->quote($value)."'";
278 return portal_get_entry_list_limited($session, $module_name, $where, $order_by, $select_fields, $row_offset, $limit);
280 $error->set_error('no_module_support');
281 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
288 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'id'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
289 array('return'=>'tns:get_entry_result'),
292 function portal_get_entry($session, $module_name, $id,$select_fields ){
293 global $beanList, $beanFiles;
294 $error = new SoapError();
296 if(!portal_validate_authenticated($session)){
297 $error->set_error('invalid_session');
298 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
301 //set the working module
302 set_module_in(array('list'=>array($id=>$id), 'in'=>'('.$id.')'), $module_name);
304 if($_SESSION['type'] == 'lead'){
305 $error->set_error('no_access');
306 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
308 if(empty($beanList[$module_name])){
309 $error->set_error('no_module');
310 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
313 if(empty($_SESSION['viewable'][$module_name][$id])){
314 $error->set_error('no_access');
315 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
318 $class_name = $beanList[$module_name];
319 require_once($beanFiles[$class_name]);
320 $seed = new $class_name();
321 $seed->retrieve($id);
322 if($module_name == 'KBDocuments') {
323 $body = $seed->get_kbdoc_body($id);
324 $seed->description = $body;
327 $output_list = Array();
328 $output_list[] = get_return_value($seed, $module_name);
330 //$output_list[0]['name_value_list']['description'] = array('name'=>'description', 'value'=>$seed->description);
331 //$output_list = filter_return_list($output_list, $select_fields, $module_name);
332 $field_list = array();
333 if(empty($field_list)){
334 $field_list = get_field_list($seed, true);
336 $output_list = filter_return_list($output_list, $select_fields, $module_name);
337 $field_list = filter_field_list($field_list,$select_fields, $module_name);
339 return array('field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
345 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'name_value_list'=>'tns:name_value_list'),
346 array('return'=>'tns:set_entry_result'),
349 function portal_set_entry($session,$module_name, $name_value_list){
350 global $beanList, $beanFiles, $valid_modules_for_contact;
352 $error = new SoapError();
353 if(!portal_validate_authenticated($session)){
354 $error->set_error('invalid_session');
355 return array('id'=>-1, 'error'=>$error->get_soap_array());
357 if(empty($beanList[$module_name])){
358 $error->set_error('no_module');
359 return array('id'=>-1, 'error'=>$error->get_soap_array());
361 if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
362 $error->set_error('no_access');
363 return array('id'=>-1, 'error'=>$error->get_soap_array());
366 if($_SESSION['type'] == 'contact' && !key_exists($module_name, $valid_modules_for_contact) ){
367 $error->set_error('no_access');
368 return array('id'=>-1, 'error'=>$error->get_soap_array());
372 $class_name = $beanList[$module_name];
373 require_once($beanFiles[$class_name]);
374 $seed = new $class_name();
376 $values_set = array();
378 foreach($name_value_list as $value){
379 if($value['name'] == 'id' && !empty($value['value'])) {
380 $seed->disable_row_level_security = true;
381 $seed->retrieve($value['value']);
385 $values_set[$value['name']] = $value['value'];
386 $seed->$value['name'] = $value['value'];
389 // If it was an update, we have to set the values again
391 foreach($name_value_list as $value){
392 $seed->$value['name'] = $value['value'];
396 if(!isset($_SESSION['viewable'][$module_name])){
397 $_SESSION['viewable'][$module_name] = array();
401 if(isset($_SESSION['assigned_user_id']) && (!key_exists('assigned_user_id', $values_set) || empty($values_set['assigned_user_id']))){
402 $seed->assigned_user_id = $_SESSION['assigned_user_id'];
404 if(isset($_SESSION['account_id']) && (!key_exists('account_id', $values_set) || empty($values_set['account_id']))){
405 $seed->account_id = $_SESSION['account_id'];
407 $seed->portal_flag = 1;
408 $seed->portal_viewable = true;
411 set_module_in(array('in'=>"('$id')", 'list'=>array($id)), $module_name);
412 if($_SESSION['type'] == 'contact' && $module_name != 'Contacts' && !$is_update){
413 if($module_name == 'Notes'){
414 $seed->contact_id = $_SESSION['user_id'];
415 if(isset( $_SESSION['account_id'])){
416 $seed->parent_type = 'Accounts';
417 $seed->parent_id = $_SESSION['account_id'];
422 $seed->contact_id = $_SESSION['user_id'];
424 if(isset( $_SESSION['account_id'])){
425 $seed->account_id = $_SESSION['account_id'];
428 $seed->save_relationship_changes(false);
431 return array('id'=>$id, 'error'=>$error->get_soap_array());
442 'portal_set_note_attachment',
443 array('session'=>'xsd:string','note'=>'tns:note_attachment'),
444 array('return'=>'tns:set_entry_result'),
447 function portal_set_note_attachment($session,$note)
449 $error = new SoapError();
450 if(!portal_validate_authenticated($session)){
451 $error->set_error('invalid_session');
452 return array('id'=>'-1', 'error'=>$error->get_soap_array());
454 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note['id']])){
455 $error->set_error('no_access');
456 return array('id'=>-1, 'error'=>$error->get_soap_array());
458 require_once('modules/Notes/NoteSoap.php');
459 $ns = new NoteSoap();
460 $id = $ns->saveFile($note, true);
461 return array('id'=>$id, 'error'=>$error->get_soap_array());
466 'portal_remove_note_attachment',
467 array('session'=>'xsd:string', 'id'=>'xsd:string'),
468 array('return'=>'tns:error_value'),
471 function portal_remove_note_attachment($session, $id)
473 $error = new SoapError();
474 if(! portal_validate_authenticated($session)){
475 $error->set_error('invalid_session');
476 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
478 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
479 $error->set_error('no_access');
480 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
484 $focus->retrieve($id);
485 $result = $focus->deleteAttachment();
487 return $error->get_soap_array();
491 'portal_get_note_attachment',
492 array('session'=>'xsd:string', 'id'=>'xsd:string'),
493 array('return'=>'tns:return_note_attachment'),
496 function portal_get_note_attachment($session,$id)
499 $error = new SoapError();
500 if(! portal_validate_authenticated($session)){
501 $error->set_error('invalid_session');
502 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
504 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$id])){
505 $error->set_error('no_access');
506 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
508 $current_user = $seed_user;
511 $note->retrieve($id);
512 require_once('modules/Notes/NoteSoap.php');
513 $ns = new NoteSoap();
514 if(!isset($note->filename)){
515 $note->filename = '';
517 $file= $ns->retrieveFile($id,$note->filename);
519 $error->set_error('no_file');
523 return array('note_attachment'=>array('id'=>$id, 'filename'=>$note->filename, 'file'=>$file), 'error'=>$error->get_soap_array());
527 'portal_relate_note_to_module',
528 array('session'=>'xsd:string', 'note_id'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string'),
529 array('return'=>'tns:error_value'),
532 function portal_relate_note_to_module($session,$note_id, $module_name, $module_id){
533 global $beanList, $beanFiles, $current_user;
534 $error = new SoapError();
535 if(! portal_validate_authenticated($session)){
536 $error->set_error('invalid_session');
537 return $error->get_soap_array();
539 if($_SESSION['type'] == 'lead' || !isset($_SESSION['viewable']['Notes'][$note_id]) || !isset($_SESSION['viewable'][$module_name][$module_id])){
540 $error->set_error('no_access');
541 return $error->get_soap_array();
543 if(empty($beanList[$module_name])){
544 $error->set_error('no_module');
545 return $error->get_soap_array();
548 $class_name = $beanList[$module_name];
549 require_once($beanFiles[$class_name]);
551 $seed = new $class_name();
552 $seed->retrieve($module_id);
553 if($module_name == 'Cases' || $module_name == 'Bugs') {
554 $seed->note_id = $note_id;
557 $error->set_error('no_module_support');
558 $error->description .= ': '. $module_name;
560 return $error->get_soap_array();
564 'portal_get_related_notes',
565 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string', 'select_fields'=>'tns:select_fields', 'order_by'=>'xsd:string'),
566 array('return'=>'tns:get_entry_result'),
569 function portal_get_related_notes($session,$module_name, $module_id, $select_fields, $order_by){
570 global $beanList, $beanFiles;
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());
576 if($_SESSION['type'] == 'lead' ){
577 $error->set_error('no_access');
578 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
580 if(empty($beanList[$module_name])){
581 $error->set_error('no_module');
582 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
584 if(empty($_SESSION['viewable'][$module_name][$module_id])){
585 $error->set_error('no_access');
586 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
589 if($module_name =='Contacts'){
590 if($_SESSION['user_id'] != $module_id){
591 $error->set_error('no_access');
592 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
594 $list = get_notes_in_contacts("('$module_id')", $order_by);
596 $list = get_notes_in_module("('$module_id')", $module_name, $order_by);
601 $output_list = Array();
602 $field_list = Array();
603 foreach($list as $value)
605 $output_list[] = get_return_value($value, 'Notes');
606 $_SESSION['viewable']['Notes'][$value->id] = $value->id;
607 if(empty($field_list)){
608 $field_list = get_field_list($value, true);
611 $output_list = filter_return_list($output_list, $select_fields, $module_name);
612 $field_list = filter_field_list($field_list,$select_fields, $module_name);
615 return array('result_count'=>sizeof($output_list), 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
619 'portal_get_related_list',
620 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'),
621 array('return'=>'tns:get_entry_result'),
624 function portal_get_related_list($session, $module_name, $rel_module, $module_id, $select_fields, $order_by, $offset, $limit){
625 global $beanList, $beanFiles;
626 $error = new SoapError();
627 if(! portal_validate_authenticated($session)){
628 $error->set_error('invalid_session');
629 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
631 if($_SESSION['type'] == 'lead' ){
632 $error->set_error('no_access');
633 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
635 if(empty($beanList[$module_name])){
636 $error->set_error('no_module');
637 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
639 if(empty($_SESSION['viewable'][$module_name][$module_id])){
640 $error->set_error('no_access');
641 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
644 $list = get_related_in_module("('$module_id')", $module_name, $rel_module, $order_by, $offset, $limit);
646 $output_list = Array();
647 $field_list = Array();
648 foreach($list as $value)
650 $output_list[] = get_return_value($value, $rel_module);
651 $_SESSION['viewable'][$rel_module][$value->id] = $value->id;
652 if(empty($field_list)){
653 $field_list = get_field_list($value, true);
656 $output_list = filter_return_list($output_list, $select_fields, $module_name);
657 $field_list = filter_field_list($field_list,$select_fields, $module_name);
660 return array('result_count'=>$list['result_count'], 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
664 'portal_get_module_fields',
665 array('session'=>'xsd:string', 'module_name'=>'xsd:string'),
666 array('return'=>'tns:module_fields'),
669 function portal_get_module_fields($session, $module_name){
670 global $beanList, $beanFiles, $portal_modules, $valid_modules_for_contact;
671 $error = new SoapError();
672 $module_fields = array();
673 if(! portal_validate_authenticated($session)){
674 $error->set_error('invalid_session');
675 $error->description .=$session;
676 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
678 if($_SESSION['type'] == 'lead' && $module_name != 'Leads'){
679 $error->set_error('no_access');
680 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
683 if(empty($beanList[$module_name])){
684 $error->set_error('no_module');
685 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
688 if(($_SESSION['type'] == 'portal'||$_SESSION['type'] == 'contact') && !key_exists($module_name, $valid_modules_for_contact)){
689 $error->set_error('no_module');
690 return array('module_name'=>$module_name, 'module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
693 $class_name = $beanList[$module_name];
694 require_once($beanFiles[$class_name]);
695 $seed = new $class_name();
696 $seed->fill_in_additional_detail_fields();
697 $returnFields = get_return_module_fields($seed, $module_name, $error->get_soap_array(), true);
698 if(is_subclass_of($seed, 'Person')) {
699 $returnFields['module_fields']['email1'] = array('name'=>'email1', 'type'=>'email', 'required'=>0, 'label'=>translate('LBL_EMAIL_ADDRESS', $seed->module_dir));
700 $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());
703 return $returnFields;
706 'portal_get_subscription_lists',
707 array('session'=>'xsd:string'),
708 array('return'=>'tns:get_subscription_lists_result'),
711 function portal_get_subscription_lists($session){
712 global $beanList, $beanFiles;
714 $error = new SoapError();
715 if(! portal_validate_authenticated($session)){
716 $error->set_error('invalid_session');
717 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
720 require_once('modules/Campaigns/utils.php');
722 $contact = new Contact();
723 $contact->retrieve($_SESSION['user_id']);
725 if(!empty($contact->id)) {
726 $result = get_subscription_lists_keyed($contact, true);
730 $return_results = array('unsubscribed' => array(), 'subscribed' => array());
732 foreach($result['unsubscribed'] as $newsletter_name => $data) {
733 $return_results['unsubscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
734 'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
735 'frequency' => $data['frequency']);
737 foreach($result['subscribed'] as $newsletter_name => $data) {
738 $return_results['subscribed'][] = array('name' => $newsletter_name, 'prospect_list_id' => $data['prospect_list_id'],
739 'campaign_id' => $data['campaign_id'], 'description' => $data['description'],
740 'frequency' => $data['frequency']);
743 return array('unsubscribed'=>$return_results['unsubscribed'], 'subscribed' => $return_results['subscribed'], 'error'=>$error->get_soap_array());
747 'portal_set_newsletters',
748 array('session'=>'xsd:string', 'subscribe_ids' => 'tns:select_fields', 'unsubscribe_ids' => 'tns:select_fields'),
749 array('return'=>'tns:error_value'),
752 function portal_set_newsletters($session, $subscribe_ids, $unsubscribe_ids){
753 global $beanList, $beanFiles;
755 $error = new SoapError();
756 if(! portal_validate_authenticated($session)){
757 $error->set_error('invalid_session');
758 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
761 require_once('modules/Campaigns/utils.php');
763 $contact = new Contact();
764 $contact->retrieve($_SESSION['user_id']);
766 if(!empty($contact->id)) {
767 foreach($subscribe_ids as $campaign_id) {
768 subscribe($campaign_id, null, $contact, true);
770 foreach($unsubscribe_ids as $campaign_id) {
771 unsubscribe($campaign_id, $contact);
775 return $error->get_soap_array();