From 4e5bd343b52e86f7674a9227de1f0de61e457170 Mon Sep 17 00:00:00 2001 From: crcro Date: Tue, 6 Sep 2016 02:44:55 +0300 Subject: [PATCH] fix #4275 - custom title --- html/includes/common/availability-map.inc.php | 333 +++++++++--------- 1 file changed, 176 insertions(+), 157 deletions(-) diff --git a/html/includes/common/availability-map.inc.php b/html/includes/common/availability-map.inc.php index fefb525830..7a3bf215bd 100644 --- a/html/includes/common/availability-map.inc.php +++ b/html/includes/common/availability-map.inc.php @@ -18,88 +18,106 @@ $select_modes = array( '2' => 'devices and services', ); -require_once 'includes/object-cache.inc.php'; - -$sql = dbFetchRow('SELECT `settings` FROM `users_widgets` WHERE `user_id` = ? AND `widget_id` = ?', array($_SESSION["user_id"], '1')); -$widget_mode = json_decode($sql['settings']); - -if (isset($_SESSION["map_view"])) { - $mode = $_SESSION["map_view"]; +if (defined('SHOW_SETTINGS')) { + $common_output[] = ' +
+
+
+ +
+
+ +
+
+
+
+ +
+
+
'; } else { - $mode = $widget_mode->{'mode'}; -} + require_once 'includes/object-cache.inc.php'; -$host_up_count = 0; -$host_warn_count = 0; -$host_down_count = 0; -$service_up_count = 0; -$service_warn_count = 0; -$service_down_count = 0; + $sql = dbFetchRow('SELECT `settings` FROM `users_widgets` WHERE `user_id` = ? AND `widget_id` = ?', array($_SESSION["user_id"], '1')); + $widget_mode = json_decode($sql['settings']); -if ($config['webui']['availability_map_sort_status'] == 1) { - $deviceOrderBy = 'status'; - $serviceOrderBy = '`S`.`service_status` DESC'; -} else { - $deviceOrderBy = 'hostname'; - $serviceOrderBy = '`D`.`hostname`'; -} - -if ($mode == 0 || $mode == 2) { - // Only show devices if mode is 0 or 2 (Only Devices or both) - if ($config['webui']['availability_map_use_device_groups'] != 0) { - $device_group = 'SELECT `D`.`device_id` FROM `device_group_device` AS `D` WHERE `device_group_id` = ?'; - $param = array($_SESSION['group_view']); - $devices = dbFetchRows($device_group, $param); - foreach ($devices as $in_dev) { - $in_devices[] = $in_dev['device_id']; - } - $in_devices = implode(',', $in_devices); - } - - $sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`os`, `D`.`icon` FROM `devices` AS `D`'; - - if (is_normal_user() === true) { - $sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND'; - $param = array( - $_SESSION['user_id'] - ); + if (isset($_SESSION["map_view"])) { + $mode = $_SESSION["map_view"]; } else { - $sql .= ' WHERE'; + $mode = $widget_mode->{'mode'}; } + $host_up_count = 0; + $host_warn_count = 0; + $host_down_count = 0; + $service_up_count = 0; + $service_warn_count = 0; + $service_down_count = 0; - if ($config['webui']['availability_map_use_device_groups'] != 0 && isset($in_devices)) { - $sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' AND `D`.`device_id` IN (" . $in_devices . ") ORDER BY `" . $deviceOrderBy . "`"; + if ($config['webui']['availability_map_sort_status'] == 1) { + $deviceOrderBy = 'status'; + $serviceOrderBy = '`S`.`service_status` DESC'; } else { - $sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `" . $deviceOrderBy . "`"; + $deviceOrderBy = 'hostname'; + $serviceOrderBy = '`D`.`hostname`'; } - $temp_output = array(); - - foreach (dbFetchRows($sql, $param) as $device) { - if ($device['status'] == '1') { - if (($device['uptime'] < $config['uptime_warning']) && ($device['uptime'] != '0')) { - $deviceState = 'warn'; - $deviceLabel = 'label-warning'; - $deviceLabelOld = 'availability-map-oldview-box-warn'; - $host_warn_count++; - } else { - $deviceState = 'up'; - $deviceLabel = 'label-success'; - $deviceLabelOld = 'availability-map-oldview-box-up'; - $host_up_count++; + if ($mode == 0 || $mode == 2) { + // Only show devices if mode is 0 or 2 (Only Devices or both) + if ($config['webui']['availability_map_use_device_groups'] != 0) { + $device_group = 'SELECT `D`.`device_id` FROM `device_group_device` AS `D` WHERE `device_group_id` = ?'; + $param = array($_SESSION['group_view']); + $devices = dbFetchRows($device_group, $param); + foreach ($devices as $in_dev) { + $in_devices[] = $in_dev['device_id']; } - } else { - $deviceState = 'down'; - $deviceLabel = 'label-danger'; - $deviceLabelOld = 'availability-map-oldview-box-down'; - $host_down_count++; + $in_devices = implode(',', $in_devices); } - if ($config['webui']['availability_map_old'] == 0) { - if ($directpage == "yes") { - $deviceIcon = getImage($device); - $temp_output[] = ' + $sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`os`, `D`.`icon` FROM `devices` AS `D`'; + + if (is_normal_user() === true) { + $sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND'; + $param = array( + $_SESSION['user_id'] + ); + } else { + $sql .= ' WHERE'; + } + + + if ($config['webui']['availability_map_use_device_groups'] != 0 && isset($in_devices)) { + $sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' AND `D`.`device_id` IN (" . $in_devices . ") ORDER BY `" . $deviceOrderBy . "`"; + } else { + $sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `" . $deviceOrderBy . "`"; + } + + $temp_output = array(); + + foreach (dbFetchRows($sql, $param) as $device) { + if ($device['status'] == '1') { + if (($device['uptime'] < $config['uptime_warning']) && ($device['uptime'] != '0')) { + $deviceState = 'warn'; + $deviceLabel = 'label-warning'; + $deviceLabelOld = 'availability-map-oldview-box-warn'; + $host_warn_count++; + } else { + $deviceState = 'up'; + $deviceLabel = 'label-success'; + $deviceLabelOld = 'availability-map-oldview-box-up'; + $host_up_count++; + } + } else { + $deviceState = 'down'; + $deviceLabel = 'label-danger'; + $deviceLabelOld = 'availability-map-oldview-box-down'; + $host_down_count++; + } + + if ($config['webui']['availability_map_old'] == 0) { + if ($directpage == "yes") { + $deviceIcon = getImage($device); + $temp_output[] = '
' . $deviceState . ' @@ -107,44 +125,44 @@ if ($mode == 0 || $mode == 2) { ' . shorthost(ip_to_sysname($device, $device['hostname'])) . '
'; - } else { - $temp_output[] = ' + } else { + $temp_output[] = ' ' . $deviceState . ' '; + } + } else { + $temp_output[] = '
'; } - } else { - $temp_output[] = '
'; } } -} -if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { - $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id` ORDER BY ' . $serviceOrderBy . ';'; - $services = dbFetchRows($service_query); - if (count($services) > 0) { - foreach ($services as $service) { - if ($service['service_status'] == '0') { - $serviceLabel = "label-success"; - $serviceLabelOld = 'availability-map-oldview-box-up'; - $serviceState = "up"; - $service_up_count++; - } elseif ($service['service_status'] == '1') { - $serviceLabel = "label-warning"; - $serviceLabelOld = 'availability-map-oldview-box-warn'; - $serviceState = "warn"; - $service_warn_count++; - } else { - $serviceLabel = "label-danger"; - $serviceLabelOld = 'availability-map-oldview-box-down'; - $serviceState = "down"; - $service_down_count++; - } + if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { + $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id` ORDER BY ' . $serviceOrderBy . ';'; + $services = dbFetchRows($service_query); + if (count($services) > 0) { + foreach ($services as $service) { + if ($service['service_status'] == '0') { + $serviceLabel = "label-success"; + $serviceLabelOld = 'availability-map-oldview-box-up'; + $serviceState = "up"; + $service_up_count++; + } elseif ($service['service_status'] == '1') { + $serviceLabel = "label-warning"; + $serviceLabelOld = 'availability-map-oldview-box-warn'; + $serviceState = "warn"; + $service_warn_count++; + } else { + $serviceLabel = "label-danger"; + $serviceLabelOld = 'availability-map-oldview-box-down'; + $serviceState = "down"; + $service_down_count++; + } - if ($config['webui']['availability_map_old'] == 0) { - if ($directpage == "yes") { - $deviceIcon = getImage($service); - $temp_output[] = ' + if ($config['webui']['availability_map_old'] == 0) { + if ($directpage == "yes") { + $deviceIcon = getImage($service); + $temp_output[] = '
' . $service["service_type"] . ' @@ -153,101 +171,102 @@ if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { ' . shorthost(ip_to_sysname($service, $service['hostname'])) . '
'; - } else { - $temp_output[] = ' + } else { + $temp_output[] = ' ' . $service['service_type'] . ' - ' . $serviceState . ' '; + } + } else { + $temp_output[] = '
'; } - } else { - $temp_output[] = '
'; } + } else { + $temp_output [] = ''; } - } else { - $temp_output [] = ''; } -} -if ($directpage == "yes") { - $temp_header[] = ' + if ($directpage == "yes") { + $temp_header[] = '
Availability map for +
+
'; + + if (($config['webui']['availability_map_use_device_groups'] != 0) && ($mode == 0 || $mode == 2)) { + $sql = 'SELECT `G`.`id`, `G`.`name` FROM `device_groups` AS `G`'; + $dev_groups = dbFetchRows($sql); + + if ($_SESSION['group_view'] == 0) { $selected = 'selected'; } else { $selected = ''; } - $temp_header[] = ''; - } - } - $temp_header[] = - ' -
-
'; - - if (($config['webui']['availability_map_use_device_groups'] != 0) && ($mode == 0 || $mode == 2)) { - $sql = 'SELECT `G`.`id`, `G`.`name` FROM `device_groups` AS `G`'; - $dev_groups = dbFetchRows($sql); - - if ($_SESSION['group_view'] == 0) { - $selected = 'selected'; - } else { - $selected = ''; - } - - $temp_header[] = ' + $temp_header[] = ' Device group '; } - $temp_header[] = ''; } -} -if ($directpage == "yes") { - $deviceClass = 'page-availability-report-host'; - $serviceClass = 'page-availability-report-host'; -} else { - $deviceClass = 'widget-availability-host'; - $serviceClass = 'widget-availability-service'; -} + if ($directpage == "yes") { + $deviceClass = 'page-availability-report-host'; + $serviceClass = 'page-availability-report-host'; + } else { + $deviceClass = 'widget-availability-host'; + $serviceClass = 'widget-availability-service'; + } -if ($mode == 0 || $mode == 2) { - $temp_header[] = ' + if ($mode == 0 || $mode == 2) { + $temp_header[] = '
Total hosts up: ' . $host_up_count . ' warn: ' . $host_warn_count . ' down: ' . $host_down_count . '
'; -} + } -if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { - $temp_header[] = ' + if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { + $temp_header[] = '
Total services up: ' . $service_up_count . ' warn: ' . $service_warn_count . ' down: ' . $service_down_count . '
'; + } + + $temp_header[] = '
'; + $temp_header[] = '
'; + + $common_output = array_merge($temp_header, $temp_output); } - -$temp_header[] = ''; -$temp_header[] = '
'; - -$common_output = array_merge($temp_header, $temp_output);