Commit version 24.12.13800
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
@ -15,122 +15,119 @@ print_warning("This page allows you to disable applications for this device that
|
||||
|
||||
# Check if the form was POSTed
|
||||
if ($vars['device']) {
|
||||
if ($readonly) {
|
||||
print_error_permission('You have insufficient permissions to edit settings.');
|
||||
} else {
|
||||
$updated = 0;
|
||||
$param[] = $device['device_id'];
|
||||
$enabled = [];
|
||||
foreach (array_keys($vars) as $key) {
|
||||
if (str_starts($key, '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);
|
||||
if ($readonly) {
|
||||
print_error_permission('You have insufficient permissions to edit settings.');
|
||||
} else {
|
||||
$updated += dbDelete('applications', "`device_id` = ?", array($param));
|
||||
}
|
||||
$updated = 0;
|
||||
$param[] = $device['device_id'];
|
||||
$enabled = [];
|
||||
foreach (array_keys($vars) as $key) {
|
||||
if (str_starts($key, 'app_')) {
|
||||
$param[] = substr($key, 4);
|
||||
$enabled[] = substr($key, 4);
|
||||
$replace[] = "?";
|
||||
}
|
||||
}
|
||||
|
||||
foreach (dbFetchRows( "SELECT `app_type` FROM `applications` WHERE `device_id` = ?", array($device['device_id'])) as $row) {
|
||||
$app_in_db[] = $row['app_type'];
|
||||
}
|
||||
if (count($enabled)) {
|
||||
$updated += dbDelete('applications', "`device_id` = ? AND `app_type` NOT IN (" . implode(",", $replace) . ")", $param);
|
||||
} else {
|
||||
$updated += dbDelete('applications', "`device_id` = ?", [$param]);
|
||||
}
|
||||
|
||||
foreach ($enabled as $app) {
|
||||
if (!in_array($app, $app_in_db)) {
|
||||
$updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications');
|
||||
}
|
||||
}
|
||||
foreach (dbFetchRows("SELECT `app_type` FROM `applications` WHERE `device_id` = ?", [$device['device_id']]) as $row) {
|
||||
$app_in_db[] = $row['app_type'];
|
||||
}
|
||||
|
||||
if ($updated) {
|
||||
print_message("Applications updated!");
|
||||
} else {
|
||||
print_message("No changes.");
|
||||
foreach ($enabled as $app) {
|
||||
if (!in_array($app, $app_in_db)) {
|
||||
$updated += dbInsert(['device_id' => $device['device_id'], 'app_type' => $app], 'applications');
|
||||
}
|
||||
}
|
||||
|
||||
if ($updated) {
|
||||
print_message("Applications updated!");
|
||||
} else {
|
||||
print_message("No changes.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Show list of apps with checkboxes
|
||||
|
||||
$apps_enabled = dbFetchRows("SELECT * from `applications` WHERE `device_id` = ? ORDER BY app_type", array($device['device_id']));
|
||||
$apps_enabled = dbFetchRows("SELECT * from `applications` WHERE `device_id` = ? ORDER BY app_type", [ $device['device_id'] ]);
|
||||
if (safe_count($apps_enabled)) {
|
||||
foreach ($apps_enabled as $application)
|
||||
{
|
||||
$app_enabled[] = $application['app_type'];
|
||||
}
|
||||
?>
|
||||
|
||||
<form id="appedit" name="appedit" method="post" action="" class="form-inline">
|
||||
<input type="hidden" name="device" value="<?php echo $device['device_id'];?>">
|
||||
|
||||
<?php echo generate_box_open(array('title' => 'Applications', 'header-border' => TRUE)); ?>
|
||||
|
||||
<table class="table table-striped table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 100px;">Enable</th>
|
||||
<th>Application</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?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);
|
||||
$app_enabled = [];
|
||||
foreach ($apps_enabled as $application) {
|
||||
$app_enabled[] = $application['app_type'];
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
?>
|
||||
|
||||
foreach ($applications as $app) {
|
||||
if (in_array($app, $app_enabled)) {
|
||||
echo(" <tr>");
|
||||
//echo(" <td>");
|
||||
$item = array(
|
||||
'id' => 'app_' . $app,
|
||||
'type' => 'switch-ng',
|
||||
'off-text' => 'Yes',
|
||||
'off-color' => 'success',
|
||||
'on-color' => 'danger',
|
||||
'on-text' => 'No',
|
||||
'size' => 'mini',
|
||||
//'height' => '15px',
|
||||
//'title' => 'Show/Hide Removed',
|
||||
//'placeholder' => 'Removed',
|
||||
'readonly' => $readonly,
|
||||
//'disabled' => TRUE,
|
||||
//'submit_by_key' => TRUE,
|
||||
'value' => 1
|
||||
);
|
||||
echo('<td class="text-center">'.generate_form_element($item).'</td>');
|
||||
//echo(" </td>");
|
||||
echo(" <td>". nicecase($app) . "</td>");
|
||||
echo(" </tr>");
|
||||
<form id="appedit" name="appedit" method="post" action="" class="form-inline">
|
||||
<input type="hidden" name="device" value="<?php echo $device['device_id']; ?>">
|
||||
|
||||
$row++;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php echo generate_box_open(['title' => 'Applications', 'header-border' => TRUE]); ?>
|
||||
|
||||
<div class="box-footer">
|
||||
<button type="submit" class="btn btn-primary pull-right" name="submit" value="save"><i class="icon-ok icon-white"></i> Save Changes</button>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-striped table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 100px;">Enable</th>
|
||||
<th>Application</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</form>
|
||||
<?php
|
||||
<?php
|
||||
|
||||
# Load our list of available applications
|
||||
$applications = [];
|
||||
foreach (get_recursive_directory_iterator($config['install_dir'] . "/includes/polling/applications/") as $file => $info) {
|
||||
if (!str_ends_with($info->getFilename(), '.inc.php')) { continue; }
|
||||
$applications[] = str_replace(".inc.php", "", $info->getFilename());
|
||||
|
||||
}
|
||||
//r($applications);
|
||||
|
||||
foreach ($applications as $app) {
|
||||
if (in_array($app, $app_enabled)) {
|
||||
echo(" <tr>");
|
||||
//echo(" <td>");
|
||||
$item = [
|
||||
'id' => 'app_' . $app,
|
||||
'type' => 'switch-ng',
|
||||
'off-text' => 'Yes',
|
||||
'off-color' => 'success',
|
||||
'on-color' => 'danger',
|
||||
'on-text' => 'No',
|
||||
'size' => 'mini',
|
||||
//'height' => '15px',
|
||||
//'title' => 'Show/Hide Removed',
|
||||
//'placeholder' => 'Removed',
|
||||
'readonly' => $readonly,
|
||||
//'disabled' => TRUE,
|
||||
//'submit_by_key' => TRUE,
|
||||
'value' => 1
|
||||
];
|
||||
echo('<td class="text-center">' . generate_form_element($item) . '</td>');
|
||||
//echo(" </td>");
|
||||
echo(" <td>" . nicecase($app) . "</td>");
|
||||
echo(" </tr>");
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="box-footer">
|
||||
<button type="submit" class="btn btn-primary pull-right" name="submit" value="save"><i class="icon-ok icon-white"></i> Save Changes</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
print_error("No applications found on this device.");
|
||||
print_error("No applications found on this device.");
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
Reference in New Issue
Block a user