<?php
	require_once("../system.engine/system.core.php");
	$l->setPrefix("ajax.handle.submit.signin");
	
	$mPong = array();
	$a = &$mPong;
	$p = &$_POST;
	
	global $systemHandler;
	$systemExecution = $systemHandler->loadHandler("EXECUTION");
	$systemHash = $systemHandler->loadHandler("HASH");
	$systemSession = $systemHandler->loadHandler("SESSION");
	/* ### DO YOUR CODES ONLY FROM HERE ### */
	
	$mPassword = $systemHash->hashString($p["loginPass"]);
	
	if(strlen($p["loginMail"]) > 0 && strlen($p["loginPass"]) > 0) {
		if($systemExecution->runQuery("SELECT COUNT(id) AS userCount FROM web_user WHERE mail = '%s' AND password = '%s'", array($p["loginMail"], $mPassword))->fetch_object()->userCount > 0) {
			$systemSession->appendSession("USER", $systemExecution->runQuery("SELECT id FROM web_user WHERE mail = '%s' AND password = '%s'", array($p["loginMail"], $mPassword))->fetch_object()->id);
			$a["isValid"] = true;
			$systemExecution->runQuery("UPDATE web_user SET signin_time = '%s' WHERE mail = '%s' AND password = '%s'", array(time(), $p["loginMail"], $mPassword));
		}
		else $a["isValid"] = $l->getValue("emailpasswrong");
	} else $a["isValid"] = $l->getValue("filloutfields");
	
	/* ### DO NOT CHANGE ANYTHING FROM HERE ### */
	header("Content-Type: application/json");
	echo json_encode($mPong);
?>