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['control'] = translate('Control');
|
||||
$tabs['privacy'] = translate('Privacy');
|
||||
$tabs['MQTT'] = translate('MQTT');
|
||||
|
||||
if (isset($_REQUEST['tab']))
|
||||
$tab = validHtmlStr($_REQUEST['tab']);
|
||||
|
@ -398,19 +399,19 @@ 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();
|
||||
} else {
|
||||
while ($row = dbFetchNext($result)) {
|
||||
$config[$row['Name']] = $row;
|
||||
if ( !($configCat = &$configCats[$row['Category']]) ) {
|
||||
$configCats[$row['Category']] = array();
|
||||
$configCat = &$configCats[$row['Category']];
|
||||
}
|
||||
$configCat[$row['Name']] = $row;
|
||||
$configCats[$row['Category']][$row['Name']] = &$config[$row['Name']];
|
||||
}
|
||||
}
|
||||
|
||||
if ($tab == 'system') {
|
||||
|
@ -432,7 +433,6 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
|||
$offsets[] = $offset = $now->getOffset();
|
||||
$timezones[$timezone] = '(' . format_GMT_offset($offset) . ') ' . format_timezone_name($timezone);
|
||||
}
|
||||
|
||||
array_multisort($offsets, $timezones);
|
||||
}
|
||||
|
||||
|
@ -454,13 +454,15 @@ 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 ) {
|
||||
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'];
|
||||
?>
|
||||
|
@ -469,34 +471,22 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
|||
<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
|
||||
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'])) {
|
||||
?>
|
||||
|
||||
<?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
|
||||
$html_options = array();
|
||||
foreach ($options as $option) {
|
||||
if (preg_match('/^([^=]+)=(.+)$/', $option, $matches)) {
|
||||
$optionLabel = $matches[1];
|
||||
$optionValue = $matches[2];
|
||||
$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
|
||||
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) ) {
|
||||
|
@ -511,39 +501,29 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as
|
|||
<?php echo htmlspecialchars($optionLabel) ?>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
} # end foreach option
|
||||
} # end if count options > 3
|
||||
} else if ( $value['Type'] == 'text' ) {
|
||||
?>
|
||||
<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
|
||||
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' ) {
|
||||
?>
|
||||
<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
|
||||
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' ) {
|
||||
?>
|
||||
<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
|
||||
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' ) {
|
||||
?>
|
||||
<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
|
||||
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 {
|
||||
?>
|
||||
<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
|
||||
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
|
||||
}
|
||||
} # end foreach config entry in the category
|
||||
} # end if category exists
|
||||
?>
|
||||
|
||||
<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 -->
|
||||
|
|
Loading…
Reference in New Issue