Ejemplo n.º 1
0
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'httptestid' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'http_item_type' => array(T_ZBX_INT, O_OPT, null, null, null), 'name' => array(T_ZBX_STR, O_OPT, null, null, null), 'width' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null), 'ymin_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymax_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymin_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'ymax_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'legend' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showworkperiod' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showtriggers' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'graphtype' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'yaxismin' => array(T_ZBX_DBL, O_OPT, null, null, null), 'yaxismax' => array(T_ZBX_DBL, O_OPT, null, null, null), 'percent_left' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'percent_right' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'items' => array(T_ZBX_STR, O_OPT, null, null, null));
$isDataValid = check_fields($fields);
if ($httptestid = get_request('httptestid', false)) {
    $color = array('current' => 0, 0 => array('next' => '1'), 1 => array('color' => 'Red', 'next' => '2'), 2 => array('color' => 'Dark Green', 'next' => '3'), 3 => array('color' => 'Blue', 'next' => '4'), 4 => array('color' => 'Dark Yellow', 'next' => '5'), 5 => array('color' => 'Cyan', 'next' => '6'), 6 => array('color' => 'Gray', 'next' => '7'), 7 => array('color' => 'Dark Red', 'next' => '8'), 8 => array('color' => 'Green', 'next' => '9'), 9 => array('color' => 'Dark Blue', 'next' => '10'), 10 => array('color' => 'Yellow', 'next' => '11'), 11 => array('color' => 'Black', 'next' => '1'));
    $items = array();
    $dbItems = DBselect('SELECT i.itemid' . ' FROM httpstepitem hi,items i,httpstep hs' . ' WHERE i.itemid=hi.itemid' . ' AND hs.httptestid=' . $httptestid . ' AND hs.httpstepid=hi.httpstepid' . ' AND hi.type=' . get_request('http_item_type', HTTPSTEP_ITEM_TYPE_TIME) . ' ORDER BY hs.no DESC');
    while ($item = DBfetch($dbItems)) {
        $itemColor = $color[$color['current'] = $color[$color['current']]['next']]['color'];
        $items[] = array('itemid' => $item['itemid'], 'color' => $itemColor);
    }
    $httptest = get_httptest_by_httptestid($httptestid);
    $name = $httptest['name'];
} else {
    $items = get_request('items', array());
    asort_by_key($items, 'sortorder');
    $dbItems = API::Item()->get(array('webitems' => true, 'itemids' => zbx_objectValues($items, 'itemid'), 'nodeids' => get_current_nodeid(true), 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => true, 'filter' => array('flags' => null)));
    $dbItems = zbx_toHash($dbItems, 'itemid');
    foreach ($items as $item) {
        if (!isset($dbItems[$item['itemid']])) {
            access_deny();
        }
    }
    $name = get_request('name', '');
}
/*
 * Display
 */
