Files
librenms-librenms/html/pages/device/edit/apps.inc.php

102 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2015-07-13 20:10:26 +02:00
// 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);
}
}
2015-07-13 20:10:26 +02:00
closedir($handle);
}
2015-07-13 20:10:26 +02:00
// 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[] = '?';
}
}
2015-07-13 20:10:26 +02:00
if (count($enabled)) {
$updated += dbDelete('applications', '`device_id` = ? AND `app_type` NOT IN ('.implode(',', $replace).')', $param);
}
else {
$updated += dbDelete('applications', '`device_id` = ?', array($param));
}
2015-07-13 20:10:26 +02:00
foreach (dbFetchRows('SELECT `app_type` FROM `applications` WHERE `device_id` = ?', array($device['device_id'])) as $row) {
$app_in_db[] = $row['app_type'];
}
2015-07-13 20:10:26 +02:00
foreach ($enabled as $app) {
if (!in_array($app, $app_in_db)) {
$updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications');
}
}
2015-07-13 20:10:26 +02:00
if ($updated) {
print_message('Applications updated!');
}
else {
print_message('No changes.');
}
}//end if
2015-07-13 20:10:26 +02:00
// Show list of apps with checkboxes
echo '<div style="padding: 10px;">';
2015-07-13 20:10:26 +02:00
$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'>
2015-07-13 20:10:26 +02:00
<form id='appedit' name='appedit' method='post' action='' role='form' class='form-horizontal'>
<input type=hidden name=device value='".$device['device_id']."'>
2015-09-21 01:30:23 +05:30
<table class='table table-hover table-responsive'>
<tr align=center>
2015-07-13 20:10:26 +02:00
<th>Enable</th>
<th>Application</th>
</tr>
2015-07-13 20:10:26 +02:00
";
$row = 1;
2015-07-13 20:10:26 +02:00
foreach ($applications as $app) {
if (is_integer($row / 2)) {
$row_colour = $list_colour_a;
}
else {
$row_colour = $list_colour_b;
}
2015-07-13 20:10:26 +02:00
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>
';
2015-07-13 20:10:26 +02:00
$row++;
}
2015-07-13 20:10:26 +02:00
echo '</table>';
echo '<div class="row">
<div class="col-md-1">
<button type="submit" name="Submit" class="btn btn-default"><i class="fa fa-check"></i> Save</button>
</div>
</div>
';
2015-07-13 20:10:26 +02:00
echo '</form>';
echo '</div>';
2015-09-21 01:30:23 +05:30
echo '</div>';