Beispiel #1
0
function screenIdents($screenids)
{
    $idents = array();
    $options = array('screenids' => $screenids, 'output' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true));
    $screens = CScreen::get($options);
    foreach ($screens as $inum => $screen) {
        $idents[$screen['screenid']] = array('node' => get_node_name_by_elid($screen['screenid'], true), 'name' => $screen['name']);
    }
    return $idents;
}
Beispiel #2
0
 protected function applyQueryOutputOptions($tableName, $tableAlias, array $options, array $sqlParts)
 {
     $sqlParts = parent::applyQueryOutputOptions($tableName, $tableAlias, $options, $sqlParts);
     if ($options['countOutput'] === null) {
         // request the templateid field for inheritance to work
         $sqlParts = $this->addQuerySelect($this->fieldId('templateid'), $sqlParts);
     }
     return $sqlParts;
 }
function make_screen_submenu()
{
    $fav_screens = get_favorites('web.favorite.screenids');
    $screenids = array();
    foreach ($fav_screens as $key => $favorite) {
        if ('screenid' == $favorite['source']) {
            $screenids[$favorite['value']] = $favorite['value'];
        }
    }
    $options = array('screenids' => $screenids, 'output' => API_OUTPUT_EXTEND);
    $screens = CScreen::get($options);
    $screens = zbx_toHash($screens, 'screenid');
    $favScreens = array();
    foreach ($fav_screens as $key => $favorite) {
        $source = $favorite['source'];
        $sourceid = $favorite['value'];
        if ('slideshowid' == $source) {
            if (!slideshow_accessible($sourceid, PERM_READ_ONLY)) {
                continue;
            }
            if (!($slide = get_slideshow_by_slideshowid($sourceid))) {
                continue;
            }
            $slide_added = true;
            $favScreens[] = array('name' => $slide['name'], 'favobj' => 'slideshowid', 'favid' => $slide['slideshowid'], 'action' => 'remove');
        } else {
            if (!isset($screens[$sourceid])) {
                continue;
            }
            $screen = $screens[$sourceid];
            $screen_added = true;
            $favScreens[] = array('name' => $screen['name'], 'favobj' => 'screenid', 'favid' => $screen['screenid'], 'action' => 'remove');
        }
    }
    if (isset($screen_added)) {
        $favScreens[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_SCREENS, 'favobj' => 'screenid', 'favid' => 0, 'action' => 'remove');
    }
    if (isset($slide_added)) {
        $favScreens[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_SLIDES, 'favobj' => 'slideshowid', 'favid' => 0, 'action' => 'remove');
    }
    return $favScreens;
}
function get_screen($screenid, $editmode, $effectiveperiod = NULL)
{
    global $USER_DETAILS;
    if ($screenid == 0) {
        return new CTableInfo(S_NO_SCREENS_DEFINED);
    }
    $r = CScreen::get(array('screenids' => $screenid, 'editable' => $editmode == 1 ? 1 : null, 'output' => API_OUTPUT_SHORTEN));
    if (empty($r)) {
        access_deny();
    }
    if (is_null($effectiveperiod)) {
        $effectiveperiod = ZBX_MIN_PERIOD;
    }
    $result = DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid=' . $screenid);
    $row = DBfetch($result);
    if (!$row) {
        return new CTableInfo(S_NO_SCREENS_DEFINED);
    }
    $sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid;
    $iresult = DBSelect($sql);
    $skip_field = array();
    $irows = array();
    while ($irow = DBfetch($iresult)) {
        $irows[] = $irow;
        for ($i = 0; $i < $irow['rowspan'] || $i == 0; $i++) {
            for ($j = 0; $j < $irow['colspan'] || $j == 0; $j++) {
                if ($i != 0 || $j != 0) {
                    if (!isset($skip_field[$irow['y'] + $i])) {
                        $skip_field[$irow['y'] + $i] = array();
                    }
                    $skip_field[$irow['y'] + $i][$irow['x'] + $j] = 1;
                }
            }
        }
    }
    $table = new CTable(new CLink(S_NO_ROWS_IN_SCREEN . SPACE . $row['name'], 'screenconf.php?config=0&form=update&screenid=' . $screenid), $editmode == 0 || $editmode == 2 ? 'screen_view' : 'screen_edit');
    $table->setAttribute('id', 'iframe');
    if ($editmode == 1) {
        $new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1)));
        for ($c = 0; $c < $row['hsize'] + 1; $c++) {
            $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer');
            $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_col={$c}';");
            array_push($new_cols, new Ccol($add_icon));
        }
        $table->addRow($new_cols);
    }
    $empty_screen_col = array();
    for ($r = 0; $r < $row['vsize']; $r++) {
        $new_cols = array();
        $empty_screen_row = true;
        if ($editmode == 1) {
            $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer');
            $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$r}';");
            array_push($new_cols, new Ccol($add_icon));
        }
        for ($c = 0; $c < $row['hsize']; $c++) {
            $item = array();
            if (isset($skip_field[$r][$c])) {
                continue;
            }
            $item_form = false;
            $irow = false;
            foreach ($irows as $tmprow) {
                if ($tmprow['x'] == $c && $tmprow['y'] == $r) {
                    $irow = $tmprow;
                    break;
                }
            }
            if ($irow) {
                $screenitemid = $irow['screenitemid'];
                $resourcetype = $irow['resourcetype'];
                $resourceid = $irow['resourceid'];
                $width = $irow['width'];
                $height = $irow['height'];
                $colspan = $irow['colspan'];
                $rowspan = $irow['rowspan'];
                $elements = $irow['elements'];
                $valign = $irow['valign'];
                $halign = $irow['halign'];
                $style = $irow['style'];
                $url = $irow['url'];
                $dynamic = $irow['dynamic'];
            } else {
                $screenitemid = 0;
                $resourcetype = 0;
                $resourceid = 0;
                $width = 0;
                $height = 0;
                $colspan = 0;
                $rowspan = 0;
                $elements = 0;
                $valign = VALIGN_DEFAULT;
                $halign = HALIGN_DEFAULT;
                $style = 0;
                $url = '';
                $dynamic = 0;
            }
            if ($screenitemid > 0) {
                $empty_screen_row = false;
                $empty_screen_col[$c] = 1;
            }
            if ($editmode == 1 && $screenitemid != 0) {
                $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&screenitemid=' . $screenitemid . "#form');";
                $action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitemid . '#form';
            } else {
                if ($editmode == 1 && $screenitemid == 0) {
                    $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&x=' . $c . '&y=' . $r . "#form');";
                    $action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r . '#form';
                } else {
                    $action = NULL;
                }
            }
            if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['x']) && $_REQUEST['x'] == $c && isset($_REQUEST['y']) && $_REQUEST['y'] == $r) {
                // click on empty field
                $item = get_screen_item_form();
                $item_form = true;
            } else {
                if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['screenitemid']) && bccomp($_REQUEST['screenitemid'], $screenitemid) == 0) {
                    // click on element
                    $item = get_screen_item_form();
                    $item_form = true;
                } else {
                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_GRAPH) {
                        if ($editmode == 0) {
                            $action = 'charts.php?graphid=' . $resourceid . url_param('period') . url_param('stime');
                        }
                        // GRAPH & ZOOM features
                        $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid;
                        $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid;
                        $graphDims = getGraphDims($resourceid);
                        $graphDims['graphHeight'] = $height;
                        $graphDims['width'] = $width;
                        $graph = get_graph_by_graphid($resourceid);
                        $graphid = $graph['graphid'];
                        $legend = $graph['show_legend'];
                        $graph3d = $graph['show_3d'];
                        //-------------
                        // Host feature
                        if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) {
                            $options = array('hostids' => $_REQUEST['hostid'], 'output' => array('hostid', 'host'));
                            $hosts = CHost::get($options);
                            $host = reset($hosts);
                            $options = array('graphids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_REFER, 'select_graph_items' => API_OUTPUT_EXTEND);
                            $graph = CGraph::get($options);
                            $graph = reset($graph);
                            if (count($graph['hosts']) == 1) {
                                // if items from one host we change them, or set calculated if not exist on that host
                                if ($graph['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymax_itemid']) {
                                    $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymax_itemid'])), $_REQUEST['hostid'], false);
                                    $new_dinamic = reset($new_dinamic);
                                    if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) {
                                        $graph['ymax_itemid'] = $new_dinamic['itemid'];
                                    } else {
                                        $graph['ymax_type'] = GRAPH_YAXIS_TYPE_CALCULATED;
                                    }
                                }
                                if ($graph['ymin_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymin_itemid']) {
                                    $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymin_itemid'])), $_REQUEST['hostid'], false);
                                    $new_dinamic = reset($new_dinamic);
                                    if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) {
                                        $graph['ymin_itemid'] = $new_dinamic['itemid'];
                                    } else {
                                        $graph['ymin_type'] = GRAPH_YAXIS_TYPE_CALCULATED;
                                    }
                                }
                            }
                            $url = $graph['graphtype'] == GRAPH_TYPE_PIE || $graph['graphtype'] == GRAPH_TYPE_EXPLODED ? 'chart7.php' : 'chart3.php';
                            $url = new Curl($url);
                            foreach ($graph as $name => $value) {
                                if ($name == 'width' || $name == 'height') {
                                    continue;
                                }
                                $url->setArgument($name, $value);
                            }
                            $new_items = get_same_graphitems_for_host($graph['gitems'], $_REQUEST['hostid'], false);
                            foreach ($new_items as $gitem) {
                                unset($gitem['gitemid']);
                                unset($gitem['graphid']);
                                foreach ($gitem as $name => $value) {
                                    $url->setArgument('items[' . $gitem['itemid'] . '][' . $name . ']', $value);
                                }
                            }
                            $url->setArgument('name', $host['host'] . ': ' . $graph['name']);
                            $url = $url->getUrl();
                        }
                        //-------------
                        $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0);
                        $default = false;
                        if ($graphDims['graphtype'] == GRAPH_TYPE_PIE || $graphDims['graphtype'] == GRAPH_TYPE_EXPLODED) {
                            if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) {
                                $url = 'chart6.php?graphid=' . $resourceid;
                                $default = true;
                            }
                            $timeline = array();
                            $timeline['period'] = $effectiveperiod;
                            $timeline['starttime'] = date('YmdHis', get_min_itemclock_by_graphid($resourceid));
                            if (isset($_REQUEST['stime'])) {
                                $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']);
                            }
                            // $src = $url.'&width='.$width.'&height='.$height.'&legend='.$legend.'&graph3d='.$graph3d;
                            $src = $url . '&width=' . $width . '&height=' . $height . '&legend=' . $legend . '&graph3d=' . $graph3d . '&period=' . $effectiveperiod . url_param('stime');
                            $objData['src'] = $src;
                        } else {
                            if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) {
                                $url = 'chart2.php?graphid=' . $resourceid;
                                $default = true;
                            }
                            $src = $url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime');
                            $timeline = array();
                            if (isset($graphid) && !is_null($graphid) && $editmode != 1) {
                                $timeline['period'] = $effectiveperiod;
                                $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD);
                                //get_min_itemclock_by_graphid($graphid);
                                if (isset($_REQUEST['stime'])) {
                                    $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']);
                                }
                                $objData['loadSBox'] = 1;
                            }
                            $objData['src'] = $src;
                        }
                        if ($editmode || !$default) {
                            $item = new CDiv();
                        } else {
                            $item = new CLink(null, $action);
                        }
                        $item->setAttribute('id', $containerid);
                        $item = array($item);
                        if ($editmode == 1) {
                            $item[] = BR();
                            $item[] = new CLink(S_CHANGE, $action);
                        }
                        if ($editmode == 2) {
                            insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');');
                        } else {
                            zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');');
                        }
                    } else {
                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) {
                            $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid;
                            $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid;
                            $graphDims = getGraphDims();
                            $graphDims['graphHeight'] = $height;
                            $graphDims['width'] = $width;
                            $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0);
                            // Host feature
                            if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) {
                                if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) {
                                    $resourceid = $newitemid;
                                } else {
                                    $resourceid = '';
                                }
                            }
                            //-------------
                            if ($editmode == 0 && !empty($resourceid)) {
                                $action = 'history.php?action=showgraph&itemid=' . $resourceid . url_param('period') . url_param('stime');
                            }
                            $timeline = array();
                            $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD);
                            if (!zbx_empty($resourceid) && $editmode != 1) {
                                $timeline['period'] = $effectiveperiod;
                                if (isset($_REQUEST['stime'])) {
                                    $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']);
                                }
                                $objData['loadSBox'] = 1;
                            }
                            $src = zbx_empty($resourceid) ? 'chart3.php?' : 'chart.php?itemid=' . $resourceid . '&';
                            $src .= $url . 'width=' . $width . '&height=' . $height;
                            $objData['src'] = $src;
                            if ($editmode) {
                                $item = new CDiv();
                            } else {
                                $item = new CLink(null, $action);
                            }
                            $item->setAttribute('id', $containerid);
                            $item = array($item);
                            if ($editmode == 1) {
                                $item[] = BR();
                                $item[] = new CLink(S_CHANGE, $action);
                            }
                            if ($editmode == 2) {
                                insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');');
                            } else {
                                zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');');
                            }
                        } else {
                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_MAP) {
                                $image_map = new CImg("map.php?noedit=1&sysmapid={$resourceid}" . "&width={$width}&height={$height}&curtime=" . time());
                                if ($editmode == 0) {
                                    $options = array('sysmapids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_selements' => API_OUTPUT_EXTEND, 'nopermissions' => 1);
                                    $sysmaps = CMap::get($options);
                                    $sysmap = reset($sysmaps);
                                    $action_map = getActionMapBySysmap($sysmap);
                                    $image_map->setMap($action_map->getName());
                                    $item = array($action_map, $image_map);
                                } else {
                                    $item = $image_map;
                                    //						$item = new CLink($image_map, $action);
                                }
                            } else {
                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) {
                                    // Host feature
                                    if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) {
                                        if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) {
                                            $resourceid = $newitemid;
                                        } else {
                                            $resourceid = 0;
                                        }
                                    }
                                    //-------------
                                    $item = array(get_screen_plaintext($resourceid, $elements, $style));
                                    if ($editmode == 1) {
                                        array_push($item, new CLink(S_CHANGE, $action));
                                    }
                                } else {
                                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTGROUP_TRIGGERS) {
                                        $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements);
                                        $tr_form = S_ALL_S;
                                        if ($resourceid > 0) {
                                            $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND);
                                            $hostgroups = CHostgroup::get($options);
                                            $hostgroup = reset($hostgroups);
                                            $tr_form = new CSpan(S_GROUP . ': ' . $hostgroup['name'], 'white');
                                            $params['groupids'] = $hostgroup['groupid'];
                                        } else {
                                            $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0));
                                            $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0));
                                            CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID);
                                            CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID);
                                            $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND);
                                            $groups = CHostGroup::get($options);
                                            order_result($groups, 'name');
                                            $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND);
                                            if ($groupid > 0) {
                                                $options['groupids'] = $groupid;
                                            }
                                            $hosts = CHost::get($options);
                                            $hosts = zbx_toHash($hosts, 'hostid');
                                            order_result($hosts, 'host');
                                            if (!isset($hosts[$hostid])) {
                                                $hostid = 0;
                                            }
                                            $tr_form = new CForm();
                                            $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()');
                                            $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()');
                                            $cmbGroup->addItem(0, S_ALL_SMALL);
                                            $cmbHosts->addItem(0, S_ALL_SMALL);
                                            foreach ($groups as $gnum => $group) {
                                                $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']);
                                            }
                                            foreach ($hosts as $hnum => $host) {
                                                $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']);
                                            }
                                            $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup));
                                            $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts));
                                            if ($groupid > 0) {
                                                $params['groupids'] = $groupid;
                                            }
                                            if ($hostid > 0) {
                                                $params['hostids'] = $hostid;
                                            }
                                        }
                                        $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form));
                                        $item[] = make_latest_issues($params);
                                        if ($editmode == 1) {
                                            array_push($item, new CLink(S_CHANGE, $action));
                                        }
                                        ///-----------------------
                                    } else {
                                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOST_TRIGGERS) {
                                            $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements);
                                            $tr_form = S_ALL_S;
                                            if ($resourceid > 0) {
                                                $options = array('hostids' => $resourceid, 'output' => API_OUTPUT_EXTEND);
                                                $hosts = CHost::get($options);
                                                $host = reset($hosts);
                                                $tr_form = new CSpan(S_HOST . ': ' . $host['host'], 'white');
                                                $params['hostids'] = $host['hostid'];
                                            } else {
                                                $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0));
                                                $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0));
                                                CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID);
                                                CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID);
                                                $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND);
                                                $groups = CHostGroup::get($options);
                                                order_result($groups, 'name');
                                                $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND);
                                                if ($groupid > 0) {
                                                    $options['groupids'] = $groupid;
                                                }
                                                $hosts = CHost::get($options);
                                                $hosts = zbx_toHash($hosts, 'hostid');
                                                order_result($hosts, 'host');
                                                if (!isset($hosts[$hostid])) {
                                                    $hostid = 0;
                                                }
                                                $tr_form = new CForm();
                                                $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()');
                                                $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()');
                                                $cmbGroup->addItem(0, S_ALL_SMALL);
                                                $cmbHosts->addItem(0, S_ALL_SMALL);
                                                foreach ($groups as $gnum => $group) {
                                                    $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']);
                                                }
                                                foreach ($hosts as $hnum => $host) {
                                                    $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']);
                                                }
                                                $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup));
                                                $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts));
                                                if ($groupid > 0) {
                                                    $params['groupids'] = $groupid;
                                                }
                                                if ($hostid > 0) {
                                                    $params['hostids'] = $hostid;
                                                }
                                            }
                                            ///-----------------------
                                            $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form));
                                            $item[] = make_latest_issues($params);
                                            if ($editmode == 1) {
                                                array_push($item, new CLink(S_CHANGE, $action));
                                            }
                                        } else {
                                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SYSTEM_STATUS) {
                                                $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => null, 'extAck' => 0);
                                                $item = array(get_table_header(array(S_SYSTEM_STATUS, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT))));
                                                $item[] = make_system_status($params);
                                                if ($editmode == 1) {
                                                    array_push($item, new CLink(S_CHANGE, $action));
                                                }
                                            } else {
                                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTS_INFO) {
                                                    $item = array(new CHostsInfo($resourceid, $style));
                                                    if ($editmode == 1) {
                                                        array_push($item, new CLink(S_CHANGE, $action));
                                                    }
                                                } else {
                                                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) {
                                                        $item = new CTriggersInfo($resourceid, null, $style);
                                                        $item = array($item);
                                                        if ($editmode == 1) {
                                                            array_push($item, new CLink(S_CHANGE, $action));
                                                        }
                                                    } else {
                                                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SERVER_INFO) {
                                                            //					$item = array(get_table_header(S_STATUS_OF_ZABBIX_BIG),make_status_of_zbx());
                                                            $item = array(new CServerInfo());
                                                            if ($editmode == 1) {
                                                                array_push($item, new CLink(S_CHANGE, $action));
                                                            }
                                                        } else {
                                                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_CLOCK) {
                                                                $item = new CFlashClock($width, $height, $style, $action);
                                                            } else {
                                                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SCREEN) {
                                                                    $item = array(get_screen($resourceid, 2, $effectiveperiod));
                                                                    if ($editmode == 1) {
                                                                        array_push($item, new CLink(S_CHANGE, $action));
                                                                    }
                                                                } else {
                                                                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_OVERVIEW) {
                                                                        $hostids = array();
                                                                        $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid);
                                                                        while ($tmp_host = DBfetch($res)) {
                                                                            $hostids[$tmp_host['hostid']] = $tmp_host['hostid'];
                                                                        }
                                                                        $item = array(get_triggers_overview($hostids, $style));
                                                                        if ($editmode == 1) {
                                                                            array_push($item, new CLink(S_CHANGE, $action));
                                                                        }
                                                                    } else {
                                                                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_DATA_OVERVIEW) {
                                                                            $hostids = array();
                                                                            $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid);
                                                                            while ($tmp_host = DBfetch($res)) {
                                                                                $hostids[$tmp_host['hostid']] = $tmp_host['hostid'];
                                                                            }
                                                                            $item = array(get_items_data_overview($hostids, $style));
                                                                            if ($editmode == 1) {
                                                                                array_push($item, new CLink(S_CHANGE, $action));
                                                                            }
                                                                        } else {
                                                                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_URL) {
                                                                                $item = array(new CIFrame($url, $width, $height, "auto"));
                                                                                if ($editmode == 1) {
                                                                                    array_push($item, BR(), new CLink(S_CHANGE, $action));
                                                                                }
                                                                            } else {
                                                                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_ACTIONS) {
                                                                                    $item = array(get_history_of_actions($elements));
                                                                                    if ($editmode == 1) {
                                                                                        array_push($item, new CLink(S_CHANGE, $action));
                                                                                    }
                                                                                } else {
                                                                                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_EVENTS) {
                                                                                        $options = array('monitored' => 1, 'value' => array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE), 'limit' => $elements);
                                                                                        $hide_unknown = CProfile::get('web.events.filter.hide_unknown', 0);
                                                                                        if ($hide_unknown) {
                                                                                            $options['value'] = array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE);
                                                                                        }
                                                                                        $item = new CTableInfo(S_NO_EVENTS_FOUND);
                                                                                        $item->SetHeader(array(S_TIME, is_show_all_nodes() ? S_NODE : null, S_HOST, S_DESCRIPTION, S_VALUE, S_SEVERITY));
                                                                                        $events = getLastEvents($options);
                                                                                        foreach ($events as $enum => $event) {
                                                                                            $trigger = $event['trigger'];
                                                                                            $host = $event['host'];
                                                                                            $value = new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value']));
                                                                                            //						$row = zbx_array_merge($triggers[$row['triggerid']],$row);
                                                                                            //						if((1 == $hide_unknown) && (!event_initial_time($row,$hide_unknown))) continue;
                                                                                            $item->addRow(array(zbx_date2str(S_EVENTS_TRIGGERS_EVENTS_HISTORY_LIST_DATE_FORMAT, $event['clock']), get_node_name_by_elid($event['objectid']), $host['host'], new CLink($trigger['description'], 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']), $value, new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority']))));
                                                                                        }
                                                                                        $item = array($item);
                                                                                        if ($editmode == 1) {
                                                                                            array_push($item, new CLink(S_CHANGE, $action));
                                                                                        }
                                                                                    } else {
                                                                                        $item = array(SPACE);
                                                                                        if ($editmode == 1) {
                                                                                            array_push($item, BR(), new CLink(S_CHANGE, $action));
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $str_halign = 'def';
            if ($halign == HALIGN_CENTER) {
                $str_halign = 'cntr';
            }
            if ($halign == HALIGN_LEFT) {
                $str_halign = 'left';
            }
            if ($halign == HALIGN_RIGHT) {
                $str_halign = 'right';
            }
            $str_valign = 'def';
            if ($valign == VALIGN_MIDDLE) {
                $str_valign = 'mdl';
            }
            if ($valign == VALIGN_TOP) {
                $str_valign = 'top';
            }
            if ($valign == VALIGN_BOTTOM) {
                $str_valign = 'bttm';
            }
            if ($editmode == 1 && !$item_form) {
                $item = new CDiv($item, 'draggable');
                $item->setAttribute('id', 'position_' . $r . '_' . $c);
                if ($editmode == 1) {
                    $item->setAttribute('onclick', 'javascript: ' . $onclick_action);
                }
            }
            $new_col = new CCol($item, $str_halign . '_' . $str_valign);
            if ($colspan) {
                $new_col->SetColSpan($colspan);
            }
            if ($rowspan) {
                $new_col->SetRowSpan($rowspan);
            }
            array_push($new_cols, $new_col);
        }
        if ($editmode == 1) {
            $rmv_icon = new Cimg('images/general/opened.gif', NULL, NULL, NULL, 'pointer');
            if ($empty_screen_row) {
                $rmv_row_link = "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_row={$r}';";
            } else {
                $rmv_row_link = "javascript: if(Confirm('" . S_THIS_SCREEN_ROW_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_row={$r}';}";
            }
            $rmv_icon->addAction('onclick', $rmv_row_link);
            array_push($new_cols, new Ccol($rmv_icon));
        }
        $table->addRow(new CRow($new_cols));
    }
    if ($editmode == 1) {
        $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer');
        $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$row['vsize']}';");
        $new_cols = array(new Ccol($add_icon));
        for ($c = 0; $c < $row['hsize']; $c++) {
            $rmv_icon = new Cimg('images/general/opened.gif', NULL, NULL, NULL, 'pointer');
            if (isset($empty_screen_col[$c])) {
                $rmv_col_link = "javascript: if(Confirm('" . S_THIS_SCREEN_COLUMN_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_col={$c}';}";
            } else {
                $rmv_col_link = "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_col={$c}';";
            }
            $rmv_icon->addAction('onclick', $rmv_col_link);
            array_push($new_cols, new Ccol($rmv_icon));
        }
        array_push($new_cols, new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1)));
        $table->addRow($new_cols);
    }
    return $table;
}
    /**
     * Get Screen data
     *
     * {@source}
     * @access public
     * @static
     * @since 1.8
     * @version 1
     *
     * @param _array $options
     * @param array $options['nodeids'] Node IDs
     * @param boolean $options['with_items'] only with items
     * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
     * @param int $options['extendoutput'] return all fields for Hosts
     * @param int $options['count'] count Hosts, returned column name is rowscount
     * @param string $options['pattern'] search hosts by pattern in host names
     * @param int $options['limit'] limit selection
     * @param string $options['order'] deprecated parameter (for now)
     * @return array|boolean Host data as array or false if error
     */
    public static function get($options = array())
    {
        global $USER_DETAILS;
        $result = array();
        $user_type = $USER_DETAILS['type'];
        $sort_columns = array('screenid', 'name');
        // allowed columns for sorting
        $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
        // allowed output options for [ select_* ] params
        $sql_parts = array('select' => array('screens' => 's.screenid'), 'from' => array('screens' => 'screens s'), 'where' => array(), 'order' => array(), 'limit' => null);
        $def_options = array('nodeids' => null, 'screenids' => null, 'screenitemids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'extendoutput' => null, 'output' => API_OUTPUT_REFER, 'select_screenitems' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
        $options = zbx_array_merge($def_options, $options);
        if (!is_null($options['extendoutput'])) {
            $options['output'] = API_OUTPUT_EXTEND;
            if (!is_null($options['select_screenitems'])) {
                $options['select_screenitems'] = API_OUTPUT_EXTEND;
            }
        }
        // editable + PERMISSION CHECK
        // nodeids
        $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
        // screenids
        if (!is_null($options['screenids'])) {
            zbx_value2array($options['screenids']);
            $sql_parts['where'][] = DBcondition('s.screenid', $options['screenids']);
        }
        // screenitemids
        if (!is_null($options['screenitemids'])) {
            zbx_value2array($options['screenitemids']);
            if ($options['output'] != API_OUTPUT_EXTEND) {
                $sql_parts['select']['screenitemid'] = 'si.screenitemid';
            }
            $sql_parts['from']['screens_items'] = 'screens_items si';
            $sql_parts['where']['ssi'] = 'si.screenid=s.screenid';
            $sql_parts['where'][] = DBcondition('si.screenitemid', $options['screenitemids']);
        }
        // extendoutput
        if ($options['output'] == API_OUTPUT_EXTEND) {
            $sql_parts['select']['screens'] = 's.*';
        }
        // countOutput
        if (!is_null($options['countOutput'])) {
            $options['sortfield'] = '';
            $sql_parts['select'] = array('count(DISTINCT s.screenid) as rowscount');
        }
        // filter
        if (is_array($options['filter'])) {
            zbx_db_filter('screens s', $options, $sql_parts);
        }
        // search
        if (is_array($options['search'])) {
            zbx_db_search('screens s', $options, $sql_parts);
        }
        // order
        // restrict not allowed columns for sorting
        $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
        if (!zbx_empty($options['sortfield'])) {
            $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
            $sql_parts['order'][] = 's.' . $options['sortfield'] . ' ' . $sortorder;
            if (!str_in_array('s.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('s.*', $sql_parts['select'])) {
                $sql_parts['select'][] = 's.' . $options['sortfield'];
            }
        }
        // limit
        if (zbx_ctype_digit($options['limit']) && $options['limit']) {
            $sql_parts['limit'] = $options['limit'];
        }
        //-------
        $screenids = array();
        $sql_parts['select'] = array_unique($sql_parts['select']);
        $sql_parts['from'] = array_unique($sql_parts['from']);
        $sql_parts['where'] = array_unique($sql_parts['where']);
        $sql_parts['order'] = array_unique($sql_parts['order']);
        $sql_select = '';
        $sql_from = '';
        $sql_where = '';
        $sql_order = '';
        if (!empty($sql_parts['select'])) {
            $sql_select .= implode(',', $sql_parts['select']);
        }
        if (!empty($sql_parts['from'])) {
            $sql_from .= implode(',', $sql_parts['from']);
        }
        if (!empty($sql_parts['where'])) {
            $sql_where .= ' AND ' . implode(' AND ', $sql_parts['where']);
        }
        if (!empty($sql_parts['order'])) {
            $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']);
        }
        $sql_limit = $sql_parts['limit'];
        $sql = 'SELECT ' . zbx_db_distinct($sql_parts) . ' ' . $sql_select . '
				FROM ' . $sql_from . '
				WHERE ' . DBin_node('s.screenid', $nodeids) . $sql_where . $sql_order;
        $res = DBselect($sql, $sql_limit);
        while ($screen = DBfetch($res)) {
            if (!is_null($options['countOutput'])) {
                $result = $screen['rowscount'];
            } else {
                $screenids[$screen['screenid']] = $screen['screenid'];
                if ($options['output'] == API_OUTPUT_SHORTEN) {
                    $result[$screen['screenid']] = array('screenid' => $screen['screenid']);
                } else {
                    if (!isset($result[$screen['screenid']])) {
                        $result[$screen['screenid']] = array();
                    }
                    if (!is_null($options['select_screenitems']) && !isset($result[$screen['screenid']]['screenitems'])) {
                        $result[$screen['screenid']]['screenitems'] = array();
                    }
                    if (isset($screen['screenitemid']) && is_null($options['select_screenitems'])) {
                        if (!isset($result[$screen['screenid']]['screenitems'])) {
                            $result[$screen['screenid']]['screenitems'] = array();
                        }
                        $result[$screen['screenid']]['screenitems'][] = array('screenitemid' => $screen['screenitemid']);
                        unset($screen['screenitemid']);
                    }
                    $result[$screen['screenid']] += $screen;
                }
            }
        }
        if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) {
        } else {
            if (!empty($result)) {
                $groups_to_check = array();
                $hosts_to_check = array();
                $graphs_to_check = array();
                $items_to_check = array();
                $maps_to_check = array();
                $screens_to_check = array();
                $screens_items = array();
                $db_sitems = DBselect('SELECT * FROM screens_items WHERE ' . DBcondition('screenid', $screenids));
                while ($sitem = DBfetch($db_sitems)) {
                    if ($sitem['resourceid'] == 0) {
                        continue;
                    }
                    $screens_items[$sitem['screenitemid']] = $sitem;
                    switch ($sitem['resourcetype']) {
                        case SCREEN_RESOURCE_HOSTS_INFO:
                        case SCREEN_RESOURCE_TRIGGERS_INFO:
                        case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
                        case SCREEN_RESOURCE_DATA_OVERVIEW:
                        case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                            $groups_to_check[] = $sitem['resourceid'];
                            break;
                        case SCREEN_RESOURCE_HOST_TRIGGERS:
                            $hosts_to_check[] = $sitem['resourceid'];
                            break;
                        case SCREEN_RESOURCE_GRAPH:
                            $graphs_to_check[] = $sitem['resourceid'];
                            break;
                        case SCREEN_RESOURCE_SIMPLE_GRAPH:
                        case SCREEN_RESOURCE_PLAIN_TEXT:
                            $items_to_check[] = $sitem['resourceid'];
                            break;
                        case SCREEN_RESOURCE_MAP:
                            $maps_to_check[] = $sitem['resourceid'];
                            break;
                        case SCREEN_RESOURCE_SCREEN:
                            $screens_to_check[] = $sitem['resourceid'];
                            break;
                    }
                }
                $groups_to_check = array_unique($groups_to_check);
                $hosts_to_check = array_unique($hosts_to_check);
                $graphs_to_check = array_unique($graphs_to_check);
                $items_to_check = array_unique($items_to_check);
                $maps_to_check = array_unique($maps_to_check);
                $screens_to_check = array_unique($screens_to_check);
                /*
                sdii($graphs_to_check);
                sdii($items_to_check);
                sdii($maps_to_check);
                sdii($screens_to_check);
                //*/
                // group
                $group_options = array('nodeids' => $nodeids, 'groupids' => $groups_to_check, 'editable' => $options['editable']);
                $allowed_groups = CHostgroup::get($group_options);
                $allowed_groups = zbx_objectValues($allowed_groups, 'groupid');
                // host
                $host_options = array('nodeids' => $nodeids, 'hostids' => $hosts_to_check, 'editable' => $options['editable']);
                $allowed_hosts = CHost::get($host_options);
                $allowed_hosts = zbx_objectValues($allowed_hosts, 'hostid');
                // graph
                $graph_options = array('nodeids' => $nodeids, 'graphids' => $graphs_to_check, 'editable' => $options['editable']);
                $allowed_graphs = CGraph::get($graph_options);
                $allowed_graphs = zbx_objectValues($allowed_graphs, 'graphid');
                // item
                $item_options = array('nodeids' => $nodeids, 'itemids' => $items_to_check, 'webitems' => 1, 'editable' => $options['editable']);
                $allowed_items = CItem::get($item_options);
                $allowed_items = zbx_objectValues($allowed_items, 'itemid');
                // map
                $map_options = array('nodeids' => $nodeids, 'sysmapids' => $maps_to_check, 'editable' => $options['editable']);
                $allowed_maps = CMap::get($map_options);
                $allowed_maps = zbx_objectValues($allowed_maps, 'sysmapid');
                // screen
                $screens_options = array('nodeids' => $nodeids, 'screenids' => $screens_to_check, 'editable' => $options['editable']);
                $allowed_screens = CScreen::get($screens_options);
                $allowed_screens = zbx_objectValues($allowed_screens, 'screenid');
                $restr_groups = array_diff($groups_to_check, $allowed_groups);
                $restr_hosts = array_diff($hosts_to_check, $allowed_hosts);
                $restr_graphs = array_diff($graphs_to_check, $allowed_graphs);
                $restr_items = array_diff($items_to_check, $allowed_items);
                $restr_maps = array_diff($maps_to_check, $allowed_maps);
                $restr_screens = array_diff($screens_to_check, $allowed_screens);
                /*
                SDI('---------------------------------------');
                SDII($restr_graphs);
                SDII($restr_items);
                SDII($restr_maps);
                SDII($restr_screens);
                SDI('/////////////////////////////////');
                //*/
                // group
                foreach ($restr_groups as $resourceid) {
                    foreach ($screens_items as $screen_itemid => $screen_item) {
                        if ($screen_item['resourceid'] == $resourceid && uint_in_array($screen_item['resourcetype'], array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS))) {
                            unset($result[$screen_item['screenid']]);
                            unset($screens_items[$screen_itemid]);
                        }
                    }
                }
                // host
                foreach ($restr_hosts as $resourceid) {
                    foreach ($screens_items as $screen_itemid => $screen_item) {
                        if ($screen_item['resourceid'] == $resourceid && uint_in_array($screen_item['resourcetype'], array(SCREEN_RESOURCE_HOST_TRIGGERS))) {
                            unset($result[$screen_item['screenid']]);
                            unset($screens_items[$screen_itemid]);
                        }
                    }
                }
                // graph
                foreach ($restr_graphs as $resourceid) {
                    foreach ($screens_items as $screen_itemid => $screen_item) {
                        if ($screen_item['resourceid'] == $resourceid && $screen_item['resourcetype'] == SCREEN_RESOURCE_GRAPH) {
                            unset($result[$screen_item['screenid']]);
                            unset($screens_items[$screen_itemid]);
                        }
                    }
                }
                // item
                foreach ($restr_items as $resourceid) {
                    foreach ($screens_items as $screen_itemid => $screen_item) {
                        if ($screen_item['resourceid'] == $resourceid && uint_in_array($screen_item['resourcetype'], array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))) {
                            unset($result[$screen_item['screenid']]);
                            unset($screens_items[$screen_itemid]);
                        }
                    }
                }
                // map
                foreach ($restr_maps as $resourceid) {
                    foreach ($screens_items as $screen_itemid => $screen_item) {
                        if ($screen_item['resourceid'] == $resourceid && $screen_item['resourcetype'] == SCREEN_RESOURCE_MAP) {
                            unset($result[$screen_item['screenid']]);
                            unset($screens_items[$screen_itemid]);
                        }
                    }
                }
                // screen
                foreach ($restr_screens as $resourceid) {
                    foreach ($screens_items as $screen_itemid => $screen_item) {
                        if ($screen_item['resourceid'] == $resourceid && $screen_item['resourcetype'] == SCREEN_RESOURCE_SCREEN) {
                            unset($result[$screen_item['screenid']]);
                            unset($screens_items[$screen_itemid]);
                        }
                    }
                }
            }
        }
        if (!is_null($options['countOutput'])) {
            if (is_null($options['preservekeys'])) {
                $result = zbx_cleanHashes($result);
            }
            return $result;
        }
        // Adding ScreenItems
        if (!is_null($options['select_screenitems']) && str_in_array($options['select_screenitems'], $subselects_allowed_outputs)) {
            if (!isset($screens_items)) {
                $screens_items = array();
                $db_sitems = DBselect('SELECT * FROM screens_items WHERE ' . DBcondition('screenid', $screenids));
                while ($sitem = DBfetch($db_sitems)) {
                    $screens_items[$sitem['screenitemid']] = $sitem;
                }
            }
            foreach ($screens_items as $snum => $sitem) {
                if (!isset($result[$sitem['screenid']]['screenitems'])) {
                    $result[$sitem['screenid']]['screenitems'] = array();
                }
                $result[$sitem['screenid']]['screenitems'][] = $sitem;
            }
        }
        // removing keys (hash -> array)
        if (is_null($options['preservekeys'])) {
            $result = zbx_cleanHashes($result);
        }
        return $result;
    }
