/**
  * Generate age data for age widget
  *
  * @author AvB
  **/
 function age()
 {
     // Authenticate
     if (!$this->authorized()) {
         die('Authenticate first.');
         // Todo: return json?
     }
     $out = array();
     $warranty = new Warranty_model();
     // Time calculations differ between sql implementations
     switch ($warranty->get_driver()) {
         case 'sqlite':
             $agesql = "CAST(strftime('%Y.%m%d', 'now') - strftime('%Y.%m%d', purchase_date) AS INT)";
             break;
         case 'mysql':
             $agesql = "TIMESTAMPDIFF(YEAR,purchase_date,CURDATE())";
             break;
         default:
             // FIXME for other DB engines
             $agesql = "SUBSTR(purchase_date, 1, 4)";
     }
     $sql = "SELECT count(1) as count, \n\t\t\t\t{$agesql} AS age \n\t\t\t\tFROM warranty\n\t\t\t\tGROUP by age \n\t\t\t\tORDER BY age DESC";
     $cnt = 0;
     foreach ($warranty->query($sql) as $obj) {
         $obj->age = $obj->age ? $obj->age : '<1';
         $out[] = array('label' => $obj->age, 'data' => array(array(intval($obj->count), $cnt++)));
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
				<div class="panel-heading">

					<h3 class="panel-title"><i class="fa fa-umbrella"></i> Warranty status</h3>
				
				</div>

				<div class="list-group scroll-box">

					<?php 
$warranty = new Warranty_model();
$sql = "SELECT count(id) as count, status from warranty group by status ORDER BY count DESC";
$class_list = array('Expired' => 'danger');
?>
					<?php 
foreach ($warranty->query($sql) as $obj) {
    ?>
 

					<?php 
    $status = array_key_exists($obj->status, $class_list) ? $class_list[$obj->status] : 'default';
    ?>

					<a href="<?php 
    echo url('show/listing/warranty#' . $obj->status);
    ?>
" class="list-group-item list-group-item-<?php 
    echo $status;
    ?>
">
						<span class="badge"><?php