mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
sensible application edit page
git-svn-id: http://www.observium.org/svn/observer/trunk@1972 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$updated = '1';
|
|
||||||
|
|
||||||
$sql = "INSERT INTO `applications` (`device_id`, `app_type`)
|
|
||||||
VALUES ('" . mres($_POST['device']). "','" . mres($_POST['type']) . "')";
|
|
||||||
|
|
||||||
$query = mysql_query($sql);
|
|
||||||
$affected = mysql_affected_rows() . "records affected";
|
|
||||||
|
|
||||||
$message .= $message_break . "application added!";
|
|
||||||
$message_break .= "<br />"
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$updated = '1';
|
|
||||||
|
|
||||||
$sql = "DELETE FROM `applications` WHERE app_id = '" . mres($_POST['app']). "'";
|
|
||||||
|
|
||||||
$query = mysql_query($sql);
|
|
||||||
$rows = mysql_affected_rows();
|
|
||||||
$affected = $rows . " records affected";
|
|
||||||
|
|
||||||
$message .= $message_break . $rows . " application deleted!";
|
|
||||||
$message_break .= "<br />"
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,102 +1,108 @@
|
|||||||
<?php
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the form was POSTed
|
||||||
|
if ($_POST['device'])
|
||||||
|
{
|
||||||
|
$updated = 0;
|
||||||
|
|
||||||
|
foreach (array_keys($_POST) as $key)
|
||||||
|
{
|
||||||
|
if (substr($key,0,4) == 'app_')
|
||||||
|
{
|
||||||
|
$enabled[] = "'" . substr($key,4) . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM applications WHERE device_id=" . $device['device_id'];
|
||||||
|
if ($enabled)
|
||||||
|
{
|
||||||
|
$sql .= " AND app_type NOT IN (" . implode(',',$enabled) . ")";
|
||||||
|
}
|
||||||
|
mysql_query($sql);
|
||||||
|
$updated += mysql_affected_rows();
|
||||||
|
|
||||||
|
$sql = "SELECT app_type FROM applications WHERE device_id=" . $device['device_id'];
|
||||||
|
$result = mysql_query($sql);
|
||||||
|
while ($row = mysql_fetch_assoc($result))
|
||||||
|
{
|
||||||
|
$app_in_db[] = $row['app_type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($enabled as $app)
|
||||||
|
{
|
||||||
|
if (!in_array(trim($app,"'"),$app_in_db))
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO applications (device_id,app_type) VALUES (" . $device['device_id'] . ", " . $app . ")";
|
||||||
|
mysql_query($sql);
|
||||||
|
$updated += mysql_affected_rows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($updated)
|
||||||
|
{
|
||||||
|
print_message("Applications updated!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print_message("No changes.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show list of apps with checkboxes
|
||||||
echo('<div style="padding: 10px;">');
|
echo('<div style="padding: 10px;">');
|
||||||
|
|
||||||
if($_POST['addapp']) {
|
if (mysql_result(mysql_query("SELECT COUNT(*) from `applications` WHERE `device_id` = '".$device['device_id']."'"), 0) > '0')
|
||||||
if($_SESSION['userlevel'] == '10') {
|
{
|
||||||
include("includes/app-add.inc.php");
|
$app_query = mysql_query("select * from applications WHERE device_id = '".$device['device_id']."' ORDER BY app_type");
|
||||||
|
while ($application = mysql_fetch_assoc($app_query))
|
||||||
|
{
|
||||||
|
$app_enabled[] = $application['app_type'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($_POST['delapp']) {
|
echo("<div style='float: left; width: 100%'>
|
||||||
if($_SESSION['userlevel'] == '10') {
|
<form id='appedit' name='appedit' method='post' action=''>
|
||||||
include("includes/app-delete.inc.php");
|
<input type=hidden name=device value='".$device['device_id']."'>
|
||||||
}
|
<table cellpadding=3 cellspacing=0 width=100%>
|
||||||
}
|
<tr align=center>
|
||||||
|
<th width=100>Enable</th>
|
||||||
if ($handle = opendir($config['install_dir'] . "/includes/polling/applications/")) {
|
<th align=left>Application</th>
|
||||||
while (false !== ($file = readdir($handle))) {
|
|
||||||
if ($file != "." && $file != ".." && strstr($file, ".inc.php")) {
|
|
||||||
$file = str_replace(".inc.php", "", $file);
|
|
||||||
$applicationsform .= "<option value='$file'>$file</option>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = mysql_query("SELECT * FROM `devices` ORDER BY `hostname`");
|
|
||||||
while($device = mysql_fetch_array($query)) {
|
|
||||||
$devicesform .= "<option value='" . $device['device_id'] . "'>" . $device['hostname'] . "</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
if($updated) { print_message("Applications Updated"); }
|
|
||||||
|
|
||||||
if(mysql_result(mysql_query("SELECT COUNT(*) from `applications` WHERE `device_id` = '".$device['device_id']."'"), 0) > '0') {
|
|
||||||
$i = "1";
|
|
||||||
$app_query = mysql_query("select * from applications WHERE device_id = '".$device['device_id']."' ORDER BY app_type");
|
|
||||||
while($application = mysql_fetch_array($app_query)) {
|
|
||||||
$existform .= "<option value='" . $application['app_id'] . "'>" . $application['app_type'] . "</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if($existform){
|
|
||||||
echo('<div style="float: left;">');
|
|
||||||
echo("
|
|
||||||
|
|
||||||
<h1>Remove application</h1>
|
|
||||||
|
|
||||||
<form id='delapp' name='delapp' method='post' action=''>
|
|
||||||
<input type=hidden name='delapp' value='yes'>
|
|
||||||
<table width='200' border='0'>
|
|
||||||
<option type=hidden name=device value='".$device['device_id']."'>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Type
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select name='app'>
|
|
||||||
$existform
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
");
|
||||||
<input type='submit' name='Submit' value='Delete' />
|
|
||||||
<label><br />
|
|
||||||
</label>
|
|
||||||
</form>");
|
|
||||||
|
|
||||||
|
$row = 1;
|
||||||
|
|
||||||
echo('</div>');
|
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 align=center>");
|
||||||
|
echo(" <input type=checkbox" . (in_array($app,$app_enabled) ? ' checked="1"' : '') . " name='app_". $app ."'>");
|
||||||
|
echo(" </td>");
|
||||||
|
echo(" <td align=left>". ucfirst($app) . "</td>");
|
||||||
|
echo(" </tr>
|
||||||
|
");
|
||||||
|
|
||||||
|
$row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo('<div style="width: 45%; float: right;">');
|
echo('<tr><td></td><td><input type="submit" value="Save"></td></tr>');
|
||||||
|
echo('</table>');
|
||||||
echo("
|
echo('</form>');
|
||||||
<h1>Add application</h1>
|
|
||||||
|
|
||||||
<form id='addapp' name='addapp' method='post' action=''>
|
|
||||||
<input type=hidden name='addapp' value='yes'>
|
|
||||||
<table width='200' border='0'>
|
|
||||||
<option type=hidden name=device value='".$device['device_id']."'>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
Type
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select name='type'>
|
|
||||||
$applicationsform
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<input type='submit' name='Submit' value='Add' />
|
|
||||||
<label><br />
|
|
||||||
</label>
|
|
||||||
</form>");
|
|
||||||
|
|
||||||
echo('</div>');
|
echo('</div>');
|
||||||
|
|
||||||
echo('</div>');
|
?>
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -8,7 +8,6 @@ if ($_POST['editing'])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device['device_id']."'"));
|
|
||||||
$descr = $device['purpose'];
|
$descr = $device['purpose'];
|
||||||
|
|
||||||
if ($updated && $update_message)
|
if ($updated && $update_message)
|
||||||
|
|||||||
Reference in New Issue
Block a user