]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/v4/SugarWebServiceUtilv4.php
Release 6.3.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     function get_field_list($value,$fields,  $translate=true) {
300
301             $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_field_list');
302                 $module_fields = array();
303                 $link_fields = array();
304                 if(!empty($value->field_defs)){
305
306                         foreach($value->field_defs as $var){
307                                 if(!empty($fields) && !in_array( $var['name'], $fields))continue;
308                                 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;
309                                 if ((isset($var['source']) && $var['source'] == 'non_db') && (isset($var['type']) && $var['type'] != 'link')) {
310                                         continue;
311                                 }
312                                 $required = 0;
313                                 $options_dom = array();
314                                 $options_ret = array();
315                                 // Apparently the only purpose of this check is to make sure we only return fields
316                                 //   when we've read a record.  Otherwise this function is identical to get_module_field_list
317                                 if( isset($var['required']) && ($var['required'] || $var['required'] == 'true' ) ){
318                                         $required = 1;
319                                 }
320
321                                 if($var['type'] == 'bool')
322                                     $var['options'] = 'checkbox_dom';
323
324                                 if(isset($var['options'])){
325                                         $options_dom = translate($var['options'], $value->module_dir);
326                                         if(!is_array($options_dom)) $options_dom = array();
327                                         foreach($options_dom as $key=>$oneOption)
328                                                 $options_ret[$key] = $this->get_name_value($key,$oneOption);
329                                 }
330
331                     if(!empty($var['dbType']) && $var['type'] == 'bool') {
332                         $options_ret['type'] = $this->get_name_value('type', $var['dbType']);
333                     }
334
335                     $entry = array();
336                     $entry['name'] = $var['name'];
337                     $entry['type'] = $var['type'];
338                     $entry['group'] = isset($var['group']) ? $var['group'] : '';
339                     $entry['id_name'] = isset($var['id_name']) ? $var['id_name'] : '';
340
341                     if ($var['type'] == 'link') {
342                             $entry['relationship'] = (isset($var['relationship']) ? $var['relationship'] : '');
343                             $entry['module'] = (isset($var['module']) ? $var['module'] : '');
344                             $entry['bean_name'] = (isset($var['bean_name']) ? $var['bean_name'] : '');
345                                         $link_fields[$var['name']] = $entry;
346                     } else {
347                             if($translate) {
348                                 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
349                             } else {
350                                 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
351                             }
352                             $entry['required'] = $required;
353                             $entry['options'] = $options_ret;
354                             $entry['related_module'] = (isset($var['id_name']) && isset($var['module'])) ? $var['module'] : '';
355                             $entry['calculated'] =  (isset($var['calculated']) && $var['calculated']) ? true : false;
356                     $entry['len'] =  isset($var['len']) ? $var['len'] : '';
357
358                                         if(isset($var['default'])) {
359                                            $entry['default_value'] = $var['default'];
360                                         }
361                                         if( $var['type'] == 'parent' && isset($var['type_name']) )
362                                            $entry['type_name'] = $var['type_name'];
363
364                                         $module_fields[$var['name']] = $entry;
365                     } // else
366                         } //foreach
367                 } //if
368
369                 if($value->module_dir == 'Meetings' || $value->module_dir == 'Calls')
370                 {
371                     if( isset($module_fields['duration_minutes']) && isset($GLOBALS['app_list_strings']['duration_intervals']))
372                     {
373                         $options_dom = $GLOBALS['app_list_strings']['duration_intervals'];
374                         $options_ret = array();
375                         foreach($options_dom as $key=>$oneOption)
376                                                 $options_ret[$key] = $this->get_name_value($key,$oneOption);
377
378                         $module_fields['duration_minutes']['options'] = $options_ret;
379                     }
380                 }
381
382                 if($value->module_dir == 'Bugs'){
383                         require_once('modules/Releases/Release.php');
384                         $seedRelease = new Release();
385                         $options = $seedRelease->get_releases(TRUE, "Active");
386                         $options_ret = array();
387                         foreach($options as $name=>$value){
388                                 $options_ret[] =  array('name'=> $name , 'value'=>$value);
389                         }
390                         if(isset($module_fields['fixed_in_release'])){
391                                 $module_fields['fixed_in_release']['type'] = 'enum';
392                                 $module_fields['fixed_in_release']['options'] = $options_ret;
393                         }
394             if(isset($module_fields['found_in_release'])){
395                 $module_fields['found_in_release']['type'] = 'enum';
396                 $module_fields['found_in_release']['options'] = $options_ret;
397             }
398                         if(isset($module_fields['release'])){
399                                 $module_fields['release']['type'] = 'enum';
400                                 $module_fields['release']['options'] = $options_ret;
401                         }
402                         if(isset($module_fields['release_name'])){
403                                 $module_fields['release_name']['type'] = 'enum';
404                                 $module_fields['release_name']['options'] = $options_ret;
405                         }
406                 }
407
408                 if(isset($value->assigned_user_name) && isset($module_fields['assigned_user_id'])) {
409                         $module_fields['assigned_user_name'] = $module_fields['assigned_user_id'];
410                         $module_fields['assigned_user_name']['name'] = 'assigned_user_name';
411                 }
412                 if(isset($value->assigned_name) && isset($module_fields['team_id'])) {
413                         $module_fields['team_name'] = $module_fields['team_id'];
414                         $module_fields['team_name']['name'] = 'team_name';
415                 }
416                 if(isset($module_fields['modified_user_id'])) {
417                         $module_fields['modified_by_name'] = $module_fields['modified_user_id'];
418                         $module_fields['modified_by_name']['name'] = 'modified_by_name';
419                 }
420                 if(isset($module_fields['created_by'])) {
421                         $module_fields['created_by_name'] = $module_fields['created_by'];
422                         $module_fields['created_by_name']['name'] = 'created_by_name';
423                 }
424
425                 $GLOBALS['log']->info('End: SoapHelperWebServices->get_field_list');
426                 return array('module_fields' => $module_fields, 'link_fields' => $link_fields);
427         }
428
429
430         function new_handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) {
431                 $GLOBALS['log']->info('Begin: SoapHelperWebServices->new_handle_set_entries');
432                 global $beanList, $beanFiles, $current_user, $app_list_strings;
433
434                 $ret_values = array();
435
436                 $class_name = $beanList[$module_name];
437                 require_once($beanFiles[$class_name]);
438                 $ids = array();
439                 $count = 1;
440                 $total = sizeof($name_value_lists);
441                 foreach($name_value_lists as $name_value_list){
442                         $seed = new $class_name();
443
444                         $seed->update_vcal = false;
445                         foreach($name_value_list as $name => $value){
446                                 if(is_array($value) &&  $value['name'] == 'id'){
447                     $seed->retrieve($value['value']);
448                     break;
449                 }
450                 else if($name === 'id' ){
451                     $seed->retrieve($value);
452                 }
453                         }
454
455                         foreach($name_value_list as $name => $value) {
456                             //Normalize the input
457                                 if(!is_array($value)){
458                     $field_name = $name;
459                     $val = $value;
460                 }
461                 else{
462                     $field_name = $value['name'];
463                     $val = $value['value'];
464                 }
465
466                                 if($seed->field_name_map[$field_name]['type'] == 'enum'){
467                                         $vardef = $seed->field_name_map[$field_name];
468                                         if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$val]) ) {
469                                                 if ( in_array($val,$app_list_strings[$vardef['options']]) ){
470                                                         $val = array_search($val,$app_list_strings[$vardef['options']]);
471                                                 }
472                                         }
473                                 }
474                                 if($module_name == 'Users' && !empty($seed->id) && ($seed->id != $current_user->id) && $field_name == 'user_hash'){
475                                         continue;
476                                 }
477
478                                 $seed->$field_name = $val;
479                         }
480
481                         if($count == $total){
482                                 $seed->update_vcal = false;
483                         }
484                         $count++;
485
486                         //Add the account to a contact
487                         if($module_name == 'Contacts'){
488                                 $GLOBALS['log']->debug('Creating Contact Account');
489                                 $this->add_create_account($seed);
490                                 $duplicate_id = $this->check_for_duplicate_contacts($seed);
491                                 if($duplicate_id == null){
492                                         if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
493                                                 $seed->save();
494                                                 if($seed->deleted == 1){
495                                                         $seed->mark_deleted($seed->id);
496                                                 }
497                                                 $ids[] = $seed->id;
498                                         }
499                                 }
500                                 else{
501                                         //since we found a duplicate we should set the sync flag
502                                         if( $seed->ACLAccess('Save')){
503                                                 $seed = new $class_name();
504                                                 $seed->id = $duplicate_id;
505                                                 $seed->contacts_users_id = $current_user->id;
506                                                 $seed->save();
507                                                 $ids[] = $duplicate_id;//we have a conflict
508                                         }
509                                 }
510                         }
511                         else if($module_name == 'Meetings' || $module_name == 'Calls'){
512                                 //we are going to check if we have a meeting in the system
513                                 //with the same outlook_id. If we do find one then we will grab that
514                                 //id and save it
515                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
516                                         if(empty($seed->id) && !isset($seed->id)){
517                                                 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){
518                                                         //at this point we have an object that does not have
519                                                         //the id set, but does have the outlook_id set
520                                                         //so we need to query the db to find if we already
521                                                         //have an object with this outlook_id, if we do
522                                                         //then we can set the id, otherwise this is a new object
523                                                         $order_by = "";
524                                                         $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'";
525                                                         $response = $seed->get_list($order_by, $query, 0,-1,-1,0);
526                                                         $list = $response['list'];
527                                                         if(count($list) > 0){
528                                                                 foreach($list as $value)
529                                                                 {
530                                                                         $seed->id = $value->id;
531                                                                         break;
532                                                                 }
533                                                         }//fi
534                                                 }//fi
535                                         }//fi
536                                     if (empty($seed->reminder_time)) {
537                         $seed->reminder_time = -1;
538                     }
539                     if($seed->reminder_time == -1){
540                         $defaultRemindrTime = $current_user->getPreference('reminder_time');
541                         if ($defaultRemindrTime != -1){
542                             $seed->reminder_checked = '1';
543                             $seed->reminder_time = $defaultRemindrTime;
544                         }
545                     }
546                                         $seed->save();
547                                         $ids[] = $seed->id;
548                                 }//fi
549                         }
550                         else
551                         {
552                                 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
553                                         $seed->save();
554                                         $ids[] = $seed->id;
555                                 }
556                         }
557
558                         // if somebody is calling set_entries_detail() and wants fields returned...
559                         if ($select_fields !== FALSE) {
560                                 $ret_values[$count] = array();
561
562                                 foreach ($select_fields as $select_field) {
563                                         if (isset($seed->$select_field)) {
564                                                 $ret_values[$count][$select_field] = $this->get_name_value($select_field, $seed->$select_field);
565                                         }
566                                 }
567                         }
568                 }
569
570                 // handle returns for set_entries_detail() and set_entries()
571                 if ($select_fields !== FALSE) {
572                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
573                         return array(
574                                 'name_value_lists' => $ret_values,
575                         );
576                 }
577                 else {
578                         $GLOBALS['log']->info('End: SoapHelperWebServices->new_handle_set_entries');
579                         return array(
580                                 'ids' => $ids,
581                         );
582                 }
583         }
584
585
586     function checkSessionAndModuleAccess($session, $login_error_key, $module_name, $access_level, $module_access_level_error_key, $errorObject)
587     {
588           if(isset($_REQUEST['oauth_token'])) {
589               $session = $this->checkOAuthAccess($errorObject);
590           }
591           if(!$session) return false;
592           return parent::checkSessionAndModuleAccess($session, $login_error_key, $module_name, $access_level, $module_access_level_error_key, $errorObject);
593     }
594
595     public function checkOAuthAccess($errorObject)
596     {
597         require_once "include/SugarOAuthServer.php";
598         try {
599                 $oauth = new SugarOAuthServer();
600                 $token = $oauth->authorizedToken();
601                 if(empty($token) || empty($token->assigned_user_id)) {
602                     return false;
603                 }
604         } catch(OAuthException $e) {
605             $GLOBALS['log']->debug("OAUTH Exception: $e");
606             $errorObject->set_error('invalid_login');
607                         $this->setFaultObject($errorObject);
608             return false;
609         }
610
611             $user = new User();
612             $user->retrieve($token->assigned_user_id);
613             if(empty($user->id)) {
614                 return false;
615             }
616         global $current_user;
617                 $current_user = $user;
618                 ini_set("session.use_cookies", 0); // disable cookies to prevent session ID from going out
619                 session_start();
620                 session_regenerate_id();
621                 $_SESSION['oauth'] = $oauth->authorization();
622                 $_SESSION['avail_modules'] = $this->get_user_module_list($user);
623                 // TODO: handle role
624                 // handle session
625                 $_SESSION['is_valid_session']= true;
626                 $_SESSION['ip_address'] = query_client_ip();
627                 $_SESSION['user_id'] = $current_user->id;
628                 $_SESSION['type'] = 'user';
629                 $_SESSION['authenticated_user_id'] = $current_user->id;
630         return session_id();
631     }
632 }