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
22require_once dirname(__FILE__).'/include/config.inc.php';
23require_once dirname(__FILE__).'/include/hosts.inc.php';
24require_once dirname(__FILE__).'/include/httptest.inc.php';
25require_once dirname(__FILE__).'/include/forms.inc.php';
26
27$page['title'] = _('Details of web scenario');
28$page['file'] = 'httpdetails.php';
29$page['scripts'] = ['class.calendar.js', 'gtlc.js', 'flickerfreescreen.js', 'layout.mode.js'];
30$page['type'] = detect_page_type(PAGE_TYPE_HTML);
31
32CView::$has_web_layout_mode = true;
33$page['web_layout_mode'] = CView::getLayoutMode();
34
35require_once dirname(__FILE__).'/include/page_header.php';
36
37// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
38$fields = [
39	'from' =>		[T_ZBX_RANGE_TIME,	O_OPT, P_SYS,	null,		null],
40	'to' =>			[T_ZBX_RANGE_TIME,	O_OPT, P_SYS,	null,		null],
41	'reset' =>		[T_ZBX_STR,			O_OPT, P_SYS|P_ACT, null,	null],
42	'httptestid' =>	[T_ZBX_INT,			O_MAND, P_SYS,	DB_ID,		null]
43];
44check_fields($fields);
45validateTimeSelectorPeriod(getRequest('from'), getRequest('to'));
46
47if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
48	require_once dirname(__FILE__).'/include/page_footer.php';
49	exit;
50}
51
52/*
53 * Collect data
54 */
55$httptest = API::HttpTest()->get([
56	'output' => ['httptestid', 'name', 'hostid'],
57	'httptestids' => getRequest('httptestid'),
58	'preservekeys' => true
59]);
60$httptest = reset($httptest);
61if (!$httptest) {
62	access_deny();
63}
64
65$timeselector_options = [
66	'profileIdx' => 'web.httpdetails.filter',
67	'profileIdx2' => $httptest['httptestid'],
68	'from' => getRequest('from'),
69	'to' => getRequest('to')
70];
71updateTimeSelectorPeriod($timeselector_options);
72
73$timeline = getTimeSelectorPeriod($timeselector_options);
74
75$http_test_name = CMacrosResolverHelper::resolveHttpTestName($httptest['hostid'], $httptest['name']);
76
77// Create details widget.
78$details_screen = CScreenBuilder::getScreen([
79	'resourcetype' => SCREEN_RESOURCE_HTTPTEST_DETAILS,
80	'mode' => SCREEN_MODE_JS,
81	'dataId' => 'httptest_details'
82] + $timeline);
83
84(new CWidget())
85	->setTitle(_('Details of web scenario').': '.$http_test_name)
86	->setWebLayoutMode($page['web_layout_mode'])
87	->setControls((new CTag('nav', true,
88		(new CForm())
89			->cleanItems()
90			->addItem((new CList())->addItem(get_icon('fullscreen')))
91		))
92			->setAttribute('aria-label', _('Content controls'))
93	)
94	->addItem($details_screen->get())
95	->show();
96
97echo BR();
98
99$graphs = [];
100
101// dims
102$graph_dims = getGraphDims();
103$graph_dims['width'] = -50;
104$graph_dims['graphHeight'] = 151;
105
106/*
107 * Graph in
108 */
109$graph_in = new CScreenBase([
110	'resourcetype' => SCREEN_RESOURCE_GRAPH,
111	'mode' => SCREEN_MODE_PREVIEW,
112	'dataId' => 'graph_in'
113] + $timeline);
114
115$items = DBfetchArray(DBselect(
116	'SELECT i.itemid,i.value_type,i.history,i.trends,i.hostid'.
117	' FROM items i,httpstepitem hi,httpstep hs'.
118	' WHERE i.itemid=hi.itemid'.
119		' AND hi.httpstepid=hs.httpstepid'.
120		' AND hs.httptestid='.zbx_dbstr($httptest['httptestid'])
121));
122
123$url = (new CUrl('chart3.php'))
124	->setArgument('height', 150)
125	->setArgument('name', $http_test_name.': '._('Speed'))
126	->setArgument('http_item_type', HTTPSTEP_ITEM_TYPE_IN)
127	->setArgument('httptestid', $httptest['httptestid'])
128	->setArgument('graphtype', GRAPH_TYPE_STACKED)
129	->setArgument('from', $graph_in->timeline['from'])
130	->setArgument('to', $graph_in->timeline['to'])
131	->setArgument('profileIdx', $graph_in->profileIdx)
132	->setArgument('profileIdx2', $graph_in->profileIdx2)
133	->getUrl();
134
135$graphs[] = (new CDiv((new CDiv())
136		->setId('graph_in_container')
137		->addClass(ZBX_STYLE_CENTER)
138	))
139	->addClass('flickerfreescreen')
140	->setId('flickerfreescreen_graph_in')
141	->setAttribute('data-timestamp', time());
142
143$time_control_data = [
144	'id' => 'graph_in',
145	'containerid' => 'graph_in_container',
146	'src' => $url,
147	'objDims' => $graph_dims,
148	'loadSBox' => 1,
149	'loadImage' => 1
150];
151zbx_add_post_js('timeControl.addObject("graph_in", '.zbx_jsvalue($graph_in->timeline).', '.
152	zbx_jsvalue($time_control_data).');'
153);
154$graph_in->insertFlickerfreeJs();
155
156/*
157 * Graph time
158 */
159$graph_time = new CScreenBase([
160	'resourcetype' => SCREEN_RESOURCE_GRAPH,
161	'mode' => SCREEN_MODE_PREVIEW,
162	'dataId' => 'graph_time'
163] + $timeline);
164
165$url = (new CUrl('chart3.php'))
166	->setArgument('height', 150)
167	->setArgument('name', $http_test_name.': '._('Response time'))
168	->setArgument('http_item_type', HTTPSTEP_ITEM_TYPE_TIME)
169	->setArgument('httptestid', $httptest['httptestid'])
170	->setArgument('graphtype', GRAPH_TYPE_STACKED)
171	->setArgument('from', $graph_time->timeline['from'])
172	->setArgument('to', $graph_time->timeline['to'])
173	->setArgument('profileIdx', $graph_time->profileIdx)
174	->setArgument('profileIdx2', $graph_time->profileIdx2)
175	->getUrl();
176
177$graphs[] = (new CDiv(((new CDiv())
178		->setId('graph_time_container')
179		->addClass(ZBX_STYLE_CENTER)
180	)))
181	->addClass('flickerfreescreen')
182	->setId('flickerfreescreen_graph_time')
183	->setAttribute('data-timestamp', time());
184
185$time_control_data = [
186	'id' => 'graph_time',
187	'containerid' => 'graph_time_container',
188	'src' => $url,
189	'objDims' => $graph_dims,
190	'loadSBox' => 1,
191	'loadImage' => 1
192];
193zbx_add_post_js('timeControl.addObject("graph_time", '.zbx_jsvalue($graph_in->timeline).', '.
194	zbx_jsvalue($time_control_data).');'
195);
196$graph_time->insertFlickerfreeJs();
197
198// scroll
199CScreenBuilder::insertScreenStandardJs($graph_in->timeline);
200
201// Create graphs widget.
202$widget = (new CWidget())
203	->setWebLayoutMode($page['web_layout_mode'])
204	->addItem(
205		(new CFilter(new CUrl()))
206			->setProfile($timeline['profileIdx'], $timeline['profileIdx2'])
207			->setActiveTab(CProfile::get($timeline['profileIdx'].'.active', 1))
208			->addTimeSelector($timeline['from'], $timeline['to'], $page['web_layout_mode'] != ZBX_LAYOUT_KIOSKMODE)
209	)
210	->addItem((new CDiv($graphs))->addClass(ZBX_STYLE_TABLE_FORMS_CONTAINER))
211	->show();
212
213require_once dirname(__FILE__).'/include/page_footer.php';
214