Newer
Older
<?php
/*********************************************************************
class.config.php
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
Peter Rotich
committed
var $config = array();
var $section = null; # Default namespace ('core')
var $table = CONFIG_TABLE; # Table name (with prefix)
var $section_column = 'namespace'; # namespace column name
var $session = null; # Session-backed configuration
# Defaults for this configuration. If settings don't exist in the
# database yet, the ->getInfo() method will not include the (default)
# values in the returned array. $defaults allows developers to define
# new settings and the corresponding default values.
var $defaults = array(); # List of default values
function __construct($section=null, $defaults=array()) {
$this->section = $section;
if ($this->section === null)
if (isset($_SESSION['cfg:'.$this->section]))
$this->session = &$_SESSION['cfg:'.$this->section];
foreach ($this->items() as $I)
$this->config[$I->key] = $I;
function getNamespace() {
return $this->section;
}
foreach ($this->config as $key=>$item)
$info[$key] = $item->value;
function get($key, $default=null) {
if (isset($this->session) && isset($this->session[$key]))
elseif (isset($this->config[$key]))
elseif (isset($this->defaults[$key]))
return $this->defaults[$key];
function exists($key) {
return $this->get($key, null) ? true : false;
}
function set($key, $value) {
return ($this->update($key, $value)) ? $value : null;
if (!isset($this->session)) {
$this->session = &$_SESSION['cfg:'.$this->section];
$this->session = array();
}
$this->session[$key] = $value;
return true;
}
function lastModified($key) {
if (isset($this->config[$key]))
return $this->config[$key]->updated;
return false;
function create($key, $value) {
$this->section_column => $this->section,
'key' => $key,
'value' => $value,
]);
if (!$item->save())
return true;
}
function update($key, $value) {
if (!$key)
return false;
elseif (!isset($this->config[$key]))
return $this->create($key, $value);
$item = $this->config[$key];
$item->value = $value;
return $item->save();
function updateAll($updates) {
if (!$this->update($key, $value))
unset($this->session);
return $this->items()->delete();
}
if (!isset($items))
$items = ConfigItem::items($this->section, $this->section_column);
return $items;
}
}
class ConfigItem
extends VerySimpleModel {
static $meta = array(
'table' => CONFIG_TABLE,
'pk' => array('id'),
);
static function items($namespace, $column='namespace') {
try {
count($items);
}
catch (InconsistentModelException $ex) {
// Pending upgrade ??
$items = array();
}
return $items;
}
function save($refetch=false) {
if ($this->dirty)
$this->updated = SqlFunction::NOW();
return parent::save($this->dirty || $refetch);
}
class OsticketConfig extends Config {
var $table = CONFIG_TABLE;
var $section = 'core';
var $defaultDept; //Default Department
var $defaultSLA; //Default SLA
var $defaultEmail; //Default Email
var $alertEmail; //Alert Email
var $defaultSMTPEmail; //Default SMTP Email
var $defaults = array(
'allow_pw_reset' => true,
'enable_richtext' => true,
'agent_name_format' => 'full', # First Last
'client_name_format' => 'original', # As entered
'auto_claim_tickets'=> true,
'message_autoresponder_collabs' => true,
'add_email_collabs' => true,
'clients_only' => false,
'client_registration' => 'closed',
'accept_unregistered_email' => true,
Loading
Loading full blame...