]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/core/SoapHelperWebService.php
Release 6.2.4
[Github/sugarcrm.git] / service / core / SoapHelperWebService.php
1 <?php
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-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 global $disable_date_format;
40 $disable_date_format = true;
41
42 class SoapHelperWebServices {
43
44         function get_field_list($value, $fields, $translate=true)
45         {
46                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_field_list');
47                 $module_fields = array();
48                 $link_fields = array();
49                 if(!empty($value->field_defs)){
50
51                         foreach($value->field_defs as $var){
52                                 if(!empty($fields) && !in_array( $var['name'], $fields))continue;
53                                 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'non-db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate'))continue;
54                                 if ($var['source'] == 'non_db' && (isset($var['type']) && $var['type'] != 'link')) {
55                                         continue;
56                                 }
57                                 $required = 0;
58                                 $options_dom = array();
59                                 $options_ret = array();
60                                 // Apparently the only purpose of this check is to make sure we only return fields
61                                 //   when we've read a record.  Otherwise this function is identical to get_module_field_list
62
63                                 if( isset($var['required']) && $var['required'] && $var['required'] !== 'false' ){
64                                         $required = 1;
65                                 }
66                                 if(isset($var['options'])){
67                                         $options_dom = translate($var['options'], $value->module_dir);
68                                         if(!is_array($options_dom)) $options_dom = array();
69                                         foreach($options_dom as $key=>$oneOption)
70                                                 $options_ret[$key] = $this->get_name_value($key,$oneOption);
71                                 }
72
73                     if(!empty($var['dbType']) && $var['type'] == 'bool') {
74                         $options_ret['type'] = $this->get_name_value('type', $var['dbType']);
75                     }
76
77                     $entry = array();
78                     $entry['name'] = $var['name'];
79                     $entry['type'] = $var['type'];
80                     if ($var['type'] == 'link') {
81                             $entry['relationship'] = (isset($var['relationship']) ? $var['relationship'] : '');
82                             $entry['module'] = (isset($var['module']) ? $var['module'] : '');
83                             $entry['bean_name'] = (isset($var['bean_name']) ? $var['bean_name'] : '');
84                                         $link_fields[$var['name']] = $entry;
85                     } else {
86                             if($translate) {
87                                 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
88                             } else {
89                                 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
90                             }
91                             $entry['required'] = $required;
92                             $entry['options'] = $options_ret;
93                                         if(isset($var['default'])) {
94                                            $entry['default_value'] = $var['default'];
95                                         }
96                                         $module_fields[$var['name']] = $entry;
97                     } // else
98                         } //foreach
99                 } //if
100
101                 if($value->module_dir == 'Bugs'){
102                         require_once('modules/Releases/Release.php');
103                         $seedRelease = new Release();
104                         $options = $seedRelease->get_releases(TRUE, "Active");
105                         $options_ret = array();
106                         foreach($options as $name=>$value){
107                                 $options_ret[] =  array('name'=> $name , 'value'=>$value);
108                         }
109                         if(isset($module_fields['fixed_in_release'])){
110                                 $module_fields['fixed_in_release']['type'] = 'enum';
111                                 $module_fields['fixed_in_release']['options'] = $options_ret;
112                         }
113                         if(isset($module_fields['release'])){
114                                 $module_fields['release']['type'] = 'enum';
115                                 $module_fields['release']['options'] = $options_ret;
116                         }
117                         if(isset($module_fields['release_name'])){
118                                 $module_fields['release_name']['type'] = 'enum';
119                                 $module_fields['release_name']['options'] = $options_ret;
120                         }
121                 }
122
123                 if(isset($value->assigned_user_name) && isset($module_fields['assigned_user_id'])) {
124                         $module_fields['assigned_user_name'] = $module_fields['assigned_user_id'];
125                         $module_fields['assigned_user_name']['name'] = 'assigned_user_name';
126                 }
127                 if(isset($module_fields['modified_user_id'])) {
128                         $module_fields['modified_by_name'] = $module_fields['modified_user_id'];
129                         $module_fields['modified_by_name']['name'] = 'modified_by_name';
130                 }
131                 if(isset($module_fields['created_by'])) {
132                         $module_fields['created_by_name'] = $module_fields['created_by'];
133                         $module_fields['created_by_name']['name'] = 'created_by_name';
134                 }
135
136                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_field_list');
137                 return array('module_fields' => $module_fields, 'link_fields' => $link_fields);
138         } // fn
139
140         function setFaultObject($errorObject) {
141                 if ($this->isLogLevelDebug()) {
142                         $GLOBALS['log']->debug('SoapHelperWebServices->setFaultObject - ' . var_export($errorObject, true));
143                 }
144                 global $service_object;
145                 $service_object->error($errorObject);
146         } // fn
147
148 /**
149  * Validate the user session based on user name and password hash.
150  *
151  * @param string $user_name -- The user name to create a session for
152  * @param string $password -- The MD5 sum of the user's password
153  * @return true -- If the session is created
154  * @return false -- If the session is not created
155  */
156 function validate_user($user_name, $password){
157         $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_user');
158         global $server, $current_user, $sugar_config, $system_config;
159         $user = new User();
160         $user->user_name = $user_name;
161         $system_config = new Administration();
162         $system_config->retrieveSettings('system');
163         $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
164         // Check to see if the user name and password are consistent.
165         if($user->authenticate_user($password)){
166                 // we also need to set the current_user.
167                 $user->retrieve($user->id);
168                 $current_user = $user;
169
170                 $GLOBALS['log']->info('End: SoapHelperWebServices->validate_user - validation passed');
171                 return true;
172         }else if(function_exists('mcrypt_cbc')){
173                 $password = $this->decrypt_string($password);
174                 if($authController->login($user_name, $password) && isset($_SESSION['authenticated_user_id'])){
175                         $user->retrieve($_SESSION['authenticated_user_id']);
176                         $current_user = $user;
177                         $GLOBALS['log']->info('End: SoapHelperWebServices->validate_user - validation passed');
178                         return true;
179                 }
180         }else{
181                 $GLOBALS['log']->fatal("SECURITY: failed attempted login for $user_name using SOAP api");
182                 $server->setError("Invalid username and/or password");
183                 return false;
184         }
185
186 }
187
188         /**
189          * Validate the provided session information is correct and current.  Load the session.
190          *
191          * @param String $session_id -- The session ID that was returned by a call to login.
192          * @return true -- If the session is valid and loaded.
193          * @return false -- if the session is not valid.
194          */
195         function validate_authenticated($session_id){
196                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_authenticated');
197                 if(!empty($session_id)){
198                         session_id($session_id);
199                         if(empty($_SESSION)) {
200                            session_start();
201                         }
202                         if(!empty($_SESSION['is_valid_session']) && $this->is_valid_ip_address('ip_address') && $_SESSION['type'] == 'user'){
203
204                                 global $current_user;
205                                 require_once('modules/Users/User.php');
206                                 $current_user = new User();
207                                 $current_user->retrieve($_SESSION['user_id']);
208                                 $this->login_success();
209                                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_authenticated - passed');
210                                 $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated');
211                                 return true;
212                         }
213
214                         $GLOBALS['log']->debug("calling destroy");
215                         session_destroy();
216                 }
217                 LogicHook::initialize();
218                 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
219                 $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated - validation failed');
220                 return false;
221         }
222
223         /**
224          * Use the same logic as in SugarAuthenticate to validate the ip address
225          *
226          * @param string $session_var
227          * @return bool - true if the ip address is valid, false otherwise.
228          */
229         function is_valid_ip_address($session_var){
230                 global $sugar_config;
231                 // grab client ip address
232                 $clientIP = query_client_ip();
233                 $classCheck = 0;
234                 // check to see if config entry is present, if not, verify client ip
235                 if (!isset ($sugar_config['verify_client_ip']) || $sugar_config['verify_client_ip'] == true) {
236                         // check to see if we've got a current ip address in $_SESSION
237                         // and check to see if the session has been hijacked by a foreign ip
238                         if (isset ($_SESSION[$session_var])) {
239                                 $session_parts = explode(".", $_SESSION[$session_var]);
240                                 $client_parts = explode(".", $clientIP);
241                     if(count($session_parts) < 4) {
242                         $classCheck = 0;
243                     }else {
244                                 // match class C IP addresses
245                                 for ($i = 0; $i < 3; $i ++) {
246                                         if ($session_parts[$i] == $client_parts[$i]) {
247                                                 $classCheck = 1;
248                                                         continue;
249                                         } else {
250                                                 $classCheck = 0;
251                                                 break;
252                                                 }
253                                         }
254                         }
255                                         // we have a different IP address
256                                         if ($_SESSION[$session_var] != $clientIP && empty ($classCheck)) {
257                                                 $GLOBALS['log']->fatal("IP Address mismatch: SESSION IP: {$_SESSION[$session_var]} CLIENT IP: {$clientIP}");
258                                                 return false;
259                                         }
260                                 } else {
261                                         return false;
262                                 }
263                 }
264                 return true;
265         }
266
267         function checkSessionAndModuleAccess($session, $login_error_key, $module_name, $access_level, $module_access_level_error_key, $errorObject) {
268                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->checkSessionAndModuleAccess');
269                 if(!$this->validate_authenticated($session)){
270                         $GLOBALS['log']->info('SoapHelperWebServices->checkSessionAndModuleAccess - validate_authenticated failed');
271                         $errorObject->set_error('invalid_session');
272                         $this->setFaultObject($errorObject);
273                         $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
274                         return false;
275                 } // if
276
277                 global  $beanList, $beanFiles;
278                 if (!empty($module_name)) {
279                         if(empty($beanList[$module_name])){
280                                 $GLOBALS['log']->info('SoapHelperWebServices->checkSessionAndModuleAccess - module does not exists - ' . $module_name);
281                                 $errorObject->set_error('no_module');
282                                 $this->setFaultObject($errorObject);
283                                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
284                                 return false;
285                         } // if
286                         global $current_user;
287                         if(!$this->check_modules_access($current_user, $module_name, $access_level)){
288                                 $GLOBALS['log']->info('SoapHelperWebServices->checkSessionAndModuleAccess - no module access - ' . $module_name);
289                                 $errorObject->set_error('no_access');
290                                 $this->setFaultObject($errorObject);
291                                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
292                                 return false;
293                         }
294                 } // if
295                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
296                 return true;
297         } // fn
298
299         function checkACLAccess($bean, $viewType, $errorObject, $error_key) {
300                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->checkACLAccess');
301                 if(!$bean->ACLAccess($viewType)) {
302                         $GLOBALS['log']->info('SoapHelperWebServices->checkACLAccess - no ACLAccess');
303                         $errorObject->set_error($error_key);
304                         $this->setFaultObject($errorObject);
305                         $GLOBALS['log']->info('End: SoapHelperWebServices->checkACLAccess');
306                         return false;
307                 } // if
308                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkACLAccess');
309                 return true;
310         } // fn
311
312         function get_name_value($field,$value){
313                 return array('name'=>$field, 'value'=>$value);
314         }
315
316         function get_user_module_list($user){
317                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_user_module_list');
318                 global $app_list_strings, $current_language;
319                 $app_list_strings = return_app_list_strings_language($current_language);
320                 $modules = query_module_access_list($user);
321                 ACLController :: filterModuleList($modules, false);
322                 global $modInvisList;
323
324                 foreach($modInvisList as $invis){
325                         $modules[$invis] = 'read_only';
326                 }
327
328                 $actions = ACLAction::getUserActions($user->id,true);
329                 foreach($actions as $key=>$value){
330                         if(isset($value['module']) && $value['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED){
331                                 if ($value['module']['access']['aclaccess'] == ACL_ALLOW_DISABLED) {
332                                         unset($modules[$key]);
333                                 } else {
334                                         $modules[$key] = 'read_only';
335                                 } // else
336                         } else {
337                                 $modules[$key] = '';
338                         } // else
339                 } // foreach
340                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_user_module_list');
341                 return $modules;
342
343         }
344
345         function check_modules_access($user, $module_name, $action='write'){
346                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->check_modules_access');
347                 if(!isset($_SESSION['avail_modules'])){
348                         $_SESSION['avail_modules'] = $this->get_user_module_list($user);
349                 }
350                 if(isset($_SESSION['avail_modules'][$module_name])){
351                         if($action == 'write' && $_SESSION['avail_modules'][$module_name] == 'read_only'){
352                                 if(is_admin($user)) {
353                                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
354                                         return true;
355                                 } // if
356                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
357                                 return false;
358                         }elseif($action == 'write' && strcmp(strtolower($module_name), 'users') == 0 && !$user->isAdminForModule($module_name)){
359                  //rrs bug: 46000 - If the client is trying to write to the Users module and is not an admin then we need to stop them
360                 return false;
361             }
362                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
363                         return true;
364                 }
365                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
366                 return false;
367
368         }
369
370         function get_name_value_list($value){
371                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_name_value_list');
372                 global $app_list_strings;
373                 $list = array();
374                 if(!empty($value->field_defs)){
375                         if(isset($value->assigned_user_name)) {
376                                 $list['assigned_user_name'] = $this->get_name_value('assigned_user_name', $value->assigned_user_name);
377                         }
378                         if(isset($value->modified_by_name)) {
379                                 $list['modified_by_name'] = $this->get_name_value('modified_by_name', $value->modified_by_name);
380                         }
381                         if(isset($value->created_by_name)) {
382                                 $list['created_by_name'] = $this->get_name_value('created_by_name', $value->created_by_name);
383                         }
384                         foreach($value->field_defs as $var){
385                                 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate'))continue;
386
387                                 if(isset($value->$var['name'])){
388                                         $val = $value->$var['name'];
389                                         $type = $var['type'];
390
391                                         if(strcmp($type, 'date') == 0){
392                                                 $val = substr($val, 0, 10);
393                                         }elseif(strcmp($type, 'enum') == 0 && !empty($var['options'])){
394                                                 //$val = $app_list_strings[$var['options']][$val];
395                                         }
396
397                                         $list[$var['name']] = $this->get_name_value($var['name'], $val);
398                                 }
399                         }
400                 }
401                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_name_value_list');
402                 return $list;
403
404         }
405
406         function filter_fields($value, $fields) {
407                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->filter_fields');
408                 global $invalid_contact_fields;
409                 $filterFields = array();
410                 foreach($fields as $field){
411                         if (is_array($invalid_contact_fields)) {
412                                 if (in_array($field, $invalid_contact_fields)) {
413                                         continue;
414                                 } // if
415                         } // if
416                         if (isset($value->field_defs[$field])) {
417                                 $var = $value->field_defs[$field];
418                                 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')) {
419
420                                         if($value->module_dir == 'Emails' && (($var['name'] == 'description') || ($var['name'] == 'description_html') || ($var['name'] == 'from_addr_name') || ($var['name'] == 'reply_to_addr') || ($var['name'] == 'to_addrs_names') || ($var['name'] == 'cc_addrs_names') || ($var['name'] == 'bcc_addrs_names') || ($var['name'] == 'raw_source'))) {
421
422                                         } else {
423                                                 continue;
424                                         }
425                                 }
426                         } // if
427                         $filterFields[] = $field;
428                 } // foreach
429                 $GLOBALS['log']->info('End: SoapHelperWebServices->filter_fields');
430                 return $filterFields;
431         } // fn
432
433         function get_name_value_list_for_fields($value, $fields) {
434                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_name_value_list_for_fields');
435                 global $app_list_strings;
436                 global $invalid_contact_fields;
437
438                 $list = array();
439                 if(!empty($value->field_defs)){
440                         if(empty($fields))$fields = array_keys($value->field_defs);
441                         if(isset($value->assigned_user_name) && in_array('assigned_user_name', $fields)) {
442                                 $list['assigned_user_name'] = $this->get_name_value('assigned_user_name', $value->assigned_user_name);
443                         }
444                         if(isset($value->modified_by_name) && in_array('modified_by_name', $fields)) {
445                                 $list['modified_by_name'] = $this->get_name_value('modified_by_name', $value->modified_by_name);
446                         }
447                         if(isset($value->created_by_name) && in_array('created_by_name', $fields)) {
448                                 $list['created_by_name'] = $this->get_name_value('created_by_name', $value->created_by_name);
449                         }
450
451                         $filterFields = $this->filter_fields($value, $fields);
452                         foreach($filterFields as $field){
453                                 $var = $value->field_defs[$field];
454                                 if(isset($value->$var['name'])){
455                                         $val = $value->$var['name'];
456                                         $type = $var['type'];
457
458                                         if(strcmp($type, 'date') == 0){
459                                                 $val = substr($val, 0, 10);
460                                         }elseif(strcmp($type, 'enum') == 0 && !empty($var['options'])){
461                                                 //$val = $app_list_strings[$var['options']][$val];
462                                         }
463
464                                         $list[$var['name']] = $this->get_name_value($var['name'], $val);
465                                 } // if
466                         } // foreach
467                 } // if
468                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_name_value_list_for_fields');
469                 if ($this->isLogLevelDebug()) {
470                         $GLOBALS['log']->debug('SoapHelperWebServices->get_name_value_list_for_fields - return data = ' . var_export($list, true));
471                 } // if
472                 return $list;
473
474         } // fn
475
476         function array_get_name_value_list($array){
477                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->array_get_name_value_list');
478                 $list = array();
479                 foreach($array as $name=>$value){
480                         $list[$name] = $this->get_name_value($name, $value);
481                 }
482                 $GLOBALS['log']->info('End: SoapHelperWebServices->array_get_name_value_list');
483                 return $list;
484
485         }
486
487         function array_get_name_value_lists($array){
488                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->array_get_name_value_lists');
489             $list = array();
490             foreach($array as $name=>$value){
491                 $tmp_value=$value;
492                 if(is_array($value)){
493                     $tmp_value = array();
494                     foreach($value as $k=>$v){
495                         $tmp_value[$k] = $this->get_name_value($k, $v);
496                     }
497                 }
498                 $list[$name] = $this->get_name_value($name, $tmp_value);
499             }
500                 $GLOBALS['log']->info('End: SoapHelperWebServices->array_get_name_value_lists');
501             return $list;
502         }
503
504         function name_value_lists_get_array($list){
505                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->name_value_lists_get_array');
506             $array = array();
507             foreach($list as $key=>$value){
508                 if(isset($value['value']) && isset($value['name'])){
509                     if(is_array($value['value'])){
510                         $array[$value['name']]=array();
511                         foreach($value['value'] as $v){
512                             $array[$value['name']][$v['name']]=$v['value'];
513                         }
514                     }else{
515                         $array[$value['name']]=$value['value'];
516                     }
517                 }
518             }
519                 $GLOBALS['log']->info('End: SoapHelperWebServices->name_value_lists_get_array');
520             return $array;
521         }
522
523         function array_get_return_value($array, $module){
524
525                 $GLOBALS['log']->info('Begin/End: SoapHelperWebServices->array_get_return_value');
526                 return Array('id'=>$array['id'],
527                                         'module_name'=> $module,
528                                         'name_value_list'=>$this->array_get_name_value_list($array)
529                                         );
530         }
531
532         function get_return_value_for_fields($value, $module, $fields) {
533                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_value_for_fields');
534                 global $module_name, $current_user;
535                 $module_name = $module;
536                 if($module == 'Users' && $value->id != $current_user->id){
537                         $value->user_hash = '';
538                 }
539                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_return_value_for_fields');
540                 return Array('id'=>$value->id,
541                                         'module_name'=> $module,
542                                         'name_value_list'=>$this->get_name_value_list_for_fields($value, $fields)
543                                         );
544         }
545
546         function getRelationshipResults($bean, $link_field_name, $link_module_fields, $optional_where = '') {
547                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->getRelationshipResults');
548                 require_once('include/TimeDate.php');
549                 global  $beanList, $beanFiles, $current_user;
550                 global $disable_date_format;
551
552                 $bean->load_relationship($link_field_name);
553                 if (isset($bean->$link_field_name)) {
554                         // get the query object for this link field
555                         $query_array = $bean->$link_field_name->getQuery(true,array(),0,'',true);
556                         if (isset($query_array['where'])) {
557                                 $query_array['where'] = str_ireplace("where", "", $query_array['where']);
558                                 if (!empty($optional_where)) {
559                                         $optional_where = $query_array['where'] . " and " . $optional_where;
560                                 } else {
561                                         $optional_where = $query_array['where'];
562                                 } // else
563                         } // if
564
565                         $params = array();
566                         $params['joined_tables'] = $query_array['join_tables'];
567
568                         // get the related module name and instantiate a bean for that.
569                         $submodulename = $bean->$link_field_name->getRelatedModuleName();
570                         $submoduleclass = $beanList[$submodulename];
571                         require_once($beanFiles[$submoduleclass]);
572                         $submodule = new $submoduleclass();
573                         $filterFields = $this->filter_fields($submodule, $link_module_fields);
574                         $relFields = $bean->$link_field_name->getRelatedFields();
575                         $roleSelect = '';
576
577                         $idSetInSubModule = false;
578                         if($submodulename == 'Users' && !in_array('id', $link_module_fields)){
579                                 $link_module_fields[] = 'id';
580                                 $idSetInSubModule = true;
581                         }
582
583                         if(!empty($relFields)){
584                                 foreach($link_module_fields as $field){
585                                         if(!empty($relFields[$field])){
586                                                 $roleSelect .= ', ' . $query_array['join_tables'][0] . '.'. $field;
587                                         }
588                                 }
589                         }
590                         // create a query
591                         $subquery = $submodule->create_new_list_query('',$optional_where ,$filterFields,$params, 0,'', true,$bean);
592                         $query =  $subquery['select'].$roleSelect .   $subquery['from'].$query_array['join']. $subquery['where'];
593                         $GLOBALS['log']->info('SoapHelperWebServices->getRelationshipResults query = ' . $query);
594
595                         $result = $submodule->db->query($query, true);
596                         $list = array();
597                         while($row = $submodule->db->fetchByAssoc($result)) {
598                                 if (!$disable_date_format) {
599                                         foreach ($filterFields as $field) {
600                                                 if (isset($submodule->field_defs[$field]) &&
601                                                         isset($submodule->field_defs[$field]['type']) &&
602                                                         isset($row[$field])) {
603
604                                                                 if ($submodule->field_defs[$field]['type'] == 'date') {
605                                                                         global $timedate;
606                                                                         $row[$field] = $timedate->to_display_date_time($row[$field]);
607                                                                 }
608                                                                 if ($submodule->field_defs[$field]['type'] == 'currency') {
609                                                                         // TODO: convert data from db to user preferred format absed on the community input
610                                                                 } // if
611                                                 } // if
612
613                                         } // foreach
614                                 }
615                                 if($submodulename == 'Users' && $current_user->id != $row['id']) {
616                                         $row['user_hash'] = "";
617                                 } // if
618                                 if ($idSetInSubModule) {
619                                         unset($row['id']);
620                                 } // if
621                                 $list[] = $row;
622                         }
623                         $GLOBALS['log']->info('End: SoapHelperWebServices->getRelationshipResults');
624                         return array('rows' => $list, 'fields_set_on_rows' => $filterFields);
625                 } else {
626                         $GLOBALS['log']->info('End: SoapHelperWebServices->getRelationshipResults - ' . $link_field_name . ' relationship does not exists');
627                         return false;
628                 } // else
629
630         } // fn
631
632         function get_return_value_for_link_fields($bean, $module, $link_name_to_value_fields_array) {
633                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_value_for_link_fields');
634                 global $module_name, $current_user;
635                 $module_name = $module;
636                 if($module == 'Users' && $bean->id != $current_user->id){
637                         $bean->user_hash = '';
638                 }
639
640                 if (empty($link_name_to_value_fields_array) || !is_array($link_name_to_value_fields_array)) {
641                         $GLOBALS['log']->debug('End: SoapHelperWebServices->get_return_value_for_link_fields - Invalid link information passed ');
642                         return array();
643                 }
644
645                 if ($this->isLogLevelDebug()) {
646                         $GLOBALS['log']->debug('SoapHelperWebServices->get_return_value_for_link_fields - link info = ' . var_export($link_name_to_value_fields_array, true));
647                 } // if
648                 $link_output = array();
649                 foreach($link_name_to_value_fields_array as $link_name_value_fields) {
650                         if (!is_array($link_name_value_fields) || !isset($link_name_value_fields['name']) || !isset($link_name_value_fields['value'])) {
651                                 continue;
652                         }
653                         $link_field_name = $link_name_value_fields['name'];
654                         $link_module_fields = $link_name_value_fields['value'];
655                         if (is_array($link_module_fields) && !empty($link_module_fields)) {
656                                 $result = $this->getRelationshipResults($bean, $link_field_name, $link_module_fields);
657                                 if (!$result) {
658                                         $link_output[] = array('name' => $link_field_name, 'records' => array());
659                                         continue;
660                                 }
661                                 $list = $result['rows'];
662                                 $filterFields = $result['fields_set_on_rows'];
663                                 if ($list) {
664                                         $rowArray = array();
665                                         foreach($list as $row) {
666                                                 $nameValueArray = array();
667                                                 foreach ($filterFields as $field) {
668                                                         $nameValue = array();
669                                                         if (isset($row[$field])) {
670                                                                 $nameValueArray[$field] = $this->get_name_value($field, $row[$field]);
671                                                         } // if
672                                                 } // foreach
673                                                 $rowArray[] = $nameValueArray;
674                                         } // foreach
675                                         $link_output[] = array('name' => $link_field_name, 'records' => $rowArray);
676                                 } // if
677                         } // if
678                 } // foreach
679                 $GLOBALS['log']->debug('End: SoapHelperWebServices->get_return_value_for_link_fields');
680                 if ($this->isLogLevelDebug()) {
681                         $GLOBALS['log']->debug('SoapHelperWebServices->get_return_value_for_link_fields - output = ' . var_export($link_output, true));
682                 } // if
683                 return $link_output;
684         } // fn
685
686         /**
687          *
688          * @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).
689          * @param String $module_id -- The ID of the bean in the specified module
690          * @param String $link_field_name - The relationship name for which to create realtionships.
691          * @param Array $related_ids -- The array of ids for which we want to create relationships
692          * @param Array $name_value_list -- The array of name value pair of additional attributes to be set when adding this relationship
693          * @param int delete -- If 0 then add relationship else delete this relationship data
694          * @return true on success, false on failure
695          */
696         function new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids, $name_value_list, $delete) {
697                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->new_handle_set_relationship');
698             global  $beanList, $beanFiles;
699
700             if(empty($beanList[$module_name])) {
701                         $GLOBALS['log']->debug('SoapHelperWebServices->new_handle_set_relationship - module ' . $module_name . ' does not exists' );
702                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
703                 return false;
704             } // if
705             $class_name = $beanList[$module_name];
706             require_once($beanFiles[$class_name]);
707             $mod = new $class_name();
708             $mod->retrieve($module_id);
709                 if(!$mod->ACLAccess('DetailView')){
710                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
711                         return false;
712                 }
713
714                 if ($mod->load_relationship($link_field_name)) {
715                         if (!$delete) {
716                                 $name_value_pair = array();
717                                 if (!empty($name_value_list)) {
718                                         $relFields = $mod->$link_field_name->getRelatedFields();
719                                         if(!empty($relFields)){
720                                                 $relFieldsKeys = array_keys($relFields);
721                                                 foreach($name_value_list as $key => $value) {
722                                                         if (in_array($value['name'], $relFieldsKeys)) {
723                                                                 $name_value_pair[$value['name']] = $value['value'];
724                                                         } // if
725                                                 } // foreach
726                                         } // if
727                                 }
728                                 $mod->$link_field_name->add($related_ids, $name_value_pair);
729                         } else {
730                                 foreach($related_ids as $id) {
731                                         $mod->$link_field_name->delete($module_id, $id);
732                                 } // foreach
733                         } // else
734                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
735                         return true;
736                 } else {
737                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
738                         return false;
739                 }
740         }
741
742         function new_handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) {
743                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->new_handle_set_entries');
744                 global $beanList, $beanFiles, $current_user, $app_list_strings;
745
746                 $ret_values = array();
747
748                 $class_name = $beanList[$module_name];
749                 require_once($beanFiles[$class_name]);
750                 $ids = array();
751                 $count = 1;
752                 $total = sizeof($name_value_lists);
753                 foreach($name_value_lists as $name_value_list){
754                         $seed = new $class_name();
755
756                         $seed->update_vcal = false;
757                         foreach($name_value_list as $value){
758                                 if($value['name'] == 'id'){
759                                         $seed->retrieve($value['value']);
760                                         break;
761                                 }
762                         }
763
764                         foreach($name_value_list as $value) {
765                                 $val = $value['value'];
766                                 if($seed->field_name_map[$value['name']]['type'] == 'enum'){
767                                         $vardef = $seed->field_name_map[$value['name']];
768                                         if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value]) ) {
769                                                 if ( in_array($val,$app_list_strings[$vardef['options']]) ){
770                                                         $val = array_search($val,$app_list_strings[$vardef['options']]);
771                                                 }
772                                         }
773                                 }
774                                 if($module_name == 'Users' && !empty($seed->id) && ($seed->id != $current_user->id) && $value['name'] == 'user_hash'){
775                                         continue;
776                                 }
777
778                                 $seed->$value['name'] = $val;
779                         }
780
781                         if($count == $total){
782                                 $seed->update_vcal = false;
783                         }
784                         $count++;
785
786                         //Add the account to a contact
787                         if($module_name == 'Contacts'){
788                                 $GLOBALS['log']->debug('Creating Contact Account');
789                                 $this->add_create_account($seed);
790                                 $duplicate_id = $this->check_for_duplicate_contacts($seed);
791                                 if($duplicate_id == null){
792                                         if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
793                                                 $seed->save();
794                                                 if($seed->deleted == 1){
795                                                         $seed->mark_deleted($seed->id);
796                                                 }
797                                                 $ids[] = $seed->id;
798                                         }
799                                 }
800                                 else{
801                                         //since we found a duplicate we should set the sync flag
802                                         if( $seed->ACLAccess('Save')){
803                                                 $seed = new $class_name();
804                                                 $seed->id = $duplicate_id;
805                                                 $seed->contacts_users_id = $current_user->id;
806                                                 $seed->save();
807                                                 $ids[] = $duplicate_id;//we have a conflict
808                                         }
809                                 }
810                         }
811                         else if($module_name == 'Meetings' || $module_name == 'Calls'){
812                                 //we are going to check if we have a meeting in the system
813                                 //with the same outlook_id. If we do find one then we will grab that
814                                 //id and save it
815                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
816                                         if(empty($seed->id) && !isset($seed->id)){
817                                                 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){
818                                                         //at this point we have an object that does not have
819                                                         //the id set, but does have the outlook_id set
820                                                         //so we need to query the db to find if we already
821                                                         //have an object with this outlook_id, if we do
822                                                         //then we can set the id, otherwise this is a new object
823                                                         $order_by = "";
824                                                         $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'";
825                                                         $response = $seed->get_list($order_by, $query, 0,-1,-1,0);
826                                                         $list = $response['list'];
827                                                         if(count($list) > 0){
828                                                                 foreach($list as $value)
829                                                                 {
830                                                                         $seed->id = $value->id;
831                                                                         break;
832                                                                 }
833                                                         }//fi
834                                                 }//fi
835                                         }//fi
836                                     if (empty($seed->reminder_time)) {
837                         $seed->reminder_time = -1;
838                     }
839                     if($seed->reminder_time == -1){
840                         $defaultRemindrTime = $current_user->getPreference('reminder_time');
841                         if ($defaultRemindrTime != -1){
842                             $seed->reminder_checked = '1';
843                             $seed->reminder_time = $defaultRemindrTime;
844                         }
845                     }
846                                         $seed->save();
847                                         $ids[] = $seed->id;
848                                 }//fi
849                         }
850                         else
851                         {
852                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
853                                         $seed->save();
854                                         $ids[] = $seed->id;
855                                 }
856                         }
857
858                         // if somebody is calling set_entries_detail() and wants fields returned...
859                         if ($select_fields !== FALSE) {
860                                 $ret_values[$count] = array();
861
862                                 foreach ($select_fields as $select_field) {
863                                         if (isset($seed->$select_field)) {
864                                                 $ret_values[$count][$select_field] = $this->get_name_value($select_field, $seed->$select_field);
865                                         }
866                                 }
867                         }
868                 }
869
870                 // handle returns for set_entries_detail() and set_entries()
871                 if ($select_fields !== FALSE) {
872                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
873                         return array(
874                                 'name_value_lists' => $ret_values,
875                         );
876                 }
877                 else {
878                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
879                         return array(
880                                 'ids' => $ids,
881                         );
882                 }
883         }
884
885         function get_return_value($value, $module){
886                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_value');
887                 global $module_name, $current_user;
888                 $module_name = $module;
889                 if($module == 'Users' && $value->id != $current_user->id){
890                         $value->user_hash = '';
891                 }
892                 $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
893                 return Array('id'=>$value->id,
894                                         'module_name'=> $module,
895                                         'name_value_list'=>$this->get_name_value_list($value)
896                                         );
897         }
898
899
900         function get_return_module_fields($value, $module,$fields, $translate=true){
901                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_module_fields');
902                 global $module_name;
903                 $module_name = $module;
904                 $result = $this->get_field_list($value,$fields,  $translate);
905                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_return_module_fields');
906                 return Array('module_name'=>$module,
907                                         'module_fields'=> $result['module_fields'],
908                                         'link_fields'=> $result['link_fields'],
909                                         );
910         } // fn
911
912         function login_success($name_value_list = array()){
913                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->login_success');
914                 global $current_language, $sugar_config, $app_strings, $app_list_strings;
915                 $current_language = $sugar_config['default_language'];
916                 if (is_array($name_value_list) && !empty($name_value_list)) {
917                         foreach($name_value_list as $key => $value) {
918                                 if (isset($value['name']) && ($value['name'] == 'language')) {
919                                         $language = $value['value'];
920                                         $supportedLanguages = $sugar_config['languages'];
921                                         if (array_key_exists($language, $supportedLanguages)) {
922                                                 $current_language = $language;
923                                         } // if
924                                 } // if
925                                 if (isset($value['name']) && ($value['name'] == 'notifyonsave')) {
926                                         if ($value['value']) {
927                                                 $_SESSION['notifyonsave'] = true;
928                                         }
929                                 } // if
930                         } // foreach
931                 } else {
932                         if (isset($_SESSION['user_language'])) {
933                                 $current_language = $_SESSION['user_language'];
934                         } // if
935                 }
936                 $GLOBALS['log']->info("Users language is = " . $current_language);
937                 $app_strings = return_application_language($current_language);
938                 $app_list_strings = return_app_list_strings_language($current_language);
939                 $GLOBALS['log']->info('End: SoapHelperWebServices->login_success');
940         } // fn
941
942
943         function checkSaveOnNotify() {
944             $notifyonsave = false;
945             if (isset($_SESSION['notifyonsave']) && $_SESSION['notifyonsave'] == true) {
946                 $notifyonsave = true;
947             } // if
948                 return $notifyonsave;
949         }
950         /*
951          *      Given an account_name, either create the account or assign to a contact.
952          */
953         function add_create_account($seed) {
954                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->add_create_account');
955                 global $current_user;
956                 $account_name = $seed->account_name;
957                 $account_id = $seed->account_id;
958                 $assigned_user_id = $current_user->id;
959
960                 // check if it already exists
961             $focus = new Account();
962             if($focus->ACLAccess('Save')) {
963                         $class = get_class($seed);
964                         $temp = new $class();
965                         $temp->retrieve($seed->id);
966                         if ( empty($account_name) && empty($account_id)) {
967                                 return;
968                         } // if
969                         if (!isset($seed->accounts)){
970                             $seed->load_relationship('accounts');
971                         } // if
972
973                         if($seed->account_name == '' && isset($temp->account_id)){
974                                 $seed->accounts->delete($seed->id, $temp->account_id);
975                                 $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account');
976                                 return;
977                         }
978                     $arr = array();
979
980             if(!empty($account_id))  // bug # 44280
981             {
982                $query = "select id, deleted from {$focus->table_name} WHERE id='".$seed->db->quote($account_id)."'";
983             }
984             else
985             {
986                $query = "select id, deleted from {$focus->table_name} WHERE name='".$seed->db->quote($account_name)."'";
987             }
988             $result = $seed->db->query($query) or sugar_die("Error selecting sugarbean: ".mysql_error());
989
990                     $row = $seed->db->fetchByAssoc($result, -1, false);
991
992                         // we found a row with that id
993                     if (isset($row['id']) && $row['id'] != -1)
994                     {
995                         // if it exists but was deleted, just remove it entirely
996                         if ( isset($row['deleted']) && $row['deleted'] == 1)
997                         {
998                             $query2 = "delete from {$focus->table_name} WHERE id='". $seed->db->quote($row['id'])."'";
999                             $result2 = $seed->db->query($query2) or sugar_die("Error deleting existing sugarbean: ".mysql_error());
1000                                 }
1001                                 // else just use this id to link the contact to the account
1002                         else
1003                         {
1004                                 $focus->id = $row['id'];
1005                         }
1006                     }
1007
1008                         // if we didnt find the account, so create it
1009                     if (! isset($focus->id) || $focus->id == '')
1010                     {
1011                         $focus->name = $account_name;
1012
1013                                 if ( isset($assigned_user_id))
1014                                 {
1015                            $focus->assigned_user_id = $assigned_user_id;
1016                            $focus->modified_user_id = $assigned_user_id;
1017                                 }
1018                         $focus->save();
1019                     }
1020
1021                     if($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id){
1022                         $seed->accounts->delete($seed->id, $temp->account_id);
1023                     }
1024
1025                     if(isset($focus->id) && $focus->id != ''){
1026                                 $seed->account_id = $focus->id;
1027                         } // if
1028                         $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account');
1029
1030             } else {
1031                         $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account - Insufficient ACLAccess');
1032             } // else
1033         } // fn
1034
1035         function check_for_duplicate_contacts($seed){
1036                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->check_for_duplicate_contacts');
1037                 require_once('modules/Contacts/Contact.php');
1038
1039                 if(isset($seed->id)){
1040                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1041                         return null;
1042                 }
1043
1044                 $query = '';
1045
1046                 $trimmed_email = trim($seed->email1);
1047         $trimmed_email2 = trim($seed->email2);
1048             $trimmed_last = trim($seed->last_name);
1049             $trimmed_first = trim($seed->first_name);
1050                 if(!empty($trimmed_email) || !empty($trimmed_email2)){
1051
1052                         //obtain a list of contacts which contain the same email address
1053                         $contacts = $seed->emailAddress->getBeansByEmailAddress($trimmed_email);
1054             $contacts2 = $seed->emailAddress->getBeansByEmailAddress($trimmed_email2);
1055             $contacts = array_merge($contacts, $contacts2);
1056                         if(count($contacts) == 0){
1057                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1058                                 return null;
1059                         }else{
1060                                 foreach($contacts as $contact){
1061                                         if(!empty($trimmed_last) && strcmp($trimmed_last, $contact->last_name) == 0){
1062                                                 if((!empty($trimmed_email) || !empty($trimmed_email2)) && (strcmp($trimmed_email, $contact->email1) == 0 || strcmp($trimmed_email, $contact->email2) == 0 || strcmp($trimmed_email2, $contact->email) == 0 || strcmp($trimmed_email2, $contact->email2) == 0)){
1063                                                         $contact->load_relationship('accounts');
1064                                                         if(empty($seed->account_name) || strcmp($seed->account_name, $contact->account_name) == 0){
1065                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - duplicte found ' . $contact->id);
1066                                                                 return $contact->id;
1067                                                         }
1068                                                 }
1069                                         }
1070                                 }
1071                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1072                                 return null;
1073                         }
1074                 }else
1075                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1076                         return null;
1077         }
1078
1079
1080         /**
1081          * decrypt a string use the TripleDES algorithm. This meant to be
1082          * modified if the end user chooses a different algorithm
1083          *
1084          * @param $string - the string to decrypt
1085          *
1086          * @return a decrypted string if we can decrypt, the original string otherwise
1087          */
1088         function decrypt_string($string){
1089                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->decrypt_string');
1090                 if(function_exists('mcrypt_cbc')){
1091                         require_once('modules/Administration/Administration.php');
1092                         $focus = new Administration();
1093                         $focus->retrieveSettings();
1094                         $key = '';
1095                         if(!empty($focus->settings['ldap_enc_key'])){
1096                                 $key = $focus->settings['ldap_enc_key'];
1097                         }
1098                         if(empty($key)) {
1099                                 $GLOBALS['log']->info('End: SoapHelperWebServices->decrypt_string - empty key');
1100                                 return $string;
1101                         } // if
1102                         $buffer = $string;
1103                         $key = substr(md5($key),0,24);
1104                     $iv = "password";
1105                         $GLOBALS['log']->info('End: SoapHelperWebServices->decrypt_string');
1106                     return mcrypt_cbc(MCRYPT_3DES, $key, pack("H*", $buffer), MCRYPT_DECRYPT, $iv);
1107                 }else{
1108                         $GLOBALS['log']->info('End: SoapHelperWebServices->decrypt_string');
1109                         return $string;
1110                 }
1111         } // fn
1112
1113         function isLogLevelDebug() {
1114                 if (isset($GLOBALS['sugar_config']['logger'])) {
1115                         if (isset($GLOBALS['sugar_config']['logger']['level'])) {
1116                                 return ($GLOBALS['sugar_config']['logger']['level'] == 'debug');
1117                         } // if
1118                 }
1119                 return false;
1120         } // fn
1121 } // clazz
1122
1123 ?>