<?php
	date_default_timezone_set('Europe/Madrid'); 
	require("../config/config.php");
	if (!isset($_SESSION)){
		session_name(SESSION);
		session_start();
	}
	require("../config/functions.php");
    header('Content-Type: text/html; charset=UTF-8');

    if (!empty($_POST["type"]) && !empty($_POST["text"])){
        $type = GetConexion()->real_escape_string($_POST["type"]);
        $text = GetConexion()->real_escape_string($_POST["text"]);
        
        $list = ["username","email","name"];
        if (in_array($type,$list)){
            if ($type == "username"){
                $a = mysqli_fetch_object(mysqli_query(GetConexion(), "select COUNT(*) as count from ".DB_ACCOUNT.".account where login = '".$text."' limit 1;"));
                if ($a->count > 0){
                    echo "<img src='style/imgs/exclamation.png'>";
                }
                else{
                    echo "<img src='style/imgs/accept.png'>";
                }
            }
            else if ($type == "email"){
                if (filter_var($text, FILTER_VALIDATE_EMAIL)){
                    echo "<img src='style/imgs/accept.png'>";
                }
                else{
                    echo "<img src='style/imgs/exclamation.png'>";
                }
            }
            else if($type == "name"){
                if (strlen($text) >= 4){
                    echo "<img src='style/imgs/accept.png'>";
                }
                else{
                    echo "<img src='style/imgs/exclamation.png'>";
                }
            }
        }
        else{
            echo "<img src='style/imgs/exclamation.png'>";
        }
    }
?>