From b7720135e982272d3e8b68eb5d6d706f90a28017 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Thu, 31 Mar 2011 17:19:54 +0000 Subject: [PATCH] small cleanups etc, plus allow sysLocation override git-svn-id: http://www.observium.org/svn/observer/trunk@2000 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/includes/functions.inc.php | 46 ++++++- html/includes/hostbox.inc.php | 75 +++++++----- html/includes/print-menubar.php | 70 +++++------ html/pages/device.inc.php | 170 +++++++++++++------------- html/pages/device/edit/alerts.inc.php | 4 + html/pages/device/edit/device.inc.php | 86 +++++++------ html/pages/device/edit/ipmi.inc.php | 4 + html/pages/devices.inc.php | 126 +++++++++---------- html/pages/locations.inc.php | 34 ++---- includes/common.php | 40 ++++++ includes/functions.php | 39 +----- poller.php | 7 +- 12 files changed, 382 insertions(+), 319 deletions(-) diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 29dd78286..fe27969ec 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -124,7 +124,7 @@ function permissions_cache($user_id) function bill_permitted($bill_id) { - global $_SESSION, $permissions; + global $permissions; if ($_SESSION['userlevel'] >= "5") { $allowed = TRUE; @@ -139,7 +139,7 @@ function bill_permitted($bill_id) function port_permitted($interface_id, $device_id = NULL) { - global $_SESSION, $permissions; + global $permissions; if (!is_numeric($device_id)) { $device_id = get_device_id_by_interface_id($interface_id); } @@ -159,7 +159,7 @@ function port_permitted($interface_id, $device_id = NULL) function application_permitted($app_id, $device_id = NULL) { - global $_SESSION, $permissions; + global $permissions; if (is_numeric($app_id)) { if (!$device_id) { $device_id = device_by_id_cache ($app_id); } @@ -181,7 +181,7 @@ function application_permitted($app_id, $device_id = NULL) function device_permitted($device_id) { - global $_SESSION, $permissions; + global $permissions; if ($_SESSION['userlevel'] >= "5") { @@ -355,4 +355,42 @@ function devclass($device) return $class; } +function getlocations() +{ + # Fetch override locations, not through get_dev_attrib, this would be a huge number of queries + $result = mysql_query("SELECT attrib_type,attrib_value,device_id FROM devices_attribs WHERE attrib_type LIKE 'override_sysLocation%' ORDER BY attrib_type"); + while ($row = mysql_fetch_assoc($result)) + { + if ($row['attrib_type'] == 'override_sysLocation_bool' && $row['attrib_value'] == 1) + { + $ignore_dev_location[$row['device_id']] = 1; + } + # We can do this because of the ORDER BY, "bool" will be handled before "string" + elseif ($row['attrib_type'] == 'override_sysLocation_string' && $ignore_dev_location[$row['device_id']] == 1) + { + if (!in_array($row['location'],$locations)) { $locations[] = $row['attrib_value']; } + } + } + + # Fetch regular locations + if ($_SESSION['userlevel'] >= '5') + { + $result = mysql_query("SELECT D.device_id,location FROM devices AS D GROUP BY location ORDER BY location"); + } else { + $result = mysql_query("SELECT D.device_id,location FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' GROUP BY location ORDER BY location"); + } + + while ($row = mysql_fetch_assoc($result)) + { + # Only add it as a location if it wasn't overridden (and not already there) + if ($row['location'] != '' && !$ignore_dev_location[$row['device_id']]) + { + if (!in_array($row['location'],$locations)) { $locations[] = $row['location']; } + } + } + + sort($locations); + return $locations; +} + ?> \ No newline at end of file diff --git a/html/includes/hostbox.inc.php b/html/includes/hostbox.inc.php index c853b1f3d..67e155203 100644 --- a/html/includes/hostbox.inc.php +++ b/html/includes/hostbox.inc.php @@ -1,43 +1,52 @@ - ' . $image . ' - ' . generate_device_link($device) . ' -
' . $device['sysName'] . ' +echo(' + ' . $image . ' + ' . generate_device_link($device) . ' +
' . $device['sysName'] . ' '); - if ($port_count) { echo(' '.$port_count); } - echo('
'); - if ($sensor_count) { echo(' '.$sensor_count); } +if ($port_count) { echo(' '.$port_count); } +echo('
'); +if ($sensor_count) { echo(' '.$sensor_count); } - echo(' - ' . $device['os_text'] . '
- ' . $device['version'] . ' - ' . $device['hardware'] . '
- ' . $device['features'] . ' - ' . formatUptime($device['uptime']) . ' -
- ' . $device['location'] . ' - - - '); +echo(' + ' . $device['os_text'] . '
+ ' . $device['version'] . ' + ' . $device['hardware'] . '
+ ' . $device['features'] . ' + ' . formatUptime($device['uptime']) . ' +
'); +if (get_dev_attrib($device,'override_sysLocation_bool')) +{ + echo(get_dev_attrib($device,'override_sysLocation_string')); +} +else +{ + echo($device['location']); +} +echo(' + + + '); -?> +?> \ No newline at end of file diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index c52e6150c..abb5e363d 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -1,27 +1,30 @@