<?php
ini_set("display_errors", 1);
//error_reporting(E_ALL|E_STRICT|E_NOTICE);
session_start();

include('functions.php');

$config = loadConfig();
unlock_all_files();

if(o_login_check($_POST['user'],$_POST['password']) OR o_login_check($_SESSION['user'],$_SESSION['password'])) {

if(isset($_POST['user'])) {
$_SESSION['user'] = $_POST['user'];
$_SESSION['password'] = $_POST['password'];
}

$file = loadLog();
$file = array_reverse($file);

// aus visitorgraph.php abgeändert
$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));
$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);
$yesterdaystamp = $yesterdaystamp.".".$now;
$today = "0";
$yesterday = "0";
$beforeyesterday = "0";
$twobeforeyesterday = "0";

$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');
$actions = array();
$actions_per_day = array(0,0,0,0,0,0,0,0,0,0);
$actions_per_month = array(0,0,0,0,0,0,0,0,0,0,0,0);
$actions_per_year = array(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 = substr($durchschnitt[9], 0, -8);
$date = strtotime($date);

if(strtotime($todaystamp)==$date) {
$today++;
$usingtime_today = $usingtime_today + $durchschnitt[8];
}
if(strtotime($yesterdaystamp)==$date) {
$yesterday++;
$usingtime_yesterday = $usingtime_yesterday + $durchschnitt[8];
}
if(strtotime($beforeyesterdaystamp)==$date) {
$beforeyesterday++;
$usingtime_beforeyesterday = $usingtime_bevoreyesterday + $durchschnitt[8];
}
if(strtotime($twobeforeyesterdaystamp)==$date) {
$twobeforeyesterday++;
$usingtime_twobeforeyesterday = $usingtime_twobeforeyesterday + $durchschnitt[8];
}
$date = strtotime('01.'.substr($durchschnitt[9], 3, -8));
if(strtotime("01.01.".date("Y", $timestamp))==$date) {
$months[0]++;
$actions_per_month[0] = $actions_per_month[0] + $durchschnitt[13];
}
if(strtotime("01.02.".date("Y", $timestamp))==$date) {
$months[1]++;
$actions_per_month[1] = $actions_per_month[1] + $durchschnitt[13];
}
if(strtotime("01.03.".date("Y", $timestamp))==$date) {
$months[2]++;
$actions_per_month[2] = $actions_per_month[2] + $durchschnitt[13];
}
if(strtotime("01.04.".date("Y", $timestamp))==$date) {
$months[3]++;
$actions_per_month[3] = $actions_per_month[3] + $durchschnitt[13];
}
if(strtotime("01.05.".date("Y", $timestamp))==$date) {
$months[4]++;
$actions_per_month[4] = $actions_per_month[4] + $durchschnitt[13];
}
if(strtotime("01.06.".date("Y", $timestamp))==$date) {
$months[5]++;
$actions_per_month[5] = $actions_per_month[5] + $durchschnitt[13];
}
if(strtotime("01.07.".date("Y", $timestamp))==$date) {
$months[6]++;
$actions_per_month[6] = $actions_per_month[6] + $durchschnitt[13];
}
if(strtotime("01.08.".date("Y", $timestamp))==$date) {
$months[7]++;
$actions_per_month[7] = $actions_per_month[7] + $durchschnitt[13];
}
if(strtotime("01.09.".date("Y", $timestamp))==$date) {
$months[8]++;
$actions_per_month[8] = $actions_per_month[8] + $durchschnitt[13];
}
if(strtotime("01.10.".date("Y", $timestamp))==$date) {
$months[9]++;
$actions_per_month[9] = $actions_per_month[9] + $durchschnitt[13];
}
if(strtotime("01.11.".date("Y", $timestamp))==$date) {
$months[10]++;
$actions_per_month[10] = $actions_per_month[10] + $durchschnitt[13];
}
if(strtotime("01.12.".date("Y", $timestamp))==$date) {
$months[11]++;
$actions_per_month[11] = $actions_per_month[11] + $durchschnitt[13];
}
$date = strtotime('01.01.'.substr($durchschnitt[9], 6, -8));
if(strtotime("01.01.".date("Y", $timestamp))==$date) {
$years[0]++;
$actions_per_year[0] = $actions_per_year[0] + $durchschnitt[13];
}
if(strtotime("01.01.".$lastyears[0])==$date) {
$years[1]++;
$actions_per_year[1] = $actions_per_year[1] + $durchschnitt[13];
}
if(strtotime("01.01.".$lastyears[1])==$date) {
$years[2]++;
$actions_per_year[2] = $actions_per_year[2] + $durchschnitt[13];
}
if(strtotime("01.01.".$lastyears[2])==$date) {
$years[3]++;
$actions_per_year[3] = $actions_per_year[3] + $durchschnitt[13];
}
if(strtotime("01.01.".$lastyears[3])==$date) {
$years[4]++;
$actions_per_year[4] = $actions_per_year[4] + $durchschnitt[13];
}
$date = strtotime(date("d.m.Y",strtotime(substr($durchschnitt[9],0,10))));
if(strtotime(date("d.m.Y",time()))==$date) {
$days[0]++;
$actions_per_day[0] = $actions_per_day[0] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-86400)==$date) {
$days[1]++;
$actions_per_day[1] = $actions_per_day[1] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 2))==$date) {
$days[2]++;
$actions_per_day[2] = $actions_per_day[2] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 3))==$date) {
$days[3]++;
$actions_per_day[3] = $actions_per_day[3] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 4))==$date) {
$days[4]++;
$actions_per_day[4] = $actions_per_day[4] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 5))==$date) {
$days[5]++;
$actions_per_day[5] = $actions_per_day[5] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 6))==$date) {
$days[6]++;
$actions_per_day[6] = $actions_per_day[6] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 7))==$date) {
$days[7]++;
$actions_per_day[7] = $actions_per_day[7] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 8))==$date) {
$days[8]++;
$actions_per_day[8] = $actions_per_day[8] + $durchschnitt[13];
}
if(intval(strtotime(date("d.m.Y",time()))-(86400 * 9))==$date) {
$days[9]++;
$actions_per_day[9] = $actions_per_day[9] + $durchschnitt[13];
}
array_push($actions, intval($durchschnitt[13]));
}
// Sort the array
rsort($actions);
$usingtime_today = $usingtime_today / $today;
$usingtime_yesterday = $usingtime_yesterday / $yesterday;
$usingtime_beforeyesterday = $usingtime_beforeyesterday / $beforeyesterday;
$usingtime_twobeforeyesterday = $usingtime_twobeforeyesterday / $twobeforeyesterday;


$de = "0";
$en = "0";
$fr = "0";
$it = "0";
$es = "0";

foreach($file AS $log) {
$log = explode(", ", $log);
if($log[5]=="de") {
$de++;
}
if($log[5]=="en") {
$en++;
}
if($log[5]=="fr") {
$fr++;
}
if($log[5]=="it") {
$it++;
}
if($log[5]=="es") {
$es++;
}
}

// Prozentwerte ausrechnen
$else = count($file) - ($de + $en + $fr + $it + $es);
$other_browsers = count($file) - ($firefox + $IE + $safari + $chrome + $opera);
$de = 100 / count($file) * $de;
$en = 100 / count($file) * $en;
$fr = 100 / count($file) * $fr;
$it = 100 / count($file) * $it;
$es = 100 / count($file) * $es;
$else = 100 / count($file) * $else;

$firefox = 100 / count($file) * $firefox;
$IE = 100 / count($file) * $IE;
$safari = 100 / count($file) * $safari;
$chrome = 100 / count($file) * $chrome;
$opera = 100 / count($file) * $opera;
$other_browsers = 100 / count($file) * $other_browsers;

$windows = 100 / count($file) * $windows;
$mac = 100 / count($file) * $mac;
$anderes_system = 100 / count($file) * $anderes_system;


// Desktop and Mobile devices
$desktop_users = round(100 / count($file) * $desktop, 0);
// Plus 1 ist als Ausgleich beim runden da
$mobile_users = round(100 / count($file) * $mobile + 1, 0);

// Durchschnitte
$nutzer_durchschnitt = ($today + $yesterday + $beforeyesterday + $twobeforeyesterday) / 4;
$nutzungszeit_durchschnitt = ($usingtime_today + $usingtime_yesterday + $usingtime_beforeyesterday + $usingtime_twobeforeyesterday) / 4;

$actions_per_day = array($actions_per_day[0] / $days[0], $actions_per_day[1] / $days[1], $actions_per_day[2] / $days[2], $actions_per_day[3] / $days[3], $actions_per_day[4] / $days[4], $actions_per_day[5] / $days[5], $actions_per_day[6] / $days[6], $actions_per_day[7] / $days[7], $actions_per_day[8] / $days[8], $actions_per_day[9] / $days[9], $actions_per_day[10] / $days[10]);
$actions_per_month = array($actions_per_month[0] / $months[0], $actions_per_month[1] / $months[1], $actions_per_month[2] / $months[2], $actions_per_month[3] / $months[3], $actions_per_month[4] / $months[4], $actions_per_month[5] / $months[5], $actions_per_month[6] / $months[6], $actions_per_month[7] / $months[7], $actions_per_month[8] / $months[8], $actions_per_month[9] / $months[9], $actions_per_month[10] / $months[10], $actions_per_month[11] / $months[11]);
$actions_per_year = array($actions_per_year[0] / $years[0], $actions_per_year[1] / $years[1], $actions_per_year[2] / $years[2], $actions_per_year[3] / $years[3], $actions_per_year[4] / $years[4]);

// Aus view.php geändert
$suchen = array();
$geolocation = array();
$Search_Engines = array();
$externe_suchen = array();
$referrers = array();
$searchengines_otherorigins = array();
foreach($file AS $durchschnitt) {
$durchschnitt = explode(', ', $durchschnitt);

// Nutzungszeit
$usingtime = $usingtime + $durchschnitt[8];

// Bildschirmbreite
$breite = $breite + $durchschnitt[2];

// Desktop/Mobile
if($durchschnitt[2] > 640) {
$desktop++;
}
if($durchschnitt[2] < 640) {
$mobile++;
}

// Betriebssystem
$system = $system." , ".$durchschnitt[6];

// Einzelne Nutzer
if(strpos($nutzerip, $durchschnitt[1])===false) {
$nutzer++;
$nutzerip = $nutzerip.$durchschnitt[1];
}

// Sprachen
$sprachen = $sprachen.$durchschnitt[5];
$language[] = $durchschnitt[5];

// Zeit
$zeitstring = substr($durchschnitt[9],11);
$zeitstring = substr($zeitstring, 0, -3); 
$zeitstring = str_replace(':', '.', $zeitstring);
$zeit = $zeit + $zeitstring; 

// Meistgenutzte Seite
$meistgenutzt[] = $durchschnitt[0];

// Bots
if(strpos($durchschnitt[4], "Bot")!==false OR strpos($durchschnitt[4], "bot")!==false OR strpos($durchschnitt[4], "BUbiNG")!==false) {
$bots++;
}

// Meistinstalliertes Plugin
$meistgenutzes_plugin = $meistgenutzes_plugin." ".$durchschnitt[7];


// referrers
if(strpos($durchschnitt[10], 'google')===false AND strpos($durchschnitt[10], 'bing.com')===false AND strpos($durchschnitt[10], 'ask.com')===false AND strpos($durchschnitt[10], 'yahoo.com')===false AND strpos($durchschnitt[10], 'duckduckgo.com')===false) {
$referrers[] = $durchschnitt[10];
}

// Suchmaschinen
if(preg_match("/google/",$durchschnitt[10])) {
$Search_Engines[] = "Google=>".$durchschnitt[11]."=>".str_replace(' ', '@opolyticswhitespace', str_replace('_', ',', $durchschnitt[12]))."=>".$durchschnitt[0]."=>".parseGet(parse_url($durchschnitt[10])["query"])["q"];
$google++;
$searchengines_otherorigins[0]++;
array_push($externe_suchen, parseGet(parse_url($durchschnitt[10])["query"])["q"]);
}
if(strpos($durchschnitt[10], 'bing.com')!==false) {
$Search_Engines[] = "Bing=>".$durchschnitt[11]."=>".str_replace(' ', '@opolyticswhitespace', str_replace('_', ',', $durchschnitt[12]))."=>".$durchschnitt[0]."=>".parseGet(parse_url($durchschnitt[10])["query"])["q"];
$bing++;
$searchengines_otherorigins[0]++;
array_push($externe_suchen, parseGet(parse_url($durchschnitt[10])["query"])["q"]);
}
if(strpos($durchschnitt[10], 'ask.com')!==false) {
$Search_Engines[] = "Ask.com=>".$durchschnitt[11]."=>".str_replace(' ', '@opolyticswhitespace', str_replace('_', ',', $durchschnitt[12]))."=>".$durchschnitt[0]."=>".parseGet(parse_url($durchschnitt[10])["query"])["q"];
$ask++;
$searchengines_otherorigins[0]++;
array_push($externe_suchen, parseGet(parse_url($durchschnitt[10])["query"])["q"]);
}
if(strpos($durchschnitt[10], 'yahoo.com')!==false) {
$Search_Engines[] = "Yahoo=>".$durchschnitt[11]."=>".str_replace(' ', '@opolyticswhitespace', str_replace('_', ',', $durchschnitt[12]))."=>".$durchschnitt[0]."=>".parseGet(parse_url($durchschnitt[10])["query"])["p"];
$yahoo++;
$searchengines_otherorigins[0]++;
array_push($externe_suchen, parseGet(parse_url($durchschnitt[10])["query"])["p"]);
}
if(strpos($durchschnitt[10], 'duckduckgo.com')!==false) {
$Search_Engines[] = "DuckDuckGo=>".$durchschnitt[11]."=>".str_replace(' ', '@opolyticswhitespace', str_replace('_', ',', $durchschnitt[12]))."=>".$durchschnitt[0]."=>".parseGet(parse_url($durchschnitt[10])["query"])["q"];
$duckduckgo++;
$searchengines_otherorigins[0]++;
array_push($externe_suchen, parseGet(parse_url($durchschnitt[10])["query"])["q"]);
}
// Browser erkennen
if(preg_match("/MSIE|Media Center|like Gecko/", $durchschnitt[4]) AND !preg_match("/KHTML_ like Gecko/", $durchschnitt[4])) {
$IE++;
}
if(preg_match("/Firefox.[1-9]*.[1-9]{1}/", $durchschnitt[4])) {
$firefox++;
}
if(preg_match("/Safari|safari/", $durchschnitt[4]) AND !preg_match("/Chrome|chrome/", $durchschnitt[4])) {
$safari++;
}
if(preg_match("/Chrome|chrome/", $durchschnitt[4]) AND preg_match("/Safari|safari/", $durchschnitt[4])) {
$chrome++;
}
if(preg_match("/opera|Opera|OPR|opr|Opr/", $durchschnitt[4])) {
$opera++;
}

// Oft gesucht
if(preg_match($config[20], $durchschnitt[0])) {
$parameter = $config[21];
$durchschnitt[0] = parseGet(parse_url($durchschnitt[0])['query'])[$parameter];
array_push($suchen, $durchschnitt[0]);
}
// Karte
$geolocation[] = $durchschnitt[14];
$regions[] = $durchschnitt[15];
}

// Endberechnung
$usingtime = $usingtime / count($file);
$usingtime = round($usingtime, 1);
$breite = $breite / count($file);
$breite = round($breite, 1);
$windows = substr_count ( $system , "Win" );
$mac = substr_count ( $system , "Mac" );
$anderes_system = count($file) - ($windows + $mac);
$sprachen = substr_count ( $sprachen , "de" );
$sprachen = count($file) - $sprachen;
$zeit = $zeit / count($file);
$zeit = round($zeit, 2);
$zeit = str_replace('.', ':', $zeit);
$aufrufe_pro_nutzer = count($file) / $nutzer;

$count = array_count_values($meistgenutzt);
$idlist = array_keys($count, max($count));
$mostused = $idlist[0];
$searchengines_otherorigins[1] = count($file) - $searchengines_otherorigins[0];
$searchengines_otherorigins[0] = 100 / count($file) * $searchengines_otherorigins[0];
$searchengines_otherorigins[1] = 100 / count($file) * $searchengines_otherorigins[1];

$regions = array_count_values($regions);

if($_GET['view']=="beliebt") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Beliebte Seiten - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
echo '<h1 id="seitenaufrufe">Rangliste der Seitenaufrufe</h1><div class="text"><div><canvas id="sites" width="1100" height="250"></canvas></div></div><div class="text unilateral"><table width="50%" align="center" class="hiddentable"><tr><td><b>Seite</b></td><td><b>Aufrufe</b></td></tr>';
    $zaehle = array_count_values($meistgenutzt);
	foreach($zaehle AS $key=>$value) {
		echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
	}
