<?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 = "Channel Successfully Deleted";
	Stemplate::assign('message',$message);
	STemplate::display("administrator/show_message.tpl");
}

// DELETE BEGIN
if($_REQUEST[delete]=="true")
{
$CID = htmlentities(strip_tags($_REQUEST[CID]));
$sql="DELETE FROM channels WHERE CID='".mysql_real_escape_string($CID)."'";
$conn->Execute($sql);
$sql="DELETE FROM channels_comments WHERE CID='".mysql_real_escape_string($CID)."'";
$conn->Execute($sql);
$sql="DELETE FROM channels_members WHERE CID='".mysql_real_escape_string($CID)."'";
$conn->Execute($sql);
$sql="DELETE FROM channels_videos WHERE CID='".mysql_real_escape_string($CID)."'";
$conn->Execute($sql);
header("location: listchannels.php?update=success");
}
// DELETE END

// SORT BEGIN
if($_REQUEST['sortby']=="name")
{
	$sort =" order by name";
}
elseif($_REQUEST['sortby']=="details")
{
	$sort =" order by details";
}
else
{
	$sort =" order by CID";
}

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

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

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

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