<?php
$timestamp = time();
$now = date("m.Y", $timestamp);
$lastyears = array(date("Y", $timestamp)-1, date("Y", $timestamp)-2, date("Y", $timestamp)-3, date("Y", $timestamp)-4, date("Y", $timestamp));
$todaystamp = date("d.", $timestamp).$now;
$lastdays = array(date("d", $timestamp), date("d", $timestamp)-1, date("d", $timestamp)-2, date("d", $timestamp)-3, date("d", $timestamp)-4, date("d", $timestamp)-5, date("d", $timestamp)-6, date("d", $timestamp)-7, date("d", $timestamp)-8, date("d", $timestamp)-9, date("d", $timestamp)-10);

$months = array('0','0','0','0','0','0','0','0','0','0','0','0');
$years = array('0','0','0', '0', '0');
$days = array('0','0','0','0','0','0','0','0','0','0','0');

$usingtime_today = "0";
$usingtime_yesterday = "0";
$usingtime_beforeyesterday = "0";
$usingtime_twobeforeyesterday = "0";

foreach($file AS $durchschnitt) {
$durchschnitt = explode(', ', $durchschnitt);

$durchschnitt[9] = str_replace('.', '_', $durchschnitt[9]);
// Ersetzten von 1 zu 01 usw.
$durchschnitt[9] = preg_replace('/^1_/', '01', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^2_/', '02_', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^3_/', '03_', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^4_/', '04_', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^5_/', '05_', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^6_/', '06_', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^7_/', '07_', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^8_/', '08_', $durchschnitt[9]);
$durchschnitt[9] = preg_replace('/^9_/', '09_', $durchschnitt[9]);
// Ersetzen der zweiten Stelle wie oben
$durchschnitt[9] = str_replace('_1_', '_01_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_2_', '_02_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_3_', '_03_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_4_', '_04_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_5_', '_05_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_6_', '_06_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_7_', '_07_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_8_', '_08_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_9_', '_09_', $durchschnitt[9]);
$durchschnitt[9] = str_replace('_', '.', $durchschnitt[9]);
$durchschnitt[9] = trim($durchschnitt[9]);
$date = strtotime('01.'.substr($durchschnitt[9], 3, -8));
if(strtotime("01.01.".date("Y", $timestamp))==$date) {
$months[0]++;
}
if(strtotime("01.02.".date("Y", $timestamp))==$date) {
$months[1]++;
}
if(strtotime("01.03.".date("Y", $timestamp))==$date) {
$months[2]++;
}
if(strtotime("01.04.".date("Y", $timestamp))==$date) {
$months[3]++;
}
if(strtotime("01.05.".date("Y", $timestamp))==$date) {
$months[4]++;
}
if(strtotime("01.06.".date("Y", $timestamp))==$date) {
$months[5]++;
}
if(strtotime("01.07.".date("Y", $timestamp))==$date) {
$months[6]++;
}
if(strtotime("01.08.".date("Y", $timestamp))==$date) {
$months[7]++;
}
if(strtotime("01.09.".date("Y", $timestamp))==$date) {
$months[8]++;
}
if(strtotime("01.10.".date("Y", $timestamp))==$date) {
$months[9]++;
}
if(strtotime("01.11.".date("Y", $timestamp))==$date) {
$months[10]++;
}
if(strtotime("01.12.".date("Y", $timestamp))==$date) {
$months[11]++;
}
$date = strtotime('01.01.'.substr($durchschnitt[9], 6, -8));
if(strtotime("01.01.".date("Y", $timestamp))==$date) {
$years[0]++;
}
if(strtotime("01.01.".$lastyears[0])==$date) {
$years[1]++;
}
if(strtotime("01.01.".$lastyears[1])==$date) {
$years[2]++;
}
if(strtotime("01.01.".$lastyears[2])==$date) {
$years[3]++;
}
if(strtotime("01.01.".$lastyears[3])==$date) {
$years[4]++;
}
$date = strtotime(date("d.m.Y",strtotime(substr($durchschnitt[9],0,10))));
if(strtotime(date("d.m.Y",time()))==$date) {
$days[0]++;
}
if(intval(strtotime(date("d.m.Y",time()))-86400)==$date) {
$days[1]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 2))==$date) {
$days[2]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 3))==$date) {
$days[3]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 4))==$date) {
$days[4]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 5))==$date) {
$days[5]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 6))==$date) {
$days[6]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 7))==$date) {
$days[7]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 8))==$date) {
$days[8]++;
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 9))==$date) {
$days[9]++;
}
}
echo '<div class="text" style="text-align:right"><div style="display:none" id="day_graph"><canvas width="1100" height="300" style="width:95%" id="canvas_day_graph"></canvas></div><div style="display:none" id="months_graph"><canvas id="canvas_months_graph" width="1100" height="300" style="width:95%"></canvas></div><div style="display:none" id="years_graph"><canvas id="canvas_years_graph" width="1100" height="300" style="width:95%"></canvas></div><br><span style="margin-right:40px"><a href="javascript:draw_days();">Tage</a> - <a href="javascript:draw_months();">Monate</a> - <a href="javascript:draw_years();">Jahre</a></span></div>
<script>
var tage = new Array('.implode(',',array_slice($days,0,-1)).').reverse();
var monate = new Array('.implode(',',$months).');
var jahre = new Array('.implode(',',$years).').reverse();
function draw_days() {
canvas = document.getElementById("day_graph");
document.getElementById("months_graph").style.display = "none";
document.getElementById("years_graph").style.display = "none";
canvas.style.display = "block";
  var names = ["-9","-8","-7","-6","-5","-4","-3","-2","-1","Heute"];
	barchart(canvas.childNodes[0],tage,names,"day","'.date("d.m.Y",time()).'",10);
}
function draw_months() {
canvas = document.getElementById("months_graph");
canvas.style.display = "block";
document.getElementById("day_graph").style.display = "none";
document.getElementById("years_graph").style.display = "none";
  names = ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"];
  barchart(canvas.childNodes[0],monate,names,"month","'.date("Y",time()).'",12);
}
function draw_years() {
  canvas = document.getElementById("years_graph");
  document.getElementById("months_graph").style.display = "none";
  document.getElementById("day_graph").style.display = "none";
  canvas.style.display = "block";
  names = '.json_encode(array(date("Y",time()-(4*31536000)),date("Y",time()-(3*31536000)),date("Y",time()-(2*31536000)),date("Y",time()-(31536000)),date("Y",time()))).';
  barchart(canvas.childNodes[0],jahre,names,"year","'.date("Y",time()).'",5);
}
draw_days();
</script>';
?>