2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2013 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 ********************************************************************************/
38 require_once('soap/SoapHelperFunctions.php');
39 require_once('soap/SoapTypes.php');
41 /*************************************************************************************
43 THIS IS FOR SUGARCRM USERS
46 *************************************************************************************/
47 $disable_date_format = true;
51 array('session'=>'xsd:string'),
52 array('return'=>'xsd:int'),
56 * Return if the user is an admin or not
58 * @param String $session -- Session ID returned by a previous call to login.
59 * @return int 1 or 0 depending on if the user is an admin
61 function is_user_admin($session){
62 if(validate_authenticated($session)){
64 return is_admin($current_user);
74 array('user_auth'=>'tns:user_auth', 'application_name'=>'xsd:string'),
75 array('return'=>'tns:set_entry_result'),
79 * Log the user into the application
81 * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
82 * in the right encoding for the type of authentication the user is setup for. For Base
83 * sugar validation, password is the MD5 sum of the plain text password.
84 * @param String $application -- The name of the application you are logging in from. (Currently unused).
85 * @return Array(session_id, error) -- session_id is the id of the session that was
86 * created. Error is set if there was any error during creation.
88 function login($user_auth, $application){
89 global $sugar_config, $system_config;
91 $error = new SoapError();
95 $system_config = new Administration();
96 $system_config->retrieveSettings('system');
97 $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
99 $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
100 $usr_id=$user->retrieve_user_id($user_auth['user_name']);
102 $user->retrieve($usr_id);
105 if ($isLoginSuccess) {
106 if ($_SESSION['hasExpiredPassword'] =='1') {
107 $error->set_error('password_expired');
108 $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
109 LogicHook::initialize();
110 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
111 return array('id'=>-1, 'error'=>$error);
113 if(!empty($user) && !empty($user->id) && !$user->is_group) {
115 global $current_user;
116 $current_user = $user;
118 } else if($usr_id && isset($user->user_name) && ($user->getPreference('lockout') == '1')) {
119 $error->set_error('lockout_reached');
120 $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
121 LogicHook::initialize();
122 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
123 return array('id'=>-1, 'error'=>$error);
124 } else if(function_exists('mcrypt_cbc')){
125 $password = decrypt_string($user_auth['password']);
126 $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
127 if($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])){
134 global $current_user;
135 //$current_user = $user;
137 $current_user->loadPreferences();
138 $_SESSION['is_valid_session']= true;
139 $_SESSION['ip_address'] = query_client_ip();
140 $_SESSION['user_id'] = $current_user->id;
141 $_SESSION['type'] = 'user';
142 $_SESSION['avail_modules']= get_user_module_list($current_user);
143 $_SESSION['authenticated_user_id'] = $current_user->id;
144 $_SESSION['unique_key'] = $sugar_config['unique_key'];
146 $current_user->call_custom_logic('after_login');
147 return array('id'=>session_id(), 'error'=>$error);
149 $error->set_error('invalid_login');
150 $GLOBALS['log']->fatal('SECURITY: User authentication for '. $user_auth['user_name']. ' failed');
151 LogicHook::initialize();
152 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
153 return array('id'=>-1, 'error'=>$error);
157 //checks if the soap server and client are running on the same machine
161 array('return'=>'xsd:int'),
165 * Check to see if the soap server and client are on the same machine.
166 * We don't allow a server to sync to itself.
168 * @return true -- if the SOAP server and client are on the same machine
169 * @return false -- if the SOAP server and client are not on the same machine.
171 function is_loopback(){
172 if(query_client_ip() == $_SERVER['SERVER_ADDR'])
178 * Validate the provided session information is correct and current. Load the session.
180 * @param String $session_id -- The session ID that was returned by a call to login.
181 * @return true -- If the session is valid and loaded.
182 * @return false -- if the session is not valid.
184 function validate_authenticated($session_id){
185 if(!empty($session_id)){
186 session_id($session_id);
189 if(!empty($_SESSION['is_valid_session']) && is_valid_ip_address('ip_address') && $_SESSION['type'] == 'user'){
191 global $current_user;
193 $current_user = new User();
194 $current_user->retrieve($_SESSION['user_id']);
201 LogicHook::initialize();
202 $GLOBALS['log']->fatal('SECURITY: The session ID is invalid');
203 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
208 * Use the same logic as in SugarAuthenticate to validate the ip address
210 * @param string $session_var
211 * @return bool - true if the ip address is valid, false otherwise.
213 function is_valid_ip_address($session_var){
214 global $sugar_config;
215 // grab client ip address
216 $clientIP = query_client_ip();
218 // check to see if config entry is present, if not, verify client ip
219 if (!isset ($sugar_config['verify_client_ip']) || $sugar_config['verify_client_ip'] == true) {
220 // check to see if we've got a current ip address in $_SESSION
221 // and check to see if the session has been hijacked by a foreign ip
222 if (isset ($_SESSION[$session_var])) {
223 $session_parts = explode(".", $_SESSION[$session_var]);
224 $client_parts = explode(".", $clientIP);
225 if(count($session_parts) < 4) {
228 // match class C IP addresses
229 for ($i = 0; $i < 3; $i ++) {
230 if ($session_parts[$i] == $client_parts[$i]) {
239 // we have a different IP address
240 if ($_SESSION[$session_var] != $clientIP && empty ($classCheck)) {
241 $GLOBALS['log']->fatal("IP Address mismatch: SESSION IP: {$_SESSION[$session_var]} CLIENT IP: {$clientIP}");
253 array('session'=>'xsd:string'),
254 array('return'=>'xsd:int'),
258 * Perform a seamless login. This is used internally during the sync process.
260 * @param String $session -- Session ID returned by a previous call to login.
261 * @return true -- if the session was authenticated
262 * @return false -- if the session could not be authenticated
264 function seamless_login($session){
265 if(!validate_authenticated($session)){
274 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'query'=>'xsd:string', 'order_by'=>'xsd:string','offset'=>'xsd:int', 'select_fields'=>'tns:select_fields', 'max_results'=>'xsd:int', 'deleted'=>'xsd:int'),
275 array('return'=>'tns:get_entry_list_result'),
279 * Retrieve a list of beans. This is the primary method for getting list of SugarBeans from Sugar using the SOAP API.
281 * @param String $session -- Session ID returned by a previous call to login.
282 * @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)..
283 * @param String $query -- SQL where clause without the word 'where'
284 * @param String $order_by -- SQL order by clause without the phrase 'order by'
285 * @param String $offset -- The record offset to start from.
286 * @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.
287 * @param String $max_results -- The maximum number of records to return. The default is the sugar configuration value for 'list_max_entries_per_page'
288 * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
289 * @return Array 'result_count' -- The number of records returned
290 * 'next_offset' -- 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.
291 * 'field_list' -- The vardef information on the selected fields.
292 * Array -- 'field'=> 'name' -- the name of the field
293 * 'type' -- the data type of the field
294 * 'label' -- the translation key for the label of the field
295 * 'required' -- Is the field required?
296 * 'options' -- Possible values for a drop down field
297 * 'entry_list' -- The records that were retrieved
298 * 'error' -- The SOAP error, if any
300 function get_entry_list($session, $module_name, $query, $order_by,$offset, $select_fields, $max_results, $deleted ){
301 global $beanList, $beanFiles, $current_user;
302 $error = new SoapError();
303 if(!validate_authenticated($session)){
304 $error->set_error('invalid_login');
305 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
308 if($module_name == 'CampaignProspects'){
309 $module_name = 'Prospects';
312 if(empty($beanList[$module_name])){
313 $error->set_error('no_module');
314 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
316 global $current_user;
317 if(!check_modules_access($current_user, $module_name, 'read')){
318 $error->set_error('no_access');
319 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
322 // If the maximum number of entries per page was specified, override the configuration value.
323 if($max_results > 0){
324 global $sugar_config;
325 $sugar_config['list_max_entries_per_page'] = $max_results;
329 $class_name = $beanList[$module_name];
330 require_once($beanFiles[$class_name]);
331 $seed = new $class_name();
332 if(! ($seed->ACLAccess('Export') && $seed->ACLAccess('list')))
334 $error->set_error('no_access');
335 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
338 require_once 'include/SugarSQLValidate.php';
339 $valid = new SugarSQLValidate();
340 if(!$valid->validateQueryClauses($query, $order_by)) {
341 $GLOBALS['log']->error("Bad query: $query $order_by");
342 $error->set_error('no_access');
344 'result_count' => -1,
345 'error' => $error->get_soap_array()
351 if($offset == '' || $offset == -1){
355 $response = $seed->retrieveTargetList($query, $select_fields, $offset,-1,-1,$deleted);
357 $response = $seed->get_list($order_by, $query, $offset,-1,-1,$deleted,true);
359 $list = $response['list'];
362 $output_list = array();
364 $isEmailModule = false;
365 if($module_name == 'Emails'){
366 $isEmailModule = true;
368 // retrieve the vardef information on the bean's fields.
369 $field_list = array();
371 require_once 'modules/Currencies/Currency.php';
373 $userCurrencyId = $current_user->getPreference('currency');
374 $userCurrency = new Currency;
375 $userCurrency->retrieve($userCurrencyId);
377 foreach($list as $value)
379 if(isset($value->emailAddress)){
380 $value->emailAddress->handleLegacyRetrieve($value);
383 $value->retrieveEmailText();
385 $value->fill_in_additional_detail_fields();
387 // bug 55129 - populate currency from user settings
388 if (property_exists($value, 'currency_id') && $userCurrency->deleted != 1)
390 // walk through all currency-related fields
391 foreach ($value->field_defs as $temp_field)
393 if (isset($temp_field['type']) && 'relate' == $temp_field['type']
394 && isset($temp_field['module']) && 'Currencies' == $temp_field['module']
395 && isset($temp_field['id_name']) && 'currency_id' == $temp_field['id_name'])
397 // populate related properties manually
398 $temp_property = $temp_field['name'];
399 $currency_property = $temp_field['rname'];
400 $value->$temp_property = $userCurrency->$currency_property;
402 else if ($value->currency_id != $userCurrency->id
403 && isset($temp_field['type'])
404 && 'currency' == $temp_field['type']
405 && substr($temp_field['name'], -9) != '_usdollar')
407 $temp_property = $temp_field['name'];
408 $value->$temp_property *= $userCurrency->conversion_rate;
412 $value->currency_id = $userCurrencyId;
416 $output_list[] = get_return_value($value, $module_name);
417 if(empty($field_list)){
418 $field_list = get_field_list($value);
422 // Filter the search results to only include the requested fields.
423 $output_list = filter_return_list($output_list, $select_fields, $module_name);
425 // Filter the list of fields to only include information on the requested fields.
426 $field_list = filter_return_list($field_list,$select_fields, $module_name);
428 // Calculate the offset for the start of the next page
429 $next_offset = $offset + sizeof($output_list);
431 return array('result_count'=>sizeof($output_list), 'next_offset'=>$next_offset,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
436 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'id'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
437 array('return'=>'tns:get_entry_result'),
441 * Retrieve a single SugarBean based on ID.
443 * @param String $session -- Session ID returned by a previous call to login.
444 * @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)..
445 * @param String $id -- The SugarBean's ID value.
446 * @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.
449 function get_entry($session, $module_name, $id,$select_fields ){
450 return get_entries($session, $module_name, array($id), $select_fields);
455 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'ids'=>'tns:select_fields', 'select_fields'=>'tns:select_fields'),
456 array('return'=>'tns:get_entry_result'),
460 * Retrieve a list of SugarBean's based on provided IDs.
462 * @param String $session -- Session ID returned by a previous call to login.
463 * @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)..
464 * @param Array $ids -- An array of SugarBean IDs.
465 * @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.
466 * @return Array 'field_list' -- Var def information about the returned fields
467 * 'entry_list' -- The records that were retrieved
468 * 'error' -- The SOAP error, if any
470 function get_entries($session, $module_name, $ids,$select_fields ){
471 global $beanList, $beanFiles;
472 $error = new SoapError();
473 $field_list = array();
474 $output_list = array();
475 if(!validate_authenticated($session)){
476 $error->set_error('invalid_login');
477 return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
480 if($module_name == 'CampaignProspects'){
481 $module_name = 'Prospects';
484 if(empty($beanList[$module_name])){
485 $error->set_error('no_module');
486 return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
488 global $current_user;
489 if(!check_modules_access($current_user, $module_name, 'read')){
490 $error->set_error('no_access');
491 return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
494 $class_name = $beanList[$module_name];
495 require_once($beanFiles[$class_name]);
497 //todo can modify in there to call bean->get_list($order_by, $where, 0, -1, -1, $deleted);
498 //that way we do not have to call retrieve for each bean
499 //perhaps also add a select_fields to this, so we only get the fields we need
500 //and not do a select *
501 foreach($ids as $id){
502 $seed = new $class_name();
505 $seed = $seed->retrieveTarget($id);
507 if ($seed->retrieve($id) == null)
511 if ($seed->deleted == 1) {
513 $list[] = array('name'=>'warning', 'value'=>'Access to this object is denied since it has been deleted or does not exist');
514 $list[] = array('name'=>'deleted', 'value'=>'1');
515 $output_list[] = Array('id'=>$id,
516 'module_name'=> $module_name,
517 'name_value_list'=>$list,
521 if(! $seed->ACLAccess('DetailView')){
522 $error->set_error('no_access');
523 return array('field_list'=>$field_list, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
525 $output_list[] = get_return_value($seed, $module_name);
527 if(empty($field_list)){
528 $field_list = get_field_list($seed);
533 $output_list = filter_return_list($output_list, $select_fields, $module_name);
534 $field_list = filter_field_list($field_list,$select_fields, $module_name);
536 return array( 'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
541 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'name_value_list'=>'tns:name_value_list'),
542 array('return'=>'tns:set_entry_result'),
546 * Update or create a single SugarBean.
548 * @param String $session -- Session ID returned by a previous call to login.
549 * @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)..
550 * @param Array $name_value_list -- The keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
551 * @return Array 'id' -- the ID of the bean that was written to (-1 on error)
552 * 'error' -- The SOAP error if any.
554 function set_entry($session,$module_name, $name_value_list){
555 global $beanList, $beanFiles;
557 $error = new SoapError();
558 if(!validate_authenticated($session)){
559 $error->set_error('invalid_login');
560 return array('id'=>-1, 'error'=>$error->get_soap_array());
562 if(empty($beanList[$module_name])){
563 $error->set_error('no_module');
564 return array('id'=>-1, 'error'=>$error->get_soap_array());
566 global $current_user;
567 if(!check_modules_access($current_user, $module_name, 'write')){
568 $error->set_error('no_access');
569 return array('id'=>-1, 'error'=>$error->get_soap_array());
572 $class_name = $beanList[$module_name];
573 require_once($beanFiles[$class_name]);
574 $seed = new $class_name();
576 foreach($name_value_list as $value){
577 if($value['name'] == 'id' && isset($value['value']) && strlen($value['value']) > 0){
578 $result = $seed->retrieve($value['value']);
579 //bug: 44680 - check to ensure the user has access before proceeding.
582 $error->set_error('no_access');
583 return array('id'=>-1, 'error'=>$error->get_soap_array());
592 foreach($name_value_list as $value){
593 $GLOBALS['log']->debug($value['name']." : ".$value['value']);
594 $seed->$value['name'] = $value['value'];
596 if(! $seed->ACLAccess('Save') || ($seed->deleted == 1 && !$seed->ACLAccess('Delete')))
598 $error->set_error('no_access');
599 return array('id'=>-1, 'error'=>$error->get_soap_array());
602 if($seed->deleted == 1){
603 $seed->mark_deleted($seed->id);
605 return array('id'=>$seed->id, 'error'=>$error->get_soap_array());
611 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'name_value_lists'=>'tns:name_value_lists'),
612 array('return'=>'tns:set_entries_result'),
616 * Update or create a list of SugarBeans
618 * @param String $session -- Session ID returned by a previous call to login.
619 * @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)..
620 * @param Array $name_value_lists -- Array of Bean specific Arrays where the keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
621 * @return Array 'ids' -- Array of the IDs of the beans that was written to (-1 on error)
622 * 'error' -- The SOAP error if any.
624 function set_entries($session,$module_name, $name_value_lists){
625 $error = new SoapError();
627 if(!validate_authenticated($session)){
628 $error->set_error('invalid_login');
632 'error' => $error->get_soap_array()
636 return handle_set_entries($module_name, $name_value_lists, FALSE);
643 'set_note_attachment',
644 array('session'=>'xsd:string','note'=>'tns:note_attachment'),
645 array('return'=>'tns:set_entry_result'),
649 * Add or replace the attachment on a Note.
651 * @param String $session -- Session ID returned by a previous call to login.
652 * @param Binary $note -- The flie contents of the attachment.
653 * @return Array 'id' -- The ID of the new note or -1 on error
654 * 'error' -- The SOAP error if any.
656 function set_note_attachment($session,$note)
659 $error = new SoapError();
660 if(!validate_authenticated($session)){
661 $error->set_error('invalid_login');
662 return array('id'=>-1, 'error'=>$error->get_soap_array());
665 require_once('modules/Notes/NoteSoap.php');
666 $ns = new NoteSoap();
667 return array('id'=>$ns->saveFile($note), 'error'=>$error->get_soap_array());
672 'get_note_attachment',
673 array('session'=>'xsd:string', 'id'=>'xsd:string'),
674 array('return'=>'tns:return_note_attachment'),
678 * Retrieve an attachment from a note
679 * @param String $session -- Session ID returned by a previous call to login.
680 * @param Binary $note -- The flie contents of the attachment.
681 * @return Array 'id' -- The ID of the new note or -1 on error
682 * 'error' -- The SOAP error if any.
684 * @param String $session -- Session ID returned by a previous call to login.
685 * @param String $id -- The ID of the appropriate Note.
686 * @return Array 'note_attachment' -- Array String 'id' -- The ID of the Note containing the attachment
687 * String 'filename' -- The file name of the attachment
688 * Binary 'file' -- The binary contents of the file.
689 * 'error' -- The SOAP error if any.
691 function get_note_attachment($session,$id)
693 $error = new SoapError();
694 if(!validate_authenticated($session)){
695 $error->set_error('invalid_login');
696 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
701 $note->retrieve($id);
702 if(!$note->ACLAccess('DetailView')){
703 $error->set_error('no_access');
704 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
706 require_once('modules/Notes/NoteSoap.php');
707 $ns = new NoteSoap();
708 if(!isset($note->filename)){
709 $note->filename = '';
711 $file= $ns->retrieveFile($id,$note->filename);
713 $error->set_error('no_file');
717 return array('note_attachment'=>array('id'=>$id, 'filename'=>$note->filename, 'file'=>$file), 'error'=>$error->get_soap_array());
721 'relate_note_to_module',
722 array('session'=>'xsd:string', 'note_id'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string'),
723 array('return'=>'tns:error_value'),
727 * Attach a note to another bean. Once you have created a note to store an
728 * attachment, the note needs to be related to the bean.
730 * @param String $session -- Session ID returned by a previous call to login.
731 * @param String $note_id -- The ID of the note that you want to associate with a bean
732 * @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)..
733 * @param String $module_id -- The ID of the bean that you want to associate the note with
734 * @return no error for success, error for failure
736 function relate_note_to_module($session,$note_id, $module_name, $module_id){
737 global $beanList, $beanFiles;
738 $error = new SoapError();
739 if(!validate_authenticated($session)){
740 $error->set_error('invalid_login');
741 return $error->get_soap_array();
743 if(empty($beanList[$module_name])){
744 $error->set_error('no_module');
745 return $error->get_soap_array();
747 global $current_user;
748 if(!check_modules_access($current_user, $module_name, 'read')){
749 $error->set_error('no_access');
750 return $error->get_soap_array();
752 $class_name = $beanList['Notes'];
753 require_once($beanFiles[$class_name]);
754 $seed = new $class_name();
755 $seed->retrieve($note_id);
756 if(!$seed->ACLAccess('ListView')){
757 $error->set_error('no_access');
758 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
761 if($module_name != 'Contacts'){
762 $seed->parent_type=$module_name;
763 $seed->parent_id = $module_id;
767 $seed->contact_id=$module_id;
773 return $error->get_soap_array();
778 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string', 'select_fields'=>'tns:select_fields'),
779 array('return'=>'tns:get_entry_result'),
783 * Retrieve the collection of notes that are related to a bean.
785 * @param String $session -- Session ID returned by a previous call to login.
786 * @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)..
787 * @param String $module_id -- The ID of the bean that you want to associate the note with
788 * @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.
789 * @return Array 'result_count' -- The number of records returned (-1 on error)
790 * 'next_offset' -- 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.
791 * 'field_list' -- The vardef information on the selected fields.
792 * 'entry_list' -- The records that were retrieved
793 * 'error' -- The SOAP error, if any
795 function get_related_notes($session,$module_name, $module_id, $select_fields){
796 global $beanList, $beanFiles;
797 $error = new SoapError();
798 if(!validate_authenticated($session)){
799 $error->set_error('invalid_login');
800 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
802 if(empty($beanList[$module_name])){
803 $error->set_error('no_module');
804 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
806 global $current_user;
807 if(!check_modules_access($current_user, $module_name, 'read')){
808 $error->set_error('no_access');
809 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
812 $class_name = $beanList[$module_name];
813 require_once($beanFiles[$class_name]);
814 $seed = new $class_name();
815 $seed->retrieve($module_id);
816 if(!$seed->ACLAccess('DetailView')){
817 $error->set_error('no_access');
818 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
820 $list = $seed->get_linked_beans('notes','Note', array(), 0, -1, 0);
822 $output_list = Array();
823 $field_list = Array();
824 foreach($list as $value)
826 $output_list[] = get_return_value($value, 'Notes');
827 if(empty($field_list))
829 $field_list = get_field_list($value);
832 $output_list = filter_return_list($output_list, $select_fields, $module_name);
833 $field_list = filter_field_list($field_list,$select_fields, $module_name);
835 return array('result_count'=>sizeof($output_list), 'next_offset'=>0,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
840 array('session'=>'xsd:string'),
841 array('return'=>'tns:error_value'),
845 * Log out of the session. This will destroy the session and prevent other's from using it.
847 * @param String $session -- Session ID returned by a previous call to login.
848 * @return Empty error on success, Error on failure
850 function logout($session){
851 global $current_user;
853 $error = new SoapError();
854 LogicHook::initialize();
855 if(validate_authenticated($session)){
856 $current_user->call_custom_logic('before_logout');
858 $GLOBALS['logic_hook']->call_custom_logic('Users', 'after_logout');
859 return $error->get_soap_array();
861 $error->set_error('no_session');
862 $GLOBALS['logic_hook']->call_custom_logic('Users', 'after_logout');
863 return $error->get_soap_array();
868 array('session'=>'xsd:string', 'module_name'=>'xsd:string'),
869 array('return'=>'tns:module_fields'),
873 * Retrieve vardef information on the fields of the specified bean.
875 * @param String $session -- Session ID returned by a previous call to login.
876 * @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)..
877 * @return Array 'module_fields' -- The vardef information on the selected fields.
878 * 'error' -- The SOAP error, if any
880 function get_module_fields($session, $module_name){
881 global $beanList, $beanFiles;
882 $error = new SoapError();
883 $module_fields = array();
884 if(! validate_authenticated($session)){
885 $error->set_error('invalid_session');
886 return array('module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
888 if(empty($beanList[$module_name])){
889 $error->set_error('no_module');
890 return array('module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
892 global $current_user;
893 if(!check_modules_access($current_user, $module_name, 'read')){
894 $error->set_error('no_access');
895 return array('module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
897 $class_name = $beanList[$module_name];
899 if(empty($beanFiles[$class_name]))
901 $error->set_error('no_file');
902 return array('module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
905 require_once($beanFiles[$class_name]);
906 $seed = new $class_name();
907 if($seed->ACLAccess('ListView', true) || $seed->ACLAccess('DetailView', true) || $seed->ACLAccess('EditView', true) )
909 return get_return_module_fields($seed, $module_name, $error);
913 $error->set_error('no_access');
914 return array('module_fields'=>$module_fields, 'error'=>$error->get_soap_array());
919 'get_available_modules',
920 array('session'=>'xsd:string'),
921 array('return'=>'tns:module_list'),
925 * Retrieve the list of available modules on the system available to the currently logged in user.
927 * @param String $session -- Session ID returned by a previous call to login.
928 * @return Array 'modules' -- An array of module names
929 * 'error' -- The SOAP error, if any
931 function get_available_modules($session){
932 $error = new SoapError();
934 if(! validate_authenticated($session)){
935 $error->set_error('invalid_session');
936 return array('modules'=> $modules, 'error'=>$error->get_soap_array());
938 $modules = array_keys($_SESSION['avail_modules']);
940 return array('modules'=> $modules, 'error'=>$error->get_soap_array());
945 'update_portal_user',
946 array('session'=>'xsd:string', 'portal_name'=>'xsd:string', 'name_value_list'=>'tns:name_value_list'),
947 array('return'=>'tns:error_value'),
951 * Update the properties of a contact that is portal user. Add the portal user name to the user's properties.
953 * @param String $session -- Session ID returned by a previous call to login.
954 * @param String $portal_name -- The portal user_name of the contact
955 * @param Array $name_value_list -- collection of 'name'=>'value' pairs for finding the contact
956 * @return Empty error on success, Error on failure
958 function update_portal_user($session,$portal_name, $name_value_list){
959 global $beanList, $beanFiles;
960 $error = new SoapError();
961 if(! validate_authenticated($session)){
962 $error->set_error('invalid_session');
963 return $error->get_soap_array();
965 $contact = new Contact();
967 $searchBy = array('deleted'=>0);
968 foreach($name_value_list as $name_value){
969 $searchBy[$name_value['name']] = $name_value['value'];
971 if($contact->retrieve_by_string_fields($searchBy) != null){
972 if(!$contact->duplicates_found){
973 $contact->portal_name = $portal_name;
974 $contact->portal_active = 1;
975 if($contact->ACLAccess('Save')){
978 $error->set_error('no_access');
980 return $error->get_soap_array();
982 $error->set_error('duplicates');
983 return $error->get_soap_array();
985 $error->set_error('no_records');
986 return $error->get_soap_array();
991 array('session'=>'xsd:string'),
992 array('return'=>'xsd:string'),
996 * Return the user_id of the user that is logged into the current session.
998 * @param String $session -- Session ID returned by a previous call to login.
999 * @return String -- the User ID of the current session
1002 function get_user_id($session){
1003 if(validate_authenticated($session)){
1004 global $current_user;
1005 return $current_user->id;
1014 array('session'=>'xsd:string'),
1015 array('return'=>'xsd:string'),
1019 * Return the ID of the default team for the user that is logged into the current session.
1021 * @param String $session -- Session ID returned by a previous call to login.
1022 * @return String -- the Team ID of the current user's default team
1023 * 1 for Community Edition
1026 function get_user_team_id($session){
1027 if(validate_authenticated($session))
1038 array('return'=>'xsd:string'),
1042 * Return the current time on the server in the format 'Y-m-d H:i:s'. This time is in the server's default timezone.
1044 * @return String -- The current date/time 'Y-m-d H:i:s'
1046 function get_server_time(){
1047 return date('Y-m-d H:i:s');
1053 array('return'=>'xsd:string'),
1057 * Return the current time on the server in the format 'Y-m-d H:i:s'. This time is in GMT.
1059 * @return String -- The current date/time 'Y-m-d H:i:s'
1061 function get_gmt_time(){
1062 return TimeDate::getInstance()->nowDb();
1068 array('return'=>'xsd:string'),
1072 * Retrieve the specific flavor of sugar.
1074 * @return String 'CE' -- For Community Edition
1075 * 'PRO' -- For Professional
1076 * 'ENT' -- For Enterprise
1078 function get_sugar_flavor(){
1079 global $sugar_flavor;
1081 return $sugar_flavor;
1086 'get_server_version',
1088 array('return'=>'xsd:string'),
1092 * Retrieve the version number of Sugar that the server is running.
1094 * @return String -- The current sugar version number.
1097 function get_server_version(){
1099 $admin = new Administration();
1100 $admin->retrieveSettings('info');
1101 if(isset($admin->settings['info_sugar_version'])){
1102 return $admin->settings['info_sugar_version'];
1110 'get_relationships',
1111 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'module_id'=>'xsd:string', 'related_module'=>'xsd:string', 'related_module_query'=>'xsd:string', 'deleted'=>'xsd:int'),
1112 array('return'=>'tns:get_relationships_result'),
1116 * Retrieve a collection of beans tha are related to the specified bean.
1117 * As of 4.5.1c, all combinations of related modules are supported
1119 * @param String $session -- Session ID returned by a previous call to login.
1120 * @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)..
1121 * @param String $module_id -- The ID of the bean in the specified module
1122 * @param String $related_module -- The name of the related 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)..
1123 * @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.
1124 * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
1127 function get_relationships($session, $module_name, $module_id, $related_module, $related_module_query, $deleted){
1128 $error = new SoapError();
1130 if(!validate_authenticated($session)){
1131 $error->set_error('invalid_login');
1132 return array('ids'=>$ids,'error'=> $error->get_soap_array());
1134 global $beanList, $beanFiles;
1135 $error = new SoapError();
1137 if(empty($beanList[$module_name]) || empty($beanList[$related_module])){
1138 $error->set_error('no_module');
1139 return array('ids'=>$ids, 'error'=>$error->get_soap_array());
1141 $class_name = $beanList[$module_name];
1142 require_once($beanFiles[$class_name]);
1143 $mod = new $class_name();
1144 $mod->retrieve($module_id);
1145 if(!$mod->ACLAccess('DetailView')){
1146 $error->set_error('no_access');
1147 return array('ids'=>$ids, 'error'=>$error->get_soap_array());
1150 require_once 'include/SugarSQLValidate.php';
1151 $valid = new SugarSQLValidate();
1152 if(!$valid->validateQueryClauses($related_module_query)) {
1153 $GLOBALS['log']->error("Bad query: $related_module_query");
1154 $error->set_error('no_access');
1156 'result_count' => -1,
1157 'error' => $error->get_soap_array()
1161 $id_list = get_linked_records($related_module, $module_name, $module_id);
1163 if ($id_list === FALSE) {
1164 $error->set_error('no_relationship_support');
1165 return array('ids'=>$ids, 'error'=>$error->get_soap_array());
1167 elseif (count($id_list) == 0) {
1168 return array('ids'=>$ids, 'error'=>$error->get_soap_array());
1173 $in = "'".implode("', '", $id_list)."'";
1175 $related_class_name = $beanList[$related_module];
1176 require_once($beanFiles[$related_class_name]);
1177 $related_mod = new $related_class_name();
1179 $sql = "SELECT {$related_mod->table_name}.id FROM {$related_mod->table_name} ";
1182 if (isset($related_mod->custom_fields)) {
1183 $customJoin = $related_mod->custom_fields->getJOIN();
1184 $sql .= $customJoin ? $customJoin['join'] : '';
1187 $sql .= " WHERE {$related_mod->table_name}.id IN ({$in}) ";
1189 if (!empty($related_module_query)) {
1190 $sql .= " AND ( {$related_module_query} )";
1193 $result = $related_mod->db->query($sql);
1194 while ($row = $related_mod->db->fetchByAssoc($result)) {
1195 $list[] = $row['id'];
1198 $return_list = array();
1200 foreach($list as $id) {
1201 $related_class_name = $beanList[$related_module];
1202 $related_mod = new $related_class_name();
1203 $related_mod->retrieve($id);
1205 $return_list[] = array(
1207 'date_modified' => $related_mod->date_modified,
1208 'deleted' => $related_mod->deleted
1212 return array('ids' => $return_list, 'error' => $error->get_soap_array());
1218 array('session'=>'xsd:string','set_relationship_value'=>'tns:set_relationship_value'),
1219 array('return'=>'tns:error_value'),
1223 * Set a single relationship between two beans. The items are related by module name and id.
1225 * @param String $session -- Session ID returned by a previous call to login.
1226 * @param Array $set_relationship_value --
1227 * 'module1' -- 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)..
1228 * 'module1_id' -- The ID of the bean in the specified module
1229 * 'module2' -- The name of the module that the related 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)..
1230 * 'module2_id' -- The ID of the bean in the specified module
1231 * @return Empty error on success, Error on failure
1233 function set_relationship($session, $set_relationship_value){
1234 $error = new SoapError();
1235 if(!validate_authenticated($session)){
1236 $error->set_error('invalid_login');
1237 return $error->get_soap_array();
1239 return handle_set_relationship($set_relationship_value, $session);
1243 'set_relationships',
1244 array('session'=>'xsd:string','set_relationship_list'=>'tns:set_relationship_list'),
1245 array('return'=>'tns:set_relationship_list_result'),
1249 * Setup several relationships between pairs of beans. The items are related by module name and id.
1251 * @param String $session -- Session ID returned by a previous call to login.
1252 * @param Array $set_relationship_list -- One for each relationship to setup. Each entry is itself an array.
1253 * 'module1' -- 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)..
1254 * 'module1_id' -- The ID of the bean in the specified module
1255 * 'module2' -- The name of the module that the related 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)..
1256 * 'module2_id' -- The ID of the bean in the specified module
1257 * @return Empty error on success, Error on failure
1259 function set_relationships($session, $set_relationship_list){
1260 $error = new SoapError();
1261 if(!validate_authenticated($session)){
1262 $error->set_error('invalid_login');
1267 foreach($set_relationship_list as $set_relationship_value){
1268 $reter = handle_set_relationship($set_relationship_value, $session);
1269 if($reter['number'] == 0){
1275 return array('created'=>$count , 'failed'=>$failed, 'error'=>$error);
1280 //INTERNAL FUNCTION NOT EXPOSED THROUGH SOAP
1282 * (Internal) Create a relationship between two beans.
1284 * @param Array $set_relationship_value --
1285 * 'module1' -- 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)..
1286 * 'module1_id' -- The ID of the bean in the specified module
1287 * 'module2' -- The name of the module that the related 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)..
1288 * 'module2_id' -- The ID of the bean in the specified module
1289 * @return Empty error on success, Error on failure
1291 function handle_set_relationship($set_relationship_value, $session='')
1293 global $beanList, $beanFiles;
1294 $error = new SoapError();
1296 $module1 = $set_relationship_value['module1'];
1297 $module1_id = $set_relationship_value['module1_id'];
1298 $module2 = $set_relationship_value['module2'];
1299 $module2_id = $set_relationship_value['module2_id'];
1301 if(empty($beanList[$module1]) || empty($beanList[$module2]) )
1303 $error->set_error('no_module');
1304 return $error->get_soap_array();
1306 $class_name = $beanList[$module1];
1307 require_once($beanFiles[$class_name]);
1308 $mod = new $class_name();
1309 $mod->retrieve($module1_id);
1310 if(!$mod->ACLAccess('DetailView')){
1311 $error->set_error('no_access');
1312 return $error->get_soap_array();
1314 if($module1 == "Contacts" && $module2 == "Users"){
1315 $key = 'contacts_users_id';
1318 $key = array_search(strtolower($module2),$mod->relationship_fields);
1320 $key = Relationship::retrieve_by_modules($module1, $module2, $GLOBALS['db']);
1322 // BEGIN SnapLogic fix for bug 32064
1323 if ($module1 == "Quotes" && $module2 == "ProductBundles") {
1324 // Alternative solution is perhaps to
1325 // do whatever Sugar does when the same
1326 // request is received from the web:
1327 $pb_cls = $beanList[$module2];
1328 $pb = new $pb_cls();
1329 $pb->retrieve($module2_id);
1331 // Check if this relationship already exists
1332 $query = "SELECT count(*) AS count FROM product_bundle_quote WHERE quote_id = '{$module1_id}' AND bundle_id = '{$module2_id}' AND deleted = '0'";
1333 $result = $GLOBALS['db']->query($query, true, "Error checking for previously existing relationship between quote and product_bundle");
1334 $row = $GLOBALS['db']->fetchByAssoc($result);
1335 if(isset($row['count']) && $row['count'] > 0){
1336 return $error->get_soap_array();
1339 $query = "SELECT MAX(bundle_index)+1 AS idx FROM product_bundle_quote WHERE quote_id = '{$module1_id}' AND deleted='0'";
1340 $result = $GLOBALS['db']->query($query, true, "Error getting bundle_index");
1341 $GLOBALS['log']->debug("*********** Getting max bundle_index");
1342 $GLOBALS['log']->debug($query);
1343 $row = $GLOBALS['db']->fetchByAssoc($result);
1350 $pb->set_productbundle_quote_relationship($module1_id,$module2_id,$idx);
1352 return $error->get_soap_array();
1354 } else if ($module1 == "ProductBundles" && $module2 == "Products") {
1355 // And, well, similar things apply in this case
1356 $pb_cls = $beanList[$module1];
1357 $pb = new $pb_cls();
1358 $pb->retrieve($module1_id);
1360 // Check if this relationship already exists
1361 $query = "SELECT count(*) AS count FROM product_bundle_product WHERE bundle_id = '{$module1_id}' AND product_id = '{$module2_id}' AND deleted = '0'";
1362 $result = $GLOBALS['db']->query($query, true, "Error checking for previously existing relationship between quote and product_bundle");
1363 $row = $GLOBALS['db']->fetchByAssoc($result);
1364 if(isset($row['count']) && $row['count'] > 0){
1365 return $error->get_soap_array();
1368 $query = "SELECT MAX(product_index)+1 AS idx FROM product_bundle_product WHERE bundle_id='{$module1_id}'";
1369 $result = $GLOBALS['db']->query($query, true, "Error getting bundle_index");
1370 $GLOBALS['log']->debug("*********** Getting max bundle_index");
1371 $GLOBALS['log']->debug($query);
1372 $row = $GLOBALS['db']->fetchByAssoc($result);
1378 $pb->set_productbundle_product_relationship($module2_id,$idx,$module1_id);
1381 $prod_cls = $beanList[$module2];
1382 $prod = new $prod_cls();
1383 $prod->retrieve($module2_id);
1384 $prod->quote_id = $pb->quote_id;
1386 return $error->get_soap_array();
1388 // END SnapLogic fix for bug 32064
1391 $mod->load_relationship($key);
1392 $mod->$key->add($module2_id);
1393 return $error->get_soap_array();
1400 $error->set_error('no_module');
1401 return $error->get_soap_array();
1404 if(($module1 == 'Meetings' || $module1 == 'Calls') && ($module2 == 'Contacts' || $module2 == 'Users')){
1405 $key = strtolower($module2);
1406 $mod->load_relationship($key);
1407 $mod->$key->add($module2_id);
1409 else if ($module1 == 'Contacts' && ($module2 == 'Notes' || $module2 == 'Calls' || $module2 == 'Meetings' || $module2 == 'Tasks') && !empty($session)){
1410 $mod->$key = $module2_id;
1411 $mod->save_relationship_changes(false);
1412 if (!empty($mod->account_id)) {
1413 // when setting a relationship from a Contact to these activities, if the Contacts is related to an Account,
1414 // we want to associate that Account to the activity as well
1415 $ret = set_relationship($session, array('module1'=>'Accounts', 'module1_id'=>$mod->account_id, 'module2'=>$module2, 'module2_id'=>$module2_id));
1419 $mod->$key = $module2_id;
1420 $mod->save_relationship_changes(false);
1423 return $error->get_soap_array();
1428 'set_document_revision',
1429 array('session'=>'xsd:string','note'=>'tns:document_revision'),
1430 array('return'=>'tns:set_entry_result'),
1434 * Enter description here...
1436 * @param String $session -- Session ID returned by a previous call to login.
1437 * @param unknown_type $document_revision
1440 function set_document_revision($session,$document_revision)
1443 $error = new SoapError();
1444 if(!validate_authenticated($session)){
1445 $error->set_error('invalid_login');
1446 return array('id'=>-1, 'error'=>$error->get_soap_array());
1449 require_once('modules/Documents/DocumentSoap.php');
1450 $dr = new DocumentSoap();
1451 return array('id'=>$dr->saveFile($document_revision), 'error'=>$error->get_soap_array());
1457 array('user_name'=>'xsd:string','password'=>'xsd:string','search_string'=>'xsd:string', 'modules'=>'tns:select_fields', 'offset'=>'xsd:int', 'max_results'=>'xsd:int'),
1458 array('return'=>'tns:get_entry_list_result'),
1462 * Given a list of modules to search and a search string, return the id, module_name, along with the fields
1463 * as specified in the $query_array
1465 * @param string $user_name - username of the Sugar User
1466 * @param string $password - password of the Sugar User
1467 * @param string $search_string - string to search
1468 * @param string[] $modules - array of modules to query
1469 * @param int $offset - a specified offset in the query
1470 * @param int $max_results - max number of records to return
1471 * @return get_entry_list_result - id, module_name, and list of fields from each record
1473 function search_by_module($user_name, $password, $search_string, $modules, $offset, $max_results){
1474 global $beanList, $beanFiles;
1476 $error = new SoapError();
1477 $hasLoginError = false;
1479 if(empty($user_name) && !empty($password))
1481 if(!validate_authenticated($password))
1483 $hasLoginError = true;
1485 } else if(!validate_user($user_name, $password)) {
1486 $hasLoginError = true;
1489 //If there is a login error, then return the error here
1492 $error->set_error('invalid_login');
1493 return array('result_count'=>-1, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
1496 global $current_user;
1497 if($max_results > 0){
1498 global $sugar_config;
1499 $sugar_config['list_max_entries_per_page'] = $max_results;
1501 // MRF - BUG:19552 - added a join for accounts' emails below
1502 $query_array = array('Accounts'=>array('where'=>array('Accounts' => array(0 => "accounts.name like '{0}%'"), 'EmailAddresses' => array(0 => "ea.email_address like '{0}%'")),'fields'=>"accounts.id, accounts.name"),
1503 'Bugs'=>array('where'=>array('Bugs' => array(0 => "bugs.name like '{0}%'", 1 => "bugs.bug_number = {0}")),'fields'=>"bugs.id, bugs.name, bugs.bug_number"),
1504 'Cases'=>array('where'=>array('Cases' => array(0 => "cases.name like '{0}%'", 1 => "cases.case_number = {0}")),'fields'=>"cases.id, cases.name, cases.case_number"),
1505 'Leads'=>array('where'=>array('Leads' => array(0 => "leads.first_name like '{0}%'",1 => "leads.last_name like '{0}%'"), 'EmailAddresses' => array(0 => "ea.email_address like '{0}%'")), 'fields'=>"leads.id, leads.first_name, leads.last_name, leads.status"),
1506 'Project'=>array('where'=>array('Project' => array(0 => "project.name like '{0}%'")), 'fields'=>"project.id, project.name"),
1507 'ProjectTask'=>array('where'=>array('ProjectTask' => array(0 => "project.id = '{0}'")), 'fields'=>"project_task.id, project_task.name"),
1508 'Contacts'=>array('where'=>array('Contacts' => array(0 => "contacts.first_name like '{0}%'", 1 => "contacts.last_name like '{0}%'"), 'EmailAddresses' => array(0 => "ea.email_address like '{0}%'")),'fields'=>"contacts.id, contacts.first_name, contacts.last_name"),
1509 'Opportunities'=>array('where'=>array('Opportunities' => array(0 => "opportunities.name like '{0}%'")), 'fields'=>"opportunities.id, opportunities.name"),
1510 'Users'=>array('where'=>array('EmailAddresses' => array(0 => "ea.email_address like '{0}%'")),'fields'=>"users.id, users.user_name, users.first_name, ea.email_address"),
1513 if(!empty($search_string) && isset($search_string)){
1514 foreach($modules as $module_name){
1515 $class_name = $beanList[$module_name];
1516 require_once($beanFiles[$class_name]);
1517 $seed = new $class_name();
1518 if(empty($beanList[$module_name])){
1521 if(!check_modules_access($current_user, $module_name, 'read')){
1524 if(! $seed->ACLAccess('ListView'))
1529 if(isset($query_array[$module_name])){
1532 //split here to do while loop
1533 foreach($query_array[$module_name]['where'] as $key => $value){
1534 foreach($value as $where_clause){
1537 $tmpQuery = ' UNION ';
1538 $tmpQuery .= "SELECT ".$query_array[$module_name]['fields']." FROM $seed->table_name ";
1539 // We need to confirm that the user is a member of the team of the item.
1542 if($module_name == 'ProjectTask'){
1543 $tmpQuery .= "INNER JOIN project ON $seed->table_name.project_id = project.id ";
1546 if(isset($seed->emailAddress) && $key == 'EmailAddresses'){
1547 $tmpQuery .= " INNER JOIN email_addr_bean_rel eabl ON eabl.bean_id = $seed->table_name.id and eabl.deleted=0";
1548 $tmpQuery .= " INNER JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
1551 $search_terms = explode(", ", $search_string);
1552 $termCount = count($search_terms);
1554 if($key != 'EmailAddresses'){
1555 foreach($search_terms as $term){
1556 if(!strpos($where_clause, 'number')){
1557 $where .= string_format($where_clause,array($GLOBALS['db']->quote($term)));
1558 }elseif(is_numeric($term)){
1559 $where .= string_format($where_clause,array($GLOBALS['db']->quote($term)));
1563 if($count < $termCount){
1570 foreach ($search_terms as $term)
1572 $where .= "ea.email_address LIKE '".$GLOBALS['db']->quote($term)."'";
1573 if ($count < $termCount)
1581 $tmpQuery .= $where;
1582 $tmpQuery .= ") AND $seed->table_name.deleted = 0";
1584 $query .= $tmpQuery;
1587 //grab the items from the db
1588 $result = $seed->db->query($query, $offset, $max_results);
1590 while(($row = $seed->db->fetchByAssoc($result)) != null){
1592 $fields = explode(", ", $query_array[$module_name]['fields']);
1593 foreach($fields as $field){
1594 $field_names = explode(".", $field);
1595 $list[$field] = array('name'=>$field_names[1], 'value'=>$row[$field_names[1]]);
1598 $output_list[] = array('id'=>$row['id'],
1599 'module_name'=>$module_name,
1600 'name_value_list'=>$list);
1601 if(empty($field_list)){
1602 $field_list = get_field_list($row);
1609 $next_offset = $offset + sizeof($output_list);
1611 return array('result_count'=>sizeof($output_list), 'next_offset'=>$next_offset,'field_list'=>$field_list, 'entry_list'=>$output_list, 'error'=>$error->get_soap_array());
1617 'get_mailmerge_document',
1618 array('session'=>'xsd:string','file_name'=>'xsd:string', 'fields' => 'tns:select_fields'),
1619 array('return'=>'tns:get_sync_result_encoded'),
1623 * Get MailMerge document
1625 * @param String $session -- Session ID returned by a previous call to login.
1626 * @param unknown_type $file_name
1627 * @param unknown_type $fields
1630 function get_mailmerge_document($session, $file_name, $fields)
1632 global $beanList, $beanFiles, $app_list_strings;
1633 $error = new SoapError();
1634 if(!validate_authenticated($session))
1636 $error->set_error('invalid_login');
1637 return array('result'=>'', 'error'=>$error->get_soap_array());
1639 if(!preg_match('/^sugardata[\.\d\s]+\.php$/', $file_name)) {
1640 $error->set_error('no_records');
1641 return array('result'=>'', 'error'=>$error->get_soap_array());
1645 $file_name = sugar_cached('MergedDocuments/').pathinfo($file_name, PATHINFO_BASENAME);
1647 $master_fields = array();
1648 $related_fields = array();
1650 if(file_exists($file_name))
1652 include($file_name);
1654 $class1 = $merge_array['master_module'];
1655 $beanL = $beanList[$class1];
1656 $bean1 = $beanFiles[$beanL];
1657 require_once($bean1);
1658 $seed1 = new $beanL();
1660 if(!empty($merge_array['related_module']))
1662 $class2 = $merge_array['related_module'];
1663 $beanR = $beanList[$class2];
1664 $bean2 = $beanFiles[$beanR];
1665 require_once($bean2);
1666 $seed2 = new $beanR();
1670 //$token1 = strtolower($class1);
1671 if($class1 == 'Prospects'){
1672 $class1 = 'CampaignProspects';
1674 foreach($fields as $field)
1676 $pos = strpos(strtolower($field), strtolower($class1));
1677 $pos2 = strpos(strtolower($field), strtolower($class2));
1679 $fieldName = str_replace(strtolower($class1).'_', '', strtolower($field));
1680 array_push($master_fields, $fieldName);
1681 }else if($pos2 !== false){
1682 $fieldName = str_replace(strtolower($class2).'_', '', strtolower($field));
1683 array_push($related_fields, $fieldName);
1687 $html = '<html ' . get_language_header() .'><body><table border = 1><tr>';
1689 foreach($master_fields as $master_field){
1690 $html .= '<td>'.$class1.'_'.$master_field.'</td>';
1692 foreach($related_fields as $related_field){
1693 $html .= '<td>'.$class2.'_'.$related_field.'</td>';
1697 $ids = $merge_array['ids'];
1698 $is_prospect_merge = ($seed1->object_name == 'Prospect');
1699 foreach($ids as $key=>$value){
1700 if($is_prospect_merge){
1701 $seed1 = $seed1->retrieveTarget($key);
1703 $seed1->retrieve($key);
1706 foreach($master_fields as $master_field){
1707 if(isset($seed1->$master_field)){
1708 if($seed1->field_name_map[$master_field]['type'] == 'enum'){
1709 //pull in the translated dom
1710 $html .='<td>'.$app_list_strings[$seed1->field_name_map[$master_field]['options']][$seed1->$master_field].'</td>';
1712 $html .='<td>'.$seed1->$master_field.'</td>';
1716 $html .= '<td></td>';
1719 if(isset($value) && !empty($value)){
1720 $seed2->retrieve($value);
1721 foreach($related_fields as $related_field){
1722 if(isset($seed2->$related_field)){
1723 if($seed2->field_name_map[$related_field]['type'] == 'enum'){
1724 //pull in the translated dom
1725 $html .='<td>'.$app_list_strings[$seed2->field_name_map[$related_field]['options']][$seed2->$related_field].'</td>';
1727 $html .= '<td>'.$seed2->$related_field.'</td>';
1731 $html .= '<td></td>';
1737 $html .= "</table></body></html>";
1740 $result = base64_encode($html);
1741 return array('result' => $result, 'error' => $error);
1745 'get_mailmerge_document2',
1746 array('session'=>'xsd:string','file_name'=>'xsd:string', 'fields' => 'tns:select_fields'),
1747 array('return'=>'tns:get_mailmerge_document_result'),
1751 * Enter description here...
1753 * @param String $session -- Session ID returned by a previous call to login.
1754 * @param unknown_type $file_name
1755 * @param unknown_type $fields
1758 function get_mailmerge_document2($session, $file_name, $fields)
1760 global $beanList, $beanFiles, $app_list_strings, $app_strings;
1762 $error = new SoapError();
1763 if(!validate_authenticated($session))
1765 $GLOBALS['log']->error('invalid_login');
1766 $error->set_error('invalid_login');
1767 return array('result'=>'', 'error'=>$error->get_soap_array());
1769 if(!preg_match('/^sugardata[\.\d\s]+\.php$/', $file_name)) {
1770 $GLOBALS['log']->error($app_strings['ERR_NO_SUCH_FILE'] . " ({$file_name})");
1771 $error->set_error('no_records');
1772 return array('result'=>'', 'error'=>$error->get_soap_array());
1776 $file_name = sugar_cached('MergedDocuments/').pathinfo($file_name, PATHINFO_BASENAME);
1778 $master_fields = array();
1779 $related_fields = array();
1781 if(file_exists($file_name))
1783 include($file_name);
1785 $class1 = $merge_array['master_module'];
1786 $beanL = $beanList[$class1];
1787 $bean1 = $beanFiles[$beanL];
1788 require_once($bean1);
1789 $seed1 = new $beanL();
1791 if(!empty($merge_array['related_module']))
1793 $class2 = $merge_array['related_module'];
1794 $beanR = $beanList[$class2];
1795 $bean2 = $beanFiles[$beanR];
1796 require_once($bean2);
1797 $seed2 = new $beanR();
1801 //$token1 = strtolower($class1);
1802 if($class1 == 'Prospects'){
1803 $class1 = 'CampaignProspects';
1805 foreach($fields as $field)
1807 $pos = strpos(strtolower($field), strtolower($class1));
1808 $pos2 = strpos(strtolower($field), strtolower($class2));
1810 $fieldName = str_replace(strtolower($class1).'_', '', strtolower($field));
1811 array_push($master_fields, $fieldName);
1812 }else if($pos2 !== false){
1813 $fieldName = str_replace(strtolower($class2).'_', '', strtolower($field));
1814 array_push($related_fields, $fieldName);
1818 $html = '<html ' . get_language_header() . '><body><table border = 1><tr>';
1820 foreach($master_fields as $master_field){
1821 $html .= '<td>'.$class1.'_'.$master_field.'</td>';
1823 foreach($related_fields as $related_field){
1824 $html .= '<td>'.$class2.'_'.$related_field.'</td>';
1828 $ids = $merge_array['ids'];
1829 $resultIds = array();
1830 $is_prospect_merge = ($seed1->object_name == 'Prospect');
1831 if($is_prospect_merge){
1834 foreach($ids as $key=>$value){
1836 if($is_prospect_merge){
1837 $seed1 = $pSeed->retrieveTarget($key);
1839 $seed1->retrieve($key);
1841 $resultIds[] = array('name' => $seed1->module_name, 'value' => $key);
1843 foreach($master_fields as $master_field){
1844 if(isset($seed1->$master_field)){
1845 if($seed1->field_name_map[$master_field]['type'] == 'enum'){
1846 //pull in the translated dom
1847 $html .='<td>'.$app_list_strings[$seed1->field_name_map[$master_field]['options']][$seed1->$master_field].'</td>';
1848 } else if ($seed1->field_name_map[$master_field]['type'] == 'multienum') {
1850 if(isset($app_list_strings[$seed1->field_name_map[$master_field]['options']]) )
1852 $items = unencodeMultienum($seed1->$master_field);
1854 foreach($items as $item) {
1855 if ( !empty($app_list_strings[$seed1->field_name_map[$master_field]['options']][$item]) )
1857 array_push($output, $app_list_strings[$seed1->field_name_map[$master_field]['options']][$item]);
1863 $encoded_output = encodeMultienumValue($output);
1864 $html .= "<td>$encoded_output</td>";
1868 $html .='<td>'.$seed1->$master_field.'</td>';
1872 $html .= '<td></td>';
1875 if(isset($value) && !empty($value)){
1876 $resultIds[] = array('name' => $seed2->module_name, 'value' => $value);
1877 $seed2->retrieve($value);
1878 foreach($related_fields as $related_field){
1879 if(isset($seed2->$related_field)){
1880 if($seed2->field_name_map[$related_field]['type'] == 'enum'){
1881 //pull in the translated dom
1882 $html .='<td>'.$app_list_strings[$seed2->field_name_map[$related_field]['options']][$seed2->$related_field].'</td>';
1884 $html .= '<td>'.$seed2->$related_field.'</td>';
1888 $html .= '<td></td>';
1894 $html .= "</table></body></html>";
1896 $result = base64_encode($html);
1898 return array('html' => $result, 'name_value_list' => $resultIds, 'error' => $error);
1902 'get_document_revision',
1903 array('session'=>'xsd:string','i'=>'xsd:string'),
1904 array('return'=>'tns:return_document_revision'),
1908 * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a
1909 * properly authenticated user to download a document that they have proper rights to download.
1911 * @param String $session -- Session ID returned by a previous call to login.
1912 * @param String $id -- ID of the document revision to obtain
1913 * @return return_document_revision - this is a complex type as defined in SoapTypes.php
1915 function get_document_revision($session,$id)
1917 global $sugar_config;
1919 $error = new SoapError();
1920 if(!validate_authenticated($session)){
1921 $error->set_error('invalid_login');
1922 return array('id'=>-1, 'error'=>$error->get_soap_array());
1926 $dr = new DocumentRevision();
1928 if(!empty($dr->filename)){
1929 $filename = "upload://{$dr->id}";
1930 $contents = base64_encode(sugar_file_get_contents($filename));
1931 return array('document_revision'=>array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents), 'error'=>$error->get_soap_array());
1933 $error->set_error('no_records');
1934 return array('id'=>-1, 'error'=>$error->get_soap_array());
1939 'set_campaign_merge',
1940 array('session'=>'xsd:string', 'targets'=>'tns:select_fields', 'campaign_id'=>'xsd:string'),
1941 array('return'=>'tns:error_value'),
1944 * Once we have successfuly done a mail merge on a campaign, we need to notify Sugar of the targets
1945 * and the campaign_id for tracking purposes
1947 * @param session the session id of the authenticated user
1948 * @param targets a string array of ids identifying the targets used in the merge
1949 * @param campaign_id the campaign_id used for the merge
1951 * @return error_value
1953 function set_campaign_merge($session,$targets, $campaign_id){
1954 $error = new SoapError();
1955 if(!validate_authenticated($session)){
1956 $error->set_error('invalid_login');
1957 return $error->get_soap_array();
1959 if (empty($campaign_id) or !is_array($targets) or count($targets) == 0) {
1960 $GLOBALS['log']->debug('set_campaign_merge: Merge action status will not be updated, because, campaign_id is null or no targets were selected.');
1962 require_once('modules/Campaigns/utils.php');
1963 campaign_log_mail_merge($campaign_id,$targets);
1966 return $error->get_soap_array();
1969 'get_entries_count',
1970 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'query'=>'xsd:string', 'deleted' => 'xsd:int'),
1971 array('return'=>'tns:get_entries_count_result'),
1975 * Retrieve number of records in a given module
1977 * @param session the session id of the authenticated user
1978 * @param module_name module to retrieve number of records from
1979 * @param query allows webservice user to provide a WHERE clause
1980 * @param deleted specify whether or not to include deleted records
1982 @return get_entries_count_result - this is a complex type as defined in SoapTypes.php
1984 function get_entries_count($session, $module_name, $query, $deleted) {
1985 global $beanList, $beanFiles, $current_user;
1987 $error = new SoapError();
1989 if (!validate_authenticated($session)) {
1990 $error->set_error('invalid_login');
1992 'result_count' => -1,
1993 'error' => $error->get_soap_array()
1997 if (empty($beanList[$module_name])) {
1998 $error->set_error('no_module');
2000 'result_count' => -1,
2001 'error' => $error->get_soap_array()
2005 if(!check_modules_access($current_user, $module_name, 'list')){
2006 $error->set_error('no_access');
2008 'result_count' => -1,
2009 'error' => $error->get_soap_array()
2013 $class_name = $beanList[$module_name];
2014 require_once($beanFiles[$class_name]);
2015 $seed = new $class_name();
2017 if (!$seed->ACLAccess('ListView')) {
2018 $error->set_error('no_access');
2020 'result_count' => -1,
2021 'error' => $error->get_soap_array()
2025 $sql = 'SELECT COUNT(*) result_count FROM ' . $seed->table_name . ' ';
2028 $customJoin = $seed->getCustomJoin();
2029 $sql .= $customJoin['join'];
2031 // build WHERE clauses, if any
2032 $where_clauses = array();
2033 if (!empty($query)) {
2034 require_once 'include/SugarSQLValidate.php';
2035 $valid = new SugarSQLValidate();
2036 if(!$valid->validateQueryClauses($query)) {
2037 $GLOBALS['log']->error("Bad query: $query");
2038 $error->set_error('no_access');
2040 'result_count' => -1,
2041 'error' => $error->get_soap_array()
2044 $where_clauses[] = $query;
2046 if ($deleted == 0) {
2047 $where_clauses[] = $seed->table_name . '.deleted = 0';
2050 // if WHERE clauses exist, add them to query
2051 if (!empty($where_clauses)) {
2052 $sql .= ' WHERE ' . implode(' AND ', $where_clauses);
2055 $res = $GLOBALS['db']->query($sql);
2056 $row = $GLOBALS['db']->fetchByAssoc($res);
2059 'result_count' => $row['result_count'],
2060 'error' => $error->get_soap_array()
2065 'set_entries_details',
2066 array('session'=>'xsd:string', 'module_name'=>'xsd:string', 'name_value_lists'=>'tns:name_value_lists', 'select_fields' => 'tns:select_fields'),
2067 array('return'=>'tns:set_entries_detail_result'),
2071 * Update or create a list of SugarBeans, returning details about the records created/updated
2073 * @param String $session -- Session ID returned by a previous call to login.
2074 * @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)..
2075 * @param Array $name_value_lists -- Array of Bean specific Arrays where the keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
2076 * @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.
2077 * @return Array 'name_value_lists' -- Array of Bean specific Arrays where the keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
2078 * 'error' -- The SOAP error if any.
2080 function set_entries_details($session, $module_name, $name_value_lists, $select_fields) {
2081 $error = new SoapError();
2083 if(!validate_authenticated($session)){
2084 $error->set_error('invalid_login');
2088 'error' => $error->get_soap_array()
2092 return handle_set_entries($module_name, $name_value_lists, $select_fields);
2095 // INTERNAL FUNCTION NOT EXPOSED THROUGH API
2096 function handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) {
2097 global $beanList, $beanFiles, $app_list_strings, $current_user;
2099 $error = new SoapError();
2100 $ret_values = array();
2102 if(empty($beanList[$module_name])){
2103 $error->set_error('no_module');
2104 return array('ids'=>array(), 'error'=>$error->get_soap_array());
2107 if(!check_modules_access($current_user, $module_name, 'write')){
2108 $error->set_error('no_access');
2109 return array('ids'=>-1, 'error'=>$error->get_soap_array());
2112 $class_name = $beanList[$module_name];
2113 require_once($beanFiles[$class_name]);
2116 $total = sizeof($name_value_lists);
2118 foreach($name_value_lists as $name_value_list){
2119 $seed = new $class_name();
2121 $seed->update_vcal = false;
2123 //See if we can retrieve the seed by a given id value
2124 foreach($name_value_list as $value)
2126 if($value['name'] == 'id')
2128 $seed->retrieve($value['value']);
2134 $dataValues = array();
2136 foreach($name_value_list as $value)
2138 $val = $value['value'];
2140 if($seed->field_name_map[$value['name']]['type'] == 'enum' || $seed->field_name_map[$value['name']]['type'] == 'radioenum')
2142 $vardef = $seed->field_name_map[$value['name']];
2143 if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$val]) )
2145 if ( in_array($val,$app_list_strings[$vardef['options']]) )
2147 $val = array_search($val,$app_list_strings[$vardef['options']]);
2151 } else if($seed->field_name_map[$value['name']]['type'] == 'multienum') {
2153 $vardef = $seed->field_name_map[$value['name']];
2155 if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value]) )
2157 $items = explode(",", $val);
2158 $parsedItems = array();
2159 foreach ($items as $item)
2161 if ( in_array($item, $app_list_strings[$vardef['options']]) )
2163 $keyVal = array_search($item,$app_list_strings[$vardef['options']]);
2164 array_push($parsedItems, $keyVal);
2168 if (!empty($parsedItems))
2170 $val = encodeMultienumValue($parsedItems);
2175 //Apply the non-empty values now since this will be used for duplicate checks
2176 //allow string or int of 0 to be updated if set.
2177 if(!empty($val) || ($val==='0' || $val===0))
2179 $seed->$value['name'] = $val;
2181 //Store all the values in dataValues Array to apply later
2182 $dataValues[$value['name']] = $val;
2185 if($count == $total)
2187 $seed->update_vcal = false;
2191 //Add the account to a contact
2192 if($module_name == 'Contacts'){
2193 $GLOBALS['log']->debug('Creating Contact Account');
2194 add_create_account($seed);
2195 $duplicate_id = check_for_duplicate_contacts($seed);
2196 if($duplicate_id == null)
2198 if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete')))
2200 //Now apply the values, since this is not a duplicate we can just pass false for the $firstSync argument
2201 apply_values($seed, $dataValues, false);
2203 if($seed->deleted == 1){
2204 $seed->mark_deleted($seed->id);
2209 //since we found a duplicate we should set the sync flag
2210 if( $seed->ACLAccess('Save'))
2212 //Determine if this is a first time sync. We find out based on whether or not a contacts_users relationship exists
2213 $seed->id = $duplicate_id;
2214 $seed->load_relationship("user_sync");
2215 $beans = $seed->user_sync->getBeans();
2216 $first_sync = empty($beans);
2218 //Now apply the values and indicate whether or not this is a first time sync
2219 apply_values($seed, $dataValues, $first_sync);
2220 $seed->contacts_users_id = $current_user->id;
2222 $ids[] = $duplicate_id;//we have a conflict
2226 } else if($module_name == 'Meetings' || $module_name == 'Calls'){
2227 //we are going to check if we have a meeting in the system
2228 //with the same outlook_id. If we do find one then we will grab that
2230 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
2231 if(empty($seed->id) && !isset($seed->id)){
2232 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){
2233 //at this point we have an object that does not have
2234 //the id set, but does have the outlook_id set
2235 //so we need to query the db to find if we already
2236 //have an object with this outlook_id, if we do
2237 //then we can set the id, otherwise this is a new object
2239 $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'";
2240 $response = $seed->get_list($order_by, $query, 0,-1,-1,0);
2241 $list = $response['list'];
2242 if(count($list) > 0){
2243 foreach($list as $value)
2245 $seed->id = $value->id;
2251 if (empty($seed->reminder_time)) {
2252 $seed->reminder_time = -1;
2254 if($seed->reminder_time == -1){
2255 $defaultRemindrTime = $current_user->getPreference('reminder_time');
2256 if ($defaultRemindrTime != -1){
2257 $seed->reminder_checked = '1';
2258 $seed->reminder_time = $defaultRemindrTime;
2262 if ($seed->deleted == 1) {
2263 $seed->mark_deleted($seed->id);
2270 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
2276 // if somebody is calling set_entries_detail() and wants fields returned...
2277 if ($select_fields !== FALSE) {
2278 $ret_values[$count] = array();
2280 foreach ($select_fields as $select_field) {
2281 if (isset($seed->$select_field)) {
2282 $ret_values[$count][] = get_name_value($select_field, $seed->$select_field);
2288 // handle returns for set_entries_detail() and set_entries()
2289 if ($select_fields !== FALSE) {
2291 'name_value_lists' => $ret_values,
2292 'error' => $error->get_soap_array()
2298 'error' => $error->get_soap_array()