示例#1
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $error = null;
     $timeOffset = null;
     $timeZone = null;
     switch ($this->screenitem['style']) {
         case TIME_TYPE_HOST:
             $items = API::Item()->get(array('itemids' => $this->screenitem['resourceid'], 'selectHosts' => array('host'), 'output' => array('itemid', 'value_type')));
             $item = reset($items);
             $host = reset($item['hosts']);
             $lastValue = Manager::History()->getLast(array($item));
             if ($lastValue) {
                 $lastValue = reset($lastValue[$item['itemid']]);
                 $item['lastvalue'] = $lastValue['value'];
                 $item['lastclock'] = $lastValue['clock'];
             } else {
                 $item['lastvalue'] = '0';
                 $item['lastclock'] = '0';
             }
             $timeType = $host['host'];
             preg_match('/([+-]{1})([\\d]{1,2}):([\\d]{1,2})/', $item['lastvalue'], $arr);
             if (!empty($arr)) {
                 $timeZone = $arr[2] * SEC_PER_HOUR + $arr[3] * SEC_PER_MIN;
                 if ($arr[1] == '-') {
                     $timeZone = 0 - $timeZone;
                 }
             }
             if ($lastvalue = strtotime($item['lastvalue'])) {
                 $diff = time() - $item['lastclock'];
                 $timeOffset = $lastvalue + $diff;
             } else {
                 $error = _('NO DATA');
             }
             break;
         case TIME_TYPE_SERVER:
             $error = null;
             $timeType = _('SERVER');
             $timeOffset = time();
             $timeZone = date('Z');
             break;
         default:
             $error = null;
             $timeType = _('LOCAL');
             $timeOffset = null;
             $timeZone = null;
             break;
     }
     if ($this->screenitem['width'] > $this->screenitem['height']) {
         $this->screenitem['width'] = $this->screenitem['height'];
     }
     $item = new CFlashClock($this->screenitem['width'], $this->screenitem['height'], $this->action);
     $item->setTimeError($error);
     $item->setTimeType($timeType);
     $item->setTimeZone($timeZone);
     $item->setTimeOffset($timeOffset);
     $flashclockOverDiv = new CDiv(null, 'flashclock');
     $flashclockOverDiv->setAttribute('style', 'width: ' . $this->screenitem['width'] . 'px; height: ' . $this->screenitem['height'] . 'px;');
     return $this->getOutput(array($item, $flashclockOverDiv));
 }
 /**
  * Display the widget in expanded or collapsed state.
  */
 public function build()
 {
     $body = new CDiv($this->body, 'body');
     $body->setAttribute('id', $this->id);
     if (!$this->open) {
         $body->setAttribute('style', 'display: none;');
         if ($this->footer) {
             $this->footer->setAttribute('style', 'display: none;');
         }
     }
     $this->cleanItems();
     $this->addItem($this->header);
     $this->addItem($body);
     $this->addItem($this->footer);
 }
 public function addValue($name, $value, $checked = null)
 {
     $this->count++;
     $id = str_replace(array('[', ']'), array('_'), $this->name) . '_' . $this->count;
     $radio = new CInput('radio', $this->name, $value);
     $radio->attr('id', zbx_formatDomId($id));
     if (strcmp($value, $this->value) == 0 || !is_null($checked) || $checked) {
         $radio->attr('checked', 'checked');
     }
     $label = new CLabel($name, $id);
     $outerDiv = new CDiv(array($radio, $label));
     if ($this->orientation == self::ORIENTATION_HORIZONTAL) {
         $outerDiv->addClass('inlineblock');
     }
     parent::addItem($outerDiv);
 }
示例#4
0
 public function __construct($title, $class, $action = '')
 {
     parent::__construct(SPACE, $class . ' menu_icon');
     $this->setAttribute('title', $title);
     if (!empty($action)) {
         $this->setAttribute('onclick', 'javascript: ' . $action);
     }
 }
示例#5
0
 public function __construct($name, $value, $insert_color_picker = true)
 {
     parent::__construct([(new CColorCell('lbl_' . $name, $value))->setTitle('#' . $value)->onClick('javascript: show_color_picker("' . zbx_formatDomId($name) . '")'), (new CTextBox($name, $value))->setWidth(ZBX_TEXTAREA_COLOR_WIDTH)->setAttribute('maxlength', 6)->onChange('set_color_by_name("' . zbx_formatDomId($name) . '", this.value)')]);
     $this->addClass(ZBX_STYLE_INPUT_COLOR_PICKER);
     if ($insert_color_picker) {
         insert_show_color_picker_javascript();
     }
 }
示例#6
0
 public function __construct($name, $value, $action = null)
 {
     parent::__construct(SPACE . SPACE . SPACE, 'pointer');
     $this->setName($name);
     $this->attr('id', zbx_formatDomId($name));
     $this->attr('title', '#' . $value);
     $this->attr('style', 'display: inline; width: 10px; height: 10px; text-decoration: none; border: 1px solid black; background-color: #' . $value);
     $this->attr('onclick', $action);
 }
示例#7
0
 public function __construct($name = null, $color)
 {
     parent::__construct();
     if ($name !== null) {
         $this->setName($name);
         $this->setId(zbx_formatDomId($name));
     }
     $this->setAttribute('style', 'background: #' . $color);
 }
示例#8
0
 public function __construct($name, $value, $action = null)
 {
     parent::__construct(SPACE . SPACE . SPACE, null);
     $this->setName($name);
     $this->setAttribute('id', $name);
     $this->setAttribute('title', '#' . $value);
     $this->setAttribute('class', 'pointer');
     $this->setAttribute('style', 'display: inline; width: 10px; height: 10px; text-decoration: none; outline: 1px solid black; background-color: #' . $value);
     $this->setAction($action);
 }
