$iter = 0;
$rrd_options .= " COMMENT:'Supply level           Cur     Min      Max\\n'";
$colours = "mixed";
// $supply_type will be set if we are included from a more specific graph
if (isset($supply_type)) {
    $rows = dbFetchRows("SELECT * FROM `printersupplies` where `device_id` = ? AND `supply_type` = ?", array($device['device_id'], $supply_type));
} else {
    $rows = dbFetchRows("SELECT * FROM `printersupplies` where `device_id` = ?", array($device['device_id']));
}
foreach ($rows as $supply) {
    // If colour was supplied by the device, pass it to the function, otherwise pass the description
    // and have the function try and figure it out from there.
    if ($supply['supply_colour'] != '') {
        $colour = toner_to_colour($supply['supply_colour'], $perc);
    } else {
        $colour = toner_to_colour($supply['supply_descr'], $perc);
    }
    // If no colour found by the toner to colour function, get one from the configured palette.
    if (!$colour['found']) {
        if (!$config['graph_colours'][$colours][$iter]) {
            $iter = 0;
        }
        $colour['left'] = $config['graph_colours'][$colours][$iter];
    }
    $hostname = get_device_by_device_id($supply['device_id']);
    $descr = rrdtool_escape($supply['supply_descr'], 16);
    $rrd_filename = get_rrd_path($device, "toner-" . $supply['supply_index'] . ".rrd");
    $supply_id = $supply['supply_id'];
    $rrd_options .= " DEF:level{$supply_id}={$rrd_filename}:level:AVERAGE";
    $rrd_options .= " LINE2:level{$supply_id}#" . $colour['left'] . ":'" . $descr . "'";
    $rrd_options .= " GPRINT:level{$supply_id}:LAST:'%5.0lf%%'";
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage graphs
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
include_once $config['html_dir'] . "/includes/graphs/common.inc.php";
$rrd_options .= " -l 0 -E ";
$iter = "1";
$rrd_options .= " COMMENT:'Imaging Drum level     Cur     Min      Max\\n'";
$drums = array('Cyan' => 'c', 'Magenta' => 'm', 'Yellow' => 'y', 'Black' => 'k');
foreach ($drums as $drum => $letter) {
    $descr = rrdtool_escape("{$drum} Drum", 16);
    $colour = toner_to_colour($descr);
    $hostname = get_device_by_device_id($device['device_id']);
    $rrd_filename = get_rrd_path($device, "drum-{$letter}.rrd");
    $rrd_options .= " DEF:drum{$iter}={$rrd_filename}:drum:AVERAGE";
    $rrd_options .= " LINE2:drum{$iter}#" . $colour['left'] . ":'" . $descr . "'";
    $rrd_options .= " GPRINT:drum{$iter}:LAST:'%5.0lf%%'";
    $rrd_options .= " GPRINT:drum{$iter}:MIN:'%5.0lf%%'";
    $rrd_options .= " GPRINT:drum{$iter}:MAX:%5.0lf%%\\l";
    $iter++;
}
// EOF
function generate_printersupplies_row($supply, $vars)
{
    $graph_type = "printersupply_usage";
    $table_cols = 5;
    $total = $supply['supply_capacity'];
    $perc = $supply['supply_value'];
    $graph_array['type'] = $graph_type;
    $graph_array['id'] = $supply['supply_id'];
    $graph_array['from'] = $GLOBALS['config']['time']['day'];
    $graph_array['to'] = $GLOBALS['config']['time']['now'];
    $graph_array['height'] = "20";
    $graph_array['width'] = "80";
    if ($supply['supply_colour'] != '') {
        $background = toner_to_colour($supply['supply_colour'], $perc);
    } else {
        $background = toner_to_colour($supply['supply_descr'], $perc);
    }
    /// FIXME - popup for printersupply entity.
    $output .= '<tr class="' . $supply['html_row_class'] . '">';
    $output .= '<td class="state-marker"></td>';
    if ($vars['popup'] == TRUE) {
        $output .= '<td style="width: 40px; text-align: center;"><i class="' . $GLOBALS['config']['entities']['printersupply']['icon'] . '"></i></td>';
    } else {
        $output .= '<td style="width: 1px;"></td>';
    }
    if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
        $output .= '<td class="entity">' . generate_device_link($supply) . '</td>';
        $table_cols++;
    }
    $output .= '<td class="entity">' . generate_entity_link('printersupply', $supply) . '</td>';
    if (!isset($vars['supply'])) {
        $output .= '<td>' . nicecase($supply['supply_type']) . '</td>';
    }
    $output .= '<td style="width: 70px;">' . generate_graph_popup($graph_array) . '</td>';
    $output .= '<td style="width: 200px;"><a href="' . $link . '">' . print_percentage_bar(400, 20, $perc, $perc . '%', 'ffffff', $background['right'], NULL, "ffffff", $background['left']) . '</a></td>';
    $output .= '<td style="width: 50px; text-align: right;"><span class="label">' . $perc . '%</span></td>';
    $output .= '</tr>';
    if ($vars['view'] == "graphs") {
        $output .= '<tr class="' . $supply['html_row_class'] . '">';
        $output .= '<td class="state-marker"></td>';
        $output .= '<td colspan=' . $table_cols . '>';
        unset($graph_array['height'], $graph_array['width'], $graph_array['legend']);
        $graph_array['to'] = $config['time']['now'];
        $graph_array['id'] = $supply['supply_id'];
        $graph_array['type'] = $graph_type;
        $output .= generate_graph_row($graph_array, TRUE);
        $output .= "</td></tr>";
    }
    # endif graphs
    return $output;
}
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2015 Observium Limited
 *
 */
$graph_type = "printersupply_usage";
$supplies = dbFetchRows("SELECT * FROM `printersupplies` WHERE `device_id` = ? ORDER BY `supply_type`", array($device['device_id']));
if (count($supplies)) {
    $box_args = array('title' => 'Printer Supplies', 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'printing')), 'icon' => 'oicon-contrast');
    echo generate_box_open($box_args);
    echo '<table class="table table-condensed table-striped">';
    foreach ($supplies as $supply) {
        $percent = round($supply['supply_value'], 0);
        if ($supply['supply_colour'] != '') {
            $background = toner_to_colour($supply['supply_colour'], $percent);
        } else {
            $background = toner_to_colour($supply['supply_descr'], $percent);
        }
        $background_percent = get_percentage_colours($percent - 100);
        $graph_array = array();
        $graph_array['height'] = "100";
        $graph_array['width'] = "210";
        $graph_array['to'] = $config['time']['now'];
        $graph_array['id'] = $supply['supply_id'];
        $graph_array['type'] = $graph_type;
        $graph_array['from'] = $config['time']['day'];
        $graph_array['legend'] = "no";
        $link_array = $graph_array;
        $link_array['page'] = "graphs";
        unset($link_array['height'], $link_array['width'], $link_array['legend']);
        $link = generate_url($link_array);
        $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $supply['supply_descr']);