if ($i == $bins - 1) {
        $bin_labels[$i] = $bin_size * $i . " to " . $max_raps_per_rope;
    } else {
        $a = $bin_size * $i;
        $b = $bin_size * ($i + 1) - 1;
        $bin_labels[$i] = $a . " to " . $b;
    }
}
/*
echo "Bins: ".$bins."\n";
echo "Max Raps Per Rope: ".$max_raps_per_rope."\n";
echo "Bin Size: ".$bin_size."\n";
print_r($bin_labels);
*/
if ($total_ropes == 0) {
    chart_error_msg("No ropes have been retired!");
} else {
    $chart_data = "<chart_data>\n" . "\t<row>\n" . "\t\t<null/>\n";
    foreach ($bin_labels as $label) {
        $chart_data .= "\t\t<string>" . $label . "</string>\n";
    }
    $chart_data .= "\t</row>\n" . "\t<row>\n" . "\t\t<string>% of retired ropes with designated raps</string>\n";
    foreach ($rope_cat as $idx => $rope_count) {
        $pct = $rope_count / $total_ropes * 100;
        $chart_data .= "\t\t<number label='" . $pct . "%' tooltip='" . $pct . "% of retired ropes\rhave only " . $bin_labels[$idx - 1] . " raps'>" . $pct . "</number>\n";
    }
    $chart_data .= "\t</row>\n" . "</chart_data>\n";
    $chart_type = "<chart_type>column</chart_type>\n";
    $chart_rect = "<chart_rect\tx='25'\n\t\t\t\t\t\t\t\t\ty='40'\n\t\t\t\t\t\t\t\t\twidth='200'\n\t\t\t\t\t\t\t\t\theight='150' />\n";
    $legend = "<legend\tlayout='horizontal'\n\t\t\t\t\t\t\t\tbullet='square'\n\t\t\t\t\t\t\t\tfont='arial'\n\t\t\t\t\t\t\t\tbold='true'\n\t\t\t\t\t\t\t\tsize='10'\n\t\t\t\t\t\t\t\tcolor='555555'\n\t\t\t\t\t\t\t\talpha='90'\n\t\t\t\t\t\t\t\twidth='250'\n\t\t\t\t\t\t\t\tx='0'\n\t\t\t\t\t\t\t\ty='0'\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\ttransition='slide_left' delay='1' duration='1'/>\n";
    $axis_value_label = "";
<?php

include '../php_doc_root.php';
require_once "classes/mydb_class.php";
require_once "classes/hrap_class.php";
require_once "classes/crew_class.php";
require_once "includes/charts/chart_error_msg.php";
session_name('raprec');
session_start();
// Get Regional Data
$query = "\n\tSELECT count(hraps.id) as hrap_count FROM hraps \n\tINNER JOIN rosters ON (rosters.hrap_id = hraps.id AND rosters.year = " . $_SESSION['current_view']['year'] . ")\n\tINNER JOIN crews ON (crews.id = rosters.crew_id AND crews.region = '" . $_SESSION['current_view']['crew']->get('region') . "')";
$result = mydb::cxn()->query($query);
if (!$result) {
    chart_error_msg("Error counting rappels:\n" . mydb::cxn()->error);
} else {
    $row = $result->fetch_assoc();
}
$total_hraps_in_region = $row['hrap_count'];
$query = "\n\tSELECT operation_type, count(raps) AS raps \n\tFROM rap_type_count \n\tWHERE year = '" . $_SESSION['current_view']['year'] . "' AND region = '" . $_SESSION['current_view']['crew']->get('region') . "' \n\tGROUP BY operation_type";
$result = mydb::cxn()->query($query);
if (!$result) {
    echo "Error: " . mydb::cxn()->error;
}
$region_avg = array('operational' => 0, 'proficiency_live' => 0, 'proficiency_tower' => 0, 'certification_new_aircraft' => 0, 'certification_new_hrap' => 0);
while ($row = $result->fetch_assoc()) {
    if (array_key_exists($row['operation_type'], $region_avg)) {
        $region_avg[$row['operation_type']] = round($row['raps'] / $total_hraps_in_region, 1);
    }
}
$region_avg['proficiency_live'] = $region_avg['proficiency_live'] + $region_avg['certification_new_aircraft'] + $region_avg['certification_new_hrap'];
$region_avg['total_live'] = $region_avg['proficiency_live'] + $region_avg['operational'];
<?php

include '../php_doc_root.php';
require_once "classes/mydb_class.php";
require_once "classes/hrap_class.php";
require_once "classes/crew_class.php";
require_once "includes/charts/chart_error_msg.php";
session_name('raprec');
session_start();
$max_rope_life = $_SESSION['max_rope_life_time'];
//Number of years before a rope MUST be retired (This value is specified in the 'includes/constants.php' file)
$query = "SELECT serial_num, life_days_remaining, status, in_service_date, DATEDIFF( STR_TO_DATE( retired_date,  '%m/%d/%Y' ) , STR_TO_DATE( in_service_date,  '%m/%d/%Y' ) ) AS retired_age FROM rope_use_view WHERE id = " . $_GET['rope_id'];
$result = mydb::cxn()->query($query);
if (!$result) {
    chart_error_msg("Rope not found!");
} else {
    $row = $result->fetch_assoc();
    if ($row['status'] != "retired") {
        $days_in_service = 365 * $max_rope_life - $row['life_days_remaining'];
        $tooltip1 = "This rope has been\rIn Service for " . $days_in_service . " days";
        if ($row['life_days_remaining'] > 0) {
            $used_life = round(100 * (365 * $max_rope_life - $row['life_days_remaining']) / (365 * $max_rope_life), 1);
            // A percentage of max_rope_life
            $remaining_life = round(100 - $used_life, 1);
            // The remaining percentage of max_rope_life
        } else {
            $used_life = 100;
            $remaining_life = 0;
        }
        $tooltip2 = "This rope must be\rretired in " . $row['life_days_remaining'] . " days";
    } else {