0 OR templates>0';
} else {
$sql_having = '';
}
$total_rows = db_fetch_cell("SELECT
COUNT(color)
FROM (
SELECT
c.id AS color,
SUM(CASE WHEN local_graph_id>0 THEN 1 ELSE 0 END) AS graphs,
SUM(CASE WHEN local_graph_id=0 THEN 1 ELSE 0 END) AS templates
FROM colors AS c
LEFT JOIN (
SELECT DISTINCT color_id, graph_template_id, local_graph_id
FROM graph_templates_item
WHERE color_id>0
) AS gti
ON gti.color_id=c.id
$sql_where
GROUP BY c.id
$sql_having
) AS rs");
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
$colors = db_fetch_assoc("SELECT *,
SUM(CASE WHEN local_graph_id>0 THEN 1 ELSE 0 END) AS graphs,
SUM(CASE WHEN local_graph_id=0 THEN 1 ELSE 0 END) AS templates
FROM (
SELECT c.*, local_graph_id
FROM colors AS c
LEFT JOIN (
SELECT DISTINCT color_id, graph_template_id, local_graph_id
FROM graph_templates_item
WHERE color_id>0
) AS gti
ON c.id=gti.color_id
) AS rs
$sql_where
GROUP BY rs.id
$sql_having
$sql_order
$sql_limit");
$nav = html_nav_bar('color.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 8, __('Colors'), 'page', 'main');
form_start('color.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'hex' => array('display' => __('Hex'), 'align' => 'left', 'sort' => 'DESC', 'tip' => __('The Hex Value for this Color.')),
'name' => array('display' => __('Color Name'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The name of this Color definition.')),
'read_only' => array('display' => __('Named Color'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('Is this color a named color which are read only.')),
'nosort1' => array('display' => __('Color'), 'align' => 'center', 'sort' => 'DESC', 'tip' => __('The Color as shown on the screen.')),
'nosort' => array('display' => __('Deletable'), 'align' => 'right', 'sort' => '', 'tip' => __('Colors in use cannot be Deleted. In use is defined as being referenced either by a Graph or a Graph Template.')),
'graphs' => array('display' => __('Graphs Using'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The number of Graph using this Color.')),
'templates' => array('display' => __('Templates Using'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The number of Graph Templates using this Color.'))
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
$i = 0;
if (cacti_sizeof($colors)) {
foreach ($colors as $color) {
if ($color['graphs'] == 0 && $color['templates'] == 0) {
$disabled = false;
} else {
$disabled = true;
}
if ($color['name'] == '') {
$color['name'] = 'Unnamed #'. $color['hex'];
}
form_alternate_row('line' . $color['id'], false, $disabled);
form_selectable_cell("" . $color['hex'] . '', $color['id']);
form_selectable_cell(filter_value($color['name'], get_request_var('filter')), $color['id']);
form_selectable_cell($color['read_only'] == 'on' ? __('Yes'):__('No'), $color['id']);
form_selectable_cell('', $color['id'], '', 'text-align:right;background-color:#' . $color['hex'] . ';min-width:30%');
form_selectable_cell($disabled ? __('No'):__('Yes'), $color['id'], '', 'text-align:right');
form_selectable_cell(number_format_i18n($color['graphs'], '-1'), $color['id'], '', 'text-align:right');
form_selectable_cell(number_format_i18n($color['templates'], '-1'), $color['id'], '', 'text-align:right');
form_checkbox_cell($color['name'], $color['id'], $disabled);
form_end_row();
}
} else {
print "
" . __('No Colors Found') . "
\n";
}
html_end_box(false);
if (cacti_sizeof($colors)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($color_actions, 1);
form_end();
}
function color_export() {
process_request_vars();
/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = 'WHERE (name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . '
OR hex LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
} else {
$sql_where = '';
}
if (get_request_var('named') == 'true') {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . " read_only='on'";
}
if (get_request_var('has_graphs') == 'true') {
$sql_having = 'HAVING graphs>0 OR templates>0';
} else {
$sql_having = '';
}
$colors = db_fetch_assoc("SELECT *,
SUM(CASE WHEN local_graph_id>0 THEN 1 ELSE 0 END) AS graphs,
SUM(CASE WHEN local_graph_id=0 THEN 1 ELSE 0 END) AS templates
FROM (
SELECT c.*, local_graph_id
FROM colors AS c
LEFT JOIN (
SELECT color_id, graph_template_id, local_graph_id
FROM graph_templates_item
WHERE color_id>0
) AS gti
ON c.id=gti.color_id
) AS rs
$sql_where
GROUP BY rs.id
$sql_having");
if (cacti_sizeof($colors)) {
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=colors.csv');
print '"name","hex"' . "\n";
foreach($colors as $color) {
print '"' . $color['name'] . '","' . $color['hex'] . '"' . "\n";
}
}
}