<!-- #include file="../inc/conn.asp" -->
<%
 Response.Buffer = True
 With Response
  .Expires = -1
  .AddHeader "Pragma","no-cache"
  .AddHeader "cache-ctrol","no-cache"
 End With
 %>
 <%
set rs2=server.createobject("adodb.recordset")
sql="select top 1 web_url from Web_Setting"
rs2.open(sql),conn,1,1
web_url=rs2("web_url")
RS2.Close
Set RS2=Nothing

Server.ScriptTimeout=50000

Dim str,objStream
 str = "<?xml version='1.0' encoding='UTF-8'?>" & vbcrlf
 str = str & "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>" & vbcrlf
 str = str & getfilelink & vbcrlf
 str = str & "</urlset>" & vbcrlf

Set objStream = Server.CreateObject("ADODB.Stream")
 With objStream
 .Open
 .Charset = "UTF-8"
 .Position = objStream.Size
 .WriteText=str
 .SaveToFile server.mappath("Sitemap.xml"),2 
 .Close
 End With
 Set objStream = Nothing

If Not Err Then
    Response.Redirect("Sitemap.xml")
    Response.End
 End If

Function getfilelink()
    SQL="SELECT w_time,w_title,w_id FROM web_Article where view_yes=1 ORDER BY w_id DESC"
    Dim RS
    Set RS=Server.CreateObject("ADODB.RecordSet")
    RS.Open SQL,Conn,1,1

   IF RS.EOF AND RS.BOF Then
       Response.Write("<url></url>")
    Else
       Do While NOT RS.EOF
    Y=year(RS("w_time"))
    if len(month(RS("w_time")))=1 then 
    M=0&month(RS("w_time"))
    else
    M=month(RS("w_time"))
    end if
    if len(day(RS("w_time")))=1 then 
    D=0&day(RS("w_time")) 
    else
    D=day(RS("w_time"))
    end if
           getfilelink = getfilelink & "<url><loc>"&web_url&"/Article/?"&RS("w_id")&".html</loc><lastmod>"&Y&"-"&M&"-"&D&"</lastmod><priority>1.0</priority></url>"
 RS.MoveNext
 Loop
 End IF
 RS.Close
 Set RS=Nothing
 Conn.Close
 Set Conn=Nothing
 End Function
 %>
