#!/mod/bin/jimsh

package require cgi
source /mod/webif/lib/setup
require epg.class

cgi_input

set table [cgi_get table TBL_RESERVATION]
set slot [cgi_get slot 0]
set event [rsv slot $table $slot]

mheader

puts "

<div data-role=header data-theme=a>
	<h1>Scheduled Event</h1>
</div>

<div data-role=content>
"

puts "
	<table class=keyval>
	<tr>
		<th>Event [$event get ulslot]</th>
		<td class=va>[join [$event iconset] ""]</td>
	</tr><tr>
		<th>Channel</th>
		<td class=va>
"
if {[$event get usLcn] ne ""} {
	puts "[epg channelicon [$event channel_name] 50]
		- [$event get usLcn] - [$event channel_name]
	"
}

puts "
		</td>
	</tr><tr>
		<th>Event Name</th>
		<td>[$event name]"
if {[$event get ucRecKind] == 4 && [$event name] ne [$event folder]} {
	puts "<span class=also>(Folder: [$event folder])</span>"
}

puts "</td>
	</tr><tr>
		<th>Start</th>
"

set s [$event get nsttime]
set d [$event get nduration]
set e $($s + $d)
set n [clock seconds]

if { $n > $e } {
	puts "<td class=blood nowrap class=va>"
} else {
	puts "<td nowrap class=va>"
}
puts "[clock format $s -format "%a %d %b %Y"]
    [clock format $s -format "%H:%M %Z"]"

if {$d > 0 && $n > $s && $n < $e} {
	puts "<br>"
	set perc [expr {[expr {$n - $s}] * 100 / $d}]
	puts "<img class=va src=/images/745_1_11_Video_1REC.png>"
	puts [progressbar $perc]
}

puts "
		</td>
	</tr><tr>
		<th>Duration</th>
		<td>[clock format [$event get nduration] -format %T]</td>
	</tr>
"

set crid [join [lrange [split [$event get szCRID] /] 1 end]]
if {$crid != ""} {
	puts "<tr><th>"
	if {[$event isseries]} { puts "Series" } else { puts "Event" }
	puts " CRID</th><td>
	<img border=0 src=/images/421_1_00_CH_Title_2R_Arrow.png
	    height=14>
	[$event get szCRID]
	</td></tr>"
}
puts "<tr><th>Events</th><td>"
set flag 0
foreach ev [split [$event get szEventToRecord] "|"] {
	if {$ev eq ""} { continue }
	set ev [string range $ev 1 end]
	if {$flag} { puts "<br>" }
	incr flag
	set crid [join [lrange [split $ev /] 1 end]]
	puts "<img border=0 src=/images/421_1_00_CH_Title_2R_Arrow.png
	    height=14>$ev"
}
puts "</td></tr>"
puts "<tr><th>Accepted</th><td>"
if {[$event get aulEventToRecordInfo] ne ""} {
	puts "Yes"
}
puts "</td></tr>"
puts "</table>"

# Buttons
puts "<a href=# data-theme=a id=delevent data-role=button
    tab=$table slot=$slot>Cancel Event</a>"
puts "<a href=# data-role=button data-theme=a id=close data-rel=back>Close</a>"

epg cleanup

mfooter

