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

edcb.htmlEscape=15
a=edcb.EnumAutoAdd()
ct={'<?xml version="1.0" encoding="UTF-8" ?><entry><total>'..#a..'</total><index>0</index><count>'..#a..'</count><items>\r\n'}
for i,v in ipairs(a) do
  table.insert(ct, '<autoaddinfo><ID>'
    ..v.dataID..'</ID><addCount>'
    ..v.addCount..'</addCount><searchsetting><disableFlag>'
    ..(ParseAndKey(v.searchInfo.andKey).disableFlag and 1 or 0)..'</disableFlag><caseFlag>'
    ..(ParseAndKey(v.searchInfo.andKey).caseFlag and 1 or 0)..'</caseFlag><andKey>'
    ..ParseAndKey(v.searchInfo.andKey).andKey..'</andKey><notKey>'
    ..ParseNotKey(v.searchInfo.notKey).notKey..'</notKey><note>'
    ..ParseNotKey(v.searchInfo.notKey).note..'</note><regExpFlag>'
    ..(v.searchInfo.regExpFlag and 1 or 0)..'</regExpFlag><titleOnlyFlag>'
    ..(v.searchInfo.titleOnlyFlag and 1 or 0)..'</titleOnlyFlag><aimaiFlag>'
    ..(v.searchInfo.aimaiFlag and 1 or 0)..'</aimaiFlag><notContetFlag>'
    ..(v.searchInfo.notContetFlag and 1 or 0)..'</notContetFlag><notDateFlag>'
    ..(v.searchInfo.notDateFlag and 1 or 0)..'</notDateFlag><freeCAFlag>'
    ..v.searchInfo.freeCAFlag..'</freeCAFlag><chkRecEnd>'
    ..(v.searchInfo.chkRecEnd and 1 or 0)..'</chkRecEnd><chkRecDay>'
    ..v.searchInfo.chkRecDay..'</chkRecDay><chkRecNoService>'
    ..(v.searchInfo.chkRecNoService and 1 or 0)..'</chkRecNoService><chkDurationMin>'
    ..v.searchInfo.chkDurationMin..'</chkDurationMin><chkDurationMax>'
    ..v.searchInfo.chkDurationMax..'</chkDurationMax>')
  for j,w in ipairs(v.searchInfo.contentList) do
    table.insert(ct, '<contentList><content_nibble>'
      ..w.content_nibble..'</content_nibble><user_nibble>'
      ..w.user_nibble..'</user_nibble></contentList>')
  end
  for j,w in ipairs(v.searchInfo.dateList) do
    table.insert(ct, '<dateList><startDayOfWeek>'
      ..w.startDayOfWeek..'</startDayOfWeek><startHour>'
      ..w.startHour..'</startHour><startMin>'
      ..w.startMin..'</startMin><endDayOfWeek>'
      ..w.endDayOfWeek..'</endDayOfWeek><endHour>'
      ..w.endHour..'</endHour><endMin>'
      ..w.endMin..'</endMin></dateList>')
  end
  for j,w in ipairs(v.searchInfo.serviceList) do
    table.insert(ct, '<serviceList><onid>'
      ..w.onid..'</onid><tsid>'
      ..w.tsid..'</tsid><sid>'
      ..w.sid..'</sid></serviceList>')
  end
  table.insert(ct, '</searchsetting>'
    ..XmlRecSetting(v.recSetting)
    ..'</autoaddinfo>\r\n')
end
table.insert(ct, '</items></entry>')
cl=0
for i,v in ipairs(ct) do cl=cl+#v end
mg.write(Response(200, 'text/xml', 'utf-8', cl) ..'\r\n')
if mg.request_info.request_method~='HEAD' then
  for i,v in ipairs(ct) do mg.write(v) end
end
