make basic data of current user available via egw.user(_field)

This commit is contained in:
Ralf Becker 2011-08-31 12:17:34 +00:00
parent 54bf7a3d2d
commit 046c0919cc
6 changed files with 62 additions and 5 deletions

View File

@ -381,6 +381,27 @@ class accounts
return $data; 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 * Saves / adds the data of one account
* *

View File

@ -476,7 +476,7 @@ class accounts_ldap
protected function _read_user($account_id) protected function _read_user($account_id)
{ {
$sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=posixAccount)(uidnumber=' . (int)$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')); 'shadowexpire','shadowlastchange','homedirectory','loginshell','createtimestamp','modifytimestamp'));
$data = ldap_get_entries($this->ds, $sri); $data = ldap_get_entries($this->ds, $sri);
@ -498,6 +498,7 @@ class accounts_ldap
'account_email' => $data['mail'][0], 'account_email' => $data['mail'][0],
'account_fullname' => $data['cn'][0], 'account_fullname' => $data['cn'][0],
'account_pwd' => $data['userpassword'][0], 'account_pwd' => $data['userpassword'][0],
'account_phone' => $data['telephonenumber'][0],
// both status and expires are encoded in the single shadowexpire value in LDAP // 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 unset an account is enabled AND does never expire
// - if it's set to 0, the account is disabled // - if it's set to 0, the account is disabled

View File

@ -114,8 +114,9 @@ class accounts_sql
$this->contacts_table.'.n_fn AS account_fullname,'. $this->contacts_table.'.n_fn AS account_fullname,'.
$this->contacts_table.'.contact_id AS person_id,'. $this->contacts_table.'.contact_id AS person_id,'.
$this->contacts_table.'.contact_created AS account_created,'. $this->contacts_table.'.contact_created AS account_created,'.
$this->contacts_table.'.contact_modified AS account_modified,'; $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.'.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), 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())) __LINE__,__FILE__,false,'',false,0,$join)->fetch()))

View File

@ -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!) // 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']) 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 .= "</script>\n"; $java_script .= "</script>\n";

View File

@ -312,6 +312,8 @@ else
/** /**
* Map to serverside available images for users template-set * Map to serverside available images for users template-set
*
* @access: private, use egw.image(_name, _app)
*/ */
images: {}, images: {},
@ -373,6 +375,36 @@ else
{ {
return egw_appName; 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];
} }
}; };
} }

View File

@ -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'])); self::validate_file('/phpgwapi/images.php',array('template' => $GLOBALS['egw_info']['user']['preferences']['common']['template_set']));
$content .= '<script type="text/javascript"> $content .= '<script type="text/javascript">
egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common"); egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['common']).', "common");
egw.set_user('.$GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['account_id']).');
</script>'."\n"; </script>'."\n";
} }
if($GLOBALS['egw_info']['user']['preferences']['common']['show_general_menu'] != 'sidebox' && !html::$ua_mobile) if($GLOBALS['egw_info']['user']['preferences']['common']['show_general_menu'] != 'sidebox' && !html::$ua_mobile)