<?php

	ob_start();	

	error_reporting(0);
	session_start();
	
	require_once('../conf/definitions.php');
	require_once('../conf/objs.php');
	require_once('../conf/functions.php');
	
	$id = fnAdjustID();
	
	$dba = new db;
	
	if($_SESSION['my_id'] == 1)
	{
		if(!file_exists('../lib/log/referer.txt'))
		{
			$fp = fopen('../lib/log/referer.txt', 'w');
		}
		else 
		{
			$fp = fopen('../lib/log/referer.txt', 'a');
		}
		fputs($fp, "Ref: ".$HTTP_REFERER."\n");
		
		fclose($fp);
	}
	
//	dump($_COOKIE['play_melody']);
	
//	if(isset($_COOKIE['play_melody']) && $_COOKIE['play_melody'] == 1)
	{
		$file = $dba->GetOne('mobile_melody', $id, 'file');
		$cesta = $filename = "../melody/".$file;
		$fp = fopen('../lib/log/content.txt', 'a');
		if(file_exists($cesta))
		{
			$video = file_get_contents($filename, 'rb');
			$size = strlen($video);
			header("Content-Disposition: inline; filename=".basename($filename));
			header("Content-Transfer-Encoding: binary");
			header("Content-Length: " . $size);
			header("Pragma: public");
			header("Expires: 0");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			
			readfile($filename);
//			readfile($cesta);
			
			$buffer = ob_get_contents();
			fputs($fp, $buffer);
			ob_flush();
		}
		else 
		{
			fputs($fp, "NEPreslo");
		}
		fclose($fp);
	}
//	else 
//	{
//		dump(true);
//	}
	

	

?>