From f59639f17dc38a8c197752abb169439242f67fb6 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 12 Feb 2007 19:49:43 +0000 Subject: [PATCH] r1397: Setting system improvements: - Settings are no longer constructed from the master array in includes/setting.php, but rather are generated directly in the code at admin/setting.php - Improve the update mechanism for settings so it's not a bunch of REPLACE INTO queries, but rather just one large one --- admin/setting.php | 209 ++++++++++++++++++++++++++++++++---------- docs/changes.txt | 1 + includes/settings.php | 122 ------------------------ install/install.php | 1 + 4 files changed, 164 insertions(+), 169 deletions(-) delete mode 100755 includes/settings.php diff --git a/admin/setting.php b/admin/setting.php index c32b4da..4ed533d 100755 --- a/admin/setting.php +++ b/admin/setting.php @@ -20,7 +20,7 @@ \*=====================================================================*/ require_once('./global.php'); -require_once('./includes/settings.php'); +require_once('./includes/class_sort.php'); require_once('./includes/functions_datastore.php'); NavLinks::optionsPages(); @@ -43,6 +43,7 @@ if (empty($_REQUEST['do'])) if ($_POST['do'] == 'update') { + $updates = array(); foreach ($bugsys->in['setting'] AS $varname => $value) { if (is_array($value)) @@ -57,9 +58,11 @@ if ($_POST['do'] == 'update') } } - $db->query("REPLACE INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('" . $bugsys->escape($varname) . "', '" . $bugsys->escape($value) . "')"); + $updates[] = "('" . $bugsys->escape($varname) . "', '" . $bugsys->escape($value) . "')"; } + $db->query("REPLACE INTO " . TABLE_PREFIX . "setting (varname, value) VALUES " . implode(',', $updates)); + build_settings(); $admin->redirect('setting.php'); @@ -75,55 +78,146 @@ if ($_REQUEST['do'] == 'modify') $IS_SETTINGS = true; - // Don't let them normal folk see what's going on ;-) - if (!DEVDEBUG) - { - unset($settings['untouchables']); - } + // ################################################################### + $admin->table_start(); + $admin->table_head(_('General Options')); + + // allownewreg + $admin->row_span(_('Allow New Registrations'), 'thead'); + $admin->row_yesno(_('If this is set to yes, then new users will be allowed to register.'), 'setting[allownewreg]', $bugsys->options['allownewreg']); + + // verifyemail + $admin->row_span(_('Require Activation Email'), 'thead'); + $admin->row_yesno(_('Setting this to yes will force all new users to verify their account with an email activation link.'), 'setting[verifyemail]', $bugsys->options['verifyemail']); + + // moderatenewusers + $admin->row_span(_('Moderate New Users'), 'thead'); + $admin->row_yesno(_('All new users will have to be approved by the administration before being able to have normal user rights.'), 'setting[moderatenewusers]', $bugsys->options['moderatenewusers']); + + // sendwelcomemail + $admin->row_span(_('Send New Use Welcome Email'), 'thead'); + $admin->row_yesno(_('Setting this option to yes will send each new verified user a welcome email.'), 'setting[sendwelcomemail]', $bugsys->options['sendwelcomemail']); + + // webmasteremail + $admin->row_span(_('Webmaster Email Address'), 'thead'); + $admin->row_input(_('The email address from which emails will be sent out.'), 'setting[webmasteremail]', $bugsys->options['webmasteremail']); + + // trackertitle + $admin->row_span(_('Tracker Title'), 'thead'); + $admin->row_input(_('The global name of the bug tracker. Example: Blue Static Bug Tracker'), 'setting[trackertitle]', $bugsys->options['trackertitle']); + + // trackerurl + $admin->row_span(_('Tracker Base URL'), 'thead'); + $admin->row_input(_('The base URL of the tracker. This is used when creating external links to the tracker. Be sure that this does not end in a trailing slash ("/").
Example: http://www.bluestatic.org/bugs'), 'setting[trackerurl]', $bugsys->options['trackerurl']); + + // dateformat + $admin->row_span(_('Date Format'), 'thead'); + $admin->row_input(_('Set the date format used for bug report and comment information. This is based on PHP\'s date() function.'), 'setting[dateformat]', $bugsys->options['dateformat']); + + // defaulttimezone + $admin->row_span(_('Default Time Zone'), 'thead'); + $admin->row_text(_('This controls the time zone that all unregistered users view the tracker with.'), construct_option_select('setting[defaulttimezone]', $bugsys->datef->fetch_timezone_list(), $bugsys->options['defaulttimezone']), $bugsys->options['defaulttimezone']); + + // defaultlanguage + $admin->row_span(_('Default Language'), 'thead'); + $admin->row_text(_('You can set the default language that all new users (and guests) will use.'), construct_option_select('setting[defaultlanguage]', $bugsys->datastore['language'], $bugsys->options['defaultlanguage'], 'languageid', 'title'), $bugsys->options['defaultlanguage']); + + // syndicateditems + $admin->row_span(_('Number of Syndicated Items'), 'thead'); + $admin->row_input(_('The number of bugs to be syndicated at any one time by the Atom XML feed.'), 'setting[syndicateditems]', $bugsys->options['syndicateditems']); + + // redirectheaders + $admin->row_span(_('Use Header Redirects'), 'thead'); + $admin->row_yesno(_('Instead of displaying an intermediate page informing the user that their action was a success and a redirect is occurring, just send the user to the next screen using HTTP headers. This can save bandwidth.'), 'setting[redirectheaders]', $bugsys->options['redirectheaders']); + + $admin->table_end(); + + // ################################################################### + $admin->table_start(); + $admin->table_head(_('Bug Reporting Options')); + + // allowhtml + $admin->row_span(_('Allow HTML in Bug Reports'), 'thead'); + $admin->row_yesno(_('Set this to yes if you want to allow users to post raw HTML in their bug reports. This is very dangerous and it is not recommended.'), 'setting[allowhtml]', $bugsys->options['allowhtml']); + + // defaultseverity + $admin->row_span(_('Default Severity'), 'thead'); + $admin->row_text(_('The default severity that is selected when creating a new bug report.'), construct_option_select('setting[defaultseverity]', $bugsys->datastore['severity'], $bugsys->options['defaultseverity'], 'severityid', 'severity')); + + // defaultpriority + $admin->row_span(_('Default Priority'), 'thead'); + $admin->row_text(_('The default priority that will be selected when creating a new bug report. Depending on your permission setup, the user may not be able to set this in a new report so this will act as the value.'), construct_option_select('setting[defaultpriority]', $bugsys->datastore['priority'], $bugsys->options['defaultpriority'], 'priorityid', 'priority')); + + // defaultstatus + $admin->row_span(_('Default Status'), 'thead'); + $admin->row_text(_('The default default that is selected when creating a new bug report. If a user can not assign a status, this will be the one inserted into the database.'), construct_option_select('setting[defaultstatus]', $bugsys->datastore['status'], $bugsys->options['defaultstatus'], 'statusid', 'status')); + + // defaultresolve + $admin->row_span(_('Default Resolution'), 'thead'); + $admin->row_text(_('This is the default bug resolution. If a user is not able to change this field, setting this will act as the default value.'), construct_option_select('setting[defaultresolve]', $bugsys->datastore['resolution'], $bugsys->options['defaultresolve'], 'resolutionid', 'resolution')); + + // defaultassign + $admin->row_span(_('Default Bug Assignment'), 'thead'); + $admin->row_text(_('This is the default developer new bugs will be assigned to. If a user does not have permisssion to assign bugs, this will be the default. If you don\'t want any default assignment, leave this as Not Selected.'), construct_option_select('setting[defaultassign]', $bugsys->datastore['assignto'], $bugsys->options['defaultassign'], 'userid', 'displayname', 0)); + + // defaultcomment + $admin->row_span(_('Default Comment Text'), 'thead'); + $admin->row_textarea(_('If you wish to set a template for entering the initial comment of a bug report, then you may specify this here. However, the template will only take effect on the initial report/comment. Note: the template cannot be forced on the user as there is no way to validate it.'), 'setting[defaultcomment]', $bugsys->options['defaultcomment']); + + $admin->table_end(); + + // ################################################################### + $admin->table_start(); + $admin->table_head(_('Bug Listing Display Options')); - $firstloop = true; - foreach ($settings AS $group => $values) + // hidestatuses + $admin->row_span(_('Hide Statuses on Bug Listings'), 'thead'); + $admin->row_text(_('Here you can specify which statuses to hide on the bug list displays. Users have options in their controls to change this from these values, and this does not affect searches or the favorites list.'), construct_option_select('setting[hidestatuses]', $bugsys->datastore['status'], $bugsys->options['hidestatuses'], 'statusid', 'status', 0, true)); + + // defaultsortkey + $admin->row_span(_('Default Sort Column'), 'thead'); + $admin->row_text(_('Select the column to sort bugs by on listings. This is only a default setting which users can override in their preferences.'), construct_option_select('setting[defaultsortkey]', ListSorter::fetch_by_text(false), $bugsys->options['defaultsortkey'])); + + // defaultsortas + $admin->row_span(_('Default Sort Direction'), 'thead'); + $admin->row_text(_('Specify the default direction to sort bugs in the selected column. This works with and follows the same rules as the Sort Column.'), construct_option_select('setting[defaultsortas]', ListSorter::fetch_as_text(false), $bugsys->options['defaultsortas'])); + + // columnoptions + $admin->row_span(_('Default Column Ordering Options'), 'thead'); + $admin->row_text(_('Specify the order of the columns for bug listings. The value 0 disables the display of a column and if two or more columns have the same position number, they will be displayed in the same column.'), ConstructColumnOptionsSetting()); + + $admin->table_end(); + + // ################################################################### + $admin->table_start(); + $admin->table_head(_('Pagination Options')); + + // defaultpp + $admin->row_span(_('Default Per-Page Amount'), 'thead'); + $admin->row_input(_('The number of items (e.g. bugs) to be displayed on a page by default. The user will have the option of over-riding these values.'), 'setting[defaultpp]', $bugsys->options['defaultpp']); + + // maxpp + $admin->row_span(_('Maximum Per-Page Value'), 'thead'); + $admin->row_input(_('To prevent your server from experiencing load problems, set the maximum per page limit. Specifying a value here will make sure any user-entered value will not be higher than this, preventing server load problems.'), 'setting[maxpp]', $bugsys->options['maxpp']); + + // pagelinks + $admin->row_span(_('Number of Page Links'), 'thead'); + $admin->row_input(_('The number of pages that will appear in the page navigation system on either side of the current page. Set this to 0 to display all pages.'), 'setting[pagelinks]', $bugsys->options['pagelinks']); + + $admin->table_end(); + + // ################################################################### + if (DEVDEBUG) { - foreach ($values AS $key => $options) - { - if ($key == ':lang') - { - if (!$firstloop) - { - $admin->table_end(); - } - $admin->table_start(); - $admin->table_head($options); - } - else - { - $admin->row_span('" . $options[3] . "", 'thead'); - switch ($options[0]) - { - case 'textbox': - $admin->row_input($options[4], 'setting[' . $key . ']', $bugsys->options["$key"]); - break; - - case 'textarea': - $admin->row_textarea($options[4], 'setting[' . $key . ']', $bugsys->options["$key"]); - break; - - case 'yesno': - $admin->list_item(_('Yes'), '1', ($bugsys->options["$key"] ? true : false)); - $admin->list_item(_('No'), '0', ($bugsys->options["$key"] ? false : true)); - $admin->row_list($options[4], 'setting[' . $key . ']', false); - break; - - default: - eval('$optcode = "' . $options[0] . '";'); - $admin->row_text($options[4], $optcode); - break; - } - } - } + $admin->table_start(); + $admin->table_head('Untouchables'); + + // trackerversion + $admin->row_span('Version Number', 'thead'); + $admin->row_input('Version Number', 'setting[trackerversion]', $bugsys->options['trackerversion']); } - $admin->table_end(); + // ################################################################### $admin->table_start(); $admin->row_submit(); $admin->table_end(); @@ -132,6 +226,27 @@ if ($_REQUEST['do'] == 'modify') $admin->page_end(); } +// ################################################################### +/** +* Helper function for the $bugsys->options['columnoptions'] setting +* +* @return string Setting HTML code +*/ +function ConstructColumnOptionsSetting() +{ + global $bugsys; + + $array = ($bugsys->options['columnoptions'] == null ? array('bugid' => 1, 'summary' => 2, 'userid' => 2, 'product' => 3, 'version' => 3, 'component' => 0, 'status' => 4, 'resolution' => 4, 'priority' => 5, 'severity' => 5, 'lastpost' => 6, 'votes' => 0) : $bugsys->options['columnoptions']); + + $return = ''; + foreach ($bugsys->columns AS $column => $mask) + { + $return .= ''; + } + $return .= '
' . $bugsys->columnNames["$column"] . '
'; + return $return; +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/docs/changes.txt b/docs/changes.txt index 9d9e09f..f470b51 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -13,6 +13,7 @@ - Reduce a query on bug updates by not querying the automation system if it is not being used - Move custom field data into the bug table to reduce the use of JOINs - Remove a query on userctrl.php's save options called by build_assignedto() because the API already does this for us +- Setting system cleanup that improves speed by reducing queries and not using eval() 1.1.5 =============================== diff --git a/includes/settings.php b/includes/settings.php deleted file mode 100755 index 40de197..0000000 --- a/includes/settings.php +++ /dev/null @@ -1,122 +0,0 @@ - array(CODE, DEFAULT, VOLATILE, NAME, DESCRIPTION); <-- sets up a setting -*/ - -require_once('./includes/class_sort.php'); - -// ################################################################### - -$settings = array( -'general' => array( - ':lang' => _('General Options'), - - 'allownewreg' => array('yesno', 1, false, _('Allow New Registrations'), _('If this is set to yes, then new users will be allowed to register.')), - 'verifyemail' => array('yesno', 0, false, _('Require Activation Email'), _('Setting this to yes will force all new users to verify their account with an email activation link.')), - 'moderatenewusers' => array('yesno', 0, false, _('Moderate New Users'), _('All new users will have to be approved by the administration before being able to have normal user rights.')), - 'sendwelcomemail' => array('yesno', 1, false, _('Send New Use Welcome Email'), _('Setting this option to yes will send each new verified user a welcome email.')), - 'webmasteremail' => array('textbox', '', false, _('Webmaster Email Address'), _('The email address from which emails will be sent out.')), - 'trackertitle' => array('textbox', '', false, _('Tracker Title'), _('The global name of the bug tracker. Example: Blue Static Bug Tracker')), - 'trackerurl' => array('textbox', '', false, _('Tracker Base URL'), _('The base URL of the tracker. This is used when creating external links to the tracker. Be sure that this does not end in a trailing slash ("/").
Example: http://www.bluestatic.org/bugs')), - 'dateformat' => array('textbox', 'F j, Y h:i:s A', false, _('Date Format'), _('Set the date format used for bug report and comment information. This is based on PHP\'s date() function.')), - 'defaulttimezone' => array('" . construct_option_select("setting[defaulttimezone]", $bugsys->datef->fetch_timezone_list(), $bugsys->options["defaulttimezone"]) . "', 0, false, _('Default Time Zone'), _('This controls the time zone that all unregistered users view the tracker with.')), - 'defaultlanguage' => array('" . construct_option_select("setting[defaultlanguage]", $bugsys->datastore["language"], $bugsys->options["defaultlanguage"], "languageid", "title") . "', 1, false, _('Default Language'), _('You can set the default language that all new users (and guests) will use.')), - 'syndicateditems' => array('textbox', 10, false, _('Number of Syndicated Items'), _('The number of bugs to be syndicated at any one time by the Atom XML feed.')), - 'redirectheaders' => array('yesno', 0, false, _('Use Header Redirects'), _('Instead of displaying an intermediate page informing the user that their action was a success and a redirect is occurring, just send the user to the next screen using HTTP headers. This can save bandwidth.')), -), - -'reporting' => array( - ':lang' => _('Bug Reporting Options'), - - 'allowhtml' => array('yesno', 0, false, _('Allow HTML in Bug Reports'), _('Set this to yes if you want to allow users to post raw HTML in their bug reports. This is very dangerous and it is not recommended.')), - 'defaultseverity' => array('" . construct_option_select("setting[defaultseverity]", $bugsys->datastore["severity"], $bugsys->options["defaultseverity"], "severityid", "severity") . "', 2, false, _('Default Severity'), _('The default severity that is selected when creating a new bug report.')), - 'defaultpriority' => array('" . construct_option_select("setting[defaultpriority]", $bugsys->datastore["priority"], $bugsys->options["defaultpriority"], "priorityid", "priority") . "', 3, false, _('Default Priority'), _('The default priority that will be selected when creating a new bug report. Depending on your permission setup, the user may not be able to set this in a new report so this will act as the value.')), - 'defaultstatus' => array('" . construct_option_select("setting[defaultstatus]", $bugsys->datastore["status"], $bugsys->options["defaultstatus"], "statusid", "status") . "', 1, false, _('Default Status'), _('The default default that is selected when creating a new bug report. If a user can not assign a status, this will be the one inserted into the database.')), - 'defaultresolve' => array('" . construct_option_select("setting[defaultresolve]", $bugsys->datastore["resolution"], $bugsys->options["defaultresolve"], "resolutionid", "resolution") . "', 1, false, _('Default Resolution'), _('This is the default bug resolution. If a user is not able to change this field, setting this will act as the default value.')), - 'defaultassign' => array('" . construct_option_select("setting[defaultassign]", $bugsys->datastore["assignto"], $bugsys->options["defaultassign"], "userid", "displayname", 0) . "', 0, false, _('Default Bug Assignment'), _('This is the default developer new bugs will be assigned to. If a user does not have permisssion to assign bugs, this will be the default. If you don\'t want any default assignment, leave this as Not Selected.')), - 'defaultcomment' => array('textarea', '', false, _('Default Comment Text'), _('If you wish to set a template for entering the initial comment of a bug report, then you may specify this here. However, the template will only take effect on the initial report/comment. Note: the template cannot be forced on the user as there is no way to validate it.')) -), - -'display' => array( - ':lang' => _('Bug Listing Display Options'), - - 'hidestatuses' => array('" . construct_option_select("setting[hidestatuses]", $bugsys->datastore["status"], $bugsys->options["hidestatuses"], "statusid", "status", 0, true) . "', '0', false, _('Hide Statuses on Bug Listings'), _('Here you can specify which statuses to hide on the bug list displays. Users have options in their controls to change this from these values, and this does not affect searches or the favorites list.')), - 'defaultsortkey' => array('" . construct_option_select("setting[defaultsortkey]", ListSorter::fetch_by_text(false), $bugsys->options["defaultsortkey"]) . "', 'lastpost', false, _('Default Sort Column'), _('Select the column to sort bugs by on listings. This is only a default setting which users can override in their preferences.')), - 'defaultsortas' => array('" . construct_option_select("setting[defaultsortas]", ListSorter::fetch_as_text(false), $bugsys->options["defaultsortas"]) . "', 'desc', false, _('Default Sort Direction'), _('Specify the default direction to sort bugs in the selected column. This works with and follows the same rules as the Sort Column.')), - 'columnoptions' => array('" . ConstructColumnOptionsSetting() . "', null, false, _('Default Column Ordering Options'), _('Specify the order of the columns for bug listings. The value 0 disables the display of a column and if two or more columns have the same position number, they will be displayed in the same column.')) -), - -'pagination' => array( - ':lang' => _('Pagination Options'), - - 'defaultpp' => array('textbox', 20, false, _('Default Per-Page Amount'), _('The number of items (e.g. bugs) to be displayed on a page by default. The user will have the option of over-riding these values.')), - 'maxpp' => array('textbox', 100, false, _('Maximum Per-Page Value'), _('To prevent your server from experiencing load problems, set the maximum per page limit. Specifying a value here will make sure any user-entered value will not be higher than this, preventing server load problems.')), - 'pagelinks' => array('textbox', 3, false, _('Number of Page Links'), _('The number of pages that will appear in the page navigation system on either side of the current page. Set this to 0 to display all pages.')) -), - -'untouchables' => array( - ':lang' => _('Untouchables'), - - 'trackerversion' => array('textbox', '[#]version[#]', true, _('Tracker Version Number'), _('Do not touch this!')) -) -); - -// ################################################################### - -// ################################################################### -/** -* Helper function for the $bugsys->options['columnoptions'] setting -* -* @return string Setting HTML code -*/ -function ConstructColumnOptionsSetting() -{ - global $bugsys; - - $array = ($bugsys->options['columnoptions'] == null ? array('bugid' => 1, 'summary' => 2, 'userid' => 2, 'product' => 3, 'version' => 3, 'component' => 0, 'status' => 4, 'resolution' => 4, 'priority' => 5, 'severity' => 5, 'lastpost' => 6, 'votes' => 0) : $bugsys->options['columnoptions']); - - $return = ''; - foreach ($bugsys->columns AS $column => $mask) - { - $return .= ''; - } - $return .= '
' . $bugsys->columnNames["$column"] . '
'; - return $return; -} - -/*=====================================================================*\ -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file diff --git a/install/install.php b/install/install.php index 16853bd..6583ba8 100644 --- a/install/install.php +++ b/install/install.php @@ -106,6 +106,7 @@ if ($bugsys->in['mark'] == 3) $sgroup) -- 2.43.5