function check_screen_recursion($mother_screenid, $child_screenid) { if (bccomp($mother_screenid, $child_screenid) == 0) { return true; } $db_scr_items = DBselect('SELECT si.resourceid' . ' FROM screens_items si' . ' WHERE si.screenid=' . zbx_dbstr($child_screenid) . ' AND si.resourcetype=' . SCREEN_RESOURCE_SCREEN); while ($scr_item = DBfetch($db_scr_items)) { if (check_screen_recursion($mother_screenid, $scr_item['resourceid'])) { return true; } } return false; }
function get_screen_item_form() { global $USER_DETAILS; $form = new CFormTable(S_SCREEN_CELL_CONFIGURATION, 'screenedit.php?screenid=' . $_REQUEST['screenid']); $form->SetHelp('web.screenedit.cell.php'); if (isset($_REQUEST['screenitemid'])) { $sql = 'SELECT * ' . ' FROM screens_items' . ' WHERE screenid=' . $_REQUEST['screenid'] . ' AND screenitemid=' . $_REQUEST['screenitemid']; $iresult = DBSelect($sql); $form->addVar('screenitemid', $_REQUEST['screenitemid']); } else { $form->addVar('x', $_REQUEST['x']); $form->addVar('y', $_REQUEST['y']); } if (isset($_REQUEST['screenitemid']) && !isset($_REQUEST['form_refresh'])) { $irow = DBfetch($iresult); $resourcetype = $irow['resourcetype']; $resourceid = $irow['resourceid']; $width = $irow['width']; $height = $irow['height']; $colspan = $irow['colspan']; $rowspan = $irow['rowspan']; $elements = $irow['elements']; $valign = $irow['valign']; $halign = $irow['halign']; $style = $irow['style']; $url = $irow['url']; $dynamic = $irow['dynamic']; } else { $resourcetype = get_request('resourcetype', 0); $resourceid = get_request('resourceid', 0); $width = get_request('width', 500); $height = get_request('height', 100); $colspan = get_request('colspan', 0); $rowspan = get_request('rowspan', 0); $elements = get_request('elements', 25); $valign = get_request('valign', VALIGN_DEFAULT); $halign = get_request('halign', HALIGN_DEFAULT); $style = get_request('style', 0); $url = get_request('url', ''); $dynamic = get_request('dynamic', SCREEN_SIMPLE_ITEM); } $form->addVar('screenid', $_REQUEST['screenid']); // a-z order!!! $cmbRes = new CCombobox('resourcetype', $resourcetype, 'submit()'); $cmbRes->addItem(SCREEN_RESOURCE_CLOCK, S_CLOCK); $cmbRes->addItem(SCREEN_RESOURCE_DATA_OVERVIEW, S_DATA_OVERVIEW); $cmbRes->addItem(SCREEN_RESOURCE_GRAPH, S_GRAPH); $cmbRes->addItem(SCREEN_RESOURCE_ACTIONS, S_HISTORY_OF_ACTIONS); $cmbRes->addItem(SCREEN_RESOURCE_EVENTS, S_HISTORY_OF_EVENTS); $cmbRes->addItem(SCREEN_RESOURCE_HOSTS_INFO, S_HOSTS_INFO); $cmbRes->addItem(SCREEN_RESOURCE_MAP, S_MAP); $cmbRes->addItem(SCREEN_RESOURCE_PLAIN_TEXT, S_PLAIN_TEXT); $cmbRes->addItem(SCREEN_RESOURCE_SCREEN, S_SCREEN); $cmbRes->addItem(SCREEN_RESOURCE_SERVER_INFO, S_SERVER_INFO); $cmbRes->addItem(SCREEN_RESOURCE_SIMPLE_GRAPH, S_SIMPLE_GRAPH); $cmbRes->addItem(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, S_STATUS_OF_HOSTGROUP_TRIGGERS); $cmbRes->addItem(SCREEN_RESOURCE_HOST_TRIGGERS, S_STATUS_OF_HOST_TRIGGERS); $cmbRes->addItem(SCREEN_RESOURCE_SYSTEM_STATUS, S_SYSTEM_STATUS); $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_INFO, S_TRIGGERS_INFO); $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, S_TRIGGERS_OVERVIEW); $cmbRes->addItem(SCREEN_RESOURCE_URL, S_URL); $form->addRow(S_RESOURCE, $cmbRes); if ($resourcetype == SCREEN_RESOURCE_GRAPH) { // User-defined graph $options = array('graphids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND); $graphs = CGraph::get($options); $caption = ''; $id = 0; if (!empty($graphs)) { $id = $resourceid; $graph = reset($graphs); order_result($graph['hosts'], 'host'); $graph['host'] = reset($graph['hosts']); $caption = $graph['host']['host'] . ':' . $graph['name']; $nodeName = get_node_name_by_elid($graph['host']['hostid']); if (!zbx_empty($nodeName)) { $caption = '(' . $nodeName . ') ' . $caption; } } $form->addVar('resourceid', $id); $textfield = new CTextbox('caption', $caption, 75, 'yes'); $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&real_hosts=1&dstfld1=resourceid&dstfld2=caption&srctbl=graphs&srcfld1=graphid&srcfld2=name',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_GRAPH_NAME, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) { // Simple graph $options = array('itemids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND); $items = CItem::get($options); $caption = ''; $id = 0; if (!empty($items)) { $id = $resourceid; $item = reset($items); $item['host'] = reset($item['hosts']); $caption = item_description($item); $nodeName = get_node_name_by_elid($item['itemid']); if (!zbx_empty($nodeName)) { $caption = '(' . $nodeName . ') ' . $caption; } } $form->addVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 75, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&real_hosts=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=simple_graph&srcfld1=itemid&srcfld2=description',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_MAP) { // Map $options = array('sysmapids' => $resourceid, 'output' => API_OUTPUT_EXTEND); $maps = CMap::get($options); $caption = ''; $id = 0; if (!empty($maps)) { $id = $resourceid; $map = reset($maps); $caption = $map['name']; $nodeName = get_node_name_by_elid($map['sysmapid']); if (!zbx_empty($nodeName)) { $caption = '(' . $nodeName . ') ' . $caption; } } $form->addVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 60, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=sysmaps&srcfld1=sysmapid&srcfld2=name',400,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) { // Plain text $options = array('itemids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND); $items = CItem::get($options); $caption = ''; $id = 0; if (!empty($items)) { $id = $resourceid; $item = reset($items); $item['host'] = reset($item['hosts']); $caption = item_description($item); $nodeName = get_node_name_by_elid($item['itemid']); if (!zbx_empty($nodeName)) { $caption = '(' . $nodeName . ') ' . $caption; } } $form->addVar('resourceid', $id); $textfield = new CTextbox('caption', $caption, 75, 'yes'); $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=plain_text&srcfld1=itemid&srcfld2=description',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2)); $form->addRow(S_SHOW_TEXT_AS_HTML, new CCheckBox('style', $style, null, 1)); } else { if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_HOST_TRIGGERS))) { // Status of triggers $caption = ''; $id = 0; if (SCREEN_RESOURCE_HOSTGROUP_TRIGGERS == $resourcetype) { if ($resourceid > 0) { $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1); $groups = CHostgroup::get($options); foreach ($groups as $gnum => $group) { $caption = get_node_name_by_elid($group['groupid'], true, ':') . $group['name']; $id = $resourceid; } } $form->addVar('resourceid', $id); $textfield = new CTextbox('caption', $caption, 60, 'yes'); $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=host_group&srcfld1=groupid&srcfld2=name',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn)); } else { if ($resourceid > 0) { $options = array('hostids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1); $hosts = CHost::get($options); foreach ($hosts as $hnum => $host) { $caption = get_node_name_by_elid($host['hostid'], true, ':') . $host['host']; $id = $resourceid; } } $form->addVar('resourceid', $id); $textfield = new CTextbox('caption', $caption, 60, 'yes'); $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=hosts&srcfld1=hostid&srcfld2=host',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_HOST, array($textfield, SPACE, $selectbtn)); } $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2)); } else { if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_EVENTS, SCREEN_RESOURCE_ACTIONS))) { // History of actions // History of events $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2)); $form->addVar('resourceid', 0); } else { if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) { // Overviews $caption = ''; $id = 0; if ($resourceid > 0) { $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1); $groups = CHostgroup::get($options); foreach ($groups as $gnum => $group) { $caption = get_node_name_by_elid($group['groupid'], true, ':') . $group['name']; $id = $resourceid; } } $form->addVar('resourceid', $id); $textfield = new CTextbox('caption', $caption, 75, 'yes'); $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=overview&srcfld1=groupid&srcfld2=name',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_SCREEN) { // Screens $caption = ''; $id = 0; if ($resourceid > 0) { $result = DBselect('SELECT DISTINCT n.name as node_name,s.screenid,s.name ' . ' FROM screens s ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.screenid') . ' WHERE s.screenid=' . $resourceid); while ($row = DBfetch($result)) { $r = CScreen::get(array('screenids' => $row['screenid'], 'output' => API_OUTPUT_SHORTEN)); if (empty($r)) { continue; } if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) { continue; } $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['name']; $id = $resourceid; } } $form->addVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 60, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=screens2&srcfld1=screenid&srcfld2=name&screenid=" . $_REQUEST['screenid'] . "',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_HOSTS_INFO || $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) { // HOSTS info $caption = ''; $id = 0; $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY); if (remove_nodes_from_id($resourceid) > 0) { $result = DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name ' . ' FROM hosts_groups hg, groups g ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND g.groupid=' . $resourceid); while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['name']; $id = $resourceid; } } else { if (remove_nodes_from_id($resourceid) == 0) { $result = DBselect('SELECT DISTINCT n.name as node_name ' . ' FROM nodes n ' . ' WHERE n.nodeid=' . id2nodeid($resourceid)); while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . S_MINUS_ALL_GROUPS_MINUS; $id = $resourceid; } } } $form->addVar('resourceid', $id); $textfield = new CTextbox('caption', $caption, 60, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=host_group_scr&srcfld1=groupid&srcfld2=name',480,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn)); } else { // SCREEN_RESOURCE_CLOCK $form->addVar('resourceid', 0); } } } } } } } } } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO))) { $cmbStyle = new CComboBox("style", $style); $cmbStyle->addItem(STYLE_HORISONTAL, S_HORIZONTAL); $cmbStyle->addItem(STYLE_VERTICAL, S_VERTICAL); $form->addRow(S_STYLE, $cmbStyle); } else { if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) { $cmbStyle = new CComboBox('style', $style); $cmbStyle->addItem(STYLE_LEFT, S_LEFT); $cmbStyle->addItem(STYLE_TOP, S_TOP); $form->addRow(S_HOSTS_LOCATION, $cmbStyle); } else { if ($resourcetype == SCREEN_RESOURCE_CLOCK) { $cmbStyle = new CComboBox('style', $style); $cmbStyle->addItem(TIME_TYPE_LOCAL, S_LOCAL_TIME); $cmbStyle->addItem(TIME_TYPE_SERVER, S_SERVER_TIME); $form->addRow(S_TIME_TYPE, $cmbStyle); } else { $form->addVar('style', 0); } } } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_URL))) { $form->addRow(S_URL, new CTextBox('url', $url, 60)); } else { $form->addVar('url', ''); } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) { $form->addRow(S_WIDTH, new CNumericBox('width', $width, 5)); $form->addRow(S_HEIGHT, new CNumericBox('height', $height, 5)); } else { $form->addVar('width', 500); $form->addVar('height', 100); } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_MAP, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) { $cmbHalign = new CComboBox('halign', $halign); $cmbHalign->addItem(HALIGN_CENTER, S_CENTRE); $cmbHalign->addItem(HALIGN_LEFT, S_LEFT); $cmbHalign->addItem(HALIGN_RIGHT, S_RIGHT); $form->addRow(S_HORIZONTAL_ALIGN, $cmbHalign); } else { $form->addVar('halign', 0); } $cmbValign = new CComboBox('valign', $valign); $cmbValign->addItem(VALIGN_MIDDLE, S_MIDDLE); $cmbValign->addItem(VALIGN_TOP, S_TOP); $cmbValign->addItem(VALIGN_BOTTOM, S_BOTTOM); $form->addRow(S_VERTICAL_ALIGN, $cmbValign); $form->addRow(S_COLUMN_SPAN, new CNumericBox('colspan', $colspan, 2)); $form->addRow(S_ROW_SPAN, new CNumericBox('rowspan', $rowspan, 2)); // dynamic AddOn if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))) { $form->addRow(S_DYNAMIC_ITEM, new CCheckBox('dynamic', $dynamic, null, 1)); } $form->addItemToBottomRow(new CButton('save', S_SAVE)); if (isset($_REQUEST['screenitemid'])) { $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonDelete(null, url_param('form') . url_param('screenid') . url_param('screenitemid'))); } $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonCancel(url_param('screenid'))); return $form; }
$data['prefix'] = get_node_name_by_elid($data['groupid'], true, NAME_DELIMITER); } } $screenFormList->addRow(_('Group'), new CMultiSelect(array('name' => 'resourceid', 'objectName' => 'hostGroup', 'objectOptions' => array('editable' => true), 'data' => $data ? array(array('id' => $data['groupid'], 'name' => $data['name'], 'prefix' => $data['prefix'])) : null, 'selectedLimit' => 1, 'popup' => array('parameters' => 'srctbl=host_groups&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid' . '&srcfld1=groupid&writeonly=1', 'width' => 450, 'height' => 450)))); $screenFormList->addRow(_('Application'), new CTextBox('application', $application, ZBX_TEXTBOX_STANDARD_SIZE, false, 255)); } elseif ($resourceType == SCREEN_RESOURCE_SCREEN) { $caption = ''; $id = 0; if ($resourceId > 0) { $db_screens = DBselect('SELECT DISTINCT n.name AS node_name,s.screenid,s.name' . ' FROM screens s' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.screenid') . ' WHERE s.screenid=' . zbx_dbstr($resourceId)); while ($row = DBfetch($db_screens)) { $screen = API::Screen()->get(array('screenids' => $row['screenid'], 'output' => array('screenid'))); if (empty($screen)) { continue; } if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) { continue; } $row['node_name'] = !empty($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['name']; $id = $resourceId; } } $screenFormList->addVar('resourceid', $id); $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=screens2&srcfld1=screenid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&writeonly=1&screenid=' . $_REQUEST['screenid'] . '", 800, 450);', 'formlist'))); } elseif ($resourceType == SCREEN_RESOURCE_HOSTS_INFO || $resourceType == SCREEN_RESOURCE_TRIGGERS_INFO) { $data = array(); if ($resourceId > 0) { $data = API::HostGroup()->get(array('groupids' => $resourceId, 'nodeids' => get_current_nodeid(true), 'output' => array('groupid', 'name'), 'editable' => true)); if ($data) { $data = reset($data);
function get_screen_item_form() { global $USER_DETAILS; $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true)); $form = new CFormTable(S_SCREEN_CELL_CONFIGURATION, 'screenedit.php#form'); $form->SetHelp('web.screenedit.cell.php'); if (isset($_REQUEST['screenitemid'])) { $iresult = DBSelect('SELECT * FROM screens_items' . ' WHERE screenid=' . $_REQUEST['screenid'] . ' AND screenitemid=' . $_REQUEST['screenitemid']); $form->AddVar('screenitemid', $_REQUEST['screenitemid']); } else { $form->AddVar('x', $_REQUEST['x']); $form->AddVar('y', $_REQUEST['y']); } if (isset($_REQUEST['screenitemid']) && !isset($_REQUEST['form_refresh'])) { $irow = DBfetch($iresult); $resourcetype = $irow['resourcetype']; $resourceid = $irow['resourceid']; $width = $irow['width']; $height = $irow['height']; $colspan = $irow['colspan']; $rowspan = $irow['rowspan']; $elements = $irow['elements']; $valign = $irow['valign']; $halign = $irow['halign']; $style = $irow['style']; $url = $irow['url']; $dynamic = $irow['dynamic']; } else { $resourcetype = get_request('resourcetype', 0); $resourceid = get_request('resourceid', 0); $width = get_request('width', 500); $height = get_request('height', 100); $colspan = get_request('colspan', 0); $rowspan = get_request('rowspan', 0); $elements = get_request('elements', 25); $valign = get_request('valign', VALIGN_DEFAULT); $halign = get_request('halign', HALIGN_DEFAULT); $style = get_request('style', 0); $url = get_request('url', ''); $dynamic = get_request('dynamic', SCREEN_SIMPLE_ITEM); } $form->addVar('screenid', $_REQUEST['screenid']); $cmbRes = new CCombobox('resourcetype', $resourcetype, 'submit()'); $cmbRes->addItem(SCREEN_RESOURCE_GRAPH, S_GRAPH); $cmbRes->addItem(SCREEN_RESOURCE_SIMPLE_GRAPH, S_SIMPLE_GRAPH); $cmbRes->addItem(SCREEN_RESOURCE_PLAIN_TEXT, S_PLAIN_TEXT); $cmbRes->addItem(SCREEN_RESOURCE_MAP, S_MAP); $cmbRes->addItem(SCREEN_RESOURCE_SCREEN, S_SCREEN); $cmbRes->addItem(SCREEN_RESOURCE_SERVER_INFO, S_SERVER_INFO); $cmbRes->addItem(SCREEN_RESOURCE_HOSTS_INFO, S_HOSTS_INFO); $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_INFO, S_TRIGGERS_INFO); $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, S_TRIGGERS_OVERVIEW); $cmbRes->addItem(SCREEN_RESOURCE_STATUS_OF_TRIGGERS, S_STATUS_OF_TRIGGERS); $cmbRes->addItem(SCREEN_RESOURCE_DATA_OVERVIEW, S_DATA_OVERVIEW); $cmbRes->addItem(SCREEN_RESOURCE_CLOCK, S_CLOCK); $cmbRes->addItem(SCREEN_RESOURCE_URL, S_URL); $cmbRes->addItem(SCREEN_RESOURCE_ACTIONS, S_HISTORY_OF_ACTIONS); $cmbRes->addItem(SCREEN_RESOURCE_EVENTS, S_HISTORY_OF_EVENTS); $form->addRow(S_RESOURCE, $cmbRes); if ($resourcetype == SCREEN_RESOURCE_GRAPH) { // User-defined graph $resourceid = graph_accessible($resourceid) ? $resourceid : 0; $caption = ''; $id = 0; if ($resourceid > 0) { $result = DBselect('SELECT DISTINCT g.graphid,g.name,n.name as node_name, h.host' . ' FROM graphs g ' . ' LEFT JOIN graphs_items gi ON g.graphid=gi.graphid ' . ' LEFT JOIN items i ON gi.itemid=i.itemid ' . ' LEFT JOIN hosts h ON h.hostid=i.hostid ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('g.graphid') . ' WHERE g.graphid=' . $resourceid); while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['host'] . ':' . $row['name']; $id = $resourceid; } } $form->addVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 75, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=graphs&srcfld1=graphid&srcfld2=name',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->AddRow(S_GRAPH_NAME, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) { // Simple graph $caption = ''; $id = 0; if ($resourceid > 0) { $result = DBselect('SELECT n.name as node_name,h.host,i.description,i.itemid,i.key_ ' . ' FROM hosts h,items i ' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('i.itemid') . ' WHERE h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('i.hostid', $available_hosts) . ' AND i.itemid=' . $resourceid); while ($row = DBfetch($result)) { $description_ = item_description($row); $row["node_name"] = isset($row["node_name"]) ? "(" . $row["node_name"] . ") " : ''; $caption = $row['node_name'] . $row['host'] . ': ' . $description_; $id = $resourceid; } } $form->AddVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 75, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=simple_graph&srcfld1=itemid&srcfld2=description',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->AddRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_MAP) { // Map $caption = ''; $id = 0; if ($resourceid > 0) { $result = DBselect('SELECT n.name as node_name, s.sysmapid,s.name ' . ' FROM sysmaps s' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.sysmapid') . ' WHERE s.sysmapid=' . $resourceid); while ($row = DBfetch($result)) { if (!sysmap_accessible($row['sysmapid'], PERM_READ_ONLY)) { continue; } $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['name']; $id = $resourceid; } } $form->AddVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 60, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=sysmaps&srcfld1=sysmapid&srcfld2=name',400,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->AddRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) { // Plain text $caption = ''; $id = 0; if ($resourceid > 0) { $result = DBselect('SELECT n.name as node_name,h.host,i.description,i.itemid,i.key_ ' . ' FROM hosts h,items i ' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('i.itemid') . ' WHERE h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('i.hostid', $available_hosts) . ' AND i.itemid=' . $resourceid); while ($row = DBfetch($result)) { $description_ = item_description($row); $row["node_name"] = isset($row["node_name"]) ? '(' . $row["node_name"] . ') ' : ''; $caption = $row['node_name'] . $row['host'] . ': ' . $description_; $id = $resourceid; } } $form->AddVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 75, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=plain_text&srcfld1=itemid&srcfld2=description',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2)); $form->addRow(S_SHOW_TEXT_AS_HTML, new CCheckBox('style', $style, null, 1)); } else { if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_EVENTS, SCREEN_RESOURCE_STATUS_OF_TRIGGERS, SCREEN_RESOURCE_ACTIONS))) { // History of actions // History of events // Status of triggers $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2)); $form->addVar('resourceid', 0); } else { if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) { // Overviews $caption = ''; $id = 0; if ($resourceid > 0) { $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY); $result = DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name ' . ' FROM hosts_groups hg,hosts h,groups g ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND g.groupid=hg.groupid ' . ' AND hg.hostid=h.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND g.groupid=' . $resourceid); while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['name']; $id = $resourceid; } } $form->AddVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 75, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=overview&srcfld1=groupid&srcfld2=name',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->AddRow(S_GROUP, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_SCREEN) { // Screens $caption = ''; $id = 0; if ($resourceid > 0) { $result = DBselect('SELECT DISTINCT n.name as node_name,s.screenid,s.name ' . ' FROM screens s ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.screenid') . ' WHERE s.screenid=' . $resourceid); while ($row = DBfetch($result)) { if (!screen_accessible($row['screenid'], PERM_READ_ONLY)) { continue; } if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) { continue; } $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['name']; $id = $resourceid; } } $form->addVar('resourceid', $id); $textfield = new Ctextbox('caption', $caption, 60, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=screens2&srcfld1=screenid&srcfld2=name&screenid=" . $_REQUEST['screenid'] . "',800,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->AddRow(S_PARAMETER, array($textfield, SPACE, $selectbtn)); } else { if ($resourcetype == SCREEN_RESOURCE_HOSTS_INFO || $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) { // HOSTS info $caption = ''; $id = 0; $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY); if (remove_nodes_from_id($resourceid) > 0) { $result = DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name ' . ' FROM hosts_groups hg, groups g ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND g.groupid=' . $resourceid); while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . $row['name']; $id = $resourceid; } } else { if (remove_nodes_from_id($resourceid) == 0) { $result = DBselect('SELECT DISTINCT n.name as node_name ' . ' FROM nodes n ' . ' WHERE n.nodeid=' . id2nodeid($resourceid)); while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $caption = $row['node_name'] . S_MINUS_ALL_GROUPS_MINUS; $id = $resourceid; } } } $form->AddVar('resourceid', $id); $textfield = new CTextbox('caption', $caption, 60, 'yes'); $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=host_group_scr&srcfld1=groupid&srcfld2=name',480,450);"); $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $form->AddRow(S_GROUP, array($textfield, SPACE, $selectbtn)); } else { // SCREEN_RESOURCE_CLOCK $form->addVar('resourceid', 0); } } } } } } } } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO))) { $cmbStyle = new CComboBox("style", $style); $cmbStyle->AddItem(STYLE_HORISONTAL, S_HORIZONTAL); $cmbStyle->AddItem(STYLE_VERTICAL, S_VERTICAL); $form->AddRow(S_STYLE, $cmbStyle); } else { if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) { $cmbStyle = new CComboBox('style', $style); $cmbStyle->AddItem(STYLE_LEFT, S_LEFT); $cmbStyle->AddItem(STYLE_TOP, S_TOP); $form->AddRow(S_HOSTS_LOCATION, $cmbStyle); } else { if ($resourcetype == SCREEN_RESOURCE_CLOCK) { $cmbStyle = new CComboBox('style', $style); $cmbStyle->AddItem(TIME_TYPE_LOCAL, S_LOCAL_TIME); $cmbStyle->AddItem(TIME_TYPE_SERVER, S_SERVER_TIME); $form->AddRow(S_TIME_TYPE, $cmbStyle); } else { $form->AddVar('style', 0); } } } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_URL))) { $form->AddRow(S_URL, new CTextBox('url', $url, 60)); } else { $form->AddVar('url', ''); } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) { $form->AddRow(S_WIDTH, new CNumericBox('width', $width, 5)); $form->AddRow(S_HEIGHT, new CNumericBox('height', $height, 5)); } else { $form->AddVar('width', 500); $form->AddVar('height', 100); } if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_MAP, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) { $cmbHalign = new CComboBox('halign', $halign); $cmbHalign->AddItem(HALIGN_CENTER, S_CENTRE); $cmbHalign->AddItem(HALIGN_LEFT, S_LEFT); $cmbHalign->AddItem(HALIGN_RIGHT, S_RIGHT); $form->AddRow(S_HORIZONTAL_ALIGN, $cmbHalign); } else { $form->AddVar('halign', 0); } $cmbValign = new CComboBox('valign', $valign); $cmbValign->AddItem(VALIGN_MIDDLE, S_MIDDLE); $cmbValign->AddItem(VALIGN_TOP, S_TOP); $cmbValign->AddItem(VALIGN_BOTTOM, S_BOTTOM); $form->AddRow(S_VERTICAL_ALIGN, $cmbValign); $form->AddRow(S_COLUMN_SPAN, new CNumericBox('colspan', $colspan, 2)); $form->AddRow(S_ROW_SPAN, new CNumericBox('rowspan', $rowspan, 2)); // dynamic AddOn if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))) { $form->AddRow(S_DYNAMIC_ITEM, new CCheckBox('dynamic', $dynamic, null, 1)); } $form->AddItemToBottomRow(new CButton('save', S_SAVE)); if (isset($_REQUEST['screenitemid'])) { $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonDelete(null, url_param('form') . url_param('screenid') . url_param('screenitemid'))); } $form->addItemToBottomRow(SPACE); $form->addItemToBottomRow(new CButtonCancel(url_param('screenid'))); return $form; }