<?php
require (dirname(__FILE__)."/./appshared.php");

pageHeader();

$recId = $_GET['id'];


$rec = app()->selectOne("select * from pvrrecordings where id='$recId'");



$chId = $rec['channelId'];
$startEpoch = $rec['startEpoch'];
$stopEpoch = $rec['stopEpoch'];

print "
<h1>".tt("Recording")."</h1>
<hr>
";




$ch = $channels[$chId];
$chNo = $ch['chNo'];
$chShort = $ch['publicShort'];
$chName  = $ch['publicName'];
$bi = epgAppFixImagePath($ch['blackIcon']);
if ( strlen($bi) > 0 ) {
	print "<img style='width:120px; ' src=\"$bi\"><br>";
}
print "<div style='height:8px'></div>";
print tt("Channel").": #$chNo $chShort, $chName <br>";

$xmltvChannelId = $ch['xmltvChannelId'];



$show = $rec;


$realStart= $show['startEpoch'];
$realStop= $show['stopEpoch'];

$ds = $realStop - $realStart;
$durSecs = $realStop - $realStart;
$durHrs = floor($durSecs / (60*60));
$rest = $durSecs - $durHrs*60*60;
$durMins = floor($rest / (60));
$rest = $durSecs - $durMins * 60;
$dur  = "";
if ( $durHrs > 0 ) { 
	$dur .= $durHrs ."h ".$durMins . " min";;
} else { 
	$dur .= $durMins." mins";
}


$chId = $show['chId'];
$startEpoch = $show['startEpoch'];
$stopEpoch = $show['stopEpoch'];
$id = $show['id'];

print tt("When").": ".date("h:i a", $realStart)."  ";
print tt(" - ").date("h:i a", $realStop)." &nbsp;&nbsp;&nbsp;, ";
print "<label>".tt("Duration").": </label>" . $dur;
print "<br>";

	$key = $show['pvrUniqueKey'];

	$pvrRecordingId = $recId;
	print "<label>".tt("Recording").": </label>";	
	print "<i style='color:#ff0000 ;margin-right:24px;' class='fa fa-circle'></i>";
	print tt("YES");
	
	print "&nbsp;&nbsp;&nbsp;&nbsp;";
	$recStatus = $show['recStatus'];
	$recStatusColor = "green";
	if ( $recStatus == "PENDING" ) { $recStatusColor = "yellow";}
	if ( $recStatus == "RECORDING" ) { $recStatusColor = "red";}
	$recStatusHtml = "<font style='color:$recStatusColor;'>".tt($recStatus)."</font>";
	print $recStatusHtml;

	print "<br>";



print "<label>".tt("Title").": </label><font style='font-size:1.5em;margin-top:24px;'>" . urldecode($show['title'])."</font>";
print "<br>";
print "<label>".tt("Sub-Title").": </label>". urldecode($show['subTitle']);
print "<br>";
print "<label>".tt("Category").": </label>". urldecode($show['category']);
print "<br>";
print "<label>".tt("Rating").": </label>". urldecode($show['rating']);
print "<br>";

$desc = "<div class='multiLine'>";
$desc .= str_replace(":", " : ", str_replace(",", "<br>", urldecode($show['desc'])));
$desc .= "</div>";
print "<label>".tt("Descr").": </label>". $desc;
print "<br>";

$credits = "<div class='multiLine'>";
$credits .= str_replace(":", " : ", str_replace(",", "<br>", urldecode($show['credits'])));
$credits .= "</div>";
print "<label>".tt("Credits").": </label>". $credits;


$bm = new ButtonMenu();

$tsHours = $ch['tsHours'];
$tsFrom = time() - $tsHours*60*60;


if ( $recStatus  == "READY") { 

	$pvrServerId = $show['pvrServerId'];
	$pvrServerRec = app()->selectOne("select * from pvrservers where id='$pvrServerId'");
	$pvrPublicUrl = $pvrServerRec['publicUrl'];
	$pvrPublicUrlRel = $pvrServerRec['publicUrlRel'];

	$routerId = $groupRec['routerId'];
	$routerRec = app()->selectOne("select * from routers where id='$routerId'");
	$routerUrl = $routerRec['url'];
	if ( strlen($routerUrl) > 0 ) { 
		$routerUrl = preg_replace("/\/$/", "", $routerUrl);
		$pvrPublicUrlRel = preg_replace("/^\//", "", $pvrPublicUrlRel);
		$pvrPublicUrl = $routerUrl."/".$pvrPublicUrlRel;
	} else { 
		$pvrPublicUrl = $pvrServerRec['publicUrl'];
	}



	$pvrPublicUrl = preg_replace("/\/$/", "", $pvrPublicUrl);
	$mrl = "$pvrPublicUrl/{$key}_{$subId}.m3u8";
	$chId = $show['channelId'];
	$i = $bm->add("Play");
	$contentId = "pvr_$recId";
	$seekTo = 0;


	//load seekTo
	$seekRec = app()->selectOne("select * from pvrrecordingspos where subId='$subId' and pvrRecId='$recId'");
	$seekTo = $seekRec['secAt'] + 0;


	$i->icon = "play";
	$i->onClick = "console.log('$mrl');try{ Android.playPvr('$mrl','$contentId',$seekTo);} catch(err) { Android.playPvr('$mrl'); }";
}

	$i = $bm->add("Delete");
	$i->icon = "trash";
	$i->onClick = "location.href='delrec?id=$pvrRecordingId&chId=$chId&start=$startEpoch&stop=$stopEpoch&$params';";



$i = $bm->add("List");
$i->icon ="list-alt";
$i->onClick = "location.href='dvr?highId=$recId&$params';";
$i->high = true;


$bm->show();

pageFooter();
?>
