<?php
//require_once("../../mysql_connect.php");
$_SESSION['username']="guest";
$_SESSION['password']="password";
$_SESSION['profilepicture']="../account_data/guest.png";

/*if(isset($_POST['logout'])){
	if($set_logout_status==true){
		if($_SESSION['username']!="guest"){
			$statusf=simplexml_load_file("status.xml");
			$file = fopen("status.xml","w");
			$userexist=false;
			for($i=0;$i<=count($statusf->user);$i++){
				if($statusf->user[$i]==$_SESSION['username']){
					$userexist=true;
					break;
				}
				if($userexist==true){break;}
			}
			$i=0;
			fwrite($file, '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status>'."\n");
			$wrote=false;
			foreach($statusf as $status){
				if(($statusf->user[$i]==$_SESSION['username'])||($userexist==false)){
					if($userexist==false){
						fwrite($file, '	<user time="'.$statusf->user[$i]['time'].'">'.$statusf->user[$i]."</user>\n");
					}
					if($wrote==false){fwrite($file, '	<user time="offline">'.$_SESSION['username']."</user>\n"); $wrote=true;}
				} else {
					fwrite($file, '	<user time="'.$statusf->user[$i]['time'].'">'.$statusf->user[$i]."</user>\n");
				}
				$i++;
			}
			fwrite($file, '</status>');
			fclose($file);
		}
	}
	$_SESSION['username']="";
	$_SESSION['password']="";
}


if($_SESSION['username']==""||$_SESSION['username']=="guest"){
	if($_POST['username']==""){
		$_SESSION['username']="guest";
		$_SESSION['password']="password";
	} else {
		$_SESSION['username']=$_POST['username'];
		$_SESSION['password']=$_POST['password'];
	}
}
$_POST['username']="";
$_POST['password']="";

if($_SESSION['username']!="guest"){
	$stmt=$dbc->prepare("select username,password from ".$dbc_ver_accounts." where username=?");
	$stmt->execute([$_SESSION['username']]);
	$getuser=$stmt->fetch();
	if($getuser[0]==$_SESSION['username']){
		if(password_verify($_SESSION['password'],$getuser[1])){
			$login_correct="true";
		} else {
			$_SESSION['username']="guest";
			$_SESSION['password']="password";
			$_SESSION['errormsglogin']="login info is incorrect";
			$login_correct="false";
		}
	} else {
		$_SESSION['username']="guest";
		$_SESSION['password']="password";
		$_SESSION['errormsglogin']="login info is incorrect";
		$login_correct="false";
	}
}
$stmt=null;
$getuser=null;
if(file_exists("../account_data/".$_SESSION['username'].".png")){
	$_SESSION['profilepicture']="../account_data/".$_SESSION['username'].".png";
} elseif(file_exists("../account_data/".$_SESSION['username'].".jpg")){
	$_SESSION['profilepicture']="../account_data/".$_SESSION['username'].".jpg";
} elseif(file_exists("../account_data/".$_SESSION['username'].".gif")){
	$_SESSION['profilepicture']="../account_data/".$_SESSION['username'].".gif";
} else {
	$_SESSION['profilepicture']="../account_data/guest.png";
}*/
?>