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$widget = (new CWidget())
22	->setTitle(_('Images'))
23	->setControls((new CForm())
24		->cleanItems()
25		->addItem((new CList())->addItem(makeAdministrationGeneralMenu('adm.images.php')))
26	);
27
28$imageForm = (new CForm('post', null, 'multipart/form-data'))
29	->addVar('form', $this->data['form']);
30if (isset($this->data['imageid'])) {
31	$imageForm->addVar('imageid', $this->data['imageid']);
32}
33$imageForm->addVar('imagetype', $this->data['imagetype']);
34
35// append form list
36$imageFormList = (new CFormList('imageFormList'))
37	->addRow(_('Name'),
38		(new CTextBox('name', $this->data['imagename'], false, 64))
39			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
40			->setAttribute('autofocus', 'autofocus')
41	)
42	->addRow(_('Upload'), (new CFile('image'))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH));
43
44if (isset($this->data['imageid'])) {
45	if ($this->data['imagetype'] == IMAGE_TYPE_BACKGROUND) {
46		$imageFormList->addRow(_('Image'), new CLink(new CImg('imgstore.php?width=200&height=200&iconid='.$this->data['imageid'], 'no image'), 'image.php?imageid='.$this->data['imageid']));
47	}
48	else {
49		$imageFormList->addRow(_('Image'), new CImg('imgstore.php?iconid='.$this->data['imageid'], 'no image', null));
50	}
51}
52
53// append tab
54$imageTab = (new CTabView())
55	->addTab('imageTab', ($this->data['imagetype'] == IMAGE_TYPE_ICON) ? _('Icon') : _('Background'), $imageFormList);
56
57// append buttons
58if (isset($this->data['imageid'])) {
59	$imageTab->setFooter(makeFormFooter(
60		new CSubmit('update', _('Update')),
61		[
62			new CButtonDelete(_('Delete selected image?'), url_param('form').url_param('imageid').
63				url_param($data['imagetype'], false, 'imagetype')
64			),
65			new CButtonCancel(url_param($data['imagetype'], false, 'imagetype'))
66		]
67	));
68}
69else {
70	$imageTab->setFooter(makeFormFooter(
71		new CSubmit('add', _('Add')),
72		[new CButtonCancel(url_param($data['imagetype'], false, 'imagetype'))]
73	));
74}
75
76$imageForm->addItem($imageTab);
77
78$widget->addItem($imageForm);
79
80return $widget;
81