Example #1
0
    /**
     * @param string $options['id']
     * @param string $options['name']
     * @param int    $options['value']
     */
    public function __construct(array $options = array())
    {
        parent::__construct('div', 'yes');
        $this->attr('id', isset($options['id']) ? $options['id'] : zbx_formatDomId($options['name']));
        $this->addClass('jqueryinputset control-severity');
        if (!isset($options['value'])) {
            $options['value'] = TRIGGER_SEVERITY_NOT_CLASSIFIED;
        }
        $items = array();
        $jsIds = '';
        $jsLabels = '';
        foreach (getSeverityCaption() as $severity => $caption) {
            $items[] = new CRadioButton($options['name'], $severity, null, $options['name'] . '_' . $severity, $options['value'] == $severity);
            $css = getSeverityStyle($severity);
            $label = new CLabel($caption, $options['name'] . '_' . $severity, $options['name'] . '_label_' . $severity);
            $label->attr('data-severity', $severity);
            $label->attr('data-severity-style', $css);
            if ($options['value'] == $severity) {
                $label->attr('aria-pressed', 'true');
                $label->addClass($css);
            } else {
                $label->attr('aria-pressed', 'false');
            }
            $items[] = $label;
            $jsIds .= ', #' . $options['name'] . '_' . $severity;
            $jsLabels .= ', #' . $options['name'] . '_label_' . $severity;
        }
        if ($jsIds) {
            $jsIds = substr($jsIds, 2);
            $jsLabels = substr($jsLabels, 2);
        }
        $this->addItem($items);
        insert_js('
			jQuery("' . $jsLabels . '").mouseenter(function() {
				jQuery("' . $jsLabels . '").each(function() {
					var obj = jQuery(this);

					if (obj.attr("aria-pressed") == "false") {
						obj.removeClass("ui-state-hover " + obj.data("severityStyle"));
					}
				});

				var obj = jQuery(this);

				obj.addClass(obj.data("severityStyle"));
			})
			.mouseleave(function() {
				jQuery("#' . $this->getAttribute('id') . ' [aria-pressed=\\"true\\"]").trigger("mouseenter");
			});

			jQuery("' . $jsIds . '").change(function() {
				jQuery("#' . $this->getAttribute('id') . ' [aria-pressed=\\"true\\"]").trigger("mouseenter");
			});', true);
    }
    $userGroups->addItem($userGroup['usrgrpid'], $userGroup['name']);
}
$scriptFormList->addRow(_('User groups'), $userGroups);
// host groups
$hostGroups = new CCombobox('hgstype', $this->get('hgstype'));
$hostGroups->addItem(0, _('All'));
$hostGroups->addItem(1, _('Selected'));
$scriptFormList->addRow(_('Host groups'), $hostGroups);
$scriptFormList->addRow(null, new CMultiSelect(array('name' => 'groupid', 'selectedLimit' => 1, 'objectName' => 'hostGroup', 'data' => $this->get('hostGroup'))), null, 'hostGroupSelection');
// access
$accessComboBox = new CCombobox('access', $this->get('access'));
$accessComboBox->addItem(PERM_READ, _('Read'));
$accessComboBox->addItem(PERM_READ_WRITE, _('Write'));
$scriptFormList->addRow(_('Required host permissions'), $accessComboBox);
$scriptFormList->addRow(new CLabel(_('Enable confirmation'), 'enableConfirmation'), new CCheckBox('enableConfirmation', $this->get('enableConfirmation')));
$confirmationLabel = new CLabel(_('Confirmation text'), 'confirmation');
$confirmationLabel->setAttribute('id', 'confirmationLabel');
$scriptFormList->addRow($confirmationLabel, array(new CTextBox('confirmation', $this->get('confirmation'), ZBX_TEXTBOX_STANDARD_SIZE), SPACE, new CButton('testConfirmation', _('Test confirmation'), null, 'link_menu')));
$scriptView = new CTabView();
$scriptView->addTab('scripts', _('Script'), $scriptFormList);
$scriptForm->addItem($scriptView);
// footer
$others = array();
if (isset($_REQUEST['scriptid'])) {
    $others[] = new CButton('clone', _('Clone'));
    $others[] = new CButtonDelete(_('Delete script?'), url_param('form') . url_param('scriptid'));
}
$others[] = new CButtonCancel();
$scriptForm->addItem(makeFormFooter(new CSubmit('save', _('Save')), $others));
$scriptsWidget->addItem($scriptForm);
return $scriptsWidget;
/**
 * Create control for trigger severities.
 * It's mostly the same as usual button set, but background color is changed based on selected severiity.
 * Js file "/include/views/js/configuration.triggers.edit.js.php" is needed to make it work correcty.
 *
 * @param $selectedSeverity
 *
 * @return CDiv
 */
function getSeverityControl($selectedSeverity = TRIGGER_SEVERITY_NOT_CLASSIFIED)
{
    $controls = array();
    foreach (getSeverityCaption() as $severity => $caption) {
        $controls[] = new CRadioButton('priority', $severity, null, 'severity_' . $severity, $selectedSeverity == $severity);
        $label = new CLabel($caption, 'severity_' . $severity, 'severity_label_' . $severity);
        $label->attr('data-severity', $severity);
        $label->attr('data-severity-style', getSeverityStyle($severity));
        $controls[] = $label;
    }
    return new CDiv($controls, 'jqueryinputset control-severity');
}
    $host_groups->addItem($group['groupid'], $group['name']);
}
$scriptTab->addRow(_('Host groups'), $host_groups);
// permissions
$select_acc = new CCombobox('access', $this->get('access'));
$select_acc->addItem(PERM_READ_ONLY, _('Read'));
$select_acc->addItem(PERM_READ_WRITE, _('Write'));
$scriptTab->addRow(_('Required host permissions'), $select_acc);
// confirmation
$enableQuestCB = new CCheckBox('enableConfirmation', $this->get('enableConfirmation'));
$scriptTab->addRow(new CLabel(_('Enable confirmation'), 'enableConfirmation'), array($enableQuestCB, SPACE));
$confirmationTB = new CTextBox('confirmation', $this->get('confirmation'));
$confirmationTB->addStyle('width: 50em;');
$confirmationTB->setAttribute('maxlength', 255);
$testLink = new CButton('testConfirmation', _('Test confirmation'), null, 'link_menu');
$confirmationLabel = new CLabel(_('Confirmation text'), 'confirmation');
$confirmationLabel->setAttribute('id', 'confirmationLabel');
$scriptTab->addRow($confirmationLabel, array($confirmationTB, SPACE, $testLink));
$scriptView = new CTabView();
$scriptView->addTab('scripts', _('Script'), $scriptTab);
$frmScr->addItem($scriptView);
// footer
$main = array(new CSubmit('save', _('Save')));
$others = array();
if (isset($_REQUEST['scriptid'])) {
    $others[] = new CButton('clone', _('Clone'));
    $others[] = new CButtonDelete(_('Delete script?'), url_param('form') . url_param('scriptid'));
}
$others[] = new CButtonCancel();
$footer = makeFormFooter($main, $others);
$frmScr->addItem($footer);