<!-- #include file="../../inc/html_clear.asp" -->
<%'容错处理
function img_content_to_html(a_id,a_pid)
On Error Resume Next
%>

<%
'网站基本信息内容读取替换
set rs=server.createobject("adodb.recordset")
sql="select web_name,web_copyright from web_settings"
rs.open(sql),cn,1,1
if not rs.eof and not rs.bof then
web_name=rs("web_name")
web_url=rs("web_url")
web_image=rs("web_image")
web_copyright=rs("web_copyright")
end if
rs.close
set rs=nothing


%>
<!--common use end-->

<%
'顶部广告读取替换
set rs=server.createobject("adodb.recordset")
sql="select top 1 name,[url],image from web_ad  where [position]=7 and view_yes=1 order by [order]"
rs.open(sql),cn,1,1
if not rs.eof and not rs.bof then
web_imgAD_3=web_imgAD_3&"<a href='"&rs("url")&"' target='_blank' ><img src='/7yimg/"&rs("image")&"'  width='250' height='88' alt='"&rs("name")&"'></a>"
else
web_imgAD_3=web_imgAD_3&"无数据"
end if
rs.close
set rs=nothing


'图片读取替换
set rs=server.createobject("adodb.recordset")
sql="select [name],[image],[time],[position] from web_img  where view_yes=1 and [id]="&a_id&""
rs.open(sql),cn,1,1
if not rs.eof then
img_content=img_content&"<div align='center'><img src='/photos/"&rs("image")&"' alt='"&rs("name")&"'><br>"&rs("name")
img_name=rs("name")
set rs_album=server.createobject("adodb.recordset")
sql="select [id],[name] from web_img_position where [id]="&rs("position")
rs_album.open(sql),cn,1,1
if not rs_album.eof then
album_title="<a href='/album/"&rs_album("id")&"/'>"&rs_album("name")&"</a>"
album_name=rs_album("name")
else
album_title=""
end if 
rs_album.close
set rs_album=nothing

end if
rs.close
set rs=nothing

%>


<% '读取模板内容
Set fso=Server.CreateObject("Scripting.FileSystemObject") 
Set htmlwrite=fso.OpenTextFile(Server.MapPath("/model/img_content_model.html")) 
replace_code=htmlwrite.ReadAll() 
htmlwrite.close 
%>

<%'替换内容
replace_code=replace(replace_code,"$web_name$",web_name)
replace_code=replace(replace_code,"$web_copyright$",web_copyright)

replace_code=replace(replace_code,"$album_title$",album_title)
replace_code=replace(replace_code,"$album_name$",album_name)
replace_code=replace(replace_code,"$img_name$",img_name)
replace_code=replace(replace_code,"$img_content$",img_content)
replace_code=replace(replace_code,"$web_imgAD_3$",web_imgAD_3)
%>

<% '判断分类文件夹是否存在，否则创建
Set Fso=Server.CreateObject("Scripting.FileSystemObject") 
If Fso.FolderExists(Server.MapPath("/album/"&a_pid&"/"&a_id))=false Then
NewFolderDir="/album/"&a_pid&"/"&a_id
call CreateFolderB(NewFolderDir)
end if
%>

<%
filepath="/album/"&a_pid&"/"&a_id&"/index.html"

Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set f=fso.CreateTextFile(Server.MapPath(filepath),true)
f.WriteLine replace_code
f.close
%>

<%end function%>