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
26$this->includeJsFile('administration.image.list.js.php');
27
28$page_url = (new CUrl('zabbix.php'))->setArgument('action', 'image.list');
29$widget = (new CWidget())
30	->setTitle(_('Images'))
31	->setTitleSubmenu(getAdministrationGeneralSubmenu())
32	->setControls((new CTag('nav', true,
33		(new CForm())
34			->cleanItems()
35			->setAction($page_url->getUrl())
36			->addItem((new CList())
37				->addItem([
38					new CLabel(_('Type'), 'label-imagetype'),
39					(new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN),
40					(new CSelect('imagetype'))
41						->setId('imagetype')
42						->setFocusableElementId('label-imagetype')
43						->addOption(new CSelectOption($page_url
44								->setArgument('imagetype', IMAGE_TYPE_ICON)
45								->getUrl(),
46							_('Icon')
47						))
48						->addOption(new CSelectOption($page_url
49								->setArgument('imagetype', IMAGE_TYPE_BACKGROUND)
50								->getUrl(),
51							_('Background')
52						))
53						->setValue($page_url
54							->setArgument('imagetype', $data['imagetype'])
55							->getUrl()
56						)
57				])
58				->addItem(
59					(new CButton(null, ($data['imagetype'] == IMAGE_TYPE_ICON)
60						? _('Create icon')
61						: _('Create background')
62					))->onClick(sprintf('javascript: document.location="%s";', (new CUrl('zabbix.php'))
63							->setArgument('action', 'image.edit')
64							->setArgument('imagetype', $data['imagetype'])
65							->getUrl()
66					))
67				)
68			)
69		))
70			->setAttribute('aria-label', _('Content controls'))
71	);
72
73if (!$data['images']) {
74	$widget->addItem(new CTableInfo());
75}
76else {
77	$image_table = (new CDiv())
78		->addClass(ZBX_STYLE_TABLE)
79		->addClass(ZBX_STYLE_ADM_IMG);
80
81	$count = 0;
82	$image_row = (new CDiv())->addClass(ZBX_STYLE_ROW);
83	$edit_url = (new Curl('zabbix.php'))->setArgument('action', 'image.edit');
84
85	foreach ($data['images'] as $image) {
86		$img = ($image['imagetype'] == IMAGE_TYPE_BACKGROUND)
87			? new CLink(
88				new CImg('imgstore.php?width=200&height=200&iconid='.$image['imageid'], 'no image'),
89				'image.php?imageid='.$image['imageid']
90			)
91			: new CImg('imgstore.php?iconid='.$image['imageid'], 'no image');
92
93		$edit_url->setArgument('imageid', $image['imageid']);
94
95		$image_row->addItem(
96			(new CDiv())
97				->addClass(ZBX_STYLE_CELL)
98				->addItem([$img, BR(), new CLink($image['name'], $edit_url->getUrl())])
99		);
100
101		if ((++$count % 5) == 0) {
102			$image_table->addItem($image_row);
103			$image_row = (new CDiv())->addClass(ZBX_STYLE_ROW);
104		}
105	}
106
107	if (($count % 5) != 0) {
108		$image_table->addItem($image_row);
109	}
110
111	$widget->addItem(
112		(new CForm())->addItem(
113			(new CTabView())->addTab('image', null, $image_table)
114		)
115	);
116}
117
118$widget->show();
119