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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2016 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 CTweenBox {
public function __construct(&$form, $name, $value = null, $size = 10) {
$this->form = &$form;
$this->name = $name.'_tweenbox';
$this->varname = $name;
$this->value = zbx_toHash($value);
$this->id_l = $this->varname.'_left';
$this->id_r = $this->varname.'_right';
$this->lbox = new CListBox($this->id_l, null, $size);
$this->rbox = new CListBox($this->id_r, null, $size);
$this->lbox->setAttribute('style', 'width: 280px;');
$this->rbox->setAttribute('style', 'width: 280px;');
}
public function setName($name = null) {
if (is_string($name)) {
$this->name = $name;
}
}
public function getName() {
return $this->name;
}
public function addItem($value, $caption, $selected = null, $enabled = true) {
if (is_null($selected)) {
if (is_array($this->value)) {
if (isset($this->value[$value])) {
$selected = 1;
}
}
elseif (strcmp($value, $this->value) == 0) {
$selected = 1;
}
}
if ((is_bool($selected) && $selected)
|| (is_int($selected) && $selected != 0)
|| (is_string($selected) && ($selected == 'yes' || $selected == 'selected' || $selected == 'on'))) {
$this->lbox->addItem($value, $caption, null, $enabled);
$this->form->addVar($this->varname.'['.$value.']', $value);
}
else {
$this->rbox->addItem($value, $caption, null, $enabled);
}
return $this;
}
public function get($caption_l = null, $caption_r = null) {
if (empty($caption_l)) {
$caption_l = _('In');
}
if (empty($caption_r)) {
$caption_r = _('Other');
}
$grp_tab = (new CTable())
->addClass('tweenBoxTable')
->setAttribute('name', $this->name)
->setId('id', zbx_formatDomId($this->name))
->setCellSpacing(0)
->setCellPadding(0);
if (!is_null($caption_l) || !is_null($caption_r)) {
$grp_tab->addRow([$caption_l, '', $caption_r]);
}
$add_btn = (new CButton('add', (new CSpan())->addClass('arrow-left')))
->addClass(ZBX_STYLE_BTN_GREY)
->onClick('moveListBoxSelectedItem("'.$this->varname.'", "'.$this->id_r.'", "'.$this->id_l.'", "add");');
$rmv_btn = (new CButton('remove', (new CSpan())->addClass('arrow-right')))
->addClass(ZBX_STYLE_BTN_GREY)
->onClick('moveListBoxSelectedItem("'.$this->varname.'", "'.$this->id_l.'", "'.$this->id_r.'", "rmv");');
$grp_tab->addRow([$this->lbox, (new CCol([$add_btn, BR(), $rmv_btn]))->addClass(ZBX_STYLE_CENTER), $this->rbox]);
return $grp_tab;
}
public function show($caption_l = null, $caption_r = null) {
if (empty($caption_l)) {
$caption_l = _('In');
}
if (empty($caption_r)) {
$caption_r = _('Other');
}
$tab = $this->get($caption_l, $caption_r);
$tab->show();
return $this;
}
public function toString() {
$tab = $this->get();
return $tab->toString();
}
}
|