1<?php
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19**/
20
21
22/**
23 * @var CView $this
24 */
25
26$table = new CTableInfo();
27
28if ($data['error'] != null) {
29	$table->setNoDataMessage($data['error']);
30}
31else {
32	$table_header = [(new CColHeader(_('Timestamp')))->addClass(ZBX_STYLE_CELL_WIDTH)];
33	$names_at_top = ($data['style'] == STYLE_TOP && count($data['items']) > 1);
34
35	if ($names_at_top) {
36		$table->makeVerticalRotation();
37
38		foreach ($data['items'] as $item) {
39			$table_header[] = (new CColHeader(
40				($data['same_host'] ? '' : $item['hosts'][0]['name'].NAME_DELIMITER).$item['name_expanded']
41			))
42				->addClass('vertical_rotation')
43				->setTitle($item['name_expanded']);
44		}
45	}
46	else {
47		if ($data['style'] == STYLE_LEFT) {
48			$table_header[] = _('Name');
49		}
50		$table_header[] = _('Value');
51	}
52	$table->setHeader($table_header);
53
54	$clock = 0;
55	$row_values = [];
56
57	do {
58		$history_item = array_shift($data['histories']);
59
60		if ($history_item !== null && !$names_at_top) {
61			$table_row = [
62				(new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $history_item['clock'])))->addClass(ZBX_STYLE_NOWRAP)
63			];
64			if ($data['style'] == STYLE_LEFT) {
65				$table->setHeadingColumn(1);
66				$table_row[] = ($data['same_host']
67					? ''
68					: $data['items'][$history_item['itemid']]['hosts'][0]['name'].NAME_DELIMITER).
69					$data['items'][$history_item['itemid']]['name_expanded'];
70			}
71			$table_row[] = $history_item['value'];
72			$table->addRow($table_row);
73		}
74		else {
75			if (($history_item === null && $row_values)
76					|| $history_item !== null
77					&& (($clock != 0 && $history_item['clock'] != $clock)
78						|| array_key_exists($history_item['itemid'], $row_values))) {
79				$table_row = [
80					(new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $clock)))->addClass(ZBX_STYLE_NOWRAP)
81				];
82				foreach ($data['items'] as $item) {
83					$table_row[] = array_key_exists($item['itemid'], $row_values)
84						? $row_values[$item['itemid']]
85						: '';
86				}
87				$table->addRow($table_row);
88				$row_values = [];
89			}
90
91			if ($history_item !== null) {
92				$clock = $history_item['clock'];
93				$row_values[$history_item['itemid']] = $history_item['value'];
94			}
95		}
96	} while ($history_item !== null && $table->getNumRows() < $data['show_lines']);
97}
98
99$output = [
100	'name' => $data['name'],
101	'body' => $table->toString()
102];
103
104if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
105	CProfiler::getInstance()->stop();
106	$output['debug'] = CProfiler::getInstance()->make()->toString();
107}
108
109echo json_encode($output);
110