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
22class CMenuPopupHelper {
23
24	/**
25	 * Prepare data for dashboard popup menu.
26	 *
27	 * @param string $dashboardid
28	 */
29	public static function getDashboard($dashboardid) {
30		return [
31			'type' => 'dashboard',
32			'data' => [
33				'dashboardid' => $dashboardid
34			]
35		];
36	}
37
38	/**
39	 * Prepare data for item history menu popup.
40	 *
41	 * @param string $itemid
42	 *
43	 * @return array
44	 */
45	public static function getHistory($itemid) {
46		return [
47			'type' => 'history',
48			'data' => [
49				'itemid' => $itemid
50			]
51		];
52	}
53
54	/**
55	 * Prepare data for Ajax host menu popup.
56	 *
57	 * @param string $hostid
58	 * @param bool   $has_goto     Show "Go to" block in popup.
59	 *
60	 * @return array
61	 */
62	public static function getHost($hostid, $has_goto = true) {
63		$data = [
64			'type' => 'host',
65			'data' => [
66				'hostid' => $hostid
67			]
68		];
69
70		if ($has_goto === false) {
71			$data['data']['has_goto'] = '0';
72		}
73
74		return $data;
75	}
76
77	/**
78	 * Prepare data for Ajax map element menu popup.
79	 *
80	 * @param string $sysmapid                   Map ID.
81	 * @param array  $selement                   Map element data (ID, type, URLs, etc...).
82	 * @param string $selement[selementid_orig]  Map element ID.
83	 * @param string $selement[elementtype]      Map element type (host, map, trigger, host group, image).
84	 * @param string $selement[urls]             Map element URLs.
85	 * @param int    $severity_min               Minimum severity.
86	 * @param string $hostid                     Host ID.
87	 *
88	 * @return array
89	 */
90	public static function getMapElement($sysmapid, $selement, $severity_min, $hostid) {
91		$data = [
92			'type' => 'map_element',
93			'data' => [
94				'sysmapid' => $sysmapid,
95				'selementid' => $selement['selementid_orig'],
96				'elementtype' => $selement['elementtype'],
97				'urls' => $selement['urls']
98			]
99		];
100
101		if ($severity_min != TRIGGER_SEVERITY_NOT_CLASSIFIED) {
102			$data['data']['severity_min'] = $severity_min;
103		}
104		if ($hostid != 0) {
105			$data['data']['hostid'] = $hostid;
106		}
107
108		return $data;
109	}
110
111	/**
112	 * Prepare data for refresh time menu popup.
113	 *
114	 * @param string $widgetName
115	 * @param string $currentRate
116	 * @param bool   $multiplier   Multiplier or time mode.
117	 * @param array  $params       (optional) URL parameters.
118	 *
119	 * @return array
120	 */
121	public static function getRefresh($widgetName, $currentRate, $multiplier = false, array $params = []) {
122		$data = [
123			'type' => 'refresh',
124			'data' => [
125				'widgetName' => $widgetName,
126				'currentRate' => $currentRate,
127				'multiplier' => $multiplier ? '1' : '0'
128			]
129		];
130
131		if ($params) {
132			$data['data']['params'] = $params;
133		}
134
135		return $data;
136	}
137
138	/**
139	 * Prepare data for Ajax trigger menu popup.
140	 *
141	 * @param string $triggerid
142	 * @param string $eventid                 (optional) Mandatory for Acknowledge and Description menus.
143	 * @param array  $acknowledge             Acknowledge link parameters (optional).
144	 * @param string $acknowledge['backurl']
145	 * @param bool   $show_description
146	 *
147	 * @return array
148	 */
149	public static function getTrigger($triggerid, $eventid = 0, array $acknowledge = [], $show_description = true) {
150		$data = [
151			'type' => 'trigger',
152			'data' => [
153				'triggerid' => $triggerid
154			]
155		];
156
157		if ($eventid != 0) {
158			$data['data']['eventid'] = $eventid;
159		}
160
161		if ($acknowledge) {
162			$data['data']['acknowledge'] = $acknowledge;
163		}
164
165		if ($show_description === false) {
166			$data['data']['show_description'] = '0';
167		}
168
169		return $data;
170	}
171
172	/**
173	 * Prepare data for trigger macro menu popup.
174	 *
175	 * @return array
176	 */
177	public static function getTriggerMacro() {
178		return [
179			'type' => 'trigger_macro'
180		];
181	}
182
183	/**
184	 * Prepare data for item popup menu.
185	 *
186	 * @param string $itemid
187	 *
188	 * @return array
189	 */
190	public static function getItem($itemid) {
191		return [
192			'type' => 'item',
193			'data' => [
194				'itemid' => $itemid
195			]
196		];
197	}
198
199	/**
200	 * Prepare data for item prototype popup menu.
201	 *
202	 * @param string $itemid
203	 */
204	public static function getItemPrototype($itemid) {
205		return [
206			'type' => 'item_prototype',
207			'data' => [
208				'itemid' => $itemid
209			]
210		];
211	}
212}
213