<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.7 ( www.phpsugar.com )
// +------------------------------------------------------------------------+
// | PHP Melody IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2011 PhpSugar.com. All rights reserved.
// +------------------------------------------------------------------------+

session_start();

require('config.php');

function get_random_video( $category_id = '')
{
	$sql = "SELECT uniq_id FROM pm_videos";
	if($category_id != '')
		$sql .= " WHERE category='".$category_id."'";
	$sql .= " ORDER BY RAND() LIMIT 1";
	
	$result = @mysql_query($sql);
	if(!$result)
		return false;
	$video = @mysql_fetch_assoc($result);
	mysql_free_result($result);
	
	return $video['uniq_id'];
}

$video_id = get_random_video();
if($video_id === false)
	$location = _URL."index."._FEXT;
else
	$location = makevideolink($video_id);

@header("Location: ".$location);
exit();
?>