-- vim:set ft=lua: dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua') post=AssertPost() dataID=GetVarInt(mg.request_info.query_string, 'id') or 0 if dataID~=0 then for i,v in ipairs(edcb.EnumAutoAdd()) do if v.dataID==dataID then key=v.searchInfo break end end end preset=mg.get_var(mg.request_info.query_string, 'preset') presetList={} for v in edcb.GetPrivateProfile('search','list','',INI):gmatch('[^,]+') do presetList[#presetList+1]=v end if preset then --区切り文字と空文字列は使えない preset=preset:gsub(',', '_'):match('.+') or '_' for i,v in ipairs(presetList) do if v==preset then presetIndex=i break end end _preset=preset..'_Search' if GetVarInt(post, 'save')==1 then if presetIndex then --上書き edcb.WritePrivateProfile(_preset, nil, '', INI) else --追加 presetList[#presetList+1]=preset edcb.WritePrivateProfile('search', 'list', table.concat(presetList, ',')..',', INI) end edcb.WritePrivateProfile(_preset, 'andKey', (GetVarInt(post,'caseFlag') and 'C!{999}' or '')..(mg.get_var(post,'andKey') or ''),INI) edcb.WritePrivateProfile(_preset, 'notKey', mg.get_var(post,'notKey') or '',INI) edcb.WritePrivateProfile(_preset, 'regExpFlag', GetVarInt(post,'regExpFlag'),INI) edcb.WritePrivateProfile(_preset, 'titleOnlyFlag', GetVarInt(post,'titleOnlyFlag'),INI) edcb.WritePrivateProfile(_preset, 'aimaiFlag', GetVarInt(post,'aimaiFlag'),INI) edcb.WritePrivateProfile(_preset, 'notContetFlag', GetVarInt(post,'notContetFlag'),INI) edcb.WritePrivateProfile(_preset, 'notDateFlag', GetVarInt(post,'notDateFlag'),INI) edcb.WritePrivateProfile(_preset, 'freeCAFlag', GetVarInt(post,'freeCAFlag'),INI) edcb.WritePrivateProfile(_preset, 'chkRecEnd', GetVarInt(post,'chkRecEnd'),INI) edcb.WritePrivateProfile(_preset, 'chkRecDay', GetVarInt(post,'chkRecDay'),INI) edcb.WritePrivateProfile(_preset, 'chkRecNoService', GetVarInt(post,'chkRecNoService'),INI) edcb.WritePrivateProfile(_preset, 'chkDurationMin', GetVarInt(post,'chkDurationMin'),INI) edcb.WritePrivateProfile(_preset, 'chkDurationMax', GetVarInt(post,'chkDurationMax'),INI) edcb.WritePrivateProfile(_preset, 'days', GetVarInt(post,'days'),INI) edcb.WritePrivateProfile(_preset, 'dateList', mg.get_var(post,'dateList') or '',INI) edcb.WritePrivateProfile(_preset, 'lock', GetVarInt(post,'lock'),INI) for i=0,10000 do v=mg.get_var(post, 'contentList', i) if not v then break end edcb.WritePrivateProfile(_preset, 'contentList'..i, v,INI) end for i=1,10000 do v=mg.get_var(post, 'serviceList', i) if not v then break end edcb.WritePrivateProfile(_preset, 'serviceList'..i, v,INI) end elseif GetVarInt(post, 'del')==1 then if presetIndex then table.remove(presetList, presetIndex) edcb.WritePrivateProfile(_preset, nil, '', INI) edcb.WritePrivateProfile('search', 'list', #presetList~=0 and table.concat(presetList, ',')..',' or '', INI) end else key={ andKey=edcb.GetPrivateProfile(_preset,'andKey','',INI), notKey=edcb.GetPrivateProfile(_preset,'notKey','',INI), regExpFlag=tonumber(edcb.GetPrivateProfile(_preset,'regExpFlag',false,INI))~=0, titleOnlyFlag=tonumber(edcb.GetPrivateProfile(_preset,'titleOnlyFlag',false,INI))~=0, aimaiFlag=tonumber(edcb.GetPrivateProfile(_preset,'aimaiFlag',false,INI))~=0, notContetFlag=tonumber(edcb.GetPrivateProfile(_preset,'notContetFlag',false,INI))~=0, notDateFlag=tonumber(edcb.GetPrivateProfile(_preset,'notDateFlag',false,INI))~=0, freeCAFlag=tonumber(edcb.GetPrivateProfile(_preset,'freeCAFlag',0,INI)), chkRecEnd=tonumber(edcb.GetPrivateProfile(_preset,'chkRecEnd',false,INI))~=0, chkRecDay=tonumber(edcb.GetPrivateProfile(_preset,'chkRecDay',0,INI)), chkRecNoService=tonumber(edcb.GetPrivateProfile(_preset,'chkRecNoService',false,INI))~=0, chkDurationMin=tonumber(edcb.GetPrivateProfile(_preset,'chkDurationMin',0,INI)), chkDurationMax=tonumber(edcb.GetPrivateProfile(_preset,'chkDurationMax',0,INI)), days=tonumber(edcb.GetPrivateProfile(_preset,'days',0,INI)), contentList={}, serviceList={}, dateList={}, lock=tonumber(edcb.GetPrivateProfile(_preset,'lock',false,INI))~=0, } for i=0,1000 do v=tonumber(edcb.GetPrivateProfile(_preset,'contentList'..i,0,INI)) if v==0 then break end table.insert(key.contentList, {content_nibble=v}) end for i=0,1000 do v=edcb.GetPrivateProfile(_preset,'serviceList'..i,0,INI) if v==0 then break end m={string.match(v, '^(%d+)%-(%d+)%-(%d+)$')} if #m==3 then table.insert(key.serviceList, {onid=0+m[1], tsid=0+m[2], sid=0+m[3]}) end end for v in string.gmatch(edcb.GetPrivateProfile(_preset,'dateList','',INI), '[^,]+') do m={string.match(v, '^(.-)%-(%d+):(%d+)%-(.-)%-(%d+):(%d+)$')} if #m==6 then dateInfo={ startDayOfWeek=({['日']=0,['月']=1,['火']=2,['水']=3,['木']=4,['金']=5,['土']=6})[m[1]], endDayOfWeek=({['日']=0,['月']=1,['火']=2,['水']=3,['木']=4,['金']=5,['土']=6})[m[4]] } if dateInfo.startDayOfWeek and dateInfo.endDayOfWeek then dateInfo.startHour=0+m[2] dateInfo.startMin=0+m[3] dateInfo.endHour=0+m[5] dateInfo.endMin=0+m[6] table.insert(key.dateList, dateInfo) end end end end end if not key then key=post and GetSearchKey(post) or GetSearchKeyKeyword(mg.request_info.query_string) end key.search=dataID==0 and not mg.get_var(post, 'id') edcb.htmlEscape=15 range=nil archive=GetVarInt(post, 'archive')==1 startDate=GetVarDate(post, 'startDate') if startDate then startDate=startDate+GetVarTime(post, 'startTime') endDate=GetVarDate(post, 'endDate') if endDate then range={startTime=os.date('!*t',startDate),durationSecond=endDate+GetVarTime(post, 'endTime')-startDate} end end if range then a=archive and edcb.SearchEpgArchive(key, range) or edcb.SearchEpg(key, range) else a={} if post or preset or dataID~=0 or mg.get_var(mg.request_info.query_string, 'andKey') then for i,v in ipairs(edcb.SearchEpg(key)) do if v.startTime then startTime=TimeWithZone(v.startTime) endTime=v.durationSecond and startTime+v.durationSecond or startTime if os.time()+9*3600<=endTime then table.insert(a, v) end end end end end table.sort(a, function(a,b) if (a.startTime and os.time(a.startTime) or 0)==(b.startTime and os.time(b.startTime) or 0) then return a.sid\n', } ct.subheader='
\n' ct.main='
\n' ..SidePanelTemplate() ..'
' if key.search then ct.dialog={{ id='dialog_preset', content='lock' ..'登録名
' ..'※同じ名前がある場合上書きします', button='
' }} ct.main=ct.main..'
' for i,v in ipairs(presetList) do lock=tonumber(edcb.GetPrivateProfile(v..'_Search','lock',false,INI))~=0 ct.main=ct.main..'' ..''..EdcbHtmlEscape(v:sub(1,(v:match('^[%w%p]') and 1 or 3)))..'' ..''..EdcbHtmlEscape(v)..'' ..(lock and '' or '
') ..'\n' ..'\n' ..'\n' ..'' end ct.main=ct.main..'
\n' end --ここからkeyはHTML出力用 key.andKey=EdcbHtmlEscape(key.andKey) key.notKey=EdcbHtmlEscape(key.notKey) ct.main=ct.main..'
\n\n' ..'
\n' ..'
\n' ..(not key.search and '\n' or '
\n
アーカイブ検索
\n' ..'
\n' ..'
\n' ..'
\n
日時指定
\n' ..'
検索開始日
' ..'
～
検索終了日
' ..'
\n' ..'
\n
詳細検索
\n' ..'
\n' ..'
\n' ) ..'\n' ..'\n' ..'\n' ..SerchTemplate(key) ..(ParseAndKey(key.andKey).disableFlag and '\n' or '') ..'
\n' ..'
' ..(key.search and '
\n' or '') ..'
\n' ..'
\n' ..'
\n' ..'
\n
\n' page=GetVarInt(mg.request_info.query_string,'page',0,100000) or 0 pageCount=tonumber(edcb.GetPrivateProfile('SET','PAGE_COUNT','30',INI)) if pageCount==0 then pageCount=#a end if #a>0 then pageNav='
\n' ..'
\n' ..'
\n' n=math.max(math.min(page-2,math.floor(#a/pageCount)-4),0) for i=n, n+4 do pageNav=pageNav..((i==page or i<#a/pageCount) and '
\n' or '') end pageNav=pageNav..'
\n' ..'
\n' ..'
\n' ct.main=ct.main..pageNav..'
' ..'