if ($isDataValid) {
    $graph = new CChart(get_request('graphtype', GRAPH_TYPE_NORMAL));
    $graph->setHeader($name);
Ejemplo n.º 2
0
function insert_graph_form()
{
    $frmGraph = new CFormTable(S_GRAPH, null, 'post');
    $frmGraph->SetName('frm_graph');
    $frmGraph->SetHelp("web.graphs.graph.php");
    $frmGraph->SetMethod('post');
    $items = get_request('items', array());
    if (isset($_REQUEST['graphid'])) {
        $frmGraph->addVar('graphid', $_REQUEST['graphid']);
        $result = DBselect('SELECT * FROM graphs WHERE graphid=' . $_REQUEST['graphid']);
        $row = DBfetch($result);
        $frmGraph->SetTitle(S_GRAPH . ' "' . $row['name'] . '"');
    }
    if (isset($_REQUEST['graphid']) && !isset($_REQUEST['form_refresh'])) {
        $name = $row['name'];
        $width = $row['width'];
        $height = $row['height'];
        $ymin_type = $row["ymin_type"];
        $ymax_type = $row["ymax_type"];
        $yaxismin = $row['yaxismin'];
        $yaxismax = $row['yaxismax'];
        $ymin_itemid = $row["ymin_itemid"];
        $ymax_itemid = $row["ymax_itemid"];
        $showworkperiod = $row['show_work_period'];
        $showtriggers = $row['show_triggers'];
        $graphtype = $row['graphtype'];
        $legend = $row['show_legend'];
        $graph3d = $row['show_3d'];
        $percent_left = $row['percent_left'];
        $percent_right = $row['percent_right'];
        $db_items = DBselect('SELECT * FROM graphs_items WHERE graphid=' . $_REQUEST['graphid']);
        while ($item = DBfetch($db_items)) {
            array_push($items, array('itemid' => $item['itemid'], 'drawtype' => $item['drawtype'], 'sortorder' => $item['sortorder'], 'color' => $item['color'], 'yaxisside' => $item['yaxisside'], 'calc_fnc' => $item['calc_fnc'], 'type' => $item['type'], 'periods_cnt' => $item['periods_cnt']));
        }
    } else {
        $name = get_request('name', '');
        $graphtype = get_request('graphtype', GRAPH_TYPE_NORMAL);
        if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) {
            $width = get_request('width', 400);
            $height = get_request('height', 300);
        } else {
            $width = get_request('width', 900);
            $height = get_request('height', 200);
        }
        $ymin_type = get_request("ymin_type", GRAPH_YAXIS_TYPE_CALCULATED);
        $ymax_type = get_request("ymax_type", GRAPH_YAXIS_TYPE_CALCULATED);
        $yaxismin = get_request("yaxismin", 0.0);
        $yaxismax = get_request("yaxismax", 100.0);
        $ymin_itemid = get_request("ymin_itemid", 0);
        $ymax_itemid = get_request("ymax_itemid", 0);
        $showworkperiod = get_request('showworkperiod', 0);
        $showtriggers = get_request('showtriggers', 0);
        $legend = get_request('legend', 0);
        $graph3d = get_request('graph3d', 0);
        $visible = get_request('visible');
        $percent_left = 0;
        $percent_right = 0;
        if (isset($visible['percent_left'])) {
            $percent_left = get_request('percent_left', 0);
        }
        if (isset($visible['percent_right'])) {
            $percent_right = get_request('percent_right', 0);
        }
    }
    /* reinit $_REQUEST */
    $_REQUEST['items'] = $items;
    $_REQUEST['name'] = $name;
    $_REQUEST['width'] = $width;
    $_REQUEST['height'] = $height;
    $_REQUEST['ymin_type'] = $ymin_type;
    $_REQUEST['ymax_type'] = $ymax_type;
    $_REQUEST['yaxismin'] = $yaxismin;
    $_REQUEST['yaxismax'] = $yaxismax;
    $_REQUEST['ymin_itemid'] = $ymin_itemid;
    $_REQUEST['ymax_itemid'] = $ymax_itemid;
    $_REQUEST['showworkperiod'] = $showworkperiod;
    $_REQUEST['showtriggers'] = $showtriggers;
    $_REQUEST['graphtype'] = $graphtype;
    $_REQUEST['legend'] = $legend;
    $_REQUEST['graph3d'] = $graph3d;
    $_REQUEST['percent_left'] = $percent_left;
    $_REQUEST['percent_right'] = $percent_right;
    /********************/
    if ($graphtype != GRAPH_TYPE_NORMAL) {
        foreach ($items as $gid => $gitem) {
            if ($gitem['type'] != GRAPH_ITEM_AGGREGATED) {
                continue;
            }
            unset($items[$gid]);
        }
    }
    asort_by_key($items, 'sortorder');
    $group_gid = get_request('group_gid', array());
    $frmGraph->addVar('ymin_itemid', $ymin_itemid);
    $frmGraph->addVar('ymax_itemid', $ymax_itemid);
    $frmGraph->addRow(S_NAME, new CTextBox('name', $name, 32));
    $g_width = new CNumericBox('width', $width, 5);
    $g_width->addoption('onblur', 'javascript: submit();');
    $frmGraph->addRow(S_WIDTH, $g_width);
    $g_height = new CNumericBox('height', $height, 5);
    $g_height->addoption('onblur', 'javascript: submit();');
    $frmGraph->addRow(S_HEIGHT, $g_height);
    $cmbGType = new CComboBox('graphtype', $graphtype, 'graphs.submit(this)');
    $cmbGType->addItem(GRAPH_TYPE_NORMAL, S_NORMAL);
    $cmbGType->addItem(GRAPH_TYPE_STACKED, S_STACKED);
    $cmbGType->addItem(GRAPH_TYPE_PIE, S_PIE);
    $cmbGType->addItem(GRAPH_TYPE_EXPLODED, S_EXPLODED);
    zbx_add_post_js('graphs.graphtype = ' . $graphtype . ";\n");
    $frmGraph->addRow(S_GRAPH_TYPE, $cmbGType);
    if ($graphtype == GRAPH_TYPE_NORMAL || $graphtype == GRAPH_TYPE_STACKED) {
        $frmGraph->addRow(S_SHOW_WORKING_TIME, new CCheckBox('showworkperiod', $showworkperiod, null, 1));
        $frmGraph->addRow(S_SHOW_TRIGGERS, new CCheckBox('showtriggers', $showtriggers, null, 1));
        if ($graphtype == GRAPH_TYPE_NORMAL) {
            $percent_left = sprintf("%2.2f", $percent_left);
            $percent_right = sprintf("%2.2f", $percent_right);
            $pr_left_input = new CTextBox('percent_left', $percent_left, '5');
            $pr_left_chkbx = new CCheckBox('visible[percent_left]', 1, "javascript: ShowHide('percent_left');", 1);
            if ($percent_left == 0) {
                $pr_left_input->addOption('style', 'display: none;');
                $pr_left_chkbx->SetChecked(0);
            }
            $pr_right_input = new CTextBox('percent_right', $percent_right, '5');
            $pr_right_chkbx = new CCheckBox('visible[percent_right]', 1, "javascript: ShowHide('percent_right');", 1);
            if ($percent_right == 0) {
                $pr_right_input->addOption('style', 'display: none;');
                $pr_right_chkbx->SetChecked(0);
            }
            $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_LEFT . ')', array($pr_left_chkbx, $pr_left_input));
            $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_RIGHT . ')', array($pr_right_chkbx, $pr_right_input));
        }
        $yaxis_min = array();
        $cmbYType = new CComboBox('ymin_type', $ymin_type, 'javascript: submit();');
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM);
        $yaxis_min[] = $cmbYType;
        if ($ymin_type == GRAPH_YAXIS_TYPE_FIXED) {
            $yaxis_min[] = new CTextBox("yaxismin", $yaxismin, 9);
        } else {
            if ($ymin_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) {
                $frmGraph->addVar('yaxismin', $yaxismin);
                $ymin_name = '';
                if ($ymin_itemid > 0) {
                    $min_host = get_host_by_itemid($ymin_itemid);
                    $min_item = get_item_by_itemid($ymin_itemid);
                    $ymin_name = $min_host['host'] . ':' . item_description($min_item);
                }
                $yaxis_min[] = new CTextBox("ymin_name", $ymin_name, 80, 'yes');
                $yaxis_min[] = new CButton('yaxis_min', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . "&dstfld1=ymin_itemid" . "&dstfld2=ymin_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');");
            } else {
                $frmGraph->addVar('yaxismin', $yaxismin);
            }
        }
        $frmGraph->addRow(S_YAXIS_MIN_VALUE, $yaxis_min);
        $yaxis_max = array();
        $cmbYType = new CComboBox("ymax_type", $ymax_type, "submit()");
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM);
        $yaxis_max[] = $cmbYType;
        if ($ymax_type == GRAPH_YAXIS_TYPE_FIXED) {
            $yaxis_max[] = new CTextBox("yaxismax", $yaxismax, 9);
        } else {
            if ($ymax_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) {
                $frmGraph->addVar('yaxismax', $yaxismax);
                $ymax_name = '';
                if ($ymax_itemid > 0) {
                    $max_host = get_host_by_itemid($ymax_itemid);
                    $max_item = get_item_by_itemid($ymax_itemid);
                    $ymax_name = $max_host['host'] . ':' . item_description($max_item);
                }
                $yaxis_max[] = new CTextBox("ymax_name", $ymax_name, 80, 'yes');
                $yaxis_max[] = new CButton('yaxis_max', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . "&dstfld1=ymax_itemid" . "&dstfld2=ymax_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');");
            } else {
                $frmGraph->addVar('yaxismax', $yaxismax);
            }
        }
        $frmGraph->addRow(S_YAXIS_MAX_VALUE, $yaxis_max);
    } else {
        $frmGraph->addRow(S_3D_VIEW, new CCheckBox('graph3d', $graph3d, 'javascript: graphs.submit(this);', 1));
        $frmGraph->addRow(S_LEGEND, new CCheckBox('legend', $legend, 'javascript: graphs.submit(this);', 1));
    }
    $only_hostid = null;
    $monitored_hosts = null;
    if (count($items)) {
        $frmGraph->addVar('items', $items);
        $items_table = new CTableInfo();
        foreach ($items as $gid => $gitem) {
            if ($graphtype == GRAPH_TYPE_STACKED && $gitem['type'] == GRAPH_ITEM_AGGREGATED) {
                continue;
            }
            $host = get_host_by_itemid($gitem['itemid']);
            $item = get_item_by_itemid($gitem['itemid']);
            if ($host['status'] == HOST_STATUS_TEMPLATE) {
                $only_hostid = $host['hostid'];
            } else {
                $monitored_hosts = 1;
            }
            if ($gitem['type'] == GRAPH_ITEM_AGGREGATED) {
                $color = '-';
            } else {
                $color = new CColorCell(null, $gitem['color']);
            }
            $do_up = new CLink(S_UP, '#', 'action');
            $do_up->OnClick("return create_var('" . $frmGraph->GetName() . "','move_up'," . $gid . ", true);");
            $do_down = new CLink(S_DOWN, '#', 'action');
            $do_down->OnClick("return create_var('" . $frmGraph->GetName() . "','move_down'," . $gid . ", true);");
            $description = new CLink($host['host'] . ': ' . item_description($item), '#', 'action');
            $description->OnClick('return PopUp("popup_gitem.php?list_name=items&dstfrm=' . $frmGraph->GetName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . url_param($gitem, false) . url_param($gid, false, 'gid') . url_param(get_request('graphid', 0), false, 'graphid') . '",550,400,"graph_item_form");');
            if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) {
                $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $gitem['sortorder'], $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), $color, array($do_up, SPACE . "|" . SPACE, $do_down)));
            } else {
                $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $gitem['sortorder'], $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), graph_item_drawtype2str($gitem["drawtype"], $gitem["type"]), $color, array($do_up, SPACE . "|" . SPACE, $do_down)));
            }
        }
        $dedlete_button = new CButton('delete_item', S_DELETE_SELECTED);
    } else {
        $items_table = $dedlete_button = null;
    }
    $frmGraph->addRow(S_ITEMS, array($items_table, new CButton('add_item', S_ADD, "return PopUp('popup_gitem.php?dstfrm=" . $frmGraph->GetName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . "',550,400,'graph_item_form');"), $dedlete_button));
    unset($items_table, $dedlete_button);
    $frmGraph->addItemToBottomRow(new CButton("save", S_SAVE));
    if (isset($_REQUEST["graphid"])) {
        $frmGraph->addItemToBottomRow(SPACE);
        $frmGraph->addItemToBottomRow(new CButton("clone", S_CLONE));
        $frmGraph->addItemToBottomRow(SPACE);
        $frmGraph->addItemToBottomRow(new CButtonDelete(S_DELETE_GRAPH_Q, url_param("graphid") . url_param('groupid') . url_param("hostid")));
    }
    $frmGraph->addItemToBottomRow(SPACE);
    $frmGraph->addItemToBottomRow(new CButtonCancel(url_param('groupid') . url_param("hostid")));
    $frmGraph->Show();
}
Ejemplo n.º 3
0
    for ($i = 0; $i < $itemCount - 1;) {
        // check if we delete an item
        $next = $i + 1;
        while (!isset($data['items'][$next]) && $next < $itemCount - 1) {
            $next++;
        }
        if (isset($data['items'][$next]) && $data['items'][$i]['sortorder'] == $data['items'][$next]['sortorder']) {
            for ($j = $next; $j < $itemCount; $j++) {
                if ($data['items'][$j - 1]['sortorder'] >= $data['items'][$j]['sortorder']) {
                    $data['items'][$j]['sortorder']++;
                }
            }
        }
        $i = $next;
    }
    asort_by_key($data['items'], 'sortorder');
    $data['items'] = array_values($data['items']);
    // is template
    $data['is_template'] = isTemplate($data['hostid']);
    // render view
    $graphView = new CView('configuration.graph.edit', $data);
    $graphView->render();
    $graphView->show();
} else {
    $data = array('pageFilter' => $pageFilter, 'hostid' => $pageFilter->hostid > 0 ? $pageFilter->hostid : get_request('hostid'), 'parent_discoveryid' => get_request('parent_discoveryid'), 'graphs' => array(), 'discovery_rule' => empty($_REQUEST['parent_discoveryid']) ? null : $discovery_rule, 'displayNodes' => is_array(get_current_nodeid()) && $pageFilter->groupid == 0 && $pageFilter->hostid == 0);
    $sortfield = getPageSortField('name');
    $sortorder = getPageSortOrder();
    // get graphs
    $options = array('hostids' => $data['hostid'] ? $data['hostid'] : null, 'groupids' => !$data['hostid'] && $pageFilter->groupid > 0 ? $pageFilter->groupid : null, 'discoveryids' => empty($_REQUEST['parent_discoveryid']) ? null : get_request('parent_discoveryid'), 'editable' => true, 'output' => array('graphid', 'name', 'graphtype'), 'limit' => $config['search_limit'] + 1);
    $data['graphs'] = empty($_REQUEST['parent_discoveryid']) ? API::Graph()->get($options) : API::GraphPrototype()->get($options);
    if ($sortfield == 'graphtype') {
Ejemplo n.º 4
0
function insert_graph_form()
{
    $frmGraph = new CFormTable(S_GRAPH, null, 'post');
    $frmGraph->setName('frm_graph');
    //$frmGraph->setHelp("web.graphs.graph.php");
    $items = get_request('items', array());
    if (isset($_REQUEST['graphid'])) {
        $frmGraph->addVar('graphid', $_REQUEST['graphid']);
        $options = array('graphids' => $_REQUEST['graphid'], 'extendoutput' => 1);
        $graphs = CGraph::get($options);
        $row = reset($graphs);
        $frmGraph->setTitle(S_GRAPH . ' "' . $row['name'] . '"');
    }
    if (isset($_REQUEST['graphid']) && !isset($_REQUEST['form_refresh'])) {
        $name = $row['name'];
        $width = $row['width'];
        $height = $row['height'];
        $ymin_type = $row['ymin_type'];
        $ymax_type = $row['ymax_type'];
        $yaxismin = $row['yaxismin'];
        $yaxismax = $row['yaxismax'];
        $ymin_itemid = $row['ymin_itemid'];
        $ymax_itemid = $row['ymax_itemid'];
        $showworkperiod = $row['show_work_period'];
        $showtriggers = $row['show_triggers'];
        $graphtype = $row['graphtype'];
        $legend = $row['show_legend'];
        $graph3d = $row['show_3d'];
        $percent_left = $row['percent_left'];
        $percent_right = $row['percent_right'];
        $options = array('graphids' => $_REQUEST['graphid'], 'sortfield' => 'sortorder', 'extendoutput' => 1);
        $items = CGraphItem::get($options);
    } else {
        $name = get_request('name', '');
        $graphtype = get_request('graphtype', GRAPH_TYPE_NORMAL);
        if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) {
            $width = get_request('width', 400);
            $height = get_request('height', 300);
        } else {
            $width = get_request('width', 900);
            $height = get_request('height', 200);
        }
        $ymin_type = get_request('ymin_type', GRAPH_YAXIS_TYPE_CALCULATED);
        $ymax_type = get_request('ymax_type', GRAPH_YAXIS_TYPE_CALCULATED);
        $yaxismin = get_request('yaxismin', 0.0);
        $yaxismax = get_request('yaxismax', 100.0);
        $ymin_itemid = get_request('ymin_itemid', 0);
        $ymax_itemid = get_request('ymax_itemid', 0);
        $showworkperiod = get_request('showworkperiod', 0);
        $showtriggers = get_request('showtriggers', 0);
        $legend = get_request('legend', 0);
        $graph3d = get_request('graph3d', 0);
        $visible = get_request('visible');
        $percent_left = 0;
        $percent_right = 0;
        if (isset($visible['percent_left'])) {
            $percent_left = get_request('percent_left', 0);
        }
        if (isset($visible['percent_right'])) {
            $percent_right = get_request('percent_right', 0);
        }
    }
    /* reinit $_REQUEST */
    $_REQUEST['items'] = $items;
    $_REQUEST['name'] = $name;
    $_REQUEST['width'] = $width;
    $_REQUEST['height'] = $height;
    $_REQUEST['ymin_type'] = $ymin_type;
    $_REQUEST['ymax_type'] = $ymax_type;
    $_REQUEST['yaxismin'] = $yaxismin;
    $_REQUEST['yaxismax'] = $yaxismax;
    $_REQUEST['ymin_itemid'] = $ymin_itemid;
    $_REQUEST['ymax_itemid'] = $ymax_itemid;
    $_REQUEST['showworkperiod'] = $showworkperiod;
    $_REQUEST['showtriggers'] = $showtriggers;
    $_REQUEST['graphtype'] = $graphtype;
    $_REQUEST['legend'] = $legend;
    $_REQUEST['graph3d'] = $graph3d;
    $_REQUEST['percent_left'] = $percent_left;
    $_REQUEST['percent_right'] = $percent_right;
    /********************/
    if ($graphtype != GRAPH_TYPE_NORMAL) {
        foreach ($items as $gid => $gitem) {
            if ($gitem['type'] == GRAPH_ITEM_AGGREGATED) {
                unset($items[$gid]);
            }
        }
    }
    $items = array_values($items);
    $icount = count($items);
    for ($i = 0; $i < $icount - 1;) {
        // check if we deletd an item
        $next = $i + 1;
        while (!isset($items[$next]) && $next < $icount - 1) {
            $next++;
        }
        if (isset($items[$next]) && $items[$i]['sortorder'] == $items[$next]['sortorder']) {
            for ($j = $next; $j < $icount; $j++) {
                if ($items[$j - 1]['sortorder'] >= $items[$j]['sortorder']) {
                    $items[$j]['sortorder']++;
                }
            }
        }
        $i = $next;
    }
    asort_by_key($items, 'sortorder');
    $items = array_values($items);
    $group_gid = get_request('group_gid', array());
    $frmGraph->addVar('ymin_itemid', $ymin_itemid);
    $frmGraph->addVar('ymax_itemid', $ymax_itemid);
    $frmGraph->addRow(S_NAME, new CTextBox('name', $name, 32));
    $frmGraph->addRow(S_WIDTH, new CNumericBox('width', $width, 5));
    $frmGraph->addRow(S_HEIGHT, new CNumericBox('height', $height, 5));
    $cmbGType = new CComboBox('graphtype', $graphtype, 'graphs.submit(this)');
    $cmbGType->addItem(GRAPH_TYPE_NORMAL, S_NORMAL);
    $cmbGType->addItem(GRAPH_TYPE_STACKED, S_STACKED);
    $cmbGType->addItem(GRAPH_TYPE_PIE, S_PIE);
    $cmbGType->addItem(GRAPH_TYPE_EXPLODED, S_EXPLODED);
    zbx_add_post_js('graphs.graphtype = ' . $graphtype . ";\n");
    $frmGraph->addRow(S_GRAPH_TYPE, $cmbGType);
    // items beforehead, to get only_hostid for miny maxy items
    $only_hostid = null;
    $monitored_hosts = null;
    if (count($items)) {
        $frmGraph->addVar('items', $items);
        $keys = array_keys($items);
        $first = reset($keys);
        $last = end($keys);
        $items_table = new CTableInfo();
        foreach ($items as $gid => $gitem) {
            //if($graphtype == GRAPH_TYPE_STACKED && $gitem['type'] == GRAPH_ITEM_AGGREGATED) continue;
            $host = get_host_by_itemid($gitem['itemid']);
            $item = get_item_by_itemid($gitem['itemid']);
            if ($host['status'] == HOST_STATUS_TEMPLATE) {
                $only_hostid = $host['hostid'];
            } else {
                $monitored_hosts = 1;
            }
            if ($gitem['type'] == GRAPH_ITEM_AGGREGATED) {
                $color = '-';
            } else {
                $color = new CColorCell(null, $gitem['color']);
            }
            if ($gid == $first) {
                $do_up = null;
            } else {
                $do_up = new CSpan(S_UP, 'link');
                $do_up->onClick("return create_var('" . $frmGraph->getName() . "','move_up'," . $gid . ", true);");
            }
            if ($gid == $last) {
                $do_down = null;
            } else {
                $do_down = new CSpan(S_DOWN, 'link');
                $do_down->onClick("return create_var('" . $frmGraph->getName() . "','move_down'," . $gid . ", true);");
            }
            $description = new CSpan($host['host'] . ': ' . item_description($item), 'link');
            $description->onClick('return PopUp("popup_gitem.php?list_name=items&dstfrm=' . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . url_param($gitem, false) . url_param($gid, false, 'gid') . url_param(get_request('graphid', 0), false, 'graphid') . '",550,400,"graph_item_form");');
            if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) {
                $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), $color, array($do_up, SPACE . "|" . SPACE, $do_down)));
            } else {
                $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), $gitem['yaxisside'] == GRAPH_YAXIS_SIDE_LEFT ? S_LEFT : S_RIGHT, graph_item_drawtype2str($gitem["drawtype"], $gitem["type"]), $color, array($do_up, !is_null($do_up) && !is_null($do_down) ? SPACE . "|" . SPACE : '', $do_down)));
            }
        }
        $dedlete_button = new CButton('delete_item', S_DELETE_SELECTED);
    } else {
        $items_table = $dedlete_button = null;
    }
    //		$frmGraph->addRow(S_SHOW_LEGEND, new CCheckBox('legend',$legend, null, 1));
    if ($graphtype == GRAPH_TYPE_NORMAL || $graphtype == GRAPH_TYPE_STACKED) {
        $frmGraph->addRow(S_SHOW_WORKING_TIME, new CCheckBox('showworkperiod', $showworkperiod, null, 1));
        $frmGraph->addRow(S_SHOW_TRIGGERS, new CCheckBox('showtriggers', $showtriggers, null, 1));
        if ($graphtype == GRAPH_TYPE_NORMAL) {
            $percent_left = sprintf('%2.2f', $percent_left);
            $percent_right = sprintf('%2.2f', $percent_right);
            $pr_left_input = new CTextBox('percent_left', $percent_left, '5');
            $pr_left_chkbx = new CCheckBox('visible[percent_left]', 1, "javascript: ShowHide('percent_left');", 1);
            if ($percent_left == 0) {
                $pr_left_input->setAttribute('style', 'display: none;');
                $pr_left_chkbx->setChecked(0);
            }
            $pr_right_input = new CTextBox('percent_right', $percent_right, '5');
            $pr_right_chkbx = new CCheckBox('visible[percent_right]', 1, "javascript: ShowHide('percent_right');", 1);
            if ($percent_right == 0) {
                $pr_right_input->setAttribute('style', 'display: none;');
                $pr_right_chkbx->setChecked(0);
            }
            $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_LEFT . ')', array($pr_left_chkbx, $pr_left_input));
            $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_RIGHT . ')', array($pr_right_chkbx, $pr_right_input));
        }
        $yaxis_min = array();
        $cmbYType = new CComboBox('ymin_type', $ymin_type, 'javascript: submit();');
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM);
        $yaxis_min[] = $cmbYType;
        if ($ymin_type == GRAPH_YAXIS_TYPE_FIXED) {
            $yaxis_min[] = new CTextBox("yaxismin", $yaxismin, 9);
        } else {
            if ($ymin_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) {
                $frmGraph->addVar('yaxismin', $yaxismin);
                $ymin_name = '';
                if ($ymin_itemid > 0) {
                    $min_host = get_host_by_itemid($ymin_itemid);
                    $min_item = get_item_by_itemid($ymin_itemid);
                    $ymin_name = $min_host['host'] . ':' . item_description($min_item);
                }
                if (count($items)) {
                    $yaxis_min[] = new CTextBox("ymin_name", $ymin_name, 80, 'yes');
                    $yaxis_min[] = new CButton('yaxis_min', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . "&dstfld1=ymin_itemid" . "&dstfld2=ymin_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');");
                } else {
                    $yaxis_min[] = SPACE . S_ADD_GRAPH_ITEMS;
                }
            } else {
                $frmGraph->addVar('yaxismin', $yaxismin);
            }
        }
        $frmGraph->addRow(S_YAXIS_MIN_VALUE, $yaxis_min);
        $yaxis_max = array();
        $cmbYType = new CComboBox("ymax_type", $ymax_type, "submit()");
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED);
        $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM);
        $yaxis_max[] = $cmbYType;
        if ($ymax_type == GRAPH_YAXIS_TYPE_FIXED) {
            $yaxis_max[] = new CTextBox('yaxismax', $yaxismax, 9);
        } else {
            if ($ymax_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) {
                $frmGraph->addVar('yaxismax', $yaxismax);
                $ymax_name = '';
                if ($ymax_itemid > 0) {
                    $max_host = get_host_by_itemid($ymax_itemid);
                    $max_item = get_item_by_itemid($ymax_itemid);
                    $ymax_name = $max_host['host'] . ':' . item_description($max_item);
                }
                if (count($items)) {
                    $yaxis_max[] = new CTextBox("ymax_name", $ymax_name, 80, 'yes');
                    $yaxis_max[] = new CButton('yaxis_max', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . "&dstfld1=ymax_itemid" . "&dstfld2=ymax_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');");
                } else {
                    $yaxis_max[] = SPACE . S_ADD_GRAPH_ITEMS;
                }
            } else {
                $frmGraph->addVar('yaxismax', $yaxismax);
            }
        }
        $frmGraph->addRow(S_YAXIS_MAX_VALUE, $yaxis_max);
    } else {
        $frmGraph->addRow(S_SHOW_LEGEND, new CCheckBox('legend', $legend, null, 1));
        $frmGraph->addRow(S_3D_VIEW, new CCheckBox('graph3d', $graph3d, null, 1));
    }
    $frmGraph->addRow(S_ITEMS, array($items_table, new CButton('add_item', S_ADD, "return PopUp('popup_gitem.php?dstfrm=" . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . "',550,400,'graph_item_form');"), $dedlete_button));
    unset($items_table, $dedlete_button);
    $preView = new CButton('preview', S_PREVIEW);
    //$preView->setAttribute('style', 'float: left;');
    $frmGraph->addItemToBottomRow($preView);
    $frmGraph->addItemToBottomRow(SPACE);
    $frmGraph->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($_REQUEST['graphid'])) {
        $frmGraph->addItemToBottomRow(SPACE);
        $frmGraph->addItemToBottomRow(new CButton('clone', S_CLONE));
        $frmGraph->addItemToBottomRow(SPACE);
        $frmGraph->addItemToBottomRow(new CButtonDelete(S_DELETE_GRAPH_Q, url_param('graphid') . url_param('groupid') . url_param('hostid')));
    }
    $frmGraph->addItemToBottomRow(SPACE);
    $frmGraph->addItemToBottomRow(new CButtonCancel(url_param('groupid') . url_param('hostid')));
    $frmGraph->show();
}