1<?php
2
3// Graphs are printed in the order they exist in \LibreNMS\Config::get('graph_types')
4$link_array = [
5    'page'   => 'device',
6    'device' => $device['device_id'],
7    'tab'    => 'graphs',
8];
9
10$bg = '#ffffff';
11
12echo '<div style="clear: both;">';
13
14print_optionbar_start();
15
16echo "<span style='font-weight: bold;'>Graphs</span> &#187; ";
17
18foreach (dbFetchRows('SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph', [$device['device_id']]) as $graph) {
19    $section = \LibreNMS\Config::get("graph_types.device.{$graph['graph']}.section");
20    if ($section != '') {
21        $graph_enable[$section][$graph['graph']] = $graph['graph'];
22    }
23}
24
25$sep = '';
26foreach ($graph_enable as $section => $nothing) {
27    if (isset($graph_enable) && is_array($graph_enable[$section])) {
28        $type = strtolower($section);
29        if (! $vars['group']) {
30            $vars['group'] = $type;
31        }
32
33        echo $sep;
34        if ($vars['group'] == $type) {
35            echo '<span class="pagemenu-selected">';
36        }
37
38        if ($type == 'customoid') {
39            echo generate_link(ucwords('Custom OID'), $link_array, ['group' => $type]);
40        } else {
41            echo generate_link(ucwords($type), $link_array, ['group' => $type]);
42        }
43        if ($vars['group'] == $type) {
44            echo '</span>';
45        }
46
47        $sep = ' | ';
48    }
49}
50
51unset($sep);
52
53print_optionbar_end();
54
55$group = $vars['group'];
56$graph_enable = $graph_enable[$group];
57
58$metric = basename($vars['metric']);
59if (($group != 'customoid') && (is_file("includes/html/pages/device/graphs/$group.inc.php"))) {
60    include "includes/html/pages/device/graphs/$group.inc.php";
61} else {
62    foreach ($graph_enable as $graph => $entry) {
63        $graph_array = [];
64        if ($graph_enable[$graph]) {
65            if ($graph == 'customoid') {
66                foreach (dbFetchRows('SELECT * FROM `customoids` WHERE `device_id` = ? ORDER BY `customoid_descr`', [$device['device_id']]) as $graph_entry) {
67                    $graph_title = \LibreNMS\Config::get("graph_types.device.$graph.descr") . ': ' . $graph_entry['customoid_descr'];
68                    $graph_array['type'] = 'customoid_' . $graph_entry['customoid_descr'];
69                    if (! empty($graph_entry['customoid_unit'])) {
70                        $graph_array['unit'] = $graph_entry['customoid_unit'];
71                    } else {
72                        $graph_array['unit'] = 'value';
73                    }
74                    include 'includes/html/print-device-graph.php';
75                }
76            } else {
77                $graph_title = \LibreNMS\Config::get("graph_types.device.$graph.descr");
78                $graph_array['type'] = 'device_' . $graph;
79                include 'includes/html/print-device-graph.php';
80            }
81        }
82    }
83}
84$pagetitle[] = 'Graphs';
85