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();
}
    insert_js('cookie.eraseArray("' . $path . '")');
}
/* header */
$form_button = new CForm(null, 'get');
if (!isset($_REQUEST['form'])) {
    $form_button->addItem(new CButton('form', S_CREATE_RULE));
}
$dscry_wdgt = new CWidget();
$dscry_wdgt->addPageHeader(S_CONFIGURATION_OF_DISCOVERY_BIG, $form_button);
if (isset($_REQUEST['form'])) {
    $form = new CFormTable();
    if (isset($_REQUEST['druleid'])) {
        $sql = 'SELECT * FROM drules WHERE druleid=' . $_REQUEST['druleid'];
        if ($rule_data = DBfetch(DBselect($sql))) {
            $form->addVar('druleid', $_REQUEST['druleid']);
            $form->setTitle(S_DISCOVERY_RULE . ' "' . $rule_data['name'] . '"');
        }
    } else {
        $form->setTitle(S_DISCOVERY_RULE);
    }
    $uniqueness_criteria = -1;
    if (isset($_REQUEST['druleid']) && $rule_data && !isset($_REQUEST["form_refresh"])) {
        $proxy_hostid = $rule_data['proxy_hostid'];
        $name = $rule_data['name'];
        $iprange = $rule_data['iprange'];
        $delay = $rule_data['delay'];
        $status = $rule_data['status'];
        //TODO init checks
        $dchecks = array();
        $db_checks = DBselect('SELECT dcheckid,type,ports,key_,snmp_community,snmpv3_securityname,' . 'snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase' . ' FROM dchecks' . ' WHERE druleid=' . $_REQUEST['druleid']);
        while ($check_data = DBfetch($db_checks)) {
Exemple #3
0
         $cmbUsrGrp->addItem($row['usrgrpid'], get_node_name_by_elid($row['usrgrpid'], null, ': ') . $row['name']);
     }
     $frmOther->addRow(S_USER_GROUP_FOR_DATABASE_DOWN_MESSAGE, $cmbUsrGrp);
     $frmOther->addItemToBottomRow(new CButton('save', S_SAVE));
     $cnf_wdgt->addItem($frmOther);
 } elseif ($_REQUEST['config'] == 6) {
     // Value Mapping
     if (isset($_REQUEST['form'])) {
         $frmValmap = new CFormTable(S_VALUE_MAP);
         $frmValmap->setHelp("web.mapping.php");
         $frmValmap->addVar("config", get_request("config", 6));
         if (isset($_REQUEST["valuemapid"])) {
             $frmValmap->addVar("valuemapid", $_REQUEST["valuemapid"]);
             $db_valuemaps = DBselect("select * FROM valuemaps" . " WHERE valuemapid=" . $_REQUEST["valuemapid"]);
             $db_valuemap = DBfetch($db_valuemaps);
             $frmValmap->setTitle(S_VALUE_MAP . ' "' . $db_valuemap["name"] . '"');
         }
         if (isset($_REQUEST["valuemapid"]) && !isset($_REQUEST["form_refresh"])) {
             $valuemap = array();
             $mapname = $db_valuemap["name"];
             $mappings = DBselect("select * FROM mappings WHERE valuemapid=" . $_REQUEST["valuemapid"]);
             while ($mapping = DBfetch($mappings)) {
                 $value = array("value" => $mapping["value"], "newvalue" => $mapping["newvalue"]);
                 array_push($valuemap, $value);
             }
         } else {
             $mapname = get_request("mapname", "");
             $valuemap = get_request("valuemap", array());
         }
         $frmValmap->addRow(S_NAME, new CTextBox("mapname", $mapname, 40));
         $i = 0;