<?php session_start(); ob_start();
include("connecting.php");
include("login_cookie.php");

$design = "d2";

function loging_out() {

/////////////////////

$login_time = $_SESSION['time'];
$logout_time = time();

$sec = $logout_time - $login_time;
echo 'Du har v&aelig;ret online i ' . $sec . ' sekunder<br />';
$min = floor($sec / 60);
echo 'Du har v&aelig;ret online i ' . $min . ' minutter<br />';
$hour = floor($min / 60);
echo 'Du har v&aelig;ret online i ' . $hour . ' timer<br />';
//$coins = floor($sec / 360);
$coins = $hour*10;
echo 'Det giver dig ' . $coins . ' pycoins<br /><br /><br />';

$bnefore = mysql_query("SELECT * FROM `pytox_community` WHERE `bruger` LIKE '{$_COOKIE[user]}' LIMIT 1") or die(mysql_error());

	while ($before = mysql_fetch_array($bnefore)) {
$pycoins = $coins+$before[coins];

echo 'Førhenværende pycoins: '.$before[coins].'!<br />';

echo 'Opdaterede pycoins: '.$pycoins.'!<br />';

echo 'Førhenværende timer: '.$before[timer].'!<br />';

$optimer = floor($hour+$before[timer]);

$totime = floor($hour);

echo 'Timer der lægges til er '.$totime.'!<br />';

echo 'Opdaterede timer: '.$optimer.'!<br />';

mysql_query("UPDATE `pytox_community` SET `timer`='{$optimer}', `coins`='{$pycoins}' WHERE `bruger` LIKE '{$_COOKIE["user"]}' LIMIT 1") or die(mysql_error());
	}

/////////////////////

setcookie("user", "0");
setcookie("pass", "0");
setcookie("com", "0");
setcookie("timein", "0");
setcookie("inactive", "0");

//unset($_COOKIE["user"]);
//unset($_COOKIE["pass"]);
//unset($_COOKIE["com"]);
//unset($_COOKIE["timein"]);
//unset($_COOKIE["inactive"]);

unset($_SESSION["pycoins"]);
}


if ($_GET[logout] == "true") {

if ($_COOKIE[user] == "0" && $_COOKIE[pass] == "0" && $_COOKIE[com] == "0") {

//
//Du er nu logget korrekt ud.
//<br />
//<br />
//(Bot: Brugeren loggede ud uden problemer, tak for benyttelse af communityet!)
//

header("Location: index.php?message=loggedout");

} else {
//print "Du er ikke logget ud... (Fejlkode: 81287)";
header("Location: index.php?message=failure&errorid=81287");
}

} else if ($_GET["mode"] == "inactive") {

loging_out();
$header1 = "Location: /pytox/designs/".$design."/index.php?site=Logout&message=inactivelogout";
header($header1);

} else {

loging_out();
$header2 = "Location: /pytox/designs/".$design."/index.php?site=Logout&logout=true";
header($header2);
}
?>