" . __('Click \'Continue\' to delete the following Data Template(s). Any data sources attached to these templates will become individual Data Source(s) and all Templating benefits will be removed.') . "
array('no_form_tag' => 'true'),
'fields' => inject_form_variables($fields_data_template_template_edit, (isset($template) ? $template : array()), (isset($template_data) ? $template_data : array()), $_REQUEST)
)
);
html_end_box(true, true);
html_start_box(__('Data Source'), '100%', true, '3', 'center', '');
/* make sure 'data source path' doesn't show up for a template... we should NEVER template this field */
unset($struct_data_source['data_source_path']);
$form_array = array();
foreach ($struct_data_source as $field_name => $field_array) {
$form_array += array($field_name => $struct_data_source[$field_name]);
if ($form_array[$field_name]['method'] != 'spacer') {
$form_array[$field_name]['value'] = (isset($template_data[$field_name]) ? $template_data[$field_name] : '');
}
$form_array[$field_name]['form_id'] = (isset($template_data) ? $template_data['data_template_id'] : '0');
if ($field_array['flags'] == 'ALWAYSTEMPLATE') {
$form_array[$field_name]['description'] .= ' ' . __('This field is always templated.') . '';
} else {
$form_array[$field_name]['sub_checkbox'] = array(
'name' => 't_' . $field_name,
'friendly_name' => __esc('Check this checkbox if you wish to allow the user to override the value on the right during Data Source creation.'),
'value' => (isset($template_data['t_' . $field_name]) ? $template_data['t_' . $field_name] : '')
);
}
}
$form_array['data_source_profile_id']['sql'] = 'SELECT id, name FROM data_source_profiles ORDER BY name';
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($form_array, (isset($template_data) ? $template_data : array()))
)
);
html_end_box(true, true);
/* fetch ALL rrd's for this data source */
if (!isempty_request_var('id')) {
$template_data_rrds = db_fetch_assoc_prepared('SELECT id, data_source_name
FROM data_template_rrd
WHERE data_template_id = ?
AND local_data_id = 0
ORDER BY data_source_name',
array(get_request_var('id')));
}
/* select the first "rrd" of this data source by default */
if (isempty_request_var('view_rrd')) {
set_request_var('view_rrd', (isset($template_data_rrds[0]['id']) ? $template_data_rrds[0]['id'] : '0'));
}
/* get more information about the rrd we chose */
if (!isempty_request_var('view_rrd')) {
$template_rrd = db_fetch_row_prepared('SELECT *
FROM data_template_rrd
WHERE id = ?',
array(get_request_var('view_rrd')));
}
$i = 0;
if (isset($template_data_rrds)) {
if (cacti_sizeof($template_data_rrds) > 1) {
/* draw the data source tabs on the top of the page */
print "
\n
\n";
} elseif (cacti_sizeof($template_data_rrds) == 1) {
set_request_var('view_rrd', $template_data_rrds[0]['id']);
}
}
if (get_request_var('id') > 0) {
$readOnly = db_fetch_cell_prepared('SELECT id
FROM data_local
WHERE data_template_id = ?
LIMIT 1',
array(get_request_var('id')));
} else {
$readOnly = false;
}
if (!$isSNMPGet && !$readOnly) {
html_start_box(__('Data Source Item [%s]', (isset($template_rrd) ? html_escape($template_rrd['data_source_name']) : '')), '100%', true, '0', 'center', (!isempty_request_var('id') ? 'data_templates.php?action=rrd_add&id=' . get_request_var('id'):''), __('New'));
} else {
html_start_box(__('Data Source Item [%s]', (isset($template_rrd) ? html_escape($template_rrd['data_source_name']) : '')), '100%', true, '0', 'center', '', '');
}
/* data input fields list */
if (empty($template_data['data_input_id'])) {
unset($struct_data_source_item['data_input_field_id']);
} else {
$input_type = db_fetch_cell_prepared('SELECT type_id
FROM data_input
WHERE id = ?',
array($template_data['data_input_id']));
if ($input_type != 1 && $input_type != 5) {
unset($struct_data_source_item['data_input_field_id']);
} else {
$struct_data_source_item['data_input_field_id']['sql'] = "SELECT id, CONCAT(data_name, ' - ', name) AS name FROM data_input_fields WHERE data_input_id=" . $template_data['data_input_id'] . " AND input_output='out' AND update_rra='on' ORDER BY data_name, name";
}
}
$form_array = array();
foreach ($struct_data_source_item as $field_name => $field_array) {
$form_array += array($field_name => $struct_data_source_item[$field_name]);
$form_array[$field_name]['value'] = (isset($template_rrd) ? $template_rrd[$field_name] : '');
$form_array[$field_name]['sub_checkbox'] = array(
'name' => 't_' . $field_name,
'friendly_name' => __esc('Check this checkbox if you wish to allow the user to override the value on the right during Data Source creation.'),
'value' => (isset($template_rrd) ? $template_rrd['t_' . $field_name] : '')
);
}
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => $form_array + array(
'data_template_rrd_id' => array(
'method' => 'hidden',
'value' => (isset($template_rrd) ? $template_rrd['id'] : '0')
)
)
)
);
html_end_box(true, true);
$i = 0;
if (!isempty_request_var('id')) {
/* get each INPUT field for this data input source */
$fields = db_fetch_assoc_prepared('SELECT *
FROM data_input_fields
WHERE data_input_id = ?
AND input_output="in" ORDER BY name',
array($template_data['data_input_id']));
$name = db_fetch_cell_prepared('SELECT name
FROM data_input
WHERE id = ?',
array($template_data['data_input_id']));
html_start_box(__('Custom Data [data input: %s]', html_escape($name)), '100%', true, '3', 'center', '');
/* loop through each field found */
if (cacti_sizeof($fields) > 0) {
$class = 'odd';
foreach ($fields as $field) {
$data_input_data = db_fetch_row_prepared('SELECT t_value, value
FROM data_input_data AS did
WHERE data_template_data_id = ?
AND data_input_field_id = ?',
array($template_data['id'], $field['id']));
// Data Query Key fields
if (data_input_field_always_checked($field['id'])) {
$message = __esc('This value is disabled due to it either it value being derived from the Device or special Data Query object that keeps track of critical data Data Query associations.');
if (cacti_sizeof($data_input_data)) {
$old_value = $data_input_data['value'];
$old_tvalue = 'on';
$disable = 'disable';
} else {
$old_value = '';
$old_tvalue = 'on';
$disable = 'disable';
}
} elseif ($field['type_code'] == 'host_id') {
$message = __esc('This value is disabled due to it being derived from the Device and read only.');
$old_value = $data_input_data['value'];
$old_tvalue = '';
$disable = 'disable';
} else {
$message = __esc('Check this checkbox if you wish to allow the user to override the value on the right during Data Source creation.');
if (cacti_sizeof($data_input_data)) {
$old_value = $data_input_data['value'];
$old_tvalue = $data_input_data['t_value'];
$disable = '';
} else {
$old_value = '';
$old_tvalue = '';
$disable = '';
}
}
if ($field['data_name'] == 'management_ip') {
$help = $fields_host_edit['hostname']['description'];
} elseif (isset($fields_host_edit[$field['data_name']])) {
$help = $fields_host_edit[$field['data_name']]['description'];
} else {
$help = $field['name'];
}
print "
";
if ($class == 'odd') {
$class = 'even';
} else {
$class = 'odd';
}
if (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field['type_code']) && $old_tvalue == '') {
$title = __esc('Value will be derived from the Device if this field is left empty.');
} else {
$title = '';
}
?>
';
$i++;
}
} else {
print '
' . __('No Input Fields for the Selected Data Input Source') . '
0';
} else {
$sql_having = '';
}
$total_rows = db_fetch_cell("SELECT COUNT(`rows`)
FROM (SELECT
COUNT(dt.id) `rows`,
SUM(CASE WHEN dtd.local_data_id>0 THEN 1 ELSE 0 END) AS data_sources
FROM data_template AS dt
INNER JOIN data_template_data AS dtd
ON dt.id=dtd.data_template_id
LEFT JOIN data_source_profiles AS dsp
ON dtd.data_source_profile_id=dsp.id
LEFT JOIN data_input AS di
ON dtd.data_input_id=di.id
$sql_where
GROUP BY dt.id
$sql_having
) AS rs");
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
$template_list_sql = "SELECT dt.id, dt.name,
di.name AS data_input_method, dtd.active AS active, dsp.name AS profile_name,
SUM(CASE WHEN dtd.local_data_id>0 THEN 1 ELSE 0 END) AS data_sources
FROM data_template AS dt
INNER JOIN data_template_data AS dtd
ON dt.id=dtd.data_template_id
LEFT JOIN data_source_profiles AS dsp
ON dtd.data_source_profile_id=dsp.id
LEFT JOIN data_input AS di
ON dtd.data_input_id=di.id
$sql_where
GROUP BY dt.id
$sql_having
$sql_order
$sql_limit";
$template_list = db_fetch_assoc($template_list_sql);
$display_text = array(
'name' => array(
'display' => __('Data Template Name'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('The name of this Data Template.')
),
'id' => array(
'display' => __('ID'),
'align' => 'right',
'sort' => 'ASC',
'tip' => __('The internal database ID for this Data Template. Useful when performing automation or debugging.')
),
'nosort' => array(
'display' => __('Deletable'),
'align' => 'right',
'tip' => __('Data Templates that are in use cannot be Deleted. In use is defined as being referenced by a Data Source.')
),
'data_sources' => array(
'display' => __('Data Sources Using'),
'align' => 'right',
'sort' => 'DESC',
'tip' => __('The number of Data Sources using this Data Template.')
),
'data_input_method' => array(
'display' => __('Input Method'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('The method that is used to place Data into the Data Source RRDfile.')
),
'profile_name' => array(
'display' => __('Profile Name'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('The default Data Source Profile for this Data Template.')
),
'active' => array(
'display' => __('Status'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('Data Sources based on Inactive Data Templates will not be updated when the poller runs.')
)
);
$nav = html_nav_bar('data_templates.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, cacti_sizeof($display_text) + 1, __('Data Templates'), 'page', 'main');
form_start('data_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);
if (cacti_sizeof($template_list)) {
foreach ($template_list as $template) {
if ($template['data_sources'] > 0) {
$disabled = true;
} else {
$disabled = false;
}
$ds_url = 'data_sources.php?reset=true&template_id=' . $template['id'];
if (get_request_var('profile') != '-1') {
$ds_url .= '&profile=' . get_request_var('profile');
}
form_alternate_row('line' . $template['id'], true, $disabled);
form_selectable_cell(filter_value($template['name'], get_request_var('filter'), 'data_templates.php?action=template_edit&id=' . $template['id']), $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['data_sources']) . '', $template['id'], '', 'right');
form_selectable_cell((empty($template['data_input_method']) ? '' . __('None') .'': html_escape($template['data_input_method'])), $template['id']);
form_selectable_cell((empty($template['profile_name']) ? __('External'):html_escape($template['profile_name'])), $template['id']);
form_selectable_cell((($template['active'] == 'on') ? __('Active'):__('Disabled')), $template['id']);
form_checkbox_cell($template['name'], $template['id'], $disabled);
form_end_row();
}
} else {
print "
" . __('No Data 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($ds_actions);
form_end();
}