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';
23
24$page['title'] = _('Resource');
25$page['file'] = 'popup_right.php';
26
27define('ZBX_PAGE_NO_MENU', 1);
28
29require_once dirname(__FILE__).'/include/page_header.php';
30
31//	VAR					TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
32$fields = [
33	'dstfrm' =>		[T_ZBX_STR, O_MAND,P_SYS, NOT_EMPTY,	null],
34	'permission' =>	[T_ZBX_INT, O_MAND,P_SYS, IN(PERM_DENY.','.PERM_READ.','.PERM_READ_WRITE), null]
35];
36check_fields($fields);
37
38$dstfrm = getRequest('dstfrm', 0);
39$permission = getRequest('permission', PERM_DENY);
40
41/*
42 * Display
43 */
44
45// host groups
46$hostGroupForm = (new CForm())->setId('groups_form');
47
48$hostGroupTable = (new CTableInfo())
49	->setHeader([
50		(new CColHeader(
51			(new CCheckBox('all_groups'))->onClick("checkAll('groups_form', 'all_groups', 'groups');")
52		))->addClass(ZBX_STYLE_CELL_WIDTH),
53		_('Name')
54	]);
55
56$hostGroups = API::HostGroup()->get([
57	'output' => ['groupid', 'name']
58]);
59
60order_result($hostGroups, 'name');
61
62$i = 0;
63foreach ($hostGroups as $hostGroup) {
64	$hostGroupTable->addRow([
65		(new CCheckBox('groups['.$i.']', $hostGroup['groupid']))
66			->setAttribute('data-id', $hostGroup['groupid'])
67			->setAttribute('data-name', $hostGroup['name'])
68			->setAttribute('data-permission', $permission),
69		$hostGroup['name']
70	]);
71	$i++;
72}
73
74$hostGroupTable->setFooter(
75	(new CCol(
76		(new CButton('select', _('Select')))->onClick('addGroups("'.$dstfrm.'")')
77	))
78);
79
80$hostGroupForm->addItem($hostGroupTable);
81
82(new CWidget())
83	->setTitle(permission2str($permission))
84	->addItem($hostGroupForm)
85	->show();
86
87?>
88<script type="text/javascript">
89	function addGroups(formName) {
90		var parentDocument = window.opener.document;
91
92		if (!parentDocument) {
93			return close_window();
94		}
95
96		jQuery('#groups_form input[type=checkbox]').each(function() {
97			var obj = jQuery(this);
98
99			if (obj.attr('name') !== 'all_groups' && obj.prop('checked')) {
100				var id = obj.data('id');
101
102				add_variable('input', 'new_right[' + id + '][permission]', obj.data('permission'), formName,
103					parentDocument);
104				add_variable('input', 'new_right[' + id + '][name]', obj.data('name'), formName, parentDocument);
105			}
106		});
107
108		parentDocument.forms[formName].submit();
109
110		close_window();
111	}
112</script>
113<?php
114
115require_once dirname(__FILE__).'/include/page_footer.php';
116