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-2012 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);
294 $modules = $availModules;
297 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_available_modules');
298 return array('modules'=> $modules);
302 * Retrieve a list of recently viewed records by module.
304 * @param String $session -- Session ID returned by a previous call to login.
305 * @param String $modules -- An array of modules or 'Home' to indicate all.
306 * @return Array The recently viewed records
307 * @exception 'SoapFault' -- The SOAP error, if any
309 function get_last_viewed($session, $module_names)
311 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_last_viewed');
312 $error = new SoapError();
313 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error))
315 $error->set_error('invalid_login');
316 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_last_viewed');
321 foreach ($module_names as $module )
323 if(!self::$helperObject->check_modules_access($GLOBALS['current_user'], $module, 'read'))
325 $GLOBALS['log']->debug("SugarWebServiceImpl->get_last_viewed: NO ACCESS to $module");
329 if($module == 'Home') $module = '';
330 $tracker = new Tracker();
331 $entryList = $tracker->get_recently_viewed($GLOBALS['current_user']->id, $module);
332 foreach ($entryList as $entry)
336 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_last_viewed');
341 * Retrieve a list of upcoming activities including Calls, Meetings,Tasks and Opportunities
343 * @param String $session -- Session ID returned by a previous call to login.
344 * @return Array List of upcoming activities
345 * @exception 'SoapFault' -- The SOAP error, if any
347 function get_upcoming_activities($session)
349 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_upcoming_activities');
350 $error = new SoapError();
351 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error))
353 $error->set_error('invalid_login');
354 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_upcoming_activities');
358 $results = self::$helperObject->get_upcoming_activities();
360 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_upcoming_activities');
366 * Given a list of modules to search and a search string, return the id, module_name, along with the fields
367 * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
369 * @param string $session - Session ID returned by a previous call to login.
370 * @param string $search_string - string to search
371 * @param string[] $modules - array of modules to query
372 * @param int $offset - a specified offset in the query
373 * @param int $max_results - max number of records to return
374 * @param string $assigned_user_id - a user id to filter all records by, leave empty to exclude the filter
375 * @param string[] $select_fields - An array of fields to return. If empty the default return fields will be from the active list view defs.
376 * @return Array return_search_result - Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
377 * @exception 'SoapFault' -- The SOAP error, if any
379 function search_by_module($session, $search_string, $modules, $offset, $max_results,$assigned_user_id = '', $select_fields = array()){
380 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module');
381 global $beanList, $beanFiles;
382 global $sugar_config,$current_language;
384 $error = new SoapError();
385 $output_list = array();
386 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
387 $error->set_error('invalid_login');
388 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
391 global $current_user;
392 if($max_results > 0){
393 $sugar_config['list_max_entries_per_page'] = $max_results;
396 require_once('modules/Home/UnifiedSearchAdvanced.php');
397 require_once 'include/utils.php';
398 $usa = new UnifiedSearchAdvanced();
399 if(!file_exists($cachedfile = sugar_cached('modules/unified_search_modules.php'))) {
403 include($cachedfile);
404 $modules_to_search = array();
405 $unified_search_modules['Users'] = array('fields' => array());
407 $unified_search_modules['ProjectTask'] = array('fields' => array());
409 foreach($unified_search_modules as $module=>$data) {
410 if (in_array($module, $modules)) {
411 $modules_to_search[$module] = $beanList[$module];
415 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
417 if(!empty($search_string) && isset($search_string)) {
418 $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH')))));
419 foreach($modules_to_search as $name => $beanName) {
420 $where_clauses_array = array();
421 $unifiedSearchFields = array () ;
422 foreach ($unified_search_modules[$name]['fields'] as $field=>$def ) {
423 $unifiedSearchFields[$name] [ $field ] = $def ;
424 $unifiedSearchFields[$name] [ $field ]['value'] = $search_string;
427 require_once $beanFiles[$beanName] ;
428 $seed = new $beanName();
429 require_once 'include/SearchForm/SearchForm2.php' ;
430 if ($beanName == "User"
431 || $beanName == "ProjectTask"
433 if(!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')){
436 if(!$seed->ACLAccess('ListView')) {
441 if ($beanName != "User"
442 && $beanName != "ProjectTask"
444 $searchForm = new SearchForm ($seed, $name ) ;
446 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
447 $where_clauses = $searchForm->generateSearchWhere() ;
448 require_once 'include/SearchForm/SearchForm2.php' ;
449 $searchForm = new SearchForm ($seed, $name ) ;
451 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
452 $where_clauses = $searchForm->generateSearchWhere() ;
456 if (count($where_clauses) > 0 ) {
457 $where = '('. implode(' ) OR ( ', $where_clauses) . ')';
460 $mod_strings = return_module_language($current_language, $seed->module_dir);
462 if(count($select_fields) > 0)
463 $filterFields = $select_fields;
465 if(file_exists('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php'))
466 require_once('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
468 require_once('modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
470 $filterFields = array();
471 foreach($listViewDefs[$seed->module_dir] as $colName => $param) {
472 if(!empty($param['default']) && $param['default'] == true)
473 $filterFields[] = strtolower($colName);
475 if (!in_array('id', $filterFields))
476 $filterFields[] = 'id';
479 //Pull in any db fields used for the unified search query so the correct joins will be added
480 $selectOnlyQueryFields = array();
481 foreach ($unifiedSearchFields[$name] as $field => $def){
482 if( isset($def['db_field']) && !in_array($field,$filterFields) ){
483 $filterFields[] = $field;
484 $selectOnlyQueryFields[] = $field;
488 //Add the assigned user filter if applicable
489 if (!empty($assigned_user_id) && isset( $seed->field_defs['assigned_user_id']) ) {
490 $ownerWhere = $seed->getOwnerWhere($assigned_user_id);
491 $where = "($where) AND $ownerWhere";
494 $ret_array = $seed->create_new_list_query('', $where, $filterFields, array(), 0, '', true, $seed, true);
495 if(empty($params) or !is_array($params)) $params = array();
496 if(!isset($params['custom_select'])) $params['custom_select'] = '';
497 if(!isset($params['custom_from'])) $params['custom_from'] = '';
498 if(!isset($params['custom_where'])) $params['custom_where'] = '';
499 if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';
500 $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'];
502 if ($beanName == "User") {
503 $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address');
504 $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users ";
505 $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'
506 LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
507 $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'";
509 if ($beanName == "ProjectTask") {
510 $filterFields = array('id', 'name', 'project_id', 'project_name');
511 $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} ";
512 $seed->add_team_security_where_clause($main_query);
513 $main_query .= "LEFT JOIN teams ON $seed->table_name.team_id=teams.id AND (teams.deleted=0) ";
514 $main_query .= "LEFT JOIN project ON $seed->table_name.project_id = project.id ";
515 $main_query .= "where {$seed->table_name}.name like '{$search_string}%'";
519 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query);
520 if($max_results < -1) {
521 $result = $seed->db->query($main_query);
524 if($max_results == -1) {
525 $limit = $sugar_config['list_max_entries_per_page'];
527 $limit = $max_results;
529 $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
533 while($row = $seed->db->fetchByAssoc($result)) {
534 $nameValueArray = array();
535 foreach ($filterFields as $field) {
536 if(in_array($field, $selectOnlyQueryFields))
538 $nameValue = array();
539 if (isset($row[$field])) {
540 $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]);
543 $rowArray[] = $nameValueArray;
545 $output_list[] = array('name' => $name, 'records' => $rowArray);
548 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
549 return array('entry_list'=>$output_list);
551 return array('entry_list'=>$output_list);
555 * Retrieve a collection of beans that are related to the specified bean and optionally return relationship data for those related beans.
556 * 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.
558 * @param String $session -- Session ID returned by a previous call to login.
559 * @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)..
560 * @param String $module_id -- The ID of the bean in the specified module
561 * @param String $link_field_name -- The name of the lnk field to return records from. This name should be the name the relationship.
562 * @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.
563 * @param Array $related_fields - Array of related bean fields to be returned.
564 * @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'))).
565 * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
566 * @param String $order_by -- field to order the result sets by
567 * @return Array 'entry_list' -- Array - The records that were retrieved
568 * '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 ) ) ) ) )
569 * @exception 'SoapFault' -- The SOAP error, if any
571 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 = ''){
572 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_relationships');
573 global $beanList, $beanFiles;
574 $error = new SoapError();
575 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
576 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
580 $class_name = $beanList[$module_name];
581 require_once($beanFiles[$class_name]);
582 $mod = new $class_name();
583 $mod->retrieve($module_id);
585 if (!self::$helperObject->checkQuery($error, $related_module_query, $order_by)) {
586 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
590 if (!self::$helperObject->checkACLAccess($mod, 'DetailView', $error, 'no_access')) {
591 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
595 $output_list = array();
596 $linkoutput_list = array();
598 // get all the related mmodules data.
599 $result = self::$helperObject->getRelationshipResults($mod, $link_field_name, $related_fields, $related_module_query,$order_by);
600 if (self::$helperObject->isLogLevelDebug()) {
601 $GLOBALS['log']->debug('SoapHelperWebServices->get_relationships - return data for getRelationshipResults is ' . var_export($result, true));
604 $list = $result['rows'];
605 $filterFields = $result['fields_set_on_rows'];
607 if (sizeof($list) > 0) {
608 // get the related module name and instantiate a bean for that.
609 $submodulename = $mod->$link_field_name->getRelatedModuleName();
610 $submoduleclass = $beanList[$submodulename];
611 require_once($beanFiles[$submoduleclass]);
613 $submoduletemp = new $submoduleclass();
614 foreach($list as $row) {
615 $submoduleobject = @clone($submoduletemp);
616 // set all the database data to this object
617 foreach ($filterFields as $field) {
618 $submoduleobject->$field = $row[$field];
620 if (isset($row['id'])) {
621 $submoduleobject->id = $row['id'];
623 $output_list[] = self::$helperObject->get_return_value_for_fields($submoduleobject, $submodulename, $filterFields);
624 if (!empty($related_module_link_name_to_fields_array)) {
625 $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($submoduleobject, $submodulename, $related_module_link_name_to_fields_array);
633 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
634 return array('entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
639 SugarWebServiceImplv3::$helperObject = new SugarWebServiceUtilv3();