]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/v4/SugarWebServiceUtilv4.php
Release 6.2.0
[Github/sugarcrm.git] / service / v4 / SugarWebServiceUtilv4.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 require_once('service/v3_1/SugarWebServiceUtilv3_1.php');
38
39 class SugarWebServiceUtilv4 extends SugarWebServiceUtilv3_1
40 {
41     function get_module_view_defs($moduleName, $type, $view)
42     {
43         require_once('include/MVC/View/SugarView.php');
44         $metadataFile = null;
45         $results = array();
46         if( empty($moduleName) )
47             return $results;
48
49         $view = strtolower($view);
50         switch (strtolower($type)){
51             case 'wireless':
52                 if( $view == 'list'){
53                     require_once('include/SugarWireless/SugarWirelessListView.php');
54                     $GLOBALS['module'] = $moduleName; //WirelessView keys off global variable not instance variable...
55                     $v = new SugarWirelessListView();
56                     $results = $v->getMetaDataFile();
57                     $results = self::formatWirelessListViewResultsToArray($results);
58
59                 }
60                 elseif ($view == 'subpanel')
61                     $results = $this->get_subpanel_defs($moduleName, $type);
62                 else{
63                     require_once('include/SugarWireless/SugarWirelessView.php');
64                     $v = new SugarWirelessView();
65                     $v->module = $moduleName;
66                     $fullView = ucfirst($view) . 'View';
67                     $meta = $v->getMetaDataFile('Wireless' . $fullView);
68                     $metadataFile = $meta['filename'];
69                     require($metadataFile);
70                     //Wireless detail metadata may actually be just edit metadata.
71                     $results = isset($viewdefs[$meta['module_name']][$fullView] ) ? $viewdefs[$meta['module_name']][$fullView] : $viewdefs[$meta['module_name']]['EditView'];
72                 }
73
74                 break;
75             case 'default':
76             default:
77                 if ($view == 'subpanel')
78                     $results = $this->get_subpanel_defs($moduleName, $type);
79                 else
80                 {
81                     $v = new SugarView(null,array());
82                     $v->module = $moduleName;
83                     $v->type = $view;
84                     $fullView = ucfirst($view) . 'View';
85                     $metadataFile = $v->getMetaDataFile();
86                     require_once($metadataFile);
87                     if($view == 'list')
88                         $results = $listViewDefs[$moduleName];
89                     else
90                         $results = $viewdefs[$moduleName][$fullView];
91                 }
92         }
93
94         //Add field level acls.
95         $results = $this->addFieldLevelACLs($moduleName,$type, $view, $results);
96
97         return $results;
98     }
99
100     /**
101      * Format the results for wirless list view metadata from an associative array to a
102      * numerically indexed array.  This conversion will ensure that consumers of the metadata
103      * can eval the json response and iterative over the results with the order of the fields
104      * preserved.
105      *
106      * @param array $fields
107      * @return array
108      */
109     function formatWirelessListViewResultsToArray($fields)
110     {
111         $results = array();
112         foreach($fields as $key => $defs)
113         {
114             $defs['name'] = $key;
115             $results[] = $defs;
116         }
117
118         return $results;
119     }
120
121     /**
122      * Equivalent of get_list function within SugarBean but allows the possibility to pass in an indicator
123      * if the list should filter for favorites.  Should eventually update the SugarBean function as well.
124      *
125      */
126     function get_data_list($seed, $order_by = "", $where = "", $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $favorites = false, $singleSelect=false)
127         {
128                 $GLOBALS['log']->debug("get_list:  order_by = '$order_by' and where = '$where' and limit = '$limit'");
129                 if(isset($_SESSION['show_deleted']))
130                 {
131                         $show_deleted = 1;
132                 }
133                 $order_by=$seed->process_order_by($order_by, null);
134
135                 if($seed->bean_implements('ACL') && ACLController::requireOwner($seed->module_dir, 'list') )
136                 {
137                         global $current_user;
138                         $owner_where = $seed->getOwnerWhere($current_user->id);
139                         if(!empty($owner_where)){
140                                 if(empty($where)){
141                                         $where = $owner_where;
142                                 }else{
143                                         $where .= ' AND '.  $owner_where;
144                                 }
145                         }
146                 }
147                 $params = array();
148                 if($favorites === TRUE )
149                   $params['favorites'] = true;
150
151                 $query = $seed->create_new_list_query($order_by, $where,array(),$params, $show_deleted,'',false,null,$singleSelect);
152                 return $seed->process_list_query($query, $row_offset, $limit, $max, $where);
153         }
154
155         /**
156      * Convert modules list to Web services result
157      *
158      * @param array $list List of module candidates (only keys are used)
159      * @param array $availModules List of module availability from Session
160      */
161     public function getModulesFromList($list, $availModules)
162     {
163         global $app_list_strings;
164         $enabled_modules = array();
165         $availModulesKey = array_flip($availModules);
166         foreach ($list as $key=>$value)
167         {
168             if( isset($availModulesKey[$key]) )
169             {
170                 $label = !empty( $app_list_strings['moduleList'][$key] ) ? $app_list_strings['moduleList'][$key] : '';
171                     $acl = $this->checkModuleRoleAccess($key);
172                     $fav = $this->is_favorites_enabled($key);
173                     $enabled_modules[] = array('module_key' => $key,'module_label' => $label, 'favorite_enabled' => $fav, 'acls' => $acl);
174             }
175         }
176         return $enabled_modules;
177     }
178
179     /**
180      * Return a boolean indicating if the bean name is favorites enabled.
181      *
182      * @param string The module name
183      * @return bool true indicating bean is favorites enabled
184      */
185     function is_favorites_enabled($module_name)
186     {
187         global $beanList, $beanFiles;
188
189         $fav = FALSE;
190         return $fav;
191     }
192
193    /**
194          * Parse wireless editview metadata and add ACL values.
195          *
196          * @param String $module_name
197          * @param array $metadata
198          * @return array Metadata with acls added
199          */
200         function metdataAclParserWirelessEdit($module_name, $metadata)
201         {
202             global  $beanList, $beanFiles;
203             $class_name = $beanList[$module_name];
204             require_once($beanFiles[$class_name]);
205             $seed = new $class_name();
206
207             $results = array();
208             $results['templateMeta'] = $metadata['templateMeta'];
209             $aclRows = array();
210             //Wireless metadata only has a single panel definition.
211             foreach ($metadata['panels'] as $row)
212             {
213                 $aclRow = array();
214                 foreach ($row as $field)
215                 {
216                     $aclField = array();
217                     if( is_string($field) )
218                         $aclField['name'] = $field;
219                     else
220                         $aclField = $field;
221
222                     if($seed->bean_implements('ACL'))
223                         $aclField['acl'] = $this->getFieldLevelACLValue($seed->module_dir, $aclField['name']);
224                     else
225                         $aclField['acl'] = ACL_FIELD_DEFAULT;
226
227                     $aclRow[] = $aclField;
228                 }
229                 $aclRows[] = $aclRow;
230             }
231
232             $results['panels'] = $aclRows;
233             return $results;
234         }
235
236         /**
237          * Parse wireless detailview metadata and add ACL values.
238          *
239          * @param String $module_name
240          * @param array $metadata
241          * @return array Metadata with acls added
242          */
243         function metdataAclParserWirelessDetail($module_name, $metadata)
244         {
245             return self::metdataAclParserWirelessEdit($module_name, $metadata);
246         }
247
248     /**
249          * Parse wireless listview metadata and add ACL values.
250          *
251          * @param String $module_name
252          * @param array $metadata
253          * @return array Metadata with acls added
254          */
255         function metdataAclParserWirelessList($module_name, $metadata)
256         {
257             global  $beanList, $beanFiles;
258             $class_name = $beanList[$module_name];
259             require_once($beanFiles[$class_name]);
260             $seed = new $class_name();
261
262             $results = array();
263             foreach ($metadata as $entry)
264             {
265                 $field_name = $entry['name'];
266                 if($seed->bean_implements('ACL'))
267                     $entry['acl'] = $this->getFieldLevelACLValue($seed->module_dir, strtolower($field_name));
268                 else
269                     $entry['acl'] = 99;
270
271                 $results[] = $entry;
272             }
273
274             return $results;
275         }
276         
277         /**
278          * Processes the filter_fields attribute to use with SugarBean::create_new_list_query()
279          *
280          * @param object $value SugarBean
281          * @param array $fields
282          * @return array
283          */
284     protected function filter_fields_for_query(SugarBean $value, array $fields)
285     {
286         $GLOBALS['log']->info('Begin: SoapHelperWebServices->filter_fields_for_query');
287         $filterFields = array();
288         foreach($fields as $field)
289         {
290             if (isset($value->field_defs[$field])) 
291             {
292                 $filterFields[$field] = $value->field_defs[$field];
293             }
294         }
295         $GLOBALS['log']->info('End: SoapHelperWebServices->filter_fields_for_query');
296         return $filterFields;
297     }
298
299     /**
300      * @see SugarWebServiceUtilv3::getRelationshipResults()
301      */
302     public function getRelationshipResults($bean, $link_field_name, $link_module_fields, $optional_where = '', $order_by = '') 
303     {
304                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->getRelationshipResults');
305                 require_once('include/TimeDate.php');
306                 global  $beanList, $beanFiles, $current_user;
307                 global $disable_date_format;
308
309                 $bean->load_relationship($link_field_name);
310                 if (isset($bean->$link_field_name)) {
311                         // get the query object for this link field
312                         $query_array = $bean->$link_field_name->getQuery(true,array(),0,'',true);
313                         if (isset($query_array['where'])) {
314                                 $query_array['where'] = str_ireplace("where", "", $query_array['where']);
315                                 if (!empty($optional_where)) {
316                                         $optional_where = $query_array['where'] . " and " . $optional_where;
317                                 } else {
318                                         $optional_where = $query_array['where'];
319                                 } // else
320                         } // if
321                         
322                         $params = array();
323                         $params['joined_tables'] = $query_array['join_tables'];
324
325                         // get the related module name and instantiate a bean for that.
326                         $submodulename = $bean->$link_field_name->getRelatedModuleName();
327                         $submoduleclass = $beanList[$submodulename];
328                         require_once($beanFiles[$submoduleclass]);
329                         $submodule = new $submoduleclass();
330                         $filterFields = $this->filter_fields($submodule, $link_module_fields);
331             $filterFieldsForQuery = $this->filter_fields_for_query($submodule, $filterFields);
332                         $relFields = $bean->$link_field_name->getRelatedFields();
333                         $roleSelect = '';
334
335                         $idSetInSubModule = false;
336                         if($submodulename == 'Users' && !in_array('id', $link_module_fields)){
337                                 $link_module_fields[] = 'id';
338                                 $idSetInSubModule = true;
339                         }
340
341                         if(!empty($relFields)){
342                                 foreach($link_module_fields as $field){
343                                         if(!empty($relFields[$field])){
344                                                 $roleSelect .= ', ' . $query_array['join_tables'][0] . '.'. $field;
345                                         }
346                                 }
347                         }
348                         // create a query
349                         $subquery = $submodule->create_new_list_query($order_by,$optional_where ,$filterFieldsForQuery,$params, 0,'', true,$bean);
350                         $query =  $subquery['select'].$roleSelect .   $subquery['from'].$query_array['join']. $subquery['where'].$subquery['order_by'];
351                         $GLOBALS['log']->info('SoapHelperWebServices->getRelationshipResults query = ' . $query);
352
353                         $result = $submodule->db->query($query, true);
354                         $list = array();
355                         while($row = $submodule->db->fetchByAssoc($result)) {
356                                 if (!$disable_date_format) {
357                                         foreach ($filterFields as $field) {
358                                                 if (isset($submodule->field_defs[$field]) &&
359                                                         isset($submodule->field_defs[$field]['type']) &&
360                                                         isset($row[$field])) {
361
362                                                                 if ($submodule->field_defs[$field]['type'] == 'date') {
363                                                                         global $timedate;
364                                                                         $row[$field] = $timedate->to_display_date_time($row[$field]);
365                                                                 }
366                                                                 if ($submodule->field_defs[$field]['type'] == 'currency') {
367                                                                         // TODO: convert data from db to user preferred format absed on the community input
368                                                                 } // if
369                                                 } // if
370
371                                         } // foreach
372                                 }
373                                 if($submodulename == 'Users' && $current_user->id != $row['id']) {
374                                         $row['user_hash'] = "";
375                                 } // if
376                                 if ($idSetInSubModule) {
377                                         unset($row['id']);
378                                 } // if
379                                 $list[] = $row;
380                         }
381                         $GLOBALS['log']->info('End: SoapHelperWebServices->getRelationshipResults');
382                         return array('rows' => $list, 'fields_set_on_rows' => $filterFields);
383                 } else {
384                         $GLOBALS['log']->info('End: SoapHelperWebServices->getRelationshipResults - ' . $link_field_name . ' relationship does not exists');
385                         return false;
386                 } // else
387
388         } // fn
389
390
391     function get_field_list($value,$fields,  $translate=true) {
392
393             $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_field_list');
394                 $module_fields = array();
395                 $link_fields = array();
396                 if(!empty($value->field_defs)){
397
398                         foreach($value->field_defs as $var){
399                                 if(!empty($fields) && !in_array( $var['name'], $fields))continue;
400                                 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;
401                                 if ((isset($var['source']) && $var['source'] == 'non_db') && (isset($var['type']) && $var['type'] != 'link')) {
402                                         continue;
403                                 }
404                                 $required = 0;
405                                 $options_dom = array();
406                                 $options_ret = array();
407                                 // Apparently the only purpose of this check is to make sure we only return fields
408                                 //   when we've read a record.  Otherwise this function is identical to get_module_field_list
409                                 if( isset($var['required']) && ($var['required'] || $var['required'] == 'true' ) ){
410                                         $required = 1;
411                                 }
412
413                                 if($var['type'] == 'bool')
414                                     $var['options'] = 'checkbox_dom';
415
416                                 if(isset($var['options'])){
417                                         $options_dom = translate($var['options'], $value->module_dir);
418                                         if(!is_array($options_dom)) $options_dom = array();
419                                         foreach($options_dom as $key=>$oneOption)
420                                                 $options_ret[$key] = $this->get_name_value($key,$oneOption);
421                                 }
422
423                     if(!empty($var['dbType']) && $var['type'] == 'bool') {
424                         $options_ret['type'] = $this->get_name_value('type', $var['dbType']);
425                     }
426
427                     $entry = array();
428                     $entry['name'] = $var['name'];
429                     $entry['type'] = $var['type'];
430                     $entry['group'] = isset($var['group']) ? $var['group'] : '';
431                     $entry['id_name'] = isset($var['id_name']) ? $var['id_name'] : '';
432
433                     if ($var['type'] == 'link') {
434                             $entry['relationship'] = (isset($var['relationship']) ? $var['relationship'] : '');
435                             $entry['module'] = (isset($var['module']) ? $var['module'] : '');
436                             $entry['bean_name'] = (isset($var['bean_name']) ? $var['bean_name'] : '');
437                                         $link_fields[$var['name']] = $entry;
438                     } else {
439                             if($translate) {
440                                 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
441                             } else {
442                                 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
443                             }
444                             $entry['required'] = $required;
445                             $entry['options'] = $options_ret;
446                             $entry['related_module'] = (isset($var['id_name']) && isset($var['module'])) ? $var['module'] : '';
447                             $entry['calculated'] =  (isset($var['calculated']) && $var['calculated']) ? true : false;
448                     $entry['len'] =  isset($var['len']) ? $var['len'] : '';
449
450                                         if(isset($var['default'])) {
451                                            $entry['default_value'] = $var['default'];
452                                         }
453                                         if( $var['type'] == 'parent' && isset($var['type_name']) )
454                                            $entry['type_name'] = $var['type_name'];
455
456                                         $module_fields[$var['name']] = $entry;
457                     } // else
458                         } //foreach
459                 } //if
460
461                 if($value->module_dir == 'Meetings' || $value->module_dir == 'Calls')
462                 {
463                     if( isset($module_fields['duration_minutes']) && isset($GLOBALS['app_list_strings']['duration_intervals']))
464                     {
465                         $options_dom = $GLOBALS['app_list_strings']['duration_intervals'];
466                         $options_ret = array();
467                         foreach($options_dom as $key=>$oneOption)
468                                                 $options_ret[$key] = $this->get_name_value($key,$oneOption);
469
470                         $module_fields['duration_minutes']['options'] = $options_ret;
471                     }
472                 }
473
474                 if($value->module_dir == 'Bugs'){
475                         require_once('modules/Releases/Release.php');
476                         $seedRelease = new Release();
477                         $options = $seedRelease->get_releases(TRUE, "Active");
478                         $options_ret = array();
479                         foreach($options as $name=>$value){
480                                 $options_ret[] =  array('name'=> $name , 'value'=>$value);
481                         }
482                         if(isset($module_fields['fixed_in_release'])){
483                                 $module_fields['fixed_in_release']['type'] = 'enum';
484                                 $module_fields['fixed_in_release']['options'] = $options_ret;
485                         }
486             if(isset($module_fields['found_in_release'])){
487                 $module_fields['found_in_release']['type'] = 'enum';
488                 $module_fields['found_in_release']['options'] = $options_ret;
489             }
490                         if(isset($module_fields['release'])){
491                                 $module_fields['release']['type'] = 'enum';
492                                 $module_fields['release']['options'] = $options_ret;
493                         }
494                         if(isset($module_fields['release_name'])){
495                                 $module_fields['release_name']['type'] = 'enum';
496                                 $module_fields['release_name']['options'] = $options_ret;
497                         }
498                 }
499
500                 if(isset($value->assigned_user_name) && isset($module_fields['assigned_user_id'])) {
501                         $module_fields['assigned_user_name'] = $module_fields['assigned_user_id'];
502                         $module_fields['assigned_user_name']['name'] = 'assigned_user_name';
503                 }
504                 if(isset($value->assigned_name) && isset($module_fields['team_id'])) {
505                         $module_fields['team_name'] = $module_fields['team_id'];
506                         $module_fields['team_name']['name'] = 'team_name';
507                 }
508                 if(isset($module_fields['modified_user_id'])) {
509                         $module_fields['modified_by_name'] = $module_fields['modified_user_id'];
510                         $module_fields['modified_by_name']['name'] = 'modified_by_name';
511                 }
512                 if(isset($module_fields['created_by'])) {
513                         $module_fields['created_by_name'] = $module_fields['created_by'];
514                         $module_fields['created_by_name']['name'] = 'created_by_name';
515                 }
516
517                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_field_list');
518                 return array('module_fields' => $module_fields, 'link_fields' => $link_fields);
519         }
520
521     
522         function new_handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) {
523                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->new_handle_set_entries');
524                 global $beanList, $beanFiles, $current_user, $app_list_strings;
525
526                 $ret_values = array();
527
528                 $class_name = $beanList[$module_name];
529                 require_once($beanFiles[$class_name]);
530                 $ids = array();
531                 $count = 1;
532                 $total = sizeof($name_value_lists);
533                 foreach($name_value_lists as $name_value_list){
534                         $seed = new $class_name();
535
536                         $seed->update_vcal = false;
537                         foreach($name_value_list as $name => $value){
538                                 if(is_array($value) &&  $value['name'] == 'id'){
539                     $seed->retrieve($value['value']);
540                     break;
541                 }
542                 else if($name === 'id' ){
543                     $seed->retrieve($value);
544                 }
545                         }
546
547                         foreach($name_value_list as $name => $value) {
548                             //Normalize the input
549                                 if(!is_array($value)){
550                     $field_name = $name;
551                     $val = $value;
552                 }
553                 else{
554                     $field_name = $value['name'];
555                     $val = $value['value'];
556                 }
557                                 
558                                 if($seed->field_name_map[$field_name]['type'] == 'enum'){
559                                         $vardef = $seed->field_name_map[$field_name];
560                                         if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$val]) ) {
561                                                 if ( in_array($val,$app_list_strings[$vardef['options']]) ){
562                                                         $val = array_search($val,$app_list_strings[$vardef['options']]);
563                                                 }
564                                         }
565                                 }
566                                 if($module_name == 'Users' && !empty($seed->id) && ($seed->id != $current_user->id) && $field_name == 'user_hash'){
567                                         continue;
568                                 }
569
570                                 $seed->$field_name = $val;
571                         }
572
573                         if($count == $total){
574                                 $seed->update_vcal = false;
575                         }
576                         $count++;
577
578                         //Add the account to a contact
579                         if($module_name == 'Contacts'){
580                                 $GLOBALS['log']->debug('Creating Contact Account');
581                                 $this->add_create_account($seed);
582                                 $duplicate_id = $this->check_for_duplicate_contacts($seed);
583                                 if($duplicate_id == null){
584                                         if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
585                                                 $seed->save();
586                                                 if($seed->deleted == 1){
587                                                         $seed->mark_deleted($seed->id);
588                                                 }
589                                                 $ids[] = $seed->id;
590                                         }
591                                 }
592                                 else{
593                                         //since we found a duplicate we should set the sync flag
594                                         if( $seed->ACLAccess('Save')){
595                                                 $seed = new $class_name();
596                                                 $seed->id = $duplicate_id;
597                                                 $seed->contacts_users_id = $current_user->id;
598                                                 $seed->save();
599                                                 $ids[] = $duplicate_id;//we have a conflict
600                                         }
601                                 }
602                         }
603                         else if($module_name == 'Meetings' || $module_name == 'Calls'){
604                                 //we are going to check if we have a meeting in the system
605                                 //with the same outlook_id. If we do find one then we will grab that
606                                 //id and save it
607                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
608                                         if(empty($seed->id) && !isset($seed->id)){
609                                                 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){
610                                                         //at this point we have an object that does not have
611                                                         //the id set, but does have the outlook_id set
612                                                         //so we need to query the db to find if we already
613                                                         //have an object with this outlook_id, if we do
614                                                         //then we can set the id, otherwise this is a new object
615                                                         $order_by = "";
616                                                         $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'";
617                                                         $response = $seed->get_list($order_by, $query, 0,-1,-1,0);
618                                                         $list = $response['list'];
619                                                         if(count($list) > 0){
620                                                                 foreach($list as $value)
621                                                                 {
622                                                                         $seed->id = $value->id;
623                                                                         break;
624                                                                 }
625                                                         }//fi
626                                                 }//fi
627                                         }//fi
628                                     if (empty($seed->reminder_time)) {
629                         $seed->reminder_time = -1;
630                     }
631                     if($seed->reminder_time == -1){
632                         $defaultRemindrTime = $current_user->getPreference('reminder_time');
633                         if ($defaultRemindrTime != -1){
634                             $seed->reminder_checked = '1';
635                             $seed->reminder_time = $defaultRemindrTime;
636                         }
637                     }
638                                         $seed->save();
639                                         $ids[] = $seed->id;
640                                 }//fi
641                         }
642                         else
643                         {
644                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
645                                         $seed->save();
646                                         $ids[] = $seed->id;
647                                 }
648                         }
649
650                         // if somebody is calling set_entries_detail() and wants fields returned...
651                         if ($select_fields !== FALSE) {
652                                 $ret_values[$count] = array();
653
654                                 foreach ($select_fields as $select_field) {
655                                         if (isset($seed->$select_field)) {
656                                                 $ret_values[$count][$select_field] = $this->get_name_value($select_field, $seed->$select_field);
657                                         }
658                                 }
659                         }
660                 }
661
662                 // handle returns for set_entries_detail() and set_entries()
663                 if ($select_fields !== FALSE) {
664                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
665                         return array(
666                                 'name_value_lists' => $ret_values,
667                         );
668                 }
669                 else {
670                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
671                         return array(
672                                 'ids' => $ids,
673                         );
674                 }
675         }
676         
677 }