\n' ..'
'..#a..' 件中 '..math.min(#a,page*pageCount+1)..' － '..math.min(#a,(page+1)*pageCount)..' 件
\n' ..'
\n
\n' ..(not archive and ' 録画\n' or '') ..' | 日付\n' ..' | 番組名\n' ..' | サービス\n' ..' | 番組内容\n' ..'
--- | --- | --- | --- | ---
\n' rt={} for i,v in ipairs(edcb.GetReserveData()) do rt[v.onid..'-'..v.tsid..'-'..v.sid..'-'..v.eid]=v.reserveID end sn={} for i,v in ipairs(edcb.GetServiceList() or {}) do sn[v.onid..'-'..v.tsid..'-'..v.sid]=v.service_name end ctt={} for i=math.max(1,page*pageCount+1),math.min(#a,(page+1)*pageCount) do v=a[i] service_name=sn[v.onid..'-'..v.tsid..'-'..v.sid] or '' r=nil id=rt[v.onid..'-'..v.tsid..'-'..v.sid..'-'..v.eid] or nil if id then r=edcb.GetReserveData(id) rs=r.recSetting end table.insert(ctt, '
' ..(not archive and '\n ' or ' class="add mdl-button mdl-js-button mdl-button--fab mdl-button--colored">add')..'' or '') ..'\n | '..FormatTimeAndDuration(v.startTime) ..'\n | '..(v.shortInfo and ConvertTitle(v.shortInfo.event_name) or '') ..'\n | '..service_name ..'\n | '..(v.shortInfo and v.shortInfo.text_char or '') ..'\n') end ct.main=ct.main..table.concat(ctt)..'