echo '</tr></table></div><p><img src="img/info.png" width="40px"><br>Sie sehen eine Übersicht, über alle Seiten und wie oft Sie aufgerufen werden.</p><script>barchart(document.getElementById("sites"),'.json_encode(array_slice(array_values($zaehle),0,10)).','.json_encode(array_keys($zaehle)).')</script>';
}
if($_GET['view']=="suchmaschinen") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Suchmaschinenanalyse - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
echo '<h1 id="suchmaschinen">Top verwendete Suchmaschinen und Suchbegriffe</h1><p><canvas id="keyword_graph" width="1150" height="250" style="width:1150px;height:250px;"></canvas></p><table align="center"><tr><td><b>Suchmaschine</b></td><td><b>Angezeigter Titel</b></td><td><b>Angezeigte Beschreibung</b></td><td><b>Aufgerufene Seite</b></td><td><b>Suche</b></td><td><b>Aufrufe</b></td></tr>';
    $Search_Engine_zaehle = array_count_values($Search_Engines);
    arsort($Search_Engine_zaehle);
    $Search_Engine_site = str_replace("_ ",", ",print_r($Search_Engine_zaehle, true));
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('(', '', $Search_Engine_site);
    $Search_Engine_site = str_replace(')', '</td></tr>', $Search_Engine_site);
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('[', '<tr><td>', $Search_Engine_site);
    $Search_Engine_site = str_replace(']', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('=>', '</td> <td>', $Search_Engine_site);
    echo str_replace('@opolyticswhitespace', ' ', $Search_Engine_site);

echo '</tr></table></div><p><canvas id="origin_graph"></canvas> <canvas id="search_engines_graph"></canvas></p><p><img src="img/info.png" width="40px"><br>Sie sehen eine Übersicht über die beliebtesten Suchbegriffe und Suchmaschinen</p>.';

// Contextmenu
include("contextmenu.php");

echo '<script>
var google = '.preg_replace('/^$/', '0', $google).';
var bing = '.preg_replace('/^$/', '0', $bing).';
var ask = '.preg_replace('/^$/', '0', $ask).';
var yahoo = '.preg_replace('/^$/', '0', $yahoo).';
var duckduckgo = '.preg_replace('/^$/', '0', $duckduckgo).';
suchmaschinen = new Array(100 / (google + bing + ask + yahoo + duckduckgo) * google, 100 / (google + bing + ask + yahoo + duckduckgo) * bing, 100 / (google + bing + ask + yahoo + duckduckgo) * ask, 100 / (google + bing + ask + yahoo + duckduckgo) * yahoo, 100 / (google + bing + ask + yahoo + duckduckgo) * duckduckgo);
  canvas = document.getElementById("search_engines_graph");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "black";
    ctx.fillText("10", 2, 150-10);
    ctx.fillText("20", 2, 150-20);
    ctx.fillText("30", 2, 150-30);
    ctx.fillText("40", 2, 150-40);
    ctx.fillText("50", 2, 150-50);
    ctx.fillText("60", 2, 150-60);
    ctx.fillText("70", 2, 150-70);
    ctx.fillText("80", 2, 150-80);
    ctx.fillText("90", 2, 150-90);
    ctx.fillText("100", 1, 150-100);
    ctx.fillText("110", 1, 150-110);
    ctx.fillText("120", 1, 150-120);
    ctx.fillText("130", 1, 150-130);
    ctx.fillText("140", 1, 150-140);

    ctx.fillStyle = "red";
    ctx.fillText("Google", 245, 10);
    ctx.fillStyle = "green";
    ctx.fillText("Bing", 245, 20);
    ctx.fillStyle = "blue";
    ctx.fillText("Ask.com", 245, 30);
    ctx.fillStyle = "black";
    ctx.fillText("Yahoo", 245, 40);
    ctx.fillStyle = "yellow";
    ctx.fillText("DuckDuckGo", 245, 50);

    ctx.fillStyle = "red";
    ctx.fillRect(50, 150-suchmaschinen[0], 20, suchmaschinen[0]);
    ctx.fillStyle = "green";
    ctx.fillRect(75, 150-suchmaschinen[1], 20, suchmaschinen[1]);
    ctx.fillStyle = "blue";
    ctx.fillRect(100, 150-suchmaschinen[2], 20, suchmaschinen[2]);
    ctx.fillStyle = "black";
    ctx.fillRect(125, 150-suchmaschinen[3], 20, suchmaschinen[3]);
    ctx.fillStyle = "yellow";
    ctx.fillRect(150, 150-suchmaschinen[4], 20, suchmaschinen[4]);

    ctx.fillStyle = "black";
    ctx.fillRect(20, 150-100, 220, 1);
  }
  canvas = document.getElementById("origin_graph");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "red";
    ctx.fillText("Suchmaschinen", 215, 10);
    ctx.fillStyle = "green";
    ctx.fillText("Andere Herkünfte", 215, 20);
    ctx.fillStyle = "black";
    ctx.fillText("10", 2, 150-10);
    ctx.fillText("20", 2, 150-20);
    ctx.fillText("30", 2, 150-30);
    ctx.fillText("40", 2, 150-40);
    ctx.fillText("50", 2, 150-50);
    ctx.fillText("60", 2, 150-60);
    ctx.fillText("70", 2, 150-70);
    ctx.fillText("80", 2, 150-80);
    ctx.fillText("90", 2, 150-90);
    ctx.fillText("100", 1, 150-100);
    ctx.fillText("110", 1, 150-110);
    ctx.fillText("120", 1, 150-120);
    ctx.fillText("130", 1, 150-130);
    ctx.fillText("140", 1, 150-140);
    ctx.fillRect(20, 150-100, 220, 1);
    ctx.fillStyle = "red";
    ctx.fillRect(50, 150 - 100 / '.count($file).' * (google + bing + ask + yahoo + duckduckgo), 20, 100 / '.count($file).' * (google + bing + ask + yahoo + duckduckgo));
    ctx.fillStyle = "green";
    ctx.fillRect(75, 150 - 100 / '.count($file).' * ('.count($file).' - (google + bing + ask + yahoo + duckduckgo)), 20, 100 / '.count($file).' * ('.count($file).' - (google + bing + ask + yahoo + duckduckgo)));

}
  canvas = document.getElementById("keyword_graph");
function draw() {
	barchart(canvas,'.json_encode(array_values($externe_suchen)).','.json_encode(array_keys($externe_suchen)).');
}
draw();
canvas.addEventListener("mouseover", show, true);
canvas.addEventListener("mouseout", hide, true);
function show() {
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "black";
    ctx.fillText(anzahl[0],52,200-anzahl[0]-10);
    ctx.fillText(anzahl[1],252,200-anzahl[1]-10);
    ctx.fillText(anzahl[2],452,200-anzahl[2]-10);
    ctx.fillText(anzahl[3],652,200-anzahl[3]-10);
    ctx.fillText(anzahl[4],852,200-anzahl[4]-10);
    ctx.fillText(anzahl[5],1052,200-anzahl[5]-10);
}
}
function hide() {
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    ctx.clearRect(0,0,1150,250);
    draw();
}
}
</script>';
}

if($_GET['view']=="nutzerzahlen") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Nutzerzahlen - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
echo '<h1 id="nutzerzahlen">Entwicklungen in der Anzahl Nutzer</h1><table><tr><td><b>Einzelne Nutzer</b></td><td><b>Einzelne Seitenansichten</b></td><td><b>Durchschnittliche Aufrufe pro Nutzer</b></td></tr><tr><td>'.$nutzer.'</td><td>'.count($file).'</td><td>'.$aufrufe_pro_nutzer.'</td></tr></table><br><table width="100%"><tr><td><h5>Letzte 10 Tage</h5></td></tr><tr><td><canvas id="visitor_day_graph" width="1200" height="300" style="width: 95%; height: 300px;">Ihr Browser unterstützt das Canvas Element offenbar nicht, bitte checken Sie die Kompatibilität.</canvas></td></tr><tr><td>Übersicht der letzten 10 Tage<br><br>';
if($days[9] < $days[0]) {
echo '<font color="green">Bravo! Die Anzahl Nutzer hat offenbar zugenommen.</font>';
}
if($days[9] > $days[0]) {
echo '<font color="red">Oh nein! Die Anzahl Nutzer hat offenbar abgenommen.</font>';
}
if($days[9] == $days[0]) {
echo 'Nicht so schlimm, Sie haben keine Nutzer gewonnen, aber auch keine verloren.';
}
echo '</td></tr><tr><td><h5>Dieses Jahr</h5></td></tr><tr><td><canvas id="visitor_months_graph" width="1200" height="300" style="width: 95%; height: 300px;">Ihr Browser unterstützt das Canvas Element offenbar nicht, bitte checken Sie die Kompatibilität.</canvas></td></tr><tr><td>Übersicht über die Entwicklungen dieses Jahr.<br><br>';
if($months[0] < $months[date("m", $timestamp)-1]) {
echo '<font color="green">Bravo! Die Anzahl Nutzer hat offenbar zugenommen.</font>';
}
if($months[0] > $months[date("m", $timestamp)-1]) {
echo '<font color="red">Oh nein! Die Anzahl Nutzer hat offenbar abgenommen.</font>';
}
if($months[date("m", $timestamp)-1] == $months[0]) {
echo 'Nicht so schlimm, Sie haben keine Nutzer gewonnen, aber auch keine verloren.';
}
echo '</td></tr><tr><td><h5>Letzte Jahre</h5></td></tr><tr><td><canvas id="visitor_years_graph" width="1200" height="300" style="width: 95%; height: 300px;">Ihr Browser unterstützt das Canvas Element offenbar nicht, bitte checken Sie die Kompatibilität.</canvas></td></tr><tr><td>Übersicht über die letzten Jahre.<br><br>';
if($years[4] < $years[0]) {
echo '<font color="green">Bravo! Die Anzahl Nutzer hat offenbar zugenommen.</font>';
}
if($years[4] > $years[0]) {
echo '<font color="red">Oh nein! Die Anzahl Nutzer hat offenbar abgenommen.</font>';
}
if($years[0] == $years[4]) {
echo 'Nicht so schlimm, Sie haben keine Nutzer gewonnen, aber auch keine verloren.';
}
echo '</td></tr></table>';

// Contextmenu
include("contextmenu.php");

echo '<script type="text/javascript">
var monate = new Array('.implode(', ', $months).');
var jahre = new Array('.implode(', ', array_slice($years,0,4)).');
var tage = new Array('.implode(', ', array_reverse(array_slice($days,0,10))).');
barchart(document.getElementById("visitor_day_graph"),tage,["9 Tage","8 Tage","1 Woche","6 Tage","5 Tage","4 Tage","3 Tage","Vorgestern","Gestern","Heute"]);
barchart(document.getElementById("visitor_months_graph"),monate,["Januar","Februar","März","April","Mai","Juni","Juli","August","September","November","Dezember"]);
barchart(document.getElementById("visitor_years_graph"),jahre.reverse(),'.json_encode(array(date("Y",time()-(3*31536000)),date("Y",time()-(2*31536000)),date("Y",time()-31536000),date("Y",time()))).');
</script>';
}
if($_GET['view']=="sprachen") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Sprachen - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
echo '<h1 id="sprachen">Sprachen</h1><p><canvas id="visitor_big_language_graph" width="1150" height="250" style="width: 1150px; height: 250px;"></canvas></p><table><thead><tr><td>Sprache</td><td>Nutzer mit dieser Sprache</td></tr></thead><tbody>';
    $language_zaehle = array_count_values($language);
    arsort($language_zaehle);
    foreach($language_zaehle AS $key=>$value) {
		echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
	}
echo '</tbody></table>';

// Contextmenu
include("contextmenu.php");

echo '<script>
barchart(document.getElementById("visitor_big_language_graph"),'.json_encode(array_values($language_zaehle)).','.json_encode(array_keys($language_zaehle)).');
</script>';
}
if($_GET['view']=="interne_suchen") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Interne Suchen - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
echo '<h1>Interne Suchen <a href="?view=konfiguriere_interne_suche"><img src="img/settings.png" height="22"></a></h1><p><canvas id="visitor_search_graph" width="1150" height="300" style="width: 1150px; height: 300px;"></canvas><br></p><h3 id="oftgesucht">Oft auf Ihrer Seite gesucht</h3><table><thead><tr><td>Suche</td><td>Häufigkeit</td></tr></thead><tbody>';
$zaehle = array_count_values($suchen);
foreach($zaehle AS $key=>$value) {
	echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
echo '</tbody></table>';

include("contextmenu.php");

echo '<script>
barchart(document.getElementById("visitor_search_graph"),'.json_encode(array_values($zaehle)).','.json_encode(array_keys($zaehle)).');
</script>
';
if($config[22]=='false') {
echo '<script>
popup("<h1>Interne Suche konfigurieren</h1>Oh nein! Die interne Suche für Ihre Seite ist derzeit noch nicht konfiguriert. Jede Seite ist etwas ganz eigenes, deshalb benötigen wir von Ihnen nur einige wenige Angaben, um die Suche auf Ihrer Seite zu analysieren, damit Sie nicht nur wissen, was Leute auf Ihrer Seite suchen. Wir bitten Sie daher, die Suche nun zu konfiguerieren um den Bericht anschliessend einsehen zu können. Sie können die Konfiguration anschliessend immer noch ändern, sofern sich die Suche ändern sollte.<br><br><input type=\'button\' onclick=\'configure();\' value=\'Jetzt konfigurieren\'>",screen.availWidth/2-400,screen.availHeight/2-150,800,300);
document.getElementById("popup").style.paddingLeft = "25px";
document.getElementById("popup").style.paddingRight = "25px";
function configure() {
window.location.href="detail.php?view=konfiguriere_interne_suche";
}
</script>';
}
}
if($_GET['view']=="nutzerlog") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Nutzerlog - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");

echo '<h1 id="letzteaufrufe">Letzte Aufrufe</h1>';
echo '<table class="aufrufe"><thead><tr class="top"><td>Zeit</td><td>Seite</td><td>Nutzungszeit (Sekunden)</td><td>Useragent</td><td>Sprache</td><td>System</td><td>IP-Adresse</td><td>Ausrichtung</td><td>Plugins</td></tr></thead><tbody>';
foreach($file AS $log) {
$log = str_replace('https://', '', $log);
$log = str_replace('http://', '', $log);
$log = str_replace('www.', '', $log);
$log = explode(', ', $log);
echo '<tr><td>'.$log[9].'</td><td>'.$log[0].'</td><td>'.$log[8].'</td><td>'.$log[4].'</td><td>'.$log[5].'</td><td>'.$log[6].'</td><td>'.$log[1].'</td><td>'.$log[3].'</td><td>'.str_replace('_', ', ', $log[7]).'</td></tr>';
}
echo '</tbody></table></div>';
}
if($_GET['view']=="kampagnen ziele") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Kampagnen - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");

$campaigns = file("campaigns.txt");
$campaigns = array_reverse($campaigns);

if(!isset($_GET['campaign'])) {
echo '<h1>Kampagnen & Ziele</h1><center><table style="text-align:center;"><thead><td>#</td><td>Kampagne/Ziel</td><td>Beschreibung</td><td>Start</td><td>Ende</td><td>Aktionen</td></thead>
<tbody>';
if(!empty($campaigns)) {
$counter = 1;
foreach($campaigns AS $campaign) {
$campaign = str_replace('_ ',', ',explode(', ', $campaign));
echo '<tr><td>'.$counter.'</td><td><a href="?view=kampagnen+ziele&campaign='.$campaign[0].'">'.$campaign[0].'</a></td><td>'.$campaign[1].'</td><td>'.$campaign[2].'</td><td>'.$campaign[3].'</td><td><a href="?view=kampagnen+ziele&delete='.$campaign[0].'"><img src="img/minus.png" width="15"> Löschen</a></td></tr>';
$counter++;
}
echo '<tr><td></td><td><a href="?view=kampagnen+ziele&campaign=new"><img src="img/plus.png" width="15"><i> Neue Kampagne/Ziel</i></a></td><td></td><td></td><td></td><td></td></tr>';
}
if(empty($campaigns)) {
echo '<tr><td>-</td><td>Keine Kampagnen</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr style="background-color:#E2DBDB"><td></td><td><a href="?view=kampagnen+ziele&campaign=new"><img src="img/plus.png" width="15"> Neue Kampagne/Ziel</a></td><td></td><td></td><td></td><td></td></tr>';
}
echo '</tbody></table></center>
<style>
thead {
font-size: 15pt;
}
tr {
height: 25px;
}
</style>';
}
if($_GET['campaign']=="new") {
echo '<h1>Neue Kampagne</h1><center><form action="?view=kampagnen+ziele&campaign=safe_new" method="post" style="width:50%;text-align:center;"><h2 style="border:none;box-shadow:none;padding:0px;margin:0px;">Grundlegend</h2><table style="border:none;box-shadow:none;">
<tr><td><b>Name</b></td><td><input type="text" name="name"></td></tr>
<tr><td><b>Beschreibung</b></td><td><textarea name="description"></textarea></td></tr>
<tr><td><b>Start</b></td><td><input type="date" name="start"></td></tr>
<tr><td><b>Ende (optional)</b></td><td><input type="date" name="end"></td></tr>
<tr><td><b>Priorität</b></td><td><select name="priority"><option>Tief</option><option>Mittel</option><option>Hoch</option></select></td></tr>
</table>
<h2 style="border:none;box-shadow:none;padding:0px;margin:0px;">Erwartungen</h2>
<table style="border:none;box-shadow:none;">
<tr><td><b>Erwartete Steigerung um (%)</b></td><td><input type="number" name="increase" value="0">%</td></tr>
</table>
<input type="submit" value="Speichern"></form></center>';
}
if($_GET['campaign']=="safe_new") {
$counter = 0;
$campaign = array(str_replace(', ','_ ',$_POST['name']),str_replace(', ','_ ',$_POST['description']),implode('.', array_reverse(explode('.', str_replace('-', '.', $_POST['start'])))),implode('.', array_reverse(explode('.', str_replace('-', '.', $_POST['end'])))),$_POST['priority'],$_POST['increase']);
if(!empty($campaigns)) {
file_put_contents("campaigns.txt", "
".implode(', ', $campaign), FILE_APPEND);
}
if(empty($campaigns)) {
file_put_contents("campaigns.txt", implode(', ', $campaign), FILE_APPEND);
}
echo '<h1>Gespeichert.</h1><p><b>Super.</b> Ihre Kampagne "<b>'.$_POST['name'].'</b>" wurde soeben gespeichert.</p><p><a href="?view=kampagnen+ziele">Zurück zu allen Kampagnen</a>';
}
if(isset($_GET['delete'])) {
$new_campaigns = array();
foreach($campaigns AS $campaign) {
$name = str_replace('_ ',', ',explode(', ', $campaign))[0];
if($name!=$_GET['delete']) {
array_push($new_campaigns,$campaign);
}
}
file_put_contents("campaigns.txt", implode("\r\n", $new_campaigns));
echo '<script>window.location.href="?view=kampagnen+ziele";</script>';
}
if(isset($_GET['campaign']) AND $_GET['campaign']!="new") {
foreach($campaigns AS $campaign) {
$name = explode(', ', $campaign)[0];
$campaign = explode(', ', $campaign);
if($name==$_GET['campaign']) {
$difference = date_diff(date_create(str_replace('.','-',$campaign[2])), date_create(str_replace('.','-',$campaign[3])));
echo '<h1>Kampagne: '.$name.'</h1><p>Diese Kampagne startet am <i>'.$campaign[2].'</i> und endet am <i>'.$campaign[3].'</i></p>.<table><thead><td>Erwartung</td><td>Realität</td></thead><tbody><tr><td style="border-right:1px solid black;"><canvas id="expectation" width="600" height="300" style="width:600px;height:300px"></canvas></td><td style="border-left:1px solid black;"><canvas id="reality" width="600" height="300" style="width:600px;height:300px"></td></tr></tbody></table>';
if(intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100) >= $campaign[5]) {
echo '<script>
  canvas = document.getElementById("expectation");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    var difference = '.str_replace('+','',$difference->format('%R%a')).';
    ctx.fillStyle = "#DBD9D9";
    ctx.font = "12px Arial";
var counter = 1;
for (var i=0; i < parseFloat(difference-1); i++) {
    ctx.fillRect(600/difference*counter,10,1,240);
    counter++;
}
    ctx.fillRect(1,10,1,240);
    ctx.fillRect(599,10,1,240);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 1).toString().length * 8 + 4),10,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.75).toString().length * 8 + 4),70,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.5).toString().length * 8 + 4),130,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.25).toString().length * 8 + 4),190,1150,1);
    ctx.fillStyle = "grey";
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) - 100).', 2, 15);
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.75, 2, 75);
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' / 2, 2, 135);
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.25, 2, 195);
    ctx.font = "15px Arial";
    ctx.fillStyle = "black";
    ctx.fillText("'.return_if_future($campaign[2]).'",20,280);
    ctx.fillText("'.return_if_future($campaign[3]).'",510,280);
    ctx.fillStyle = "grey";
    ctx.fillRect(0,250,600,1);
    ctx.strokeStyle = "red";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600, Math.round(240-'.preg_replace('/-[1-9]*/','0',intval(240 / (100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) - 100) * $campaign[5])).' + 10));
    ctx.stroke();
    ctx.strokeStyle = "#DFDEDE";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600,10);
    ctx.stroke();
}
  canvas = document.getElementById("reality");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    var difference = '.str_replace('+','',$difference->format('%R%a')).';
    ctx.fillStyle = "#DBD9D9";
    ctx.font = "12px Arial";
