-- vim:set ft=lua:
dofile(mg.document_root..'\\api\\util.lua')
edcb.htmlEscape=15
a=edcb.EnumAutoAdd()
rsdef=edcb.GetReserveData(0x7FFFFFFF)
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
  disableFlag=string.match(v.searchInfo.andKey, '^^!{999}(.*)')
  caseFlag=(disableFlag or v.searchInfo.andKey):match('^C!{999}(.*)')
  table.insert(ct, '<autoaddinfo><ID>'
    ..v.dataID..'</ID><searchsetting><disableFlag>'
    ..(disableFlag and 1 or 0)..'</disableFlag><caseFlag>'
    ..(caseFlag and 1 or 0)..'</caseFlag><andKey>'
    ..(caseFlag or disableFlag or v.searchInfo.andKey)..'</andKey><notKey>'
    ..v.searchInfo.notKey..'</notKey><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, rsdef)
    ..'</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
