<?php
if(isset($_GET['source'])) {
    die(
highlight_file('tijdgrafiek.php'));
}

$db = new SQLite3('db/koffie.db');
$stmt $db->prepare('SELECT * from koffie;');
$result $stmt->execute();
$freq = array();
$firstdate 0;

$g 6;

for(
$h 0$h 24 * (60/$g); $h++) {
    
$freq[$h] = 0.0;
}
 while (
$row $result->fetchArray())
{
    
$lastdate strtotime($row['datum']);
    
$fivedate intval((strtotime(date('1970-01-01 H:i',$lastdate))) / ($g*60))+(60/$g);
    if(
$firstdate == 0)
        
$firstdate $lastdate;
    
$h date('H',$lastdate);
    
$m date('i',$lastdate);
    
$freq[$fivedate]+= $row['aantal'];
}
//ksort($freq);

$maxval max(array_values($freq));

$cmult intval(255 $maxval);

//echo '<pre>';var_dump($freq);exit;
//$data = array_values($freq);

$s intval($g/1.5);

header('Content-type: image/png');
$img imagecreatetruecolor(100,24*(60/$g)*$s);
$col imagecolorallocate($img255,255,255);
$black imagecolorallocate($img,0,0,0);
imagefilledrectangle($img0010024*60/$g*$s$col); // x1, y1, x2, y2

$i 0;
foreach(
$freq as $k => $v) {
    
$cv $cmult $v;
    
$col imagecolorallocate($img0,$cv,0);
    
imagefilledrectangle($img0$i*$s40$i $s + ($s-1), $col);
    
$i++;
    if(
$i % (60/$g) == 0) {
        
$h intval($i / (60/$g));
        
imagefilledrectangle($img41,$i*$s,100,$i*$s,$black);
        if(
$h 0)
            
imagestring($img250$i $s 20''.($h-1).'-'.($h),$black);
    }
}

$img imagerotate($img90$black);

imagepng($img);
imagedestroy($img);

?>
1