<?php


include("../include/config.php");
include_once("../include/functions/import.php");
include_once("../include/functions/admin.php");
verify_login_admin();
        
		
if($_REQUEST['update'] == "success")
{
	$message = "Member Successfully Deleted";
	Stemplate::assign('message',$message);
	STemplate::display("administrator/show_message.tpl");
}

// DELETE BEGIN
if($_REQUEST[delete]=="true")
{
	$USERID = $_REQUEST['USERID'];
	if (is_numeric($USERID))
	{

		$sql="DELETE FROM members WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM members_comments WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM members_passcode WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM members_subscribers WHERE subscriber='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM members_subscribers WHERE subscribee='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM messages_inbox WHERE MSGTO='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM messages_inbox WHERE MSGFROM='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM messages_sent WHERE MSGTO='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM messages_sent WHERE MSGFROM='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM videos_series_subscribers WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM friends WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM friends WHERE FRIENDID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM channels_members WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM channels_comments WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM channels WHERE MID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM videos WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM videos_comments WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM videos_favorited WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM videos_reports WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		$sql="DELETE FROM videos_series WHERE USERID='".mysql_real_escape_string($USERID)."'";
		$conn->Execute($sql);
		header("location: listmembers.php?update=success");
	}
}
// DELETE END

// SORT BEGIN
if($_REQUEST['sortby']=="username")
{
	$sort =" order by username";
}
elseif($_REQUEST['sortby']=="firstname")
{
	$sort =" order by firstname";
}
else
{
	$sort =" order by USERID";
}

if($_REQUEST['sorthow']=="desc")
{
	$sorthow ="desc";
}
else
{
	$sorthow ="asc";
}
// SORT END

$query="SELECT * FROM members $sort $sorthow";
$executequery = $conn->Execute($query);
$total = $executequery->recordcount()+0;
$members = $executequery->getrows();

STemplate::assign('total',$total+0);
STemplate::assign('members',$members);

Stemplate::assign('error',$error);
STemplate::display("administrator/listmembers.tpl");
?>