From 9130ebb7b64f0a5d010e8af92b04a8cf006cccbf Mon Sep 17 00:00:00 2001 From: Crack Date: Sat, 3 Jul 2010 19:02:54 +0200 Subject: [PATCH] allow to group fields in forms --- libraries/config.values.php | 2 + libraries/config/Form.class.php | 26 +++++++++--- libraries/config/FormDisplay.class.php | 8 ++++ libraries/config/FormDisplay.tpl.php | 57 ++++++++++++++++++++++++-- setup/styles.css | 14 +++++++ 5 files changed, 99 insertions(+), 8 deletions(-) diff --git a/libraries/config.values.php b/libraries/config.values.php index e79ef04e5..33e120d77 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -84,6 +84,8 @@ $cfg_db['Export']['format'] = array('codegen', 'csv', 'excel', 'htmlexcel', $cfg_db['Export']['compression'] = array('none', 'zip', 'gzip', 'bzip2'); $cfg_db['Export']['charset'] = array_merge(array(''), $GLOBALS['cfg']['AvailableCharsets']); $cfg_db['Export']['codegen_format'] = array('#', 'NHibernate C# DO', 'NHibernate XML'); +$cfg_db['Export']['excel_edition'] = array('win' => 'Windows', + 'mac_excel2003' => 'Excel 2003 / Macintosh', 'mac_excel2008' => 'Excel 2008 / Macintosh'); /** * Default values overrides diff --git a/libraries/config/Form.class.php b/libraries/config/Form.class.php index 6e2f99474..e91f03d2e 100644 --- a/libraries/config/Form.class.php +++ b/libraries/config/Form.class.php @@ -88,13 +88,25 @@ class Form trigger_error("$option_path - not a static value list", E_USER_ERROR); return array(); } - // convert value list array('a', 'b') to array('a' => 'a', 'b' => 'b') - // and array('#', 'a', 'b') to array('a', 'b') - if ($value[0] == '#') { + // convert array('#', 'a', 'b') to array('a', 'b') + if (isset($value[0]) && $value[0] == '#') { + // remove first element ('#') array_shift($value); - return $value; + } else { + // convert value list array('a', 'b') to array('a' => 'a', 'b' => 'b') + $has_string_keys = false; + for ($i = 0; $i < count($value); $i++) { + if (!isset($value[$i])) { + $has_string_keys = true; + break; + } + } + if (!$has_string_keys) { + $value = array_combine($value, $value); + } } - return array_combine($value, $value); + // $value has keys and value names, return it + return $value; } /** @@ -148,6 +160,10 @@ class Form { $cf = ConfigFile::getInstance(); foreach ($this->fields as $name => $path) { + if (strpos($name, ':group:') === 0) { + $this->fieldsTypes[$name] = 'group'; + continue; + } $v = $cf->getDbEntry($path); if ($v !== null) { $type = is_array($v) ? 'select' : $v; diff --git a/libraries/config/FormDisplay.class.php b/libraries/config/FormDisplay.class.php index 4e3f8d586..c20e926ef 100644 --- a/libraries/config/FormDisplay.class.php +++ b/libraries/config/FormDisplay.class.php @@ -327,6 +327,14 @@ class FormDisplay $value = (array) $value; $value_default = (array) $value_default; break; + case 'group': + $text = substr($field, 7); + if ($text != 'end') { + display_group_header($text); + } else { + display_group_footer(); + } + return; case 'NULL': trigger_error("Field $system_path has no type", E_USER_WARNING); return; diff --git a/libraries/config/FormDisplay.tpl.php b/libraries/config/FormDisplay.tpl.php index 2ec8142cd..efdb22433 100644 --- a/libraries/config/FormDisplay.tpl.php +++ b/libraries/config/FormDisplay.tpl.php @@ -66,6 +66,10 @@ function display_tabs_top($tabs) { */ function display_fieldset_top($title = '', $description = '', $errors = null, $attributes = array()) { + global $_FormDisplayGroup; + + $_FormDisplayGroup = false; + $attributes = array_merge(array('class' => 'optbox'), $attributes); foreach ($attributes as $k => &$attr) { $attr = $k . '="' . htmlspecialchars($attr) . '"'; @@ -113,6 +117,7 @@ function display_fieldset_top($title = '', $description = '', $errors = null, $a */ function display_input($path, $name, $description = '', $type, $value, $value_is_default = true, $opts = null) { + global $_FormDisplayGroup; static $base_dir, $img_path; $is_setup_script = defined('PMA_SETUP') && PMA_SETUP; @@ -129,8 +134,17 @@ function display_input($path, $name, $description = '', $type, $value, $value_is } $field_class = $field_class ? ' class="' . $field_class . '"' : ''; $name_id = 'name="' . $path . '" id="' . $path . '"'; + $tr_class = $_FormDisplayGroup ? ' class="group-field"' : ''; + if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') { + unset($opts['setvalue']); + $tr_class = ' class="group-header"'; + if ($_FormDisplayGroup) { + display_group_footer(); + } + $_FormDisplayGroup = true; + } ?> - +> @@ -229,9 +243,46 @@ function display_input($path, $name, $description = '', $type, $value, $value_is } /** - * Displays bottom part of a fieldset + * Display group header * - * @param array $js_array + * @param string $header_text + */ +function display_group_header($header_text) +{ + global $_FormDisplayGroup; + + if ($_FormDisplayGroup) { + display_group_footer(); + } + $_FormDisplayGroup = true; + if (!$header_text) { + return; + } + $colspan = 2; + if (defined('PMA_SETUP') && PMA_SETUP) { + $colspan++; + } +?> + + + + + +