示例#9
0
 public function __construct($header, $messages = [], $buttons = [])
 {
     parent::__construct($header);
     $this->addClass(ZBX_STYLE_MSG_BAD);
     $this->addClass('msg-global');
     if ($messages) {
         parent::addItem((new CDiv((new CList($messages))->addClass(ZBX_STYLE_MSG_DETAILS_BORDER)))->addClass(ZBX_STYLE_MSG_DETAILS));
     }
     parent::addItem((new CDiv($buttons))->addClass('msg-buttons'));
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $image = new CImg('map.php?noedit=1&sysmapid=' . $this->screenitem['resourceid'] . '&width=' . $this->screenitem['width'] . '&height=' . $this->screenitem['height'] . '&curtime=' . time());
     $image->setAttribute('id', 'map_' . $this->screenitem['screenitemid']);
     if ($this->mode == SCREEN_MODE_PREVIEW) {
         $sysmap = API::Map()->get(array('sysmapids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'selectSelements' => API_OUTPUT_EXTEND, 'selectLinks' => API_OUTPUT_EXTEND, 'expandUrls' => true, 'nopermissions' => true, 'preservekeys' => true));
         $sysmap = reset($sysmap);
         $actionMap = getActionMapBySysmap($sysmap);
         $image->setMap($actionMap->getName());
         $output = array($actionMap, $image);
     } elseif ($this->mode == SCREEN_MODE_EDIT) {
         $output = array($image, BR(), new CLink(_('Change'), $this->action));
     } else {
         $output = array($image);
     }
     $this->insertFlickerfreeJs();
     $div = new CDiv($output, 'map-container flickerfreescreen', $this->getScreenId());
     $div->setAttribute('data-timestamp', $this->timestamp);
     $div->addStyle('position: relative;');
     return $div;
 }
示例#11
0
 function bodyToString($destroy = true)
 {
     $left = new CDiv(null, 'left');
     $left->addItem(new CDiv($this->getList(), 'left_menu'));
     $link1 = new CLink('www.zabbix.com', 'http://www.zabbix.com/', null, null, true);
     $link1->setAttribute('target', '_blank');
     $link2 = new CLink('GPL v2', 'http://www.zabbix.com/license.php', null, null, true);
     $link2->setAttribute('target', '_blank');
     $licence = new CDiv(array($link1, BR(), ' Licensed under ', $link2), 'setup_wizard_licence');
     $left->addItem($licence);
     $right = new CDiv(null, 'right');
     if ($this->getStep() == 0) {
         $right->addItem(new CDiv(null, 'blank_title'));
         $right->addItem(new CDiv($this->getState(), 'blank_under_title'));
         $container = new CDiv(array($left, $right), 'setup_wizard setup_wizard_welcome');
     } else {
         $right->addItem(new CDiv($this->stage[$this->getStep()]['title'], 'setup_title'));
         $right->addItem(new CDiv($this->getState(), 'under_title'));
         $container = new CDiv(array($left, $right), 'setup_wizard');
     }
     if (isset($this->stage[$this->getStep() + 1])) {
         $next = new CSubmit('next[' . $this->getStep() . ']', _('Next') . SPACE . '»');
     } else {
         $next = new CSubmit('finish', _('Finish'));
     }
     if (isset($this->HIDE_CANCEL_BUTTON) && $this->HIDE_CANCEL_BUTTON) {
         $cancel = null;
     } else {
         $cancel = new CDiv(new CSubmit('cancel', _('Cancel')), 'footer_left');
     }
     if ($this->DISABLE_NEXT_BUTTON) {
         $next->setEnabled(false);
     }
     // if the user is not logged in (first setup run) hide the "previous" button on the final step
     if ($this->getStep() && (CWebUser::$data && CWebUser::getType() == USER_TYPE_SUPER_ADMIN || $this->getStep() < 5)) {
         $back = new CSubmit('back[' . $this->getStep() . ']', '&laquo;' . SPACE . _('Previous'));
     } else {
         $back = null;
     }
     $footer = new CDiv(array($cancel, new CDiv(array($back, $next), 'footer_right')), 'footer');
     $container->addItem($footer);
     return parent::bodyToString($destroy) . $container->ToString();
 }
 public function toString($destroy = true)
 {
     if (count($this->tabs) == 1) {
         $this->setAttribute('class', 'min-width ui-tabs ui-widget ui-widget-content ui-corner-all widget');
         $header = reset($this->headers);
         $header = new CDiv($header);
         $header->addClass('ui-corner-all ui-widget-header header');
         $header->setAttribute('id', 'tab_' . key($this->headers));
         $this->addItem($header);
         $tab = reset($this->tabs);
         $tab->addClass('ui-tabs ui-tabs-panel ui-widget ui-widget-content ui-corner-all widget');
         $this->addItem($tab);
     } else {
         $headersList = new CList();
         foreach ($this->headers as $id => $header) {
             $tabLink = new CLink($header, '#' . $id, null, null, false);
             $tabLink->setAttribute('id', 'tab_' . $id);
             $headersList->addItem($tabLink);
         }
         $this->addItem($headersList);
         $this->addItem($this->tabs);
         $options = array();
         if (!is_null($this->selectedTab)) {
             $options['selected'] = $this->selectedTab;
         }
         if ($this->rememberTab) {
             $options['cookie'] = array();
         }
         zbx_add_post_js('jQuery("#' . $this->id . '").tabs(' . zbx_jsvalue($options, true) . ').show();');
     }
     return parent::toString($destroy);
 }
示例#13
0
 if (time() - $trigger['lastchange'] < TRIGGER_BLINK_PERIOD) {
     $status->setAttribute('name', 'blink');
 }
 $lastchange = new CLink(zbx_date2str(S_DATE_FORMAT_YMDHMS, $trigger['lastchange']), 'events.php?triggerid=' . $trigger['triggerid']);
 //.'&stime='.date('YmdHis', $trigger['lastchange']
 if ($config['event_ack_enable']) {
     if ($trigger['event_count']) {
         $to_ack = new CCol(array(new CLink(S_ACKNOWLEDGE, 'acknow.php?triggers[]=' . $trigger['triggerid'] . '&backurl=' . $page['file'], 'on'), ' (' . $trigger['event_count'] . ')'));
     } else {
         $to_ack = new CCol(S_ACKNOWLEDGED, 'off');
     }
 } else {
     $to_ack = null;
 }
 if ($show_events != EVENTS_OPTION_NOEVENT && !empty($trigger['events'])) {
     $open_close = new CDiv(SPACE, 'filterclosed');
     $open_close->setAttribute('data-switcherid', $trigger['triggerid']);
 } else {
     if ($show_events == EVENTS_OPTION_NOEVENT) {
         $open_close = null;
     } else {
         $open_close = SPACE;
     }
 }
 $severity_col = new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority'], $trigger['value']));
 if ($show_event_col) {
     $severity_col->setColSpan(2);
 }
 $table->addRow(array($open_close, $config['event_ack_enable'] ? $show_event_col ? null : new CCheckBox('triggers[' . $trigger['triggerid'] . ']', 'no', null, $trigger['triggerid']) : null, $severity_col, $status, $lastchange, zbx_date2age($trigger['lastchange']), $show_event_col ? SPACE : NULL, $to_ack, get_node_name_by_elid($trigger['triggerid']), $host, $tr_desc, new CLink(zbx_empty($trigger['comments']) ? S_ADD : S_SHOW, 'tr_comments.php?triggerid=' . $trigger['triggerid'])), 'even_row');
 if ($show_events != EVENTS_OPTION_NOEVENT) {
     $i = 1;
示例#14
0
        if (isset($services[$row['serviceid']])) {
            $services[$row['serviceid']] = array_merge($services[$row['serviceid']], $row);
        } else {
            $services[$row['serviceid']] = $row;
        }
        if (isset($row['serviceupid'])) {
            $services[$row['serviceupid']]['childs'][] = array('id' => $row['serviceid'], 'soft' => 0, 'linkid' => 0);
        }
        if (isset($row['servicedownid'])) {
            $services[$row['serviceid']]['childs'][] = array('id' => $row['servicedownid'], 'soft' => 1, 'linkid' => $row['linkid']);
        }
    }
    $treeServ = array();
    createShowServiceTree($services, $treeServ);
    //return into $treeServ parametr
    //permission issue
    $treeServ = del_empty_nodes($treeServ);
    $tree = new CTree($treeServ, array('caption' => bold(S_SERVICE), 'status' => bold(S_STATUS), 'reason' => bold(S_REASON), 'sla' => bold(S_SLA_LAST_7_DAYS), 'sla2' => bold(nbsp(S_SLA)), 'graph' => bold(S_GRAPH)));
    if ($tree) {
        $url = '?fullscreen=' . ($_REQUEST['fullscreen'] ? '0' : '1');
        $fs_icon = new CDiv(SPACE, 'fullscreen');
        $fs_icon->AddOption('title', $_REQUEST['fullscreen'] ? S_NORMAL . ' ' . S_VIEW : S_FULLSCREEN);
        $fs_icon->AddAction('onclick', new CScript("javascript: document.location = '" . $url . "';"));
        $tab = create_hat(S_IT_SERVICES_BIG, $tree->getHTML(), null, 'hat_services', get_profile('web.srv_status.hats.hat_services.state', 1));
        $tab->Show();
        unset($tab);
    } else {
        error('Can not format Tree. Check logik structure in service links');
    }
}
include_once "include/page_footer.php";
 foreach ($this->data['new_operation']['opcommand_hst'] as $ohnum => $cmd) {
     $this->data['new_operation']['opcommand_hst'][$ohnum]['name'] = $cmd['hostid'] > 0 ? $hosts[$cmd['hostid']]['name'] : '';
 }
 order_result($this->data['new_operation']['opcommand_hst'], 'name');
 $groups = API::HostGroup()->get(array('groupids' => zbx_objectValues($this->data['new_operation']['opcommand_grp'], 'groupid'), 'output' => array('groupid', 'name'), 'preservekeys' => true, 'editable' => true));
 $this->data['new_operation']['opcommand_grp'] = array_values($this->data['new_operation']['opcommand_grp']);
 foreach ($this->data['new_operation']['opcommand_grp'] as $ognum => $cmd) {
     $this->data['new_operation']['opcommand_grp'][$ognum]['name'] = $groups[$cmd['groupid']]['name'];
 }
 order_result($this->data['new_operation']['opcommand_grp'], 'name');
 // js add commands
 $jsInsert = 'addPopupValues(' . zbx_jsvalue(array('object' => 'hostid', 'values' => $this->data['new_operation']['opcommand_hst'])) . ');';
 $jsInsert .= 'addPopupValues(' . zbx_jsvalue(array('object' => 'groupid', 'values' => $this->data['new_operation']['opcommand_grp'])) . ');';
 zbx_add_post_js($jsInsert);
 // target list
 $cmdList = new CDiv($cmdList, 'objectgroup border_dotted ui-corner-all inlineblock');
 $cmdList->setAttribute('id', 'opCmdList');
 $newOperationsTable->addRow(array(_('Target list'), $cmdList), 'indent_top');
 // type
 $typeComboBox = new CComboBox('new_operation[opcommand][type]', $this->data['new_operation']['opcommand']['type'], 'javascript: showOpTypeForm();');
 $typeComboBox->addItem(ZBX_SCRIPT_TYPE_IPMI, _('IPMI'));
 $typeComboBox->addItem(ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT, _('Custom script'));
 $typeComboBox->addItem(ZBX_SCRIPT_TYPE_SSH, _('SSH'));
 $typeComboBox->addItem(ZBX_SCRIPT_TYPE_TELNET, _('Telnet'));
 $typeComboBox->addItem(ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT, _('Global script'));
 $userScriptId = new CVar('new_operation[opcommand][scriptid]', $this->data['new_operation']['opcommand']['scriptid']);
 $userScriptName = new CTextBox('new_operation[opcommand][script]', $this->data['new_operation']['opcommand']['script'], 32, true);
 $userScriptSelect = new CButton('select_opcommand_script', _('Select'), null, 'link_menu');
 $userScript = new CDiv(array($userScriptId, $userScriptName, SPACE, $userScriptSelect), 'class_opcommand_userscript inlineblock hidden');
 $newOperationsTable->addRow(array(_('Type'), array($typeComboBox, SPACE, $userScript)), 'indent_bottom');
 // script
示例#16
0
 public function get()
 {
     $widget = array();
     if (!empty($this->pageHeaders)) {
         $widget[] = $this->createPageHeader();
     }
     if (!empty($this->headers)) {
         $widget[] = $this->createHeader();
     }
     if (!empty($this->flicker)) {
         $flicker_domid = 'flicker_' . $this->bodyId;
         $flicker_tab = new CTable();
         $flicker_tab->setAttribute('width', '100%');
         $flicker_tab->setCellPadding(0);
         $flicker_tab->setCellSpacing(0);
         $div = new CDiv($this->flicker, null, $flicker_domid);
         if (!$this->flicker_state) {
             $div->setAttribute('style', 'display: none;');
         }
         $icon_l = new CDiv(SPACE . SPACE, $this->flicker_state ? 'dbl_arrow_up' : 'dbl_arrow_down', 'flicker_icon_l');
         $icon_l->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
         $icon_r = new CDiv(SPACE . SPACE, $this->flicker_state ? 'dbl_arrow_up' : 'dbl_arrow_down', 'flicker_icon_r');
         $icon_r->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
         $icons_row = new CTable(null, 'textwhite');
         $flickerTitleWhenVisible = _('Hide filter');
         $flickerTitleWhenHidden = _('Show filter');
         $flickerTitle = $this->flicker_state ? $flickerTitleWhenVisible : $flickerTitleWhenHidden;
         $icons_row->addRow(array($icon_l, new CSpan(SPACE . $flickerTitle . SPACE, null, 'flicker_title'), $icon_r));
         $thin_tab = $this->createFlicker($icons_row);
         $thin_tab->attr('id', 'filter_icon');
         $thin_tab->addAction('onclick', "javascript: changeFlickerState(" . "'" . $flicker_domid . "', " . CJs::encodeJson($flickerTitleWhenVisible) . ", " . CJs::encodeJson($flickerTitleWhenHidden) . ");");
         $flicker_tab->addRow($thin_tab, 'textcolorstyles pointer');
         $flicker_tab->addRow($div);
         $widget[] = $flicker_tab;
     }
     $div = new CDiv($this->body, 'w');
     $div->setAttribute('id', $this->bodyId);
     $widget[] = $div;
     return new CDiv($widget, $this->getRootClass());
 }
** 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.
**/
include 'include/views/js/administration.general.triggerSeverity.js.php';
$severityTab = new CFormList('scriptsTab');
$headerDiv = new CDiv(_('Custom severity'), 'inlineblock');
$headerDiv->addStyle('width: 16.3em; margin-left: 3px; zoom:1; *display: inline;');
$severityTab->addRow(SPACE, array($headerDiv, _('Colour')));
$severityNameTB0 = new CTextBox('severity_name_0', $this->data['config']['severity_name_0']);
$severityNameTB0->addStyle('width: 15em;');
$severityNameTB0->setAttribute('maxlength', 32);
$severityColorTB0 = new CColor('severity_color_0', $this->data['config']['severity_color_0']);
$severityTab->addRow(_('Not classified'), array($severityNameTB0, SPACE, $severityColorTB0));
$severityNameTB1 = new CTextBox('severity_name_1', $this->data['config']['severity_name_1']);
$severityNameTB1->addStyle('width: 15em;');
$severityNameTB1->setAttribute('maxlength', 32);
$severityColorTB1 = new CColor('severity_color_1', $this->data['config']['severity_color_1']);
$severityTab->addRow(_('Information'), array($severityNameTB1, SPACE, $severityColorTB1));
$severityNameTB2 = new CTextBox('severity_name_2', $this->data['config']['severity_name_2']);
$severityNameTB2->addStyle('width: 15em;');
$severityNameTB2->setAttribute('maxlength', 32);
// getting inventory fields to make a drop down
$inventoryFields = getHostInventories(true);
// 'true' means list should be ordered by title
$inventoryFieldsComboBox = new CComboBox('filter_field', $this->data['filterField']);
foreach ($inventoryFields as $inventoryField) {
    $inventoryFieldsComboBox->addItem($inventoryField['db_field'], $inventoryField['title']);
}
$exactComboBox = new CComboBox('filter_exact', $this->data['filterExact']);
$exactComboBox->addItem('0', _('like'));
$exactComboBox->addItem('1', _('exactly'));
$filterTable->addRow(array(array(array(bold(_('Field')), SPACE, $inventoryFieldsComboBox), array($exactComboBox, new CTextBox('filter_field_value', $this->data['filterFieldValue'], 20)))), 'host-inventories');
$filter = new CSubmit('filter_set', _('Filter'));
$filter->useJQueryStyle('main');
$reset = new CSubmit('filter_rst', _('Reset'));
$reset->useJQueryStyle();
$divButtons = new CDiv(array($filter, SPACE, $reset));
$divButtons->setAttribute('style', 'padding: 4px 0px;');
$footerCol = new CCol($divButtons, 'controls');
$filterTable->addRow($footerCol);
$filterForm = new CForm('get');
$filterForm->setAttribute('name', 'zbx_filter');
$filterForm->setAttribute('id', 'zbx_filter');
$filterForm->addItem($filterTable);
$hostInventoryWidget->addFlicker($filterForm, CProfile::get('web.hostinventories.filter.state', 0));
$hostInventoryWidget->addHeaderRowNumber();
$table = new CTableInfo(_('No hosts found.'));
$table->setHeader(array(make_sorting_header(_('Host'), 'name', $this->data['sort'], $this->data['sortorder']), _('Group'), make_sorting_header(_('Name'), 'pr_name', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Type'), 'pr_type', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('OS'), 'pr_os', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Serial number A'), 'pr_serialno_a', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Tag'), 'pr_tag', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('MAC address A'), 'pr_macaddress_a', $this->data['sort'], $this->data['sortorder'])));
foreach ($this->data['hosts'] as $host) {
    $hostGroups = array();
    foreach ($host['groups'] as $group) {
        $hostGroups[] = $group['name'];
示例#19
0
 public function toString($destroy = true)
 {
     $this->get();
     return parent::toString($destroy);
 }
 /**
  * Process screen with particular screen objects.
  *
  * @return CTable
  */
 public function show()
 {
     if (empty($this->screen)) {
         return new CTableInfo(_('No screens defined.'));
     }
     $skipedFields = array();
     $screenitems = array();
     $emptyScreenColumns = array();
     // calculate table columns and rows
     foreach ($this->screen['screenitems'] as $screenitem) {
         $screenitems[] = $screenitem;
         for ($i = 0; $i < $screenitem['rowspan'] || $i == 0; $i++) {
             for ($j = 0; $j < $screenitem['colspan'] || $j == 0; $j++) {
                 if ($i != 0 || $j != 0) {
                     if (!isset($skipedFields[$screenitem['y'] + $i])) {
                         $skipedFields[$screenitem['y'] + $i] = array();
                     }
                     $skipedFields[$screenitem['y'] + $i][$screenitem['x'] + $j] = 1;
                 }
             }
         }
     }
     // create screen table
     $screenTable = new CTable();
     $screenTable->setAttribute('class', in_array($this->mode, array(SCREEN_MODE_PREVIEW, SCREEN_MODE_SLIDESHOW)) ? 'screen_view' : 'screen_edit');
     $screenTable->setAttribute('id', 'iframe');
     // action top row
     if ($this->mode == SCREEN_MODE_EDIT) {
         $newColumns = array(new CCol(new CImg('images/general/zero.png', 'zero', 1, 1)));
         for ($i = 0, $size = $this->screen['hsize'] + 1; $i < $size; $i++) {
             $icon = new CImg('images/general/plus.png', null, null, null, 'pointer');
             $icon->addAction('onclick', 'javascript: location.href = "screenedit.php?config=1&screenid=' . $this->screen['screenid'] . '&add_col=' . $i . '";');
             array_push($newColumns, new CCol($icon));
         }
         $screenTable->addRow($newColumns);
     }
     for ($r = 0; $r < $this->screen['vsize']; $r++) {
         $newColumns = array();
         $emptyScreenRow = true;
         // action left cell
         if ($this->mode == SCREEN_MODE_EDIT) {
             $icon = new CImg('images/general/plus.png', null, null, null, 'pointer');
             $icon->addAction('onclick', 'javascript: location.href = "screenedit.php?config=1&screenid=' . $this->screen['screenid'] . '&add_row=' . $r . '";');
             array_push($newColumns, new CCol($icon));
         }
         for ($c = 0; $c < $this->screen['hsize']; $c++) {
             if (isset($skipedFields[$r][$c])) {
                 continue;
             }
             // screen item
             $isEditForm = false;
             $screenitem = array();
             foreach ($screenitems as $tmprow) {
                 if ($tmprow['x'] == $c && $tmprow['y'] == $r) {
                     $screenitem = $tmprow;
                     break;
                 }
             }
             if (empty($screenitem)) {
                 $screenitem = array('screenitemid' => 0, 'resourcetype' => 0, 'resourceid' => 0, 'width' => 0, 'height' => 0, 'colspan' => 1, 'rowspan' => 1, 'elements' => 0, 'valign' => VALIGN_DEFAULT, 'halign' => HALIGN_DEFAULT, 'style' => 0, 'url' => '', 'dynamic' => 0, 'sort_triggers' => SCREEN_SORT_TRIGGERS_DATE_DESC);
             }
             if (!empty($screenitem['screenitemid'])) {
                 $emptyScreenRow = false;
                 $emptyScreenColumns[$c] = 1;
             }
             // action
             if ($this->mode == SCREEN_MODE_EDIT && $screenitem['screenitemid'] != 0) {
                 $action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitem['screenitemid'];
             } elseif ($this->mode == SCREEN_MODE_EDIT && $screenitem['screenitemid'] == 0) {
                 $action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r;
             } else {
                 $action = null;
             }
             // edit form cell
             if ($this->mode == SCREEN_MODE_EDIT && (isset($_REQUEST['form']) && $_REQUEST['form'] == 'update') && (isset($_REQUEST['x']) && $_REQUEST['x'] == $c && isset($_REQUEST['y']) && $_REQUEST['y'] == $r || isset($_REQUEST['screenitemid']) && bccomp($_REQUEST['screenitemid'], $screenitem['screenitemid']) == 0)) {
                 $screenView = new CView('configuration.screen.constructor.edit', array('screen' => $this->screen));
                 $item = $screenView->render();
                 $isEditForm = true;
             } elseif (!empty($screenitem['screenitemid']) && isset($screenitem['resourcetype'])) {
                 $screenBase = CScreenBuilder::getScreen(array('isFlickerfree' => $this->isFlickerfree, 'pageFile' => $this->pageFile, 'mode' => $this->mode, 'timestamp' => $this->timestamp, 'hostid' => $this->hostid, 'profileIdx' => $this->profileIdx, 'profileIdx2' => $this->profileIdx2, 'updateProfile' => $this->updateProfile, 'timeline' => $this->timeline, 'resourcetype' => $screenitem['resourcetype'], 'screenitem' => $screenitem));
                 if (!empty($screenBase)) {
                     if ($this->mode == SCREEN_MODE_EDIT && !empty($screenitem['screenitemid'])) {
                         $screenBase->action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitem['screenitemid'];
                     } elseif ($this->mode == SCREEN_MODE_EDIT && empty($screenitem['screenitemid'])) {
                         $screenBase->action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r;
                     }
                     $item = $screenBase->get();
                 } else {
                     $item = null;
                 }
             } else {
                 $item = array(SPACE);
                 if ($this->mode == SCREEN_MODE_EDIT) {
                     array_push($item, BR(), new CLink(_('Change'), $action, 'empty_change_link'));
                 }
             }
             // align
             $halign = 'def';
             if ($screenitem['halign'] == HALIGN_CENTER) {
                 $halign = 'cntr';
             }
             if ($screenitem['halign'] == HALIGN_LEFT) {
                 $halign = 'left';
             }
             if ($screenitem['halign'] == HALIGN_RIGHT) {
                 $halign = 'right';
             }
             $valign = 'def';
             if ($screenitem['valign'] == VALIGN_MIDDLE) {
                 $valign = 'mdl';
             }
             if ($screenitem['valign'] == VALIGN_TOP) {
                 $valign = 'top';
             }
             if ($screenitem['valign'] == VALIGN_BOTTOM) {
                 $valign = 'bttm';
             }
             if ($this->mode == SCREEN_MODE_EDIT && !$isEditForm) {
                 $item = new CDiv($item, 'draggable');
                 $item->setAttribute('id', 'position_' . $r . '_' . $c);
                 $item->setAttribute('data-xcoord', $c);
                 $item->setAttribute('data-ycoord', $r);
             }
             // colspan/rowspan
             $newColumn = new CCol($item, $halign . '_' . $valign . ' screenitem');
             if (!empty($screenitem['colspan'])) {
                 $newColumn->setColSpan($screenitem['colspan']);
             }
             if (!empty($screenitem['rowspan'])) {
                 $newColumn->setRowSpan($screenitem['rowspan']);
             }
             array_push($newColumns, $newColumn);
         }
         // action right cell
         if ($this->mode == SCREEN_MODE_EDIT) {
             $icon = new CImg('images/general/minus.png', null, null, null, 'pointer');
             if ($emptyScreenRow) {
                 $removeRowLink = 'javascript: location.href = "screenedit.php?screenid=' . $this->screen['screenid'] . '&rmv_row=' . $r . '";';
             } else {
                 $removeRowLink = 'javascript: if (Confirm("' . _('This screen-row is not empty. Delete it?') . '")) {' . ' location.href = "screenedit.php?screenid=' . $this->screen['screenid'] . '&rmv_row=' . $r . '"; }';
             }
             $icon->addAction('onclick', $removeRowLink);
             array_push($newColumns, new CCol($icon));
         }
         $screenTable->addRow(new CRow($newColumns));
     }
     // action bottom row
     if ($this->mode == SCREEN_MODE_EDIT) {
         $icon = new CImg('images/general/plus.png', null, null, null, 'pointer');
         $icon->addAction('onclick', 'javascript: location.href = "screenedit.php?screenid=' . $this->screen['screenid'] . '&add_row=' . $this->screen['vsize'] . '";');
         $newColumns = array(new CCol($icon));
         for ($i = 0; $i < $this->screen['hsize']; $i++) {
             $icon = new CImg('images/general/minus.png', null, null, null, 'pointer');
             if (isset($emptyScreenColumns[$i])) {
                 $removeColumnLink = 'javascript: if (Confirm("' . _('This screen-column is not empty. Delete it?') . '")) {' . ' location.href = "screenedit.php?screenid=' . $this->screen['screenid'] . '&rmv_col=' . $i . '"; }';
             } else {
                 $removeColumnLink = 'javascript: location.href = "screenedit.php?config=1&screenid=' . $this->screen['screenid'] . '&rmv_col=' . $i . '";';
             }
             $icon->addAction('onclick', $removeColumnLink);
             array_push($newColumns, new CCol($icon));
         }
         array_push($newColumns, new CCol(new CImg('images/general/zero.png', 'zero', 1, 1)));
         $screenTable->addRow($newColumns);
     }
     return $screenTable;
 }
    $dependenciesTable->setHeader(array(_('Name'), _('Action')));
    foreach ($this->data['dependencies'] as $dependency) {
        $triggersForm->addVar('dependencies[]', $dependency['triggerid'], 'dependencies_' . $dependency['triggerid']);
        $hostNames = array();
        foreach ($dependency['hosts'] as $host) {
            $hostNames[] = CHtml::encode($host['name']);
            $hostNames[] = ', ';
        }
        array_pop($hostNames);
        if ($dependency['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
            $description = new CLink(array($hostNames, NAME_DELIMITER, CHtml::encode($dependency['description'])), 'triggers.php?form=update&hostid=' . $dependency['hostid'] . '&triggerid=' . $dependency['triggerid']);
            $description->setAttribute('target', '_blank');
        } else {
            $description = array($hostNames, NAME_DELIMITER, $dependency['description']);
        }
        $row = new CRow(array($description, new CButton('remove', _('Remove'), 'javascript: removeDependency(\'' . $dependency['triggerid'] . '\');', 'link_menu')));
        $row->setAttribute('id', 'dependency_' . $dependency['triggerid']);
        $dependenciesTable->addRow($row);
    }
    $dependenciesDiv = new CDiv(array($dependenciesTable, new CButton('btn1', _('Add'), 'return PopUp("popup.php?' . 'dstfrm=massupdate' . '&dstact=add_dependency' . '&reference=deptrigger' . '&dstfld1=new_dependency' . '&srctbl=triggers' . '&objname=triggers' . '&srcfld1=triggerid' . '&multiselect=1' . '&with_triggers=1", 1000, 700);', 'link_menu')), 'objectgroup inlineblock border_dotted ui-corner-all');
    $dependenciesDiv->setAttribute('id', 'dependencies_div');
    $triggersFormList->addRow(array(_('Replace dependencies'), SPACE, new CVisibilityBox('visible[dependencies]', isset($this->data['visible']['dependencies']), 'dependencies_div', _('Original'))), $dependenciesDiv);
}
// append tabs to form
$triggersTab = new CTabView();
$triggersTab->addTab('triggersTab', _('Mass update'), $triggersFormList);
$triggersForm->addItem($triggersTab);
// append buttons to form
$triggersForm->addItem(makeFormFooter(new CSubmit('massupdate', _('Update')), new CButtonCancel(url_params(array('groupid', 'hostid', 'parent_discoveryid')))));
$triggersWidget->addItem($triggersForm);
return $triggersWidget;
示例#22
0
        }
        array_pop($sub_menu_row);
        $sub_menu_div = new CDiv($sub_menu_row);
        $sub_menu_div->setAttribute('id', 'sub_' . $label);
        $sub_menu_div->addAction('onmouseover', 'javascript: MMenu.submenu_mouseOver();');
        $sub_menu_div->addAction('onmouseout', 'javascript: MMenu.mouseOut();');
        if (isset($page['menu']) && $page['menu'] == $label) {
            $menu_selected = true;
            $sub_menu_div->setAttribute('style', 'display: block;');
            insert_js('MMenu.def_label = ' . zbx_jsvalue($label));
        } else {
            $sub_menu_div->setAttribute('style', 'display: none;');
        }
        $menu_divs[] = $sub_menu_div;
    }
    $sub_menu_div = new CDiv(SPACE);
    $sub_menu_div->setAttribute('id', 'sub_empty');
    $sub_menu_div->setAttribute('style', 'display: ' . ($menu_selected ? 'none;' : 'block;'));
    $menu_divs[] = $sub_menu_div;
    $search_div = null;
    if ($page['file'] != 'index.php' && CWebUser::$data['userid'] > 0) {
        $searchForm = new CView('general.search');
        $search_div = $searchForm->render();
    }
    $sub_menu_table->addRow(array($menu_divs, $search_div));
    $page_menu->addItem($sub_menu_table);
    $page_menu->show();
}
// create history
if (isset($page['hist_arg']) && CWebUser::$data['alias'] != ZBX_GUEST_USER && $page['type'] == PAGE_TYPE_HTML && !defined('ZBX_PAGE_NO_MENU')) {
    $table = new CTable(null, 'history left');
示例#23
0
function show_messages($bool = true, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $message = array();
    $width = 0;
    $height = 0;
    if (!$bool && !is_null($errmsg)) {
        $msg = _('ERROR') . ': ' . $errmsg;
    } elseif ($bool && !is_null($okmsg)) {
        $msg = $okmsg;
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                array_push($message, array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68), 'font' => 2));
                $width = max($width, imagefontwidth(2) * zbx_strlen($msg) + 1);
                $height += imagefontheight(2) + 1;
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(_('Details'), 'blacklink');
                    $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");');
                    $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            $msg_font = 2;
            foreach ($ZBX_MESSAGES as $msg) {
                if ($msg['type'] == 'error') {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55), 'font' => $msg_font));
                } else {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55), 'font' => $msg_font));
                }
                $width = max($width, imagefontwidth($msg_font) * zbx_strlen($msg['message']) + 1);
                $height += imagefontheight($msg_font) + 1;
            }
        } elseif ($page['type'] == PAGE_TYPE_XML) {
            foreach ($ZBX_MESSAGES as $msg) {
                echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
            }
        } else {
            $lst_error = new CList(null, 'messages');
            foreach ($ZBX_MESSAGES as $msg) {
                $lst_error->addItem($msg['message'], $msg['type']);
                $bool = $bool && 'error' != zbx_strtolower($msg['type']);
            }
            $msg_show = 6;
            $msg_count = count($ZBX_MESSAGES);
            if ($msg_count > $msg_show) {
                $msg_count = $msg_show * 16;
                $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
            }
            $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
            $tab->setCellPadding(0);
            $tab->setCellSpacing(0);
            $tab->setAttribute('id', 'msg_messages');
            $tab->setAttribute('style', 'width: 100%;');
            if (isset($msg_tab) && $bool) {
                $tab->setAttribute('style', 'display: none;');
            }
            $tab->addRow(new CCol($lst_error, 'msg'));
            $tab->show();
        }
        $ZBX_MESSAGES = null;
    }
    if ($page['type'] == PAGE_TYPE_IMAGE && count($message) > 0) {
        $width += 2;
        $height += 2;
        $canvas = imagecreate($width, $height);
        imagefilledrectangle($canvas, 0, 0, $width, $height, imagecolorallocate($canvas, 255, 255, 255));
        foreach ($message as $id => $msg) {
            $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0);
            $message[$id]['h'] = imagefontheight($msg['font']);
            imagestring($canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']));
            $previd = $id;
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
        if ($inventory_mode == HOST_INVENTORY_AUTOMATIC) {
            $input->setAttribute('disabled', 'disabled');
        }
    } else {
        $populatingItemCell = '';
    }
    $input->addStyle('float: left;');
    $populatingItem = new CSpan($populatingItemCell, 'populating_item');
    if ($inventory_mode != HOST_INVENTORY_AUTOMATIC) {
        // those links are visible only in automatic mode
        $populatingItem->addStyle('display: none');
    }
    $inventoryFormList->addRow($inventoryInfo['title'], array($input, $populatingItem));
}
// clearing the float
$clearFixDiv = new CDiv();
$clearFixDiv->addStyle('clear: both;');
$inventoryFormList->addRow('', $clearFixDiv);
$divTabs->addTab('inventoryTab', _('Host inventory'), $inventoryFormList);
$frmHost->addItem($divTabs);
/*
 * footer
 */
