<%@ LANGUAGE="VBScript" %>
<!--#include virtual="/_shared/db_config_domusmart.asp"-->
<%
Response.Buffer = True
Response.ContentType = "application/xml"
Response.Charset = "utf-8"
Response.AddHeader "Cache-Control", "public, max-age=3600"

Function XmlEscape(ByVal s)
  If IsNull(s) Then s = ""
  s = Replace(s, "&", "&amp;")
  s = Replace(s, "<", "&lt;")
  s = Replace(s, ">", "&gt;")
  s = Replace(s, """", "&quot;")
  s = Replace(s, "'", "&apos;")
  XmlEscape = s
End Function

Dim site : site = "https://" & Request.ServerVariables("HTTP_HOST")

Const adCmdText = 1
Dim cmd, rs
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = db
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT ID, data_ins FROM prodotti WHERE attivo=1 AND casa=1 ORDER BY data_ins DESC"
Set rs = cmd.Execute

Response.Write "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf
Response.Write "<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">" & vbCrLf

' Home
Response.Write "  <url>" & vbCrLf
Response.Write "    <loc>" & XmlEscape(site & "/default.asp") & "</loc>" & vbCrLf
Response.Write "    <changefreq>daily</changefreq>" & vbCrLf
Response.Write "    <priority>1.0</priority>" & vbCrLf
Response.Write "  </url>" & vbCrLf

' Prodotti
Do While Not rs.EOF
  Dim pid, lastmod, d
  pid = rs("ID")
  If IsNull(rs("data_ins")) Then d = Date() Else d = rs("data_ins")

  Response.Write "  <url>" & vbCrLf
  Response.Write "    <loc>" & XmlEscape(site & "/prodotto.asp?id=" & pid) & "</loc>" & vbCrLf
  Response.Write "    <lastmod>" & Year(d) & "-" & Right("0" & Month(d),2) & "-" & Right("0" & Day(d),2) & "</lastmod>" & vbCrLf
  Response.Write "    <changefreq>weekly</changefreq>" & vbCrLf
  Response.Write "    <priority>0.8</priority>" & vbCrLf
  Response.Write "  </url>" & vbCrLf

  rs.MoveNext
Loop

On Error Resume Next
rs.Close : Set rs = Nothing : Set cmd = Nothing
db.Close : Set db = Nothing
On Error GoTo 0

Response.Write "</urlset>"
%>
