<?php
if ((isset($_GET["q"]) && !empty($_GET["q"]) && is_numeric($_GET["q"])) && (isset($_GET["p"]) && !empty($_GET["p"]) && is_numeric($_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 ($p!=$q)
	{
	if($q==1)
		{
		db_open();
		$x="SELECT * FROM users WHERE user_id='$p'";
		$row=mysql_fetch_array(mysql_query($x));
		$device_id=$row['device_id'];
		$sql="DELETE FROM users WHERE user_id='$p'";
		@ $result=mysql_query($sql);
		if ($result!=0)
			{
			$sql1="DELETE FROM messages WHERE user_id='$p'";
			@ $resulto=mysql_query($sql1);
			$sql1="DELETE FROM troubleshoots WHERE user_id='$p'";
			@ $resulto=mysql_query($sql1);
			$sql1="DELETE FROM charts WHERE device_id='$device_id'";
			@ $resulto=mysql_query($sql1);
			$sql1="DELETE FROM schedule_scenarios WHERE device_id='$device_id'";
			@ $resulto=mysql_query($sql1);
			$sql1="DELETE FROM scenarios WHERE device_id='$device_id'";
			@ $resulto=mysql_query($sql1);
			$sql1="DELETE FROM devices WHERE device_id='$device_id'";
			@ $resulto=mysql_query($sql1);
			$sql1="DELETE FROM data WHERE device_id='$device_id'";
			@ $resulto=mysql_query($sql1);
			echo "User Deleted!";
			}
			
		else
			{
			echo "Database problem!";
			}
		}
	db_close();
	}
	else
		{
		db_open();
		$sql1="DELETE FROM messages WHERE message_id='$q'";
		@ $resulto=mysql_query($sql1);
			if ($resulto!=0)
				{
				echo"Message deleted!";
				}
		db_close();
		}
}

?>