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

$design = "d2";

function loging_out() {

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

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

	while ($before = mysql_fetch_array($bnefore)) {

$tid = $before[timer];
$samlign = time() - $_COOKIE[timer];



$min = $samlign / 60;

//if($minutter > 60){
//$regn = $minutter - 60;
//$min = round($regn);
//}else{
//$min = round($minutter);
//}

$onlinetid = time()-$_COOKIE[timer];

$timer = round($min / 60);
//$tiden = $timer+$min;
$tiden = round($min);

$coins = $timer*10;

$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($tiden+$before[timer]);

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());

mysql_query("UPDATE `pytox_community` SET `status`='0' WHERE `bruger` LIKE '{$_COOKIE["user"]}' LIMIT 1") or die(mysql_error());
	}

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

if ($_COOKIE['remember'] != "1") {
setcookie("user", "", time()-60000, "/", $_SERVER["HTTP_HOST"]);
setcookie("pass", "", time()-60000, "/", $_SERVER["HTTP_HOST"]);
setcookie("com", "", time()-60000, "/", $_SERVER["HTTP_HOST"]);
}
setcookie("timein", "", time()-60000, "/", $_SERVER["HTTP_HOST"]);
setcookie("inactive", "", time()-60000, "/", $_SERVER["HTTP_HOST"]);
setcookie("timer", 0, time()-60000, "/", $_SERVER["HTTP_HOST"]);


//setcookie("user", "0", "/", time()+3600000, $_SERVER["HTTP_HOST"]);
//setcookie("pass", "0", "/", time()+3600000, $_SERVER["HTTP_HOST"]);
//setcookie("com", "0", "/", time()+3600000, $_SERVER["HTTP_HOST"]);
//setcookie("timein", "0", "/", time()+3600000, $_SERVER["HTTP_HOST"]);
//setcookie("inactive", "0", "/", time()+3600000, $_SERVER["HTTP_HOST"]);

//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") {
if (!isset($_COOKIE[user]) && !isset($_COOKIE[pass]) && !isset($_COOKIE[com])) {

//
//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);
}
?>