diff --git a/include/class.config.php b/include/class.config.php index dc5bb7511f0dd13bcb42df9d6661f55dec007ad9..8993ff264bed9decf7adb3768e30b787a934679d 100644 --- a/include/class.config.php +++ b/include/class.config.php @@ -29,13 +29,16 @@ class Config { # new settings and the corresponding default values. var $defaults = array(); # List of default values - function Config($section=null) { + function Config($section=null, $defaults=array()) { if ($section) $this->section = $section; if ($this->section === null) return false; + if ($defaults) + $this->defaults = $defaults; + if (isset($_SESSION['cfg:'.$this->section])) $this->session = &$_SESSION['cfg:'.$this->section]; $this->load(); diff --git a/include/class.staff.php b/include/class.staff.php index 84fed044440be2f4dcb7d27e533c2ffdcfa210c9..8eb4aab3996fb43e95798f8c5de09d8a09489a21 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -51,6 +51,7 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { var $passwd_change; var $_roles = null; var $_teams = null; + var $_config = null; var $_perm; function __onload() { @@ -66,6 +67,33 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { $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() { return (string) $this->getName(); } @@ -102,6 +130,10 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { $base = $this->ht; unset($base['teams']); unset($base['dept_access']); + + if ($this->getConfig()) + $base += $this->getConfig(); + return $base; } @@ -625,10 +657,9 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { $this->max_page_size = $vars['max_page_size']; $this->auto_refresh_rate = $vars['auto_refresh_rate']; $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->lang = $vars['lang']; - $this->onvacation = isset($vars['onvacation'])?1:0; + $this->onvacation = isset($vars['onvacation']) ? 1 : 0; if (isset($vars['avatar_code'])) $this->setExtraAttr('avatar', $vars['avatar_code']); @@ -639,6 +670,15 @@ implements AuthenticatedUser, EmailContact, TemplateVariable { $_SESSION['::lang'] = null; 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(); }