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/v3_1/SugarWebServiceImplv3_1.php');
43 require_once('SugarWebServiceUtilv4.php');
46 class SugarWebServiceImplv4 extends SugarWebServiceImplv3_1 {
48 public function __construct()
50 self::$helperObject = new SugarWebServiceUtilv4();
54 * Log the user into the application
56 * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
57 * in the right encoding for the type of authentication the user is setup for. For Base
58 * sugar validation, password is the MD5 sum of the plain text password.
59 * @param String $application -- The name of the application you are logging in from. (Currently unused).
60 * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
61 * @return Array - id - String id is the session_id of the session that was created.
62 * - module_name - String - module name of user
63 * - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name,
64 * - user_default_team_id, user_is_admin, user_default_dateformat, user_default_timeformat
65 * @exception 'SoapFault' -- The SOAP error, if any
67 public function login($user_auth, $application, $name_value_list = array()){
68 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
69 global $sugar_config, $system_config;
70 $error = new SoapError();
74 $system_config = new Administration();
75 $system_config->retrieveSettings('system');
76 $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
78 if(!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN' && $authController->authController->userAuthenticateClass != "LDAPAuthenticateUser")
80 $user_auth['password'] = md5($user_auth['password']);
82 $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
83 $usr_id=$user->retrieve_user_id($user_auth['user_name']);
85 $user->retrieve($usr_id);
89 if ($_SESSION['hasExpiredPassword'] =='1')
91 $error->set_error('password_expired');
92 $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
93 LogicHook::initialize();
94 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
95 self::$helperObject->setFaultObject($error);
98 if(!empty($user) && !empty($user->id) && !$user->is_group)
101 global $current_user;
102 $current_user = $user;
105 else if($usr_id && isset($user->user_name) && ($user->getPreference('lockout') == '1'))
107 $error->set_error('lockout_reached');
108 $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
109 LogicHook::initialize();
110 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
111 self::$helperObject->setFaultObject($error);
114 else if( $authController->authController->userAuthenticateClass == "LDAPAuthenticateUser"
115 && (empty($user_auth['encryption']) || $user_auth['encryption'] !== 'PLAIN' ) )
117 $error->set_error('ldap_error');
118 LogicHook::initialize();
119 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
120 self::$helperObject->setFaultObject($error);
123 else if(function_exists('mcrypt_cbc'))
125 $password = self::$helperObject->decrypt_string($user_auth['password']);
126 if($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id']))
133 global $current_user;
134 //$current_user = $user;
135 self::$helperObject->login_success($name_value_list);
136 $current_user->loadPreferences();
137 $_SESSION['is_valid_session']= true;
138 $_SESSION['ip_address'] = query_client_ip();
139 $_SESSION['user_id'] = $current_user->id;
140 $_SESSION['type'] = 'user';
141 $_SESSION['avail_modules']= self::$helperObject->get_user_module_list($current_user);
142 $_SESSION['authenticated_user_id'] = $current_user->id;
143 $_SESSION['unique_key'] = $sugar_config['unique_key'];
144 $current_user->call_custom_logic('after_login');
145 $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
146 $nameValueArray = array();
147 global $current_language;
148 $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
149 $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
150 $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
151 $cur_id = $current_user->getPreference('currency');
152 $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
153 $nameValueArray['user_is_admin'] = self::$helperObject->get_name_value('user_is_admin', is_admin($current_user));
154 $nameValueArray['user_default_team_id'] = self::$helperObject->get_name_value('user_default_team_id', $current_user->default_team );
155 $nameValueArray['user_default_dateformat'] = self::$helperObject->get_name_value('user_default_dateformat', $current_user->getPreference('datef') );
156 $nameValueArray['user_default_timeformat'] = self::$helperObject->get_name_value('user_default_timeformat', $current_user->getPreference('timef') );
158 $num_grp_sep = $current_user->getPreference('num_grp_sep');
159 $dec_sep = $current_user->getPreference('dec_sep');
160 $nameValueArray['user_number_seperator'] = self::$helperObject->get_name_value('user_number_seperator', empty($num_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $num_grp_sep);
161 $nameValueArray['user_decimal_seperator'] = self::$helperObject->get_name_value('user_decimal_seperator', empty($dec_sep) ? $sugar_config['default_decimal_seperator'] : $dec_sep);
163 $nameValueArray['mobile_max_list_entries'] = self::$helperObject->get_name_value('mobile_max_list_entries', $sugar_config['wl_list_max_entries_per_page'] );
164 $nameValueArray['mobile_max_subpanel_entries'] = self::$helperObject->get_name_value('mobile_max_subpanel_entries', $sugar_config['wl_list_max_entries_per_subpanel'] );
167 $currencyObject = new Currency();
168 $currencyObject->retrieve($cur_id);
169 $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
170 $_SESSION['user_language'] = $current_language;
171 return array('id'=>session_id(), 'module_name'=>'Users', 'name_value_list'=>$nameValueArray);
173 LogicHook::initialize();
174 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
175 $error->set_error('invalid_login');
176 self::$helperObject->setFaultObject($error);
177 $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
182 * Retrieve a list of SugarBean's based on provided IDs. This API will not wotk with report module
184 * @param String $session -- Session ID returned by a previous call to login.
185 * @param String $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)..
186 * @param Array $ids -- An array of SugarBean IDs.
187 * @param Array $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
188 * @param Array $link_name_to_fields_array -- A list of link_names and for each link_name, what fields value to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
190 * 'entry_list' -- Array - The records name value pair for the simple data types excluding link field data.
191 * 'relationship_list' -- Array - The records link field data. The example is if asked about accounts 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 ) ) ) ) )
192 * @exception 'SoapFault' -- The SOAP error, if any
194 public function get_entries($session, $module_name, $ids, $select_fields, $link_name_to_fields_array)
196 $result = parent::get_entries($session, $module_name, $ids, $select_fields, $link_name_to_fields_array);
197 $relationshipList = $result['relationship_list'];
198 $returnRelationshipList = array();
199 foreach($relationshipList as $rel){
200 $link_output = array();
201 foreach($rel as $row){
203 foreach($row['records'] as $record){
204 $rowArray[]['link_value'] = $record;
206 $link_output[] = array('name' => $row['name'], 'records' => $rowArray);
208 $returnRelationshipList[]['link_list'] = $link_output;
211 $result['relationship_list'] = $returnRelationshipList;
216 * Retrieve a list of beans. This is the primary method for getting list of SugarBeans from Sugar using the SOAP API.
218 * @param String $session -- Session ID returned by a previous call to login.
219 * @param String $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)..
220 * @param String $query -- SQL where clause without the word 'where'
221 * @param String $order_by -- SQL order by clause without the phrase 'order by'
222 * @param integer $offset -- The record offset to start from.
223 * @param Array $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
224 * @param Array $link_name_to_fields_array -- A list of link_names and for each link_name, what fields value to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
225 * @param integer $max_results -- The maximum number of records to return. The default is the sugar configuration value for 'list_max_entries_per_page'
226 * @param integer $deleted -- false if deleted records should not be include, true if deleted records should be included.
227 * @return Array 'result_count' -- integer - The number of records returned
228 * 'next_offset' -- integer - The start of the next page (This will always be the previous offset plus the number of rows returned. It does not indicate if there is additional data unless you calculate that the next_offset happens to be closer than it should be.
229 * 'entry_list' -- Array - The records that were retrieved
230 * 'relationship_list' -- Array - The records link field data. The example is if asked about accounts 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 ) ) ) ) )
231 * @exception 'SoapFault' -- The SOAP error, if any
233 function get_entry_list($session, $module_name, $query, $order_by,$offset, $select_fields, $link_name_to_fields_array, $max_results, $deleted, $favorites = false ){
235 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entry_list');
236 global $beanList, $beanFiles;
237 $error = new SoapError();
239 if($module_name == 'CampaignProspects'){
240 $module_name = 'Prospects';
243 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
244 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
248 // If the maximum number of entries per page was specified, override the configuration value.
249 if($max_results > 0){
250 global $sugar_config;
251 $sugar_config['list_max_entries_per_page'] = $max_results;
254 $class_name = $beanList[$module_name];
255 require_once($beanFiles[$class_name]);
256 $seed = new $class_name();
258 if (!self::$helperObject->checkACLAccess($seed, 'list', $error, 'no_access')) {
259 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
266 if($offset == '' || $offset == -1){
270 $response = $seed->retrieveTargetList($query, $select_fields, $offset,-1,-1,$deleted);
273 $response = self::$helperObject->get_data_list($seed,$order_by, $query, $offset,-1,-1,$deleted,$favorites);
275 $list = $response['list'];
277 $output_list = array();
278 $linkoutput_list = array();
280 foreach($list as $value) {
281 if(isset($value->emailAddress)){
282 $value->emailAddress->handleLegacyRetrieve($value);
284 $value->fill_in_additional_detail_fields();
286 $output_list[] = self::$helperObject->get_return_value_for_fields($value, $module_name, $select_fields);
287 if(!empty($link_name_to_fields_array)){
288 $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($value, $module_name, $link_name_to_fields_array);
292 // Calculate the offset for the start of the next page
293 $next_offset = $offset + sizeof($output_list);
295 $returnRelationshipList = array();
296 foreach($linkoutput_list as $rel){
297 $link_output = array();
298 foreach($rel as $row){
300 foreach($row['records'] as $record){
301 $rowArray[]['link_value'] = $record;
303 $link_output[] = array('name' => $row['name'], 'records' => $rowArray);
305 $returnRelationshipList[]['link_list'] = $link_output;
308 $totalRecordCount = $response['row_count'];
309 if( !empty($sugar_config['disable_count_query']) )
310 $totalRecordCount = -1;
312 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
313 return array('result_count'=>sizeof($output_list), 'total_count' => $totalRecordCount, 'next_offset'=>$next_offset, 'entry_list'=>$output_list, 'relationship_list' => $returnRelationshipList);
317 * Retrieve the layout metadata for a given module given a specific type and view.
319 * @param String $session -- Session ID returned by a previous call to login.
320 * @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)..
321 * @return array $type The type(s) of views requested. Current supported types are 'default' (for application) and 'wireless'
322 * @return array $view The view(s) requested. Current supported types are edit, detail, list, and subpanel.
323 * @exception 'SoapFault' -- The SOAP error, if any
325 function get_module_layout($session, $a_module_names, $a_type, $a_view,$acl_check = TRUE, $md5 = FALSE){
326 $GLOBALS['log']->fatal('Begin: SugarWebServiceImpl->get_module_layout');
328 global $beanList, $beanFiles;
329 $error = new SoapError();
331 foreach ($a_module_names as $module_name)
333 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error))
335 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_layout');
339 if( empty($module_name) )
342 $class_name = $beanList[$module_name];
343 require_once($beanFiles[$class_name]);
344 $seed = new $class_name();
346 foreach ($a_view as $view)
348 $aclViewCheck = (strtolower($view) == 'subpanel') ? 'DetailView' : ucfirst(strtolower($view)) . 'View';
349 if(!$acl_check || $seed->ACLAccess($aclViewCheck, true) )
351 foreach ($a_type as $type)
353 $a_vardefs = self::$helperObject->get_module_view_defs($module_name, $type, $view);
355 $results[$module_name][$type][$view] = md5(serialize($a_vardefs));
357 $results[$module_name][$type][$view] = $a_vardefs;
363 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_layout');
370 * Given a list of modules to search and a search string, return the id, module_name, along with the fields
371 * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
373 * @param string $session - Session ID returned by a previous call to login.
374 * @param string $search_string - string to search
375 * @param string[] $modules - array of modules to query
376 * @param int $offset - a specified offset in the query
377 * @param int $max_results - max number of records to return
378 * @param string $assigned_user_id - a user id to filter all records by, leave empty to exclude the filter
379 * @param string[] $select_fields - An array of fields to return. If empty the default return fields will be from the active list view defs.
380 * @param bool $unified_search_only - A boolean indicating if we should only search against those modules participating in the unified search.
381 * @param bool $favorites - A boolean indicating if we should only search against records marked as favorites.
382 * @return Array return_search_result - Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
383 * @exception 'SoapFault' -- The SOAP error, if any
385 function search_by_module($session, $search_string, $modules, $offset, $max_results,$assigned_user_id = '', $select_fields = array(), $unified_search_only = TRUE, $favorites = FALSE){
386 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module');
387 global $beanList, $beanFiles;
388 global $sugar_config,$current_language;
390 $error = new SoapError();
391 $output_list = array();
392 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
393 $error->set_error('invalid_login');
394 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
397 global $current_user;
398 if($max_results > 0){
399 $sugar_config['list_max_entries_per_page'] = $max_results;
402 require_once('modules/Home/UnifiedSearchAdvanced.php');
403 require_once 'include/utils.php';
404 $usa = new UnifiedSearchAdvanced();
405 if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php')) {
409 include($GLOBALS['sugar_config']['cache_dir'].'modules/unified_search_modules.php');
410 $modules_to_search = array();
411 $unified_search_modules['Users'] = array('fields' => array());
413 $unified_search_modules['ProjectTask'] = array('fields' => array());
415 //If we are ignoring the unified search flag within the vardef we need to re-create the search fields. This allows us to search
416 //against a specific module even though it is not enabled for the unified search within the application.
417 if( !$unified_search_only )
419 foreach ($modules as $singleModule)
421 if( !isset($unified_search_modules[$singleModule]) )
423 $newSearchFields = array('fields' => self::$helperObject->generateUnifiedSearchFields($singleModule) );
424 $unified_search_modules[$singleModule] = $newSearchFields;
430 foreach($unified_search_modules as $module=>$data) {
431 if (in_array($module, $modules)) {
432 $modules_to_search[$module] = $beanList[$module];
436 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
438 if(!empty($search_string) && isset($search_string)) {
439 $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH')))));
440 foreach($modules_to_search as $name => $beanName) {
441 $where_clauses_array = array();
442 $unifiedSearchFields = array () ;
443 foreach ($unified_search_modules[$name]['fields'] as $field=>$def ) {
444 $unifiedSearchFields[$name] [ $field ] = $def ;
445 $unifiedSearchFields[$name] [ $field ]['value'] = $search_string;
448 require_once $beanFiles[$beanName] ;
449 $seed = new $beanName();
450 require_once 'include/SearchForm/SearchForm2.php' ;
451 if ($beanName == "User"
452 || $beanName == "ProjectTask"
454 if(!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')){
457 if(!$seed->ACLAccess('ListView')) {
462 if ($beanName != "User"
463 && $beanName != "ProjectTask"
465 $searchForm = new SearchForm ($seed, $name ) ;
467 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
468 $where_clauses = $searchForm->generateSearchWhere() ;
469 require_once 'include/SearchForm/SearchForm2.php' ;
470 $searchForm = new SearchForm ($seed, $name ) ;
472 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
473 $where_clauses = $searchForm->generateSearchWhere() ;
477 if (count($where_clauses) > 0 ) {
478 $where = '('. implode(' ) OR ( ', $where_clauses) . ')';
481 $mod_strings = return_module_language($current_language, $seed->module_dir);
483 if(count($select_fields) > 0)
484 $filterFields = $select_fields;
486 if(file_exists('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php'))
487 require_once('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
489 require_once('modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
491 $filterFields = array();
492 foreach($listViewDefs[$seed->module_dir] as $colName => $param) {
493 if(!empty($param['default']) && $param['default'] == true)
494 $filterFields[] = strtolower($colName);
496 if (!in_array('id', $filterFields))
497 $filterFields[] = 'id';
500 //Pull in any db fields used for the unified search query so the correct joins will be added
501 $selectOnlyQueryFields = array();
502 foreach ($unifiedSearchFields[$name] as $field => $def){
503 if( isset($def['db_field']) && !in_array($field,$filterFields) ){
504 $filterFields[] = $field;
505 $selectOnlyQueryFields[] = $field;
509 //Add the assigned user filter if applicable
510 if (!empty($assigned_user_id) && isset( $seed->field_defs['assigned_user_id']) ) {
511 $ownerWhere = $seed->getOwnerWhere($assigned_user_id);
512 $where = "($where) AND $ownerWhere";
515 if( $beanName == "Employee" )
517 $where = "($where) AND users.deleted = 0 AND users.is_group = 0 AND users.employee_status = 'Active'";
520 $list_params = array();
522 $ret_array = $seed->create_new_list_query('', $where, $filterFields, $list_params, 0, '', true, $seed, true);
523 if(empty($params) or !is_array($params)) $params = array();
524 if(!isset($params['custom_select'])) $params['custom_select'] = '';
525 if(!isset($params['custom_from'])) $params['custom_from'] = '';
526 if(!isset($params['custom_where'])) $params['custom_where'] = '';
527 if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';
528 $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'];
530 if ($beanName == "User") {
531 $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address');
532 $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users ";
533 $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'
534 LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
535 $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'";
537 if ($beanName == "ProjectTask") {
538 $filterFields = array('id', 'name', 'project_id', 'project_name');
539 $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} ";
540 $seed->add_team_security_where_clause($main_query);
541 $main_query .= "LEFT JOIN teams ON $seed->table_name.team_id=teams.id AND (teams.deleted=0) ";
542 $main_query .= "LEFT JOIN project ON $seed->table_name.project_id = project.id ";
543 $main_query .= "where {$seed->table_name}.name like '{$search_string}%'";
547 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query);
548 if($max_results < -1) {
549 $result = $seed->db->query($main_query);
552 if($max_results == -1) {
553 $limit = $sugar_config['list_max_entries_per_page'];
555 $limit = $max_results;
557 $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
561 while($row = $seed->db->fetchByAssoc($result)) {
562 $nameValueArray = array();
563 foreach ($filterFields as $field) {
564 if(in_array($field, $selectOnlyQueryFields))
566 $nameValue = array();
567 if (isset($row[$field])) {
568 $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]);
571 $rowArray[] = $nameValueArray;
573 $output_list[] = array('name' => $name, 'records' => $rowArray);
576 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
577 return array('entry_list'=>$output_list);
579 return array('entry_list'=>$output_list);
585 SugarWebServiceImplv4::$helperObject = new SugarWebServiceUtilv4();