Add MQTT tab. Rework code that spits out options lines to be easier to read.

This commit is contained in:
Isaac Connor 2021-12-29 13:15:20 -05:00
parent fb8db3b046
commit 2d8aa0801f
1 changed files with 54 additions and 77 deletions

View File

@ -45,6 +45,7 @@ $tabs['lowband'] = translate('LowBW');
$tabs['users'] = translate('Users');
$tabs['control'] = translate('Control');
$tabs['privacy'] = translate('Privacy');
$tabs['MQTT'] = translate('MQTT');
if (isset($_REQUEST['tab']))
$tab = validHtmlStr($_REQUEST['tab']);
@ -398,22 +399,22 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
} // $tab == API
else {
$config = array();
$configCat = array();
$configCats = array();
$result = $dbConn->query('SELECT * FROM `Config` ORDER BY `Id` ASC');
if ( !$result )
if (!$result) {
echo mysql_error();
while ( $row = dbFetchNext($result) ) {
$config[$row['Name']] = $row;
if ( !($configCat = &$configCats[$row['Category']]) ) {
$configCats[$row['Category']] = array();
$configCat = &$configCats[$row['Category']];
} else {
while ($row = dbFetchNext($result)) {
$config[$row['Name']] = $row;
if ( !($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_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) ));
@ -422,17 +423,16 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
function timezone_list() {
static $timezones = null;
if ( $timezones === null ) {
if ($timezones === null) {
$timezones = [];
$offsets = [];
$now = new DateTime('now', new DateTimeZone('UTC'));
foreach ( DateTimeZone::listIdentifiers() as $timezone ) {
foreach (DateTimeZone::listIdentifiers() as $timezone) {
$now->setTimezone(new DateTimeZone($timezone));
$offsets[] = $offset = $now->getOffset();
$timezones[$timezone] = '(' . format_GMT_offset($offset) . ') ' . format_timezone_name($timezone);
}
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();
} # 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="tab" value="<?php echo $tab ?>"/>
<input type="hidden" name="action" value="options"/>
<?php
$configCat = $configCats[$tab];
foreach ( $configCat as $name=>$value ) {
$shortName = preg_replace( '/^ZM_/', '', $name );
$optionPromptText = !empty($OLANG[$shortName])?$OLANG[$shortName]['Prompt']:$value['Prompt'];
if (!isset($configCats[$tab])) {
echo 'There are no config entries for category '.$tab.'.<br/>';
} else {
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">
<label for="<?php echo $name ?>" class="col-md-4 control-label text-md-right"><?php echo $shortName ?></label>
<div class="col-md">
<?php
if ( $value['Type'] == 'boolean' ) {
?>
<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"' ?>/>
<?php
} elseif ( is_array($value['Hint']) ) {
echo htmlSelect("newConfig[$name]", $value['Hint'], $value['Value']);
} elseif ( preg_match('/\|/', $value['Hint']) ) {
?>
<?php
$options = explode('|', $value['Hint']);
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];
if ($value['Type'] == 'boolean') {
echo '<input type="checkbox" id="'.$name.'" name="newConfig['.$name.']" value="1"'. ( $value['Value'] ? ' checked="checked"':'').( $canEdit?'':' disabled="disabled"' ).'/>'.PHP_EOL;
} else if (is_array($value['Hint'])) {
echo htmlSelect("newConfig[$name]", $value['Hint'], $value['Value']);
} else if (preg_match('/\|/', $value['Hint'])) {
$options = explode('|', $value['Hint']);
if (count($options) > 3) {
$html_options = array();
foreach ($options as $option) {
if (preg_match('/^([^=]+)=(.+)$/', $option, $matches)) {
$html_options[$matches[2]] = $matcahes[1];
} 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
}
?>
</select>
<?php
} else {
echo htmlSelect("newConfig[$name]", $html_options, $value['Value'],
$canEdit?array('class'=>'form-control-sm') : array('class'=>'form-control-sm', 'disabled'=>'disabled'));
} else {
foreach ( $options as $option ) {
if ( preg_match('/^([^=]+)=(.+)$/', $option) ) {
$optionLabel = $matches[1];
@ -506,44 +496,34 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
$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"' ?>/>
<?php echo htmlspecialchars($optionLabel) ?>
</label>
<?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
} 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">
<button type="submit" <?php echo $canEdit?'':' disabled="disabled"' ?>><?php echo translate('Save') ?></button>
</div>
@ -551,9 +531,6 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
<?php
}
?>
</div><!-- end #options -->
</div>
</div> <!-- end row -->