Add MQTT tab. Rework code that spits out options lines to be easier to read.
This commit is contained in:
parent
fb8db3b046
commit
2d8aa0801f
|
@ -45,6 +45,7 @@ $tabs['lowband'] = translate('LowBW');
|
||||||
$tabs['users'] = translate('Users');
|
$tabs['users'] = translate('Users');
|
||||||
$tabs['control'] = translate('Control');
|
$tabs['control'] = translate('Control');
|
||||||
$tabs['privacy'] = translate('Privacy');
|
$tabs['privacy'] = translate('Privacy');
|
||||||
|
$tabs['MQTT'] = translate('MQTT');
|
||||||
|
|
||||||
if (isset($_REQUEST['tab']))
|
if (isset($_REQUEST['tab']))
|
||||||
$tab = validHtmlStr($_REQUEST['tab']);
|
$tab = validHtmlStr($_REQUEST['tab']);
|
||||||
|
@ -398,22 +399,22 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
||||||
} // $tab == API
|
} // $tab == API
|
||||||
else {
|
else {
|
||||||
$config = array();
|
$config = array();
|
||||||
$configCat = array();
|
|
||||||
$configCats = array();
|
$configCats = array();
|
||||||
|
|
||||||
$result = $dbConn->query('SELECT * FROM `Config` ORDER BY `Id` ASC');
|
$result = $dbConn->query('SELECT * FROM `Config` ORDER BY `Id` ASC');
|
||||||
if ( !$result )
|
if (!$result) {
|
||||||
echo mysql_error();
|
echo mysql_error();
|
||||||
while ( $row = dbFetchNext($result) ) {
|
} else {
|
||||||
$config[$row['Name']] = $row;
|
while ($row = dbFetchNext($result)) {
|
||||||
if ( !($configCat = &$configCats[$row['Category']]) ) {
|
$config[$row['Name']] = $row;
|
||||||
$configCats[$row['Category']] = array();
|
if ( !($configCat = &$configCats[$row['Category']]) ) {
|
||||||
$configCat = &$configCats[$row['Category']];
|
$configCats[$row['Category']] = array();
|
||||||
|
}
|
||||||
|
$configCats[$row['Category']][$row['Name']] = &$config[$row['Name']];
|
||||||
}
|
}
|
||||||
$configCat[$row['Name']] = $row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $tab == 'system' ) {
|
if ($tab == 'system') {
|
||||||
$configCats[$tab]['ZM_LANG_DEFAULT']['Hint'] = join('|', getLanguages());
|
$configCats[$tab]['ZM_LANG_DEFAULT']['Hint'] = join('|', getLanguages());
|
||||||
$configCats[$tab]['ZM_SKIN_DEFAULT']['Hint'] = join('|', array_map('basename', glob('skins/*',GLOB_ONLYDIR)));
|
$configCats[$tab]['ZM_SKIN_DEFAULT']['Hint'] = join('|', array_map('basename', glob('skins/*',GLOB_ONLYDIR)));
|
||||||
$configCats[$tab]['ZM_CSS_DEFAULT']['Hint'] = join('|', array_map ( 'basename', glob('skins/'.ZM_SKIN_DEFAULT.'/css/*',GLOB_ONLYDIR) ));
|
$configCats[$tab]['ZM_CSS_DEFAULT']['Hint'] = join('|', array_map ( 'basename', glob('skins/'.ZM_SKIN_DEFAULT.'/css/*',GLOB_ONLYDIR) ));
|
||||||
|
@ -422,17 +423,16 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
||||||
function timezone_list() {
|
function timezone_list() {
|
||||||
static $timezones = null;
|
static $timezones = null;
|
||||||
|
|
||||||
if ( $timezones === null ) {
|
if ($timezones === null) {
|
||||||
$timezones = [];
|
$timezones = [];
|
||||||
$offsets = [];
|
$offsets = [];
|
||||||
$now = new DateTime('now', new DateTimeZone('UTC'));
|
$now = new DateTime('now', new DateTimeZone('UTC'));
|
||||||
|
|
||||||
foreach ( DateTimeZone::listIdentifiers() as $timezone ) {
|
foreach (DateTimeZone::listIdentifiers() as $timezone) {
|
||||||
$now->setTimezone(new DateTimeZone($timezone));
|
$now->setTimezone(new DateTimeZone($timezone));
|
||||||
$offsets[] = $offset = $now->getOffset();
|
$offsets[] = $offset = $now->getOffset();
|
||||||
$timezones[$timezone] = '(' . format_GMT_offset($offset) . ') ' . format_timezone_name($timezone);
|
$timezones[$timezone] = '(' . format_GMT_offset($offset) . ') ' . format_timezone_name($timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
array_multisort($offsets, $timezones);
|
array_multisort($offsets, $timezones);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,50 +454,40 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
||||||
$configCats[$tab]['ZM_TIMEZONE']['Hint'] = array(''=> translate('TZUnset')) + timezone_list();
|
$configCats[$tab]['ZM_TIMEZONE']['Hint'] = array(''=> translate('TZUnset')) + timezone_list();
|
||||||
} # end if tab == system
|
} # end if tab == system
|
||||||
?>
|
?>
|
||||||
<form name="optionsForm" class="" method="post" action="?">
|
<form name="optionsForm" method="post" action="?">
|
||||||
<input type="hidden" name="view" value="<?php echo $view ?>"/>
|
<input type="hidden" name="view" value="<?php echo $view ?>"/>
|
||||||
<input type="hidden" name="tab" value="<?php echo $tab ?>"/>
|
<input type="hidden" name="tab" value="<?php echo $tab ?>"/>
|
||||||
<input type="hidden" name="action" value="options"/>
|
<input type="hidden" name="action" value="options"/>
|
||||||
<?php
|
<?php
|
||||||
$configCat = $configCats[$tab];
|
if (!isset($configCats[$tab])) {
|
||||||
foreach ( $configCat as $name=>$value ) {
|
echo 'There are no config entries for category '.$tab.'.<br/>';
|
||||||
$shortName = preg_replace( '/^ZM_/', '', $name );
|
} else {
|
||||||
$optionPromptText = !empty($OLANG[$shortName])?$OLANG[$shortName]['Prompt']:$value['Prompt'];
|
foreach ($configCats[$tab] as $name=>$value) {
|
||||||
|
$shortName = preg_replace( '/^ZM_/', '', $name );
|
||||||
|
$optionPromptText = !empty($OLANG[$shortName])?$OLANG[$shortName]['Prompt']:$value['Prompt'];
|
||||||
?>
|
?>
|
||||||
<div class="form-group form-row">
|
<div class="form-group form-row">
|
||||||
<label for="<?php echo $name ?>" class="col-md-4 control-label text-md-right"><?php echo $shortName ?></label>
|
<label for="<?php echo $name ?>" class="col-md-4 control-label text-md-right"><?php echo $shortName ?></label>
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
<?php
|
<?php
|
||||||
if ( $value['Type'] == 'boolean' ) {
|
if ($value['Type'] == 'boolean') {
|
||||||
?>
|
echo '<input type="checkbox" id="'.$name.'" name="newConfig['.$name.']" value="1"'. ( $value['Value'] ? ' checked="checked"':'').( $canEdit?'':' disabled="disabled"' ).'/>'.PHP_EOL;
|
||||||
<input type="checkbox" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="1"<?php if ( $value['Value'] ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/>
|
} else if (is_array($value['Hint'])) {
|
||||||
<?php
|
echo htmlSelect("newConfig[$name]", $value['Hint'], $value['Value']);
|
||||||
} elseif ( is_array($value['Hint']) ) {
|
} else if (preg_match('/\|/', $value['Hint'])) {
|
||||||
echo htmlSelect("newConfig[$name]", $value['Hint'], $value['Value']);
|
$options = explode('|', $value['Hint']);
|
||||||
} elseif ( preg_match('/\|/', $value['Hint']) ) {
|
if (count($options) > 3) {
|
||||||
?>
|
$html_options = array();
|
||||||
|
foreach ($options as $option) {
|
||||||
<?php
|
if (preg_match('/^([^=]+)=(.+)$/', $option, $matches)) {
|
||||||
$options = explode('|', $value['Hint']);
|
$html_options[$matches[2]] = $matcahes[1];
|
||||||
if ( count($options) > 3 ) {
|
|
||||||
?>
|
|
||||||
<select class="form-control-sm" name="newConfig[<?php echo $name ?>]"<?php echo $canEdit?'':' disabled="disabled"' ?>>
|
|
||||||
<?php
|
|
||||||
foreach ( $options as $option ) {
|
|
||||||
if ( preg_match('/^([^=]+)=(.+)$/', $option, $matches) ) {
|
|
||||||
$optionLabel = $matches[1];
|
|
||||||
$optionValue = $matches[2];
|
|
||||||
} else {
|
} else {
|
||||||
$optionLabel = $optionValue = $option;
|
$html_options[$option] = $option;
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
<option value="<?php echo $optionValue ?>"<?php if ( $value['Value'] == $optionValue ) { echo ' selected="selected"'; } ?>><?php echo htmlspecialchars($optionLabel) ?></option>
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
?>
|
echo htmlSelect("newConfig[$name]", $html_options, $value['Value'],
|
||||||
</select>
|
$canEdit?array('class'=>'form-control-sm') : array('class'=>'form-control-sm', 'disabled'=>'disabled'));
|
||||||
<?php
|
} else {
|
||||||
} else {
|
|
||||||
foreach ( $options as $option ) {
|
foreach ( $options as $option ) {
|
||||||
if ( preg_match('/^([^=]+)=(.+)$/', $option) ) {
|
if ( preg_match('/^([^=]+)=(.+)$/', $option) ) {
|
||||||
$optionLabel = $matches[1];
|
$optionLabel = $matches[1];
|
||||||
|
@ -506,44 +496,34 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
||||||
$optionLabel = $optionValue = $option;
|
$optionLabel = $optionValue = $option;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<label class="font-weight-bold form-control-sm">
|
<label class="font-weight-bold form-control-sm">
|
||||||
<input type="radio" id="<?php echo $name.'_'.preg_replace('/[^a-zA-Z0-9]/', '', $optionValue) ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo $optionValue ?>"<?php if ( $value['Value'] == $optionValue ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/>
|
<input type="radio" id="<?php echo $name.'_'.preg_replace('/[^a-zA-Z0-9]/', '', $optionValue) ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo $optionValue ?>"<?php if ( $value['Value'] == $optionValue ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/>
|
||||||
<?php echo htmlspecialchars($optionLabel) ?>
|
<?php echo htmlspecialchars($optionLabel) ?>
|
||||||
</label>
|
</label>
|
||||||
<?php
|
<?php
|
||||||
}
|
} # end foreach option
|
||||||
|
} # end if count options > 3
|
||||||
|
} else if ( $value['Type'] == 'text' ) {
|
||||||
|
echo '<textarea class="form-control-sm" id="'.$name.'" name="newConfig['.$name.']" rows="5" cols="40"'.($canEdit?'':' disabled="disabled"').'>'.validHtmlStr($value['Value']).'</textarea>'.PHP_EOL;
|
||||||
|
} else if ( $value['Type'] == 'integer' ) {
|
||||||
|
echo '<input type="number" class="form-control-sm" id="'.$name.'" name="newConfig['.$name.']" value="'.validHtmlStr($value['Value']).'" '.($canEdit?'':' disabled="disabled"' ).' step="1"/>'.PHP_EOL;
|
||||||
|
} else if ( $value['Type'] == 'hexadecimal' ) {
|
||||||
|
echo '<input type="text" class="form-control-sm" id="'.$name.'" name="newConfig['.$name.']" value="'.validHtmlStr($value['Value']).'" '.($canEdit?'':' disabled="disabled"' ).'/>'.PHP_EOL;
|
||||||
|
} else if ( $value['Type'] == 'decimal' ) {
|
||||||
|
echo '<input type="text" class="form-control-sm" id="'.$name.'" name="newConfig['.$name.']" value="'.validHtmlStr($value['Value']).'" '.($canEdit?'':' disabled="disabled"' ).'/>'.PHP_EOL;
|
||||||
|
} else if ( $value['Type'] == 'password' ) {
|
||||||
|
echo '<input type="password" class="form-control-sm" id="'.$name.'" name="newConfig['.$name.']" value="'.validHtmlStr($value['Value']).'" '.($canEdit?'':' disabled="disabled"' ).'/>'.PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo '<input type="text" class="form-control-sm" id="'.$name.'" name="newConfig['.$name.']" value="'.validHtmlStr($value['Value']).'" '.($canEdit?'':' disabled="disabled"' ).'/>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
<span class="form-text form-control-sm"><?php echo validHtmlStr($optionPromptText); echo makeHelpLink($name) ?></span>
|
||||||
|
</div><!-- End .col-sm-9 -->
|
||||||
|
</div><!-- End .form-group -->
|
||||||
<?php
|
<?php
|
||||||
} else if ( $value['Type'] == 'text' ) {
|
} # end foreach config entry in the category
|
||||||
|
} # end if category exists
|
||||||
?>
|
?>
|
||||||
<textarea class="form-control-sm" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" rows="5" cols="40"<?php echo $canEdit?'':' disabled="disabled"' ?>><?php echo validHtmlStr($value['Value']) ?></textarea>
|
|
||||||
<?php
|
|
||||||
} else if ( $value['Type'] == 'integer' ) {
|
|
||||||
?>
|
|
||||||
<input type="number" class="form-control-sm" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo validHtmlStr($value['Value']) ?>" <?php echo $canEdit?'':' disabled="disabled"' ?>/>
|
|
||||||
<?php
|
|
||||||
} else if ( $value['Type'] == 'hexadecimal' ) {
|
|
||||||
?>
|
|
||||||
<input type="text" class="form-control-sm" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo validHtmlStr($value['Value']) ?>" <?php echo $canEdit?'':' disabled="disabled"' ?>/>
|
|
||||||
<?php
|
|
||||||
} else if ( $value['Type'] == 'decimal' ) {
|
|
||||||
?>
|
|
||||||
<input type="text" class="form-control-sm" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo validHtmlStr($value['Value']) ?>" <?php echo $canEdit?'':' disabled="disabled"' ?>/>
|
|
||||||
<?php
|
|
||||||
} else {
|
|
||||||
?>
|
|
||||||
<input type="text" class="form-control-sm" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="<?php echo validHtmlStr($value['Value']) ?>" <?php echo $canEdit?'':' disabled="disabled"' ?>/>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<span class="form-text form-control-sm"><?php echo validHtmlStr($optionPromptText); echo makeHelpLink($name) ?></span>
|
|
||||||
</div><!-- End .col-sm-9 -->
|
|
||||||
</div><!-- End .form-group -->
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div id="contentButtons">
|
<div id="contentButtons">
|
||||||
<button type="submit" <?php echo $canEdit?'':' disabled="disabled"' ?>><?php echo translate('Save') ?></button>
|
<button type="submit" <?php echo $canEdit?'':' disabled="disabled"' ?>><?php echo translate('Save') ?></button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -551,9 +531,6 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div><!-- end #options -->
|
</div><!-- end #options -->
|
||||||
</div>
|
</div>
|
||||||
</div> <!-- end row -->
|
</div> <!-- end row -->
|
||||||
|
|
Loading…
Reference in New Issue