-- vim:set ft=lua:
dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua')

ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE)
ct:Append([=[
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1">
<link rel="stylesheet" type="text/css" href="default.css">
<title>番組詳細 - EDCB</title>
</head>
<body>
<h1>番組詳細</h1>
<div id="main">
  <dl>
]=])

onid,tsid,sid,startTime=(mg.get_var(mg.request_info.query_string,'id') or ''):match('^(%d?%d?%d?%d?%d)%-(%d?%d?%d?%d?%d)%-(%d?%d?%d?%d?%d)%-(%d+)$')
onid=tonumber(onid) or 0
tsid=tonumber(tsid) or 0
sid=tonumber(sid) or 0
startTime=tonumber(startTime) or 0

edcb.htmlEscape=15
et=edcb.EnumEventInfoArchive({{onid=onid,tsid=tsid,sid=sid}}, {startTime=os.date('!*t',startTime), durationSecond=1})
if et and #et~=0 then
  ct:Append('    <dt>番組情報</dt><dd>\n'..ConvertEpgInfoText2(et[1]):gsub('\r?\n','<br>\n')..'</dd>\n')
end

ct:Append([=[
  </dl>
</div>
<div id="footer">
  <a href="epg.html">番組表</a> <a href="epglist.html?id=]=]..onid..'-'..tsid..'-'..sid..[=[#now">リスト番組表</a>
</div>
</body>
</html>
]=])
ct:Finish()
mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len)..(ct.gzip and 'Content-Encoding: gzip\r\n' or '')..'\r\n'))
