<?php
if ((isset($_GET["q"]) && !empty($_GET["q"]) && $_GET["q"]<=3 || $_GET["q"]==7) && (isset($_GET["p"]) && !empty($_GET["p"])))
{
if (file_exists("functions/site_functions.php"))
	{
	include_once("functions/site_functions.php");
	}
else
	{
include_once("../../functions/site_functions.php");
	}
$q=$_GET["q"];
$p=$_GET["p"];	
if($q==1)
	{
		if (is_numeric($p))
		{
		db_open();
		$sql="SELECT * FROM users WHERE device_id='$p'";
		$result=mysql_numrows(mysql_query($sql));
		if ($result==0)
				{
				echo '<a class="valid">Done!</a>';
				}
			else
				{
				echo '<a class="invalid">Already exists!</a>';
				}
			db_close();
		}
		else
		{
		echo '<a class="invalid">Invalid Data!</a>';
		}
	}
else if ($q==2 || $q==7)
	{
	if(preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $p))
	{
		db_open();
		$sql="SELECT * FROM users WHERE email='$p'";
		$result=mysql_numrows(mysql_query($sql));
		if ($result==0)
				{
				
				if ($q==7)
					{
					echo '<a class="valid">Done!</a><input type="button" value="Save" onclick="change_email(2);" />';
					}
				else
					{
					echo '<a class="valid">Done!</a>';
					}
				}
			else
				{
				echo '<a class="invalid">Already exists!</a>';
				}
			db_close();
	}
	else
		{
		echo '<a class="invalid">Invalid Data!</a>';
		}
	}
else
	{
	if ($p!=1 && $p!=8)
		{
		echo '<a class="invalid">Invalid Data!</a>';
		}
	else if ($p=="")
		{
		echo '<a class="invalid">Not Empty!</a>';
		}
	else
		{
		echo '<a class="valid">Done!</a>';
		}
	}
}
?>