function CZabbixXMLImport() { global $USER_DETAILS; $this->main_node = null; $this->sub_node = null; $this->data = null; $this->host = array('exist' => 0, 'missed' => 0); $this->template = array('exist' => 0, 'missed' => 0); $this->item = array('exist' => 0, 'missed' => 0); $this->trigger = array('exist' => 0, 'missed' => 0); $this->graph = array('exist' => 0, 'missed' => 0); $this->available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE); $this->available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE); $this->available_nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY); }
function make_system_summary($args = array()) { global $USER_DETAILS; $config = select_config(); $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY); $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY); $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY); if (isset($args['hosts']) && !empty($args['hosts'])) { $available_hosts = zbx_uint_array_intersect($args['hosts'], $available_hosts); } if (isset($args['groups']) && !empty($args['groups'])) { $available_groups = zbx_uint_array_intersect($args['groups'], $available_groups); } $sql_where = ''; if (isset($args['severity']) && ctype_digit($args['severity'])) { $sql_where = ' AND t.priority>=' . $args['severity']; } $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST_GROUP, S_DISASTER, S_HIGH, S_AVERAGE, S_WARNING, S_INFORMATION, S_NOT_CLASSIFIED)); $sql = 'SELECT DISTINCT g.groupid,g.name ' . ' FROM groups g, hosts_groups hg, hosts h, items i, functions f, triggers t ' . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . ' AND ' . DBcondition('g.groupid', $available_groups) . ' AND hg.groupid=g.groupid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' ORDER BY g.name'; $gr_result = DBselect($sql); while ($group = DBFetch($gr_result)) { $group_row = new CRow(); if (is_show_all_nodes()) { $group_row->addItem(get_node_name_by_elid($group['groupid'])); } $name = new CLink($group['name'], 'tr_status.php?groupid=' . $group['groupid'] . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE); $name->setTarget('blank'); $group_row->addItem($name); $tab_priority[TRIGGER_SEVERITY_DISASTER] = 0; $tab_priority[TRIGGER_SEVERITY_HIGH] = 0; $tab_priority[TRIGGER_SEVERITY_AVERAGE] = 0; $tab_priority[TRIGGER_SEVERITY_WARNING] = 0; $tab_priority[TRIGGER_SEVERITY_INFORMATION] = 0; $tab_priority[TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0; $sql = 'SELECT count(DISTINCT t.triggerid) as tr_cnt,t.priority ' . ' FROM hosts h,items i,hosts_groups hg, functions f, triggers t ' . ' WHERE h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND hg.groupid=' . $group['groupid'] . ' AND hg.hostid=h.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.value=' . TRIGGER_VALUE_TRUE . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' GROUP BY t.priority'; //SDI($sql); $tr_result = DBSelect($sql); while ($group_stat = DBFetch($tr_result)) { $tab_priority[$group_stat['priority']] = $group_stat['tr_cnt']; } foreach ($tab_priority as $key => $value) { $tr_count = 0; if ($value) { //* trigger list $table_inf = new CTableInfo(); $table_inf->setAttribute('style', 'width: 400px;'); $table_inf->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS)); $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description,t.expression,t.priority,t.lastchange,t.value,h.host,h.hostid ' . ' FROM triggers t,hosts h,items i,functions f, hosts_groups hg ' . ' WHERE f.itemid=i.itemid ' . ' AND hg.groupid=' . $group['groupid'] . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.value=' . TRIGGER_VALUE_TRUE . ' AND t.priority=' . $key . ' ORDER BY t.lastchange DESC'; $result = DBselect($sql); while ($row_inf = DBfetch($result)) { // Check for dependencies if (trigger_dependent($row_inf["triggerid"])) { continue; } $tr_count++; if ($tr_count > 30) { continue; } $host = new CSpan($row_inf['host']); $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type ' . ' FROM events e, triggers t ' . ' WHERE e.object=' . EVENT_SOURCE_TRIGGERS . ' AND e.objectid=' . $row_inf['triggerid'] . ' AND t.triggerid=e.objectid ' . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC'; if ($row_inf_event = DBfetch(DBselect($event_sql, 1))) { if ($config['event_ack_enable']) { if ($row_inf_event['acknowledged'] == 1) { $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_inf_event['eventid'], 'action'); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_inf_event['eventid'], 'on'); } } $description = expand_trigger_description_by_data(array_merge($row_inf, array('clock' => $row_inf_event['clock'])), ZBX_FLAG_EVENT); //actions $actions = get_event_actions_status($row_inf_event['eventid']); //-------- } else { $description = expand_trigger_description_by_data($row_inf, ZBX_FLAG_EVENT); $ack = '-'; $actions = S_NO_DATA_SMALL; $row_inf_event['clock'] = $row_inf['clock']; } $table_inf->addRow(array(get_node_name_by_elid($row_inf['triggerid']), $host, new CCol($description, get_severity_style($row_inf['priority'])), zbx_date2age($row_inf_event['clock']), $config['event_ack_enable'] ? new CCol($ack, 'center') : NULL, $actions)); unset($row_inf, $description, $actions); } $value = new CSpan($tr_count, 'pointer'); $value->setHint($table_inf); //-------------*/ } $group_row->AddItem(new CCol($value, get_severity_style($key, $tr_count))); unset($table_inf); } $table->addRow($group_row); } $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time()))); return $table; }
function get_viewed_groups($perm, $options = array(), $nodeid = null, $sql = array()) { global $USER_DETAILS; global $page; $def_sql = array('select' => array('g.groupid', 'g.name'), 'from' => array('groups g'), 'where' => array(), 'order' => array()); $def_options = array('deny_all' => 0, 'allow_all' => 0, 'select_first_group' => 0, 'select_first_group_if_empty' => 0, 'do_not_select' => 0, 'do_not_select_if_empty' => 0, 'monitored_hosts' => 0, 'templated_hosts' => 0, 'real_hosts' => 0, 'not_proxy_hosts' => 0, 'with_items' => 0, 'with_monitored_items' => 0, 'with_historical_items' => 0, 'with_triggers' => 0, 'with_monitored_triggers' => 0, 'with_httptests' => 0, 'with_monitored_httptests' => 0, 'with_graphs' => 0, 'only_current_node' => 0); $def_options = zbx_array_merge($def_options, $options); $config = select_config(); $dd_first_entry = $config['dropdown_first_entry']; // if($page['menu'] == 'config') $dd_first_entry = ZBX_DROPDOWN_FIRST_NONE; if ($def_options['allow_all']) { $dd_first_entry = ZBX_DROPDOWN_FIRST_ALL; } if ($def_options['deny_all']) { $dd_first_entry = ZBX_DROPDOWN_FIRST_NONE; } $result = array('original' => -1, 'selected' => 0, 'groups' => array(), 'groupids' => array()); $groups =& $result['groups']; $groupids =& $result['groupids']; $first_entry = $dd_first_entry == ZBX_DROPDOWN_FIRST_NONE ? S_NOT_SELECTED_SMALL : S_ALL_SMALL; $groups['0'] = $first_entry; $_REQUEST['groupid'] = $result['original'] = get_request('groupid', -1); $_REQUEST['hostid'] = get_request('hostid', -1); //----- if (is_null($nodeid)) { if (!$def_options['only_current_node']) { $nodeid = get_current_nodeid(); } else { $nodeid = get_current_nodeid(false); } } // $nodeid = is_null($nodeid)?get_current_nodeid(!$def_options['only_current_node']):$nodeid; $available_groups = get_accessible_groups_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, $nodeid, AVAILABLE_NOCACHE); // nodes if (ZBX_DISTRIBUTED) { $def_sql['select'][] = 'n.name as node_name'; $def_sql['from'][] = 'nodes n'; $def_sql['where'][] = 'n.nodeid=' . DBid2nodeid('g.groupid'); $def_sql['order'][] = 'node_name'; } // hosts if ($def_options['monitored_hosts']) { $def_sql['where'][] = 'h.status=' . HOST_STATUS_MONITORED; } else { if ($def_options['real_hosts']) { $def_sql['where'][] = 'h.status IN(' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')'; } else { if ($def_options['templated_hosts']) { $def_sql['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE; } else { if ($def_options['not_proxy_hosts']) { $def_sql['where'][] = 'h.status<>' . HOST_STATUS_PROXY; } else { $in_hosts = false; } } } } if (!isset($in_hosts)) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['from'][] = 'hosts h'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'h.hostid=hg.hostid'; } // items if ($def_options['with_items']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE hg.hostid=i.hostid )'; } else { if ($def_options['with_monitored_items']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE hg.hostid=i.hostid AND i.status=' . ITEM_STATUS_ACTIVE . ')'; } else { if ($def_options['with_historical_items']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE hg.hostid=i.hostid AND (i.status=' . ITEM_STATUS_ACTIVE . ' OR i.status=' . ITEM_STATUS_NOTSUPPORTED . ') AND i.lastvalue IS NOT NULL)'; } } } // triggers if ($def_options['with_triggers']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS( SELECT t.triggerid ' . ' FROM items i, functions f, triggers t' . ' WHERE i.hostid=hg.hostid ' . ' AND f.itemid=i.itemid ' . ' AND t.triggerid=f.triggerid)'; } else { if ($def_options['with_monitored_triggers']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS( SELECT t.triggerid ' . ' FROM items i, functions f, triggers t' . ' WHERE i.hostid=hg.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ')'; } } // httptests if ($def_options['with_httptests']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS( SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=hg.hostid ' . ' AND ht.applicationid=a.applicationid)'; } else { if ($def_options['with_monitored_httptests']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS( ' . ' SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=hg.hostid ' . ' AND ht.applicationid=a.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE . ')'; } } // graphs if ($def_options['with_graphs']) { $def_sql['from'][] = 'hosts_groups hg'; $def_sql['where'][] = 'hg.groupid=g.groupid'; $def_sql['where'][] = 'EXISTS( SELECT DISTINCT i.itemid ' . ' FROM items i, graphs_items gi ' . ' WHERE i.hostid=hg.hostid ' . ' AND i.itemid=gi.itemid)'; } //----- $def_sql['order'][] = 'g.name'; foreach ($sql as $key => $value) { zbx_value2array($value); if (isset($def_sql[$key])) { $def_sql[$key] = zbx_array_merge($def_sql[$key], $value); } else { $def_sql[$key] = $value; } } $def_sql['select'] = array_unique($def_sql['select']); $def_sql['from'] = array_unique($def_sql['from']); $def_sql['where'] = array_unique($def_sql['where']); $def_sql['order'] = array_unique($def_sql['order']); $sql_select = ''; $sql_from = ''; $sql_where = ''; $sql_order = ''; if (!empty($def_sql['select'])) { $sql_select .= implode(',', $def_sql['select']); } if (!empty($def_sql['from'])) { $sql_from .= implode(',', $def_sql['from']); } if (!empty($def_sql['where'])) { $sql_where .= ' AND ' . implode(' AND ', $def_sql['where']); } if (!empty($def_sql['order'])) { $sql_order .= implode(',', $def_sql['order']); } $sql = 'SELECT DISTINCT ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . DBcondition('g.groupid', $available_groups) . $sql_where . ' ORDER BY ' . $sql_order; //SDI($sql); $res = DBselect($sql); while ($group = DBfetch($res)) { $groups[$group['groupid']] = $group['name']; $groupids[$group['groupid']] = $group['groupid']; if (bccomp($_REQUEST['groupid'], $group['groupid']) == 0) { $result['selected'] = $group['groupid']; } } $profile_groupid = CProfile::get('web.' . $page['menu'] . '.groupid'); //----- if ($def_options['do_not_select']) { $result['selected'] = $_REQUEST['groupid'] = 0; } else { if ($def_options['do_not_select_if_empty'] && $_REQUEST['groupid'] == -1) { $result['selected'] = $_REQUEST['groupid'] = 0; } else { if ($def_options['select_first_group'] || $def_options['select_first_group_if_empty'] && $_REQUEST['groupid'] == -1 && is_null($profile_groupid)) { $first_groupid = next($groupids); reset($groupids); if ($first_groupid !== FALSE) { $_REQUEST['groupid'] = $result['selected'] = $first_groupid; } else { $_REQUEST['groupid'] = $result['selected'] = 0; } } else { if ($config['dropdown_first_remember']) { if ($_REQUEST['groupid'] == -1) { $_REQUEST['groupid'] = is_null($profile_groupid) ? '0' : $profile_groupid; } if (isset($groupids[$_REQUEST['groupid']])) { $result['selected'] = $_REQUEST['groupid']; } else { $_REQUEST['groupid'] = $result['selected']; } } else { $_REQUEST['groupid'] = $result['selected']; } } } } return $result; }
** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **/ require_once 'include/config.inc.php'; require_once 'include/hosts.inc.php'; require_once 'include/maintenances.inc.php'; require_once 'include/forms.inc.php'; $page['title'] = 'S_MAINTENANCE'; $page['file'] = 'maintenance.php'; $page['hist_arg'] = array('groupid', 'hostid'); $page['scripts'] = array('menu_scripts.js', 'calendar.js'); include_once 'include/page_header.php'; $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE); $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE); if (isset($_REQUEST['groupid']) && $_REQUEST['groupid'] > 0 && !isset($available_groups[$_REQUEST['groupid']])) { access_deny(); } if (isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0 && !isset($available_hosts[$_REQUEST['hostid']])) { access_deny(); } // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('hosts' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'groups' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'hostids' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'groupids' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'maintenanceid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form})&&({form}=="update")'), 'maintenanceids' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'mname' => array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save})'), 'maintenance_type' => array(T_ZBX_INT, O_OPT, null, null, 'isset({save})'), 'description' => array(T_ZBX_STR, O_OPT, NULL, null, 'isset({save})'), 'active_since' => array(T_ZBX_INT, O_OPT, null, BETWEEN(1, time() * 2), 'isset({save})'), 'active_till' => array(T_ZBX_INT, O_OPT, null, BETWEEN(1, time() * 2), 'isset({save})'), 'new_timeperiod' => array(T_ZBX_STR, O_OPT, null, null, 'isset({add_timeperiod})'), 'timeperiods' => array(T_ZBX_STR, O_OPT, null, null, null), 'g_timeperiodid' => array(null, O_OPT, null, null, null), 'edit_timeperiodid' => array(null, O_OPT, P_ACT, DB_ID, null), 'go' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'add_timeperiod' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'del_timeperiod' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'cancel_new_timeperiod' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'save' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'clone' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'delete' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'form_refresh' => array(T_ZBX_STR, O_OPT, NULL, NULL, NULL)); check_fields($fields); validate_sort_and_sortorder('h.host', ZBX_SORT_UP); $_REQUEST['go'] = get_request('go', 'none'); /************ MAINTENANCE ****************/ if (inarr_isset(array('clone', 'maintenanceid'))) { unset($_REQUEST['maintenanceid']);
function validate_operation($operation) { global $USER_DETAILS; switch ($operation['operationtype']) { case OPERATION_TYPE_MESSAGE: switch ($operation['object']) { case OPERATION_OBJECT_USER: if (!get_user_by_userid($operation['objectid'])) { error(S_INCORRECT_USER); return false; } break; case OPERATION_OBJECT_GROUP: if (!get_group_by_usrgrpid($operation['objectid'])) { error(S_INCORRECT_GROUP); return false; } break; default: error(S_INCORRECT_OBJECT_TYPE); return false; } break; case OPERATION_TYPE_COMMAND: return validate_commands($operation['longdata']); case OPERATION_TYPE_HOST_ADD: case OPERATION_TYPE_HOST_REMOVE: break; case OPERATION_TYPE_GROUP_ADD: case OPERATION_TYPE_GROUP_REMOVE: if (!uint_in_array($operation['objectid'], get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) { error(S_INCORRECT_GROUP); return false; } break; case OPERATION_TYPE_TEMPLATE_ADD: case OPERATION_TYPE_TEMPLATE_REMOVE: if (!uint_in_array($operation['objectid'], get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) { error(S_INCORRECT_HOST); return false; } break; default: error(S_INCORRECT_OPERATION_TYPE); return false; } return true; }
$msg_ok = S_HOSTS . SPACE . S_UPDATED; $msg_fail = S_CANNOT_UPDATE . SPACE . S_HOSTS; show_messages($result, $msg_ok, $msg_fail); if ($result) { unset($_REQUEST['massupdate']); unset($_REQUEST['form']); unset($_REQUEST['hosts']); } unset($_REQUEST['save']); } else { if (($_REQUEST['config'] == 0 || $_REQUEST['config'] == 3) && isset($_REQUEST['save'])) { $useip = get_request('useip', 0); $groups = get_request('groups', array()); $useipmi = get_request('useipmi', 'no'); if (count($groups) > 0) { $accessible_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY); foreach ($groups as $gid) { if (isset($accessible_groups[$gid])) { continue; } access_deny(); } } else { if (!count(get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) { access_deny(); } } $templates = get_request('templates', array()); $_REQUEST['proxy_hostid'] = get_request('proxy_hostid', 0); $clone_hostid = false; if ($_REQUEST['form'] == 'full_clone') {
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(); }
function get_accessible_nodes_by_user(&$user_data, $perm, $perm_res = null, $nodeid = null, $cache = 1) { global $ZBX_LOCALNODEID, $ZBX_NODES_IDS; if (is_null($perm_res)) { $perm_res = PERM_RES_IDS_ARRAY; } if (is_null($nodeid)) { $nodeid = $ZBX_NODES_IDS; } if (!is_array($nodeid)) { $nodeid = array($nodeid); } $userid =& $user_data['userid']; $user_type =& $user_data['type']; if (!isset($userid)) { fatal_error('Incorrect user data in "get_accessible_nodes_by_user"'); } $node_data = array(); $result = array(); //COpt::counter_up('perm'); if (USER_TYPE_SUPER_ADMIN == $user_type) { $nodes = DBselect('SELECT nodeid FROM nodes'); // WHERE '.DBcondition('nodeid',$nodeid)); while ($node = DBfetch($nodes)) { $node_data[$node['nodeid']] = $node; $node_data[$node['nodeid']]['permission'] = PERM_READ_WRITE; } if (empty($node_data)) { $node_data[0]['nodeid'] = 0; } } else { $available_groups = get_accessible_groups_by_user($user_data, $perm, PERM_RES_DATA_ARRAY, $nodeid, $cache); foreach ($available_groups as $id => $group) { $nodeid = id2nodeid($group['groupid']); $permission = isset($node_data[$nodeid]) && $permission < $node_data[$nodeid]['permission'] ? $node_data[$nodeid]['permission'] : $group['permission']; $node_data[$nodeid]['nodeid'] = $nodeid; $node_data[$nodeid]['permission'] = $permission; } } foreach ($node_data as $nodeid => $node) { switch ($perm_res) { case PERM_RES_DATA_ARRAY: $db_node = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid=' . $nodeid)); if (!ZBX_DISTRIBUTED) { if (!$node) { $db_node = array('nodeid' => $ZBX_LOCALNODEID, 'name' => 'local', 'permission' => PERM_READ_WRITE, 'userid' => null); } else { continue; } } $result[$nodeid] = array_merge($db_node, $node); break; default: $result[$nodeid] = $nodeid; break; } } if ($perm_res == PERM_RES_STRING_LINE) { if (count($result) == 0) { $result = '-1'; } else { $result = implode(',', $result); } } return $result; }
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; }
while ($row = DBfetch($result)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; $name = new CLink($row['name'], '#', 'action'); $row['name'] = $row['node_name'] . $row['name']; if (isset($_REQUEST['reference']) && $_REQUEST['reference'] == 'dashboard') { $action = get_window_opener($dstfrm, $dstfld1, $srcfld2) . get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) . "window.opener.setTimeout('add2favorites();', 1000);"; } else { $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : ''); } $name->setAction($action . " close_window(); return false;"); $table->addRow($name); } $table->Show(); } else { if ($srctbl == 'host_group_scr') { $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY, null, $nodeid); $table = new CTableInfo(S_NO_GROUPS_DEFINED); $table->setHeader(array(S_NAME)); $db_groups = DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name,n.nodeid ' . ' FROM hosts_groups hg, groups g ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND ' . DBin_node('g.groupid', $nodeid) . ' ORDER BY n.nodeid,g.name'); $all = false; while ($row = DBfetch($db_groups)) { $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : ''; if (!$all) { $name = new CLink(bold(S_MINUS_ALL_GROUPS_MINUS), '#', 'action'); if (isset($_REQUEST['reference']) && $_REQUEST['reference'] == 'dashboard') { $action = get_window_opener($dstfrm, $dstfld1, $srcfld2) . get_window_opener($dstfrm, $dstfld2, create_id_by_nodeid(0, $nodeid)) . "window.opener.setTimeout('add2favorites();', 1000);"; } else { $action = get_window_opener($dstfrm, $dstfld1, create_id_by_nodeid(0, $nodeid)) . get_window_opener($dstfrm, $dstfld2, $row['node_name'] . S_MINUS_ALL_GROUPS_MINUS); } $name->setAction($action . " close_window(); return false;"); $table->addRow($name);
function get_accessible_nodes_by_user(&$userData, $perm, $permRes = null, $nodeId = null, $cache = true) { $userId =& $userData['userid']; if (!isset($userId)) { fatal_error(_('Incorrect user data in "get_accessible_nodes_by_user".')); } global $ZBX_LOCALNODEID, $ZBX_NODES_IDS; static $available_nodes; if (is_null($permRes)) { $permRes = PERM_RES_IDS_ARRAY; } if (is_null($nodeId)) { $nodeId = $ZBX_NODES_IDS; } if (!is_array($nodeId)) { $nodeId = array($nodeId); } $userType =& $userData['type']; $nodeIdStr = is_array($nodeId) ? md5(implode('', $nodeId)) : strval($nodeId); if ($cache && isset($available_nodes[$userId][$perm][$permRes][$nodeIdStr])) { return $available_nodes[$userId][$perm][$permRes][$nodeIdStr]; } $nodeData = array(); $result = array(); if ($userType == USER_TYPE_SUPER_ADMIN) { $dbNodes = DBselect('SELECT n.nodeid FROM nodes n'); while ($node = DBfetch($dbNodes)) { $nodeData[$node['nodeid']] = $node; $nodeData[$node['nodeid']]['permission'] = PERM_READ_WRITE; } if (empty($nodeData)) { $nodeData[0]['nodeid'] = 0; } } else { $availableGroups = get_accessible_groups_by_user($userData, $perm, PERM_RES_DATA_ARRAY, $nodeId); foreach ($availableGroups as $availableGroup) { $nodeId = id2nodeid($availableGroup['groupid']); $permission = isset($nodeData[$nodeId]) && $permission < $nodeData[$nodeId]['permission'] ? $nodeData[$nodeId]['permission'] : $availableGroup['permission']; $nodeData[$nodeId]['nodeid'] = $nodeId; $nodeData[$nodeId]['permission'] = $permission; } } foreach ($nodeData as $nodeId => $node) { switch ($permRes) { case PERM_RES_DATA_ARRAY: $dbNode = DBfetch(DBselect('SELECT n.* FROM nodes n WHERE n.nodeid=' . $nodeId . ' ORDER BY n.name')); if (!ZBX_DISTRIBUTED) { if (!$node) { $dbNode = array('nodeid' => $ZBX_LOCALNODEID, 'name' => 'local', 'permission' => PERM_READ_WRITE, 'userid' => null); } else { continue; } } $result[$nodeId] = zbx_array_merge($dbNode, $node); break; default: $result[$nodeId] = $nodeId; break; } } $available_nodes[$userId][$perm][$permRes][$nodeIdStr] = $result; return $result; }
function get_screen($screenid, $editmode, $effectiveperiod = NULL) { global $USER_DETAILS; if ($screenid == 0) { return new CTableInfo(S_NO_SCREENS_DEFINED); } if (!screen_accessible($screenid, $editmode == 1 ? PERM_READ_WRITE : PERM_READ_ONLY)) { access_deny(); } if (is_null($effectiveperiod)) { $effectiveperiod = ZBX_MIN_PERIOD; } $result = DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid=' . $screenid); $row = DBfetch($result); if (!$row) { return new CTableInfo(S_NO_SCREENS_DEFINED); } for ($r = 0; $r < $row['vsize']; $r++) { for ($c = 0; $c < $row['hsize']; $c++) { if (isset($skip_field[$r][$c])) { continue; } $sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid . ' AND x=' . $c . ' AND y=' . $r; $iresult = DBSelect($sql); $irow = DBfetch($iresult); if ($irow) { $colspan = $irow['colspan']; $rowspan = $irow['rowspan']; } else { $colspan = 0; $rowspan = 0; } for ($i = 0; $i < $rowspan || $i == 0; $i++) { for ($j = 0; $j < $colspan || $j == 0; $j++) { if ($i != 0 || $j != 0) { $skip_field[$r + $i][$c + $j] = 1; } } } } } $table = new CTable(new CLink('No rows in screen ' . $row['name'], 'screenconf.php?config=0&form=update&screenid=' . $screenid), $editmode == 0 || $editmode == 2 ? 'screen_view' : 'screen_edit'); $table->setAttribute('id', 'iframe'); if ($editmode == 1) { $add_col_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_col='; $new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); for ($c = 0; $c < $row['hsize'] + 1; $c++) { array_push($new_cols, new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_col_link . $c))); } $table->addRow($new_cols); } $empty_screen_col = array(); for ($r = 0; $r < $row['vsize']; $r++) { $new_cols = array(); $empty_screen_row = true; if ($editmode == 1) { $add_row_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_row='; array_push($new_cols, new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_row_link . $r))); } for ($c = 0; $c < $row['hsize']; $c++) { $item = array(); if (isset($skip_field[$r][$c])) { continue; } $item_form = false; $iresult = DBSelect('SELECT * FROM screens_items WHERE screenid=' . $screenid . ' AND x=' . $c . ' AND y=' . $r); $irow = DBfetch($iresult); if ($irow) { $screenitemid = $irow['screenitemid']; $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 { $screenitemid = 0; $resourcetype = 0; $resourceid = 0; $width = 0; $height = 0; $colspan = 0; $rowspan = 0; $elements = 0; $valign = VALIGN_DEFAULT; $halign = HALIGN_DEFAULT; $style = 0; $url = ''; $dynamic = 0; } if ($screenitemid > 0) { $empty_screen_row = false; $empty_screen_col[$c] = 1; } if ($editmode == 1 && $screenitemid != 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&screenitemid=' . $screenitemid . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitemid . '#form'; } else { if ($editmode == 1 && $screenitemid == 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&x=' . $c . '&y=' . $r . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r . '#form'; } else { $action = NULL; } } if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['x']) && $_REQUEST['x'] == $c && isset($_REQUEST['y']) && $_REQUEST['y'] == $r) { // click on empty field $item = get_screen_item_form(); $item_form = true; } else { if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['screenitemid']) && bccomp($_REQUEST['screenitemid'], $screenitemid) == 0) { // click on element $item = get_screen_item_form(); $item_form = true; } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_GRAPH) { if ($editmode == 0) { $action = 'charts.php?graphid=' . $resourceid . url_param('period') . url_param('stime'); } $graphid = null; $graphtype = GRAPH_TYPE_NORMAL; $yaxis = 0; // GRAPH & ZOOM features $sql = 'SELECT MAX(g.graphid) as graphid, MAX(g.graphtype) as graphtype, MIN(gi.yaxisside) as yaxissidel, MAX(gi.yaxisside) as yaxissider,' . ' MAX(g.show_legend) as legend, MAX(g.show_3d) as show3d ' . ' FROM graphs g, graphs_items gi ' . ' WHERE g.graphid=' . $resourceid . ' AND gi.graphid=g.graphid '; $res = DBselect($sql); while ($graph = DBfetch($res)) { $graphid = $graph['graphid']; $graphtype = $graph['graphtype']; $yaxis = $graph['yaxissider']; $yaxis = $graph['yaxissidel'] == $yaxis ? $yaxis : 2; $legend = $graph['legend']; $graph3d = $graph['show3d']; } if ($yaxis == 2) { $shiftXleft = 60; $shiftXright = 60; } else { if ($yaxis == 0) { $shiftXleft = 60; $shiftXright = 20; } else { $shiftXleft = 10; $shiftXright = 60; } } //------------- // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { $def_items = array(); $di_res = get_graphitems_by_graphid($resourceid); while ($gitem = DBfetch($di_res)) { $def_items[] = $gitem; } $url = ''; if ($new_items = get_same_graphitems_for_host($def_items, $_REQUEST['hostid'])) { $url .= make_url_from_gitems($new_items); } $url = make_url_from_graphid($resourceid, false) . $url; } //------------- $default = false; if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart6.php?graphid=' . $resourceid; $default = true; } $g_img = new CImg($url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime') . '&legend=' . $legend . '&graph3d=' . $graph3d); } else { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart2.php?graphid=' . $resourceid; $default = true; } $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $g_img = new CImg($url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime')); $g_img->setAttribute('id', $dom_graph_id); if (!is_null($graphid) && $editmode != 1) { insert_js(' A_SBOX["' . $dom_graph_id . '"] = new Object;' . 'A_SBOX["' . $dom_graph_id . '"].shiftT = 17;' . 'A_SBOX["' . $dom_graph_id . '"].shiftL = ' . $shiftXleft . ';'); if (isset($_REQUEST['stime'])) { $stime = $_REQUEST['stime']; $stime = mktime(substr($stime, 8, 2), substr($stime, 10, 2), 0, substr($stime, 4, 2), substr($stime, 6, 2), substr($stime, 0, 4)); } else { $stime = 'null'; } global $page; if ($page['type'] == PAGE_TYPE_HTML) { zbx_add_post_js('graph_zoom_init("' . $dom_graph_id . '",' . $stime . ',' . $effectiveperiod . ',' . $width . ',' . $height . ', false);'); } else { $g_img->setAttribute('onload', 'javascript: graph_zoom_init("' . $dom_graph_id . '",' . $stime . ',' . $effectiveperiod . ',' . $width . ',' . $height . ', false);'); // insert_js('graph_zoom_init("'.$dom_graph_id.'",'.$stime.','.$effectiveperiod.','.$width.','.$height.', false);'); } } } if ($default && $editmode == 0) { $item = new CLink($g_img, $action); } else { $item =& $g_img; } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) { if ($editmode == 0) { $action = "history.php?action=showgraph&itemid={$resourceid}" . url_param("period") . url_param("inc") . url_param("dec"); } // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = ''; } } //------------- $url = empty($resourceid) ? 'chart3.php?' : "chart.php?itemid={$resourceid}&"; $item = new CLink(new CImg($url . "width={$width}&height={$height}" . "&period={$effectiveperiod}" . url_param("stime")), $action); } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_MAP) { $image_map = new CImg("map.php?noedit=1&sysmapid={$resourceid}" . "&width={$width}&height={$height}"); if ($editmode == 0) { $action_map = get_action_map_by_sysmapid($resourceid); $image_map->SetMap($action_map->GetName()); $item = array($action_map, $image_map); } else { $item = $image_map; // $item = new CLink($image_map, $action); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) { // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = 0; } } //------------- $item = array(get_screen_plaintext($resourceid, $elements, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_STATUS_OF_TRIGGERS) { $params = array(); $params['groupid'] = get_request('tr_groupid', get_profile('web.screens.tr_groupid', 0)); $params['hostid'] = get_request('tr_hostid', get_profile('web.screens.tr_hostid', 0)); $params['limit'] = $elements; update_profile('web.screens.tr_groupid', $params['groupid'], PROFILE_TYPE_ID); update_profile('web.screens.tr_hostid', $params['hostid'], PROFILE_TYPE_ID); $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $params['groupid'], 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $params['hostid'], 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY); $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY); $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY); $sql = 'SELECT DISTINCT g.groupid,g.name ' . ' FROM groups g, hosts_groups hg, hosts h ' . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND hg.groupid=g.groupid ' . ' AND h.hostid=hg.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND EXISTS(SELECT i.itemid FROM items i WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND i.hostid=h.hostid ) ' . ' ORDER BY g.name'; $tresult = DBselect($sql); while ($tr_row = DBfetch($tresult)) { $cmbGroup->addItem($tr_row['groupid'], get_node_name_by_elid($tr_row['groupid']) . $tr_row['name']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $sql_from = ''; $sql_where = ''; if ($params['groupid'] > 0) { $sql_from .= ',hosts_groups hg '; $sql_where .= ' AND hg.hostid=h.hostid AND hg.groupid=' . $params['groupid']; } $sql = 'SELECT DISTINCT h.hostid,h.host ' . ' FROM hosts h, items i, functions f, triggers t ' . $sql_from . ' WHERE h.status=' . HOST_STATUS_MONITORED . $sql_where . ' AND h.hostid=i.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' ORDER BY h.host'; $tresult = DBselect($sql); while ($tr_row = DBfetch($tresult)) { $cmbHosts->addItem($tr_row['hostid'], get_node_name_by_elid($tr_row['hostid']) . $tr_row['host']); } $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, date('[H:i:s]', time())), $tr_form)); //*/ // $item = array(); $item[] = make_latest_issues($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SYSTEM_STATUS) { $item = array(get_table_header(array(S_SYSTEM_STATUSBIG, SPACE, date('[H:i:s]', time())))); $item[] = make_system_summary(); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTS_INFO) { $item = array(new CHostsInfo($resourceid, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) { $item = new CTriggersInfo($style); if ($resourceid > 0) { $item->set_host_group($resourceid); } $item = array($item); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SERVER_INFO) { // $item = array(get_table_header(S_STATUS_OF_ZABBIX_BIG),make_status_of_zbx()); $item = array(new CServerInfo()); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_CLOCK) { $item = new CFlashClock($width, $height, $style, $action); } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SCREEN) { $item = array(get_screen($resourceid, 2, $effectiveperiod)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_triggers_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_DATA_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_items_data_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_URL) { $item = array(new CIFrame($url, $width, $height, "auto")); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_ACTIONS) { $item = array(get_history_of_actions($elements)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_EVENTS) { $item = array(get_history_of_triggers_events(0, $elements)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { $item = array(SPACE); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } } } } } } } } } } } } } } } } } } $str_halign = 'def'; if ($halign == HALIGN_CENTER) { $str_halign = 'cntr'; } if ($halign == HALIGN_LEFT) { $str_halign = 'left'; } if ($halign == HALIGN_RIGHT) { $str_halign = 'right'; } $str_valign = 'def'; if ($valign == VALIGN_MIDDLE) { $str_valign = 'mdl'; } if ($valign == VALIGN_TOP) { $str_valign = 'top'; } if ($valign == VALIGN_BOTTOM) { $str_valign = 'bttm'; } if ($editmode == 1 && !$item_form) { $item = new CDiv($item, 'draggable'); $item->setAttribute('id', 'position_' . $r . '_' . $c); if ($editmode == 1) { $item->setAttribute('onclick', 'javascript: ' . $onclick_action); } } $new_col = new CCol($item, $str_halign . '_' . $str_valign); if ($colspan) { $new_col->SetColSpan($colspan); } if ($rowspan) { $new_col->SetRowSpan($rowspan); } array_push($new_cols, $new_col); } if ($editmode == 1) { $rmv_icon = new Cimg('images/general/opened.gif'); if ($empty_screen_row) { $rmv_row_link = 'javascript: location.href = ' . "'screenedit.php?config=1&screenid=" . $screenid . '&rmv_row=' . $r . "';"; } else { $rmv_row_link = "javascript: if(Confirm('This screen-row is not empty. Delete it?')){" . " location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_row=" . $r . "';}"; } $rmv_icon->addAction('onclick', $rmv_row_link); array_push($new_cols, new Ccol($rmv_icon)); } $table->AddRow(new CRow($new_cols)); } if ($editmode == 1) { $add_row_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_row='; $new_cols = array(new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_row_link . $row['vsize']))); for ($c = 0; $c < $row['hsize']; $c++) { $rmv_icon = new Cimg('images/general/opened.gif'); if (isset($empty_screen_col[$c])) { $rmv_col_link = "javascript: if(Confirm('This screen-column is not empty. Delete it?')){" . " location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_col=" . $c . "';}"; } else { $rmv_col_link = "javascript: location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_col=" . $c . "';"; } $rmv_icon->addAction('onclick', $rmv_col_link); array_push($new_cols, new Ccol($rmv_icon)); } array_push($new_cols, new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); $table->addRow($new_cols); } return $table; }
function sysmap_accessible($sysmapid, $perm) { global $USER_DETAILS; $result = false; $sql = 'SELECT * ' . ' FROM sysmaps_elements ' . ' WHERE sysmapid=' . $sysmapid . ' AND ' . DBin_node('sysmapid', get_current_nodeid(null, $perm)); if ($db_result = DBselect($sql)) { $result = true; $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, get_current_nodeid(true)); //SDI($available_hosts); while (($se_data = DBfetch($db_result)) && $result) { switch ($se_data['elementtype']) { case SYSMAP_ELEMENT_TYPE_HOST: if (!isset($available_hosts[$se_data['elementid']])) { $result = false; } break; case SYSMAP_ELEMENT_TYPE_MAP: $result = sysmap_accessible($se_data['elementid'], $perm); break; case SYSMAP_ELEMENT_TYPE_TRIGGER: $available_triggers = get_accessible_triggers($perm, array(), PERM_RES_IDS_ARRAY); if (!isset($available_triggers[$se_data['elementid']])) { $result = false; } break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: $available_groups = get_accessible_groups_by_user($USER_DETAILS, $perm); if (!isset($available_groups[$se_data['elementid']])) { $result = false; } break; } } //SDI($se_data['elementid']); } else { if (DBselect('SELECT sysmapid FROM sysmaps WHERE sysmapid=' . $sysmapid . ' AND ' . DBin_node('sysmapid', get_current_nodeid($perm)))) { $result = true; } } return $result; }