add $cfg['UserprefsDisallow'] and allow setting it in setup script
correct IE opacity issue for "restore default value" button fix regressions introduced in previous commit
This commit is contained in:
@@ -2176,6 +2176,11 @@ setfacl -d -m "g:www-data:rwx" tmp
|
||||
closed state. A value of <tt>'open'</tt> does the reverse. To completely
|
||||
disable all visual sliders, use <tt>'disabled'</tt>.</dd>
|
||||
|
||||
<dt id="cfg_UserprefsDisallow">$cfg['UserprefsDisallow'] array</dt>
|
||||
<dd>Contains names of configuration options (keys in <tt>$cfg</tt> array)
|
||||
that users can't set through user preferences. For possible values, refer
|
||||
to <tt>libraries/config/user_preferences.forms.php</tt>.</dd>
|
||||
|
||||
<dt id="cfg_TitleTable">$cfg['TitleTable'] string</dt>
|
||||
<dt id="cfg_TitleDatabase">$cfg['TitleDatabase'] string</dt>
|
||||
<dt id="cfg_TitleServer">$cfg['TitleServer'] string</dt>
|
||||
|
@@ -571,7 +571,8 @@ function restoreField(field_id) {
|
||||
$(function() {
|
||||
$('.restore-default, .set-value').each(function() {
|
||||
var link = $(this);
|
||||
link.css('opacity', 0.25);
|
||||
// inline-block for IE so opacity inheritance works
|
||||
link.css('display', 'inline-block').css('opacity', 0.25);
|
||||
if (!link.hasClass('restore-default')) {
|
||||
// restore-default is handled by markField
|
||||
link.css('display', '');
|
||||
|
@@ -2282,7 +2282,13 @@ $cfg['NaturalOrder'] = true;
|
||||
*/
|
||||
$cfg['InitialSlidersState'] = 'closed';
|
||||
|
||||
|
||||
/**
|
||||
* User preferences: disallow these settings
|
||||
* For possible setting names look in libraries/config/user_preferences.forms.php
|
||||
*
|
||||
* @global array $cfg['UserprefsDisallow']
|
||||
*/
|
||||
$cfg['UserprefsDisallow'] = array();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// custom-setup by mkkeck: 2004-05-04
|
||||
|
@@ -499,8 +499,9 @@ class ConfigFile
|
||||
} else {
|
||||
// more than 4 values - value per line
|
||||
$ret = "\$cfg['$var_name'] = array(";
|
||||
for ($i = 0, $imax = count($ret)-1; $i <= $imax; $i++) {
|
||||
$ret .= ($i < $imax ? $crlf : '') . ' ' . $v;
|
||||
$imax = count($retv)-1;
|
||||
for ($i = 0; $i <= $imax; $i++) {
|
||||
$ret .= ($i < $imax ? ($i > 0 ? ',' : '') : '') . $crlf . ' ' . $retv[$i];
|
||||
}
|
||||
$ret .= ');' . $crlf;
|
||||
}
|
||||
|
@@ -8,9 +8,8 @@
|
||||
* o translated_path - work_path modified for HTML field name, a path with
|
||||
* slashes changed to hyphens, eg. Servers-4-verbose
|
||||
*
|
||||
* @package phpMyAdmin-setup
|
||||
* @package phpMyAdmin
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -64,7 +63,19 @@ class FormDisplay
|
||||
* Tells whether forms have been validated
|
||||
* @var bool
|
||||
*/
|
||||
private $is_valdiated = true;
|
||||
private $is_validated = true;
|
||||
|
||||
/**
|
||||
* Dictionary with user preferences keys
|
||||
* @var array
|
||||
*/
|
||||
private $userprefs_keys;
|
||||
|
||||
/**
|
||||
* Dictionary with disallowed user preferences keys
|
||||
* @var array
|
||||
*/
|
||||
private $userprefs_disallow;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -86,7 +97,7 @@ class FormDisplay
|
||||
public function registerForm($form_name, array $form, $server_id = null)
|
||||
{
|
||||
$this->forms[$form_name] = new Form($form_name, $form, $server_id);
|
||||
$this->is_valdiated = false;
|
||||
$this->is_validated = false;
|
||||
foreach ($this->forms[$form_name]->fields as $path) {
|
||||
$work_path = $server_id === null
|
||||
? $path
|
||||
@@ -121,7 +132,7 @@ class FormDisplay
|
||||
*/
|
||||
private function _validate()
|
||||
{
|
||||
if ($this->is_valdiated) {
|
||||
if ($this->is_validated) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,7 +166,7 @@ class FormDisplay
|
||||
$this->errors[$work_path] = $error_list;
|
||||
}
|
||||
}
|
||||
$this->is_valdiated = true;
|
||||
$this->is_validated = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,6 +208,16 @@ class FormDisplay
|
||||
$this->_validate();
|
||||
}
|
||||
|
||||
// user preferences
|
||||
if ($this->userprefs_keys === null) {
|
||||
$this->userprefs_keys = array_flip(PMA_read_userprefs_fieldnames());
|
||||
// read real config for user preferences display
|
||||
$userprefs_disallow = defined('PMA_SETUP') && PMA_SETUP
|
||||
? ConfigFile::getInstance()->get('UserprefsDisallow', array())
|
||||
: $GLOBALS['cfg']['UserprefsDisallow'];
|
||||
$this->userprefs_disallow = array_flip($userprefs_disallow);
|
||||
}
|
||||
|
||||
// display forms
|
||||
foreach ($this->forms as $form) {
|
||||
/* @var $form Form */
|
||||
@@ -211,9 +232,13 @@ class FormDisplay
|
||||
foreach ($form->fields as $field => $path) {
|
||||
$work_path = array_search($path, $this->system_paths);
|
||||
$translated_path = $this->translated_paths[$work_path];
|
||||
// always true/false for user preferences display
|
||||
$userprefs_allow = isset($this->userprefs_keys[$path])
|
||||
? !isset($this->userprefs_disallow[$path])
|
||||
: null;
|
||||
// display input
|
||||
$this->_displayFieldInput($form, $field, $path, $work_path,
|
||||
$translated_path, $show_restore_default, $js_default);
|
||||
$translated_path, $show_restore_default, $userprefs_allow, $js_default);
|
||||
// register JS validators for this field
|
||||
if (isset($validators[$path])) {
|
||||
js_validate($translated_path, $validators[$path], $js);
|
||||
@@ -250,10 +275,11 @@ class FormDisplay
|
||||
* @param string $work_path work path, eg. Servers/4/verbose
|
||||
* @param string $translated_path work path changed so that it can be used as XHTML id
|
||||
* @param bool $show_restore_default whether show "restore default" button besides the input field
|
||||
* @param mixed $userprefs_allow whether user preferences are enabled for this field (null - no support, true/false - enabled/disabled)
|
||||
* @param array &$js_default array which stores JavaScript code to be displayed
|
||||
*/
|
||||
private function _displayFieldInput(Form $form, $field, $system_path, $work_path,
|
||||
$translated_path, $show_restore_default, array &$js_default)
|
||||
$translated_path, $show_restore_default, $userprefs_allow, array &$js_default)
|
||||
{
|
||||
$name = PMA_lang_name($system_path);
|
||||
$description = PMA_lang_desc($system_path);
|
||||
@@ -270,7 +296,8 @@ class FormDisplay
|
||||
$opts = array(
|
||||
'doc' => $this->getDocLink($system_path),
|
||||
'wiki' => $this->getWikiLink($system_path),
|
||||
'show_restore_default' => $show_restore_default);
|
||||
'show_restore_default' => $show_restore_default,
|
||||
'userprefs_allow' => $userprefs_allow);
|
||||
if (isset($form->default[$system_path])) {
|
||||
$opts['setvalue'] = $form->default[$system_path];
|
||||
}
|
||||
@@ -417,6 +444,16 @@ class FormDisplay
|
||||
|
||||
$values = array();
|
||||
$to_save = array();
|
||||
$is_setup_script = defined('PMA_SETUP') && PMA_SETUP;
|
||||
if ($is_setup_script && $this->userprefs_keys === null) {
|
||||
$this->userprefs_keys = array_flip(PMA_read_userprefs_fieldnames());
|
||||
// read real config for user preferences display
|
||||
$userprefs_disallow = $is_setup_script
|
||||
? ConfigFile::getInstance()->get('UserprefsDisallow', array())
|
||||
: $GLOBALS['cfg']['UserprefsDisallow'];
|
||||
$this->userprefs_disallow = array_flip($userprefs_disallow);
|
||||
}
|
||||
|
||||
$this->errors = array();
|
||||
foreach ($forms as $form) {
|
||||
/* @var $form Form */
|
||||
@@ -448,6 +485,16 @@ class FormDisplay
|
||||
}
|
||||
}
|
||||
|
||||
// user preferences allow/disallow
|
||||
if ($is_setup_script && isset($this->userprefs_keys[$system_path])) {
|
||||
if (isset($this->userprefs_disallow[$system_path])
|
||||
&& isset($_POST[$key . '-userprefs-allow'])) {
|
||||
unset($this->userprefs_disallow[$system_path]);
|
||||
} else if (!isset($_POST[$key . '-userprefs-allow'])) {
|
||||
$this->userprefs_disallow[$system_path] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// cast variables to correct type
|
||||
$type = $form->getOptionType($field);
|
||||
switch ($type) {
|
||||
@@ -516,6 +563,9 @@ class FormDisplay
|
||||
}
|
||||
$cf->set($work_path, $values[$path], $path);
|
||||
}
|
||||
if ($is_setup_script) {
|
||||
$cf->set('UserprefsDisallow', array_keys($this->userprefs_disallow));
|
||||
}
|
||||
}
|
||||
|
||||
// don't look for non-critical errors
|
||||
|
@@ -2,9 +2,8 @@
|
||||
/**
|
||||
* Form templates
|
||||
*
|
||||
* @package phpMyAdmin-setup
|
||||
* @package phpMyAdmin
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -98,7 +97,7 @@ function display_fieldset_top($title = '', $description = '', $errors = null, $a
|
||||
* o errors - error array
|
||||
* o setvalue - (string) shows button allowing to set poredefined value
|
||||
* o show_restore_default - (boolean) whether show "restore default" button
|
||||
* o userprefs_allow - whether show user preferences allow/deny checkbox (null - no, true/false - yes)
|
||||
* o userprefs_allow - whether user preferences are enabled for this field (null - no support, true/false - enabled/disabled)
|
||||
* o values - key - value paris for <select> fields
|
||||
* o values_escaped - (boolean) tells whether values array is already escaped (defaults to false)
|
||||
* o values_disabled - (array)list of disabled values (keys from values)
|
||||
@@ -116,21 +115,20 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
|
||||
{
|
||||
static $base_dir, $img_path;
|
||||
|
||||
$is_setup_script = defined('PMA_SETUP') && PMA_SETUP;
|
||||
if ($base_dir === null) {
|
||||
$is_setup_script = defined('PMA_SETUP') && PMA_SETUP;
|
||||
$base_dir = $is_setup_script ? '../' : '';
|
||||
$img_path = $is_setup_script
|
||||
? '../' . ltrim($GLOBALS['cfg']['ThemePath'], './') . '/original/img/'
|
||||
: $_SESSION['PMA_Theme']->img_path;
|
||||
}
|
||||
$has_errors = isset($opts['errors']) && !empty($opts['errors']);
|
||||
$field_class = $type == 'checkbox' ? '' : 'checkbox';
|
||||
$field_class = $type == 'checkbox' ? 'checkbox' : '';
|
||||
if (!$value_is_default) {
|
||||
$field_class .= ($field_class == '' ? '' : ' ') . ($has_errors ? 'custom field-error' : 'custom');
|
||||
}
|
||||
$field_class = 'class="' . $field_class . '"';
|
||||
$field_class = $field_class ? ' class="' . $field_class . '"' : '';
|
||||
$name_id = 'name="' . $path . '" id="' . $path . '"';
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<th>
|
||||
@@ -152,8 +150,7 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
|
||||
. ' value="' . htmlspecialchars($value) . '" />';
|
||||
break;
|
||||
case 'checkbox':
|
||||
echo '<span ' . $field_class
|
||||
. '"><input type="checkbox" ' . $name_id
|
||||
echo '<span' . $field_class . '><input type="checkbox" ' . $name_id
|
||||
. ($value ? ' checked="checked"' : '') . ' /></span>';
|
||||
break;
|
||||
case 'select':
|
||||
@@ -212,8 +209,18 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
|
||||
echo '</dl>';
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
<?php
|
||||
if ($is_setup_script && isset($opts['userprefs_allow'])) {
|
||||
?>
|
||||
<td class="userprefs-allow" title="<?php echo __('Allow users to customize this value') ?>">
|
||||
<input type="checkbox" name="<?php echo $path ?>-userprefs-allow" <?php if ($opts['userprefs_allow']) echo 'checked="checked"' ?> />
|
||||
</td>
|
||||
<?php
|
||||
} else if ($is_setup_script) {
|
||||
echo '<td> </td>';
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
@@ -225,9 +232,13 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
|
||||
*/
|
||||
function display_fieldset_bottom()
|
||||
{
|
||||
$colspan = 2;
|
||||
if (defined('PMA_SETUP') && PMA_SETUP) {
|
||||
$colspan++;
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="2" class="lastrow">
|
||||
<td colspan="<?php echo $colspan ?>" class="lastrow">
|
||||
<input type="submit" name="submit_save" value="<?php echo __('Save') ?>" class="green" />
|
||||
<input type="button" name="submit_reset" value="<?php echo __('Reset') ?>" />
|
||||
</td>
|
||||
|
@@ -168,3 +168,25 @@ function ajaxValidate(parent, id, values) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// END: Form validation and field operations
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// User preferences allow/disallow UI
|
||||
//
|
||||
|
||||
$(function() {
|
||||
$('.userprefs-allow').click(function(e) {
|
||||
if (this != e.target) {
|
||||
return;
|
||||
}
|
||||
var el = $(this).find('input');
|
||||
el.attr('checked', !el.attr('checked'));
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// END: User preferences allow/disallow UI
|
||||
// ------------------------------------------------------------------
|
@@ -262,6 +262,18 @@ fieldset td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
fieldset td.userprefs-allow {
|
||||
padding: 0;
|
||||
vertical-align: middle;
|
||||
text-align: center;
|
||||
width: 3em;
|
||||
}
|
||||
|
||||
fieldset td.userprefs-allow:hover {
|
||||
cursor: pointer;
|
||||
background-color: #EEE;
|
||||
}
|
||||
|
||||
fieldset th small {
|
||||
display: block;
|
||||
font-weight: normal;
|
||||
@@ -307,7 +319,7 @@ fieldset.simple .lastrow {
|
||||
|
||||
span.checkbox {
|
||||
padding: 2px;
|
||||
display: inline-block;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.custom { /* customized field */
|
||||
|
Reference in New Issue
Block a user