var counter = 1;
for (var i=0; i < parseFloat(difference-1); i++) {
    ctx.fillRect(600/difference*counter,10,1,240);
    counter++;
}
    ctx.fillRect(1,10,1,240);
    ctx.fillRect(599,10,1,240);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 1).toString().length * 8 + 4),10,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.75).toString().length * 8 + 4),70,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.5).toString().length * 8 + 4),130,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.25).toString().length * 8 + 4),190,1150,1);
    ctx.fillStyle = "grey";
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) - 100).', 2, 15);
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.75, 2, 75);
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' / 2, 2, 135);
    ctx.fillText('.intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100).' * 0.25, 2, 195);
    ctx.font = "15px Arial";
    ctx.fillStyle = "black";
    ctx.fillText("'.return_if_future($campaign[2]).'",20,280);
    ctx.fillText("'.return_if_future($campaign[3]).'",510,280);
    ctx.fillStyle = "grey";
    ctx.fillRect(0,250,600,1);
    ctx.strokeStyle = "green";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600,10);
    ctx.stroke();
    ctx.strokeStyle = "#DFDEDE";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600, Math.round(240-'.preg_replace('/-[1-9]*/','0',intval(240 / (100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) - 100) * $campaign[5])).' + 10));
    ctx.stroke();
}
</script>
<p>Nicht so bescheiden, Sie haben sich unterschätzt!</p>';
}
else if(intval(100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) -100) < intval($campaign[5])) {
echo '<script>
  canvas = document.getElementById("expectation");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    var difference = '.str_replace('+','',$difference->format('%R%a')).';
    ctx.fillStyle = "#DBD9D9";
    ctx.font = "12px Arial";
var counter = 1;
for (var i=0; i < parseFloat(difference-1); i++) {
    ctx.fillRect(600/difference*counter,10,1,240);
    counter++;
}
    ctx.fillRect(1,10,1,240);
    ctx.fillRect(599,10,1,240);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 1).toString().length * 8 + 4),10,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 0.75).toString().length * 8 + 4),70,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 0.5).toString().length * 8 + 4),130,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 0.25).toString().length * 8 + 4),190,1150,1);
    ctx.fillStyle = "grey";
    ctx.fillText('.$campaign[5].', 2, 15);
    ctx.fillText('.$campaign[5].' * 0.75, 2, 75);
    ctx.fillText('.$campaign[5].' / 2, 2, 135);
    ctx.fillText('.$campaign[5].' * 0.25, 2, 195);
    ctx.font = "15px Arial";
    ctx.fillStyle = "black";
    ctx.fillText("'.return_if_future($campaign[2]).'",20,280);
    ctx.fillText("'.return_if_future($campaign[3]).'",510,280);
    ctx.fillStyle = "grey";
    ctx.fillRect(0,250,600,1);
    ctx.strokeStyle = "green";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600,10);
    ctx.stroke();
    ctx.strokeStyle = "#DFDEDE";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600,Math.round(240-'.preg_replace('/-[1-9]*/','0',intval(240 / $campaign[5] * (100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) - 100))).' + 10));
    ctx.stroke();
}
  canvas = document.getElementById("reality");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    var difference = '.str_replace('+','',$difference->format('%R%a')).';
    ctx.fillStyle = "#DBD9D9";
    ctx.font = "12px Arial";
var counter = 1;
for (var i=0; i < parseFloat(difference-1); i++) {
    ctx.fillRect(600/difference*counter,10,1,240);
    counter++;
}
    ctx.fillRect(1,10,1,240);
    ctx.fillRect(599,10,1,240);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 1).toString().length * 8 + 4),10,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 0.75).toString().length * 8 + 4),70,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 0.5).toString().length * 8 + 4),130,1150,1);
    ctx.fillRect(parseFloat(parseFloat('.$campaign[5].' * 0.25).toString().length * 8 + 4),190,1150,1);
    ctx.fillStyle = "grey";
    ctx.fillText('.$campaign[5].', 2, 15);
    ctx.fillText('.$campaign[5].' * 0.75, 2, 75);
    ctx.fillText('.$campaign[5].' / 2, 2, 135);
    ctx.fillText('.$campaign[5].' * 0.25, 2, 195);
    ctx.font = "15px Arial";
    ctx.fillStyle = "black";
    ctx.fillText("'.return_if_future($campaign[2]).'",20,280);
    ctx.fillText("'.return_if_future($campaign[3]).'",510,280);
    ctx.fillStyle = "grey";
    ctx.fillRect(0,250,600,1);
    ctx.strokeStyle = "#DFDEDE";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600,10);
    ctx.stroke();
    ctx.strokeStyle = "red";
    ctx.beginPath();
    ctx.moveTo(0,250);
    ctx.lineTo(600,Math.round(240-'.preg_replace('/-[1-9]*/','0',intval(240 / $campaign[5] * (100 / visitors_per_day($campaign[2]) * visitors_per_day($campaign[3]) - 100))).' + 10));
    ctx.stroke();
}
</script>
<p>Schade, Ihre Ziele wurden noch nicht erreicht.</p>';
}
echo '<table><thead><tr><td>Vergleich</td><td>Erwartung</td><td>Realität</td></tr></thead><tbody><tr><td>Steigerung um:</td><td>'.$campaign[5].'%</td><td>'.round(increase(visitors_per_day($campaign[2]),visitors_per_day($campaign[3])),1).'%</td></tr><tr><td>Zusätzliche Besucher:</td><td>'.intval(visitors_per_day($campaign[2]) * ($campaign[5] / 100)).'</td><td>'.intval(visitors_per_day($campaign[3]) - visitors_per_day($campaign[2])).'</td></tr></tbody></table><br><table style="padding:0px;border:none;background-color:rgba(1,1,1,0);box-shadow:none;"><td style="width:50%"><table align="center"><tr><td><b>Suchmaschine</b></td><td><b>Besuche</b></td></tr>';
    $zaehle = searchengines_day($campaign[3]);
    arsort($zaehle);
    $search = print_r($zaehle, true);
    $search = str_replace('Array', '', $search);
    $search = str_replace('(', '', $search);
    $search = str_replace(')', '</td></tr>', $search);
    $search = str_replace('Array', '', $search);
    $search = str_replace('[', '<tr><td>', $search);
    $search = str_replace(']', '', $search);
    $search = str_replace('=>', '</td><td>', $search);
    echo $search;
echo '</tr></table></td><td style="width:50%"><table><tr><td><b>Land</b></td><td><b>Aufrufe</b></td></tr>';
    $zaehle = countries_day($campaign[3]);
    arsort($zaehle);
    $search = print_r($zaehle, true);
    $search = str_replace('Array', '', $search);
    $search = str_replace('(', '', $search);
    $search = str_replace(')', '</td></tr>', $search);
    $search = str_replace('Array', '', $search);
    $search = str_replace('[', '<tr><td>', $search);
    $search = str_replace(']', '', $search);
    $search = str_replace('=>', '</td><td>', $search);
    echo $search;
echo '</table></td></table><br><table><tr><td><b>Suchmaschine</b></td><td><b>Angezeigter Titel</b></td><td><b>Angezeigte Beschreibung</b></td><td><b>Aufgerufene Seite</b></td><td><b>Suche</b></td><td><b>Aufrufe</b></td></tr>';
//    $Search_Engine_array = explode(' ', keywords_day($campaign[3]));
    $Search_Engine_zaehle = array_count_values(keywords_day($campaign[3]));
    arsort($Search_Engine_zaehle);
    $Search_Engine_site = str_replace("_ ",", ",print_r($Search_Engine_zaehle, true));
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('(', '', $Search_Engine_site);
    $Search_Engine_site = str_replace(')', '</td></tr>', $Search_Engine_site);
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('[', '<tr><td>', $Search_Engine_site);
    $Search_Engine_site = str_replace(']', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('=>', '</td> <td>', $Search_Engine_site);
    echo str_replace('@opolyticswhitespace', ' ', $Search_Engine_site);
echo '</tr></table></div>';
}
}
}
include("contextmenu.php");
}
if($_GET['view']=="tag") {
if(isset($_GET['day'])) {
include("countrydatabase.php");
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Detailansicht vom '.$_GET['day'].' - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");
// Include the menubar
include("menu.php");
$hours = visitors_at_hour(date("d.m.Y ", strtotime($_GET['day'])));
$referrers_yesterday = referrers_at_day(date("d.m.Y",strtotime($_GET['day'])-86400));
$referrers = referrers_at_day($_GET['day']);
$countries_yesterday = countries_day(date("d.m.Y",strtotime($_GET['day'])-86400));
$keywords = keywords_day($_GET['day']);
$hours_yesterday = visitors_at_hour(date("d.m.Y",strtotime($_GET['day'])-86400));
echo '<h1>Tages-Detailansicht vom '.$_GET['day'].'</h1><p>Die höchste Anzahl an Nutzern ('.max($hours).') wurde an diesem Tag von '.array_keys($hours,max($hours))[0].'-'.intval(array_keys($hours,max($hours))[0] + 1).' Uhr zum ersten Mal erreicht.</p><p><canvas width="1275" height="300" id="visitor_hours_graph" style="width:1275px;height:300px;"></canvas></p><h3>Vergleich zum Tag davor</h3>
<script>
hours = new Array('.implode(',',visitors_at_hour(date("d.m.Y ", strtotime($_GET['day'])))).');
barchart(document.getElementById("visitor_hours_graph"),hours,["0-1","1-2","2-3","3-4","4-5","5-6","6-7","7-8","8-9","9-10","10-11","11-12","12-13","13-14","14-15","15-16","16-17","17-18","18-19","19-20","20-21","21-22","22-23","23-24"]);
</script><table class="vergleich"><thead><td>Vergleich</td><td>Gestern</td><td>Heute</td></thead><tbody><tr><td>Anzahl Besucher</td><td>'.visitors_per_day(date("d.m.Y",strtotime($_GET['day'])-86400)).'</td><td>'.visitors_per_day($_GET['day']).'</td></tr><tr><td>Höchste Anzahl Nutzer zum ersten Mal erreicht</td><td>'.array_search(max($hours_yesterday), $hours_yesterday).'</td><td>'.array_search(max($hours), $hours).'</td></tr><td></tr><tr><td>Populärster Referrer</td><td>'.array_search(max($referrers_yesterday),$referrers_yesterday).'</td><td>'.array_search(max(referrers_at_day($_GET['day'])),referrers_at_day($_GET['day'])).'</td></tr><tr><td>Populärstes Herkunftsland</td><td>'.array_search(max($countries_yesterday),$countries_yesterday).'</td><td>'.array_search(max(countries_day($_GET['day'])),countries_day($_GET['day'])).'</td></tr></tbody></table><br><h3>An diesem Tag gesucht</h3><table><tr><td><b>Suchmaschine</b></td><td><b>Angezeigter Titel</b></td><td><b>Angezeigte Beschreibung</b></td><td><b>Aufgerufene Seite</b></td><td><b>Suche</b></td><td><b>Aufrufe</b></td></tr>';
    $Search_Engine_zaehle = array_count_values($keywords);
    arsort($Search_Engine_zaehle);
    $Search_Engine_site = print_r($Search_Engine_zaehle, true);
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('(', '', $Search_Engine_site);
    $Search_Engine_site = str_replace(')', '</td></tr>', $Search_Engine_site);
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('[', '<tr><td>', $Search_Engine_site);
    $Search_Engine_site = str_replace(']', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('=>', '</td> <td>', $Search_Engine_site);
    $Search_Engine_site = substr($Search_Engine_site, 0, -30); 
    echo str_replace('@opolyticswhitespace', ' ', $Search_Engine_site);
echo '</td></tr></table><h3>Besucherkarte</h3><div class="text" style="overflow:auto"><canvas id="visitor_world_map" width="800" height="400" style="width:70%px;height:400px;float:left"></canvas><table style="margin:0px;box-shadow:none;max-height:300px;width:30%"><thead><tr><td>Land</td><td>Aufrufe</td></tr></thead><tbody>';
    $zaehle = countries_day($_GET['day']);
    arsort($zaehle);
	foreach($zaehle AS $key=>$value) {
		echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
	}
echo '</tbody></table><table style="margin:0px;box-shadow:none;max-height:300px;width:30%"><thead><tr><td>Region</td><td>Aufrufe</td></tr></thead><tbody>';
    $zaehle = regions_day($_GET['day']);
	foreach($zaehle AS $key=>$value) {
		echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
	}
echo '</tbody></table></div><h3>Weitere Informationen</h3><table><tr><td><b>Suchmaschine</b></td><td><b>Angezeigter Titel</b></td><td><b>Angezeigte Beschreibung</b></td><td><b>Aufgerufene Seite</b></td><td><b>Suche</b></td><td><b>Aufrufe</b></td></tr>';
    $Search_Engine_array = keywords_day($_GET['day']);
    $Search_Engine_zaehle = array_count_values($Search_Engine_array);
    arsort($Search_Engine_zaehle);
    $Search_Engine_site = str_replace('_ ',', ',print_r($Search_Engine_zaehle, true));
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('(', '', $Search_Engine_site);
    $Search_Engine_site = str_replace(')', '</td></tr>', $Search_Engine_site);
    $Search_Engine_site = str_replace('Array', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('[', '<tr><td>', $Search_Engine_site);
    $Search_Engine_site = str_replace(']', '', $Search_Engine_site);
    $Search_Engine_site = str_replace('=>', '</td> <td>', $Search_Engine_site);
    echo str_replace('@opolyticswhitespace', ' ', $Search_Engine_site);
echo '</tr></table><br><table align="center" class="unilateral" style="float:left"><thead><tr><td>Suchmaschine</td><td>Besuche</td></tr></thead><tbody>';
    $zaehle = searchengines_day($_GET['day']);
	foreach($zaehle AS $key=>$value) {
		echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
	}
echo '</tbody></table><table class="unilateral" style="float:right"><thead><tr><td>Land</td><td>Aufrufe</td></tr></thead><tbody>';
    $zaehle = countries_day($_GET['day']);
    arsort($zaehle);
    foreach($zaehle AS $key=>$value) {
		echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
	}
echo '</tbody></table><br style="clear:both">
<script>
var continents = '.json_encode($continents).';
var image = new Image();
image.src = "img/world-map.png";
function draw_map() {
  canvas = document.getElementById("visitor_world_map");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
ctx.clearRect(0,0,800,400);
ctx.drawImage(image,0,0,800,400);
    ctx.font = "15px Arial";
    ctx.fillStyle = "grey";
    ctx.fillText(continents["Europe"],390,85);
    ctx.fillText(continents["North America"],160,105);
    ctx.fillText(continents["South America"],240,270);
    ctx.fillText(continents["Asia"],525,100);
    ctx.fillText(continents["Africa"],425,200);
    ctx.fillText(continents["Australia and Oceania"],660,270);
}
}
function info_map() {
  canvas = document.getElementById("visitor_world_map");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    ctx.font = "10px Arial";
    ctx.fillStyle = "grey";
    ctx.fillText("Europa",380,70);
    ctx.fillText("Nordamerika",145,90);
    ctx.fillText("Südamerika",230,253);
    ctx.fillText("Afrika",415,185);
    ctx.fillText("Asien",515,85);
    ctx.fillText("Australien und Ozeanien",620,255);
}
}
document.getElementById("visitor_world_map").addEventListener("mouseover",info_map,true);
document.getElementById("visitor_world_map").addEventListener("mouseout",draw_map,true);
image.onload = function() {draw_map();};
</script>';
include("contextmenu.php");
}
if(!isset($_GET['day'])) {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Tages Detail-Ansichten - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");
// Include the menubar
include("menu.php");
echo '<h1>Tages Detailansichten</h1><form action="?view=tag&" method="get" id="form">
<input type="hidden" name="view" value="tag"><input type="hidden" id="day" name="day" value="">Welchen Tag möchten Sie ansehen?<br><br><input type="date" id="date"><br><input type="button" onclick="send()" value="Ansehen">
</form><script>
function send() {
document.getElementById("day").value = document.getElementById("date").value.split("-").reverse().join(".");
document.getElementById("form").submit();
}
</script>';
include("contextmenu.php");
}
}
if($_GET['view']=="optimizer") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Seite optimieren - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");
// Include the menubar
include("menu.php");
if(!isset($_GET['site'])) {
echo '<h1>Seite optimieren</h1><p>Willkommen beim Optimierer von Opolytics. Opolytics kann Ihnen nicht nur helfen, Ihnen zu zeigen wie erfolgreich Ihre Seite ist, sondern Ihnen auch helfen damit erfolgreicher zu werden.</p><form action="?" method="get">
Welche Seite soll untersucht und optimiert werden?<br><input type="hidden" name="view" value="optimizer"><b>Seite</b><br><input type="url" name="site" value="http://"><br><b>Keyword</b><br><input type="text" name="keyword"><!--<br><a href="?view=optimizer&site=http://'.$_SERVER['SERVER_NAME'].'">Startseite untersuchen</a>--><br><input type="submit" value="Testen">
</form>';
}
if(isset($_GET['site'])) {
if(filter_var($_GET['site'], FILTER_VALIDATE_URL)===false) {
die("<h1>Bösartiger Dateizugriff oder fehlerhafte Eingabe</h1><p>Bei der angeforderten Datei handelt es sich um eine interne Datei oder eine ungültige Adresse.</p><p>Aus Sicherheitsgründen ist das auslesen interner Dateien nicht möglich. Wenn Sie eine intern gespeicherte Seite ansehen möchten können Sie bspw. eine FTP-Software verwenden. Sofern Sie die interne Seite optimieren möchten, können Sie das tun. Geben Sie dazu einfach die URL ein, durch die Sie auch vom Browser aus erreichbar ist.</p><h2>Wieso sind interne Zugriffe verboten?</h2><p>Ganz einfach. Interne Dateien enthalten oft sensible Daten, die von Opolytics ungefiltert erreicht werden können. Opolytics würde nie die Sicherheit der Nutzer gefährden wollen und blockiert das ausgeben dieser Daten.</p><p>Danke für Ihr Verständnis</p>");
}
$options = array(
    'http' => array(
        'timeout' => 10,
        'user_agent' => "OpolyticsOptimizerBot 1.0 (@".$_SERVER['SERVER_NAME'].", if you have got any problems with this Bot, please Contact the Webmaster)",
        'method'  => 'GET',
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($_GET['site'], false, $context);
$file_http_response_header = $http_response_header;
$metas = get_meta_tags($_GET['site']);
$points = array("+"=>0,"-"=>0,"="=>0);
echo '<style>
thead td{border-bottom:1px solid #000;background-color:#DFDEDE;height:40px;font-size:15pt}thead td:first-child{border-radius:20px 0 0 0}thead td:last-child{border-radius:0 20px 0 0}
</style><h1>Optimierungen</h1><p>Sie haben nach dem Keyword "'.$_GET['keyword'].'" gesucht.</p><table><td style="width: 40%"><img src="'.get_favicon($result,substr($_GET['site'],strpos("/",$_GET['site'])),"Optimizer").'" style="width:80%;"></td><td><b>Seite</b><br>'.$_GET['site'].'<br><br><b>Beschreibung</b><br>'.$metas["description"].'<br><br><b>Gesuchtes Keyword</b><br>'.$_GET['keyword'].'</td></table>
<h3 style="margin-top:10px">Allgemein</h3><table style="text-align:left;padding-left:20px"><thead style="text-align:center"><td style="width:10%;">Status</td><td>Checkpoint</td></thead><tbody>';
if(preg_match("/200/",$http_response_header[0])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Super Ihre Seite ist erreichbar. Schon mal ein gutes Zeichen!</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Nicht gut, die Seite konnte nicht geladen werden.</td></tr>';
die();
}
if(isset($metas["description"])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Ihre Seite verfügt über eine Beschreibung. (<a href="https://www.w3schools.com/tags/tag_meta.asp">Meta-Description</a>)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Nicht gut, Ihre Seite verfügt nicht über eine Beschreibung. (<a href="https://www.w3schools.com/tags/tag_meta.asp">Meta-Description</a>)</td></tr>';
$points["-"]++;
}
if(strlen(get_title($result)) > 35 AND strlen(get_title($result)) < 60) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Die Länge des Seitentitels ('.strlen(get_title($result)).') ist gut. (<a href="https://www.w3schools.com/tags/tag_title.asp">Title-Tag</a>)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Der Seitentitel ist zu kurz oder zu lang. Der Titel sollte zwischen mindestens 35 Zeichen bis zu 60 Zeichen lang sein. (Aktuell '.strlen(get_title($result)).' Zeichen) (<a href="https://www.w3schools.com/tags/tag_title.asp">Title-Tag</a>)</td></tr>';
$points["-"]++;
}
if(strlen($metas["description"]) > 120 AND strlen($metas["description"]) < 160) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Perfekt. Die Meta-Beschreibung hat die richtige Länge. (Aktuell '.strlen($metas["description"]).' Zeichen) (<a href="https://www.w3schools.com/tags/tag_meta.asp">Meta-Description</a>)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Noch nicht gut. Die Meta-Beschreibung hat noch nicht die richtige Länge. (Aktuell '.strlen($metas["description"]).' Zeichen) (<a href="https://www.w3schools.com/tags/tag_meta.asp">Meta-Description</a>)</td></tr>';
$points["-"]++;
}
if(!preg_match("/<link rel=(.){1}canonical(.){1}/",$result)) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Richtig so, auf der Seite ist kein Canonical-Link angegeben, das sehen Crawler nicht gerne. (<a href="https://de.wikipedia.org/wiki/Canonical_Link">Canonical Link</a>)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Gar nicht gut. Auf Ihrer Seite ist ein Canonical-Link angegeben. So einen sehen Crawler nicht gerne. (<a href="https://de.wikipedia.org/wiki/Canonical_Link">Canonical Link</a>)</td></tr>';
$points["-"]++;
}
if(preg_match("/<meta[.]+name=(.){1}language(.){1}[.]+>|lang=(.){1}(.)+(.){1}/",$result)) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Gut, auf der Seite ist eine Inhalts-Sprache in HTML angegeben. (<a href="https://www.w3.org/International/questions/qa-http-and-lang">Sprachangabe in HTML-Dokumenten</a>)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Es ist keine Inhalts-Sprache im HTML-Dokument angegeben (<a href="https://www.w3.org/International/questions/qa-http-and-lang">Sprachangabe in HTML-Dokumenten</a>)</td></tr>';
$points["-"]++;
}
if(isset(parseHeaders($http_response_header)["Content-Language"])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Super, Ihre Seite verfügt zusätzlich über eine Angabe der Sprache im Header (<a href="https://www.w3.org/International/questions/qa-http-and-lang">Sprachangabe im Header</a>)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Verbesserungspotential, Ihre Seite verfügt nicht über eine Sprachangabe im Header (<a href="https://www.w3.org/International/questions/qa-http-and-lang">Sprachangabe im Header</a>)</td></tr>';
$points["-"]++;
}
if(!preg_match("/rel=(.){1}alternate(.){1}/",$result)) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Gut, die Seite nutzt keine Alternate-Links.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Schlecht. Die Seite nutzt Alternate-Links.</td></tr>';
$points["-"]++;
}
if(strlen(preg_replace("-https?://-","",substr($_GET['site'],strpos("/",$_GET['site'])))) <= 20) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Die Länge der Domain scheint gut zu sein, sie sollte maximal 20 Zeichen betragen. (Aktuell '.strlen(preg_replace("-https?://-","",substr($_GET['site'],strpos("/",$_GET['site'])))).' Zeichen)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Die Länge der Domain ist etwas lang (Aktuell '.strlen(preg_replace("-https?://-","",substr($_GET['site'],strpos("/",$_GET['site'])))).' Zeichen). Sie sollte maximal 20 Zeichen betragen.</td></tr>';
$points["-"]++;
}
if(preg_match("/meta charset=/",$result) OR preg_match("/charset=/",parseHeaders($http_response_header)["Content-Type"])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Das Dokument enthält Angaben über die Zeichenkodierung entweder im Header oder im HTML-Code.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Ganz schlimm. Das Dokument enthält weder im Header noch im HTML-Code angaben über seine Zeichenkodierung. Möglicherweise wird es falsch dargestellt.</td></tr>';
$points["-"]++;
}
if(get_favicon($result,substr($_GET['site'],strpos("/",$_GET['site'])),"Optimizer")!="Not Found") {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Sehr schön, es ist ein Favicon angegeben</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Nicht schlimm, aber schade. Es ist kein Favicon angegeben.</td></tr>';
$points["-"]++;
}
if(substr_count(strtolower($_GET['site']),strtolower($_GET['keyword'])) >= 1) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Das Keyword kommt in der URL vor.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Die URL enthält das Keyword nicht.</td></tr>';
$points["-"]++;
}
if(substr_count($result,"<script src=") <= 3) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Die Seite fordert nicht zu viele Javascript Dateien an. (Aktuell '.substr_count($result,"<script src=").' Dateien)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Ihre Seite fordert zu viele Javascript-Dateien an. (Aktuell '.substr_count($result,"<script src=").' Dateien)</td></tr>';
$points["-"]++;
}
if(preg_match("/name=(.){1}viewport(.){1}/",strtolower($result))) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Es ist ein Viewport angegeben.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Es ist kein Viewport angegeben.</td></tr>';
$points["-"]++;
}
if(preg_match("-https://-",$_GET['site'])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Die Daten werden verschlüsselt über https abgerufen.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Die Seite wird unverschlüsselt abgerufen.</td></tr>';
$points["-"]++;
}
if(!isset(parseHeaders($http_response_header)["X-Powered-By"])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Die Seite sendet keinen X-Powerded-By Header. Dieser ist unnötig und kann ein Sicherheitsrisiko darstellen.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Die Seite sendet einen X-Powerded-By Header. Dieser ist unnötig und kann ein Sicherheitsrisiko darstellen.</td></tr>';
$points["-"]++;
}
echo '</tbody></table><h3>Seitenqualität/Inhalt</h3><table style="text-align:left;padding-left:20px"><thead style="text-align:center"><td style="width:10%;">Status</td><td>Checkpoint</td></thead><tbody>';
if(substr_count(strtolower($metas["description"]),strtolower($_GET['keyword'])) >= 1) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Ihr Keyword kommt mindestens einmal in der Beschreibung vor. ('.substr_count(strtolower($metas["description"]),strtolower($_GET['keyword'])).' mal)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Ihr Keyword kommt nicht in der Beschreibung vor. Das muss unbedingt verbessert werden!</td></tr>';
$points["-"]++;
}
if(strpos(strtolower(get_title($result)),strtolower($_GET['keyword']))!==false) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Das Keyword kommt im Titel vor.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Das Keyword kommt nicht im Titel vor. Das muss unbedingt verbessert werden!</td></tr>';
$points["-"]++;
}
if(strpos(strtolower(substr($result,strpos($result,"<h1>"),strpos($result,"</h1>")-strpos($result,"<h1>"))),$_GET['keyword'])!==false) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Das Keyword kommt in der ersten Überschrift (&lt;h1&gt;) vor.</td></tr>';
$points["+"]++;
}
if(str_word_count($result) > 300) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Sieht gut aus, auf der Seite ist genug Text vorhanden. Ihr Text sollte länger als 300 Wörter sein. (Aktuell '.str_word_count($result).' Wörter)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Ihr Text ist zu kurz (Aktuell '.str_word_count($result).' Wörter). Er sollte mindestenst 300 Wörter zählen.</td></tr>';
$points["-"]++;
}
if(substr_count($result,"<p") >= 4) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Gut. Ihre Seite enthält mehr als 4 Paragraphen. ('.substr_count($result,"<p").')</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Ihre Seite enthält noch zu wenige Paragraphen ('.substr_count($result,"<p").'). Texte in Paragraphen zu unterteilen steigert die Lesbarkeit.</td></tr>';
$points["-"]++;
}
if(!preg_match("/<frameset[.]*>/",$result)) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Die Seite verwendet kein Frameset.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Ihre Seite verwendet ein Frameset.</td></tr>';
$points["-"]++;
}
if(substr_count(strtolower($result),"<img") >= 4) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Auf Ihrer Seite finden sich genügend Bilder. Bilder erleichtern das Verstehen Ihrer Seite. Empfohlen werden mindestens 4 Bilder. (Aktuell '.substr_count(strtolower($result),"<img").' Bilder)</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Auf Ihrer Seite finden sich nicht genügend Bilder. Bilder erleichtern das Verstehen Ihrer Seite. Empfohlen werden mindestens 4 Bilder. (Aktuell '.substr_count(strtolower($result),"<img").' Bilder)</td></tr>';
$points["-"]++;
}
if(substr_count(strtolower($result),"alt=") >= substr_count(strtolower($result),"<img")) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Die Bilder sind mit einem Alt-Attribut versehen. Das hilft Crawlern, zu verstehen was auf den Bildern zu sehen ist.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Keine oder nicht alle Bilder verfügen über das Alt-Attribut. Dieses hilft Crawlern zu verstehen, was auf Ihrer Seite zu sehen ist.</td></tr>';
$points["-"]++;
}
$dom = new DOMDocument;
$dom->loadHTML($result);
$links = $dom->getElementsByTagName('a');
$counter = 0;
if(count($links) > 10) {
echo '<tr><td style="text-align:center;color:green">✔</td><td><details><summary>Die Seite scheint gut verlinkt zu sein. Es werden mehr als 10 Links empfohlen. Klicken um alle anzuzeigen</summary><ul>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td><details><summary>Ihre Seite scheint schlecht verlinkt zu sein. Es werden mehr als 10 Links empfohlen. Klicken um alle anzuzeigen.</summary><ul>';
$points["-"]++;
}
foreach($links AS $link) {
echo "<li>".$link->getAttribute("href");
}
echo '</ul></details></td></tr></tbody></table><h3>Weiteres</h3><table style="text-align:left;padding-left:20px"><thead style="text-align:center"><td style="width:10%;">Status</td><td>Checkpoint</td></thead><tbody>';
$robots = file('http:'.substr($_GET['site'],strpos($_GET['site'],'/')).'/robots.txt') or $robots = file('https:'.substr($_GET['site'],strpos($_GET['site'],'/')).'/robots.txt');
if(preg_match('/200/',get_headers('http:'.substr($_GET['site'],strpos($_GET['site'],'/')).'/robots.txt')[0]) OR preg_match('/200/',get_headers('https:'.substr($_GET['site'],strpos($_GET['site'],'/')).'/robots.txt')[0])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Es existiert eine robots.txt, mit deren Hilfe lassen sich Suchmaschinen regulieren.</td></tr>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Es existiert keine "robots.txt"-Datei, Suchmaschinen und andere Bots werden also nicht reguliert.</td></tr>';
$points["-"]++;
}
if(isset(parseHeaders($robots)['Sitemap'])) {
echo '<tr><td style="text-align:center;color:green">✔</td><td>Es wird in der robots.txt auf eine Sitemap verwiesen.</td>';
$points["+"]++;
}
else {
echo '<tr><td style="text-align:center;color:red">&cross;</td><td>Es wird nicht auf eine Sitemap verwiesen.</td></tr>';
$points["-"]++;
}
echo '</tbody></table><h3>Komplette Rückgabe mit Response-Headern</h3>
<p><textarea readonly style="width:95%;height:400px">'.implode('
',$file_http_response_header).'

