Beispiel #1
0
function get_action_map_by_sysmapid($sysmapid)
{
    $action_map = new CMap("links{$sysmapid}");
    $db_elements = DBselect('SELECT * FROM sysmaps_elements WHERE sysmapid=' . $sysmapid);
    while ($db_element = DBfetch($db_elements)) {
        $url = $db_element["url"];
        $alt = "Label: " . $db_element["label"];
        $scripts_by_hosts = null;
        if ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST) {
            $host = get_host_by_hostid($db_element["elementid"]);
            if ($host["status"] != HOST_STATUS_MONITORED) {
                continue;
            }
            $scripts_by_hosts = get_accessible_scripts_by_hosts(array($db_element["elementid"]));
            if (empty($url)) {
                $url = 'tr_status.php?hostid=' . $db_element['elementid'] . '&noactions=true&onlytrue=true&compact=true';
            }
            $alt = "Host: " . $host["host"] . " " . $alt;
        } else {
            if ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP) {
                $map = get_sysmap_by_sysmapid($db_element["elementid"]);
                if (empty($url)) {
                    $url = "maps.php?sysmapid=" . $db_element["elementid"];
                }
                $alt = "Host: " . $map["name"] . " " . $alt;
            } elseif ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_TRIGGER) {
                if (empty($url) && $db_element["elementid"] != 0) {
                    $url = "events.php?triggerid=" . $db_element["elementid"];
                }
            } else {
                if ($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) {
                    if (empty($url) && $db_element["elementid"] != 0) {
                        $url = "events.php?hostid=0&groupid=" . $db_element["elementid"];
                    }
                }
            }
        }
        if (empty($url)) {
            continue;
        }
        $back = get_png_by_selementid($db_element["selementid"]);
        if (!$back) {
            continue;
        }
        $x1_ = $db_element["x"];
        $y1_ = $db_element["y"];
        $x2_ = $db_element["x"] + imagesx($back);
        $y2_ = $db_element["y"] + imagesy($back);
        $r_area = new CArea(array($x1_, $y1_, $x2_, $y2_), $url, $alt, 'rect');
        if (!empty($scripts_by_hosts)) {
            $menus = '';
            $host_nodeid = id2nodeid($db_element["elementid"]);
            foreach ($scripts_by_hosts[$db_element["elementid"]] as $id => $script) {
                $script_nodeid = id2nodeid($script['scriptid']);
                if (bccomp($host_nodeid, $script_nodeid) == 0) {
                    $menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $db_element["elementid"] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
                }
            }
            $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],";
            $menus .= "['" . S_STATUS_OF_TRIGGERS . "',\"javascript: redirect('tr_status.php?hostid=" . $db_element['elementid'] . "&noactions=true&onlytrue=true&compact=true')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
            if (!empty($db_element["url"])) {
                $menus .= "['" . S_MAP . SPACE . S_URL . "',\"javascript: redirect('" . $url . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
            }
            $menus = trim($menus, ',');
            $menus = "show_popup_menu(event,[[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus . "],180); cancelEvent(event);";
            $r_area->AddAction('onclick', 'javascript: ' . $menus);
        }
        $action_map->AddItem($r_area);
        //AddRectArea($x1_,$y1_,$x2_,$y2_, $url, $alt);
    }
    $jsmenu = new CPUMenu(null, 170);
    $jsmenu->InsertJavaScript();
    return $action_map;
}