]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/v3/SugarWebServiceImplv3.php
Release 6.4.0
[Github/sugarcrm.git] / service / v3 / SugarWebServiceImplv3.php
1 <?php
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.
6  * 
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.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
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  ********************************************************************************/
37
38
39 /**
40  * This class is an implemenatation class for all the rest services
41  */
42 require_once('service/core/SugarWebServiceImpl.php');
43 require_once('SugarWebServiceUtilv3.php');
44
45
46 class SugarWebServiceImplv3 extends SugarWebServiceImpl {
47
48     public function __construct()
49     {
50         self::$helperObject = new SugarWebServiceUtilv3();
51     }
52
53
54     /**
55      * Log the user into the application
56      *
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
67      */
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();
72         $user = new User();
73         $success = false;
74         if(!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN')
75         {
76             $user_auth['password'] = md5($user_auth['password']);
77         }
78         //rrs
79         $system_config = new Administration();
80         $system_config->retrieveSettings('system');
81         $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
82         //rrs
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']);
85         if($usr_id)
86             $user->retrieve($usr_id);
87
88         if ($isLoginSuccess)
89         {
90             if ($_SESSION['hasExpiredPassword'] =='1')
91             {
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);
97                 return;
98             }
99             if(!empty($user) && !empty($user->id) && !$user->is_group)
100             {
101                 $success = true;
102                 global $current_user;
103                 $current_user = $user;
104             }
105         }
106         else if($usr_id && isset($user->user_name) && ($user->getPreference('lockout') == '1'))
107         {
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);
113             return;
114         }
115         else if(function_exists('mcrypt_cbc'))
116         {
117             $password = self::$helperObject->decrypt_string($user_auth['password']);
118             if($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id']))
119                 $success = true;
120         }
121
122         if($success)
123         {
124             session_start();
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);
154         }
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');
160     }
161
162     /**
163      * Retrieve the md5 hash of the vardef entries for a particular module.
164      *
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
169      */
170     function get_module_fields_md5($session, $module_name){
171
172         $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_module_fields_md5(v3) for module: '. print_r($module_name, true));
173
174         $results = array();
175         if( is_array($module_name) )
176         {
177             foreach ($module_name as $module)
178                 $results[$module] = md5(serialize(self::get_module_fields($session, $module)));
179         }
180         else
181             $results[$module_name] = md5(serialize(self::get_module_fields($session, $module_name)));
182
183         return $results;
184     }
185
186     /**
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
192      */
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');
197
198         return array('flavor' => $GLOBALS['sugar_flavor'], 'version' => $GLOBALS['sugar_version'], 'gmt_time' => TimeDate::getInstance()->nowDb());
199     } // fn
200
201     /**
202      * Retrieve the layout metadata for a given module given a specific type and view.
203      *
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
209      */
210     function get_module_layout($session, $a_module_names, $a_type, $a_view,$md5 = FALSE){
211         $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_module_layout');
212
213         global  $beanList, $beanFiles;
214         $error = new SoapError();
215         $results = array();
216         foreach ($a_module_names as $module_name)
217         {
218             if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error))
219             {
220                 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_layout');
221                 continue;
222             }
223
224             $class_name = $beanList[$module_name];
225             require_once($beanFiles[$class_name]);
226             $seed = new $class_name();
227
228             foreach ($a_view as $view)
229             {
230                 $aclViewCheck = (strtolower($view) == 'subpanel') ? 'DetailView' : ucfirst(strtolower($view)) . 'View';
231                 if($seed->ACLAccess($aclViewCheck, true) )
232                 {
233                     foreach ($a_type as $type)
234                     {
235                         $a_vardefs = self::$helperObject->get_module_view_defs($module_name, $type, $view);
236                         if($md5)
237                             $results[$module_name][$type][$view] = md5(serialize($a_vardefs));
238                         else
239                             $results[$module_name][$type][$view] = $a_vardefs;
240                     }
241                 }
242             }
243         }
244
245         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_layout');
246
247         return $results;
248     }
249
250     /**
251      * Retrieve the md5 hash of a layout metadata for a given module given a specific type and view.
252      *
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
258      */
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');
264     }
265
266     /**
267      * Retrieve the list of available modules on the system available to the currently logged in user.
268      *
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
275      */
276     function get_available_modules($session,$filter='all'){
277         $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_available_modules');
278
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');
283                 return;
284         } // if
285
286         $modules = array();
287         $availModules = array_keys($_SESSION['avail_modules']); //ACL check already performed.
288         switch ($filter){
289             case 'default':
290                 $modules = self::$helperObject->get_visible_modules($availModules);
291                break;
292             case 'mobile':
293                 $modules = self::$helperObject->get_visible_mobile_modules($availModules);
294                 break;
295             case 'all':
296             default:
297                 $modules = $availModules;
298         }
299
300         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_available_modules');
301         return array('modules'=> $modules);
302     } // fn
303
304     /**
305      * Retrieve a list of recently viewed records by module.
306      *
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
311      */
312     function get_last_viewed($session, $module_names)
313     {
314         $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_last_viewed');
315         $error = new SoapError();
316         if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error))
317         {
318                 $error->set_error('invalid_login');
319                 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_last_viewed');
320                 return;
321         } // if
322
323         $results = array();
324         foreach ($module_names as $module )
325         {
326             if(!self::$helperObject->check_modules_access($GLOBALS['current_user'], $module, 'read'))
327             {
328                 $GLOBALS['log']->debug("SugarWebServiceImpl->get_last_viewed: NO ACCESS to $module");
329                 continue;
330             }
331
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)
336                 $results[] = $entry;
337         }
338
339         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_last_viewed');
340         return $results;
341     }
342
343     /**
344      * Retrieve a list of upcoming activities including Calls, Meetings,Tasks and Opportunities
345      *
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
349      */
350     function get_upcoming_activities($session)
351     {
352         $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_upcoming_activities');
353         $error = new SoapError();
354         if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error))
355         {
356                 $error->set_error('invalid_login');
357                 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_upcoming_activities');
358                 return;
359         } // if
360
361         $results = self::$helperObject->get_upcoming_activities();
362
363         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_upcoming_activities');
364
365         return $results;
366     }
367
368     /**
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
371      *
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
381      */
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;
386
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');
392                 return;
393         }
394         global $current_user;
395         if($max_results > 0){
396                 $sugar_config['list_max_entries_per_page'] = $max_results;
397         }
398
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'))) {
403             $usa->buildCache();
404         }
405
406         include($cachedfile);
407         $modules_to_search = array();
408         $unified_search_modules['Users'] =   array('fields' => array());
409
410         $unified_search_modules['ProjectTask'] =   array('fields' => array());
411
412         foreach($unified_search_modules as $module=>$data) {
413                 if (in_array($module, $modules)) {
414                 $modules_to_search[$module] = $beanList[$module];
415                 } // if
416         } // foreach
417
418         $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
419
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;
428                         }
429
430                         require_once $beanFiles[$beanName] ;
431                         $seed = new $beanName();
432                         require_once 'include/SearchForm/SearchForm2.php' ;
433                         if ($beanName == "User"
434                             || $beanName == "ProjectTask"
435                             ) {
436                                 if(!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')){
437                                         continue;
438                                 } // if
439                                 if(!$seed->ACLAccess('ListView')) {
440                                         continue;
441                                 } // if
442                         }
443
444                         if ($beanName != "User"
445                             && $beanName != "ProjectTask"
446                             ) {
447                                 $searchForm = new SearchForm ($seed, $name ) ;
448
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 ) ;
453
454                                 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
455                                 $where_clauses = $searchForm->generateSearchWhere() ;
456                                 $emailQuery = false;
457
458                                 $where = '';
459                                 if (count($where_clauses) > 0 ) {
460                                         $where = '('. implode(' ) OR ( ', $where_clauses) . ')';
461                                 }
462
463                                 $mod_strings = return_module_language($current_language, $seed->module_dir);
464
465                                 if(count($select_fields) > 0)
466                                     $filterFields = $select_fields;
467                                 else {
468                                     if(file_exists('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php'))
469                                            require_once('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
470                                         else
471                                                 require_once('modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
472
473                                         $filterFields = array();
474                                         foreach($listViewDefs[$seed->module_dir] as $colName => $param) {
475                                 if(!empty($param['default']) && $param['default'] == true)
476                                     $filterFields[] = strtolower($colName);
477                             }
478                             if (!in_array('id', $filterFields))
479                                 $filterFields[] = 'id';
480                                 }
481
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;
488                                     }
489                                 }
490
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";
495                     }
496
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'];
504                         } else {
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'";
511                                 } // if
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}%'";
519                                 } // if
520                         } // else
521
522                         $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query);
523                         if($max_results < -1) {
524                                 $result = $seed->db->query($main_query);
525                         }
526                         else {
527                                 if($max_results == -1) {
528                                         $limit = $sugar_config['list_max_entries_per_page'];
529                     } else {
530                         $limit = $max_results;
531                     }
532                     $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
533                         }
534
535                         $rowArray = array();
536                         while($row = $seed->db->fetchByAssoc($result)) {
537                                 $nameValueArray = array();
538                                 foreach ($filterFields as $field) {
539                                     if(in_array($field, $selectOnlyQueryFields))
540                                         continue;
541                                         $nameValue = array();
542                                         if (isset($row[$field])) {
543                                                 $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]);
544                                         } // if
545                                 } // foreach
546                                 $rowArray[] = $nameValueArray;
547                         } // while
548                         $output_list[] = array('name' => $name, 'records' => $rowArray);
549                 } // foreach
550
551         $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
552         return array('entry_list'=>$output_list);
553         } // if
554         return array('entry_list'=>$output_list);
555     } // fn
556
557     /**
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.
560      *
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
573     */
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');
580                 return;
581         } // if
582
583         $class_name = $beanList[$module_name];
584         require_once($beanFiles[$class_name]);
585         $mod = new $class_name();
586         $mod->retrieve($module_id);
587
588         if (!self::$helperObject->checkQuery($error, $related_module_query, $order_by)) {
589                 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
590                 return;
591         } // if
592
593         if (!self::$helperObject->checkACLAccess($mod, 'DetailView', $error, 'no_access')) {
594                 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
595                 return;
596         } // if
597
598         $output_list = array();
599         $linkoutput_list = array();
600
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));
605         } // if
606         if ($result) {
607                 $list = $result['rows'];
608                 $filterFields = $result['fields_set_on_rows'];
609
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]);
615
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];
622                                 } // foreach
623                                 if (isset($row['id'])) {
624                                         $submoduleobject->id = $row['id'];
625                                 }
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);
629                                 } // if
630
631                         } // foreach
632                 }
633
634         } // if
635
636         $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
637         return array('entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
638
639     } // fn
640 }
641
642 SugarWebServiceImplv3::$helperObject = new SugarWebServiceUtilv3();