Beispiel #1
0
function insert_map_element_form()
{
    global $USER_DETAILS;
    $frmEl = new CFormTable('New map element', 'sysmap.php');
    $frmEl->SetHelp('web.sysmap.host.php');
    $frmEl->addVar('sysmapid', $_REQUEST['sysmapid']);
    if (isset($_REQUEST['selementid'])) {
        $frmEl->addVar('selementid', $_REQUEST['selementid']);
        $element = get_sysmaps_element_by_selementid($_REQUEST['selementid']);
        $frmEl->SetTitle('Map element "' . $element['label'] . '"');
    }
    if (isset($_REQUEST['selementid']) && !isset($_REQUEST['form_refresh'])) {
        $elementid = $element['elementid'];
        $elementtype = $element['elementtype'];
        $label = $element['label'];
        $x = $element['x'];
        $y = $element['y'];
        $url = $element['url'];
        $iconid_off = $element['iconid_off'];
        $iconid_on = $element['iconid_on'];
        $iconid_unknown = $element['iconid_unknown'];
        $iconid_disabled = $element['iconid_disabled'];
        $label_location = $element['label_location'];
        if (is_null($label_location)) {
            $label_location = -1;
        }
    } else {
        $elementid = get_request('elementid', 0);
        $elementtype = get_request('elementtype', SYSMAP_ELEMENT_TYPE_HOST);
        $label = get_request('label', '');
        $x = get_request('x', 0);
        $y = get_request('y', 0);
        $url = get_request('url', '');
        $iconid_off = get_request('iconid_off', 0);
        $iconid_on = get_request('iconid_on', 0);
        $iconid_unknown = get_request('iconid_unknown', 0);
        $iconid_disabled = get_request('iconid_disabled', 0);
        $label_location = get_request('label_location', '-1');
    }
    $cmbType = new CComboBox('elementtype', $elementtype, 'submit()');
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, null, get_current_nodeid(true));
    $sql = 'SELECT DISTINCT n.name as node_name,h.hostid,h.host ' . ' FROM hosts h' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('h.hostid') . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . ' ORDER BY node_name,h.host';
    $db_hosts = DBselect($sql);
    if ($db_hosts) {
        $cmbType->addItem(SYSMAP_ELEMENT_TYPE_HOST, S_HOST);
    }
    $db_maps = DBselect('SELECT sysmapid FROM sysmaps WHERE sysmapid!=' . $_REQUEST['sysmapid']);
    if (DBfetch($db_maps)) {
        $cmbType->addItem(SYSMAP_ELEMENT_TYPE_MAP, S_MAP);
    }
    $cmbType->addItem(SYSMAP_ELEMENT_TYPE_TRIGGER, S_TRIGGER);
    $cmbType->addItem(SYSMAP_ELEMENT_TYPE_HOST_GROUP, S_HOST_GROUP);
    $cmbType->addItem(SYSMAP_ELEMENT_TYPE_IMAGE, S_IMAGE);
    $frmEl->addRow(S_TYPE, $cmbType);
    $frmEl->addRow(S_LABEL, new CTextArea('label', $label, 32, 4));
    $cmbLocation = new CComboBox('label_location', $label_location);
    $cmbLocation->addItem(-1, '-');
    $cmbLocation->addItem(0, S_BOTTOM);
    $cmbLocation->addItem(1, S_LEFT);
    $cmbLocation->addItem(2, S_RIGHT);
    $cmbLocation->addItem(3, S_TOP);
    $frmEl->addRow(S_LABEL_LOCATION, $cmbLocation);
    if ($elementtype == SYSMAP_ELEMENT_TYPE_HOST) {
        $host = '';
        $host_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,h.hostid,h.host ' . ' FROM hosts h ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('h.hostid') . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . ' AND hostid=' . $elementid . ' ORDER BY node_name,h.host'));
        if ($host_info) {
            $host = $host_info['host'];
        } else {
            $elementid = 0;
        }
        if ($elementid == 0) {
            $host = '';
            $elementid = 0;
        }
        $frmEl->addVar('elementid', $elementid);
        $frmEl->addRow(S_HOST, array(new CTextBox('host', $host, 32, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmEl->GetName() . "&dstfld1=elementid&dstfld2=host&srctbl=hosts&srcfld1=hostid&srcfld2=host',450,450);", 'T')));
    } else {
        if ($elementtype == SYSMAP_ELEMENT_TYPE_MAP) {
            $cmbMaps = new CComboBox('elementid', $elementid);
            $db_maps = DBselect('SELECT DISTINCT n.name as node_name,s.sysmapid,s.name ' . ' FROM sysmaps s' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('s.sysmapid') . ' ORDER BY node_name,s.name');
            while ($db_map = DBfetch($db_maps)) {
                if (!sysmap_accessible($db_map['sysmapid'], PERM_READ_ONLY)) {
                    continue;
                }
                $node_name = isset($db_map['node_name']) ? '(' . $db_map['node_name'] . ') ' : '';
                $cmbMaps->addItem($db_map['sysmapid'], $node_name . $db_map['name']);
            }
            $frmEl->addRow(S_MAP, $cmbMaps);
        } else {
            if ($elementtype == SYSMAP_ELEMENT_TYPE_TRIGGER) {
                $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY, get_current_nodeid(true));
                $trigger = '';
                $trigger_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,h.hostid,h.host,t.*' . ' FROM triggers t ' . ' LEFT JOIN functions f on t.triggerid=f.triggerid ' . ' LEFT JOIN items i on i.itemid=f.itemid ' . ' LEFT JOIN hosts h on h.hostid=i.hostid ' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('t.triggerid') . ' WHERE t.triggerid=' . $elementid . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' ORDER BY node_name,h.host,t.description'));
                if ($trigger_info) {
                    $trigger = expand_trigger_description_by_data($trigger_info);
                } else {
                    $elementid = 0;
                }
                if ($elementid == 0) {
                    $trigger = '';
                    $elementid = 0;
                }
                $frmEl->addVar('elementid', $elementid);
                $frmEl->addRow(S_TRIGGER, array(new CTextBox('trigger', $trigger, 32, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmEl->GetName() . "&dstfld1=elementid&dstfld2=trigger&srctbl=triggers&srcfld1=triggerid&srcfld2=description');", 'T')));
            } else {
                if ($elementtype == SYSMAP_ELEMENT_TYPE_HOST_GROUP) {
                    $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY, null, get_current_nodeid(true));
                    $group = '';
                    $group_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name ' . ' FROM groups g ' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND g.groupid=' . $elementid . ' ORDER BY node_name,g.name'));
                    if ($group_info) {
                        $group = $group_info['name'];
                    } else {
                        $elementid = 0;
                    }
                    if ($elementid == 0) {
                        $group = '';
                        $elementid = 0;
                    }
                    $frmEl->addVar('elementid', $elementid);
                    $frmEl->addRow(S_HOST_GROUP, array(new CTextBox('group', $group, 32, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmEl->GetName() . "&dstfld1=elementid&dstfld2=group&srctbl=host_group&srcfld1=groupid&srcfld2=name',450,450);", 'T')));
                } else {
                    if ($elementtype == SYSMAP_ELEMENT_TYPE_IMAGE) {
                        $frmEl->addVar('elementid', 0);
                    }
                }
            }
        }
    }
    $cmbIconOff = new CComboBox('iconid_off', $iconid_off);
    $cmbIconOn = new CComboBox('iconid_on', $iconid_on);
    if ($elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
        $cmbIconUnknown = new CComboBox('iconid_unknown', $iconid_unknown);
    }
    if ($elementtype != SYSMAP_ELEMENT_TYPE_HOST_GROUP && $elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
        $cmbIconDisabled = new CComboBox('iconid_disabled', $iconid_disabled);
    }
    $result = DBselect('SELECT * FROM images WHERE imagetype=1 AND ' . DBin_node('imageid') . ' order by name');
    while ($row = DBfetch($result)) {
        $row['name'] = get_node_name_by_elid($row['imageid']) . $row['name'];
        $cmbIconOff->addItem($row['imageid'], $row['name']);
        $cmbIconOn->addItem($row['imageid'], $row['name']);
        if ($elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
            $cmbIconUnknown->addItem($row['imageid'], $row['name']);
        }
        if ($elementtype != SYSMAP_ELEMENT_TYPE_HOST_GROUP && $elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
            $cmbIconDisabled->addItem($row['imageid'], $row['name']);
        }
    }
    $frmEl->addRow(S_ICON_OK, $cmbIconOff);
    if ($elementtype != SYSMAP_ELEMENT_TYPE_IMAGE) {
        $frmEl->addRow(S_ICON_PROBLEM, $cmbIconOn);
    } else {
        $frmEl->addVar('iconid_on', 0);
    }
    if ($elementtype != SYSMAP_ELEMENT_TYPE_MAP && $elementtype != SYSMAP_ELEMENT_TYPE_IMAGE) {
        $frmEl->addRow(S_ICON_UNKNOWN, $cmbIconUnknown);
    } else {
        $frmEl->addVar('iconid_unknown', 0);
    }
    if ($elementtype != SYSMAP_ELEMENT_TYPE_HOST_GROUP && $elementtype != SYSMAP_ELEMENT_TYPE_MAP && $elementtype != SYSMAP_ELEMENT_TYPE_IMAGE) {
        $frmEl->addRow(S_ICON_DISABLED, $cmbIconDisabled);
    } else {
        $frmEl->addVar('iconid_disabled', 0);
    }
    $frmEl->addRow(S_COORDINATE_X, new CNumericBox('x', $x, 5));
    $frmEl->addRow(S_COORDINATE_Y, new CNumericBox('y', $y, 5));
    $frmEl->addRow(S_URL, new CTextBox('url', $url, 64));
    $frmEl->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($_REQUEST['selementid'])) {
        $frmEl->addItemToBottomRow(SPACE);
        $frmEl->addItemToBottomRow(new CButtonDelete('Delete element?', url_param('form') . url_param('selementid') . url_param('sysmapid')));
    }
    $frmEl->addItemToBottomRow(SPACE);
    $frmEl->addItemToBottomRow(new CButtonCancel(url_param('sysmapid')));
    $frmEl->Show();
}
Beispiel #2
0
function get_icon_center_by_selementid($selementid)
{
    $element = get_sysmaps_element_by_selementid($selementid);
    $x = $element["x"];
    $y = $element["y"];
    $image = get_png_by_selementid($selementid);
    if ($image) {
        $x += imagesx($image) / 2;
        $y += imagesy($image) / 2;
    }
    return array($x, $y);
}