Skip to content
Snippets Groups Projects
Commit 352db45d authored by Peter Rotich's avatar Peter Rotich
Browse files

Agents' Preferences

Support using global config table to store agent's preference.
parent 91b87a01
No related branches found
No related tags found
No related merge requests found
...@@ -29,13 +29,16 @@ class Config { ...@@ -29,13 +29,16 @@ class Config {
# new settings and the corresponding default values. # new settings and the corresponding default values.
var $defaults = array(); # List of default values var $defaults = array(); # List of default values
function Config($section=null) { function Config($section=null, $defaults=array()) {
if ($section) if ($section)
$this->section = $section; $this->section = $section;
if ($this->section === null) if ($this->section === null)
return false; return false;
if ($defaults)
$this->defaults = $defaults;
if (isset($_SESSION['cfg:'.$this->section])) if (isset($_SESSION['cfg:'.$this->section]))
$this->session = &$_SESSION['cfg:'.$this->section]; $this->session = &$_SESSION['cfg:'.$this->section];
$this->load(); $this->load();
......
...@@ -51,6 +51,7 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { ...@@ -51,6 +51,7 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
var $passwd_change; var $passwd_change;
var $_roles = null; var $_roles = null;
var $_teams = null; var $_teams = null;
var $_config = null;
var $_perm; var $_perm;
function __onload() { function __onload() {
...@@ -66,6 +67,33 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { ...@@ -66,6 +67,33 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
$this->passwd_change = time()-$time; //XXX: check timezone issues. $this->passwd_change = time()-$time; //XXX: check timezone issues.
} }
function get($field, $default=false) {
// Autoload config if not loaded already
if (!isset($this->_config))
$this->getConfig();
if (isset($this->_config[$field]))
return $this->_config[$field];
return parent::get($field, $default);
}
function getConfig() {
if (!isset($this->_config) && $this->getId()) {
$_config = new Config('staff.'.$this->getId(),
// Defaults
array(
'default_from_name' => '',
'datetime_format' => '',
));
$this->_config = $_config->getInfo();
}
return $this->_config;
}
function __toString() { function __toString() {
return (string) $this->getName(); return (string) $this->getName();
} }
...@@ -102,6 +130,10 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { ...@@ -102,6 +130,10 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
$base = $this->ht; $base = $this->ht;
unset($base['teams']); unset($base['teams']);
unset($base['dept_access']); unset($base['dept_access']);
if ($this->getConfig())
$base += $this->getConfig();
return $base; return $base;
} }
...@@ -625,10 +657,9 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { ...@@ -625,10 +657,9 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
$this->max_page_size = $vars['max_page_size']; $this->max_page_size = $vars['max_page_size'];
$this->auto_refresh_rate = $vars['auto_refresh_rate']; $this->auto_refresh_rate = $vars['auto_refresh_rate'];
$this->default_signature_type = $vars['default_signature_type']; $this->default_signature_type = $vars['default_signature_type'];
$this->default_from_name = $vars['default_from_name'];
$this->default_paper_size = $vars['default_paper_size']; $this->default_paper_size = $vars['default_paper_size'];
$this->lang = $vars['lang']; $this->lang = $vars['lang'];
$this->onvacation = isset($vars['onvacation'])?1:0; $this->onvacation = isset($vars['onvacation']) ? 1 : 0;
if (isset($vars['avatar_code'])) if (isset($vars['avatar_code']))
$this->setExtraAttr('avatar', $vars['avatar_code']); $this->setExtraAttr('avatar', $vars['avatar_code']);
...@@ -639,6 +670,15 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { ...@@ -639,6 +670,15 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
$_SESSION['::lang'] = null; $_SESSION['::lang'] = null;
TextDomain::configureForUser($this); TextDomain::configureForUser($this);
// Update the config information
$_config = new Config('staff.'.$this->getId());
$_config->updateAll(array(
'datetime_format' => $vars['datetime_format'],
'default_from_name' => $vars['default_from_name'],
)
);
$this->_config = $_config->getInfo();
return $this->save(); return $this->save();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment