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 menu.
143	 * @param bool   $acknowledge  (optional) Whether to show Acknowledge menu.
144	 *
145	 * @return array
146	 */
147	public static function getTrigger($triggerid, $eventid = 0, $acknowledge = false) {
148		$data = [
149			'type' => 'trigger',
150			'data' => [
151				'triggerid' => $triggerid
152			]
153		];
154
155		if ($eventid != 0) {
156			$data['data']['eventid'] = $eventid;
157			$data['data']['acknowledge'] = $acknowledge ? '1' : '0';
158		}
159
160		return $data;
161	}
162
163	/**
164	 * Prepare data for trigger macro menu popup.
165	 *
166	 * @return array
167	 */
168	public static function getTriggerMacro() {
169		return [
170			'type' => 'trigger_macro'
171		];
172	}
173
174	/**
175	 * Prepare data for item popup menu.
176	 *
177	 * @param string $itemid
178	 *
179	 * @return array
180	 */
181	public static function getItem($itemid) {
182		return [
183			'type' => 'item',
184			'data' => [
185				'itemid' => $itemid
186			]
187		];
188	}
189
190	/**
191	 * Prepare data for item prototype popup menu.
192	 *
193	 * @param string $itemid
194	 */
195	public static function getItemPrototype($itemid) {
196		return [
197			'type' => 'item_prototype',
198			'data' => [
199				'itemid' => $itemid
200			]
201		];
202	}
203}
204