mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix coding style part 2
This commit is contained in:
@@ -1,112 +1,103 @@
|
||||
<?php
|
||||
|
||||
# Load our list of available applications
|
||||
if ($handle = opendir($config['install_dir'] . "/includes/polling/applications/"))
|
||||
{
|
||||
while (false !== ($file = readdir($handle)))
|
||||
{
|
||||
if ($file != "." && $file != ".." && strstr($file, ".inc.php"))
|
||||
{
|
||||
$applications[] = str_replace(".inc.php", "", $file);
|
||||
// Load our list of available applications
|
||||
if ($handle = opendir($config['install_dir'].'/includes/polling/applications/')) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != '.' && $file != '..' && strstr($file, '.inc.php')) {
|
||||
$applications[] = str_replace('.inc.php', '', $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
# Check if the form was POSTed
|
||||
if ($_POST['device'])
|
||||
{
|
||||
$updated = 0;
|
||||
$param[] = $device['device_id'];
|
||||
foreach (array_keys($_POST) as $key)
|
||||
{
|
||||
if (substr($key,0,4) == 'app_')
|
||||
{
|
||||
$param[] = substr($key,4);
|
||||
$enabled[] = substr($key,4);
|
||||
$replace[] = "?";
|
||||
// Check if the form was POSTed
|
||||
if ($_POST['device']) {
|
||||
$updated = 0;
|
||||
$param[] = $device['device_id'];
|
||||
foreach (array_keys($_POST) as $key) {
|
||||
if (substr($key, 0, 4) == 'app_') {
|
||||
$param[] = substr($key, 4);
|
||||
$enabled[] = substr($key, 4);
|
||||
$replace[] = '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($enabled)) {
|
||||
$updated += dbDelete('applications', "`device_id` = ? AND `app_type` NOT IN (".implode(",",$replace).")", $param);
|
||||
} else {
|
||||
$updated += dbDelete('applications', "`device_id` = ?", array($param));
|
||||
}
|
||||
|
||||
foreach (dbFetchRows( "SELECT `app_type` FROM `applications` WHERE `device_id` = ?", array($device['device_id'])) as $row)
|
||||
{
|
||||
$app_in_db[] = $row['app_type'];
|
||||
}
|
||||
|
||||
foreach ($enabled as $app)
|
||||
{
|
||||
if (!in_array($app,$app_in_db))
|
||||
{
|
||||
$updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications');
|
||||
if (count($enabled)) {
|
||||
$updated += dbDelete('applications', '`device_id` = ? AND `app_type` NOT IN ('.implode(',', $replace).')', $param);
|
||||
}
|
||||
else {
|
||||
$updated += dbDelete('applications', '`device_id` = ?', array($param));
|
||||
}
|
||||
}
|
||||
|
||||
if ($updated)
|
||||
{
|
||||
print_message("Applications updated!");
|
||||
}
|
||||
else
|
||||
{
|
||||
print_message("No changes.");
|
||||
}
|
||||
foreach (dbFetchRows('SELECT `app_type` FROM `applications` WHERE `device_id` = ?', array($device['device_id'])) as $row) {
|
||||
$app_in_db[] = $row['app_type'];
|
||||
}
|
||||
|
||||
foreach ($enabled as $app) {
|
||||
if (!in_array($app, $app_in_db)) {
|
||||
$updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications');
|
||||
}
|
||||
}
|
||||
|
||||
if ($updated) {
|
||||
print_message('Applications updated!');
|
||||
}
|
||||
else {
|
||||
print_message('No changes.');
|
||||
}
|
||||
}//end if
|
||||
|
||||
// Show list of apps with checkboxes
|
||||
echo '<div style="padding: 10px;">';
|
||||
|
||||
$apps_enabled = dbFetchRows('SELECT * from `applications` WHERE `device_id` = ? ORDER BY app_type', array($device['device_id']));
|
||||
if (count($apps_enabled)) {
|
||||
foreach ($apps_enabled as $application) {
|
||||
$app_enabled[] = $application['app_type'];
|
||||
}
|
||||
}
|
||||
|
||||
# Show list of apps with checkboxes
|
||||
echo('<div style="padding: 10px;">');
|
||||
|
||||
$apps_enabled = dbFetchRows("SELECT * from `applications` WHERE `device_id` = ? ORDER BY app_type", array($device['device_id']));
|
||||
if (count($apps_enabled))
|
||||
{
|
||||
foreach ($apps_enabled as $application)
|
||||
{
|
||||
$app_enabled[] = $application['app_type'];
|
||||
}
|
||||
}
|
||||
|
||||
echo("<div class='row'>
|
||||
<div class='col-md-4'>
|
||||
<form id='appedit' name='appedit' method='post' action='' role='form' class='form-horizontal'>
|
||||
<input type=hidden name=device value='".$device['device_id']."'>
|
||||
<table class='table table-condensed table-striped table-responsive'>
|
||||
echo "<div class='row'>
|
||||
<div class='col-md-4'>
|
||||
<form id='appedit' name='appedit' method='post' action='' role='form' class='form-horizontal'>
|
||||
<input type=hidden name=device value='".$device['device_id']."'>
|
||||
<table class='table table-condensed table-striped table-responsive'>
|
||||
<tr align=center>
|
||||
<th>Enable</th>
|
||||
<th>Application</th>
|
||||
<th>Enable</th>
|
||||
<th>Application</th>
|
||||
</tr>
|
||||
");
|
||||
";
|
||||
|
||||
$row = 1;
|
||||
|
||||
foreach ($applications as $app)
|
||||
{
|
||||
if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
|
||||
foreach ($applications as $app) {
|
||||
if (is_integer($row / 2)) {
|
||||
$row_colour = $list_colour_a;
|
||||
}
|
||||
else {
|
||||
$row_colour = $list_colour_b;
|
||||
}
|
||||
|
||||
echo(" <tr bgcolor=$row_colour>");
|
||||
echo(" <td>");
|
||||
echo(" <input type=checkbox" . (in_array($app,$app_enabled) ? ' checked="1"' : '') . " name='app_". $app ."'>");
|
||||
echo(" </td>");
|
||||
echo(" <td>". ucfirst($app) . "</td>");
|
||||
echo(" </tr>
|
||||
");
|
||||
echo " <tr bgcolor=$row_colour>";
|
||||
echo ' <td>';
|
||||
echo ' <input type=checkbox'.(in_array($app, $app_enabled) ? ' checked="1"' : '')." name='app_".$app."'>";
|
||||
echo ' </td>';
|
||||
echo ' <td>'.ucfirst($app).'</td>';
|
||||
echo ' </tr>
|
||||
';
|
||||
|
||||
$row++;
|
||||
$row++;
|
||||
}
|
||||
|
||||
echo('<tr>
|
||||
<td>
|
||||
echo '<tr>
|
||||
<td>
|
||||
<button type="submit" class="btn btn-default" value="Save">Save</button>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>');
|
||||
echo('</table>');
|
||||
echo('</form>');
|
||||
echo('</div>');
|
||||
echo('</div>');
|
||||
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>';
|
||||
echo '</table>';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
Reference in New Issue
Block a user