$others = array();
// do not display the clone and delete buttons for clone forms and new host forms
if (getRequest('hostid') && !in_array(getRequest('form'), array('clone', 'full_clone'))) {
    $others[] = new CSubmit('clone', _('Clone'));
    $others[] = new CSubmit('full_clone', _('Full clone'));
    $others[] = new CButtonDelete(_('Delete selected host?'), url_param('form') . url_param('hostid') . url_param('groupid'));
}
$others[] = new CButtonCancel(url_param('groupid'));
示例#25
0
 public function toString($destroy = true)
 {
     $this->addItem($this->formList);
     return parent::toString($destroy);
 }
示例#26
0
        $trigger = '';
    }
    $row = new CRow(array(new CCol(S_TRIGGER, 'form_row_l'), new CCol(array(new CTextBox('trigger', $trigger, 96, 'yes'), new CButton("btn1", S_SELECT, "return PopUp('popup.php?" . "dstfrm=" . $filterForm->getName() . "&dstfld1=triggerid&dstfld2=trigger" . "&srctbl=triggers&srcfld1=triggerid&srcfld2=description&real_hosts=1');", 'T')), 'form_row_r')));
    $filterForm->addRow($row);
    $filterForm->addVar('hide_unknown', $_REQUEST['hide_unknown']);
    $unkcbx = new CCheckBox('hide_unk', $_REQUEST['hide_unknown'], null, '1');
    $unkcbx->setAction('javascript: create_var("' . $filterForm->GetName() . '", "hide_unknown", (this.checked?1:0), 0); ');
    $filterForm->addRow(S_HIDE_UNKNOWN, $unkcbx);
    $reset = new CButton('filter_rst', S_RESET);
    $reset->setType('button');
    $reset->setAction('javascript: var uri = new Curl(location.href); uri.setArgument("filter_rst",1); location.href = uri.getUrl();');
    $filterForm->addItemToBottomRow(new CButton('filter_set', S_FILTER));
    $filterForm->addItemToBottomRow($reset);
}
$events_wdgt->addFlicker($filterForm, CProfile::get('web.events.filter.state', 0));
$scroll_div = new CDiv();
$scroll_div->setAttribute('id', 'scrollbar_cntr');
$events_wdgt->addFlicker($scroll_div, CProfile::get('web.events.filter.state', 0));
// }}} FILTER
$table = new CTableInfo(S_NO_EVENTS_FOUND);
// CHECK IF EVENTS EXISTS {{{
$options = array('output' => API_OUTPUT_EXTEND, 'sortfield' => 'eventid', 'sortorder' => ZBX_SORT_UP, 'nopermissions' => 1, 'limit' => 1);
if ($source == EVENT_SOURCE_DISCOVERY) {
    $options['source'] = EVENT_SOURCE_DISCOVERY;
} else {
    if (isset($_REQUEST['triggerid']) && $_REQUEST['triggerid'] > 0) {
        $options['object'] = EVENT_OBJECT_TRIGGER;
        $options['triggerids'] = $_REQUEST['triggerid'];
    }
}
$firstEvent = CEvent::get($options);
示例#27
0
         $sub_menu_div->setAttribute('style', 'display: block;');
         insert_js('MMenu.def_label = ' . zbx_jsvalue($label));
     } else {
         $sub_menu_div->setAttribute('style', 'display: none;');
     }
     $menu_divs[] = $sub_menu_div;
 }
 $sub_menu_div = new CDiv(SPACE);
 $sub_menu_div->setAttribute('id', 'sub_empty');
 $sub_menu_div->setAttribute('style', 'display: ' . ($menu_selected ? 'none;' : 'block;'));
 $menu_divs[] = $sub_menu_div;
 $search_form = new CForm('search.php');
 $search_form->setMethod('get');
 $search_form->setAttribute('class', 'thin');
 $search_form->addItem(new CDiv(array(S_SEARCH_BIG . ': ', new CTextBox('search', '', 15))));
 $search_div = new CDiv($search_form);
 $search_div->setAttribute('id', 'zbx_search');
 $search_div->setAttribute('class', 'zbx_search');
 $sub_menu_table->addRow(array($menu_divs, $search_div));
 $page_menu->addItem($sub_menu_table);
 //---
 /* SEARCH form
 		$search_form = new CForm('search.php');
 		$search_form->addItem(new CDiv(array(S_SEARCH_BIG.': ', new CTextBox('search','',20))));
 
 		$search_div = new CDiv($search_form);
 		$search_div->setAttribute('id','zbx_search');
 		$search_div->setAttribute('class','zbx_search');
 
 		$page_menu->addItem($search_div);
 //*/
