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')) { ...@@ -14,7 +14,18 @@ if (!canView('system')) {
@include_once( "./functions/admin_func.php" ); @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 // get a list of permitted companies
$company = new CCompany(); $company = new CCompany();
...@@ -231,16 +242,9 @@ $config_options = array( ...@@ -231,16 +242,9 @@ $config_options = array(
//if this is a submitted page, overwrite the config file. //if this is a submitted page, overwrite the config file.
if(w2PgetParam( $_POST, "Save", '' )!=''){ if(w2PgetParam( $_POST, "Save", '' )!=''){
$q = new w2p_Database_Query;
if (is_writable($CONFIG_FILE)) { if (!$q) {
if (!$handle = fopen($CONFIG_FILE, 'w')) { $AppUI->setMsg($AppUI->_('Configuration table not accessible.'), UI_MSG_ERROR );
$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 { } else {
foreach ($config_options as $key=>$value){ foreach ($config_options as $key=>$value){
if(substr($key,0,7)=='heading') continue; if(substr($key,0,7)=='heading') continue;
...@@ -256,7 +260,7 @@ if(w2PgetParam( $_POST, "Save", '' )!=''){ ...@@ -256,7 +260,7 @@ if(w2PgetParam( $_POST, "Save", '' )!=''){
case 'select': case 'select':
$val = isset($_POST[$key])?$_POST[$key]:"0"; $val = isset($_POST[$key])?$_POST[$key]:"0";
break; break;
case 'multiselect': case 'multiselect'
if(isset($_POST[$key])){ if(isset($_POST[$key])){
foreach ($_POST[$key] as $idx=>$watcher){ foreach ($_POST[$key] as $idx=>$watcher){
$val .= $watcher.","; $val .= $watcher.",";
...@@ -271,25 +275,21 @@ if(w2PgetParam( $_POST, "Save", '' )!=''){ ...@@ -271,25 +275,21 @@ if(w2PgetParam( $_POST, "Save", '' )!=''){
default: default:
break; break;
} }
$q->addTable('helpdesk_config');
fwrite($handle, "\$HELPDESK_CONFIG['".$key."'] = '".$val."';\n"); $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();
fwrite($handle, "?>\n");
$AppUI->setMsg( $CONFIG_FILE." ".$AppUI->_('has been successfully updated'), UI_MSG_OK );
fclose($handle);
require( $CONFIG_FILE );
} }
} else { $AppUI->setMsg( $AppUI->_('Configuration has been successfully updated'), UI_MSG_OK );
$AppUI->setMsg( $CONFIG_FILE." ".$AppUI->_('is not writable'), UI_MSG_ERROR );
} }
} else if(w2PgetParam( $_POST, $AppUI->_('cancel'), '' )!=''){ } else if(w2PgetParam( $_POST, $AppUI->_('cancel'), '' )!=''){
$AppUI->redirect("m=system&a=viewmods"); $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. //Read the current config values from the config file and update the array.
foreach ($config_options as $key=>$value){ foreach ($config_options as $key=>$value){
if(isset($HELPDESK_CONFIG[$key])){ if(isset($HELPDESK_CONFIG[$key])){
......
...@@ -190,6 +190,19 @@ class CSetupHelpDesk extends w2p_Core_Setup ...@@ -190,6 +190,19 @@ class CSetupHelpDesk extends w2p_Core_Setup
$i++; $i++;
} }
// Helpdesk configuration table
$result = $this->_createConfigurationTable();
if (!$result) {
db_error();
return false;
}
$result = $this-> _insertConfigurationData();
if (!$result) {
db_error();
return false;
}
global $AppUI; global $AppUI;
$perms = $AppUI->acl(); $perms = $AppUI->acl();
...@@ -200,6 +213,7 @@ class CSetupHelpDesk extends w2p_Core_Setup ...@@ -200,6 +213,7 @@ class CSetupHelpDesk extends w2p_Core_Setup
{ {
$success = true; $success = true;
$bulk_sql[] = "DROP TABLE helpdesk_config";
$bulk_sql[] = "DROP TABLE helpdesk_items"; $bulk_sql[] = "DROP TABLE helpdesk_items";
$bulk_sql[] = "DROP TABLE helpdesk_item_status"; $bulk_sql[] = "DROP TABLE helpdesk_item_status";
$bulk_sql[] = "DROP TABLE helpdesk_item_watchers"; $bulk_sql[] = "DROP TABLE helpdesk_item_watchers";
...@@ -318,6 +332,16 @@ class CSetupHelpDesk extends w2p_Core_Setup ...@@ -318,6 +332,16 @@ class CSetupHelpDesk extends w2p_Core_Setup
} }
break; break;
case 0.9: case 0.9:
$result = $this->_createConfigurationTable();
if (!$result) {
db_error();
return false;
}
$result = $this-> _insertConfigurationData();
if (!$result) {
db_error();
return false;
}
default: default:
$success = 0; $success = 0;
} }
...@@ -336,4 +360,89 @@ class CSetupHelpDesk extends w2p_Core_Setup ...@@ -336,4 +360,89 @@ class CSetupHelpDesk extends w2p_Core_Setup
return true; 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