Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CFormList.php « html « classes « include « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9b5aeedb756e7ff19e98bebd589053b04be22082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


class CFormList extends CList {

	protected $editable = true;
	protected $formInputs = ['ctextbox', 'cnumericbox', 'ctextarea', 'ccombobox', 'ccheckbox', 'cpassbox'];

	public function __construct($id = null) {
		parent::__construct();

		$this->addClass(ZBX_STYLE_TABLE_FORMS);

		if ($id) {
			$this->setId(zbx_formatDomId($id));
		}
	}

	public function addRow($term, $description = null, $id = null, $class = null) {
		$input_id = null;

		$input = $description;
		if (is_array($input)) {
			$input = reset($input);
		}

		if (is_object($input)) {
			$input_class = strtolower(get_class($input));

			if (in_array($input_class, $this->formInputs)) {
				if ($input_class !== 'ccheckbox' || $input->getLabel() === '') {
					$input_id = $input->getAttribute('id');
				}
			}
		}

		$label = is_object($term) ? $term : new CLabel($term, $input_id);

		if ($description === null) {
			$this->addItem([
				(new CDiv(SPACE))->addClass(ZBX_STYLE_TABLE_FORMS_TD_LEFT),
				(new CDiv($label))->addClass(ZBX_STYLE_TABLE_FORMS_TD_RIGHT)],
				$class, $id);
		}
		else {
			$this->addItem([
				(new CDiv($label))->addClass(ZBX_STYLE_TABLE_FORMS_TD_LEFT),
				(new CDiv($description))->addClass(ZBX_STYLE_TABLE_FORMS_TD_RIGHT)],
				$class, $id);
		}

		return $this;
	}

	public function addInfo($text) {
		$this->addItem(
			[
				(new CDiv())->addClass(ZBX_STYLE_TABLE_FORMS_TD_LEFT),
				(new CDiv(
					(new CDiv($text))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
				))->addClass(ZBX_STYLE_TABLE_FORMS_TD_RIGHT)
			]
		);
		return $this;
	}

	public function toString($destroy = true) {
		return parent::toString($destroy);
	}

	public function addVar($name, $value, $id = null) {
		if ($value !== null) {
			$this->addItem(new CVar($name, $value, $id));
		}
		return $this;
	}
}