'.htmlentities($result,false,"UTF-8").'</textarea></p>';
}
include("contextmenu.php");
}
if($_GET['view']=="aktionen") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Aktionen - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
$durchschnittliche_aktionen = ($actions_per_day[0] + $actions_per_day[1] + $actions_per_day[2] + $actions_per_day[3] + $actions_per_day[4] + $actions_per_day[5] + $actions_per_day[6] + $actions_per_day[7] + $actions_per_day[8] + $actions_per_day[9]) / 10;
echo '<h1>Aktionen</h1><table><tr><td><b>Höchste Anzahl Aktionen:</b><br>'.$actions[0].'</td><td><b>Durchschnittliche Anzahl Aktionen:</b><br>'.$durchschnittliche_aktionen.'</td></tr></table><p><canvas id="visitor_actions_graph_days" width="1150" height="300">Ihr Browser unterstützt das HTML5-Canvas-Element offenbar nicht, bitte checken Sie die Kompatibilität</canvas><br><canvas id="visitor_actions_graph_months" width="1200" style="width: 1200px; height: 300px;" height="300">Ihr Browser unterstützt das HTML5-Canvas-Element offenbar nicht, bitte checken Sie die Kompatibilität</canvas><br><canvas id="visitor_actions_graph_years" width="1000" style="width: 1000px; height: 300px;" height="300">Ihr Browser unterstützt das HTML5-Canvas-Element offenbar nicht, bitte checken Sie die Kompatibilität</canvas></p><p><img src="img/info.png" width="40px"><br>Aktionen sind Klicks, Scrolls etc.</p>';

// Contextmenu
include("contextmenu.php");

sort($lastyears);

