-- vim:set ft=lua:
dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua')
edcb.htmlEscape=15
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')
if preset then
_preset=preset..'_Search'
if GetVarInt(post, 'save')==1 then
list=edcb.GetPrivateProfile('search', 'list','',ini)
for v in string.gmatch(edcb.GetPrivateProfile('search','list','',ini), '[^,]+') do
if v==preset then --上書き
edcb.WritePrivateProfile(_preset, nil, '',ini)
done=true
break
end
end
if not done then edcb.WritePrivateProfile('search', 'list', list..preset..',',ini) end
edcb.WritePrivateProfile(_preset, 'andKey', (GetVarInt(post,'caseFlag') and 'C!{999}' or '')..mg.get_var(post,'andKey'),ini)
edcb.WritePrivateProfile(_preset, 'notKey', mg.get_var(post,'notKey'),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'),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
edcb.WritePrivateProfile(_preset, nil, '',ini)
edcb.WritePrivateProfile('search', 'list', edcb.GetPrivateProfile('search','list','',ini):gsub(preset..',',''),ini)
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=getSearchKey(post)
end
key.search=dataID==0 and not mg.get_var(post, 'id')
key.disableFlag=key.andKey:match('^^!{999}(.*)')
key.caseFlag=(key.disableFlag or key.andKey):match('^C!{999}(.*)')
ct={
title='検索',
js='\n',
progres=true,
macro=sidePanel
}
ct.subheader='
\n'
..'\n'
..'
\n'
ct.main='\n'
..(sidePanel and sidePanelTemplate(true) or '')
..'
'
if key.search then
ct.dialog={{
id='dialog_preset',
content=''
..'登録名'
..'※同じ名前がある場合上書きします',
button=''
}}
ct.main=ct.main..'
\n'
b=(post or preset or dataID~=0 or mg.get_var(mg.request_info.query_string, 'andKey')) and edcb.SearchEpg(key) or {}
table.sort(b, function(a,b) return os.time(a.startTime) < os.time(b.startTime) end)
a={}
for i,v in ipairs(b) do
if v.startTime then
startTime=os.time(v.startTime)
endTime=v.durationSecond and startTime+v.durationSecond or startTime
if os.time()<=endTime then
table.insert(a, v)
end
end
end
pageIndex=GetVarInt(mg.request_info.query_string,'page',0,100000) or 0
autopage=GetVarInt(mg.request_info.query_string,'autopage',0,100000) or 0
PAGE_COUNT=tonumber(edcb.GetPrivateProfile('SET','PAGE_COUNT','30',ini))
if PAGE_COUNT==0 then PAGE_COUNT=#a end
if #a>0 then
if math.ceil((#a/PAGE_COUNT)-1)>0 then
pg='\n'
..'\n'
n=pageIndex>(#a/PAGE_COUNT-2) and math.floor(#a/PAGE_COUNT)-4 or math.max(0,pageIndex-2)
for i=n, n+4 do
pg=pg..(i>=0 and i<#a/PAGE_COUNT and '\n' or '')
end
pg=pg..'\n'
..'\n'
pg='
\n'
rt={}
for i,v in ipairs(edcb.GetReserveData()) do
rt[v.onid..'-'..v.tsid..'-'..v.sid..'-'..v.eid]=v.reserveID
end
ctt={}
for i=math.max(1,pageIndex*PAGE_COUNT+1),math.min(#a,(pageIndex+1)*PAGE_COUNT) do
v=a[i]
for j,w in ipairs(edcb.GetServiceList() or {}) do
if w.onid==v.onid and w.tsid==v.tsid and w.sid==v.sid then
service_name=w.service_name
break
end
end
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, '
\n'
..'
os.time() and '>'
or ' class="search '..(r and 'recmark">' or 'add mdl-button mdl-js-button mdl-button--fab mdl-button--colored">add'))
..'\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'..(pg or '')
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'
end
ct.main=ct.main..'\n'
ct=template(ct)
mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len)..(ct.gzip and 'Content-Encoding: gzip\r\n' or '')..'\r\n'))