From 046c0919ccecd3429cda82282322c2e8fc6eba76 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 31 Aug 2011 12:17:34 +0000 Subject: [PATCH] make basic data of current user available via egw.user(_field) --- phpgwapi/inc/class.accounts.inc.php | 21 ++++++++++++ phpgwapi/inc/class.accounts_ldap.inc.php | 3 +- phpgwapi/inc/class.accounts_sql.inc.php | 7 ++-- phpgwapi/inc/class.egw_framework.inc.php | 3 +- phpgwapi/js/jsapi/egw.js | 32 +++++++++++++++++++ .../idots/class.idots_framework.inc.php | 1 + 6 files changed, 62 insertions(+), 5 deletions(-) diff --git a/phpgwapi/inc/class.accounts.inc.php b/phpgwapi/inc/class.accounts.inc.php index 8390c5c7b2..77183162c8 100644 --- a/phpgwapi/inc/class.accounts.inc.php +++ b/phpgwapi/inc/class.accounts.inc.php @@ -381,6 +381,27 @@ class accounts return $data; } + /** + * Get an account as json, returns only whitelisted fields: + * - 'account_id','account_lid','person_id','account_status', + * - 'account_firstname','account_lastname','account_email','account_fullname','account_phone' + * + * @param int|string $id + * @return string|boolean json or false if not found + */ + function json($id) + { + static $keys = array( + 'account_id','account_lid','person_id','account_status', + 'account_firstname','account_lastname','account_email','account_fullname','account_phone', + ); + if (($account = $this->read($id))) + { + $account = array_intersect_key($account, array_flip($keys)); + } + return json_encode($account); + } + /** * Saves / adds the data of one account * diff --git a/phpgwapi/inc/class.accounts_ldap.inc.php b/phpgwapi/inc/class.accounts_ldap.inc.php index 4b1e6df0bd..674b19e49f 100644 --- a/phpgwapi/inc/class.accounts_ldap.inc.php +++ b/phpgwapi/inc/class.accounts_ldap.inc.php @@ -476,7 +476,7 @@ class accounts_ldap protected function _read_user($account_id) { $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber=' . (int)$account_id.'))', - array('dn','uidnumber','uid','gidnumber','givenname','sn','cn','mail','userpassword', + array('dn','uidnumber','uid','gidnumber','givenname','sn','cn','mail','userpassword','telephonenumber', 'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp')); $data = ldap_get_entries($this->ds, $sri); @@ -498,6 +498,7 @@ class accounts_ldap 'account_email' => $data['mail'][0], 'account_fullname' => $data['cn'][0], 'account_pwd' => $data['userpassword'][0], + 'account_phone' => $data['telephonenumber'][0], // both status and expires are encoded in the single shadowexpire value in LDAP // - if it's unset an account is enabled AND does never expire // - if it's set to 0, the account is disabled diff --git a/phpgwapi/inc/class.accounts_sql.inc.php b/phpgwapi/inc/class.accounts_sql.inc.php index d1abb98555..77133b1953 100644 --- a/phpgwapi/inc/class.accounts_sql.inc.php +++ b/phpgwapi/inc/class.accounts_sql.inc.php @@ -114,8 +114,9 @@ class accounts_sql $this->contacts_table.'.n_fn AS account_fullname,'. $this->contacts_table.'.contact_id AS person_id,'. $this->contacts_table.'.contact_created AS account_created,'. - $this->contacts_table.'.contact_modified AS account_modified,'; - $join = 'LEFT JOIN '.$this->contacts_table.' ON '.$this->table.'.account_id='.$this->contacts_table.'.account_id'; + $this->contacts_table.'.contact_modified AS account_modified,'. + $this->contacts_table.'.tel_work AS account_phone,'; + $join = 'LEFT JOIN '.$this->contacts_table.' ON '.$this->table.'.account_id='.$this->contacts_table.'.account_id'; } if (!($data = $this->db->select($this->table,$extra_cols.$this->table.'.*',$this->table.'.account_id='.abs($account_id), __LINE__,__FILE__,false,'',false,0,$join)->fetch())) @@ -176,7 +177,7 @@ class accounts_sql if (!isset($to_write['account_pwd'])) $to_write['account_pwd'] = ''; // is NOT NULL! if (!isset($to_write['account_status'])) $to_write['account_status'] = ''; // is NOT NULL! - // postgres requires the auto-id field to be unset! + // postgres requires the auto-id field to be unset! if (isset($to_write['account_id']) && !$to_write['account_id']) unset($to_write['account_id']); if (!in_array($to_write['account_type'],array('u','g')) || diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 21acd93eaf..0708693c4a 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -781,7 +781,8 @@ abstract class egw_framework // add link registry to non-popup windows, if explicit requested (idots_framework::navbar() loads it, if not explicit specified!) if ($GLOBALS['egw_info']['flags']['js_link_registry']) { - $java_script .= 'egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");'; + $java_script .= 'egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");'."\n"; + $java_script .= 'egw.set_user('.$GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['account_id']).');'."\n"; } $java_script .= "\n"; diff --git a/phpgwapi/js/jsapi/egw.js b/phpgwapi/js/jsapi/egw.js index 486ccbb651..09d36d9a20 100644 --- a/phpgwapi/js/jsapi/egw.js +++ b/phpgwapi/js/jsapi/egw.js @@ -312,6 +312,8 @@ else /** * Map to serverside available images for users template-set + * + * @access: private, use egw.image(_name, _app) */ images: {}, @@ -373,6 +375,36 @@ else { return egw_appName; } + }, + + /** + * Data about current user + * + * @access: private, use egw.user(_field) + */ + userData: {}, + + /** + * Set data of current user + * + * @param object _data + */ + set_user: function(_data) + { + this.userData = _data; + }, + + /** + * Get data about current user + * + * @param string _field + * - 'account_id','account_lid','person_id','account_status', + * - 'account_firstname','account_lastname','account_email','account_fullname','account_phone' + * @return string|null + */ + user: function (_field) + { + return this.userData[_field]; } }; } diff --git a/phpgwapi/templates/idots/class.idots_framework.inc.php b/phpgwapi/templates/idots/class.idots_framework.inc.php index d730fe0571..7fe8196733 100644 --- a/phpgwapi/templates/idots/class.idots_framework.inc.php +++ b/phpgwapi/templates/idots/class.idots_framework.inc.php @@ -166,6 +166,7 @@ class idots_framework extends egw_framework self::validate_file('/phpgwapi/images.php',array('template' => $GLOBALS['egw_info']['user']['preferences']['common']['template_set'])); $content .= ''."\n"; } if($GLOBALS['egw_info']['user']['preferences']['common']['show_general_menu'] != 'sidebox' && !html::$ua_mobile)