$val) { if (preg_match('/^cg_(\d+)$/', $var, $matches)) { $selected_graphs['cg'][$matches[1]][$matches[1]] = true; } elseif (preg_match('/^cg_g$/', $var)) { if (get_nfilter_request_var('cg_g') > 0) { $selected_graphs['cg'][get_nfilter_request_var('cg_g')][get_nfilter_request_var('cg_g')] = true; } } elseif (preg_match('/^sg_(\d+)_([a-f0-9]{32})$/', $var, $matches)) { $selected_graphs['sg'][$matches[1]][get_nfilter_request_var('sgg_' . $matches[1])][$matches[2]] = true; } if (strpos($var, 'sgg_') !== false) { $snmp_query_id = str_replace('sgg_', '', $var); store_get_selected_dq_index($snmp_query_id); } } if (!isset_request_var('host_id')) { $host_id = 0; } else { $host_id = get_filter_request_var('host_id'); } if (!isset_request_var('host_template_id')) { $host_template_id = 0; } else { $host_template_id = get_filter_request_var('host_template_id'); } if (isset($selected_graphs)) { html_graph_new_graphs('graphs_new.php', $host_id, $host_template_id, $selected_graphs); exit; } header('Location: graphs_new.php?host_id=' . $host_id . '&header=false'); } if (isset_request_var('save_component_new_graphs')) { host_new_graphs_save(get_filter_request_var('host_id')); header('Location: graphs_new.php?host_id=' . get_filter_request_var('host_id') . '&header=false'); } } /* ------------------- Data Query Functions ------------------- */ function host_reload_query() { /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('host_id'); /* ==================================================== */ run_data_query(get_request_var('host_id'), get_request_var('id')); } /* ------------------- New Graph Functions ------------------- */ function host_new_graphs_save($host_id) { $selected_graphs_array = unserialize(stripslashes(get_nfilter_request_var('selected_graphs_array'))); $values = array(); /* form an array that contains all of the data on the previous form */ foreach ($_POST as $var => $val) { if (preg_match('/^g_(\d+)_(\d+)_(\w+)/', $var, $matches)) { // 1: snmp_query_id, 2: graph_template_id, 3: field_name if (empty($matches[1])) { // this is a new graph from template field $values['cg'][$matches[2]]['graph_template'][$matches[3]] = $val; } else { // this is a data query field $values['sg'][$matches[1]][$matches[2]]['graph_template'][$matches[3]] = $val; } } elseif (preg_match('/^gi_(\d+)_(\d+)_(\d+)_(\w+)/', $var, $matches)) { // 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name /* ================= input validation ================= */ input_validate_input_number($matches[3]); /* ==================================================== */ /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc_prepared('SELECT graph_template_item_id FROM graph_template_input_defs WHERE graph_template_input_id = ?', array($matches[3])); /* loop through each item affected and update column data */ if (cacti_sizeof($item_list)) { foreach ($item_list as $item) { if (empty($matches[1])) { // this is a new graph from template field $values['cg'][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val; } else { // this is a data query field $values['sg'][$matches[1]][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val; } } } } elseif (preg_match('/^d_(\d+)_(\d+)_(\d+)_(\w+)/', $var, $matches)) { // 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_nam if (empty($matches[1])) { // this is a new graph from template field $values['cg'][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val; } else { // this is a data query field $values['sg'][$matches[1]][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val; } } elseif (preg_match('/^c_(\d+)_(\d+)_(\d+)_(\d+)/', $var, $matches)) { // 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id if (empty($matches[1])) { // this is a new graph from template field $values['cg'][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val; } else { // this is a data query field $values['sg'][$matches[1]][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val; } } elseif (preg_match('/^di_(\d+)_(\d+)_(\d+)_(\d+)_(\w+)/', $var, $matches)) { // 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name if (empty($matches[1])) { // this is a new graph from template field $values['cg'][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val; } else { // this is a data query field $values['sg'][$matches[1]][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val; } } } debug_log_clear('new_graphs'); foreach ($selected_graphs_array as $form_type => $form_array) { $current_form_type = $form_type; foreach ($form_array as $form_id1 => $form_array2) { /* enumerate information from the arrays stored in post variables */ create_save_graph($host_id, $form_type, $form_id1, $form_array2, $values); } } } /* ------------------- Graph Functions ------------------- */ function graphs() { global $config, $item_rows; /* ================= input validation and session storage ================= */ $filters = array( 'rows' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'filter' => array( 'filter' => FILTER_DEFAULT, 'pageset' => true, 'default' => '' ), 'host_id' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1') ), 'graph_type' => array( 'filter' => FILTER_VALIDATE_INT, 'default' => read_user_setting('graph_type', read_config_option('default_graphs_new_dropdown'), true) ) ); validate_store_request_vars($filters, 'sess_grn'); /* ================= input validation ================= */ if (get_request_var('rows') == '-1') { $rows = read_user_setting('num_rows_table', read_config_option('num_rows_table'), true); } else { $rows = get_request_var('rows'); } if (!isempty_request_var('host_id')) { $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array(get_request_var('host_id'))); if (cacti_sizeof($host)) { $name = db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id'])); $header = __esc('New Graphs for [ %s ] (%s %s)', $host['description'], $host['hostname'], (!empty($host['host_template_id']) ? $name:'')); } else { $header = __('New Graphs for [ All Devices ]'); $host['id'] = -1; $host['host_template_id'] = 0; } } else { $host['id'] = 0; $host['host_template_id'] = 0; $header = __('New Graphs for None Host Type'); } html_start_box($header, '100%', '', '3', 'center', ''); print ''; ?>
' title=''> ' title=''> ' title=''>
'>
*'>
*'>
0) { /* validate the page filter */ if (isset_request_var('page' . get_request_var('graph_type'))) { get_filter_request_var('page' . get_request_var('graph_type')); } load_current_session_value('page' . get_request_var('graph_type'), 'sess_grn_page' . get_request_var('graph_type'), '1'); }else if (get_request_var('graph_type') == -2) { foreach($snmp_queries as $query) { /* validate the page filter */ if (isset_request_var('page' . $query['id'])) { get_filter_request_var('page' . $query['id']); } load_current_session_value('page' . $query['id'], 'sess_grn_page' . $query['id'], '1'); } } $script = ""; print $script; } form_hidden_box('save_component_graph', '1', ''); if (!isempty_request_var('host_id')) { form_hidden_box('host_id', $host['id'], '0'); form_hidden_box('host_template_id', $host['host_template_id'], '0'); } if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) { set_request_var('returnto', basename($_SERVER['HTTP_REFERER'])); } load_current_session_value('returnto', 'sess_grn_returnto', ''); if (substr_count(get_nfilter_request_var('returnto'), 'host.php') == 0) { set_request_var('returnto', ''); } form_save_button(get_nfilter_request_var('returnto'), 'create'); }