function make_sysmap_submenu() { $sysmapids = array(); $fav_sysmaps = get_favorites('web.favorite.sysmapids'); foreach ($fav_sysmaps as $key => $favorite) { $source = $favorite['source']; $sourceid = $favorite['value']; if (!($sysmap = get_sysmap_by_sysmapid($sourceid))) { continue; } $sysmapids[] = array('name' => $sysmap['name'], 'favobj' => 'sysmapid', 'favid' => $sourceid, 'action' => 'remove'); } if (!empty($sysmapids)) { $sysmapids[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_MAPS, 'favobj' => 'sysmapid', 'favid' => 0, 'action' => 'remove'); } return $sysmapids; }
function insert_map_link_form() { $frmCnct = new CFormTable('New connector', 'sysmap.php'); $frmCnct->SetHelp('web.sysmap.connector.php'); $frmCnct->addVar('sysmapid', $_REQUEST['sysmapid']); if (isset($_REQUEST['linkid']) && !isset($_REQUEST['form_refresh'])) { $frmCnct->addVar('linkid', $_REQUEST['linkid']); $db_links = DBselect('SELECT * FROM sysmaps_links WHERE linkid=' . $_REQUEST['linkid']); $db_link = DBfetch($db_links); $selementid1 = $db_link['selementid1']; $selementid2 = $db_link['selementid2']; $triggers = array(); $drawtype = $db_link['drawtype']; $color = $db_link['color']; $res = DBselect('SELECT * FROM sysmaps_link_triggers WHERE linkid=' . $_REQUEST['linkid']); while ($rows = DBfetch($res)) { $triggers[] = $rows; } } else { if (isset($_REQUEST['linkid'])) { $frmCnct->addVar('linkid', $_REQUEST['linkid']); } $selementid1 = get_request('selementid1', 0); $selementid2 = get_request('selementid2', 0); $triggers = get_request('triggers', array()); $drawtype = get_request('drawtype', 0); $color = get_request('color', 0); } /* START comboboxes preparations */ $cmbElements1 = new CComboBox('selementid1', $selementid1); $cmbElements2 = new CComboBox('selementid2', $selementid2); $db_selements = DBselect('SELECT selementid,label,elementid,elementtype ' . ' FROM sysmaps_elements ' . ' WHERE sysmapid=' . $_REQUEST['sysmapid']); while ($db_selement = DBfetch($db_selements)) { $label = $db_selement['label']; if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) { $db_host = get_host_by_hostid($db_selement['elementid']); $label .= ':' . $db_host['host']; } else { if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP) { $db_map = get_sysmap_by_sysmapid($db_selement['elementid']); $label .= ':' . $db_map['name']; } else { if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) { if ($db_selement['elementid'] > 0) { $label .= ':' . expand_trigger_description($db_selement['elementid']); } } else { if ($db_selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) { if ($db_selement['elementid'] > 0) { $db_group = DBfetch(DBselect('SELECT name FROM groups WHERE groupid=' . $db_selement['elementid'])); $label .= ':' . $db_group['name']; } } } } } $cmbElements1->addItem($db_selement['selementid'], $label); $cmbElements2->addItem($db_selement['selementid'], $label); } $cmbType = new CComboBox('drawtype', $drawtype); foreach (map_link_drawtypes() as $i) { $value = map_link_drawtype2str($i); $cmbType->addItem($i, $value); } /* END preparation */ $frmCnct->addRow(S_ELEMENT_1, $cmbElements1); $frmCnct->addRow(S_ELEMENT_2, $cmbElements2); //trigger links foreach ($triggers as $id => $trigger) { if (isset($trigger['triggerid'])) { $triggers[$id]['description'] = expand_trigger_description($trigger['triggerid']); } } $table = new CTable(); $table->SetClass('tableinfo'); $table->setOddRowClass('even_row'); $table->setEvenRowClass('even_row'); $table->options['cellpadding'] = 3; $table->options['cellspacing'] = 1; $table->headerClass = 'header'; $table->footerClass = 'footer'; $table->SetHeader(array(new CCheckBox('all_triggers', null, "CheckAll('" . $frmCnct->GetName() . "','all_triggers','triggers');"), S_TRIGGERS, S_TYPE, S_COLOR)); $table->addOption('id', 'link_triggers'); foreach ($triggers as $id => $trigger) { if (!isset($trigger['triggerid'])) { continue; } $colorbox = new CSpan(SPACE . SPACE . SPACE); $colorbox->addOption('style', 'text-decoration: none; outline-color: black; outline-style: solid; outline-width: 1px; background-color: #' . $trigger['color'] . ';'); $table->addRow(array(array(new CCheckBox('triggers[' . $trigger['triggerid'] . '][triggerid]', null, null, $trigger['triggerid']), new CVar('triggers[' . $trigger['triggerid'] . '][triggerid]', $trigger['triggerid'])), array(new CLink($trigger['description'], "javascript: openWinCentered('popup_link_tr.php?form=1&dstfrm=" . $frmCnct->GetName() . "&triggerid=" . $trigger['triggerid'] . url_param('linkid') . "','ZBX_Link_Indicator',560,260,'scrollbars=1, toolbar=0, menubar=0, resizable=0');"), new CVar('triggers[' . $trigger['triggerid'] . '][description]', $trigger['description'])), array(map_link_drawtype2str($trigger['drawtype']), new CVar('triggers[' . $trigger['triggerid'] . '][drawtype]', $trigger['drawtype'])), array($colorbox, new CVar('triggers[' . $trigger['triggerid'] . '][color]', $trigger['color'])))); } $btnadd = new CButton('btn1', S_ADD, "javascript: openWinCentered('popup_link_tr.php?form=1&dstfrm=" . $frmCnct->GetName() . url_param('linkid') . "','ZBX_Link_Indicator',560,180,'scrollbars=1, toolbar=0, menubar=0, resizable=0');", 'T'); $btnRemove = new CButton('btn1', S_REMOVE, "javascript: remove_childs('" . $frmCnct->GetName() . "','triggers','tr');", 'T'); $btnadd->SetType('button'); $frmCnct->addRow(S_LINK_STATUS_INDICATORS, array($table, BR(), $btnadd, $btnRemove)); //---------- $frmCnct->addRow(S_TYPE . ' (' . S_OK_BIG . ')', $cmbType); $frmCnct->addRow(S_COLOR . ' (' . S_OK_BIG . ')', new CColor('color', $color)); $frmCnct->addItemToBottomRow(new CButton("save_link", S_SAVE)); if (isset($_REQUEST["linkid"])) { $frmCnct->addItemToBottomRow(SPACE); $frmCnct->addItemToBottomRow(new CButtonDelete("Delete link?", url_param("linkid") . url_param("sysmapid"))); } $frmCnct->addItemToBottomRow(SPACE); $frmCnct->addItemToBottomRow(new CButtonCancel(url_param("sysmapid"))); $frmCnct->Show(); }
function get_resource_name($permission, $id) { $res = '-'; if ($permission == 'Graph') { if (isset($id) && $id != 0) { if ($graph = get_graph_by_graphid($id)) { $res = $graph['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All graphs'; } } } else { if ($permission == 'Host') { if (isset($id) && $id != 0) { if ($host = get_host_by_hostid($id)) { $res = $host['host']; } } else { if (!isset($id) || $id == 0) { $res = 'All hosts'; } } } else { if ($permission == 'Screen') { if (isset($id) && $id != 0) { if ($screen = get_screen_by_screenid($id)) { $res = $screen['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All screens'; } } } else { if ($permission == 'Item') { if (isset($id) && $id != 0) { if ($item = get_item_by_itemid($id)) { if ($host = get_host_by_hostid($item['hostid'])) { $res = $host['host'] . ':' . $item['description']; } } } else { if (!isset($id) || $id == 0) { $res = 'All items'; } } } else { if ($permission == 'User') { if (isset($id) && $id != 0) { if ($user = get_user_by_userid($id)) { $res = $user['alias']; } } else { if (!isset($id) || $id == 0) { $res = 'All users'; } } } else { if ($permission == 'Network map') { if (isset($id) && $id != 0) { if ($user = get_sysmap_by_sysmapid($id)) { $res = $user['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All maps'; } } } else { if ($permission == 'Application') { if (isset($id) && $id > 0) { if ($app = get_application_by_applicationid($id)) { $res = $app['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All applications'; } } } else { if ($permission == 'Service') { if (isset($id) && $id > 0) { if ($service = get_service_by_serviceid($id)) { $res = $service['name']; } } else { if (!isset($id) || $id == 0) { $res = 'All services'; } } } } } } } } } } if ($res == '-' && isset($id) && $id > 0) { $res = $id; } return $res; }
$triggers[$id]['description'] = expand_trigger_description($trigger['triggerid']); } $description[] = $triggers[$id]['description']; } if (empty($description)) { $description = '-'; } /* draw row */ $table->addRow(array(new CLink('link ' . $i++, 'sysmap.php?sysmapid=' . $_REQUEST['sysmapid'] . '&form=update&linkid=' . $row['linkid'], 'action'), $label1, $label2, $description)); } $table->Show(); } } show_messages(); echo SBR; $map = get_sysmap_by_sysmapid($_REQUEST['sysmapid']); show_table_header($map['name']); $table = new CTable(NULL, 'map'); if (isset($_REQUEST['sysmapid'])) { $linkMap = new CMap('links' . $_REQUEST['sysmapid'] . '_' . rand(0, 100000)); $db_elements = DBselect('select * from sysmaps_elements where sysmapid=' . $_REQUEST['sysmapid']); while ($db_element = DBfetch($db_elements)) { $tmp_img = get_png_by_selementid($db_element['selementid']); if (!$tmp_img) { continue; } $x1_ = $db_element['x']; $y1_ = $db_element['y']; $x2_ = $db_element['x'] + imagesx($tmp_img); $y2_ = $db_element['y'] + imagesy($tmp_img); $linkMap->addRectArea($x1_, $y1_, $x2_, $y2_, 'sysmap.php?form=update&sysmapid=' . $_REQUEST['sysmapid'] . '&selementid=' . $db_element['selementid'], $db_element['label']);
$form->AddItem($cmbMaps); $p_elements[] = get_table_header($text, $form); } $table = new CTable(S_NO_MAPS_DEFINED, "map"); if (isset($_REQUEST["sysmapid"])) { $action_map = get_action_map_by_sysmapid($_REQUEST["sysmapid"]); $table->AddRow($action_map); $imgMap = new CImg("map.php?noedit=1&sysmapid=" . $_REQUEST["sysmapid"]); $imgMap->SetMap($action_map->GetName()); $table->AddRow($imgMap); } $p_elements[] = $table; $icon = null; $fs_icon = null; if (isset($_REQUEST["sysmapid"])) { $sysmap = get_sysmap_by_sysmapid($_REQUEST["sysmapid"]); $text = $all_maps[$_REQUEST["sysmapid"]]; if (infavorites('web.favorite.sysmapids', $_REQUEST['sysmapid'], 'sysmapid')) { $icon = new CDiv(SPACE, 'iconminus'); $icon->AddOption('title', S_REMOVE_FROM . ' ' . S_FAVORITES); $icon->AddAction('onclick', new CScript("javascript: rm4favorites('sysmapid','" . $_REQUEST["sysmapid"] . "',0);")); } else { $icon = new CDiv(SPACE, 'iconplus'); $icon->AddOption('title', S_ADD_TO . ' ' . S_FAVORITES); $icon->AddAction('onclick', new CScript("javascript: add2favorites('sysmapid','" . $_REQUEST["sysmapid"] . "');")); } $icon->AddOption('id', 'addrm_fav'); $url = '?sysmapid=' . $_REQUEST['sysmapid'] . ($_REQUEST['fullscreen'] ? '' : '&fullscreen=1'); $fs_icon = new CDiv(SPACE, 'fullscreen'); $fs_icon->AddOption('title', $_REQUEST['fullscreen'] ? S_NORMAL . ' ' . S_VIEW : S_FULLSCREEN); $fs_icon->AddAction('onclick', new CScript("javascript: document.location = '" . $url . "';"));
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; }