]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/core/SoapHelperWebService.php
Release 6.2.0
[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                         session_start();
200                         if(!empty($_SESSION['is_valid_session']) && $this->is_valid_ip_address('ip_address') && $_SESSION['type'] == 'user'){
201
202                                 global $current_user;
203                                 require_once('modules/Users/User.php');
204                                 $current_user = new User();
205                                 $current_user->retrieve($_SESSION['user_id']);
206                                 $this->login_success();
207                                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_authenticated - passed');
208                                 $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated');
209                                 return true;
210                         }
211
212                         $GLOBALS['log']->debug("calling destroy");
213                         session_destroy();
214                 }
215                 LogicHook::initialize();
216                 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
217                 $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated - validation failed');
218                 return false;
219         }
220
221         /**
222          * Use the same logic as in SugarAuthenticate to validate the ip address
223          *
224          * @param string $session_var
225          * @return bool - true if the ip address is valid, false otherwise.
226          */
227         function is_valid_ip_address($session_var){
228                 global $sugar_config;
229                 // grab client ip address
230                 $clientIP = query_client_ip();
231                 $classCheck = 0;
232                 // check to see if config entry is present, if not, verify client ip
233                 if (!isset ($sugar_config['verify_client_ip']) || $sugar_config['verify_client_ip'] == true) {
234                         // check to see if we've got a current ip address in $_SESSION
235                         // and check to see if the session has been hijacked by a foreign ip
236                         if (isset ($_SESSION[$session_var])) {
237                                 $session_parts = explode(".", $_SESSION[$session_var]);
238                                 $client_parts = explode(".", $clientIP);
239                     if(count($session_parts) < 4) {
240                         $classCheck = 0;
241                     }else {
242                                 // match class C IP addresses
243                                 for ($i = 0; $i < 3; $i ++) {
244                                         if ($session_parts[$i] == $client_parts[$i]) {
245                                                 $classCheck = 1;
246                                                         continue;
247                                         } else {
248                                                 $classCheck = 0;
249                                                 break;
250                                                 }
251                                         }
252                         }
253                                         // we have a different IP address
254                                         if ($_SESSION[$session_var] != $clientIP && empty ($classCheck)) {
255                                                 $GLOBALS['log']->fatal("IP Address mismatch: SESSION IP: {$_SESSION[$session_var]} CLIENT IP: {$clientIP}");
256                                                 return false;
257                                         }
258                                 } else {
259                                         return false;
260                                 }
261                 }
262                 return true;
263         }
264
265         function checkSessionAndModuleAccess($session, $login_error_key, $module_name, $access_level, $module_access_level_error_key, $errorObject) {
266                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->checkSessionAndModuleAccess');
267                 if(!$this->validate_authenticated($session)){
268                         $GLOBALS['log']->info('SoapHelperWebServices->checkSessionAndModuleAccess - validate_authenticated failed');
269                         $errorObject->set_error('invalid_session');
270                         $this->setFaultObject($errorObject);
271                         $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
272                         return false;
273                 } // if
274
275                 global  $beanList, $beanFiles;
276                 if (!empty($module_name)) {
277                         if(empty($beanList[$module_name])){
278                                 $GLOBALS['log']->info('SoapHelperWebServices->checkSessionAndModuleAccess - module does not exists - ' . $module_name);
279                                 $errorObject->set_error('no_module');
280                                 $this->setFaultObject($errorObject);
281                                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
282                                 return false;
283                         } // if
284                         global $current_user;
285                         if(!$this->check_modules_access($current_user, $module_name, $access_level)){
286                                 $GLOBALS['log']->info('SoapHelperWebServices->checkSessionAndModuleAccess - no module access - ' . $module_name);
287                                 $errorObject->set_error('no_access');
288                                 $this->setFaultObject($errorObject);
289                                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
290                                 return false;
291                         }
292                 } // if
293                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkSessionAndModuleAccess');
294                 return true;
295         } // fn
296
297         function checkACLAccess($bean, $viewType, $errorObject, $error_key) {
298                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->checkACLAccess');
299                 if(!$bean->ACLAccess($viewType)) {
300                         $GLOBALS['log']->info('SoapHelperWebServices->checkACLAccess - no ACLAccess');
301                         $errorObject->set_error($error_key);
302                         $this->setFaultObject($errorObject);
303                         $GLOBALS['log']->info('End: SoapHelperWebServices->checkACLAccess');
304                         return false;
305                 } // if
306                 $GLOBALS['log']->info('End: SoapHelperWebServices->checkACLAccess');
307                 return true;
308         } // fn
309
310         function get_name_value($field,$value){
311                 return array('name'=>$field, 'value'=>$value);
312         }
313
314         function get_user_module_list($user){
315                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_user_module_list');
316                 global $app_list_strings, $current_language;
317                 $app_list_strings = return_app_list_strings_language($current_language);
318                 $modules = query_module_access_list($user);
319                 ACLController :: filterModuleList($modules, false);
320                 global $modInvisList;
321
322                 foreach($modInvisList as $invis){
323                         $modules[$invis] = 'read_only';
324                 }
325
326                 $actions = ACLAction::getUserActions($user->id,true);
327                 foreach($actions as $key=>$value){
328                         if(isset($value['module']) && $value['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED){
329                                 if ($value['module']['access']['aclaccess'] == ACL_ALLOW_DISABLED) {
330                                         unset($modules[$key]);
331                                 } else {
332                                         $modules[$key] = 'read_only';
333                                 } // else
334                         } else {
335                                 $modules[$key] = '';
336                         } // else
337                 } // foreach
338                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_user_module_list');
339                 return $modules;
340
341         }
342
343         function check_modules_access($user, $module_name, $action='write'){
344                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->check_modules_access');
345                 if(!isset($_SESSION['avail_modules'])){
346                         $_SESSION['avail_modules'] = $this->get_user_module_list($user);
347                 }
348                 if(isset($_SESSION['avail_modules'][$module_name])){
349                         if($action == 'write' && $_SESSION['avail_modules'][$module_name] == 'read_only'){
350                                 if(is_admin($user)) {
351                                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
352                                         return true;
353                                 } // if
354                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
355                                 return false;
356                         }
357                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
358                         return true;
359                 }
360                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_modules_access');
361                 return false;
362
363         }
364
365         function get_name_value_list($value){
366                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_name_value_list');
367                 global $app_list_strings;
368                 $list = array();
369                 if(!empty($value->field_defs)){
370                         if(isset($value->assigned_user_name)) {
371                                 $list['assigned_user_name'] = $this->get_name_value('assigned_user_name', $value->assigned_user_name);
372                         }
373                         if(isset($value->modified_by_name)) {
374                                 $list['modified_by_name'] = $this->get_name_value('modified_by_name', $value->modified_by_name);
375                         }
376                         if(isset($value->created_by_name)) {
377                                 $list['created_by_name'] = $this->get_name_value('created_by_name', $value->created_by_name);
378                         }
379                         foreach($value->field_defs as $var){
380                                 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate'))continue;
381
382                                 if(isset($value->$var['name'])){
383                                         $val = $value->$var['name'];
384                                         $type = $var['type'];
385
386                                         if(strcmp($type, 'date') == 0){
387                                                 $val = substr($val, 0, 10);
388                                         }elseif(strcmp($type, 'enum') == 0 && !empty($var['options'])){
389                                                 //$val = $app_list_strings[$var['options']][$val];
390                                         }
391
392                                         $list[$var['name']] = $this->get_name_value($var['name'], $val);
393                                 }
394                         }
395                 }
396                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_name_value_list');
397                 return $list;
398
399         }
400
401         function filter_fields($value, $fields) {
402                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->filter_fields');
403                 global $invalid_contact_fields;
404                 $filterFields = array();
405                 foreach($fields as $field){
406                         if (is_array($invalid_contact_fields)) {
407                                 if (in_array($field, $invalid_contact_fields)) {
408                                         continue;
409                                 } // if
410                         } // if
411                         if (isset($value->field_defs[$field])) {
412                                 $var = $value->field_defs[$field];
413                                 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')) {
414
415                                         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'))) {
416
417                                         } else {
418                                                 continue;
419                                         }
420                                 }
421                         } // if
422                         $filterFields[] = $field;
423                 } // foreach
424                 $GLOBALS['log']->info('End: SoapHelperWebServices->filter_fields');
425                 return $filterFields;
426         } // fn
427
428         function get_name_value_list_for_fields($value, $fields) {
429                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_name_value_list_for_fields');
430                 global $app_list_strings;
431                 global $invalid_contact_fields;
432
433                 $list = array();
434                 if(!empty($value->field_defs)){
435                         if(empty($fields))$fields = array_keys($value->field_defs);
436                         if(isset($value->assigned_user_name) && in_array('assigned_user_name', $fields)) {
437                                 $list['assigned_user_name'] = $this->get_name_value('assigned_user_name', $value->assigned_user_name);
438                         }
439                         if(isset($value->modified_by_name) && in_array('modified_by_name', $fields)) {
440                                 $list['modified_by_name'] = $this->get_name_value('modified_by_name', $value->modified_by_name);
441                         }
442                         if(isset($value->created_by_name) && in_array('created_by_name', $fields)) {
443                                 $list['created_by_name'] = $this->get_name_value('created_by_name', $value->created_by_name);
444                         }
445
446                         $filterFields = $this->filter_fields($value, $fields);
447                         foreach($filterFields as $field){
448                                 $var = $value->field_defs[$field];
449                                 if(isset($value->$var['name'])){
450                                         $val = $value->$var['name'];
451                                         $type = $var['type'];
452
453                                         if(strcmp($type, 'date') == 0){
454                                                 $val = substr($val, 0, 10);
455                                         }elseif(strcmp($type, 'enum') == 0 && !empty($var['options'])){
456                                                 //$val = $app_list_strings[$var['options']][$val];
457                                         }
458
459                                         $list[$var['name']] = $this->get_name_value($var['name'], $val);
460                                 } // if
461                         } // foreach
462                 } // if
463                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_name_value_list_for_fields');
464                 if ($this->isLogLevelDebug()) {
465                         $GLOBALS['log']->debug('SoapHelperWebServices->get_name_value_list_for_fields - return data = ' . var_export($list, true));
466                 } // if
467                 return $list;
468
469         } // fn
470
471         function array_get_name_value_list($array){
472                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->array_get_name_value_list');
473                 $list = array();
474                 foreach($array as $name=>$value){
475                         $list[$name] = $this->get_name_value($name, $value);
476                 }
477                 $GLOBALS['log']->info('End: SoapHelperWebServices->array_get_name_value_list');
478                 return $list;
479
480         }
481
482         function array_get_name_value_lists($array){
483                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->array_get_name_value_lists');
484             $list = array();
485             foreach($array as $name=>$value){
486                 $tmp_value=$value;
487                 if(is_array($value)){
488                     $tmp_value = array();
489                     foreach($value as $k=>$v){
490                         $tmp_value[$k] = $this->get_name_value($k, $v);
491                     }
492                 }
493                 $list[$name] = $this->get_name_value($name, $tmp_value);
494             }
495                 $GLOBALS['log']->info('End: SoapHelperWebServices->array_get_name_value_lists');
496             return $list;
497         }
498
499         function name_value_lists_get_array($list){
500                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->name_value_lists_get_array');
501             $array = array();
502             foreach($list as $key=>$value){
503                 if(isset($value['value']) && isset($value['name'])){
504                     if(is_array($value['value'])){
505                         $array[$value['name']]=array();
506                         foreach($value['value'] as $v){
507                             $array[$value['name']][$v['name']]=$v['value'];
508                         }
509                     }else{
510                         $array[$value['name']]=$value['value'];
511                     }
512                 }
513             }
514                 $GLOBALS['log']->info('End: SoapHelperWebServices->name_value_lists_get_array');
515             return $array;
516         }
517
518         function array_get_return_value($array, $module){
519
520                 $GLOBALS['log']->info('Begin/End: SoapHelperWebServices->array_get_return_value');
521                 return Array('id'=>$array['id'],
522                                         'module_name'=> $module,
523                                         'name_value_list'=>$this->array_get_name_value_list($array)
524                                         );
525         }
526
527         function get_return_value_for_fields($value, $module, $fields) {
528                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_value_for_fields');
529                 global $module_name, $current_user;
530                 $module_name = $module;
531                 if($module == 'Users' && $value->id != $current_user->id){
532                         $value->user_hash = '';
533                 }
534                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_return_value_for_fields');
535                 return Array('id'=>$value->id,
536                                         'module_name'=> $module,
537                                         'name_value_list'=>$this->get_name_value_list_for_fields($value, $fields)
538                                         );
539         }
540
541         function getRelationshipResults($bean, $link_field_name, $link_module_fields, $optional_where = '') {
542                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->getRelationshipResults');
543                 require_once('include/TimeDate.php');
544                 global  $beanList, $beanFiles, $current_user;
545                 global $disable_date_format;
546
547                 $bean->load_relationship($link_field_name);
548                 if (isset($bean->$link_field_name)) {
549                         // get the query object for this link field
550                         $query_array = $bean->$link_field_name->getQuery(true,array(),0,'',true);
551                         if (isset($query_array['where'])) {
552                                 $query_array['where'] = str_ireplace("where", "", $query_array['where']);
553                                 if (!empty($optional_where)) {
554                                         $optional_where = $query_array['where'] . " and " . $optional_where;
555                                 } else {
556                                         $optional_where = $query_array['where'];
557                                 } // else
558                         } // if
559
560                         $params = array();
561                         $params['joined_tables'] = $query_array['join_tables'];
562
563                         // get the related module name and instantiate a bean for that.
564                         $submodulename = $bean->$link_field_name->getRelatedModuleName();
565                         $submoduleclass = $beanList[$submodulename];
566                         require_once($beanFiles[$submoduleclass]);
567                         $submodule = new $submoduleclass();
568                         $filterFields = $this->filter_fields($submodule, $link_module_fields);
569                         $relFields = $bean->$link_field_name->getRelatedFields();
570                         $roleSelect = '';
571
572                         $idSetInSubModule = false;
573                         if($submodulename == 'Users' && !in_array('id', $link_module_fields)){
574                                 $link_module_fields[] = 'id';
575                                 $idSetInSubModule = true;
576                         }
577
578                         if(!empty($relFields)){
579                                 foreach($link_module_fields as $field){
580                                         if(!empty($relFields[$field])){
581                                                 $roleSelect .= ', ' . $query_array['join_tables'][0] . '.'. $field;
582                                         }
583                                 }
584                         }
585                         // create a query
586                         $subquery = $submodule->create_new_list_query('',$optional_where ,$filterFields,$params, 0,'', true,$bean);
587                         $query =  $subquery['select'].$roleSelect .   $subquery['from'].$query_array['join']. $subquery['where'];
588                         $GLOBALS['log']->info('SoapHelperWebServices->getRelationshipResults query = ' . $query);
589
590                         $result = $submodule->db->query($query, true);
591                         $list = array();
592                         while($row = $submodule->db->fetchByAssoc($result)) {
593                                 if (!$disable_date_format) {
594                                         foreach ($filterFields as $field) {
595                                                 if (isset($submodule->field_defs[$field]) &&
596                                                         isset($submodule->field_defs[$field]['type']) &&
597                                                         isset($row[$field])) {
598
599                                                                 if ($submodule->field_defs[$field]['type'] == 'date') {
600                                                                         global $timedate;
601                                                                         $row[$field] = $timedate->to_display_date_time($row[$field]);
602                                                                 }
603                                                                 if ($submodule->field_defs[$field]['type'] == 'currency') {
604                                                                         // TODO: convert data from db to user preferred format absed on the community input
605                                                                 } // if
606                                                 } // if
607
608                                         } // foreach
609                                 }
610                                 if($submodulename == 'Users' && $current_user->id != $row['id']) {
611                                         $row['user_hash'] = "";
612                                 } // if
613                                 if ($idSetInSubModule) {
614                                         unset($row['id']);
615                                 } // if
616                                 $list[] = $row;
617                         }
618                         $GLOBALS['log']->info('End: SoapHelperWebServices->getRelationshipResults');
619                         return array('rows' => $list, 'fields_set_on_rows' => $filterFields);
620                 } else {
621                         $GLOBALS['log']->info('End: SoapHelperWebServices->getRelationshipResults - ' . $link_field_name . ' relationship does not exists');
622                         return false;
623                 } // else
624
625         } // fn
626
627         function get_return_value_for_link_fields($bean, $module, $link_name_to_value_fields_array) {
628                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_value_for_link_fields');
629                 global $module_name, $current_user;
630                 $module_name = $module;
631                 if($module == 'Users' && $bean->id != $current_user->id){
632                         $bean->user_hash = '';
633                 }
634
635                 if (empty($link_name_to_value_fields_array) || !is_array($link_name_to_value_fields_array)) {
636                         $GLOBALS['log']->debug('End: SoapHelperWebServices->get_return_value_for_link_fields - Invalid link information passed ');
637                         return array();
638                 }
639
640                 if ($this->isLogLevelDebug()) {
641                         $GLOBALS['log']->debug('SoapHelperWebServices->get_return_value_for_link_fields - link info = ' . var_export($link_name_to_value_fields_array, true));
642                 } // if
643                 $link_output = array();
644                 foreach($link_name_to_value_fields_array as $link_name_value_fields) {
645                         if (!is_array($link_name_value_fields) || !isset($link_name_value_fields['name']) || !isset($link_name_value_fields['value'])) {
646                                 continue;
647                         }
648                         $link_field_name = $link_name_value_fields['name'];
649                         $link_module_fields = $link_name_value_fields['value'];
650                         if (is_array($link_module_fields) && !empty($link_module_fields)) {
651                                 $result = $this->getRelationshipResults($bean, $link_field_name, $link_module_fields);
652                                 if (!$result) {
653                                         $link_output[] = array('name' => $link_field_name, 'records' => array());
654                                         continue;
655                                 }
656                                 $list = $result['rows'];
657                                 $filterFields = $result['fields_set_on_rows'];
658                                 if ($list) {
659                                         $rowArray = array();
660                                         foreach($list as $row) {
661                                                 $nameValueArray = array();
662                                                 foreach ($filterFields as $field) {
663                                                         $nameValue = array();
664                                                         if (isset($row[$field])) {
665                                                                 $nameValueArray[$field] = $this->get_name_value($field, $row[$field]);
666                                                         } // if
667                                                 } // foreach
668                                                 $rowArray[] = $nameValueArray;
669                                         } // foreach
670                                         $link_output[] = array('name' => $link_field_name, 'records' => $rowArray);
671                                 } // if
672                         } // if
673                 } // foreach
674                 $GLOBALS['log']->debug('End: SoapHelperWebServices->get_return_value_for_link_fields');
675                 if ($this->isLogLevelDebug()) {
676                         $GLOBALS['log']->debug('SoapHelperWebServices->get_return_value_for_link_fields - output = ' . var_export($link_output, true));
677                 } // if
678                 return $link_output;
679         } // fn
680
681         /**
682          *
683          * @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).
684          * @param String $module_id -- The ID of the bean in the specified module
685          * @param String $link_field_name - The relationship name for which to create realtionships.
686          * @param Array $related_ids -- The array of ids for which we want to create relationships
687          * @param Array $name_value_list -- The array of name value pair of additional attributes to be set when adding this relationship
688          * @param int delete -- If 0 then add relationship else delete this relationship data
689          * @return true on success, false on failure
690          */
691         function new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids, $name_value_list, $delete) {
692                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->new_handle_set_relationship');
693             global  $beanList, $beanFiles;
694
695             if(empty($beanList[$module_name])) {
696                         $GLOBALS['log']->debug('SoapHelperWebServices->new_handle_set_relationship - module ' . $module_name . ' does not exists' );
697                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
698                 return false;
699             } // if
700             $class_name = $beanList[$module_name];
701             require_once($beanFiles[$class_name]);
702             $mod = new $class_name();
703             $mod->retrieve($module_id);
704                 if(!$mod->ACLAccess('DetailView')){
705                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
706                         return false;
707                 }
708
709                 if ($mod->load_relationship($link_field_name)) {
710                         if (!$delete) {
711                                 $name_value_pair = array();
712                                 if (!empty($name_value_list)) {
713                                         $relFields = $mod->$link_field_name->getRelatedFields();
714                                         if(!empty($relFields)){
715                                                 $relFieldsKeys = array_keys($relFields);
716                                                 foreach($name_value_list as $key => $value) {
717                                                         if (in_array($value['name'], $relFieldsKeys)) {
718                                                                 $name_value_pair[$value['name']] = $value['value'];
719                                                         } // if
720                                                 } // foreach
721                                         } // if
722                                 }
723                                 $mod->$link_field_name->add($related_ids, $name_value_pair);
724                         } else {
725                                 foreach($related_ids as $id) {
726                                         $mod->$link_field_name->delete($module_id, $id);
727                                 } // foreach
728                         } // else
729                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
730                         return true;
731                 } else {
732                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_relationship');
733                         return false;
734                 }
735         }
736
737         function new_handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) {
738                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->new_handle_set_entries');
739                 global $beanList, $beanFiles, $current_user, $app_list_strings;
740
741                 $ret_values = array();
742
743                 $class_name = $beanList[$module_name];
744                 require_once($beanFiles[$class_name]);
745                 $ids = array();
746                 $count = 1;
747                 $total = sizeof($name_value_lists);
748                 foreach($name_value_lists as $name_value_list){
749                         $seed = new $class_name();
750
751                         $seed->update_vcal = false;
752                         foreach($name_value_list as $value){
753                                 if($value['name'] == 'id'){
754                                         $seed->retrieve($value['value']);
755                                         break;
756                                 }
757                         }
758
759                         foreach($name_value_list as $value) {
760                                 $val = $value['value'];
761                                 if($seed->field_name_map[$value['name']]['type'] == 'enum'){
762                                         $vardef = $seed->field_name_map[$value['name']];
763                                         if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value]) ) {
764                                                 if ( in_array($val,$app_list_strings[$vardef['options']]) ){
765                                                         $val = array_search($val,$app_list_strings[$vardef['options']]);
766                                                 }
767                                         }
768                                 }
769                                 if($module_name == 'Users' && !empty($seed->id) && ($seed->id != $current_user->id) && $value['name'] == 'user_hash'){
770                                         continue;
771                                 }
772
773                                 $seed->$value['name'] = $val;
774                         }
775
776                         if($count == $total){
777                                 $seed->update_vcal = false;
778                         }
779                         $count++;
780
781                         //Add the account to a contact
782                         if($module_name == 'Contacts'){
783                                 $GLOBALS['log']->debug('Creating Contact Account');
784                                 $this->add_create_account($seed);
785                                 $duplicate_id = $this->check_for_duplicate_contacts($seed);
786                                 if($duplicate_id == null){
787                                         if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
788                                                 $seed->save();
789                                                 if($seed->deleted == 1){
790                                                         $seed->mark_deleted($seed->id);
791                                                 }
792                                                 $ids[] = $seed->id;
793                                         }
794                                 }
795                                 else{
796                                         //since we found a duplicate we should set the sync flag
797                                         if( $seed->ACLAccess('Save')){
798                                                 $seed = new $class_name();
799                                                 $seed->id = $duplicate_id;
800                                                 $seed->contacts_users_id = $current_user->id;
801                                                 $seed->save();
802                                                 $ids[] = $duplicate_id;//we have a conflict
803                                         }
804                                 }
805                         }
806                         else if($module_name == 'Meetings' || $module_name == 'Calls'){
807                                 //we are going to check if we have a meeting in the system
808                                 //with the same outlook_id. If we do find one then we will grab that
809                                 //id and save it
810                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
811                                         if(empty($seed->id) && !isset($seed->id)){
812                                                 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){
813                                                         //at this point we have an object that does not have
814                                                         //the id set, but does have the outlook_id set
815                                                         //so we need to query the db to find if we already
816                                                         //have an object with this outlook_id, if we do
817                                                         //then we can set the id, otherwise this is a new object
818                                                         $order_by = "";
819                                                         $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'";
820                                                         $response = $seed->get_list($order_by, $query, 0,-1,-1,0);
821                                                         $list = $response['list'];
822                                                         if(count($list) > 0){
823                                                                 foreach($list as $value)
824                                                                 {
825                                                                         $seed->id = $value->id;
826                                                                         break;
827                                                                 }
828                                                         }//fi
829                                                 }//fi
830                                         }//fi
831                                     if (empty($seed->reminder_time)) {
832                         $seed->reminder_time = -1;
833                     }
834                     if($seed->reminder_time == -1){
835                         $defaultRemindrTime = $current_user->getPreference('reminder_time');
836                         if ($defaultRemindrTime != -1){
837                             $seed->reminder_checked = '1';
838                             $seed->reminder_time = $defaultRemindrTime;
839                         }
840                     }
841                                         $seed->save();
842                                         $ids[] = $seed->id;
843                                 }//fi
844                         }
845                         else
846                         {
847                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
848                                         $seed->save();
849                                         $ids[] = $seed->id;
850                                 }
851                         }
852
853                         // if somebody is calling set_entries_detail() and wants fields returned...
854                         if ($select_fields !== FALSE) {
855                                 $ret_values[$count] = array();
856
857                                 foreach ($select_fields as $select_field) {
858                                         if (isset($seed->$select_field)) {
859                                                 $ret_values[$count][$select_field] = $this->get_name_value($select_field, $seed->$select_field);
860                                         }
861                                 }
862                         }
863                 }
864
865                 // handle returns for set_entries_detail() and set_entries()
866                 if ($select_fields !== FALSE) {
867                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
868                         return array(
869                                 'name_value_lists' => $ret_values,
870                         );
871                 }
872                 else {
873                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
874                         return array(
875                                 'ids' => $ids,
876                         );
877                 }
878         }
879
880         function get_return_value($value, $module){
881                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_value');
882                 global $module_name, $current_user;
883                 $module_name = $module;
884                 if($module == 'Users' && $value->id != $current_user->id){
885                         $value->user_hash = '';
886                 }
887                 $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
888                 return Array('id'=>$value->id,
889                                         'module_name'=> $module,
890                                         'name_value_list'=>$this->get_name_value_list($value)
891                                         );
892         }
893
894
895         function get_return_module_fields($value, $module,$fields, $translate=true){
896                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_module_fields');
897                 global $module_name;
898                 $module_name = $module;
899                 $result = $this->get_field_list($value,$fields,  $translate);
900                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_return_module_fields');
901                 return Array('module_name'=>$module,
902                                         'module_fields'=> $result['module_fields'],
903                                         'link_fields'=> $result['link_fields'],
904                                         );
905         } // fn
906
907         function login_success($name_value_list = array()){
908                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->login_success');
909                 global $current_language, $sugar_config, $app_strings, $app_list_strings;
910                 $current_language = $sugar_config['default_language'];
911                 if (is_array($name_value_list) && !empty($name_value_list)) {
912                         foreach($name_value_list as $key => $value) {
913                                 if (isset($value['name']) && ($value['name'] == 'language')) {
914                                         $language = $value['value'];
915                                         $supportedLanguages = $sugar_config['languages'];
916                                         if (array_key_exists($language, $supportedLanguages)) {
917                                                 $current_language = $language;
918                                         } // if
919                                 } // if
920                                 if (isset($value['name']) && ($value['name'] == 'notifyonsave')) {
921                                         if ($value['value']) {
922                                                 $_SESSION['notifyonsave'] = true;
923                                         }
924                                 } // if
925                         } // foreach
926                 } else {
927                         if (isset($_SESSION['user_language'])) {
928                                 $current_language = $_SESSION['user_language'];
929                         } // if
930                 }
931                 $GLOBALS['log']->info("Users language is = " . $current_language);
932                 $app_strings = return_application_language($current_language);
933                 $app_list_strings = return_app_list_strings_language($current_language);
934                 $GLOBALS['log']->info('End: SoapHelperWebServices->login_success');
935         } // fn
936
937
938         function checkSaveOnNotify() {
939             $notifyonsave = false;
940             if (isset($_SESSION['notifyonsave']) && $_SESSION['notifyonsave'] == true) {
941                 $notifyonsave = true;
942             } // if
943                 return $notifyonsave;
944         }
945         /*
946          *      Given an account_name, either create the account or assign to a contact.
947          */
948         function add_create_account($seed) {
949                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->add_create_account');
950                 global $current_user;
951                 $account_name = $seed->account_name;
952                 $account_id = $seed->account_id;
953                 $assigned_user_id = $current_user->id;
954
955                 // check if it already exists
956             $focus = new Account();
957             if($focus->ACLAccess('Save')) {
958                         $class = get_class($seed);
959                         $temp = new $class();
960                         $temp->retrieve($seed->id);
961                         if ((!isset($account_name) || $account_name == '')) {
962                                 return;
963                         } // if
964                         if (!isset($seed->accounts)){
965                             $seed->load_relationship('accounts');
966                         } // if
967
968                         if($seed->account_name = '' && isset($temp->account_id)){
969                                 $seed->accounts->delete($seed->id, $temp->account_id);
970                                 $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account');
971                                 return;
972                         }
973                     $arr = array();
974
975                     $query = "select id, deleted from {$focus->table_name} WHERE name='".$seed->db->quote($account_name)."'";
976                     $result = $seed->db->query($query) or sugar_die("Error selecting sugarbean: ".mysql_error());
977
978                     $row = $seed->db->fetchByAssoc($result, -1, false);
979
980                         // we found a row with that id
981                     if (isset($row['id']) && $row['id'] != -1)
982                     {
983                         // if it exists but was deleted, just remove it entirely
984                         if ( isset($row['deleted']) && $row['deleted'] == 1)
985                         {
986                             $query2 = "delete from {$focus->table_name} WHERE id='". $seed->db->quote($row['id'])."'";
987                             $result2 = $seed->db->query($query2) or sugar_die("Error deleting existing sugarbean: ".mysql_error());
988                                 }
989                                 // else just use this id to link the contact to the account
990                         else
991                         {
992                                 $focus->id = $row['id'];
993                         }
994                     }
995
996                         // if we didnt find the account, so create it
997                     if (! isset($focus->id) || $focus->id == '')
998                     {
999                         $focus->name = $account_name;
1000
1001                                 if ( isset($assigned_user_id))
1002                                 {
1003                            $focus->assigned_user_id = $assigned_user_id;
1004                            $focus->modified_user_id = $assigned_user_id;
1005                                 }
1006                         $focus->save();
1007                     }
1008
1009                     if($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id){
1010                         $seed->accounts->delete($seed->id, $temp->account_id);
1011                     }
1012
1013                     if(isset($focus->id) && $focus->id != ''){
1014                                 $seed->account_id = $focus->id;
1015                         } // if
1016                         $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account');
1017
1018             } else {
1019                         $GLOBALS['log']->info('End: SoapHelperWebServices->add_create_account - Insufficient ACLAccess');
1020             } // else
1021         } // fn
1022
1023         function check_for_duplicate_contacts($seed){
1024                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->check_for_duplicate_contacts');
1025                 require_once('modules/Contacts/Contact.php');
1026
1027                 if(isset($seed->id)){
1028                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1029                         return null;
1030                 }
1031
1032                 $query = '';
1033
1034                 $trimmed_email = trim($seed->email1);
1035                 $trimmed_last = trim($seed->last_name);
1036                 $trimmed_first = trim($seed->first_name);
1037                 if(!empty($trimmed_email)){
1038
1039                         //obtain a list of contacts which contain the same email address
1040                         $contacts = $seed->emailAddress->getBeansByEmailAddress($trimmed_email);
1041                         if(count($contacts) == 0){
1042                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1043                                 return null;
1044                         }else{
1045                                 foreach($contacts as $contact){
1046                                         if(!empty($trimmed_last) && strcmp($trimmed_last, $contact->last_name) == 0){
1047                                                 if(!empty($trimmed_email) && strcmp($trimmed_email, $contact->email1) == 0){
1048                                                         if(!empty($trimmed_email)){
1049                                                                 if(strcmp($trimmed_email, $contact->email1) == 0){
1050                                                                         //bug: 39234 - check if the account names are the same
1051                                                                         //if the incoming contact's account_name is empty OR it is not empty and is the same
1052                                                                         //as an existing contact's account name, then find the match.
1053                                                                         $contact->load_relationship('accounts');
1054                                                                         if(empty($seed->account_name) || strcmp($seed->account_name, $contact->account_name) == 0){
1055                                                                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - duplicte found ' . $contact->id);
1056                                                                                 return $contact->id;
1057                                                                         }
1058                                                                 }
1059                                                         }else{
1060                                                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - duplicte found' . $contact->id);
1061                                                                 return $contact->id;
1062                                                         }
1063                                                 }
1064                                         }
1065                                 }
1066                                 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1067                                 return null;
1068                         }
1069                 }else
1070                         $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - no duplicte found');
1071                         return null;
1072         }
1073
1074
1075         /**
1076          * decrypt a string use the TripleDES algorithm. This meant to be
1077          * modified if the end user chooses a different algorithm
1078          *
1079          * @param $string - the string to decrypt
1080          *
1081          * @return a decrypted string if we can decrypt, the original string otherwise
1082          */
1083         function decrypt_string($string){
1084                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->decrypt_string');
1085                 if(function_exists('mcrypt_cbc')){
1086                         require_once('modules/Administration/Administration.php');
1087                         $focus = new Administration();
1088                         $focus->retrieveSettings();
1089                         $key = '';
1090                         if(!empty($focus->settings['ldap_enc_key'])){
1091                                 $key = $focus->settings['ldap_enc_key'];
1092                         }
1093                         if(empty($key)) {
1094                                 $GLOBALS['log']->info('End: SoapHelperWebServices->decrypt_string - empty key');
1095                                 return $string;
1096                         } // if
1097                         $buffer = $string;
1098                         $key = substr(md5($key),0,24);
1099                     $iv = "password";
1100                         $GLOBALS['log']->info('End: SoapHelperWebServices->decrypt_string');
1101                     return mcrypt_cbc(MCRYPT_3DES, $key, pack("H*", $buffer), MCRYPT_DECRYPT, $iv);
1102                 }else{
1103                         $GLOBALS['log']->info('End: SoapHelperWebServices->decrypt_string');
1104                         return $string;
1105                 }
1106         } // fn
1107
1108         function isLogLevelDebug() {
1109                 if (isset($GLOBALS['sugar_config']['logger'])) {
1110                         if (isset($GLOBALS['sugar_config']['logger']['level'])) {
1111                                 return ($GLOBALS['sugar_config']['logger']['level'] == 'debug');
1112                         } // if
1113                 }
1114                 return false;
1115         } // fn
1116 } // clazz
1117
1118 ?>