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(); }