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:
Tom Laermans
2011-03-25 11:45:05 +00:00
parent b6418c4231
commit 33e5fe2b4d
4 changed files with 94 additions and 119 deletions

View File

@@ -1,102 +1,108 @@
<?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;">');
if($_POST['addapp']) {
if($_SESSION['userlevel'] == '10') {
include("includes/app-add.inc.php");
if (mysql_result(mysql_query("SELECT COUNT(*) from `applications` WHERE `device_id` = '".$device['device_id']."'"), 0) > '0')
{
$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']) {
if($_SESSION['userlevel'] == '10') {
include("includes/app-delete.inc.php");
}
}
if ($handle = opendir($config['install_dir'] . "/includes/polling/applications/")) {
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>
echo("<div style='float: left; width: 100%'>
<form id='appedit' name='appedit' method='post' action=''>
<input type=hidden name=device value='".$device['device_id']."'>
<table cellpadding=3 cellspacing=0 width=100%>
<tr align=center>
<th width=100>Enable</th>
<th align=left>Application</th>
</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("
<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('<tr><td></td><td><input type="submit" value="Save"></td></tr>');
echo('</table>');
echo('</form>');
echo('</div>');
echo('</div>');
?>
?>