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
26if ($data['uncheck']) {
27	uncheckTableRows('userrole');
28}
29
30$widget = (new CWidget())
31	->setTitle(_('User roles'))
32	->setControls((new CTag('nav', true,
33		(new CList())
34			->addItem(new CRedirectButton(_('Create user role'),
35				(new CUrl('zabbix.php'))->setArgument('action', 'userrole.edit'))
36			)
37		))->setAttribute('aria-label', _('Content controls'))
38	)
39	->addItem((new CFilter((new CUrl('zabbix.php'))->setArgument('action', 'userrole.list')))
40		->addVar('action', 'userrole.list')
41		->setProfile($data['profileIdx'])
42		->setActiveTab($data['active_tab'])
43		->addFilterTab(_('Filter'), [
44			(new CFormList())->addRow(_('Name'),
45				(new CTextBox('filter_name', $data['filter']['name']))
46					->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH)
47					->setAttribute('autofocus', 'autofocus')
48			)
49		])
50	);
51
52$form = (new CForm())
53	->setName('userroles_form')
54	->setId('userroles');
55
56$table = (new CTableInfo())
57	->setHeader([
58		(new CColHeader((new CCheckBox('all_roles'))->onClick(sprintf(
59			'checkAll(\'%s\',\'all_roles\',\'roleids\');', $form->getName()
60		))))->addClass(ZBX_STYLE_CELL_WIDTH),
61		make_sorting_header(_('Name'), 'name', $data['sort'], $data['sortorder'],
62			(new CUrl('zabbix.php'))
63				->setArgument('action', 'userrole.list')
64				->getUrl()
65		),
66		'#',
67		_('Users')
68	]);
69
70foreach ($this->data['roles'] as $role) {
71	$users = [];
72
73	foreach ($role['users'] as $user) {
74		if ($users) {
75			$users[] = ', ';
76		}
77
78		$user_has_access = ($user['gui_access'] != GROUP_GUI_ACCESS_DISABLED
79			&& $user['users_status'] != GROUP_STATUS_DISABLED
80		);
81
82		$user = $data['allowed_ui_users']
83			? (new CLink(getUserFullname($user), (new CUrl('zabbix.php'))
84				->setArgument('action', 'user.edit')
85				->setArgument('userid', $user['userid'])
86				->getUrl()
87			))
88				->addClass(ZBX_STYLE_LINK_ALT)
89			: new CSpan(getUserFullname($user));
90
91		$users[] = $user->addClass($user_has_access ? ZBX_STYLE_GREEN : ZBX_STYLE_RED);
92	}
93
94	if (count($role['users']) != $role['user_cnt']) {
95		$users[] = ' &hellip;';
96	}
97
98	$name = new CLink($role['name'], (new CUrl('zabbix.php'))
99		->setArgument('action', 'userrole.edit')
100		->setArgument('roleid', $role['roleid'])
101		->getUrl()
102	);
103
104	$table->addRow([
105		(new CCheckBox('roleids['.$role['roleid'].']', $role['roleid']))->setEnabled($role['readonly'] ? false : true),
106		(new CCol($name))->addClass(ZBX_STYLE_NOWRAP),
107		[
108			$data['allowed_ui_users']
109				? new CLink(_('Users'), (new CUrl('zabbix.php'))
110					->setArgument('action', 'user.list')
111					->setArgument('filter_roles[]', $role['roleid'])
112					->setArgument('filter_set', 1)
113					->getUrl()
114				)
115				: _('Users'),
116			CViewHelper::showNum($role['user_cnt'])
117		],
118		$users
119	]);
120}
121
122$form->addItem([
123	$table,
124	$this->data['paging'],
125	new CActionButtonList('action', 'roleids', [
126		'userrole.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected roles?')]
127	], 'userrole')
128]);
129
130$widget->addItem($form);
131$widget->show();
132