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

// DELETE BEGIN
if($_REQUEST[delete]=="true")
{
$VIDEOID = htmlentities(strip_tags($_REQUEST[VIDEOID]));
$sql="DELETE FROM videos WHERE VIDEOID='".mysql_real_escape_string($VIDEOID)."'";
$conn->Execute($sql);
$sql="DELETE FROM videos_comments WHERE VIDEOID='".mysql_real_escape_string($VIDEOID)."'";
$conn->Execute($sql);
$sql="DELETE FROM videos_favorited WHERE VIDEOID='".mysql_real_escape_string($VIDEOID)."'";
$conn->Execute($sql);
$sql="DELETE FROM videos_reports WHERE VIDEOID='".mysql_real_escape_string($VIDEOID)."'";
$conn->Execute($sql);
header("location: listvideos.php?update=success");
}
// DELETE END

// SORT BEGIN
if($_REQUEST['sortby']=="title")
{
	$sort =" order by title";
}
elseif($_REQUEST['sortby']=="description")
{
	$sort =" order by description";
}
else
{
	$sort =" order by VIDEOID";
}

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

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

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

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