Commit 4ec527ec authored by Jean-Paul Saman's avatar Jean-Paul Saman

config: rewrite how configuration is handled.

Store the module configuration in a separate tabel 'helpdesk_config'.
parent 1e5b5577
......@@ -14,7 +14,18 @@ if (!canView('system')) {
@include_once( "./functions/admin_func.php" );
$CONFIG_FILE = "./modules/helpdesk/config.php";
$HELPDESK_CONFIG = array();
$q = new w2p_Database_Query;
// Read values from table
$q->addQuery('*');
$q->addTable('helpdesk_config');
if (!$q->exec()) {
$AppUI->setMsg(db_error(), UI_MSG_ERROR);
}
while ($row = $q->fetchRow()) {
$HELPDESK_CONFIG[$row['helpdesk_config']] = $row['helpdesk_value'];
}
$q->clear();
// get a list of permitted companies
$company = new CCompany();
......@@ -231,65 +242,54 @@ $config_options = array(
//if this is a submitted page, overwrite the config file.
if(w2PgetParam( $_POST, "Save", '' )!=''){
$q = new w2p_Database_Query;
if (!$q) {
$AppUI->setMsg($AppUI->_('Configuration table not accessible.'), UI_MSG_ERROR );
} else {
foreach ($config_options as $key=>$value){
if(substr($key,0,7)=='heading') continue;
if (is_writable($CONFIG_FILE)) {
if (!$handle = fopen($CONFIG_FILE, 'w')) {
$AppUI->setMsg( $CONFIG_FILE." ".$AppUI->_('cannot be opened'), UI_MSG_ERROR );
exit;
}
if (fwrite($handle, "<?php //Do not edit this file by hand, it will be overwritten by the configuration utility. \n") === FALSE) {
$AppUI->setMsg( $CONFIG_FILE." ".$AppUI->_('cannot be written to'), UI_MSG_ERROR );
exit;
} else {
foreach ($config_options as $key=>$value){
if(substr($key,0,7)=='heading') continue;
$val="";
switch($value['type']){
case 'checkbox':
$val = isset($_POST[$key])?"1":"0";
break;
case 'text':
$val = isset($_POST[$key])?$_POST[$key]:"";
break;
case 'select':
$val = isset($_POST[$key])?$_POST[$key]:"0";
break;
case 'multiselect':
if(isset($_POST[$key])){
foreach ($_POST[$key] as $idx=>$watcher){
$val .= $watcher.",";
}
$val=trim($val,',');
}
else $val=0;
break;
case 'radio':
$val = $_POST[$key];
break;
default:
break;
$val="";
switch($value['type']){
case 'checkbox':
$val = isset($_POST[$key])?"1":"0";
break;
case 'text':
$val = isset($_POST[$key])?$_POST[$key]:"";
break;
case 'select':
$val = isset($_POST[$key])?$_POST[$key]:"0";
break;
case 'multiselect'
if(isset($_POST[$key])){
foreach ($_POST[$key] as $idx=>$watcher){
$val .= $watcher.",";
}
$val=trim($val,',');
}
fwrite($handle, "\$HELPDESK_CONFIG['".$key."'] = '".$val."';\n");
}
fwrite($handle, "?>\n");
$AppUI->setMsg( $CONFIG_FILE." ".$AppUI->_('has been successfully updated'), UI_MSG_OK );
fclose($handle);
require( $CONFIG_FILE );
else $val=0;
break;
case 'radio':
$val = $_POST[$key];
break;
default:
break;
}
} else {
$AppUI->setMsg( $CONFIG_FILE." ".$AppUI->_('is not writable'), UI_MSG_ERROR );
$q->addTable('helpdesk_config');
$q->addUpdate('helpdesk_config', $key);
$q->addUpdate('helpdesk_value', $_POST[$val]);
$q->addWhere('helpdesk_config = "$key"');
if (!$q->exec()) {
$AppUI->setMsg(db_error(), UI_MSG_ERROR);
}
$q->clear();
}
$AppUI->setMsg( $AppUI->_('Configuration has been successfully updated'), UI_MSG_OK );
}
} else if(w2PgetParam( $_POST, $AppUI->_('cancel'), '' )!=''){
$AppUI->redirect("m=system&a=viewmods");
}
//$HELPDESK_CONFIG = array();
require_once( $CONFIG_FILE );
//Read the current config values from the config file and update the array.
foreach ($config_options as $key=>$value){
if(isset($HELPDESK_CONFIG[$key])){
......
......@@ -190,6 +190,19 @@ class CSetupHelpDesk extends w2p_Core_Setup
$i++;
}
// Helpdesk configuration table
$result = $this->_createConfigurationTable();
if (!$result) {
db_error();
return false;
}
$result = $this-> _insertConfigurationData();
if (!$result) {
db_error();
return false;
}
global $AppUI;
$perms = $AppUI->acl();
......@@ -200,6 +213,7 @@ class CSetupHelpDesk extends w2p_Core_Setup
{
$success = true;
$bulk_sql[] = "DROP TABLE helpdesk_config";
$bulk_sql[] = "DROP TABLE helpdesk_items";
$bulk_sql[] = "DROP TABLE helpdesk_item_status";
$bulk_sql[] = "DROP TABLE helpdesk_item_watchers";
......@@ -318,6 +332,16 @@ class CSetupHelpDesk extends w2p_Core_Setup
}
break;
case 0.9:
$result = $this->_createConfigurationTable();
if (!$result) {
db_error();
return false;
}
$result = $this-> _insertConfigurationData();
if (!$result) {
db_error();
return false;
}
default:
$success = 0;
}
......@@ -336,4 +360,89 @@ class CSetupHelpDesk extends w2p_Core_Setup
return true;
}
private function _createConfigurationTable() {
$q = new w2p_Database_Query();
$sql = "( " .
" `helpdesk_config` varchar(25) NOT NULL, " .
" `helpdesk_value` varchar(25), " .
" PRIMARY KEY (`helpdesk_config`) " .
") ENGINE = MYISAM DEFAULT CHARSET = utf8";
$q->createTable('helpdesk_config');
$q->createDefinition($sql);
$result = $q->exec();
return $result;
}
private function _insertConfigurationData() {
$q = new w2p_Database_Query();
$q->addTable('helpdesk_config');
$q->addInsert('helpdesk_config', 'items_per_page');
$q->addInsert('helpdesk_value', '30');
$q->addInsert('helpdesk_config', 'status_log_items_per_page');
$q->addInsert('helpdesk_value', '15');
$q->addInsert('helpdesk_config', 'pages_per_side');
$q->addInsert('helpdesk_value', '5');
$q->addInsert('helpdesk_config', 'the_company');
$q->addInsert('helpdesk_value', '0');
$q->addInsert('helpdesk_config', 'no_company_editable');
$q->addInsert('helpdesk_value', '0');
$q->addInsert('helpdesk_config', 'minimum_edit_level');
$q->addInsert('helpdesk_value', '0');
$q->addInsert('helpdesk_config','use_project_perms');
$q->addInsert('helpdesk_value', '0');
$q->addInsert('helpdesk_config', 'minimum_report_level');
$q->addInsert('helpdesk_value', '0');
$q->addInsert('helpdesk_config', 'new_hd_item_title_prefix');
$q->addInsert('helpdesk_value', 'HD-%05d');
$q->addInsert('helpdesk_config', 'default_assigned_to_current_user');
$q->addInsert('helpdesk_value', '-1');
$q->addInsert('helpdesk_config', 'default_company_current_company');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'default_watcher');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'default_watcher_list');
$q->addInsert('helpdesk_value', '0');
$q->addInsert('helpdesk_config', 'search_criteria_search');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_call_type');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_company');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_status');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_call_source');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_project');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_assigned_to');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_priority');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_application');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_requestor');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_severity');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'search_criteria_service');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'default_notify_by_email');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'task_watchers_notification');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'task_requestor_notification');
$q->addInsert('helpdesk_value', '1');
$q->addInsert('helpdesk_config', 'notity_email_address');
$q->addInsert('helpdesk_value', 'support@yourcomapany.com');
$q->addInsert('helpdesk_config', 'email_subject');
$q->addInsert('helpdesk_value', 'Your Company registered your recent request');
$q->addInsert('helpdesk_config','email_header');
$q->addInsert('helpdesk_value', 'Your Company Management Registry');
$result = $q->exec();
return $result;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment