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:
**********************************************************************/
class Config {
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
$this->section = $section;
if ($this->section === null)
if (!isset($_SESSION['cfg:'.$this->section]))
$_SESSION['cfg:'.$this->section] = array();
$this->session = &$_SESSION['cfg:'.$this->section];
$sql='SELECT id, `key`, value, `updated` FROM '.$this->table
.' WHERE `'.$this->section_column.'` = '.db_input($this->section);
if(($res=db_query($sql)) && db_num_rows($res))
while ($row = db_fetch_array($res))
$this->config[$row['key']] = $row;
function getNamespace() {
return $this->section;
}
foreach ($this->config as $key=>$setting)
$info[$key] = $setting['value'];
return $info;
}
function get($key, $default=null) {
if (isset($this->session[$key]))
elseif (isset($this->config[$key]))
return $this->config[$key]['value'];
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;
function persist($key, $value) {
$this->session[$key] = $value;
return true;
}
function lastModified($key) {
if (isset($this->config[$key]))
return $this->config[$key]['updated'];
else
return false;
}
function create($key, $value) {
.' SET `'.$this->section_column.'`='.db_input($this->section)
.', `key`='.db_input($key)
.', value='.db_input($value);
if (!db_query($sql) || !($id=db_insert_id()))
$this->config[$key] = array('key'=>$key, 'value'=>$value, 'id'=>$id);
return true;
}
function update($key, $value) {
if (!$key)
return false;
elseif (!isset($this->config[$key]))
return $this->create($key, $value);
$setting = &$this->config[$key];
if ($setting['value'] == $value)
return true;
if (!db_query('UPDATE '.$this->table.' SET updated=NOW(), value='
.db_input($value).' WHERE id='.db_input($setting['id'])))
$setting['value'] = $value;
return true;
}
function updateAll($updates) {
if (!$this->update($key, $value))
$sql='DELETE FROM '.$this->table
.' WHERE `'.$this->section_column.'` = '.db_input($this->section);
db_query($sql);
unset($this->session);
}
}
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_html_thread' => true,
'name_format' => 'full', # First Last
'auto_claim_tickets'=> true,
'message_autoresponder_collabs' => true,
'add_email_collabs' => true,
'clients_only' => false,
'client_registration' => 'closed',
'accept_unregistered_email' => true,
'default_help_topic' => 0,
'help_topic_sort_mode' => 'a',
'client_verify_email' => 1,
function OsticketConfig($section=null) {
parent::Config($section);
if (count($this->config) == 0) {
// Fallback for osticket < 1.7@852ca89e
$sql='SELECT * FROM '.$this->table.' WHERE id = 1';
if (($res=db_query($sql)) && db_num_rows($res))
foreach (db_fetch_array($res) as $key=>$value)
$this->config[$key] = array('value'=>$value);
}
return true;
}
function lastModified($key=false) {
return max(array_map(array('parent', 'lastModified'),
array_keys($this->config)));
}
return !$this->isOnline();
function isHelpDeskOnline() {
return $this->isOnline();
function isOnline() {
function isKnowledgebaseEnabled() {
Loading
Loading full blame...