2 if(!defined('sugarEntry'))define('sugarEntry', true);
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 ********************************************************************************/
40 * This class is an implemenatation class for all the rest services
42 require_once('service/core/SugarWebServiceImpl.php');
43 require_once('SugarWebServiceUtilv3.php');
46 class SugarWebServiceImplv3 extends SugarWebServiceImpl {
48 public function __construct()
50 self::$helperObject = new SugarWebServiceUtilv3();
55 * Log the user into the application
57 * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
58 * in the right encoding for the type of authentication the user is setup for. For Base
59 * sugar validation, password is the MD5 sum of the plain text password.
60 * @param String $application -- The name of the application you are logging in from. (Currently unused).
61 * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
62 * @return Array - id - String id is the session_id of the session that was created.
63 * - module_name - String - module name of user
64 * - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name,
65 * - user_default_team_id, user_is_admin, user_default_dateformat, user_default_timeformat
66 * @exception 'SoapFault' -- The SOAP error, if any
68 public function login($user_auth, $application, $name_value_list){
69 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
70 global $sugar_config, $system_config;
71 $error = new SoapError();
74 if(!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN')
76 $user_auth['password'] = md5($user_auth['password']);
79 $system_config = new Administration();
80 $system_config->retrieveSettings('system');
81 $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
83 $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
84 $usr_id=$user->retrieve_user_id($user_auth['user_name']);
86 $user->retrieve($usr_id);
90 if ($_SESSION['hasExpiredPassword'] =='1')
92 $error->set_error('password_expired');
93 $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
94 LogicHook::initialize();
95 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
96 self::$helperObject->setFaultObject($error);
99 if(!empty($user) && !empty($user->id) && !$user->is_group)
102 global $current_user;
103 $current_user = $user;
106 else if($usr_id && isset($user->user_name) && ($user->getPreference('lockout') == '1'))
108 $error->set_error('lockout_reached');
109 $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
110 LogicHook::initialize();
111 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
112 self::$helperObject->setFaultObject($error);
115 else if(function_exists('mcrypt_cbc'))
117 $password = self::$helperObject->decrypt_string($user_auth['password']);
118 if($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id']))
125 global $current_user;
126 //$current_user = $user;
127 self::$helperObject->login_success($name_value_list);
128 $current_user->loadPreferences();
129 $_SESSION['is_valid_session']= true;
130 $_SESSION['ip_address'] = query_client_ip();
131 $_SESSION['user_id'] = $current_user->id;
132 $_SESSION['type'] = 'user';
133 $_SESSION['avail_modules']= self::$helperObject->get_user_module_list($current_user);
134 $_SESSION['authenticated_user_id'] = $current_user->id;
135 $_SESSION['unique_key'] = $sugar_config['unique_key'];
136 $current_user->call_custom_logic('after_login');
137 $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
138 $nameValueArray = array();
139 global $current_language;
140 $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
141 $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
142 $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
143 $cur_id = $current_user->getPreference('currency');
144 $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
145 $nameValueArray['user_is_admin'] = self::$helperObject->get_name_value('user_is_admin', is_admin($current_user));
146 $nameValueArray['user_default_team_id'] = self::$helperObject->get_name_value('user_default_team_id', $current_user->default_team );
147 $nameValueArray['user_default_dateformat'] = self::$helperObject->get_name_value('user_default_dateformat', $current_user->getPreference('datef') );
148 $nameValueArray['user_default_timeformat'] = self::$helperObject->get_name_value('user_default_timeformat', $current_user->getPreference('timef') );
149 $currencyObject = new Currency();
150 $currencyObject->retrieve($cur_id);
151 $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
152 $_SESSION['user_language'] = $current_language;
153 return array('id'=>session_id(), 'module_name'=>'Users', 'name_value_list'=>$nameValueArray);
155 LogicHook::initialize();
156 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
157 $error->set_error('invalid_login');
158 self::$helperObject->setFaultObject($error);
159 $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
163 * Retrieve the md5 hash of the vardef entries for a particular module.
165 * @param String $session -- Session ID returned by a previous call to login.
166 * @param String|array $module_name -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
167 * @return String The md5 hash of the vardef definition.
168 * @exception 'SoapFault' -- The SOAP error, if any
170 function get_module_fields_md5($session, $module_name){
172 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_module_fields_md5(v3) for module: '. print_r($module_name, true));
175 if( is_array($module_name) )
177 foreach ($module_name as $module)
178 $results[$module] = md5(serialize(self::get_module_fields($session, $module)));
181 $results[$module_name] = md5(serialize(self::get_module_fields($session, $module_name)));
187 * Gets server info. This will return information like version, flavor and gmt_time.
188 * @return Array - flavor - String - Retrieve the specific flavor of sugar.
189 * - version - String - Retrieve the version number of Sugar that the server is running.
190 * - gmt_time - String - Return the current time on the server in the format 'Y-m-d H:i:s'. This time is in GMT.
191 * @exception 'SoapFault' -- The SOAP error, if any
193 function get_server_info(){
194 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_server_info');
195 require_once('sugar_version.php');
196 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_server_info');
198 return array('flavor' => $GLOBALS['sugar_flavor'], 'version' => $GLOBALS['sugar_version'], 'gmt_time' => TimeDate::getInstance()->nowDb());
202 * Retrieve the layout metadata for a given module given a specific type and view.
204 * @param String $session -- Session ID returned by a previous call to login.
205 * @param array $module_name(s) -- The name of the module(s) to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
206 * @return array $type The type(s) of views requested. Current supported types are 'default' (for application) and 'wireless'
207 * @return array $view The view(s) requested. Current supported types are edit, detail, list, and subpanel.
208 * @exception 'SoapFault' -- The SOAP error, if any
210 function get_module_layout($session, $a_module_names, $a_type, $a_view,$md5 = FALSE){
211 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_module_layout');
213 global $beanList, $beanFiles;
214 $error = new SoapError();
216 foreach ($a_module_names as $module_name)
218 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error))
220 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_layout');
224 $class_name = $beanList[$module_name];
225 require_once($beanFiles[$class_name]);
226 $seed = new $class_name();
228 foreach ($a_view as $view)
230 $aclViewCheck = (strtolower($view) == 'subpanel') ? 'DetailView' : ucfirst(strtolower($view)) . 'View';
231 if($seed->ACLAccess($aclViewCheck, true) )
233 foreach ($a_type as $type)
235 $a_vardefs = self::$helperObject->get_module_view_defs($module_name, $type, $view);
237 $results[$module_name][$type][$view] = md5(serialize($a_vardefs));
239 $results[$module_name][$type][$view] = $a_vardefs;
245 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_layout');
251 * Retrieve the md5 hash of a layout metadata for a given module given a specific type and view.
253 * @param String $session -- Session ID returned by a previous call to login.
254 * @param array $module_name(s) -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
255 * @return array $type(s) The type of view requested. Current supported types are 'default' (for application) and 'wireless'
256 * @return array $view(s) The view requested. Current supported types are edit, detail, and list.
257 * @exception 'SoapFault' -- The SOAP error, if any
259 function get_module_layout_md5($session, $module_name, $type, $view){
260 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_module_layout_md5');
261 $results = self::get_module_layout($session, $module_name, $type, $view, TRUE);
262 return array('md5'=> $results);
263 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_layout_md5');
267 * Retrieve the list of available modules on the system available to the currently logged in user.
269 * @param String $session -- Session ID returned by a previous call to login.
270 * @param String $filter -- Valid values are: all - Return all modules,
271 * default - Return all visible modules for the application
272 * mobile - Return all visible modules for the mobile view
273 * @return Array 'modules' -- Array - An array of module names
274 * @exception 'SoapFault' -- The SOAP error, if any
276 function get_available_modules($session,$filter='all'){
277 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_available_modules');
279 $error = new SoapError();
280 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
281 $error->set_error('invalid_login');
282 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_available_modules');
287 $availModules = array_keys($_SESSION['avail_modules']); //ACL check already performed.
290 $modules = self::$helperObject->get_visible_modules($availModules);
293 $modules = self::$helperObject->get_visible_mobile_modules($availModules);
297 $modules = $availModules;
300 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_available_modules');
301 return array('modules'=> $modules);
305 * Retrieve a list of recently viewed records by module.
307 * @param String $session -- Session ID returned by a previous call to login.
308 * @param String $modules -- An array of modules or 'Home' to indicate all.
309 * @return Array The recently viewed records
310 * @exception 'SoapFault' -- The SOAP error, if any
312 function get_last_viewed($session, $module_names)
314 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_last_viewed');
315 $error = new SoapError();
316 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error))
318 $error->set_error('invalid_login');
319 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_last_viewed');
324 foreach ($module_names as $module )
326 if(!self::$helperObject->check_modules_access($GLOBALS['current_user'], $module, 'read'))
328 $GLOBALS['log']->debug("SugarWebServiceImpl->get_last_viewed: NO ACCESS to $module");
332 if($module == 'Home') $module = '';
333 $tracker = new Tracker();
334 $entryList = $tracker->get_recently_viewed($GLOBALS['current_user']->id, $module);
335 foreach ($entryList as $entry)
339 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_last_viewed');
344 * Retrieve a list of upcoming activities including Calls, Meetings,Tasks and Opportunities
346 * @param String $session -- Session ID returned by a previous call to login.
347 * @return Array List of upcoming activities
348 * @exception 'SoapFault' -- The SOAP error, if any
350 function get_upcoming_activities($session)
352 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_upcoming_activities');
353 $error = new SoapError();
354 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error))
356 $error->set_error('invalid_login');
357 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_upcoming_activities');
361 $results = self::$helperObject->get_upcoming_activities();
363 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_upcoming_activities');
369 * Given a list of modules to search and a search string, return the id, module_name, along with the fields
370 * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
372 * @param string $session - Session ID returned by a previous call to login.
373 * @param string $search_string - string to search
374 * @param string[] $modules - array of modules to query
375 * @param int $offset - a specified offset in the query
376 * @param int $max_results - max number of records to return
377 * @param string $assigned_user_id - a user id to filter all records by, leave empty to exclude the filter
378 * @param string[] $select_fields - An array of fields to return. If empty the default return fields will be from the active list view defs.
379 * @return Array return_search_result - Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
380 * @exception 'SoapFault' -- The SOAP error, if any
382 function search_by_module($session, $search_string, $modules, $offset, $max_results,$assigned_user_id = '', $select_fields = array()){
383 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module');
384 global $beanList, $beanFiles;
385 global $sugar_config,$current_language;
387 $error = new SoapError();
388 $output_list = array();
389 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
390 $error->set_error('invalid_login');
391 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
394 global $current_user;
395 if($max_results > 0){
396 $sugar_config['list_max_entries_per_page'] = $max_results;
399 require_once('modules/Home/UnifiedSearchAdvanced.php');
400 require_once 'include/utils.php';
401 $usa = new UnifiedSearchAdvanced();
402 if(!file_exists($cachedfile = sugar_cached('modules/unified_search_modules.php'))) {
406 include($cachedfile);
407 $modules_to_search = array();
408 $unified_search_modules['Users'] = array('fields' => array());
410 $unified_search_modules['ProjectTask'] = array('fields' => array());
412 foreach($unified_search_modules as $module=>$data) {
413 if (in_array($module, $modules)) {
414 $modules_to_search[$module] = $beanList[$module];
418 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
420 if(!empty($search_string) && isset($search_string)) {
421 $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH')))));
422 foreach($modules_to_search as $name => $beanName) {
423 $where_clauses_array = array();
424 $unifiedSearchFields = array () ;
425 foreach ($unified_search_modules[$name]['fields'] as $field=>$def ) {
426 $unifiedSearchFields[$name] [ $field ] = $def ;
427 $unifiedSearchFields[$name] [ $field ]['value'] = $search_string;
430 require_once $beanFiles[$beanName] ;
431 $seed = new $beanName();
432 require_once 'include/SearchForm/SearchForm2.php' ;
433 if ($beanName == "User"
434 || $beanName == "ProjectTask"
436 if(!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')){
439 if(!$seed->ACLAccess('ListView')) {
444 if ($beanName != "User"
445 && $beanName != "ProjectTask"
447 $searchForm = new SearchForm ($seed, $name ) ;
449 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
450 $where_clauses = $searchForm->generateSearchWhere() ;
451 require_once 'include/SearchForm/SearchForm2.php' ;
452 $searchForm = new SearchForm ($seed, $name ) ;
454 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
455 $where_clauses = $searchForm->generateSearchWhere() ;
459 if (count($where_clauses) > 0 ) {
460 $where = '('. implode(' ) OR ( ', $where_clauses) . ')';
463 $mod_strings = return_module_language($current_language, $seed->module_dir);
465 if(count($select_fields) > 0)
466 $filterFields = $select_fields;
468 if(file_exists('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php'))
469 require_once('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
471 require_once('modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
473 $filterFields = array();
474 foreach($listViewDefs[$seed->module_dir] as $colName => $param) {
475 if(!empty($param['default']) && $param['default'] == true)
476 $filterFields[] = strtolower($colName);
478 if (!in_array('id', $filterFields))
479 $filterFields[] = 'id';
482 //Pull in any db fields used for the unified search query so the correct joins will be added
483 $selectOnlyQueryFields = array();
484 foreach ($unifiedSearchFields[$name] as $field => $def){
485 if( isset($def['db_field']) && !in_array($field,$filterFields) ){
486 $filterFields[] = $field;
487 $selectOnlyQueryFields[] = $field;
491 //Add the assigned user filter if applicable
492 if (!empty($assigned_user_id) && isset( $seed->field_defs['assigned_user_id']) ) {
493 $ownerWhere = $seed->getOwnerWhere($assigned_user_id);
494 $where = "($where) AND $ownerWhere";
497 $ret_array = $seed->create_new_list_query('', $where, $filterFields, array(), 0, '', true, $seed, true);
498 if(empty($params) or !is_array($params)) $params = array();
499 if(!isset($params['custom_select'])) $params['custom_select'] = '';
500 if(!isset($params['custom_from'])) $params['custom_from'] = '';
501 if(!isset($params['custom_where'])) $params['custom_where'] = '';
502 if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';
503 $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
505 if ($beanName == "User") {
506 $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address');
507 $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users ";
508 $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'
509 LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
510 $main_query = $main_query . "where ((users.first_name like '{$search_string}') or (users.last_name like '{$search_string}') or (users.user_name like '{$search_string}') or (ea.email_address like '{$search_string}')) and users.deleted = 0 and users.is_group = 0 and users.employee_status = 'Active'";
512 if ($beanName == "ProjectTask") {
513 $filterFields = array('id', 'name', 'project_id', 'project_name');
514 $main_query = "select {$seed->table_name}.project_task_id id,{$seed->table_name}.project_id, {$seed->table_name}.name, project.name project_name from {$seed->table_name} ";
515 $seed->add_team_security_where_clause($main_query);
516 $main_query .= "LEFT JOIN teams ON $seed->table_name.team_id=teams.id AND (teams.deleted=0) ";
517 $main_query .= "LEFT JOIN project ON $seed->table_name.project_id = project.id ";
518 $main_query .= "where {$seed->table_name}.name like '{$search_string}%'";
522 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query);
523 if($max_results < -1) {
524 $result = $seed->db->query($main_query);
527 if($max_results == -1) {
528 $limit = $sugar_config['list_max_entries_per_page'];
530 $limit = $max_results;
532 $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
536 while($row = $seed->db->fetchByAssoc($result)) {
537 $nameValueArray = array();
538 foreach ($filterFields as $field) {
539 if(in_array($field, $selectOnlyQueryFields))
541 $nameValue = array();
542 if (isset($row[$field])) {
543 $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]);
546 $rowArray[] = $nameValueArray;
548 $output_list[] = array('name' => $name, 'records' => $rowArray);
551 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
552 return array('entry_list'=>$output_list);
554 return array('entry_list'=>$output_list);
558 * Retrieve a collection of beans that are related to the specified bean and optionally return relationship data for those related beans.
559 * So in this API you can get contacts info for an account and also return all those contact's email address or an opportunity info also.
561 * @param String $session -- Session ID returned by a previous call to login.
562 * @param String $module_name -- The name of the module that the primary record is from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
563 * @param String $module_id -- The ID of the bean in the specified module
564 * @param String $link_field_name -- The name of the lnk field to return records from. This name should be the name the relationship.
565 * @param String $related_module_query -- A portion of the where clause of the SQL statement to find the related items. The SQL query will already be filtered to only include the beans that are related to the specified bean.
566 * @param Array $related_fields - Array of related bean fields to be returned.
567 * @param Array $related_module_link_name_to_fields_array - For every related bean returrned, specify link fields name to fields info for that bean to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))).
568 * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
569 * @param String $order_by -- field to order the result sets by
570 * @return Array 'entry_list' -- Array - The records that were retrieved
571 * 'relationship_list' -- Array - The records link field data. The example is if asked about accounts contacts email address then return data would look like Array ( [0] => Array ( [name] => email_addresses [records] => Array ( [0] => Array ( [0] => Array ( [name] => id [value] => 3fb16797-8d90-0a94-ac12-490b63a6be67 ) [1] => Array ( [name] => email_address [value] => hr.kid.qa@example.com ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 1 ) ) [1] => Array ( [0] => Array ( [name] => id [value] => 403f8da1-214b-6a88-9cef-490b63d43566 ) [1] => Array ( [name] => email_address [value] => kid.hr@example.name ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 0 ) ) ) ) )
572 * @exception 'SoapFault' -- The SOAP error, if any
574 function get_relationships($session, $module_name, $module_id, $link_field_name, $related_module_query, $related_fields, $related_module_link_name_to_fields_array, $deleted, $order_by = ''){
575 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_relationships');
576 global $beanList, $beanFiles;
577 $error = new SoapError();
578 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
579 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
583 $class_name = $beanList[$module_name];
584 require_once($beanFiles[$class_name]);
585 $mod = new $class_name();
586 $mod->retrieve($module_id);
588 if (!self::$helperObject->checkQuery($error, $related_module_query, $order_by)) {
589 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
593 if (!self::$helperObject->checkACLAccess($mod, 'DetailView', $error, 'no_access')) {
594 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
598 $output_list = array();
599 $linkoutput_list = array();
601 // get all the related mmodules data.
602 $result = self::$helperObject->getRelationshipResults($mod, $link_field_name, $related_fields, $related_module_query,$order_by);
603 if (self::$helperObject->isLogLevelDebug()) {
604 $GLOBALS['log']->debug('SoapHelperWebServices->get_relationships - return data for getRelationshipResults is ' . var_export($result, true));
607 $list = $result['rows'];
608 $filterFields = $result['fields_set_on_rows'];
610 if (sizeof($list) > 0) {
611 // get the related module name and instantiate a bean for that.
612 $submodulename = $mod->$link_field_name->getRelatedModuleName();
613 $submoduleclass = $beanList[$submodulename];
614 require_once($beanFiles[$submoduleclass]);
616 $submoduletemp = new $submoduleclass();
617 foreach($list as $row) {
618 $submoduleobject = @clone($submoduletemp);
619 // set all the database data to this object
620 foreach ($filterFields as $field) {
621 $submoduleobject->$field = $row[$field];
623 if (isset($row['id'])) {
624 $submoduleobject->id = $row['id'];
626 $output_list[] = self::$helperObject->get_return_value_for_fields($submoduleobject, $submodulename, $filterFields);
627 if (!empty($related_module_link_name_to_fields_array)) {
628 $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($submoduleobject, $submodulename, $related_module_link_name_to_fields_array);
636 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
637 return array('entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
642 SugarWebServiceImplv3::$helperObject = new SugarWebServiceUtilv3();