\n
\n'..pageNav end ct.main=ct.main..'\n
\n' if dataID>0 or post or preset or mg.get_var(mg.request_info.query_string, 'andKey') then ct.main=ct.main..'\n' ..(not key.search and '\n' or '') ..'\n' ..'\n' ..'\n' ..(archive and '\n' or '') ..(range and '\n' ..'\n' ..'\n' ..'\n' or '') ..'\n' ..'\n' ..(key.regExpFlag and '\n' or '') ..(key.titleOnlyFlag and '\n' or '') ..(key.aimaiFlag and '\n' or '') ..(key.notContetFlag and '\n' or '') ..(key.notDateFlag and '\n' or '') ..(key.freeCAFlag and '\n' or '') ..(key.days and '\n' or '') ..(key.chkRecNoService and '\n' or '') ..(key.chkDurationMin and '\n' or '') ..(key.chkDurationMax and '\n' or '') ..(key.chkRecEnd and '\n' or '') ..(key.chkRecDay and '\n' or '') ..(ParseAndKey(key.andKey).disableFlag and '\n' or '') ..(ParseAndKey(key.andKey).caseFlag and '\n' or '') if key.contentList then for i,v in ipairs(key.contentList) do ct.main=ct.main..'\n' end end if key.serviceList then for i,v in ipairs(key.serviceList) do ct.main=ct.main..'\n' end end if key.dateList then ct.main=ct.main..'\n' end ct.main=ct.main..'\n' end ct.main=ct.main..'
\n' ct=Template(ct) mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len,ct.gzip)..'\r\n'))