__('Delete'), 2 => __('Duplicate'), 3 => __('Sync Devices') ); /* set default action */ set_default_action(); api_plugin_hook('device_template_top'); switch (get_request_var('action')) { case 'save': form_save(); break; case 'actions': form_actions(); break; case 'item_add_gt': template_item_add_gt(); header('Location: host_templates.php?action=edit&id=' . get_filter_request_var('host_template_id')); break; case 'item_remove_gt_confirm': template_item_remove_gt_confirm(); break; case 'item_remove_gt': template_item_remove_gt(); header('Location: host_templates.php?action=edit&id=' . get_filter_request_var('host_template_id')); break; case 'item_add_dq': template_item_add_dq(); header('Location: host_templates.php?action=edit&id=' . get_filter_request_var('host_template_id')); break; case 'item_remove_dq_confirm': template_item_remove_dq_confirm(); break; case 'item_remove_dq': template_item_remove_dq(); header('Location: host_templates.php?action=edit&id=' . get_filter_request_var('host_template_id')); break; case 'edit': top_header(); template_edit(); bottom_footer(); break; default: top_header(); template(); bottom_footer(); break; } function form_save() { /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('host_template_id'); get_filter_request_var('snmp_query_id'); get_filter_request_var('graph_template_id'); /* ==================================================== */ if (isset_request_var('save_component_template')) { $save['id'] = get_nfilter_request_var('id'); $save['hash'] = get_hash_host_template(get_nfilter_request_var('id')); $save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3); $save['class'] = form_input_validate(get_nfilter_request_var('class'), 'class', '', false, 3); if (!is_error_message()) { $host_template_id = sql_save($save, 'host_template'); if ($host_template_id) { raise_message(1); } else { raise_message(2); } } header('Location: host_templates.php?action=edit&id=' . (empty($host_template_id) ? get_nfilter_request_var('id') : $host_template_id)); } } function template_item_add_dq() { /* ================= input validation ================= */ get_filter_request_var('host_template_id'); get_filter_request_var('snmp_query_id'); /* ==================================================== */ db_execute_prepared( 'REPLACE INTO host_template_snmp_query (host_template_id, snmp_query_id) VALUES (?, ?)', array(get_request_var('host_template_id'), get_request_var('snmp_query_id')) ); raise_message(41); } function template_item_add_gt() { /* ================= input validation ================= */ get_filter_request_var('host_template_id'); get_filter_request_var('graph_template_id'); /* ==================================================== */ db_execute_prepared( 'REPLACE INTO host_template_graph (host_template_id, graph_template_id) VALUES (?, ?)', array(get_request_var('host_template_id'), get_request_var('graph_template_id')) ); raise_message(41); } function form_actions() { global $actions; /* ================= input validation ================= */ get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/'))); /* ==================================================== */ /* if we are to save this form, instead of display it */ if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); if ($selected_items != false) { if (get_nfilter_request_var('drp_action') == '1') { // delete db_execute('DELETE FROM host_template WHERE ' . array_to_sql_or($selected_items, 'id')); db_execute('DELETE FROM host_template_snmp_query WHERE ' . array_to_sql_or($selected_items, 'host_template_id')); db_execute('DELETE FROM host_template_graph WHERE ' . array_to_sql_or($selected_items, 'host_template_id')); /* "undo" any device that is currently using this template */ db_execute('UPDATE host SET host_template_id = 0 WHERE deleted = "" AND ' . array_to_sql_or($selected_items, 'host_template_id')); } elseif (get_nfilter_request_var('drp_action') == '2') { // duplicate for ($i=0;($i $val) { if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1], 'chk[1]'); /* ==================================================== */ $ilist .= '
  • ' . html_escape(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($matches[1]))) . '
  • '; $iarray[] = $matches[1]; } } $form_data = array( 'general' => array( 'page' => 'host_templates.php', 'actions' => $actions, 'optvar' => 'drp_action', 'item_array' => $iarray, 'item_list' => $ilist ), 'options' => array( 1 => array( 'smessage' => __('Click \'Continue\' to Delete the following Device Template.'), 'pmessage' => __('Click \'Continue\' to Delete following Device Templates.'), 'scont' => __('Delete Device Template'), 'pcont' => __('Delete Device Templates') ), 2 => array( 'smessage' => __('Click \'Continue\' to Duplicate the following Device Template.'), 'pmessage' => __('Click \'Continue\' to Duplicate following Device Templates.'), 'scont' => __('Duplicate Device Template'), 'pcont' => __('Duplicate Device Templates'), 'extra' => array( 'title_format' => array( 'method' => 'textbox', 'title' => __('Title Format:'), 'default' => ' (1)', 'width' => 25 ) ) ), 3 => array( 'smessage' => __('Click \'Continue\' to Sync Devices to the following Device Template.'), 'pmessage' => __('Click \'Continue\' to Sync Devices to the following Device Templates.'), 'scont' => __('Sync Device Template'), 'pcont' => __('Sync Device Templates') ), ) ); form_continue_confirmation($form_data); } } function template_item_remove_gt_confirm() { /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('host_template_id'); /* ==================================================== */ form_start('host_templates.php?action=edit&id' . get_request_var('host_template_id')); html_start_box('', '100%', '', '3', 'center', ''); $template = db_fetch_row_prepared('SELECT * FROM graph_templates WHERE id = ?', array(get_request_var('id'))); ?>

    '
    ' onClick='$("#cdialog").dialog("close")' name='cancel'> ' name='continue' title=''>

    '
    ' onClick='$("#cdialog").dialog("close")' name='cancel'> ' name='continue' title=''> array('no_form_tag' => 'true'), 'fields' => inject_form_variables($fields_host_template_edit, (isset($host_template) ? $host_template : array())) ) ); /* we have to hide this button to make a form change in the main form trigger the correct * submit action */ print "

    "; html_end_box(true, true); if (!isempty_request_var('id')) { html_start_box(__('Associated Graph Templates'), '100%', '', '3', 'center', ''); $selected_graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id, graph_templates.name FROM (graph_templates,host_template_graph) WHERE graph_templates.id = host_template_graph.graph_template_id AND host_template_graph.host_template_id = ? ORDER BY graph_templates.name', array(get_request_var('id'))); $i = 0; if (cacti_sizeof($selected_graph_templates)) { foreach ($selected_graph_templates as $item) { form_alternate_row("gt$i", true); ?> ) ' href=''> ' . __('No associated graph templates.') . ''; } ?>
    ' id='add_gt' title=''>
    ) ' href=''> ' . __('No associated data queries.') . ''; } ?>
    ' id='add_dq' title=''>
    array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'page' => array( 'filter' => FILTER_VALIDATE_INT, 'default' => '1' ), 'filter' => array( 'filter' => FILTER_DEFAULT, 'pageset' => true, 'default' => '' ), 'class' => array( 'filter' => FILTER_CALLBACK, 'default' => '-1', 'pageset' => true, 'sort' => 'ASC', 'options' => array('options' => 'sanitize_search_string') ), 'sort_column' => array( 'filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => array('options' => 'sanitize_search_string') ), 'sort_direction' => array( 'filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string') ), 'has_hosts' => array( 'filter' => FILTER_VALIDATE_REGEXP, 'options' => array('options' => array('regexp' => '(true|false)')), 'pageset' => true, 'default' => read_config_option('default_has') == 'on' ? 'true' : 'false' ) ); validate_store_request_vars($filters, 'sess_ht'); /* ================= input validation ================= */ if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } html_start_box(__('Device Templates'), '100%', '', '3', 'center', 'host_templates.php?action=edit'); ?>
    '> > ' title=''> ' title=''>
    0'; } else { $sql_having = ''; } $total_rows = db_fetch_cell("SELECT COUNT(*) FROM host_template $sql_where $sql_having"); $sql_order = get_order_string(); $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; $template_list = db_fetch_assoc("SELECT host_template.id, host_template.name, host_template.class, devices AS hosts FROM host_template $sql_where $sql_having $sql_order $sql_limit"); $display_text = array( 'name' => array( 'display' => __('Device Template Name'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The name of this Device Template.') ), 'host_template.class' => array( 'display' => __('Device Class'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The Class of this Device Template. The Class Name should be representative of it\'s function.') ), 'host_template.id' => array( 'display' => __('ID'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The internal database ID for this Device Template. Useful when performing automation or debugging.') ), 'nosort' => array( 'display' => __('Deletable'), 'align' => 'right', 'sort' => '', 'tip' => __('Device Templates in use cannot be Deleted. In use is defined as being referenced by a Device.') ), 'hosts' => array( 'display' => __('Devices Using'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The number of Devices using this Device Template.') ) ); $nav = html_nav_bar('host_templates.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, cacti_sizeof($display_text) + 1, __('Device Templates'), 'page', 'main'); form_start('host_templates.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); $i = 0; if (cacti_sizeof($template_list)) { foreach ($template_list as $template) { if ($template['hosts'] > 0) { $disabled = true; } else { $disabled = false; } form_alternate_row('line' . $template['id'], true, $disabled); form_selectable_cell(filter_value($template['name'], get_request_var('filter'), 'host_templates.php?action=edit&id=' . $template['id']), $template['id']); if ($template['class'] != '') { form_selectable_cell($device_classes[$template['class']], $template['id']); } else { form_selectable_cell(__('Unassigned'), $template['id']); } form_selectable_cell($template['id'], $template['id'], '', 'right'); form_selectable_cell($disabled ? __('No') : __('Yes'), $template['id'], '', 'right'); form_selectable_cell('' . number_format_i18n($template['hosts'], '-1') . '', $template['id'], '', 'right'); form_checkbox_cell($template['name'], $template['id'], $disabled); form_end_row(); } } else { print "" . __('No Device Templates Found') . "\n"; } html_end_box(false); if (cacti_sizeof($template_list)) { print $nav; } /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($actions); form_end(); }