Beispiel #6
0
         $table->addRow($name);
     }
     if ($multiselect) {
         $button = new CButton('select', S_SELECT, "javascript: addSelectedValues('screens', " . zbx_jsvalue($reference) . ");");
         $button->setType('button');
         $table->setFooter(new CCol($button, 'right'));
     }
     $form->addItem($table);
     $form->show();
 } else {
     if ($srctbl == 'screens2') {
         require_once 'include/screens.inc.php';
         $table = new CTableInfo(S_NO_NODES_DEFINED);
         $table->setHeader(S_NAME);
         $options = array('nodeids' => $nodeid, 'output' => API_OUTPUT_EXTEND);
         $screens = CScreen::get($options);
         order_result($screens, 'name');
         foreach ($screens as $snum => $row) {
             $row['node_name'] = get_node_name_by_elid($row['screenid'], true);
             if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) {
                 continue;
             }
             $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
             $name = new CLink($row['name'], '#');
             $row['name'] = $row['node_name'] . $row['name'];
             $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
             $name->setAttribute('onclick', $action . " close_window(); return false;");
             $table->addRow($name);
         }
         $table->show();
     } else {
 private static function screen($action, $params)
 {
     CScreen::$error = array();
     switch ($action) {
         default:
             $result = call_user_func(array('CScreen', $action), $params);
     }
     self::$result = $result;
 }
 public static function parseScreen($rules)
 {
     try {
         self::validate(dirname(__FILE__) . '/xmlschemas/screens.rng');
         $importScreens = self::XMLtoArray(self::$xml);
         $importScreens = $importScreens['zabbix_export']['screens'];
         $result = true;
         $screens = array();
         foreach ($importScreens as $mnum => &$screen) {
             unset($screen['screenid']);
             $exists = CScreen::exists(array('name' => $screen['name']));
             if ($exists && isset($rules['screens']['exist'])) {
                 $db_screens = CScreen::getObjects(array('name' => $screen['name']));
                 if (empty($db_screens)) {
                     throw new Exception(S_NO_PERMISSIONS_FOR_SCREEN . ' "' . $screen['name'] . '" import');
                 }
                 $db_screen = reset($db_screens);
                 $screen['screenid'] = $db_screen['screenid'];
             } else {
                 if ($exists || !isset($rules['screens']['missed'])) {
                     info('Screen [' . $screen['name'] . '] skipped - user rule');
                     unset($importScreens[$mnum]);
                     continue;
                     // break if not update exist
                 }
             }
             if (!isset($screen['screenitems'])) {
                 $screen['screenitems'] = array();
             }
             foreach ($screen['screenitems'] as $snum => &$screenitem) {
                 $nodeCaption = isset($screenitem['resourceid']['node']) ? $screenitem['resourceid']['node'] . ':' : '';
                 if (!isset($screenitem['resourceid'])) {
                     $screenitem['resourceid'] = 0;
                 }
                 if (is_array($screenitem['resourceid'])) {
                     switch ($screenitem['resourcetype']) {
                         case SCREEN_RESOURCE_HOSTS_INFO:
                         case SCREEN_RESOURCE_TRIGGERS_INFO:
                         case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
                         case SCREEN_RESOURCE_DATA_OVERVIEW:
                         case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                             if (is_array($screenitem['resourceid'])) {
                                 $db_hostgroups = CHostgroup::getObjects($screenitem['resourceid']);
                                 if (empty($db_hostgroups)) {
                                     $error = S_CANNOT_FIND_HOSTGROUP . ' "' . $nodeCaption . $screenitem['resourceid']['name'] . '" ' . S_USED_IN_EXPORTED_SCREEN_SMALL . ' "' . $screen['name'] . '"';
                                     throw new Exception($error);
                                 }
                                 $tmp = reset($db_hostgroups);
                                 $screenitem['resourceid'] = $tmp['groupid'];
                             }
                             break;
                         case SCREEN_RESOURCE_HOST_TRIGGERS:
                             $db_hosts = CHost::getObjects($screenitem['resourceid']);
                             if (empty($db_hosts)) {
                                 $error = S_CANNOT_FIND_HOST . ' "' . $nodeCaption . $screenitem['resourceid']['host'] . '" ' . S_USED_IN_EXPORTED_SCREEN_SMALL . ' "' . $screen['name'] . '"';
                                 throw new Exception($error);
                             }
                             $tmp = reset($db_hosts);
                             $screenitem['resourceid'] = $tmp['hostid'];
                             break;
                         case SCREEN_RESOURCE_GRAPH:
                             $db_graphs = CGraph::getObjects($screenitem['resourceid']);
                             if (empty($db_graphs)) {
                                 $error = S_CANNOT_FIND_GRAPH . ' "' . $nodeCaption . $screenitem['resourceid']['host'] . ':' . $screenitem['resourceid']['name'] . '" ' . S_USED_IN_EXPORTED_SCREEN_SMALL . ' "' . $screen['name'] . '"';
                                 throw new Exception($error);
                             }
                             $tmp = reset($db_graphs);
                             $screenitem['resourceid'] = $tmp['graphid'];
                             break;
                         case SCREEN_RESOURCE_SIMPLE_GRAPH:
                         case SCREEN_RESOURCE_PLAIN_TEXT:
                             $db_items = CItem::getObjects($screenitem['resourceid']);
                             if (empty($db_items)) {
                                 $error = S_CANNOT_FIND_ITEM . ' "' . $nodeCaption . $screenitem['resourceid']['host'] . ':' . $screenitem['resourceid']['key_'] . '" ' . S_USED_IN_EXPORTED_SCREEN_SMALL . ' "' . $screen['name'] . '"';
                                 throw new Exception($error);
                             }
                             $tmp = reset($db_items);
                             $screenitem['resourceid'] = $tmp['itemid'];
                             break;
                         case SCREEN_RESOURCE_MAP:
                             $db_sysmaps = CMap::getObjects($screenitem['resourceid']);
                             if (empty($db_sysmaps)) {
                                 $error = S_CANNOT_FIND_MAP . ' "' . $nodeCaption . $screenitem['resourceid']['name'] . '" ' . S_USED_IN_EXPORTED_SCREEN_SMALL . ' "' . $screen['name'] . '"';
                                 throw new Exception($error);
                             }
                             $tmp = reset($db_sysmaps);
                             $screenitem['resourceid'] = $tmp['sysmapid'];
                             break;
                         case SCREEN_RESOURCE_SCREEN:
                             $db_screens = CScreen::getObjects($screenitem['resourceid']);
                             if (empty($db_screens)) {
                                 $error = S_CANNOT_FIND_SCREEN . ' "' . $nodeCaption . $screenitem['resourceid']['name'] . '" ' . S_USED_IN_EXPORTED_SCREEN_SMALL . ' "' . $screen['name'] . '"';
                                 throw new Exception($error);
                             }
                             $tmp = reset($db_screens);
                             $screenitem['resourceid'] = $tmp['screenid'];
                             break;
                         default:
                             $screenitem['resourceid'] = 0;
                             break;
                     }
                 }
             }
             unset($screenitem);
             $screens[] = $screen;
         }
         unset($screen);
         $importScreens = $screens;
         foreach ($importScreens as $mnum => $screen) {
             if (isset($screen['screenid'])) {
                 $result = CScreen::update($screen);
             } else {
                 $result = CScreen::create($screen);
             }
             if (isset($screen['screenid'])) {
                 info(S_SCREEN . ' [' . $screen['name'] . '] ' . S_UPDATED_SMALL);
             } else {
                 info(S_SCREEN . ' [' . $screen['name'] . '] ' . S_ADDED_SMALL);
             }
         }
     } catch (Exception $e) {
         error($e->getMessage());
         return false;
     }
     return $result;
 }
Beispiel #9
0
    $elementid = CProfile::get('web.screens.elementid', null);
    //this flag will be used in case this element does not exist
    $id_has_been_fetched_from_profile = true;
} else {
    $id_has_been_fetched_from_profile = false;
}
$screens_wdgt = new CWidget();
$scroll_div = new CDiv();
$scroll_div->setAttribute('id', 'scrollbar_cntr');
$screens_wdgt->addFlicker($scroll_div, CProfile::get('web.screens.filter.state', 1));
$formHeader = new CForm();
$cmbConfig = new CComboBox('config', 'screens.php', 'javascript: redirect(this.options[this.selectedIndex].value);');
$cmbConfig->addItem('screens.php', S_SCREENS);
$cmbConfig->addItem('slides.php', S_SLIDESHOWS);
$formHeader->addItem($cmbConfig);
$screens = CScreen::get(array('nodeids' => get_current_nodeid(), 'output' => API_OUTPUT_EXTEND));
//if screen name is provided it takes priority over elementid
if ($use_screen_name) {
    $screens = zbx_toHash($screens, 'name');
    $elementIdentifier = $_REQUEST['screenname'];
} else {
    $screens = zbx_toHash($screens, 'screenid');
    $elementIdentifier = $elementid;
}
order_result($screens, 'name');
//no screens defined at all
if (empty($screens)) {
    $screens_wdgt->addPageHeader(S_SCREENS_BIG, $formHeader);
    $screens_wdgt->addItem(BR());
    $screens_wdgt->addItem(new CTableInfo(S_NO_SCREENS_DEFINED));
    $screens_wdgt->show();