示例#28
0
/**
 * Generate table for dashboard triggers popup.
 *
 * @see make_system_status
 *
 * @param array $triggers
 * @param array $ackParams
 * @param array $actions
 *
 * @return CTableInfo
 */
function makeTriggersPopup(array $triggers, array $ackParams, array $actions)
{
    $config = select_config();
    $popupTable = new CTableInfo();
    $popupTable->setAttribute('style', 'width: 400px;');
    $popupTable->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host'), _('Issue'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions')));
    CArrayHelper::sort($triggers, array(array('field' => 'lastchange', 'order' => ZBX_SORT_DOWN)));
    foreach ($triggers as $trigger) {
        // unknown triggers
        $unknown = SPACE;
        if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) {
            $unknown = new CDiv(SPACE, 'status_icon iconunknown');
            $unknown->setHint($trigger['error'], '', 'on');
        }
        // ack
        if ($config['event_ack_enable']) {
            $ack = isset($trigger['event']['eventid']) ? getEventAckState($trigger['event'], true, true, $ackParams) : _('No events');
        } else {
            $ack = null;
        }
        // action
        $action = isset($trigger['event']['eventid']) && isset($actions[$trigger['event']['eventid']]) ? $actions[$trigger['event']['eventid']] : _('-');
        $popupTable->addRow(array(get_node_name_by_elid($trigger['triggerid']), $trigger['hosts'][0]['name'], getSeverityCell($trigger['priority'], $trigger['description']), zbx_date2age($trigger['lastchange']), $unknown, $ack, $action));
    }
    return $popupTable;
}
示例#29
0
function getItemFilterForm(&$items)
{
    $filter_groupId = $_REQUEST['filter_groupid'];
    $filter_hostId = $_REQUEST['filter_hostid'];
    $filter_application = $_REQUEST['filter_application'];
    $filter_name = $_REQUEST['filter_name'];
    $filter_type = $_REQUEST['filter_type'];
    $filter_key = $_REQUEST['filter_key'];
    $filter_snmp_community = $_REQUEST['filter_snmp_community'];
    $filter_snmpv3_securityname = $_REQUEST['filter_snmpv3_securityname'];
    $filter_snmp_oid = $_REQUEST['filter_snmp_oid'];
    $filter_port = $_REQUEST['filter_port'];
    $filter_value_type = $_REQUEST['filter_value_type'];
    $filter_data_type = $_REQUEST['filter_data_type'];
    $filter_delay = $_REQUEST['filter_delay'];
    $filter_history = $_REQUEST['filter_history'];
    $filter_trends = $_REQUEST['filter_trends'];
    $filter_status = $_REQUEST['filter_status'];
    $filter_state = $_REQUEST['filter_state'];
    $filter_templated_items = $_REQUEST['filter_templated_items'];
    $filter_with_triggers = $_REQUEST['filter_with_triggers'];
    $subfilter_hosts = $_REQUEST['subfilter_hosts'];
    $subfilter_apps = $_REQUEST['subfilter_apps'];
    $subfilter_types = $_REQUEST['subfilter_types'];
    $subfilter_value_types = $_REQUEST['subfilter_value_types'];
    $subfilter_status = $_REQUEST['subfilter_status'];
    $subfilter_state = $_REQUEST['subfilter_state'];
    $subfilter_templated_items = $_REQUEST['subfilter_templated_items'];
    $subfilter_with_triggers = $_REQUEST['subfilter_with_triggers'];
    $subfilter_history = $_REQUEST['subfilter_history'];
    $subfilter_trends = $_REQUEST['subfilter_trends'];
    $subfilter_interval = $_REQUEST['subfilter_interval'];
    $form = new CForm('get');
    $form->setAttribute('name', 'zbx_filter');
    $form->setAttribute('id', 'zbx_filter');
    $form->addVar('subfilter_hosts', $subfilter_hosts);
    $form->addVar('subfilter_apps', $subfilter_apps);
    $form->addVar('subfilter_types', $subfilter_types);
    $form->addVar('subfilter_value_types', $subfilter_value_types);
    $form->addVar('subfilter_status', $subfilter_status);
    $form->addVar('subfilter_state', $subfilter_state);
    $form->addVar('subfilter_templated_items', $subfilter_templated_items);
    $form->addVar('subfilter_with_triggers', $subfilter_with_triggers);
    $form->addVar('subfilter_history', $subfilter_history);
    $form->addVar('subfilter_trends', $subfilter_trends);
    $form->addVar('subfilter_interval', $subfilter_interval);
    // type select
    $fTypeVisibility = array();
    $cmbType = new CComboBox('filter_type', $filter_type);
    $cmbType->setAttribute('id', 'filter_type');
    $cmbType->addItem(-1, _('all'));
    foreach (array('filter_delay_label', 'filter_delay') as $vItem) {
        zbx_subarray_push($fTypeVisibility, -1, $vItem);
    }
    $itemTypes = item_type2str();
    unset($itemTypes[ITEM_TYPE_HTTPTEST]);
    // httptest items are only for internal zabbix logic
    $cmbType->addItems($itemTypes);
    foreach ($itemTypes as $typeNum => $typeLabel) {
        if ($typeNum != ITEM_TYPE_TRAPPER) {
            zbx_subarray_push($fTypeVisibility, $typeNum, 'filter_delay_label');
            zbx_subarray_push($fTypeVisibility, $typeNum, 'filter_delay');
        }
        switch ($typeNum) {
            case ITEM_TYPE_SNMPV1:
            case ITEM_TYPE_SNMPV2C:
                $snmp_types = array('filter_snmp_community_label', 'filter_snmp_community', 'filter_snmp_oid_label', 'filter_snmp_oid', 'filter_port_label', 'filter_port');
                foreach ($snmp_types as $vItem) {
                    zbx_subarray_push($fTypeVisibility, $typeNum, $vItem);
                }
                break;
            case ITEM_TYPE_SNMPV3:
                foreach (array('filter_snmpv3_securityname_label', 'filter_snmpv3_securityname', 'filter_snmp_oid_label', 'filter_snmp_oid', 'filter_port_label', 'filter_port') as $vItem) {
                    zbx_subarray_push($fTypeVisibility, $typeNum, $vItem);
                }
                break;
        }
    }
    zbx_add_post_js("var filterTypeSwitcher = new CViewSwitcher('filter_type', 'change', " . zbx_jsvalue($fTypeVisibility, true) . ');');
    // type of information select
    $fVTypeVisibility = array();
    $cmbValType = new CComboBox('filter_value_type', $filter_value_type);
    $cmbValType->addItem(-1, _('all'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_UINT64, _('Numeric (unsigned)'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_FLOAT, _('Numeric (float)'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_STR, _('Character'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_LOG, _('Log'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_TEXT, _('Text'));
    foreach (array('filter_data_type_label', 'filter_data_type') as $vItem) {
        zbx_subarray_push($fVTypeVisibility, ITEM_VALUE_TYPE_UINT64, $vItem);
    }
    zbx_add_post_js("var filterValueTypeSwitcher = new CViewSwitcher('filter_value_type', 'change', " . zbx_jsvalue($fVTypeVisibility, true) . ');');
    // status select
    $cmbStatus = new CComboBox('filter_status', $filter_status);
    $cmbStatus->addItem(-1, _('all'));
    foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED) as $status) {
        $cmbStatus->addItem($status, item_status2str($status));
    }
    // state select
    $cmbState = new CComboBox('filter_state', $filter_state);
    $cmbState->addItem(-1, _('all'));
    foreach (array(ITEM_STATE_NORMAL, ITEM_STATE_NOTSUPPORTED) as $state) {
        $cmbState->addItem($state, itemState($state));
    }
    // update interval
    $updateIntervalLabel = new CSpan(array(bold(_('Update interval')), SPACE . _('(in sec)') . NAME_DELIMITER));
    $updateIntervalLabel->setAttribute('id', 'filter_delay_label');
    $updateIntervalInput = new CNumericBox('filter_delay', $filter_delay, 5, false, true);
    $updateIntervalInput->setEnabled('no');
    // data type
    $dataTypeLabel = new CSpan(bold(_('Data type') . NAME_DELIMITER));
    $dataTypeLabel->setAttribute('id', 'filter_data_type_label');
    $dataTypeInput = new CComboBox('filter_data_type', $filter_data_type);
    $dataTypeInput->addItem(-1, _('all'));
    $dataTypeInput->addItems(item_data_type2str());
    $dataTypeInput->setEnabled('no');
    // filter table
    $table = new CTable('', 'filter');
    $table->setCellPadding(0);
    $table->setCellSpacing(0);
    // SNMP community
    $snmpCommunityLabel = new CSpan(array(bold(_('SNMP community')), SPACE . _('like') . NAME_DELIMITER));
    $snmpCommunityLabel->setAttribute('id', 'filter_snmp_community_label');
    $snmpCommunityField = new CTextBox('filter_snmp_community', $filter_snmp_community, ZBX_TEXTBOX_FILTER_SIZE);
    $snmpCommunityField->setEnabled('no');
    // SNMPv3 security name
    $snmpSecurityLabel = new CSpan(array(bold(_('Security name')), SPACE . _('like') . NAME_DELIMITER));
    $snmpSecurityLabel->setAttribute('id', 'filter_snmpv3_securityname_label');
    $snmpSecurityField = new CTextBox('filter_snmpv3_securityname', $filter_snmpv3_securityname, ZBX_TEXTBOX_FILTER_SIZE);
    $snmpSecurityField->setEnabled('no');
    // SNMP OID
    $snmpOidLabel = new CSpan(array(bold(_('SNMP OID')), SPACE . _('like') . NAME_DELIMITER));
    $snmpOidLabel->setAttribute('id', 'filter_snmp_oid_label');
    $snmpOidField = new CTextBox('filter_snmp_oid', $filter_snmp_oid, ZBX_TEXTBOX_FILTER_SIZE);
    $snmpOidField->setEnabled('no');
    // port
    $portLabel = new CSpan(array(bold(_('Port')), SPACE . _('like') . NAME_DELIMITER));
    $portLabel->setAttribute('id', 'filter_port_label');
    $portField = new CNumericBox('filter_port', $filter_port, 5, false, true);
    $portField->setEnabled('no');
    // row 1
    $groupFilter = null;
    if (!empty($filter_groupId)) {
        $getHostInfo = API::HostGroup()->get(array('groupids' => $filter_groupId, 'output' => array('name')));
        $getHostInfo = reset($getHostInfo);
        if (!empty($getHostInfo)) {
            $groupFilter[] = array('id' => $getHostInfo['groupid'], 'name' => $getHostInfo['name']);
        }
    }
    $table->addRow(array(new CCol(bold(_('Host group') . NAME_DELIMITER), 'label col1'), new CCol(array(new CMultiSelect(array('name' => 'filter_groupid', 'selectedLimit' => 1, 'objectName' => 'hostGroup', 'objectOptions' => array('editable' => true), 'data' => $groupFilter, 'popup' => array('parameters' => 'srctbl=host_groups&dstfrm=' . $form->getName() . '&dstfld1=filter_groupid' . '&srcfld1=groupid&writeonly=1', 'width' => 450, 'height' => 450, 'buttonClass' => 'input filter-multiselect-select-button')))), 'col1'), new CCol(bold(_('Type') . NAME_DELIMITER), 'label col2'), new CCol($cmbType, 'col2'), new CCol(bold(_('Type of information') . NAME_DELIMITER), 'label col3'), new CCol($cmbValType, 'col3'), new CCol(bold(_('State') . NAME_DELIMITER), 'label'), new CCol($cmbState, 'col4')), 'item-list-row');
    // row 2
    $hostFilterData = null;
    if (!empty($filter_hostId)) {
        $getHostInfo = API::Host()->get(array('hostids' => $filter_hostId, 'templated_hosts' => true, 'output' => array('name')));
        $getHostInfo = reset($getHostInfo);
        if (!empty($getHostInfo)) {
            $hostFilterData[] = array('id' => $getHostInfo['hostid'], 'name' => $getHostInfo['name']);
        }
    }
    $table->addRow(array(new CCol(bold(_('Host') . NAME_DELIMITER), 'label'), new CCol(array(new CMultiSelect(array('name' => 'filter_hostid', 'selectedLimit' => 1, 'objectName' => 'hosts', 'objectOptions' => array('editable' => true, 'templated_hosts' => true), 'data' => $hostFilterData, 'popup' => array('parameters' => 'srctbl=host_templates&dstfrm=' . $form->getName() . '&dstfld1=filter_hostid' . '&srcfld1=hostid&writeonly=1', 'width' => 450, 'height' => 450, 'buttonClass' => 'input filter-multiselect-select-button')))), 'col1'), new CCol($updateIntervalLabel, 'label'), new CCol($updateIntervalInput), new CCol($dataTypeLabel, 'label'), new CCol($dataTypeInput), new CCol(bold(_('Status') . NAME_DELIMITER), 'label col4'), new CCol($cmbStatus, 'col4')), 'item-list-row');
    // row 3
    $table->addRow(array(new CCol(bold(_('Application') . NAME_DELIMITER), 'label'), new CCol(array(new CTextBox('filter_application', $filter_application, ZBX_TEXTBOX_FILTER_SIZE), new CButton('btn_app', _('Select'), 'return PopUp("popup.php?srctbl=applications&srcfld1=name' . '&dstfrm=' . $form->getName() . '&dstfld1=filter_application' . '&with_applications=1' . '" + (jQuery("input[name=\'filter_hostid\']").length > 0 ? "&hostid="+jQuery("input[name=\'filter_hostid\']").val() : "")' . ', 550, 450, "application");', 'filter-select-button')), 'col1'), new CCol(array($snmpCommunityLabel, $snmpSecurityLabel), 'label'), new CCol(array($snmpCommunityField, $snmpSecurityField)), new CCol(array(bold(_('History')), SPACE . _('(in days)') . NAME_DELIMITER), 'label'), new CCol(new CNumericBox('filter_history', $filter_history, 8, false, true)), new CCol(bold(_('Triggers') . NAME_DELIMITER), 'label'), new CCol(new CComboBox('filter_with_triggers', $filter_with_triggers, null, array(-1 => _('all'), 1 => _('With triggers'), 0 => _('Without triggers'))))), 'item-list-row');
    // row 4
    $table->addRow(array(new CCol(array(bold(_('Name')), SPACE . _('like') . NAME_DELIMITER), 'label'), new CCol(new CTextBox('filter_name', $filter_name, ZBX_TEXTBOX_FILTER_SIZE), 'col1'), new CCol($snmpOidLabel, 'label'), new CCol($snmpOidField), new CCol(array(bold(_('Trends')), SPACE . _('(in days)') . NAME_DELIMITER), 'label'), new CCol(new CNumericBox('filter_trends', $filter_trends, 8, false, true)), new CCol(bold(_('Template') . NAME_DELIMITER), 'label'), new CCol(new CComboBox('filter_templated_items', $filter_templated_items, null, array(-1 => _('all'), 1 => _('Templated items'), 0 => _('Not Templated items'))))), 'item-list-row');
    // row 5
    $table->addRow(array(new CCol(array(bold(_('Key')), SPACE . _('like') . NAME_DELIMITER), 'label'), new CCol(new CTextBox('filter_key', $filter_key, ZBX_TEXTBOX_FILTER_SIZE), 'col1'), new CCol($portLabel, 'label'), new CCol($portField), new CCol(null, 'label'), new CCol(), new CCol(null, 'label'), new CCol()), 'item-list-row');
    $filter = new CSubmit('filter_set', _('Filter'), 'chkbxRange.clearSelectedOnFilterChange();');
    $filter->useJQueryStyle('main');
    $reset = new CSubmit('filter_rst', _('Reset'), 'chkbxRange.clearSelectedOnFilterChange();');
    $reset->useJQueryStyle();
    $div_buttons = new CDiv(array($filter, SPACE, $reset));
    $div_buttons->setAttribute('style', 'padding: 4px 0px;');
    $footer = new CCol($div_buttons, 'controls', 8);
    $table->addRow($footer);
    $form->addItem($table);
    // subfilters
    $table_subfilter = new CTable(null, 'filter sub-filter');
    // array contains subfilters and number of items in each
    $item_params = array('hosts' => array(), 'applications' => array(), 'types' => array(), 'value_types' => array(), 'status' => array(), 'state' => array(), 'templated_items' => array(), 'with_triggers' => array(), 'history' => array(), 'trends' => array(), 'interval' => array());
    // generate array with values for subfilters of selected items
    foreach ($items as $item) {
        // hosts
        if (zbx_empty($filter_hostId)) {
            $host = reset($item['hosts']);
            if (!isset($item_params['hosts'][$host['hostid']])) {
                $item_params['hosts'][$host['hostid']] = array('name' => $host['name'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_hosts') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $host = reset($item['hosts']);
                $item_params['hosts'][$host['hostid']]['count']++;
            }
        }
        // applications
        if (!empty($item['applications'])) {
            foreach ($item['applications'] as $application) {
                if (!isset($item_params['applications'][$application['name']])) {
                    $item_params['applications'][$application['name']] = array('name' => $application['name'], 'count' => 0);
                }
            }
        }
        $show_item = true;
        foreach ($item['subfilters'] as $name => $value) {
            if ($name == 'subfilter_apps') {
                continue;
            }
            $show_item &= $value;
        }
        $sel_app = false;
        if ($show_item) {
            // if any of item applications are selected
            foreach ($item['applications'] as $app) {
                if (str_in_array($app['name'], $subfilter_apps)) {
                    $sel_app = true;
                    break;
                }
            }
            foreach ($item['applications'] as $app) {
                if (str_in_array($app['name'], $subfilter_apps) || !$sel_app) {
                    $item_params['applications'][$app['name']]['count']++;
                }
            }
        }
        // types
        if ($filter_type == -1) {
            if (!isset($item_params['types'][$item['type']])) {
                $item_params['types'][$item['type']] = array('name' => item_type2str($item['type']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_types') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['types'][$item['type']]['count']++;
            }
        }
        // value types
        if ($filter_value_type == -1) {
            if (!isset($item_params['value_types'][$item['value_type']])) {
                $item_params['value_types'][$item['value_type']] = array('name' => itemValueTypeString($item['value_type']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_value_types') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['value_types'][$item['value_type']]['count']++;
            }
        }
        // status
        if ($filter_status == -1) {
            if (!isset($item_params['status'][$item['status']])) {
                $item_params['status'][$item['status']] = array('name' => item_status2str($item['status']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_status') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['status'][$item['status']]['count']++;
            }
        }
        // state
        if ($filter_state == -1) {
            if (!isset($item_params['state'][$item['state']])) {
                $item_params['state'][$item['state']] = array('name' => itemState($item['state']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_state') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['state'][$item['state']]['count']++;
            }
        }
        // template
        if ($filter_templated_items == -1) {
            if ($item['templateid'] == 0 && !isset($item_params['templated_items'][0])) {
                $item_params['templated_items'][0] = array('name' => _('Not Templated items'), 'count' => 0);
            } elseif ($item['templateid'] > 0 && !isset($item_params['templated_items'][1])) {
                $item_params['templated_items'][1] = array('name' => _('Templated items'), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_templated_items') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                if ($item['templateid'] == 0) {
                    $item_params['templated_items'][0]['count']++;
                } else {
                    $item_params['templated_items'][1]['count']++;
                }
            }
        }
        // with triggers
        if ($filter_with_triggers == -1) {
            if (count($item['triggers']) == 0 && !isset($item_params['with_triggers'][0])) {
                $item_params['with_triggers'][0] = array('name' => _('Without triggers'), 'count' => 0);
            } elseif (count($item['triggers']) > 0 && !isset($item_params['with_triggers'][1])) {
                $item_params['with_triggers'][1] = array('name' => _('With triggers'), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_with_triggers') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                if (count($item['triggers']) == 0) {
                    $item_params['with_triggers'][0]['count']++;
                } else {
                    $item_params['with_triggers'][1]['count']++;
                }
            }
        }
        // trends
        if (zbx_empty($filter_trends)) {
            if (!isset($item_params['trends'][$item['trends']])) {
                $item_params['trends'][$item['trends']] = array('name' => $item['trends'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_trends') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['trends'][$item['trends']]['count']++;
            }
        }
        // history
        if (zbx_empty($filter_history)) {
            if (!isset($item_params['history'][$item['history']])) {
                $item_params['history'][$item['history']] = array('name' => $item['history'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_history') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['history'][$item['history']]['count']++;
            }
        }
        // interval
        if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER) {
            if (!isset($item_params['interval'][$item['delay']])) {
                $item_params['interval'][$item['delay']] = array('name' => $item['delay'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_interval') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['interval'][$item['delay']]['count']++;
            }
        }
    }
    // output
    if (zbx_empty($filter_hostId) && count($item_params['hosts']) > 1) {
        $hosts_output = prepareSubfilterOutput($item_params['hosts'], $subfilter_hosts, 'subfilter_hosts');
        $table_subfilter->addRow(array(_('Hosts'), $hosts_output));
    }
    if (!empty($item_params['applications']) && count($item_params['applications']) > 1) {
        $application_output = prepareSubfilterOutput($item_params['applications'], $subfilter_apps, 'subfilter_apps');
        $table_subfilter->addRow(array(_('Applications'), $application_output));
    }
    if ($filter_type == -1 && count($item_params['types']) > 1) {
        $type_output = prepareSubfilterOutput($item_params['types'], $subfilter_types, 'subfilter_types');
        $table_subfilter->addRow(array(_('Types'), $type_output));
    }
    if ($filter_value_type == -1 && count($item_params['value_types']) > 1) {
        $value_types_output = prepareSubfilterOutput($item_params['value_types'], $subfilter_value_types, 'subfilter_value_types');
        $table_subfilter->addRow(array(_('Type of information'), $value_types_output));
    }
    if ($filter_status == -1 && count($item_params['status']) > 1) {
        $status_output = prepareSubfilterOutput($item_params['status'], $subfilter_status, 'subfilter_status');
        $table_subfilter->addRow(array(_('Status'), $status_output));
    }
    if ($filter_state == -1 && count($item_params['state']) > 1) {
        $state_output = prepareSubfilterOutput($item_params['state'], $subfilter_state, 'subfilter_state');
        $table_subfilter->addRow(array(_('State'), $state_output));
    }
    if ($filter_templated_items == -1 && count($item_params['templated_items']) > 1) {
        $templated_items_output = prepareSubfilterOutput($item_params['templated_items'], $subfilter_templated_items, 'subfilter_templated_items');
        $table_subfilter->addRow(array(_('Template'), $templated_items_output));
    }
    if ($filter_with_triggers == -1 && count($item_params['with_triggers']) > 1) {
        $with_triggers_output = prepareSubfilterOutput($item_params['with_triggers'], $subfilter_with_triggers, 'subfilter_with_triggers');
        $table_subfilter->addRow(array(_('With triggers'), $with_triggers_output));
    }
    if (zbx_empty($filter_history) && count($item_params['history']) > 1) {
        $history_output = prepareSubfilterOutput($item_params['history'], $subfilter_history, 'subfilter_history');
        $table_subfilter->addRow(array(_('History'), $history_output));
    }
    if (zbx_empty($filter_trends) && count($item_params['trends']) > 1) {
        $trends_output = prepareSubfilterOutput($item_params['trends'], $subfilter_trends, 'subfilter_trends');
        $table_subfilter->addRow(array(_('Trends'), $trends_output));
    }
    if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER && count($item_params['interval']) > 1) {
        $interval_output = prepareSubfilterOutput($item_params['interval'], $subfilter_interval, 'subfilter_interval');
        $table_subfilter->addRow(array(_('Interval'), $interval_output));
    }
    $form->addItem(new CDiv(_('Subfilter [affects only filtered data!]'), 'thin_header'));
    $form->addItem($table_subfilter);
    return $form;
}
示例#30
-1
function show_messages($bool = true, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $imageMessages = array();
    if (!$bool && !is_null($errmsg)) {
        $msg = _('ERROR') . ': ' . $errmsg;
    } elseif ($bool && !is_null($okmsg)) {
        $msg = $okmsg;
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                // save all of the messages in an array to display them later in an image
                $imageMessages[] = array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68));
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(_('Details'), 'blacklink');
                    $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");');
                    $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            foreach ($ZBX_MESSAGES as $msg) {
                // save all of the messages in an array to display them later in an image
                if ($msg['type'] == 'error') {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55));
                } else {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55));
                }
            }
        } elseif ($page['type'] == PAGE_TYPE_XML) {
            foreach ($ZBX_MESSAGES as $msg) {
                echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
            }
        } else {
            $lst_error = new CList(null, 'messages');
            foreach ($ZBX_MESSAGES as $msg) {
                $lst_error->addItem($msg['message'], $msg['type']);
                $bool = $bool && 'error' !== strtolower($msg['type']);
            }
            $msg_show = 6;
            $msg_count = count($ZBX_MESSAGES);
            if ($msg_count > $msg_show) {
                $msg_count = $msg_show * 16;
                $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
            }
            $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
            $tab->setCellPadding(0);
            $tab->setCellSpacing(0);
            $tab->setAttribute('id', 'msg_messages');
            $tab->setAttribute('style', 'width: 100%;');
            if (isset($msg_tab) && $bool) {
                $tab->setAttribute('style', 'display: none;');
            }
            $tab->addRow(new CCol($lst_error, 'msg'));
            $tab->show();
        }
        $ZBX_MESSAGES = null;
    }
    // draw an image with the messages
    if ($page['type'] == PAGE_TYPE_IMAGE && count($imageMessages) > 0) {
        $imageFontSize = 8;
        // calculate the size of the text
        $imageWidth = 0;
        $imageHeight = 0;
        foreach ($imageMessages as &$msg) {
            $size = imageTextSize($imageFontSize, 0, $msg['text']);
            $msg['height'] = $size['height'] - $size['baseline'];
            // calculate the total size of the image
            $imageWidth = max($imageWidth, $size['width']);
            $imageHeight += $size['height'] + 1;
        }
        unset($msg);
        // additional padding
        $imageWidth += 2;
        $imageHeight += 2;
        // create the image
        $canvas = imagecreate($imageWidth, $imageHeight);
        imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255));
        // draw each message
        $y = 1;
        foreach ($imageMessages as $msg) {
            $y += $msg['height'];
            imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']);
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}