2013-09-23 19:30:44 +00:00
< ? php
2018-07-12 10:40:10 +00:00
if ( ! defined ( 'sugarEntry' )) {
define ( 'sugarEntry' , true );
}
2018-08-01 19:14:25 +00:00
/**
*
2013-09-23 19:30:44 +00:00
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM , Inc . Copyright ( C ) 2004 - 2013 SugarCRM Inc .
2018-08-01 19:14:25 +00:00
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd .
* Copyright ( C ) 2011 - 2018 SalesAgility Ltd .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7 ( a ) : FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM , SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
2018-08-01 19:14:25 +00:00
* FOR A PARTICULAR PURPOSE . See the GNU Affero General Public License for more
2013-09-23 19:30:44 +00:00
* details .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* You should have received a copy of the GNU Affero General Public License along with
* this program ; if not , see http :// www . gnu . org / licenses or write to the Free
* Software Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA
* 02110 - 1301 USA .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* You can contact SugarCRM , Inc . headquarters at 10050 North Wolfe Road ,
* SW2 - 130 , Cupertino , CA 95014 , USA . or at email address contact @ sugarcrm . com .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices , as required under
* Section 5 of the GNU Affero General Public License version 3.
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* In accordance with Section 7 ( b ) of the GNU Affero General Public License version 3 ,
* these Appropriate Legal Notices must retain the display of the " Powered by
2014-07-07 15:33:23 +00:00
* SugarCRM " logo and " Supercharged by SuiteCRM " logo. If the display of the logos is not
2018-08-01 19:14:25 +00:00
* reasonably feasible for technical reasons , the Appropriate Legal Notices must
* display the words " Powered by SugarCRM " and " Supercharged by SuiteCRM " .
*/
2013-09-23 19:30:44 +00:00
/**
2019-10-28 11:44:06 +00:00
* This class is an implementation class for all the rest services
2013-09-23 19:30:44 +00:00
*/
require_once ( 'service/v3_1/SugarWebServiceImplv3_1.php' );
require_once ( 'SugarWebServiceUtilv4.php' );
2018-06-21 20:05:17 +00:00
class SugarWebServiceImplv4 extends SugarWebServiceImplv3_1
{
2013-09-23 19:30:44 +00:00
public function __construct ()
{
self :: $helperObject = new SugarWebServiceUtilv4 ();
}
2018-07-12 10:40:10 +00:00
/**
2013-09-23 19:30:44 +00:00
* Log the user into the application
*
* @ param UserAuth array $user_auth -- Set user_name and password ( password needs to be
* in the right encoding for the type of authentication the user is setup for . For Base
* sugar validation , password is the MD5 sum of the plain text password .
* @ param String $application -- The name of the application you are logging in from . ( Currently unused ) .
* @ param array $name_value_list -- Array of name value pair of extra parameters . As of today only 'language' and 'notifyonsave' is supported
* @ return Array - id - String id is the session_id of the session that was created .
* - module_name - String - module name of user
* - name_value_list - Array - The name value pair of user_id , user_name , user_language , user_currency_id , user_currency_name ,
* - user_default_team_id , user_is_admin , user_default_dateformat , user_default_timeformat
* @ exception 'SoapFault' -- The SOAP error , if any
*/
2018-07-12 10:40:10 +00:00
public function login ( $user_auth , $application = null , $name_value_list = array ())
{
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> info ( " Begin: SugarWebServiceImpl->login( { $user_auth [ 'user_name' ] } , $application , " . print_r ( $name_value_list , true ) . " ) " );
global $sugar_config , $system_config ;
$error = new SoapError ();
2020-01-22 13:50:51 +00:00
$user = BeanFactory :: newBean ( 'Users' );
2013-09-23 19:30:44 +00:00
$success = false ;
//rrs
2020-01-22 13:50:51 +00:00
$system_config = BeanFactory :: newBean ( 'Administration' );
2013-09-23 19:30:44 +00:00
$system_config -> retrieveSettings ( 'system' );
$authController = new AuthenticationController ();
//rrs
2018-07-12 10:40:10 +00:00
if ( ! empty ( $user_auth [ 'encryption' ]) && $user_auth [ 'encryption' ] === 'PLAIN' && $authController -> authController -> userAuthenticateClass != " LDAPAuthenticateUser " ) {
2013-09-23 19:30:44 +00:00
$user_auth [ 'password' ] = md5 ( $user_auth [ 'password' ]);
}
$isLoginSuccess = $authController -> login ( $user_auth [ 'user_name' ], $user_auth [ 'password' ], array ( 'passwordEncrypted' => true ));
$usr_id = $user -> retrieve_user_id ( $user_auth [ 'user_name' ]);
2018-07-12 10:40:10 +00:00
if ( $usr_id ) {
2013-09-23 19:30:44 +00:00
$user -> retrieve ( $usr_id );
2018-07-12 10:40:10 +00:00
}
2013-09-23 19:30:44 +00:00
2018-07-12 10:40:10 +00:00
if ( $isLoginSuccess ) {
if ( $_SESSION [ 'hasExpiredPassword' ] == '1' ) {
2013-09-23 19:30:44 +00:00
$error -> set_error ( 'password_expired' );
$GLOBALS [ 'log' ] -> fatal ( 'password expired for user ' . $user_auth [ 'user_name' ]);
LogicHook :: initialize ();
$GLOBALS [ 'logic_hook' ] -> call_custom_logic ( 'Users' , 'login_failed' );
self :: $helperObject -> setFaultObject ( $error );
return ;
}
2018-07-12 10:40:10 +00:00
if ( ! empty ( $user ) && ! empty ( $user -> id ) && ! $user -> is_group ) {
2013-09-23 19:30:44 +00:00
$success = true ;
global $current_user ;
$current_user = $user ;
}
2018-07-12 10:40:10 +00:00
} elseif ( $usr_id && isset ( $user -> user_name ) && ( $user -> getPreference ( 'lockout' ) == '1' )) {
2013-09-23 19:30:44 +00:00
$error -> set_error ( 'lockout_reached' );
$GLOBALS [ 'log' ] -> fatal ( 'Lockout reached for user ' . $user_auth [ 'user_name' ]);
LogicHook :: initialize ();
$GLOBALS [ 'logic_hook' ] -> call_custom_logic ( 'Users' , 'login_failed' );
self :: $helperObject -> setFaultObject ( $error );
return ;
2018-07-12 10:40:10 +00:00
} elseif ( function_exists ( 'openssl_decrypt' ) && $authController -> authController -> userAuthenticateClass == " LDAPAuthenticateUser "
2018-07-19 10:46:21 +00:00
&& ( empty ( $user_auth [ 'encryption' ]) || $user_auth [ 'encryption' ] !== 'PLAIN' )) {
2013-09-23 19:30:44 +00:00
$password = self :: $helperObject -> decrypt_string ( $user_auth [ 'password' ]);
$authController -> loggedIn = false ; // reset login attempt to try again with decrypted password
2018-07-12 10:40:10 +00:00
if ( $authController -> login ( $user_auth [ 'user_name' ], $password ) && isset ( $_SESSION [ 'authenticated_user_id' ])) {
2013-09-23 19:30:44 +00:00
$success = true ;
2018-07-12 10:40:10 +00:00
}
2018-07-12 14:44:43 +00:00
} elseif ( $authController -> authController -> userAuthenticateClass == " LDAPAuthenticateUser "
&& ( empty ( $user_auth [ 'encryption' ]) || $user_auth [ 'encryption' ] == 'PLAIN' )) {
2018-07-12 10:40:10 +00:00
$authController -> loggedIn = false ; // reset login attempt to try again with md5 password
if ( $authController -> login ( $user_auth [ 'user_name' ], md5 ( $user_auth [ 'password' ]), array ( 'passwordEncrypted' => true ))
2018-07-19 10:46:21 +00:00
&& isset ( $_SESSION [ 'authenticated_user_id' ])) {
2018-07-12 10:40:10 +00:00
$success = true ;
} else {
$error -> set_error ( 'ldap_error' );
LogicHook :: initialize ();
$GLOBALS [ 'logic_hook' ] -> call_custom_logic ( 'Users' , 'login_failed' );
self :: $helperObject -> setFaultObject ( $error );
return ;
}
2013-09-23 19:30:44 +00:00
}
2018-07-12 10:40:10 +00:00
if ( $success ) {
2013-09-23 19:30:44 +00:00
session_start ();
global $current_user ;
//$current_user = $user;
self :: $helperObject -> login_success ( $name_value_list );
$current_user -> loadPreferences ();
$_SESSION [ 'is_valid_session' ] = true ;
$_SESSION [ 'ip_address' ] = query_client_ip ();
$_SESSION [ 'user_id' ] = $current_user -> id ;
$_SESSION [ 'type' ] = 'user' ;
$_SESSION [ 'avail_modules' ] = self :: $helperObject -> get_user_module_list ( $current_user );
$_SESSION [ 'authenticated_user_id' ] = $current_user -> id ;
$_SESSION [ 'unique_key' ] = $sugar_config [ 'unique_key' ];
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->login - successful login' );
$current_user -> call_custom_logic ( 'after_login' );
$nameValueArray = array ();
global $current_language ;
$nameValueArray [ 'user_id' ] = self :: $helperObject -> get_name_value ( 'user_id' , $current_user -> id );
$nameValueArray [ 'user_name' ] = self :: $helperObject -> get_name_value ( 'user_name' , $current_user -> user_name );
$nameValueArray [ 'user_language' ] = self :: $helperObject -> get_name_value ( 'user_language' , $current_language );
$cur_id = $current_user -> getPreference ( 'currency' );
$nameValueArray [ 'user_currency_id' ] = self :: $helperObject -> get_name_value ( 'user_currency_id' , $cur_id );
$nameValueArray [ 'user_is_admin' ] = self :: $helperObject -> get_name_value ( 'user_is_admin' , is_admin ( $current_user ));
2018-07-12 14:44:43 +00:00
$nameValueArray [ 'user_default_team_id' ] = self :: $helperObject -> get_name_value ( 'user_default_team_id' , $current_user -> default_team );
$nameValueArray [ 'user_default_dateformat' ] = self :: $helperObject -> get_name_value ( 'user_default_dateformat' , $current_user -> getPreference ( 'datef' ));
$nameValueArray [ 'user_default_timeformat' ] = self :: $helperObject -> get_name_value ( 'user_default_timeformat' , $current_user -> getPreference ( 'timef' ));
2013-09-23 19:30:44 +00:00
$num_grp_sep = $current_user -> getPreference ( 'num_grp_sep' );
$dec_sep = $current_user -> getPreference ( 'dec_sep' );
2020-02-13 18:18:52 +00:00
$nameValueArray [ 'user_number_separator' ] = self :: $helperObject -> get_name_value ( 'user_number_separator' , empty ( $num_grp_sep ) ? $sugar_config [ 'default_number_grouping_seperator' ] : $num_grp_sep );
$nameValueArray [ 'user_decimal_separator' ] = self :: $helperObject -> get_name_value ( 'user_decimal_separator' , empty ( $dec_sep ) ? $sugar_config [ 'default_decimal_seperator' ] : $dec_sep );
2013-09-23 19:30:44 +00:00
2018-07-12 14:44:43 +00:00
$nameValueArray [ 'mobile_max_list_entries' ] = self :: $helperObject -> get_name_value ( 'mobile_max_list_entries' , $sugar_config [ 'wl_list_max_entries_per_page' ]);
$nameValueArray [ 'mobile_max_subpanel_entries' ] = self :: $helperObject -> get_name_value ( 'mobile_max_subpanel_entries' , $sugar_config [ 'wl_list_max_entries_per_subpanel' ]);
2013-09-23 19:30:44 +00:00
2020-01-22 13:50:51 +00:00
$currencyObject = BeanFactory :: newBean ( 'Currencies' );
2013-09-23 19:30:44 +00:00
$currencyObject -> retrieve ( $cur_id );
$nameValueArray [ 'user_currency_name' ] = self :: $helperObject -> get_name_value ( 'user_currency_name' , $currencyObject -> name );
$_SESSION [ 'user_language' ] = $current_language ;
return array ( 'id' => session_id (), 'module_name' => 'Users' , 'name_value_list' => $nameValueArray );
}
LogicHook :: initialize ();
$GLOBALS [ 'logic_hook' ] -> call_custom_logic ( 'Users' , 'login_failed' );
$error -> set_error ( 'invalid_login' );
self :: $helperObject -> setFaultObject ( $error );
$GLOBALS [ 'log' ] -> error ( 'End: SugarWebServiceImpl->login - failed login' );
}
2018-07-12 10:40:10 +00:00
/**
* Retrieve a list of SugarBean ' s based on provided IDs . This API will not wotk with report module
*
* @ param String $session -- Session ID returned by a previous call to login .
* @ 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 ) ..
* @ param Array $ids -- An array of SugarBean IDs .
* @ 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 .
* @ 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' )))
* @ return Array
* 'entry_list' -- Array - The records name value pair for the simple data types excluding link field data .
* '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 ] => 3 fb16797 - 8 d90 - 0 a94 - ac12 - 490 b63a6be67 ) [ 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 ] => 403 f8da1 - 214 b - 6 a88 - 9 cef - 490 b63d43566 ) [ 1 ] => Array ( [ name ] => email_address [ value ] => kid . hr @ example . name ) [ 2 ] => Array ( [ name ] => opt_out [ value ] => 0 ) [ 3 ] => Array ( [ name ] => primary_address [ value ] => 0 ) ) ) ) )
* @ exception 'SoapFault' -- The SOAP error , if any
*/
2018-01-12 10:54:59 +00:00
public function get_entries (
$session ,
$module_name ,
$ids ,
$select_fields ,
$link_name_to_fields_array ,
$track_view = false
2018-01-12 10:55:15 +00:00
) {
2018-07-19 10:46:21 +00:00
$result = parent :: get_entries (
$session ,
$module_name ,
$ids ,
$select_fields ,
$link_name_to_fields_array ,
$track_view
);
2018-01-12 10:55:15 +00:00
$relationshipList = $result [ 'relationship_list' ];
$returnRelationshipList = array ();
foreach ( $relationshipList as $rel ) {
$link_output = array ();
foreach ( $rel as $row ) {
$rowArray = array ();
foreach ( $row [ 'records' ] as $record ) {
$rowArray [][ 'link_value' ] = $record ;
}
$link_output [] = array ( 'name' => $row [ 'name' ], 'records' => $rowArray );
}
$returnRelationshipList [][ 'link_list' ] = $link_output ;
}
$result [ 'relationship_list' ] = $returnRelationshipList ;
return $result ;
}
2013-09-23 19:30:44 +00:00
2018-07-12 10:40:10 +00:00
/**
2013-09-23 19:30:44 +00:00
* Retrieve a list of beans . This is the primary method for getting list of SugarBeans from Sugar using the SOAP API .
*
2019-04-26 11:19:45 +00:00
* @ param string $session -- Session ID returned by a previous call to login .
* @ 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 ) ..
* @ param string $query -- SQL where clause without the word 'where'
* @ param string $order_by -- SQL order by clause without the phrase 'order by'
2013-09-23 19:30:44 +00:00
* @ param integer $offset -- The record offset to start from .
2019-04-26 11:19:45 +00:00
* @ 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 .
* @ 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' )))
* @ param integer $max_results -- The maximum number of records to return . The default is the sugar configuration value for 'list_max_entries_per_page'
* @ param bool $deleted -- false if deleted records should not be include , true if deleted records should be included .
* @ return array 'result_count' -- integer - The number of records returned
2013-09-23 19:30:44 +00:00
* '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 .
* 'entry_list' -- Array - The records that were retrieved
2019-04-26 11:19:45 +00:00
* '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 ] => 3 fb16797 - 8 d90 - 0 a94 - ac12 - 490 b63a6be67 ) [ 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 ] => 403 f8da1 - 214 b - 6 a88 - 9 cef - 490 b63d43566 ) [ 1 ] => Array ( [ name ] => email_address [ value ] => kid . hr @ example . name ) [ 2 ] => Array ( [ name ] => opt_out [ value ] => 0 ) [ 3 ] => Array ( [ name ] => primary_address [ value ] => 0 ) ) ) ) )
* @ exception 'SoapFault' -- The SOAP error , if any
*/
public function get_entry_list (
$session = null ,
$module_name = null ,
$query = null ,
$order_by = null ,
$offset = null ,
$select_fields = null ,
$link_name_to_fields_array = null ,
$max_results = null ,
$deleted = false ,
$favorites = false
) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->get_entry_list' );
global $beanList , $beanFiles ;
$error = new SoapError ();
$using_cp = false ;
2018-07-12 10:40:10 +00:00
if ( $module_name == 'CampaignProspects' ) {
2013-09-23 19:30:44 +00:00
$module_name = 'Prospects' ;
$using_cp = true ;
}
if ( ! self :: $helperObject -> checkSessionAndModuleAccess ( $session , 'invalid_session' , $module_name , 'read' , 'no_access' , $error )) {
$GLOBALS [ 'log' ] -> error ( 'End: SugarWebServiceImpl->get_entry_list - FAILED on checkSessionAndModuleAccess' );
return ;
} // if
if ( ! self :: $helperObject -> checkQuery ( $error , $query , $order_by )) {
2018-07-12 10:40:10 +00:00
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->get_entry_list' );
return ;
2013-09-23 19:30:44 +00:00
} // if
// If the maximum number of entries per page was specified, override the configuration value.
2018-07-12 10:40:10 +00:00
if ( $max_results > 0 ) {
2013-09-23 19:30:44 +00:00
global $sugar_config ;
$sugar_config [ 'list_max_entries_per_page' ] = $max_results ;
} // if
$class_name = $beanList [ $module_name ];
require_once ( $beanFiles [ $class_name ]);
$seed = new $class_name ();
if ( ! self :: $helperObject -> checkACLAccess ( $seed , 'list' , $error , 'no_access' )) {
$GLOBALS [ 'log' ] -> error ( 'End: SugarWebServiceImpl->get_entry_list - FAILED on checkACLAccess' );
return ;
} // if
2018-07-12 10:40:10 +00:00
if ( $query == '' ) {
2013-09-23 19:30:44 +00:00
$where = '' ;
} // if
2018-07-12 10:40:10 +00:00
if ( $offset == '' || $offset == - 1 ) {
2013-09-23 19:30:44 +00:00
$offset = 0 ;
} // if
2018-07-12 10:40:10 +00:00
if ( $deleted ) {
2013-09-23 19:30:44 +00:00
$deleted = - 1 ;
}
2018-07-12 10:40:10 +00:00
if ( $using_cp ) {
2018-07-16 15:17:46 +00:00
$response = $seed -> retrieveTargetList ( $query , $select_fields , $offset , - 1 , - 1 , $deleted );
2018-07-12 10:40:10 +00:00
} else {
2018-07-16 15:17:46 +00:00
$response = self :: $helperObject -> get_data_list ( $seed , $order_by , $query , $offset , - 1 , - 1 , $deleted , $favorites );
2013-09-23 19:30:44 +00:00
} // else
$list = $response [ 'list' ];
$output_list = array ();
$linkoutput_list = array ();
2018-07-12 10:40:10 +00:00
foreach ( $list as $value ) {
if ( isset ( $value -> emailAddress )) {
2013-09-23 19:30:44 +00:00
$value -> emailAddress -> handleLegacyRetrieve ( $value );
} // if
$value -> fill_in_additional_detail_fields ();
$output_list [] = self :: $helperObject -> get_return_value_for_fields ( $value , $module_name , $select_fields );
2018-07-12 10:40:10 +00:00
if ( ! empty ( $link_name_to_fields_array )) {
2013-09-23 19:30:44 +00:00
$linkoutput_list [] = self :: $helperObject -> get_return_value_for_link_fields ( $value , $module_name , $link_name_to_fields_array );
}
} // foreach
// Calculate the offset for the start of the next page
2019-10-17 12:30:22 +00:00
$next_offset = $offset + count ( $output_list );
2013-09-23 19:30:44 +00:00
2018-07-12 10:40:10 +00:00
$returnRelationshipList = array ();
foreach ( $linkoutput_list as $rel ) {
$link_output = array ();
foreach ( $rel as $row ) {
$rowArray = array ();
foreach ( $row [ 'records' ] as $record ) {
$rowArray [][ 'link_value' ] = $record ;
}
$link_output [] = array ( 'name' => $row [ 'name' ], 'records' => $rowArray );
}
$returnRelationshipList [][ 'link_list' ] = $link_output ;
}
$totalRecordCount = $response [ 'row_count' ];
2018-07-12 14:44:43 +00:00
if ( ! empty ( $sugar_config [ 'disable_count_query' ])) {
2013-09-23 19:30:44 +00:00
$totalRecordCount = - 1 ;
2018-07-12 10:40:10 +00:00
}
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->get_entry_list - SUCCESS' );
2019-10-17 12:30:22 +00:00
return array ( 'result_count' => count ( $output_list ), 'total_count' => $totalRecordCount , 'next_offset' => $next_offset , 'entry_list' => $output_list , 'relationship_list' => $returnRelationshipList );
2013-09-23 19:30:44 +00:00
} // fn
2018-07-12 10:40:10 +00:00
/**
2013-09-23 19:30:44 +00:00
* Retrieve the layout metadata for a given module given a specific type and view .
*
* @ param String $session -- Session ID returned by a previous call to login .
* @ 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 ) ..
* @ return array $type The type ( s ) of views requested . Current supported types are 'default' ( for application ) and 'wireless'
* @ return array $view The view ( s ) requested . Current supported types are edit , detail , list , and subpanel .
* @ exception 'SoapFault' -- The SOAP error , if any
*/
2018-07-17 14:38:41 +00:00
public function get_module_layout ( $session , $a_module_names , $a_type , $a_view , $acl_check = true , $md5 = false )
2018-07-12 10:40:10 +00:00
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->get_module_layout' );
2013-09-23 19:30:44 +00:00
2018-07-12 10:40:10 +00:00
global $beanList , $beanFiles ;
$error = new SoapError ();
2013-09-23 19:30:44 +00:00
$results = array ();
2018-07-12 10:40:10 +00:00
foreach ( $a_module_names as $module_name ) {
if ( ! self :: $helperObject -> checkSessionAndModuleAccess ( $session , 'invalid_session' , $module_name , 'read' , 'no_access' , $error )) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> error ( " End: SugarWebServiceImpl->get_module_layout for $module_name - FAILED on checkSessionAndModuleAccess " );
continue ;
}
2018-07-12 14:44:43 +00:00
if ( empty ( $module_name )) {
2013-09-23 19:30:44 +00:00
continue ;
2018-07-12 10:40:10 +00:00
}
2013-09-23 19:30:44 +00:00
$class_name = $beanList [ $module_name ];
require_once ( $beanFiles [ $class_name ]);
$seed = new $class_name ();
2018-07-12 10:40:10 +00:00
foreach ( $a_view as $view ) {
2013-09-23 19:30:44 +00:00
$aclViewCheck = ( strtolower ( $view ) == 'subpanel' ) ? 'DetailView' : ucfirst ( strtolower ( $view )) . 'View' ;
2018-07-12 14:44:43 +00:00
if ( ! $acl_check || $seed -> ACLAccess ( $aclViewCheck , true )) {
2018-07-12 10:40:10 +00:00
foreach ( $a_type as $type ) {
2013-09-23 19:30:44 +00:00
$a_vardefs = self :: $helperObject -> get_module_view_defs ( $module_name , $type , $view );
2018-07-12 10:40:10 +00:00
if ( $md5 ) {
2013-09-23 19:30:44 +00:00
$results [ $module_name ][ $type ][ $view ] = md5 ( serialize ( $a_vardefs ));
2018-07-12 10:40:10 +00:00
} else {
2013-09-23 19:30:44 +00:00
$results [ $module_name ][ $type ][ $view ] = $a_vardefs ;
2018-07-12 10:40:10 +00:00
}
2013-09-23 19:30:44 +00:00
}
}
}
}
2018-07-16 15:17:46 +00:00
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->get_module_layout ->> ' . print_r ( $results , true ));
2013-09-23 19:30:44 +00:00
return $results ;
}
2018-07-12 10:40:10 +00:00
/**
2013-09-23 19:30:44 +00:00
* Given a list of modules to search and a search string , return the id , module_name , along with the fields
2013-10-30 16:30:58 +00:00
* We will support Accounts , Bugs , Cases , Contacts , Leads , Opportunities , Project , ProjectTask , Quotes
2013-09-23 19:30:44 +00:00
*
* @ param string $session - Session ID returned by a previous call to login .
* @ param string $search_string - string to search
* @ param string [] $modules - array of modules to query
* @ param int $offset - a specified offset in the query
* @ param int $max_results - max number of records to return
* @ param string $assigned_user_id - a user id to filter all records by , leave empty to exclude the filter
* @ param string [] $select_fields - An array of fields to return . If empty the default return fields will be from the active list view defs .
* @ param bool $unified_search_only - A boolean indicating if we should only search against those modules participating in the unified search .
* @ param bool $favorites - A boolean indicating if we should only search against records marked as favorites .
* @ return Array return_search_result - Array ( 'Accounts' => array ( array ( 'name' => 'first_name' , 'value' => 'John' , 'name' => 'last_name' , 'value' => 'Do' )))
* @ exception 'SoapFault' -- The SOAP error , if any
*/
2018-07-17 14:38:41 +00:00
public function search_by_module ( $session , $search_string , $modules , $offset , $max_results , $assigned_user_id = '' , $select_fields = array (), $unified_search_only = true , $favorites = false )
2018-07-12 10:40:10 +00:00
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->search_by_module' );
global $beanList , $beanFiles ;
global $sugar_config , $current_language ;
$error = new SoapError ();
$output_list = array ();
if ( ! self :: $helperObject -> checkSessionAndModuleAccess ( $session , 'invalid_session' , '' , '' , '' , $error )) {
$error -> set_error ( 'invalid_login' );
$GLOBALS [ 'log' ] -> error ( 'End: SugarWebServiceImpl->search_by_module - FAILED on checkSessionAndModuleAccess' );
return ;
}
global $current_user ;
if ( $max_results > 0 ) {
$sugar_config [ 'list_max_entries_per_page' ] = $max_results ;
}
require_once ( 'modules/Home/UnifiedSearchAdvanced.php' );
require_once 'include/utils.php' ;
$usa = new UnifiedSearchAdvanced ();
if ( ! file_exists ( $cachefile = sugar_cached ( 'modules/unified_search_modules.php' ))) {
2013-09-23 19:30:44 +00:00
$usa -> buildCache ();
}
2018-07-12 10:40:10 +00:00
include $cachefile ;
$modules_to_search = array ();
$unified_search_modules [ 'Users' ] = array ( 'fields' => array ());
2013-09-23 19:30:44 +00:00
2018-07-12 10:40:10 +00:00
$unified_search_modules [ 'ProjectTask' ] = array ( 'fields' => array ());
2013-09-23 19:30:44 +00:00
//If we are ignoring the unified search flag within the vardef we need to re-create the search fields. This allows us to search
//against a specific module even though it is not enabled for the unified search within the application.
2018-07-12 14:44:43 +00:00
if ( ! $unified_search_only ) {
2018-07-12 10:40:10 +00:00
foreach ( $modules as $singleModule ) {
2018-07-12 14:44:43 +00:00
if ( ! isset ( $unified_search_modules [ $singleModule ])) {
2013-09-23 19:30:44 +00:00
$newSearchFields = array ( 'fields' => self :: $helperObject -> generateUnifiedSearchFields ( $singleModule ) );
$unified_search_modules [ $singleModule ] = $newSearchFields ;
}
}
}
2018-07-12 10:40:10 +00:00
foreach ( $unified_search_modules as $module => $data ) {
if ( in_array ( $module , $modules )) {
$modules_to_search [ $module ] = $beanList [ $module ];
} // if
2013-09-23 19:30:44 +00:00
} // foreach
$GLOBALS [ 'log' ] -> info ( 'SugarWebServiceImpl->search_by_module - search string = ' . $search_string );
2018-07-12 10:40:10 +00:00
if ( ! empty ( $search_string ) && isset ( $search_string )) {
$search_string = trim ( DBManagerFactory :: getInstance () -> quote ( securexss ( from_html ( clean_string ( $search_string , 'UNIFIED_SEARCH' )))));
foreach ( $modules_to_search as $name => $beanName ) {
$where_clauses_array = array ();
2018-07-19 10:16:53 +00:00
$unifiedSearchFields = array () ;
2018-07-12 14:44:43 +00:00
foreach ( $unified_search_modules [ $name ][ 'fields' ] as $field => $def ) {
2018-07-12 10:40:10 +00:00
$unifiedSearchFields [ $name ] [ $field ] = $def ;
$unifiedSearchFields [ $name ] [ $field ][ 'value' ] = $search_string ;
}
require_once $beanFiles [ $beanName ] ;
$seed = new $beanName ();
require_once 'include/SearchForm/SearchForm2.php' ;
if ( $beanName == " User "
2018-07-19 10:46:21 +00:00
|| $beanName == " ProjectTask "
) {
2018-07-12 10:40:10 +00:00
if ( ! self :: $helperObject -> check_modules_access ( $current_user , $seed -> module_dir , 'read' )) {
continue ;
} // if
if ( ! $seed -> ACLAccess ( 'ListView' )) {
continue ;
} // if
}
if ( $beanName != " User "
2018-07-19 10:46:21 +00:00
&& $beanName != " ProjectTask "
) {
2018-07-12 10:40:10 +00:00
require_once 'include/SearchForm/SearchForm2.php' ;
2018-07-19 10:16:53 +00:00
$searchForm = new SearchForm ( $seed , $name ) ;
2018-07-12 10:40:10 +00:00
2018-07-19 10:16:53 +00:00
$searchForm -> setup ( array ( $name => array ()), $unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
2018-07-12 10:40:10 +00:00
$where_clauses = $searchForm -> generateSearchWhere () ;
$emailQuery = false ;
$where = '' ;
2018-07-12 14:44:43 +00:00
if ( count ( $where_clauses ) > 0 ) {
2018-07-12 10:40:10 +00:00
$where = '(' . implode ( ' ) OR ( ' , $where_clauses ) . ')' ;
}
$mod_strings = return_module_language ( $current_language , $seed -> module_dir );
if ( count ( $select_fields ) > 0 ) {
$filterFields = $select_fields ;
} else {
if ( file_exists ( 'custom/modules/' . $seed -> module_dir . '/metadata/listviewdefs.php' )) {
require_once ( 'custom/modules/' . $seed -> module_dir . '/metadata/listviewdefs.php' );
} else {
require_once ( 'modules/' . $seed -> module_dir . '/metadata/listviewdefs.php' );
}
$filterFields = array ();
foreach ( $listViewDefs [ $seed -> module_dir ] as $colName => $param ) {
if ( ! empty ( $param [ 'default' ]) && $param [ 'default' ] == true ) {
$filterFields [] = strtolower ( $colName );
}
}
if ( ! in_array ( 'id' , $filterFields )) {
$filterFields [] = 'id' ;
}
}
//Pull in any db fields used for the unified search query so the correct joins will be added
$selectOnlyQueryFields = array ();
foreach ( $unifiedSearchFields [ $name ] as $field => $def ) {
2018-07-16 15:17:46 +00:00
if ( isset ( $def [ 'db_field' ]) && ! in_array ( $field , $filterFields )) {
2018-07-12 10:40:10 +00:00
$filterFields [] = $field ;
$selectOnlyQueryFields [] = $field ;
}
}
//Add the assigned user filter if applicable
2018-07-12 14:44:43 +00:00
if ( ! empty ( $assigned_user_id ) && isset ( $seed -> field_defs [ 'assigned_user_id' ])) {
2018-07-12 10:40:10 +00:00
$ownerWhere = $seed -> getOwnerWhere ( $assigned_user_id );
$where = " ( $where ) AND $ownerWhere " ;
}
2018-07-12 14:44:43 +00:00
if ( $beanName == " Employee " ) {
2018-07-12 10:40:10 +00:00
$where = " ( $where ) AND users.deleted = 0 AND users.is_group = 0 AND users.employee_status = 'Active' " ;
}
$list_params = array ();
$ret_array = $seed -> create_new_list_query ( '' , $where , $filterFields , $list_params , 0 , '' , true , $seed , true );
if ( empty ( $params ) or ! is_array ( $params )) {
$params = array ();
}
if ( ! isset ( $params [ 'custom_select' ])) {
$params [ 'custom_select' ] = '' ;
}
if ( ! isset ( $params [ 'custom_from' ])) {
$params [ 'custom_from' ] = '' ;
}
if ( ! isset ( $params [ 'custom_where' ])) {
$params [ 'custom_where' ] = '' ;
}
if ( ! isset ( $params [ 'custom_order_by' ])) {
$params [ 'custom_order_by' ] = '' ;
}
$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' ];
} else {
if ( $beanName == " User " ) {
$filterFields = array ( 'id' , 'user_name' , 'first_name' , 'last_name' , 'email_address' );
$main_query = " select users.id, ea.email_address, users.user_name, first_name, last_name from users " ;
$main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = ' { $seed -> module_dir } '
2013-09-23 19:30:44 +00:00
LEFT JOIN email_addresses ea ON ( ea . id = eabl . email_address_id ) " ;
2018-07-12 10:40:10 +00:00
$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' " ;
} // if
if ( $beanName == " ProjectTask " ) {
$filterFields = array ( 'id' , 'name' , 'project_id' , 'project_name' );
$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 } " ;
$main_query .= " LEFT JOIN project ON $seed->table_name .project_id = project.id " ;
$main_query .= " where { $seed -> table_name } .name like ' { $search_string } %' " ;
} // if
} // else
2013-09-23 19:30:44 +00:00
2018-07-19 10:46:21 +00:00
$GLOBALS [ 'log' ] -> info ( 'SugarWebServiceImpl->search_by_module - query = ' . $main_query );
2018-07-12 10:40:10 +00:00
if ( $max_results < - 1 ) {
$result = $seed -> db -> query ( $main_query );
} else {
if ( $max_results == - 1 ) {
$limit = $sugar_config [ 'list_max_entries_per_page' ];
} else {
$limit = $max_results ;
}
$result = $seed -> db -> limitQuery ( $main_query , $offset , $limit + 1 );
}
$rowArray = array ();
while ( $row = $seed -> db -> fetchByAssoc ( $result )) {
$nameValueArray = array ();
foreach ( $filterFields as $field ) {
if ( in_array ( $field , $selectOnlyQueryFields )) {
continue ;
}
$nameValue = array ();
if ( isset ( $row [ $field ])) {
$nameValueArray [ $field ] = self :: $helperObject -> get_name_value ( $field , $row [ $field ]);
} // if
} // foreach
2018-07-19 10:46:21 +00:00
$rowArray [] = $nameValueArray ;
2018-07-12 10:40:10 +00:00
} // while
$output_list [] = array ( 'name' => $name , 'records' => $rowArray );
} // foreach
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->search_by_module' );
return array ( 'entry_list' => $output_list );
} // if
return array ( 'entry_list' => $output_list );
2013-09-23 19:30:44 +00:00
} // fn
/**
* Get OAuth reqtest token
*/
public function oauth_request_token ()
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->oauth_request_token' );
require_once " include/SugarOAuthServer.php " ;
try {
2018-07-16 15:17:46 +00:00
$oauth = new SugarOAuthServer ( rtrim ( $GLOBALS [ 'sugar_config' ][ 'site_url' ], '/' ) . '/service/v4/rest.php' );
2018-07-12 10:40:10 +00:00
$result = $oauth -> requestToken () . " &oauth_callback_confirmed=true&authorize_url= " . $oauth -> authURL ();
} catch ( OAuthException $e ) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> debug ( " OAUTH Exception: $e " );
$errorObject = new SoapError ();
$errorObject -> set_error ( 'invalid_login' );
2018-07-12 10:40:10 +00:00
self :: $helperObject -> setFaultObject ( $errorObject );
2013-09-23 19:30:44 +00:00
$result = null ;
}
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->oauth_request_token' );
return $result ;
}
/**
* Get OAuth access token
*/
public function oauth_access_token ()
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->oauth_access_token' );
require_once " include/SugarOAuthServer.php " ;
try {
2018-07-12 10:40:10 +00:00
$oauth = new SugarOAuthServer ();
$result = $oauth -> accessToken ();
} catch ( OAuthException $e ) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> debug ( " OAUTH Exception: $e " );
$errorObject = new SoapError ();
$errorObject -> set_error ( 'invalid_login' );
2018-07-12 10:40:10 +00:00
self :: $helperObject -> setFaultObject ( $errorObject );
2013-09-23 19:30:44 +00:00
$result = null ;
}
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->oauth_access_token' );
return $result ;
}
public function oauth_access ( $session = '' )
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->oauth_access' );
$error = new SoapError ();
2018-07-12 10:40:10 +00:00
$output_list = array ();
if ( ! self :: $helperObject -> checkSessionAndModuleAccess ( $session , 'invalid_session' , '' , '' , '' , $error )) {
$error -> set_error ( 'invalid_login' );
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->oauth_access' );
$result = $error ;
} else {
2013-09-23 19:30:44 +00:00
$result = array ( 'id' => session_id ());
2018-07-12 10:40:10 +00:00
}
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->oauth_access' );
return $result ;
}
/**
* Get next job from the queue
* @ param string $session
* @ param string $clientid
*/
public function job_queue_next ( $session , $clientid )
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->job_queue_next' );
$error = new SoapError ();
2018-07-16 15:17:46 +00:00
if ( ! self :: $helperObject -> checkSessionAndModuleAccess ( $session , 'invalid_session' , '' , 'read' , 'no_access' , $error )) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->job_queue_next denied.' );
return ;
}
require_once 'include/SugarQueue/SugarJobQueue.php' ;
$queue = new SugarJobQueue ();
$job = $queue -> nextJob ( $clientid );
2018-07-12 10:40:10 +00:00
if ( ! empty ( $job )) {
2013-09-23 19:30:44 +00:00
$jobid = $job -> id ;
} else {
$jobid = null ;
}
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->job_queue_next' );
return array ( " results " => $jobid );
}
/**
* Run cleanup and schedule
* @ param string $session
* @ param string $clientid
*/
public function job_queue_cycle ( $session , $clientid )
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->job_queue_cycle' );
$error = new SoapError ();
2018-07-16 15:17:46 +00:00
if ( ! self :: $helperObject -> checkSessionAndModuleAccess ( $session , 'invalid_session' , '' , 'read' , 'no_access' , $error )) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->job_queue_cycle denied.' );
return ;
}
require_once 'include/SugarQueue/SugarJobQueue.php' ;
$queue = new SugarJobQueue ();
$queue -> cleanup ();
$queue -> runSchedulers ();
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->job_queue_cycle' );
return array ( " results " => " ok " );
}
/**
* Run job from queue
* @ param string $session
* @ param string $jobid
* @ param string $clientid
*/
public function job_queue_run ( $session , $jobid , $clientid )
{
$GLOBALS [ 'log' ] -> info ( 'Begin: SugarWebServiceImpl->job_queue_run' );
$error = new SoapError ();
2018-07-16 15:17:46 +00:00
if ( ! self :: $helperObject -> checkSessionAndModuleAccess ( $session , 'invalid_session' , '' , 'read' , 'no_access' , $error )) {
2013-09-23 19:30:44 +00:00
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->job_queue_run denied.' );
return ;
}
$GLOBALS [ 'log' ] -> debug ( 'Starting job $jobid execution as $clientid' );
require_once 'modules/SchedulersJobs/SchedulersJob.php' ;
$result = SchedulersJob :: runJobId ( $jobid , $clientid );
$GLOBALS [ 'log' ] -> info ( 'End: SugarWebServiceImpl->job_queue_run' );
2018-07-12 10:40:10 +00:00
if ( $result === true ) {
2013-09-23 19:30:44 +00:00
return array ( " results " => true );
2018-07-24 14:42:22 +00:00
}
return array ( " results " => false , " message " => $result );
2013-09-23 19:30:44 +00:00
}
}
SugarWebServiceImplv4 :: $helperObject = new SugarWebServiceUtilv4 ();