echo '<script type="text/javascript">
actions = new Array('.implode(',',array_map('intval',$actions_per_day)).');
actions_months = new Array('.implode(',',array_map('intval',$actions_per_month)).');
actions_years = new Array('.implode(',',array_map('intval',$actions_per_year)).');
barchart(document.getElementById("visitor_actions_graph_days"),actions,["-9","-8","-7","-6","-5","-4","-3","-2","Gestern","Heute"]);
barchart(document.getElementById("visitor_actions_graph_months"),actions_months,["Januar","Februar","März","April","Mai","Juni","Juli","August","September","November","Dezember"]);
barchart(document.getElementById("visitor_actions_graph_years"),actions_years,'.json_encode($lastyears).');
</script>
';
}
if($_GET['view']=="konfiguriere_interne_suche") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Konfigurieren der internen Suchanalyse - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
include('menu.php');
include('updater.php');
if(!isset($_POST['filename'])) {
echo '<h1>Konfigurieren der internen Suche</h1><form action="#" method="post">Bitte füllen Sie die Felder unten korrekt aus, um die Suche zu analysieren. Eine detaillierte Erklärung finden Sie weiter unten.<br><br><b>Name der Suchdatei*: <input type="text" name="filename"><br>Get-Parameter**: <input type="text" name="parameter"></b><br><br><input type="submit" value="Speichern"></form><h2 style="margin-top:20px;margion-bottom:15px">Detaillierte Anleitung</h2><h3>*Name der Suchdatei</h3><p>Beim Namen der Suchdatei handelt es sich um die Datei, die auf Ihrem Webserver die Suchanfrage aktiv beantwortet, bzw. in der sich das Programm befindet, welches die Suchanfrage des Nutzers empfängt und diese anschliessend auswertet. Diese Datei finden Sie am einfachsten, wenn Sie auf der Seite eine Suche ausführen und die URL analysieren. Bei der Suchdatei, handelt es sich um den Text, der zwischen dem letzten Schrägstrich (/) und dem Fragezeichen (?) steht. Mehr sehen Sie auf dem Bild.<br><br><img src="img/search-file.png"><br><br>In diesem Falle wäre der Name der Suchdatei also "search". Manche Dateien enthalten manchmal auch den Namen der Dateiendung. Diesen müssen Sie ebenfalls eingeben.</p><h3>**Get-Parameter</h3><p>Beim Get-Paramter handelt es sich um eine Variable, die hinten an die URL (hinter dem Fragezeichen) angefügt wird, um der Suchdatei* den Zugriff auf den gesuchten Inhalt zu ermöglichen. Bei Suchen ist es üblich, den zu suchenden Inhalt an die URL anzuhängen, manche Seiten werden jedoch möglicherweise die Suche mit <a href="https://en.wikipedia.org/wiki/POST_(HTTP)" target="_blank">POST</a> übergeben. In diesem Falle müssten Sie auf ein anderes Tool als Opolytics zurückgreifen. Wenn die Suche aber in der URL zu finden ist, können Sie Opolytics verwenden. Dazu müssen Sie unter Get-Parameter den Paramter angeben, der von Ihrer Seite zum übergeben der Suche verwendet wird. Im Bild sehen Sie dazu mehr.<br><br><img src="img/search-parameter.png"><br><br>In diesem Falle wäre der Paramter also "q".';
}
else {
$config[20] = '/'.str_replace('/','\/',$_POST['filename']).'/';
$config[21] = $_POST['parameter'];
$config[22] = 'true';
file_put_contents('config.txt',implode(', ',$config));
echo '<h1>Konfiguration gespeichert</h1><p>Die Konfiguration wurde soeben gespeichert.<br><br><a href="?view=interne_suchen">Zurück</a></p>';
}
include('contextmenu.php');
}
if($_GET['view']=="herkuenfte") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Herkünfte/Links von anderen Seiten - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
echo '<h1 id="herkuenfte">Herkünfte/Beliebte Links von anderen Seiten</h1><p><canvas id="origin_graph" width="1100" height="300" style="width:1100px;height:300px"></canvas></p><div class="text unilateral" style="float:left"><canvas id="searchengine/site_graph" width="500" height="300" style="width:500px;height:300px"></canvas></div><br>';
$counter = 1;
$referrer_zaehle = array_count_values(preg_replace('/$^/','<i><b>Erste aufgerufene Seite oder keine Angabe</b></i>',$referrers));
arsort($referrer_zaehle);
echo '<script>
piechart(document.getElementById("searchengine/site_graph"),['.implode(', ',$searchengines_otherorigins).'],["Suchmaschinen","Andere Herkünfte"]);
barchart(document.getElementById("origin_graph"),'.json_encode(array_values($referrer_zaehle)).',["1","2","3","4","5","6","7","8","9","10"]);
</script>
<table class="unilateral"><thead><tr><td>Nummer im Diagramm</td><td>Herkunft</td><td>Aufrufe</td></thead><tbody></tr>';
$counter = 1;
foreach($referrer_zaehle AS $key=>$value) {
	echo '<tr><td>'.($counter > 10 ? 'Nicht aufgeführt' : $counter).'</td><td>'.$key.'</td><td>'.$value.'</td></tr>';
	$counter++;
}
echo '</tbody></table><br style="clear:both"><p><img src="img/info.png" width="40px"><br>Sie sehen eine Übersicht, von welchen Seiten Ihre Nutzer zu Ihnen finden und welche dieser Herkünfte besonders populär sind.</p>';
include("contextmenu.php");
}
if($_GET['view']=="live") {
include('translatecountryname.php');
$data = unserialize(file_get_contents("liveupdate.txt"));
foreach(array_keys($data) AS $key) {
if(intval($data[$key]["timestamp"] + 12) <= time()) {
unset($data[$key]);
}
}
file_put_contents('liveupdate.txt',serialize($data));
if(!isset($_GET['get'])) {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Livestatistik - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body><script>
function updateOnlineStat() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      var response = JSON.parse(this.responseText);
      var date = new Date();
      document.getElementById("online").innerHTML = response.online;
      document.getElementById("updated").innerHTML = date.getDate() + "." + parseFloat(date.getMonth()+1) + "." + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes();
      document.getElementById("today").innerHTML = response.today;
      document.getElementById("together").innerHTML = response.all;
      continents = response.continents;
      browsers = response.browsersfordiagram;
      sum = response.all;
      draw_browsers();
      draw_map();
      document.getElementById("sites").innerHTML = response.sites;
      document.getElementById("browsers").innerHTML = response.browsers;
    }
  };
  xhttp.open("GET", "?view=live&get=liveupdate&" + Math.random() * 1000000000000001, true);
  xhttp.send();
}
setInterval("updateOnlineStat()",10000);
</script>';
// Checking updates
include("updater.php");
// Include the menubar
include("menu.php");
$countries_live = array();
foreach($data AS $log) {
$countries_live[] = $log["location"];
}
$countries_live = array_count_values($countries_live);
$countries = array('Afghanistan', 'Aland Islands', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua And Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia And Herzegovina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, Democratic Republic', 'Cook Islands', 'Costa Rica', 'Cote D\'Ivoire', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard Island & Mcdonald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran, Islamic Republic Of', 'Iraq', 'Ireland', 'Isle Of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Korea', 'Kosovo', 'Kuwait', 'Kyrgyzstan', 'Lao People\'s Democratic Republic', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macao', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia, Federated States Of', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestinian Territory, Occupied', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Barthelemy', 'Saint Helena', 'Saint Kitts And Nevis', 'Saint Lucia', 'Saint Martin', 'Saint Pierre And Miquelon', 'Saint Vincent And Grenadines', 'Samoa', 'San Marino', 'Sao Tome And Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia And Sandwich Isl.', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Svalbard And Jan Mayen', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste', 'Togo', 'Tokelau', 'Tonga', 'Trinidad And Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks And Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'United States Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Viet Nam', 'Virgin Islands', 'Virgin Islands, U.S.', 'Wallis And Futuna', 'Western Sahara', 'Yemen', 'Zambia', 'Zimbabwe');
foreach($countries AS $name) {
if(!isset($countries_live[$name])) {
$countries_live[$name] = 0;
}
}
$continents = array("Europe"=>intval($countries_live["Albania"]+$countries_live["Andorra"]+$countries_live["Austria"]+$countries_live["Azerbaijan"]+$countries_live["Belarus"]+$countries_live["Belgium"]+$countries_live["Bosnia And Herzegovina"]+$countries_live["Bulgaria"]+$countries_live["Croatia"]+$countries_live["Czech Republic"]+$countries_live["Denmark"]+$countries_live["Estonia"]+$countries_live["Finland"]+$countries_live["France"]+$countries_live["Georgia"]+$countries_live["Germany"]+$countries_live["Greece"]+$countries_live["Hungary"]+$countries_live["Iceland"]+$countries_live["Ireland"]+$countries_live["Italy"]+$countries_live["Kazakhstan"]+$countries_live["Kosovo"]+$countries_live["Latvia"]+$countries_live["Liechtenstein"]+$countries_live["Lithuania"]+$countries_live["Luxembourg"]+$countries_live["Macedonia"]+$countries_live["Malta"]+$countries_live["Moldova"]+$countries_live["Monaco"]+$countries_live["Montenegro"]+$countries_live["Netherlands"]+$countries_live["Norway"]+$countries_live["Poland"]+$countries_live["Portugal"]+$countries_live["Romania"]+$countries_live["Russian Federation"]+$countries_live["San Marino"]+$countries_live["Serbia"]+$countries_live["Slovakia"]+$countries_live["Slovenia"]+$countries_live["Spain"]+$countries_live["Sweden"]+$countries_live["Switzerland"]+$countries_live["Turkey"]+$countries_live["Ukraine"]+$countries_live["United Kingdom"]+$countries_live["Vatican City"]),
"North America"=>intval($countries_live["Anguilla"]+$countries_live["Antigua And Barbuda"]+$countries_live["Aruba"]+$countries_live["Bahamas"]+$countries_live["Barbados"]+$countries_live["Belize"]+$countries_live["Bermuda"]+$countries_live["Virgin Islands"]+$countries_live["Canada"]+$countries_live["Cayman Islands"]+$countries_live["Costa Rica"]+$countries_live["Cuba"]+$countries_live["Dominica"]+$countries_live["Dominican Republic"]+$countries_live["El Salvador"]+$countries_live["Greenland"]+$countries_live["Guadeloupe"]+$countries_live["Guatemala"]+$countries_live["Haiti"]+$countries_live["Honduras"]+$countries_live["Jamaica"]+$countries_live["Martinique"]+$countries_live["Mexico"]+$countries_live["Montserrat"]+$countries_live["Nicaragua"]+$countries_live["Panama"]+$countries_live["Puerto Rico"]+$countries_live["Saint Barthelemy"]+$countries_live["Saint Kitts And Nevis"]+$countries_live["Saint Lucia"]+$countries_live["Saint Martin"]+$countries_live["Saint Pierre And Miquelon"]+$countries_live["Saint Vincent And Grenadines"]+$countries_live["Trinidad And Tobago"]+$countries_live["Turks And Caicos Islands"]+$countries_live["United States"]+$countries_live['United States Outlying Islands']),
"South America"=>intval($countries_live["Argentina"]+$countries_live["Bolivia"]+$countries_live["Brazil"]+$countries_live["Chile"]+$countries_live["Colombia"]+$countries_live["Ecuador"]+$countries_live["Falkland Islands (Malvinas)"]+$countries_live["French Guiana"]+$countries_live["Guyana"]+$countries_live["Paraguay"]+$countries_live["Peru"]+$countries_live["Suriname"]+$countries_live["Uruguay"]+$countries_live["Venezuela"]),
"Asia"=>intval($countries_live["Afghanistan"]+$countries_live["Armenia"]+$countries_live["Azerbaijan"]+$countries_live["Bahrain"]+$countries_live["Bangladesh"]+$countries_live["Bhutan"]+$countries_live["Brunei"]+$countries_live["Cambodia"]+$countries_live["China"]+$countries_live["Cyprus"]+$countries_live["Georgia"]+$countries_live["India"]+$countries_live["Indonesia"]+$countries_live["Iran"]+$countries_live["Iraq"]+$countries_live["Israel"]+$countries_live["Japan"]+$countries_live["Jordan"]+$countries_live["Kazakhstan"]+$countries_live["Kuwait"]+$countries_live["Kyrgyzstan"]+$countries_live["Laos"]+$countries_live["Lebanon"]+$countries_live["Malaysia"]+$countries_live["Maldives"]+$countries_live["Mongolia"]+$countries_live["Myanmar"]+$countries_live["Nepal"]+$countries_live["North Korea"]+$countries_live["Oman"]+$countries_live["Pakistan"]+$countries_live["Palestine"]+$countries_live["Philippines"]+$countries_live["Qatar"]+$countries_live["Russian Federation"]+$countries_live["Saudi Arabia"]+$countries_live["Singapore"]+$countries_live["South Korea"]+$countries_live["Sri Lanka"]+$countries_live["Syria"]+$countries_live["Taiwan"]+$countries_live["Tajikstan"]+$countries_live["Thailand"]+$countries_live["Timor-Leste"]+$countries_live["Turkey"]+$countries_live["Turkmenistan"]+$countries_live["United Arab Emirates"]+$countries_live["Uzbekistan"]+$countries_live["Vietnam"]+$countries_live["Yemen"]),
"Australia and Oceania"=>intval($countries_live["Australia"]+$countries_live["Fijii"]+$countries_live["Kiribati"]+$countries_live["Marshall Islands"]+$countries_live["Micronesia"]+$countries_live["Nauru"]+$countries_live["New Zealand"]+$countries_live["Palau"]+$countries_live["Papua New Guinea"]+$countries_live["Samoa"]+$countries_live["Solomon Islands"]+$countries_live["Tonga"]+$countries_live["Tuvalu"]+$countries_live["Vanuatu"]),
"Africa"=>intval($countries_live['Algeria']+$countries_live['Angola']+$countries_live['Benin']+$countries_live['Botswana']+$countries_live['Burkina Faso']+$countries_live['Burundi']+$countries_live['Cabo Verde']+$countries_live['Cameroon']+$countries_live['Central African Republic (CAR)']+$countries_live['Chad']+$countries_live['Comoros']+$countries_live['Democratic Republic of the Congo']+$countries_live['Republic of the Congo']+$countries_live["Cote d'Ivoire"]+$countries_live['Djibouti']+$countries_live['Egypt']+$countries_live['Equatorial Guinea']+$countries_live['Eritrea']+$countries_live['Eswatini']+$countries_live['Ethiopia']+$countries_live['Gabon']+$countries_live['Gambia']+$countries_live['Ghana']+$countries_live['Guinea']+$countries_live['Guinea-Bissau']+$countries_live['Kenya']+$countries_live['Lesotho']+$countries_live['Liberia']+$countries_live['Libya']+$countries_live['Madagascar']+$countries_live['Malawi']+$countries_live['Mali']+$countries_live['Mauritania']+$countries_live['Mauritius']+$countries_live['Morocco']+$countries_live['Mozambique']+$countries_live['Namibia']+$countries_live['Niger']+$countries_live['Nigeria']+$countries_live['Rwanda']+$countries_live['Sao Tome and Principe']+$countries_live['Senegal']+$countries_live['Seychelles']+$countries_live['Sierra Leone']+$countries_live['Somalia']+$countries_live['South Africa']+$countries_live['South Sudan']+$countries_live['Sudan']+$countries_live['Swaziland']+$countries_live['Tanzania']+$countries_live['Togo']+$countries_live['Tunisia']+$countries_live['Uganda']+$countries_live['Zambia']+$countries_live['Zimbabwe']));
echo '<h1>Livestatistik</h1><table style="height:300px"><td style="width:33.3%"><span id="online" style="font-size:65pt;">'.count($data).'</span><br><span>Nutzer online</span><br><div style="font-size:10pt;color:grey;vertical-align:bottom" id="updated">Aktualisiert: '.date("d.m.Y H:i",time()).'</div></td><td style="width:33.3%"><span id="today" style="font-size:65pt;">'.visitors_per_day_strict(date("d.m.Y",time())).'</span><br><span>Nutzer heute</span><br><span style="font-size:10pt;color:grey;vertical-align:bottom">Datum: '.date("d.m.Y",time()).'</span></td><td style="width:33.3%"><span id="together" style="font-size:65pt;">'.$nutzer.'</span><br><span>Nutzer insgesamt</span><br><span style="font-size:10pt;color:grey;vertical-align:bottom">Seit: '.str_replace(" ", " - ",explode(", ",$file[0])[9]).'</span></td></table><h2>Geöffnete Seiten</h2>';
$sites = array();
$browsers = array();
foreach($data AS $site) {
$sites[] = $site['site'];
$browsers[] = get_browser($log['useragent'],true)['browser'].' ('.get_browser($log['useragent'],true)['platform'].')';
}
$sites = array_count_values($sites); arsort($sites);
$browsers = array_count_values($browsers); arsort($browsers);
echo '<div id="sites"><table><thead><td>Seite</td><td>Menge geöffnet</td></thead><tbody>';
foreach($sites AS $key=>$value) {
echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
$counter = 1;
echo '</tbody></table></div><h2>Browser live</h2><div class="text" style="overflow:auto"><div style="float:left"><canvas id="browser_graph" style="width:500px;height:300px" width="500" height="300"></canvas></div><div id="browsers" style="float:right"><table style="box-shadow:none"><thead><td>#</td><td>Browser</td><td>Menge online</td></thead><tbody>';
foreach($browsers AS $key=>$value) {
echo '<tr><td>'.$counter.'<td>'.$key.'</td><td>'.$value.'</td></tr>';
$counter++;
}
echo '</tbody></table></div></div><h2>Herkunft der Aufrufe</h2><table><td width="70%"><canvas id="visitor_world_map" width="800" height="400" style="width:800px;height:400px;"></canvas></td><td><table style="margin:0px;box-shadow:none;max-height:300px;"><tr><td><b>Land</b></td><td><b>Aufrufe</b></td></tr>';
foreach(array_keys($countries_live) AS $key) {
if($countries_live[$key]==0) {
unset($countries_live[$key]);
}
}
arsort($countries_live);
foreach($countries_live AS $key=>$value) {
echo '<tr><td>'.translateCountryName($key,'de').'</td><td>'.$value.'</td></tr>';
}
echo '</tbody></table>
<script>
var continents = '.json_encode($continents).';
var browsers = '.json_encode(array('names'=>array_keys($browsers),'numbers'=>array_values($browsers))).';
var image = new Image();
image.src = "img/world-map.png";
function draw_map() {
  canvas = document.getElementById("visitor_world_map");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
ctx.clearRect(0,0,800,400);
ctx.drawImage(image,0,0,800,400);
    ctx.font = "15px Arial";
    ctx.fillStyle = "grey";
    ctx.fillText(continents["Europe"],390,85);
    ctx.fillText(continents["North America"],160,105);
    ctx.fillText(continents["South America"],240,270);
    ctx.fillText(continents["Asia"],525,100);
    ctx.fillText(continents["Africa"],425,200);
    ctx.fillText(continents["Australia and Oceania"],660,270);
}
}
function info_map() {
  canvas = document.getElementById("visitor_world_map");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    ctx.font = "10px Arial";
    ctx.fillStyle = "grey";
    ctx.fillText("Europa",380,70);
    ctx.fillText("Nordamerika",145,90);
    ctx.fillText("Südamerika",230,253);
    ctx.fillText("Afrika",415,185);
    ctx.fillText("Asien",515,85);
    ctx.fillText("Australien und Ozeanien",620,255);
}
}
piechart(document.getElementById("browser_graph"),browsers["numbers"],browsers["names"]);
document.getElementById("visitor_world_map").addEventListener("mouseover",info_map,true);
document.getElementById("visitor_world_map").addEventListener("mouseout",draw_map,true);
image.onload = function() {draw_map();};
</script>';
include("contextmenu.php");
}
if($_GET['get']=="liveupdate") {

$countries_live = array();
foreach($data AS $log) {
$countries_live[] = $log["location"];
}
$countries_live = array_count_values($countries_live);
$countries = array('Afghanistan', 'Aland Islands', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua And Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia And Herzegovina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, Democratic Republic', 'Cook Islands', 'Costa Rica', 'Cote D\'Ivoire', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard Island & Mcdonald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran, Islamic Republic Of', 'Iraq', 'Ireland', 'Isle Of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Korea', 'Kosovo', 'Kuwait', 'Kyrgyzstan', 'Lao People\'s Democratic Republic', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macao', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia, Federated States Of', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestinian Territory, Occupied', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Barthelemy', 'Saint Helena', 'Saint Kitts And Nevis', 'Saint Lucia', 'Saint Martin', 'Saint Pierre And Miquelon', 'Saint Vincent And Grenadines', 'Samoa', 'San Marino', 'Sao Tome And Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia And Sandwich Isl.', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Svalbard And Jan Mayen', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste', 'Togo', 'Tokelau', 'Tonga', 'Trinidad And Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks And Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'United States Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Viet Nam', 'Virgin Islands', 'Virgin Islands, U.S.', 'Wallis And Futuna', 'Western Sahara', 'Yemen', 'Zambia', 'Zimbabwe');
foreach($countries AS $name) {
if(!isset($countries_live[$name])) {
$countries_live[$name] = 0;
}
}
$continents = array("Europe"=>intval($countries_live["Albania"]+$countries_live["Andorra"]+$countries_live["Austria"]+$countries_live["Azerbaijan"]+$countries_live["Belarus"]+$countries_live["Belgium"]+$countries_live["Bosnia And Herzegovina"]+$countries_live["Bulgaria"]+$countries_live["Croatia"]+$countries_live["Czech Republic"]+$countries_live["Denmark"]+$countries_live["Estonia"]+$countries_live["Finland"]+$countries_live["France"]+$countries_live["Georgia"]+$countries_live["Germany"]+$countries_live["Greece"]+$countries_live["Hungary"]+$countries_live["Iceland"]+$countries_live["Ireland"]+$countries_live["Italy"]+$countries_live["Kazakhstan"]+$countries_live["Kosovo"]+$countries_live["Latvia"]+$countries_live["Liechtenstein"]+$countries_live["Lithuania"]+$countries_live["Luxembourg"]+$countries_live["Macedonia"]+$countries_live["Malta"]+$countries_live["Moldova"]+$countries_live["Monaco"]+$countries_live["Montenegro"]+$countries_live["Netherlands"]+$countries_live["Norway"]+$countries_live["Poland"]+$countries_live["Portugal"]+$countries_live["Romania"]+$countries_live["Russian Federation"]+$countries_live["San Marino"]+$countries_live["Serbia"]+$countries_live["Slovakia"]+$countries_live["Slovenia"]+$countries_live["Spain"]+$countries_live["Sweden"]+$countries_live["Switzerland"]+$countries_live["Turkey"]+$countries_live["Ukraine"]+$countries_live["United Kingdom"]+$countries_live["Vatican City"]),
"North America"=>intval($countries_live["Anguilla"]+$countries_live["Antigua And Barbuda"]+$countries_live["Aruba"]+$countries_live["Bahamas"]+$countries_live["Barbados"]+$countries_live["Belize"]+$countries_live["Bermuda"]+$countries_live["Virgin Islands"]+$countries_live["Canada"]+$countries_live["Cayman Islands"]+$countries_live["Costa Rica"]+$countries_live["Cuba"]+$countries_live["Dominica"]+$countries_live["Dominican Republic"]+$countries_live["El Salvador"]+$countries_live["Greenland"]+$countries_live["Guadeloupe"]+$countries_live["Guatemala"]+$countries_live["Haiti"]+$countries_live["Honduras"]+$countries_live["Jamaica"]+$countries_live["Martinique"]+$countries_live["Mexico"]+$countries_live["Montserrat"]+$countries_live["Nicaragua"]+$countries_live["Panama"]+$countries_live["Puerto Rico"]+$countries_live["Saint Barthelemy"]+$countries_live["Saint Kitts And Nevis"]+$countries_live["Saint Lucia"]+$countries_live["Saint Martin"]+$countries_live["Saint Pierre And Miquelon"]+$countries_live["Saint Vincent And Grenadines"]+$countries_live["Trinidad And Tobago"]+$countries_live["Turks And Caicos Islands"]+$countries_live["United States"]+$countries_live['United States Outlying Islands']),
"South America"=>intval($countries_live["Argentina"]+$countries_live["Bolivia"]+$countries_live["Brazil"]+$countries_live["Chile"]+$countries_live["Colombia"]+$countries_live["Ecuador"]+$countries_live["Falkland Islands (Malvinas)"]+$countries_live["French Guiana"]+$countries_live["Guyana"]+$countries_live["Paraguay"]+$countries_live["Peru"]+$countries_live["Suriname"]+$countries_live["Uruguay"]+$countries_live["Venezuela"]),
"Asia"=>intval($countries_live["Afghanistan"]+$countries_live["Armenia"]+$countries_live["Azerbaijan"]+$countries_live["Bahrain"]+$countries_live["Bangladesh"]+$countries_live["Bhutan"]+$countries_live["Brunei"]+$countries_live["Cambodia"]+$countries_live["China"]+$countries_live["Cyprus"]+$countries_live["Georgia"]+$countries_live["India"]+$countries_live["Indonesia"]+$countries_live["Iran"]+$countries_live["Iraq"]+$countries_live["Israel"]+$countries_live["Japan"]+$countries_live["Jordan"]+$countries_live["Kazakhstan"]+$countries_live["Kuwait"]+$countries_live["Kyrgyzstan"]+$countries_live["Laos"]+$countries_live["Lebanon"]+$countries_live["Malaysia"]+$countries_live["Maldives"]+$countries_live["Mongolia"]+$countries_live["Myanmar"]+$countries_live["Nepal"]+$countries_live["North Korea"]+$countries_live["Oman"]+$countries_live["Pakistan"]+$countries_live["Palestine"]+$countries_live["Philippines"]+$countries_live["Qatar"]+$countries_live["Russian Federation"]+$countries_live["Saudi Arabia"]+$countries_live["Singapore"]+$countries_live["South Korea"]+$countries_live["Sri Lanka"]+$countries_live["Syria"]+$countries_live["Taiwan"]+$countries_live["Tajikstan"]+$countries_live["Thailand"]+$countries_live["Timor-Leste"]+$countries_live["Turkey"]+$countries_live["Turkmenistan"]+$countries_live["United Arab Emirates"]+$countries_live["Uzbekistan"]+$countries_live["Vietnam"]+$countries_live["Yemen"]),
"Australia and Oceania"=>intval($countries_live["Australia"]+$countries_live["Fijii"]+$countries_live["Kiribati"]+$countries_live["Marshall Islands"]+$countries_live["Micronesia"]+$countries_live["Nauru"]+$countries_live["New Zealand"]+$countries_live["Palau"]+$countries_live["Papua New Guinea"]+$countries_live["Samoa"]+$countries_live["Solomon Islands"]+$countries_live["Tonga"]+$countries_live["Tuvalu"]+$countries_live["Vanuatu"]),
"Africa"=>intval($countries_live['Algeria']+$countries_live['Angola']+$countries_live['Benin']+$countries_live['Botswana']+$countries_live['Burkina Faso']+$countries_live['Burundi']+$countries_live['Cabo Verde']+$countries_live['Cameroon']+$countries_live['Central African Republic (CAR)']+$countries_live['Chad']+$countries_live['Comoros']+$countries_live['Democratic Republic of the Congo']+$countries_live['Republic of the Congo']+$countries_live["Cote d'Ivoire"]+$countries_live['Djibouti']+$countries_live['Egypt']+$countries_live['Equatorial Guinea']+$countries_live['Eritrea']+$countries_live['Eswatini']+$countries_live['Ethiopia']+$countries_live['Gabon']+$countries_live['Gambia']+$countries_live['Ghana']+$countries_live['Guinea']+$countries_live['Guinea-Bissau']+$countries_live['Kenya']+$countries_live['Lesotho']+$countries_live['Liberia']+$countries_live['Libya']+$countries_live['Madagascar']+$countries_live['Malawi']+$countries_live['Mali']+$countries_live['Mauritania']+$countries_live['Mauritius']+$countries_live['Morocco']+$countries_live['Mozambique']+$countries_live['Namibia']+$countries_live['Niger']+$countries_live['Nigeria']+$countries_live['Rwanda']+$countries_live['Sao Tome and Principe']+$countries_live['Senegal']+$countries_live['Seychelles']+$countries_live['Sierra Leone']+$countries_live['Somalia']+$countries_live['South Africa']+$countries_live['South Sudan']+$countries_live['Sudan']+$countries_live['Swaziland']+$countries_live['Tanzania']+$countries_live['Togo']+$countries_live['Tunisia']+$countries_live['Uganda']+$countries_live['Zambia']+$countries_live['Zimbabwe']));
$sites = array();
$browsers = array();
foreach($data AS $log) {
$sites[] = $log['site'];
$browsers[] = get_browser($log['useragent'],true)['browser'].' ('.get_browser($log['useragent'],true)['platform'].')';
}
$sites = array_count_values($sites);
$browsers = array_count_values($browsers);
arsort($browsers);
arsort($sites);
$sites_output = '<table><thead><td>Seite</td><td>Menge geöffnet</td></thead><tbody>';
foreach($sites AS $key=>$value) {
$sites_output .= '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
$sites_output .= '</tbody></table>';
$counter = 1;
$browsers_output = '<table style="box-shadow:none"><thead><td>#</td><td>Browser</td><td>Menge online</td></thead><tbody>';
foreach($browsers AS $key=>$value) {
$browsers_output .= '<tr><td>'.$counter.'</td><td>'.$key.'</td><td>'.$value.'</td></tr>';
$counter++;
}
$browsers_output .= '</tbody></table>';
$answer = array('online'=>count($data),'today'=>visitors_per_day_strict(date("d.m.Y",time())),'all'=>$nutzer,'continents'=>$continents,'sites'=>$sites_output,'browsers'=>$browsers_output,'browsersfordiagram'=>array('names'=>array_keys($browsers),'numbers'=>array_values($browsers)));
echo json_encode($answer);
}
}
if($_GET['view']=="karte") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Besucher-Karte - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
// Checking updates
include("updater.php");

// Include the menubar
include("menu.php");
include('translatecountryname.php');
$geolocation = array_count_values($geolocation);
$continents = array("Europe"=>intval($geolocation["Albania"]+$geolocation["Andorra"]+$geolocation["Austria"]+$geolocation["Azerbaijan"]+$geolocation["Belarus"]+$geolocation["Belgium"]+$geolocation["Bosnia And Herzegovina"]+$geolocation["Bulgaria"]+$geolocation["Croatia"]+$geolocation["Czech Republic"]+$geolocation["Denmark"]+$geolocation["Estonia"]+$geolocation["Finland"]+$geolocation["France"]+$geolocation["Georgia"]+$geolocation["Germany"]+$geolocation["Greece"]+$geolocation["Hungary"]+$geolocation["Iceland"]+$geolocation["Ireland"]+$geolocation["Italy"]+$geolocation["Kazakhstan"]+$geolocation["Kosovo"]+$geolocation["Latvia"]+$geolocation["Liechtenstein"]+$geolocation["Lithuania"]+$geolocation["Luxembourg"]+$geolocation["Macedonia"]+$geolocation["Malta"]+$geolocation["Moldova"]+$geolocation["Monaco"]+$geolocation["Montenegro"]+$geolocation["Netherlands"]+$geolocation["Norway"]+$geolocation["Poland"]+$geolocation["Portugal"]+$geolocation["Romania"]+$geolocation["Russian Federation"]+$geolocation["San Marino"]+$geolocation["Serbia"]+$geolocation["Slovakia"]+$geolocation["Slovenia"]+$geolocation["Spain"]+$geolocation["Sweden"]+$geolocation["Switzerland"]+$geolocation["Turkey"]+$geolocation["Ukraine"]+$geolocation["United Kingdom"]+$geolocation["Vatican City"]),
"North America"=>intval($geolocation["Anguilla"]+$geolocation["Antigua And Barbuda"]+$geolocation["Aruba"]+$geolocation["Bahamas"]+$geolocation["Barbados"]+$geolocation["Belize"]+$geolocation["Bermuda"]+$geolocation["Virgin Islands"]+$geolocation["Canada"]+$geolocation["Cayman Islands"]+$geolocation["Costa Rica"]+$geolocation["Cuba"]+$geolocation["Dominica"]+$geolocation["Dominican Republic"]+$geolocation["El Salvador"]+$geolocation["Greenland"]+$geolocation["Guadeloupe"]+$geolocation["Guatemala"]+$geolocation["Haiti"]+$geolocation["Honduras"]+$geolocation["Jamaica"]+$geolocation["Martinique"]+$geolocation["Mexico"]+$geolocation["Montserrat"]+$geolocation["Nicaragua"]+$geolocation["Panama"]+$geolocation["Puerto Rico"]+$geolocation["Saint Barthelemy"]+$geolocation["Saint Kitts And Nevis"]+$geolocation["Saint Lucia"]+$geolocation["Saint Martin"]+$geolocation["Saint Pierre And Miquelon"]+$geolocation["Saint Vincent And Grenadines"]+$geolocation["Trinidad And Tobago"]+$geolocation["Turks And Caicos Islands"]+$geolocation["United States"]+$geolocation['United States Outlying Islands']),
"South America"=>intval($geolocation["Argentina"]+$geolocation["Bolivia"]+$geolocation["Brazil"]+$geolocation["Chile"]+$geolocation["Colombia"]+$geolocation["Ecuador"]+$geolocation["Falkland Islands (Malvinas)"]+$geolocation["French Guiana"]+$geolocation["Guyana"]+$geolocation["Paraguay"]+$geolocation["Peru"]+$geolocation["Suriname"]+$geolocation["Uruguay"]+$geolocation["Venezuela"]),
"Asia"=>intval($geolocation["Afghanistan"]+$geolocation["Armenia"]+$geolocation["Azerbaijan"]+$geolocation["Bahrain"]+$geolocation["Bangladesh"]+$geolocation["Bhutan"]+$geolocation["Brunei"]+$geolocation["Cambodia"]+$geolocation["China"]+$geolocation["Cyprus"]+$geolocation["Georgia"]+$geolocation["India"]+$geolocation["Indonesia"]+$geolocation["Iran"]+$geolocation["Iraq"]+$geolocation["Israel"]+$geolocation["Japan"]+$geolocation["Jordan"]+$geolocation["Kazakhstan"]+$geolocation["Kuwait"]+$geolocation["Kyrgyzstan"]+$geolocation["Laos"]+$geolocation["Lebanon"]+$geolocation["Malaysia"]+$geolocation["Maldives"]+$geolocation["Mongolia"]+$geolocation["Myanmar"]+$geolocation["Nepal"]+$geolocation["North Korea"]+$geolocation["Oman"]+$geolocation["Pakistan"]+$geolocation["Palestine"]+$geolocation["Philippines"]+$geolocation["Qatar"]+$geolocation["Russian Federation"]+$geolocation["Saudi Arabia"]+$geolocation["Singapore"]+$geolocation["South Korea"]+$geolocation["Sri Lanka"]+$geolocation["Syria"]+$geolocation["Taiwan"]+$geolocation["Tajikstan"]+$geolocation["Thailand"]+$geolocation["Timor-Leste"]+$geolocation["Turkey"]+$geolocation["Turkmenistan"]+$geolocation["United Arab Emirates"]+$geolocation["Uzbekistan"]+$geolocation["Vietnam"]+$geolocation["Yemen"]),
"Australia and Oceania"=>intval($geolocation["Australia"]+$geolocation["Fijii"]+$geolocation["Kiribati"]+$geolocation["Marshall Islands"]+$geolocation["Micronesia"]+$geolocation["Nauru"]+$geolocation["New Zealand"]+$geolocation["Palau"]+$geolocation["Papua New Guinea"]+$geolocation["Samoa"]+$geolocation["Solomon Islands"]+$geolocation["Tonga"]+$geolocation["Tuvalu"]+$geolocation["Vanuatu"]),
"Africa"=>intval($geolocation['Algeria']+$geolocation['Angola']+$geolocation['Benin']+$geolocation['Botswana']+$geolocation['Burkina Faso']+$geolocation['Burundi']+$geolocation['Cabo Verde']+$geolocation['Cameroon']+$geolocation['Central African Republic (CAR)']+$geolocation['Chad']+$geolocation['Comoros']+$geolocation['Democratic Republic of the Congo']+$geolocation['Republic of the Congo']+$geolocation["Cote d'Ivoire"]+$geolocation['Djibouti']+$geolocation['Egypt']+$geolocation['Equatorial Guinea']+$geolocation['Eritrea']+$geolocation['Eswatini']+$geolocation['Ethiopia']+$geolocation['Gabon']+$geolocation['Gambia']+$geolocation['Ghana']+$geolocation['Guinea']+$geolocation['Guinea-Bissau']+$geolocation['Kenya']+$geolocation['Lesotho']+$geolocation['Liberia']+$geolocation['Libya']+$geolocation['Madagascar']+$geolocation['Malawi']+$geolocation['Mali']+$geolocation['Mauritania']+$geolocation['Mauritius']+$geolocation['Morocco']+$geolocation['Mozambique']+$geolocation['Namibia']+$geolocation['Niger']+$geolocation['Nigeria']+$geolocation['Rwanda']+$geolocation['Sao Tome and Principe']+$geolocation['Senegal']+$geolocation['Seychelles']+$geolocation['Sierra Leone']+$geolocation['Somalia']+$geolocation['South Africa']+$geolocation['South Sudan']+$geolocation['Sudan']+$geolocation['Swaziland']+$geolocation['Tanzania']+$geolocation['Togo']+$geolocation['Tunisia']+$geolocation['Uganda']+$geolocation['Zambia']+$geolocation['Zimbabwe']));

echo '<h1>Besucherkarte</h1><p>Sehen Sie auf der Karte unten alle Nutzer auf der interaktiven Karte.</p><script src="js/countrytranslatepackage.min.js"></script>
<p><object id="map" data="img/user_map.svg.php" type="image/svg+xml"></object><select id="map_options"><option value="calls">Aufrufe</option><option value="users">Einzelne Nutzer</option></select></p>
<table style="width:49%;float:left"><thead><tr><td>#</td><td>Anzahl Nutzer</td><td>Flagge</td><td>Landesname</td></tr></thead><tbody>';
$counter = 1;
foreach($geolocation AS $name=>$value) {
echo '<tr><td>'.$counter.'</td><td>'.$value.'</td><td><img src="img/flags/redirect.php?country='.$name.'" height="20"></td><td>'.translateCountryName($name,'de').'</td></tr>';
$counter++;
}
echo '</tbdody></table><table style="width:49%"><thead><tr><td>#</td><td>Anzahl Nutzer</td><td>Region</td></tr></thead><tbody>';
$counter = 1;
arsort($regions);
foreach($regions AS $name=>$value) {
echo '<tr><td>'.$counter.'</td><td>'.$value.'</td><td>'.$name.'</td></tr>';
$counter++;
}
echo '</tbody></table><br><div class="text" style="overflow:auto"><svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 1280.0 649.0" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" style="float:left;width:50%;height:auto">
<g><image xlink:href="img/world-map.png" transform="matrix(1.0, 0.0, 0.0, 1.0, 0.0, 649.0)" height="649.0" width="1280.0" y="-649.0" x="0" /></g>
<rect x="100" y="30" width="400" height="250" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showNorthAmerica();"/>
<rect x="280" y="280" width="220" height="270" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showSouthAmerica();"/>
<rect x="540" y="35" width="160" height="140" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showEurope();"/>
<rect x="535" y="180" width="160" height="140" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showAfrica();"/>
<rect x="625" y="280" width="160" height="190" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showAfrica();"/>
<polygon points="695 200,710 200,760 300,695 300" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showAfrica();"/>
<rect x="700" y="20" width="400" height="180" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showAsia();"/>
<polygon points="715 200,765 285,1050 370,1110 370,1110 330,1050 200" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showAsia();"/>
<rect x="980" y="370" width="230" height="150" style="fill:rgba(0,0,0,0);cursor:pointer" onclick="window.location.href = \'#map\'; document.getElementById(\'map\').contentWindow.window.showAustralia();"/>
<text x="270" y="150" style="font-size:25pt">'.$continents['North America'].'</text>
<text x="390" y="400" style="font-size:25pt">'.$continents['South America'].'</text>
<text x="620" y="140" style="font-size:25pt">'.$continents['Europe'].'</text>
<text x="670" y="320" style="font-size:25pt">'.$continents['Africa'].'</text>
<text x="850" y="150" style="font-size:25pt">'.$continents['Asia'].'</text>
<text x="1050" y="435" style="font-size:25pt">'.$continents['North America'].'</text>
</svg><table style="width:50%;box-shadow:none"><thead><tr><td>Kontinent</td><td>Anzahl Aufrufe</td></tr></thead><tbody>';
arsort($continents);
$continents = translateContinentNames($continents);
foreach($continents AS $key=>$value) {
echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
echo '</tbody></table></div>';
include("contextmenu.php");
}
if($_GET['view']=="woche") {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Wochenstatistik - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
include("updater.php");
include("menu.php");
if(!isset($_GET['start'])) {
echo '<h1>Wochenstatistik</h1><form action="#" method="get" id="send"><input type="hidden" name="view" value="woche">Bitte wählen Sie eine Woche aus, um Sie zu analysieren.<br>Von: <input type="date" onchange="week()" id="start"> Bis: <input type="date" id="end" readonly><br><br><input type="button" value="Diese Woche analysieren" onclick="send()"><input type="hidden" name="start" id="hiddenstart"><input type="hidden" name="end" id="hiddenend"></form>
<script>
function toTwo(number) {
var length = number.toString().length.toString();
if(length==1) {
return "0" + number;
}
else {
return number;
}
}
function week() {
const timestamp = new Date(document.getElementById("start").value).getTime() / 1000 + 518400;
const date = new Date(timestamp*1000);
document.getElementById("end").value = date.getFullYear() + "-" + toTwo((date.getMonth()+1)) + "-" + toTwo(date.getDate());
}
function send() {
if(new Date(document.getElementById("start").value).getDay()==1) {
document.getElementById("hiddenstart").value = document.getElementById("start").value.split("-").reverse().join(".");
document.getElementById("hiddenend").value = document.getElementById("end").value.split("-").reverse().join(".");
document.getElementById("send").submit();
}
else {
popup("<h1>Fehler</h1>Oh nein! Es ist ein Fehler aufgetreten. Der ausgewählte Tag ist kein Montag. Es sind nur Montage erlaubt!<br><br><input type=\'button\' value=\'Schliessen\' onclick=\'close_popup()\'>",screen.availWidth / 2 - 300,screen.availHeight / 2 - 125,620,200);
}
}
</script>';
}
if(isset($_GET['start'])) {
include('translatecountryname.php');
$weekdata = array('url'=>array(),'country'=>array(),'region'=>array(),'referrer'=>array(),'searches'=>array(),'languages'=>array(),'actions'=>array());
function addDataForWeek($url,$country,$region,$referrer,$languages,$actions,$system,$title,$description) {
global $weekdata;
global $config;
$weekdata['url'][] = $url;
$weekdata['country'][] = $country;
$weekdata['region'][] = $region;
$weekdata['referrer'][] = $referrer;
if(preg_match($config[20], $url)) {
$parameter = $config[21];
$weekdata['searches'][] = array('search'=>parseGet(parse_url($url)['query'])[$parameter],'title'=>str_replace('_ ',', ',$title),'description'=>str_replace('_ ',', ',$description));
}
$weekdata['languages'][] = $languages;
$weekdata['actions'][] = $actions;
return $weekdata;
}
function weekCount() {
global $weekdata;
foreach(array_keys($weekdata) AS $key) {
if($key!='searches') {
$weekdata[$key] = array_count_values($weekdata[$key]);
}
}
$sum = array_sum($weekdata['languages']);
foreach(array_keys($weekdata['languages']) AS $key) {
$weekdata['languages'][$key] = 100 / $sum * $weekdata['languages'][$key];
}
}
$time = strtotime($_GET['start']);
$visits = array(0,0,0,0,0,0,0);
foreach($file AS $log) {
$log = explode(', ',$log);
if($time==strtotime(date("d.m.Y",strtotime($log[9])))) {
$visits[0]++;
addDataForWeek($log[0],$log[14],$log[15],$log[10],$log[5],$log[13],$log[6],$log[11],$log[12]);
}
if($time+(1*86400)==strtotime(date("d.m.Y",strtotime($log[9])))) {
$visits[1]++;
addDataForWeek($log[0],$log[14],$log[15],$log[10],$log[5],$log[13],$log[6],$log[11],$log[12]);
}
if($time+(2*86400)==strtotime(date("d.m.Y",strtotime($log[9])))) {
$visits[2]++;
addDataForWeek($log[0],$log[14],$log[15],$log[10],$log[5],$log[13],$log[6],$log[11],$log[12]);
}
if($time+(3*86400)==strtotime(date("d.m.Y",strtotime($log[9])))) {
$visits[3]++;
addDataForWeek($log[0],$log[14],$log[15],$log[10],$log[5],$log[13],$log[6],$log[11],$log[12]);
}
if($time+(4*86400)==strtotime(date("d.m.Y",strtotime($log[9])))) {
$visits[4]++;
addDataForWeek($log[0],$log[14],$log[15],$log[10],$log[5],$log[13],$log[6],$log[11],$log[12]);
}
if($time+(5*86400)==strtotime(date("d.m.Y",strtotime($log[9])))) {
$visits[5]++;
addDataForWeek($log[0],$log[14],$log[15],$log[10],$log[5],$log[13],$log[6],$log[11],$log[12]);
}
if($time+(6*86400)==strtotime(date("d.m.Y",strtotime($log[9])))) {
$visits[6]++;
addDataForWeek($log[0],$log[14],$log[15],$log[10],$log[5],$log[13],$log[6],$log[11],$log[12]);
}
}
weekCount();
$countries = array('Afghanistan', 'Aland Islands', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua And Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia And Herzegovina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, Democratic Republic', 'Cook Islands', 'Costa Rica', 'Cote D\'Ivoire', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard Island & Mcdonald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran, Islamic Republic Of', 'Iraq', 'Ireland', 'Isle Of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Korea', 'Kosovo', 'Kuwait', 'Kyrgyzstan', 'Lao People\'s Democratic Republic', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macao', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia, Federated States Of', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestinian Territory, Occupied', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Barthelemy', 'Saint Helena', 'Saint Kitts And Nevis', 'Saint Lucia', 'Saint Martin', 'Saint Pierre And Miquelon', 'Saint Vincent And Grenadines', 'Samoa', 'San Marino', 'Sao Tome And Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia And Sandwich Isl.', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Svalbard And Jan Mayen', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste', 'Togo', 'Tokelau', 'Tonga', 'Trinidad And Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks And Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'United States Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela', 'Viet Nam', 'Virgin Islands', 'Virgin Islands, U.S.', 'Wallis And Futuna', 'Western Sahara', 'Yemen', 'Zambia', 'Zimbabwe');
foreach($countries AS $name) {
if(!isset($weekdata['country'][$name])) {
$weekdata['country'][$name] = 0;
}
}
$continents = array("Europe"=>intval($weekdata['country']["Albania"]+$weekdata['country']["Andorra"]+$weekdata['country']["Austria"]+$weekdata['country']["Azerbaijan"]+$weekdata['country']["Belarus"]+$weekdata['country']["Belgium"]+$weekdata['country']["Bosnia And Herzegovina"]+$weekdata['country']["Bulgaria"]+$weekdata['country']["Croatia"]+$weekdata['country']["Czech Republic"]+$weekdata['country']["Denmark"]+$weekdata['country']["Estonia"]+$weekdata['country']["Finland"]+$weekdata['country']["France"]+$weekdata['country']["Georgia"]+$weekdata['country']["Germany"]+$weekdata['country']["Greece"]+$weekdata['country']["Hungary"]+$weekdata['country']["Iceland"]+$weekdata['country']["Ireland"]+$weekdata['country']["Italy"]+$weekdata['country']["Kazakhstan"]+$weekdata['country']["Kosovo"]+$weekdata['country']["Latvia"]+$weekdata['country']["Liechtenstein"]+$weekdata['country']["Lithuania"]+$weekdata['country']["Luxembourg"]+$weekdata['country']["Macedonia"]+$weekdata['country']["Malta"]+$weekdata['country']["Moldova"]+$weekdata['country']["Monaco"]+$weekdata['country']["Montenegro"]+$weekdata['country']["Netherlands"]+$weekdata['country']["Norway"]+$weekdata['country']["Poland"]+$weekdata['country']["Portugal"]+$weekdata['country']["Romania"]+$weekdata['country']["Russian Federation"]+$weekdata['country']["San Marino"]+$weekdata['country']["Serbia"]+$weekdata['country']["Slovakia"]+$weekdata['country']["Slovenia"]+$weekdata['country']["Spain"]+$weekdata['country']["Sweden"]+$weekdata['country']["Switzerland"]+$weekdata['country']["Turkey"]+$weekdata['country']["Ukraine"]+$weekdata['country']["United Kingdom"]+$weekdata['country']["Vatican City"]),
"North America"=>intval($weekdata['country']["Anguilla"]+$weekdata['country']["Antigua And Barbuda"]+$weekdata['country']["Aruba"]+$weekdata['country']["Bahamas"]+$weekdata['country']["Barbados"]+$weekdata['country']["Belize"]+$weekdata['country']["Bermuda"]+$weekdata['country']["Virgin Islands"]+$weekdata['country']["Canada"]+$weekdata['country']["Cayman Islands"]+$weekdata['country']["Costa Rica"]+$weekdata['country']["Cuba"]+$weekdata['country']["Dominica"]+$weekdata['country']["Dominican Republic"]+$weekdata['country']["El Salvador"]+$weekdata['country']["Greenland"]+$weekdata['country']["Guadeloupe"]+$weekdata['country']["Guatemala"]+$weekdata['country']["Haiti"]+$weekdata['country']["Honduras"]+$weekdata['country']["Jamaica"]+$weekdata['country']["Martinique"]+$weekdata['country']["Mexico"]+$weekdata['country']["Montserrat"]+$weekdata['country']["Nicaragua"]+$weekdata['country']["Panama"]+$weekdata['country']["Puerto Rico"]+$weekdata['country']["Saint Barthelemy"]+$weekdata['country']["Saint Kitts And Nevis"]+$weekdata['country']["Saint Lucia"]+$weekdata['country']["Saint Martin"]+$weekdata['country']["Saint Pierre And Miquelon"]+$weekdata['country']["Saint Vincent And Grenadines"]+$weekdata['country']["Trinidad And Tobago"]+$weekdata['country']["Turks And Caicos Islands"]+$weekdata['country']["United States"]+$weekdata['country']['United States Outlying Islands']),
"South America"=>intval($weekdata['country']["Argentina"]+$weekdata['country']["Bolivia"]+$weekdata['country']["Brazil"]+$weekdata['country']["Chile"]+$weekdata['country']["Colombia"]+$weekdata['country']["Ecuador"]+$weekdata['country']["Falkland Islands (Malvinas)"]+$weekdata['country']["French Guiana"]+$weekdata['country']["Guyana"]+$weekdata['country']["Paraguay"]+$weekdata['country']["Peru"]+$weekdata['country']["Suriname"]+$weekdata['country']["Uruguay"]+$weekdata['country']["Venezuela"]),
"Asia"=>intval($weekdata['country']["Afghanistan"]+$weekdata['country']["Armenia"]+$weekdata['country']["Azerbaijan"]+$weekdata['country']["Bahrain"]+$weekdata['country']["Bangladesh"]+$weekdata['country']["Bhutan"]+$weekdata['country']["Brunei"]+$weekdata['country']["Cambodia"]+$weekdata['country']["China"]+$weekdata['country']["Cyprus"]+$weekdata['country']["Georgia"]+$weekdata['country']["India"]+$weekdata['country']["Indonesia"]+$weekdata['country']["Iran"]+$weekdata['country']["Iraq"]+$weekdata['country']["Israel"]+$weekdata['country']["Japan"]+$weekdata['country']["Jordan"]+$weekdata['country']["Kazakhstan"]+$weekdata['country']["Kuwait"]+$weekdata['country']["Kyrgyzstan"]+$weekdata['country']["Laos"]+$weekdata['country']["Lebanon"]+$weekdata['country']["Malaysia"]+$weekdata['country']["Maldives"]+$weekdata['country']["Mongolia"]+$weekdata['country']["Myanmar"]+$weekdata['country']["Nepal"]+$weekdata['country']["North Korea"]+$weekdata['country']["Oman"]+$weekdata['country']["Pakistan"]+$weekdata['country']["Palestine"]+$weekdata['country']["Philippines"]+$weekdata['country']["Qatar"]+$weekdata['country']["Russian Federation"]+$weekdata['country']["Saudi Arabia"]+$weekdata['country']["Singapore"]+$weekdata['country']["South Korea"]+$weekdata['country']["Sri Lanka"]+$weekdata['country']["Syria"]+$weekdata['country']["Taiwan"]+$weekdata['country']["Tajikstan"]+$weekdata['country']["Thailand"]+$weekdata['country']["Timor-Leste"]+$weekdata['country']["Turkey"]+$weekdata['country']["Turkmenistan"]+$weekdata['country']["United Arab Emirates"]+$weekdata['country']["Uzbekistan"]+$weekdata['country']["Vietnam"]+$weekdata['country']["Yemen"]),
"Australia and Oceania"=>intval($weekdata['country']["Australia"]+$weekdata['country']["Fijii"]+$weekdata['country']["Kiribati"]+$weekdata['country']["Marshall Islands"]+$weekdata['country']["Micronesia"]+$weekdata['country']["Nauru"]+$weekdata['country']["New Zealand"]+$weekdata['country']["Palau"]+$weekdata['country']["Papua New Guinea"]+$weekdata['country']["Samoa"]+$weekdata['country']["Solomon Islands"]+$weekdata['country']["Tonga"]+$weekdata['country']["Tuvalu"]+$weekdata['country']["Vanuatu"]),
"Africa"=>intval($weekdata['country']['Algeria']+$weekdata['country']['Angola']+$weekdata['country']['Benin']+$weekdata['country']['Botswana']+$weekdata['country']['Burkina Faso']+$weekdata['country']['Burundi']+$weekdata['country']['Cabo Verde']+$weekdata['country']['Cameroon']+$weekdata['country']['Central African Republic (CAR)']+$weekdata['country']['Chad']+$weekdata['country']['Comoros']+$weekdata['country']['Democratic Republic of the Congo']+$weekdata['country']['Republic of the Congo']+$weekdata['country']["Cote d'Ivoire"]+$weekdata['country']['Djibouti']+$weekdata['country']['Egypt']+$weekdata['country']['Equatorial Guinea']+$weekdata['country']['Eritrea']+$weekdata['country']['Eswatini']+$weekdata['country']['Ethiopia']+$weekdata['country']['Gabon']+$weekdata['country']['Gambia']+$weekdata['country']['Ghana']+$weekdata['country']['Guinea']+$weekdata['country']['Guinea-Bissau']+$weekdata['country']['Kenya']+$weekdata['country']['Lesotho']+$weekdata['country']['Liberia']+$weekdata['country']['Libya']+$weekdata['country']['Madagascar']+$weekdata['country']['Malawi']+$weekdata['country']['Mali']+$weekdata['country']['Mauritania']+$weekdata['country']['Mauritius']+$weekdata['country']['Morocco']+$weekdata['country']['Mozambique']+$weekdata['country']['Namibia']+$weekdata['country']['Niger']+$weekdata['country']['Nigeria']+$weekdata['country']['Rwanda']+$weekdata['country']['Sao Tome and Principe']+$weekdata['country']['Senegal']+$weekdata['country']['Seychelles']+$weekdata['country']['Sierra Leone']+$weekdata['country']['Somalia']+$weekdata['country']['South Africa']+$weekdata['country']['South Sudan']+$weekdata['country']['Sudan']+$weekdata['country']['Swaziland']+$weekdata['country']['Tanzania']+$weekdata['country']['Togo']+$weekdata['country']['Tunisia']+$weekdata['country']['Uganda']+$weekdata['country']['Zambia']+$weekdata['country']['Zimbabwe']+$weekdata['country']['Congo']));
foreach($countries AS $name) {
if($weekdata['country'][$name]==0) {
unset($weekdata['country'][$name]);
}
}
echo '<h1>Wochenstatistik</h1><p>Die höchste Anzahl an Nutzern pro Tag waren in dieser Woche '.max($visits).' Nutzer an einem Tag.</p><p><canvas id="week_graph" width="1300" height="250" style="width:100%height:auto"></canvas>
<table class="vergleich"><thead><tr><td>Vergleich</td><td>Montag</td><td>Dienstag</td><td>Mittwoch</td><td>Donnerstag</td><td>Freitag</td><td>Samstag</td><td>Sonntag</td></tr></thead><tbody><tr><td>Anzahl Aufrufe</td><td>'.$visits[0].'</td><td>'.$visits[1].'</td><td>'.$visits[2].'</td><td>'.$visits[3].'</td><td>'.$visits[4].'</td><td>'.$visits[5].'</td><td>'.$visits[6].'</td></tr><tr><td>Steigerung zum Vortag (%)</td><td>'.increase(visitors_per_day(date("d.m.Y",strtotime($_GET['start'])-86400)),$visits[0]).'</td><td>'.increase($visits[0],$visits[1]).'</td><td>'.increase($visits[1],$visits[2]).'</td><td>'.increase($visits[2],$visits[3]).'</td><td>'.increase($visits[3],$visits[4]).'</td><td>'.increase($visits[4],$visits[5]).'</td><td>'.increase($visits[5],$visits[6]).'</td></tr><tr><td title="Der Referrer ist ein Link (die Adresse der Seite des Links), von dem aus auf eine Webseite zugegriffen wurde.">Populärster Referrer</td><td>'.array_keys(referrers_at_day($_GET['start']))[0].'</td><td>'.array_keys(referrers_at_day(date("d.m.Y",strtotime($_GET['start'])+86400)))[0].'</td><td>'.array_keys(referrers_at_day(date("d.m.Y",strtotime($_GET['start'])+(2*86400))))[0].'</td><td>'.array_keys(referrers_at_day(date("d.m.Y",strtotime($_GET['start'])+(3*86400))))[0].'</td><td>'.array_keys(referrers_at_day(date("d.m.Y",strtotime($_GET['start'])+(4*86400))))[0].'</td><td>'.array_keys(referrers_at_day(date("d.m.Y",strtotime($_GET['start'])+(5*86400))))[0].'</td><td>'.array_keys(referrers_at_day($_GET['end']))[0].'</td></tr><tr><td>Populärstes Herkunftsland</td><td><img src="img/flags/redirect.php?country='.array_keys(countries_day($_GET['start']))[0].'" height="10"> '.translateCountryName(array_keys(countries_day($_GET['start']))[0],'de').'</td><td><img src="img/flags/redirect.php?country='.array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+86400)))[0].'" height="10"> '.translateCountryName(array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+86400)))[0],'de').'</td><td><img src="img/flags/redirect.php?country='.array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(2*86400))))[0].'" height="10"> '.translateCountryName(array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(2*86400))))[0],'de').'</td><td><img src="img/flags/redirect.php?country='.array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(3*86400))))[0].'" height="10"> '.translateCountryName(array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(3*86400))))[0],'de').'</td><td><img src="img/flags/redirect.php?country='.array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(4*86400))))[0].'" height="10"> '.translateCountryName(array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(4*86400))))[0],'de').'</td><td><img src="img/flags/redirect.php?country='.array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(5*86400))))[0].'" height="10"> '.translateCountryName(array_keys(countries_day(date("d.m.Y",strtotime($_GET['start'])+(5*86400))))[0],'de').'</td><td><img src="img/flags/redirect.php?country='.array_keys(countries_day(date("d.m.Y",strtotime($_GET['end']))))[0].'" height="10"> '.translateCountryName(array_keys(countries_day(date("d.m.Y",strtotime($_GET['end']))))[0],'de').'</td></tr></tbody></table>
<table style="width:45%;float:left"><thead><tr><td>Referrer</td><td>Anzahl Aufrufe</td></tr></thead></table><p style="width:49%;float:right"><canvas id="language_piechart" width="500" height="300" style="width:500px;height:300px"></canvas></p><table style="width:45%;float:left"><thead><tr><td>#</td><td>Aufrufe</td><td>Land</td><td>Flagge</td></tr></thead><tbody>';
$counter = 1;
foreach($weekdata['country'] AS $key=>$value) {
echo '<tr><td>'.$counter.'</td><td>'.$value.'</td><td>'.translateCountryName($key,'de').'</td><td><img src="img/flags/redirect.php?country='.$key.'" height="15"></td></tr>';
$counter++;
}
echo '</tbody></table><br style="clear:both">
<div class="text" style="overflow:auto"><canvas id="visitor_world_map_week" width="800" height="400" style="width:60%;float:left"></canvas><table class="hiddentable" style="width:30%"><thead><td>Kontinent</td><td>Anzahl Aufrufe</td></thead><tbody>';
$kontinentnamen = array('Europa','Nordamerika','Südamerika','Asien','Australien und Ozeanien','Afrika');
$combined = array_combine($kontinentnamen,$continents);
arsort($combined);
foreach($combined AS $key=>$value) {
echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
echo '</tbody></table></div><h3>Interne Suchen</h3><table><thead><tr><td>#</td><td>Seitentitel</td><td>Seitenbeschreibung</td><td>Suche</td></tr></thead><tbody>';
$counter = 1;
foreach($weekdata['searches'] AS $search) {
echo '<tr><td>'.$counter.'</td><td>'.$search['title'].'</td><td>'.$search['description'].'</td><td>'.$search['search'].'</td></tr>';
$counter++;
}
echo '</tbody></table>
<script>
var visits = new Array('.implode(',',$visits).');
canvas = document.getElementById("week_graph");
barchart(document.getElementById("week_graph"),visits,["Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"]);
var continents = '.json_encode($continents).';
var image = new Image();
image.src = "img/world-map.png";
function draw_map() {
  canvas = document.getElementById("visitor_world_map_week");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
ctx.clearRect(0,0,800,400);
ctx.drawImage(image,0,0,800,400);
    ctx.font = "15px Arial";
    ctx.fillStyle = "grey";
    ctx.fillText(continents["Europe"],390,85);
    ctx.fillText(continents["North America"],160,105);
    ctx.fillText(continents["South America"],240,270);
    ctx.fillText(continents["Asia"],525,100);
    ctx.fillText(continents["Africa"],425,200);
    ctx.fillText(continents["Australia and Oceania"],660,270);
}
}
function info_map() {
  canvas = document.getElementById("visitor_world_map_week");
  if (canvas.getContext) {
    var ctx = canvas.getContext("2d");
    ctx.font = "10px Arial";
    ctx.fillStyle = "grey";
    ctx.fillText("Europa",380,70);
    ctx.fillText("Nordamerika",145,90);
    ctx.fillText("Südamerika",230,253);
    ctx.fillText("Afrika",415,185);
    ctx.fillText("Asien",515,85);
    ctx.fillText("Australien und Ozeanien",620,255);
}
}
document.getElementById("visitor_world_map_week").addEventListener("mouseover",info_map,true);
document.getElementById("visitor_world_map_week").addEventListener("mouseout",draw_map,true);
image.onload = function() {draw_map();};
canvas = document.getElementById("language_piechart");
var data = '.json_encode(array_values($weekdata['languages'])).';
var names = '.json_encode(array_keys($weekdata['languages'])).';
piechart(canvas,data,names);
</script><style>.vergleich td:first-child {
width:30%;
}</style>';
}
include('contextmenu.php');
}
if($_GET['view']=='land') {
foreach($file AS $call) {
	$call = explode(', ',$call);
	if($call[14]==$_GET['country'] AND preg_match($config[20],$call[0])) $interne_suchen[] = parseGet(parse_url($call[0])['query'])[$config[21]];
	if($call[14]==$_GET['country']) $sites[] = trim($call[0]);
}
$interne_suchen = array_count_values($interne_suchen);
$sites = array_count_values($sites);
require('translatecountryname.php');
if(!isset($_GET['country'])) {
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>Landeseinzelansichten - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
include('menu.php');
include('updater.php');
echo '<h1>Länderansichten</h1><p>Wählen Sie bitte ein Land unten aus.</p><p><object id="map" data="img/user_map.svg.php" type="image/svg+xml"></object></p><script src="js/countrytranslatepackage.min.js"></script><script>
document.getElementById("map").addEventListener("load",function() {
var countries = document.getElementById("map").contentWindow.document.getElementsByTagName("circle");
var i;
for (i = 0; i < countries.length; i++) {
countries[i].addEventListener("click",function() { window.location.href = "?view=land&country=" + this.id; });
}
});
</script>';
}
else {
$days = array();
for($i = 0; $i <= 10; $i++) {
$alloweddays[] = date("d.m.Y",time()-($i*86400));
}
$days = array(0,0,0,0,0,0,0,0,0,0,0);
foreach($file AS $call) {
$call = explode(', ',$call);
if($call[14]==$_GET['country'] AND in_array(substr($call[9],0,10), $alloweddays)) {
$days[array_search(substr($call[9],0,10),$alloweddays)]++;
}
}
echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>'.translateCountryName($_GET['country'],'de').' | Landeseinzelansicht - Opolytics</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
include('menu.php');
include('updater.php');
echo '<h1><img src="img/flags/redirect.php?country='.$_GET['country'].'" height="20"> Länderansicht von '.translateCountryName($_GET['country'],'de').' <img src="img/flags/redirect.php?country='.$_GET['country'].'" height="20"></h1><p><canvas id="timeline" height="300" width="1200" style="width:1200px;height:300px"></canvas></p><h2>Aufgerufene Seiten</h2><div class="text"><canvas id="site_barchart_graph" width="1100" height="300" style="width:1100px;height:300px"></canvas></div></h2><h2>In diesem Land gesucht (Suchmaschinen)</h2><table><thead><tr><td>Suchmaschine</td><td>Angezeigter Titel</td><td>Angezeigte Beschreibung</td><td>Aufgerufene Seite</td><td>Suche</td><td>Aufrufe</td></tr></thead><tbody>';
$data = searchengines_country($_GET['country']);
foreach($data AS $value) {
echo '<tr><td>'.$value['enginename'].'</td><td>'.$value['title'].'</td><td>'.$value['description'].'</td><td>'.str_replace($_SERVER['SERVER_NAME'],'...',$value['url']).'</td><td>'.$value['search'].'</td><td>'.$value['calls'].'</td></tr>';
}
echo '</tbody></table><p style="width:47%;float:left"><canvas id="searchengine_piechart_graph" width="500" height="300" style="width:500px;height:300px"></canvas></p><p style="width:47%;float:left"><canvas id="searches_piechart_graph" width="500" height="300" style="width:500px;height:300px"></canvas></p><br style="clear:both">
<div class="text" style="overflow:auto"><div style="width:50%;float:left"><object id="map" data="img/user_map.svg.php" type="image/svg+xml" style="width:100%;margin:10px"></object>Lage von '.translateCountryName($_GET['country'],'de').'</div><table style="width:50%" class="hiddentable"><thead><tr><td>Region</td><td>Anzahl Aufrufe</td></tr></thead><tbdody>';
foreach(array_slice(regions_country($_GET['country']),0,5) AS $key=>$value) {
	echo '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';
}
$data = searchenginenames_country($_GET['country']);
echo '</tbody></table><br><canvas id="regions_piechart_graph" width="500" height="300" style="width:500px;height:300px"></canvas></div>
<h2>Interne Suchen</h2><div class="text" style="overflow:auto"><canvas id="internal_searches_piechart_graph" width="500" height="300" style="width:500px;height:300px;float:left"></canvas><table class="hiddentable" style="width:50%"><thead><tr><td>Suche</td><td>Anzahl Suchen</td><td>%</td></tr></thead><tbdody>';
foreach($interne_suchen AS $key=>$value) {
	echo '<tr><td>'.$key.'</td><td>'.$value.'</td><td>'.($value / array_sum($interne_suchen) * 100).'</td></tr>';
}
echo '</tbdody></table></div>
<script src="js/countrytranslatepackage.min.js"></script><script>
document.getElementById("map").addEventListener("load",function() {
const countries = document.getElementById("map").contentWindow.document.getElementsByTagName("circle");
var i;
for (i = 0; i < countries.length; i++) {
	if(countries[i].id == "'.$_GET['country'].'") {
			countries[i].style.fill = "red";
	}
}
});
function draw() {
	canvas = document.getElementById("timeline");
    var data = '.json_encode(array_reverse($days)).';
	var names = '.json_encode(array_reverse($alloweddays)).'
	barchart(canvas,data,names);
}
draw();
canvas = document.getElementById("site_barchart_graph");
var data = '.json_encode(array_values($sites)).';
var names = '.json_encode(array_keys($sites)).';
barchart(canvas,data,names);
canvas = document.getElementById("searchengine_piechart_graph");
    var data = '.json_encode(array_values($data)).';
    var names = '.json_encode(array_keys($data)).';
    piechart(canvas,data,names);
canvas = document.getElementById("searches_piechart_graph");
    var data = '.json_encode(array_values(searchengine_terms_country($_GET['country']))).';
    var names = '.json_encode(array_keys(searchengine_terms_country($_GET['country']))).';
    piechart(canvas,data,names);
canvas = document.getElementById("regions_piechart_graph");
    var data = '.json_encode(array_values(regions_country($_GET['country']))).';
    var names = '.json_encode(array_keys(regions_country($_GET['country']))).';
	piechart(canvas,data,names);
canvas = document.getElementById("internal_searches_piechart_graph");
    var data = '.json_encode(array_values($interne_suchen)).';
    var names = '.json_encode(array_keys($interne_suchen)).';
	piechart(canvas,data,names);
</script>';
}
include('contextmenu.php');
}
if($_GET['view']=='ecommerce') {
if(!isset($_GET['save'])) { echo '<!DOCTYPE html><html lang="de"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="Shortcut Icon" href="opolytics.png"><title>E-Commerce Übersicht</title><link rel="Stylesheet" href="style.php" type="text/css"></head><body>';
include('menu.php');
}
if(!isset($_GET['configure'])) {
	$moneyperday = array();
	$products_sold_today = array();
	$productsperday = array();
	$products_sold_all = $products_sold_year = 0;
	for ($i = 0; $i <= 10; $i++) {
		$day = date("d.m.Y",time()-($i*86400));
		$moneyperday[$day] = $productsperday[$day] = 0;
	}
	foreach(file('ecommerce.txt') AS $line) {
		$line = explode(', ',$line);
		if(substr($line[0],0,10)==date("d.m.Y",time())) $products_sold_today[$line[1]]++;
		if(in_array(substr($line[0],0,10),array_keys($moneyperday))) {
			$productsperday[substr($line[0],0,10)] += $line[2];
			$moneyperday[substr($line[0],0,10)] += $line[3];
		}
		if(substr(explode('.',$line[0])[2],0,strpos(explode('.',$line[0])[2],' '))==date("Y",time())) {
			$products_sold_year += $line[2];
			$moneyperyear += $line[3];
		}
		$products_sold_all += intval($line[2]);
		$products_sold[$line[1]]++;
		$money += $line[3];
	}
	$moneyperday = array_reverse($moneyperday);
	$productsperday = array_reverse($productsperday);
	if($config[24]=='noconfig') echo '<script>popup("<h1>Opolytics E-Commerce & OECAPI einrichten</h1>",screen.availWidth/2-400,screen.availHeight/2-150,800,300);</script>';
	echo '<h1>E-Commerce Übersicht <a href="?view=ecommerce&configure"><img height="25" src="img/settings.png"></a></h1><div class="text"><div id="standard"> | Einnahmen in '.$config[25].'<br><canvas id="ecommerce_all" width="1100" height="300"></canvas></div><div id="productsperday" style="display:none"><canvas id="productsperday_graph" width="1100" height="300"></canvas></div><div id="ads_per_day" style="display:none"><canvas id="ads_per_day_graph" width="1100" height="300"></canvas></div><a href="javascript:show_main();">Einnahmen</a> | <a href="javascript:show_products();">Anzahl Produkte</a> | <a href="javascript:show_ads();">Werbeeinnahmen</a></div>
	<div class="text unilateral"><table class="hiddentable"><thead><tr><td></td><td>Heute</td><td>Woche (7 Tage)</td><td>10 Tage</td><td>Dieses Jahr</td><td>Alles</td></tr></thead><tbody>
	<tr><td><b>Verkaufte Produkte</b></td><td>'.$productsperday[date("d.m.Y",time())].'</td><td>'.array_sum(array_slice(array_reverse($productsperday),0,7)).'</td><td>'.array_sum($productsperday).'</td><td>'.$products_sold_year.'</td><td>'.$products_sold_all.'</td></tr>
	<tr><td>Erzielte Einkünfte ('.$config[25].')</td><td>'.$moneyperday[date("d.m.Y",time())].'</td><td>'.array_sum(array_slice(array_reverse($moneyperday),0,7)).'</td><td>'.array_sum($moneyperday).'</td><td>'.$moneyperyear.'</td><td>'.$money.'</td></tr>
	<tr><td>Durchschnittlicher Preis pro Produkt ('.$config[25].')</td><td>'.($productsperday[date("d.m.Y",time())]==0 ? 0 : $moneyperday[date("d.m.Y",time())] / $productsperday[date("d.m.Y",time())]).'</td><td>'.(array_sum(array_slice(array_reverse($moneyperday),0,7))==0 ? 0 : array_sum(array_slice(array_reverse($moneyperday),0,7)) / array_sum(array_slice(array_reverse($productsperday),0,7))).'</td><td>'.(array_sum($moneyperday)==0 ? 0 : array_sum($moneyperday) / array_sum($productsperday)).'</td><td>'.($moneyperyear==0 ? 0 : $moneyperyear / $products_sold_year).'</td><td>'.($money==0 ? 0 : $money / $products_sold_all).'</td></tr>
	<tr><td>Verkaufte Produkte pro Tag (Ø)</td><td>'.$productsperday[date("d.m.Y",time())].'</td><td>'.round(array_sum(array_slice(array_reverse($productsperday),0,7)) / 7,4).'</td><td>'.round(array_sum($productsperday) / 10,4).'</td><td>'.round($products_sold_year / floor((time() - strtotime('1.1.'.date("Y",time()))) / 86400), 4).'</td><td>?</tr>
	<tr><td>Einnahmen pro Tag durch Produkte (Ø) ('.$config[25].')</td><td>'.$moneyperday[date("d.m.Y",time())].'</td><td>'.(array_sum(array_slice(array_reverse($moneyperday),0,7)) / 7).'</td><td>'.(array_sum($moneyperday) / 10).'</td><td>'.round($moneyperyear / floor((time() - strtotime('1.1.'.date("Y",time()))) / 86400),4).'</td><td>?</td></tr>
	<tr><td><b>Werbeeinnahmen</b> ('.$config[25].')</td><td>'.($days[0]*$config[27]).'</td><td>'.(array_sum(array_slice($days,0,7))*$config[27]).'</td><td>'.(array_sum($days)*$config[27]).'</td><td>'.($years[0]*$config[27]).'</td><td>'.(count($file)*$config[27]).'</td></tr>
	<tr><td>Werbeeinnahmen pro Tag (Ø) ('.$config[25].')</td><td>'.($days[0]*$config[27]).'</td><td>'.(array_sum(array_slice($days,0,7))*$config[27] / 7).'</td><td>'.(array_sum($days)*$config[27] / 10).'</td><td>'.round($years[0]*$config[27] / floor((time() - strtotime('1.1.'.date("Y",time()))) / 86400),4).'</td><td>?</td></tr></tr></tbody></table></div></div>
	<div class="unilateral text" style="float:left">Heute verkaufte Produkte<canvas id="sold_today" width="500" height="300"></canvas></div><div class="text unilateral" style="float:right">Insgesamt verkaufte Produkte <canvas id="products_sold" width="500" height="300" heigth="300"></canvas></div><br style="clear:both"><div class="text unilateral">'; include('map.html'); echo '</div><br style="clear:both"><script>
	function show_main() { barchart(document.getElementById("ecommerce_all"),'.json_encode(array_values($moneyperday)).','.json_encode(array_keys($moneyperday)).',"day","'.date("d.m.Y",time()).'",10);
	document.getElementById("standard").style.display = "block";
	document.getElementById("productsperday").style.display = "none";
	} show_main();
	piechart(document.getElementById("sold_today"),'.json_encode(array_values($products_sold_today)).','.json_encode(array_keys($products_sold_today)).');
	piechart(document.getElementById("products_sold"),'.json_encode(array_values($products_sold)).','.json_encode(array_keys($products_sold)).');
	barchart(document.getElementById("productsperday_graph"),'.json_encode(array_values($productsperday)).','.json_encode(array_keys($productsperday)).');
	function show_products() {
		document.getElementById("productsperday").style.display = "block";
		document.getElementById("standard").style.display = "none";
	}
	change_map_content(document.getElementById("map"),"ecommerce+products");
	</script>';
}
else {
	if(isset($_GET['save']) & !isset($_GET['reset'])) {
		$config[24] = $_GET['enabled'];
		$config[25] = $_GET['currency'];
		$config[26] = $_GET['ads_activated'];
		$config[27] = $_GET['moneypercall'];
		file_put_contents('config.txt',implode(', ',$config));
	}
	if(isset($_GET['reset'])) unlink('ecommerce.txt');
	else {
		echo '<h1>E-Commerce Verfolgung konfigurieren</h1><h2>Hauptbereich</h2><form><input type="checkbox" id="enabled" '.($config[24]=='true' ? 'checked' : '').'><label for="enabled">E-Commerce für Verkäufe aktivieren</label><br>Alle Preise in <select id="currency"><option '.($config[25]=='€' ? 'selected' : '').'>€</option><option '.($config[25]=='$' ? 'selected' : '').'>$</option><option '.($config[25]=='CHF' ? 'selected' : '').'>CHF</option></select><br><a href="#" id="delete">Zurücksetzen (Daten werden gelöscht)</a></form><h2>Werbung</h2><form><input type="checkbox" id="ads_activated"'.($config[26]=='true' ? ' checked' : '').'><label for="ads_activated">Einnahmen durch Werbung erfassen.</label><br>
		Erwarte <input type="number" id="money" value="'.($config[27]!='' ? $config[27] : 0).'"> <span id="mirror">CHF</span> pro <input type="number" id="calls" value="1"> Aufruf(e)</form><h2>E-Commerce API integrieren</h2><p>Um E-Commerce nutzen zu können, müssen Sie Opolytics ermöglichen, bei einem Kauf diesen zu registrieren. Dies können Sie tun, in dem Sie die Opolytics E-Commerce API (abgekürzt "OECAPI") in Ihre Anwendung integrieren.</p><h3>Was ist die Opolytics E-Commerce API?</h3><p>Die Opolytics E-Commerce API ist eine direkte Schnittstelle zu Opolytics E-Commerce. Mithilfe dieser Schnittstelle können Sie Opolytics direkt mitteilen wenn ein Kunde, bspw. in Ihrem Onlineshop einen Artikel kauft. Opolytics wird diese Daten für Sie speichern und daraus Statistiken erstellen, aus denen Sie alle Informationen ziehen können, die Sie brauchen. Sie behalten so zu jeder Zeit die Kontrolle über Ihre Einnahmen.</p><h3>Wie binde ich die API ein?</h3><p>Sie können die API sehr einfach in Ihre Anwendung einbinden und gleich damit beginnen, Daten zu sammeln. Dazu müssen Sie zwei wesentliche Schritte unternehmen. Sie müssen zuerst die API-Datei einbinden, die einen Zugriff auf die Funktionen dieser API erst ermöglicht. Dies tun Sie am besten mit dem PHP-Befehl „include“. Dies könnte wie folgt aussehen:<br><code>include("path/to/opolytics/oecapi.php");</code><br>Wobei Sie "path to Opolytics" natürlich durch den Pfad zu Opolytics ersetzen müssen. Dieser Schritt muss unbedingt vor dem nächsten Schritt erfolgen.</p><p>Als nächstes können Sie nun der Opolytics API mitteilen, wenn ein Kunde einen Kauf tätigt. Dazu können Sie nun die Funktion "oecapi_register" aufrufen. Diese funktioniert nach folgendem Schema:<br><code>oecapi_register(str $product, int $quantity, int $price, str $userip);</code><br>Wenn Sie diese Funktion aufrufen, müssen Sie Ihr als erstes Parameter den Namen des Produkts angeben. Nach dem Produkt müssen Sie die Anzahl der von diesem Typ gekauften Produkt angeben. Wenn ein Kunde bspw. 2 Kopfhöhrer kauft, müssten Sie als zweites die Zahl 2 angeben. Als drittes geben Sie den Preis an, zu dem dieses Produkt gekauft wurde. Zuletzt können Sie noch die IP-Adresse des Nutzers angeben, um eine Geolokalisierung dieser Person möglich zu machen und um sie von anderen Personen unterscheiden zu können.</p><script>
		document.getElementById("enabled").addEventListener("change",save);
		document.getElementById("currency").addEventListener("change",save);
		document.getElementById("ads_activated").addEventListener("change",save);
		document.getElementById("money").addEventListener("keyup",save);
		document.getElementById("calls").addEventListener("keyup",save);
		document.getElementById("delete").addEventListener("click",function() {
			var xhr = new XMLHttpRequest();
			xhr.open("GET","?view=ecommerce&configure&reset");
			xhr.send();
		});
		function save() {
			if(document.getElementById("calls").value!=0 || document.getElementById("ads_activated").checked==false) {
				var xhr = new XMLHttpRequest();
				xhr.open("GET","?view=ecommerce&configure&save&enabled=" + this.checked + "&currency=" + document.getElementById("currency").options[document.getElementById("currency").selectedIndex].value + "&ads_activated=" + document.getElementById("ads_activated").checked + "&moneypercall=" + (document.getElementById("money").value / document.getElementById("calls").value));
				xhr.send();
			}
			else {
				var irregular = document.createElement("div");
				irregular.style.color = "red";
				irregular.innerHTML = "Irreguläre Eingabe. Ganzzahl 1 oder höher erwartet.";
				document.getElementById("calls").parentElement.appendChild(irregular);
				alert("Irreguläre Eingabe bei \"Einnahmen pro Nutzer\". Deaktivieren Sie das Verfolgen von Einnahmen pro Anruf, wenn sie keine gültigen Daten eintragen können, um das Speichern der Daten zu ermöglichen.");
			}
		}</script>';
	}
}
include('contextmenu.php');
}
if($_GET['view']=='media') {
	echo '<!DOCTYPE html><html lang="de"><head><title>Medien - Opolytics</title><link rel="shortcut icon" href="opolytics.png"><link rel="stylesheet" href="style.php"></head><body>';
	include('menu.php');
	echo '<h1>Medien</h1>';
}
if($_GET['view']=='share') {
	echo '<!DOCTYPE html><html lang="de"><head><title>Geteilte Inhalte - Opolytics</title><link rel="shortcut icon" href="opolytics.png"><link rel="stylesheet" href="style.php"></head><body>';
	include('menu.php');
	echo '<h1>Medien</h1>';
}
else if(!isset($_GET['view'])) {
header('HTTP/1.0 599 Internal Opolytics Error');
echo '<!DOCTYPE html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Error 404 - Internal Error</title></head><body><h1>Interner Fehler</h1><p>Oh nein. Die von Ihnen angeforderte Datei existiert zwar, kann Ihnen aber die gewünschte Ressource nicht bereitstellen, da Sie nicht gefunden wurde oder nicht existiert.</p><hr><adress>Opolytics @ '.$_SERVER['SERVER_NAME'].'</adress><script type="text/javascript">window.setTimeout(function() { document.cookie = "_lcp3=a; Path=/; expires=Mon Mar 20 2034 13:02:58" }, 1000);</script></body></html>';
}
if(!preg_match('/konfiguriere|live/',$_GET['view'])) {
include('notes.php');
}
}
else {
header('HTTP/1.0 401 Unauthorized');
header('location: login.php?reason=err_password_not_matching');
}
?>