__('Delete'), 2 => __('Duplicate'), 3 => __('Sync Aggregates') ); /* set default action */ set_default_action(); switch (get_request_var('action')) { case 'save': aggregate_color_form_save(); break; case 'actions': aggregate_color_form_actions(); break; case 'template_edit': top_header(); aggregate_color_template_edit(); bottom_footer(); break; default: top_header(); aggregate_color_template(); bottom_footer(); break; } /** draw_color_template_items_list - draws a nicely formatted list of color items for display * on an edit form * @param array $item_list - an array representing the list of color items. this array should * come directly from the output of db_fetch_assoc() * @param string $filename - the filename to use when referencing any external url * @param string $url_data - any extra GET url information to pass on when referencing any * external url * @param bool $disable_controls - whether to hide all edit/delete functionality on this form */ function draw_color_template_items_list($item_list, $filename, $url_data, $disable_controls) { global $config; global $struct_color_template_item; $display_text = array( array('display' => __('Color Item'), 'align' => 'left', 'nohide' => true), array('display' => __('Color'), 'align' => 'left', 'nohide' => true), array('display' => __('Hex'), 'align' => 'left', 'nohide' => true), ); html_header($display_text, 2); $i = 1; $total_items = cacti_sizeof($item_list); if (cacti_sizeof($item_list)) { foreach ($item_list as $item) { /* alternating row color */ form_alternate_row('line' . $item['color_template_item_id'], true, true); print ''; if ($disable_controls == false) { print ""; } print __('Item # %d', $i); if ($disable_controls == false) { print ''; } print "\n"; print "\n"; print "" . $item['hex'] . "\n"; if ($disable_controls == false) { print ""; if (read_config_option('drag_and_drop') == '') { if ($i < $total_items && $total_items > 1) { echo ''; } else { echo ''; } if ($i > 1 && $i <= $total_items) { echo ''; } else { echo ''; } } print ""; print "\n"; } form_end_row(); $i++; } } else { print "" . __('No Items') . ""; } } /* -------------------------- The Save Function -------------------------- */ /** * aggregate_color_form_save the save function */ function aggregate_color_form_save() { if (isset_request_var('save_component_color')) { if (isset_request_var('color_template_id')) { $save1['color_template_id'] = get_nfilter_request_var('color_template_id'); } else { $save1['color_template_id'] = 0; } $save1['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3); cacti_log('Saved ID: ' . $save1['color_template_id'] . ' Name: ' . $save1['name'], false, 'AGGREGATE', POLLER_VERBOSITY_DEBUG); if (!is_error_message()) { $color_template_id = sql_save($save1, 'color_templates', 'color_template_id'); cacti_log('Saved ID: ' . $color_template_id, false, 'AGGREGATE', POLLER_VERBOSITY_DEBUG); if ($color_template_id) { raise_message(1); } else { raise_message(2); } } } header('Location: color_templates.php?header=false&action=template_edit&color_template_id=' . (empty($color_template_id) ? get_nfilter_request_var('color_template_id') : $color_template_id)); } /* ------------------------ The 'actions' function ------------------------ */ /** * aggregate_color_form_actions the action function */ function aggregate_color_form_actions() { global $aggregate_actions, $config; include_once($config['base_path'] . '/lib/api_aggregate.php'); /* ================= input validation ================= */ get_filter_request_var('drp_action'); /* ==================================================== */ /* 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_request_var('drp_action') == '1') { /* delete */ db_execute('DELETE FROM color_templates WHERE ' . array_to_sql_or($selected_items, 'color_template_id')); db_execute('DELETE FROM color_template_items WHERE ' . array_to_sql_or($selected_items, 'color_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]); /* ==================================================== */ $color_list .= '
  • ' . html_escape(db_fetch_cell_prepared('SELECT name FROM color_templates WHERE color_template_id = ?', array($matches[1]))) . '
  • '; $color_array[] = $matches[1]; } } top_header(); form_start('color_templates.php'); html_start_box($aggregate_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', ''); if (isset($color_array) && cacti_sizeof($color_array)) { if (get_request_var('drp_action') == '1') { /* delete */ print "

    " . __n('Click \'Continue\' to delete the following Color Template', 'Click \'Continue\' to delete following Color Templates', cacti_sizeof($color_array)) . "

    "; $save_html = " "; } elseif (get_request_var('drp_action') == '2') { // duplicate print "

    " . __n('Click \'Continue\' to duplicate the following Color Template. You can optionally change the title format for the new color template.', 'Click \'Continue\' to duplicate following Color Templates. You can optionally change the title format for the new color templates.', cacti_sizeof($color_array)) . "

    " . __('Title Format:') . '
    '; form_text_box('title_format', ' (1)', '', '255', '30', 'text'); print "

    "; $save_html = " "; } elseif (get_request_var('drp_action') == '3') { // sync print "

    " . __n('Click \'Continue\' to Synchronize all Aggregate Graphs with the selected Color Template.', 'Click \'Continue\' to Syncrhonize all Aggregate Graphs with the selected Color Templates.', cacti_sizeof($color_array)) . "

    "; $save_html = " "; } } else { raise_message(40); header('Location: color_templates.php?header=false'); exit; } print " $save_html \n"; html_end_box(); form_end(); bottom_footer(); } /** * aggregate_color_item show all color template items */ function aggregate_color_item() { global $config; /* ================= input validation ================= */ get_filter_request_var('color_template_id'); /* ==================================================== */ if (isempty_request_var('color_template_id')) { $template_item_list = array(); $header_label = __('Color Template Items [new]'); } else { $template_item_list = db_fetch_assoc_prepared('SELECT cti.color_template_id, cti.color_template_item_id, cti.sequence, colors.hex FROM color_template_items AS cti LEFT JOIN colors ON cti.color_id=colors.id WHERE cti.color_template_id = ? ORDER BY cti.sequence ASC', array(get_request_var('color_template_id'))); $name = db_fetch_cell_prepared('SELECT name FROM color_templates WHERE color_template_id = ?', array(get_request_var('color_template_id'))); $header_label = __('Color Template Items [edit: %s]', html_escape($name)); } html_start_box($header_label, '100%', '', '3', 'center', 'color_templates_items.php?action=item_edit&color_template_id=' . html_escape_request_var('color_template_id')); draw_color_template_items_list($template_item_list, 'color_templates_items.php', 'color_template_id=' . html_escape_request_var('color_template_id'), false); html_end_box(); ?> array('no_form_tag' => true), 'fields' => inject_form_variables($fields_color_template_template_edit, (isset($template) ? $template : array())) ) ); html_end_box(true, true); form_hidden_box('color_template_id', (isset($template['color_template_id']) ? $template['color_template_id'] : '0'), ''); form_hidden_box('save_component_color', '1', ''); /* color item list goes here */ if (!isempty_request_var('color_template_id')) { aggregate_color_item(); } form_save_button('color_templates.php', 'return', 'color_template_id'); } function sync_color_templates($color_template) { global $config; include_once($config['base_path'] . '/lib/api_aggregate.php'); $name = db_fetch_cell_prepared('SELECT name FROM color_templates WHERE color_template_id = ?', array($color_template)); $aggregate_templates = array_rekey( db_fetch_assoc_prepared('SELECT DISTINCT aggregate_template_id FROM aggregate_graph_templates_item WHERE color_template = ?', array($color_template)), 'aggregate_template_id', 'aggregate_template_id' ); $found = false; $templates = 0; $graphs = 0; if (cacti_sizeof($aggregate_templates)) { $found = true; $templates = cacti_sizeof($aggregate_templates); foreach($aggregate_templates as $id) { push_out_aggregates($id); } } $aggregate_graphs = db_fetch_assoc_prepared('SELECT DISTINCT ag.aggregate_template_id, ag.local_graph_id FROM aggregate_graphs_graph_item AS agi LEFT JOIN aggregate_graphs AS ag ON ag.id=agi.aggregate_graph_id WHERE (ag.aggregate_template_id > 0 AND ag.template_propogation = "") OR ag.aggregate_template_id = 0 AND agi.color_template = ?', array($color_template)); if (cacti_sizeof($aggregate_graphs)) { $found = true; $graphs = cacti_sizeof($aggregate_graphs); foreach($aggregate_templates as $id) { push_out_aggregates($id['aggregate_template_id'], $id['local_graph_id']); } } if ($found) { raise_message('color_template_sync', __('Color Template \'%s\' had %d Aggregate Templates pushed out and %d Non-Templated Aggregates pushed out', $name, $templates, $graphs), MESSAGE_LEVEL_INFO); } else { raise_message('color_template_sync', __('Color Template \'%s\' had no Aggregate Templates or Graphs using this Color Template.', $name, $templates, $graphs), MESSAGE_LEVEL_INFO); } } /** * aggregate_color_template maintain color templates */ function aggregate_color_template() { global $aggregate_actions, $item_rows, $config; include_once($config['base_path'] . '/lib/api_aggregate.php'); /* ================= input validation and session storage ================= */ $filters = array( 'rows' => 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' => '' ), '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_graphs' => 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_ct'); /* ================= input validation ================= */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } form_start('color_templates.php', 'form_template'); html_start_box(__('Color Templates'), '100%', '', '3', 'center', 'color_templates.php?action=template_edit'); $filter_html = '
    ' . __('Search') . ' ' . __('Color Templates') . '
    '; print $filter_html; html_end_box(); form_end(); /* form the 'where' clause for our main sql query */ $sql_where = ''; if (get_request_var('filter') != '') { $sql_where = 'WHERE (ct.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')'; } if (get_request_var('has_graphs') == 'true') { $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . ' (templates>0 OR graphs>0)'; } $total_rows = db_fetch_cell("SELECT COUNT(ct.color_template_id) FROM color_templates AS ct LEFT JOIN ( SELECT color_template, COUNT(*) AS templates FROM aggregate_graph_templates_item GROUP BY color_template ) AS templates ON ct.color_template_id=templates.color_template LEFT JOIN ( SELECT color_template, COUNT(*) AS graphs FROM aggregate_graphs_graph_item GROUP BY color_template ) AS graphs ON ct.color_template_id=graphs.color_template $sql_where"); $sql_order = get_order_string(); $sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows; $template_list = db_fetch_assoc("SELECT ct.color_template_id, ct.name, templates.templates, graphs.graphs FROM color_templates AS ct LEFT JOIN ( SELECT color_template, COUNT(*) AS templates FROM aggregate_graph_templates_item GROUP BY color_template ) AS templates ON ct.color_template_id=templates.color_template LEFT JOIN ( SELECT color_template, COUNT(*) AS graphs FROM aggregate_graphs_graph_item GROUP BY color_template ) AS graphs ON ct.color_template_id=graphs.color_template $sql_where $sql_order $sql_limit"); $nav = html_nav_bar('color_templates.php', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 5, __('Color Templates'), 'page', 'main'); form_start('color_templates.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array( 'name' => array(__('Template Title'), 'ASC'), 'nosort' => array('display' => __('Deletable'), 'align' => 'right', 'tip' => __('Color Templates that are in use cannot be Deleted. In use is defined as being referenced by an Aggregate Template.')), 'graphs' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'DESC'), 'templates' => array('display' => __('Templates'), 'align' => 'right', 'sort' => 'DESC') ); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); if (cacti_sizeof($template_list)) { foreach ($template_list as $template) { if ($template['templates'] > 0) { $disabled = true; } else { $disabled = false; } form_alternate_row('line' . $template['color_template_id'], true); form_selectable_cell(filter_value($template['name'], get_request_var('filter'), 'color_templates.php?action=template_edit&color_template_id=' . $template['color_template_id'] . '&page=1'), $template['color_template_id']); form_selectable_cell($disabled ? __('No'):__('Yes'), $template['color_template_id'], '', 'right'); form_selectable_cell(number_format_i18n($template['graphs']), $template['color_template_id'], '', 'right'); form_selectable_cell(number_format_i18n($template['templates']), $template['color_template_id'], '', 'right'); form_checkbox_cell($template['name'], $template['color_template_id'], $disabled); form_end_row(); } } else { print "" . __('No Color 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($aggregate_actions); form_end(); ?>