%@language=vbscript codepage=936 %>
<%
option explicit
response.buffer=true
Const PurviewLevel=2
Const CheckChannelID=0
Const PurviewLevel_Others="Layout"
%>
<%
dim rs, sql
dim Action,LayoutID,LayoutType,FoundErr,ErrMsg
Action=trim(request("Action"))
LayoutID=trim(request("LayoutID"))
LayoutType=trim(request("LayoutType"))
if LayoutType="" then
LayoutType=session("LayoutType")
end if
if LayoutType="" then
LayoutType=2
else
LayoutType=CLng(LayoutType)
end if
session("LayoutType")=LayoutType
%>
<%
select case Action
case "Add","Modify"
call ShowLayoutSet()
case "SaveAdd"
call SaveAdd()
case "SaveModify"
call SaveModify()
case "Set"
call SetDefault()
case "Del"
call DelLayout()
case else
call main()
end select
if FoundErr=True then
call WriteErrMsg()
end if
call CloseConn()
sub main()
sql="select * from Layout where LayoutType=" & LayoutType
Set rs=Server.CreateObject("Adodb.RecordSet")
rs.Open sql,conn,1,1
%>
<%
rs.close
set rs=nothing
end sub
sub ShowLayoutSet()
if Action="Add" then
sql="select * from Layout where IsDefault=True and LayoutType=" & LayoutType
elseif Action="Modify" then
if LayoutID="" then
FoundErr=True
ErrMsg=ErrMsg & "
请指定LayoutID
"
exit sub
else
LayoutID=Clng(LayoutID)
end if
sql="select * from Layout where LayoutID=" & LayoutID
end if
Set rs=Server.CreateObject("Adodb.RecordSet")
rs.Open sql,conn,1,1
if rs.bof and rs.eof then
FoundErr=True
ErrMsg=ErrMsg & "
数据库出现错误!
"
rs.close
set rs=nothing
exit sub
end if
%>
<%
rs.close
set rs=nothing
end sub
%>
<%
sub SaveAdd()
call CheckLayout()
if FoundErr=True then exit sub
sql="select top 1 * from Layout"
Set rs=Server.CreateObject("Adodb.RecordSet")
rs.Open sql,conn,1,3
rs.addnew
rs("IsDefault")=False
rs("DesignType")=1
call SaveLayout()
rs.close
set rs=nothing
call WriteSuccessMsg("成功添加新的版面设计模板:"& trim(request("LayoutName")))
end sub
sub SaveModify()
if LayoutID="" then
FoundErr=True
ErrMsg=ErrMsg & "
请指定LayoutID
"
else
LayoutID=Clng(LayoutID)
end if
call CheckLayout()
if FoundErr=True then exit sub
sql="select * from Layout where LayoutID=" & LayoutID
Set rs=Server.CreateObject("Adodb.RecordSet")
rs.Open sql,conn,1,3
if rs.bof and rs.eof then
FoundErr=True
ErrMsg=ErrMsg & "
找不到指定的版面设计模板!
"
else
call SaveLayout()
call WriteSuccessMsg("保存版面设计模板设置成功!")
end if
rs.close
set rs=nothing
end sub
sub SetDefault()
if LayoutID="" then
FoundErr=True
ErrMsg=ErrMsg & "
请指定LayoutID
"
exit sub
else
LayoutID=Clng(LayoutID)
end if
conn.execute("update Layout set IsDefault=False where IsDefault=True and LayoutType=" & LayoutType)
conn.execute("update Layout set IsDefault=True where LayoutID=" & LayoutID)
call WriteSuccessMsg("成功将选定的模板设置为默认模板")
end sub
sub CheckLayout()
if trim(request("LayoutName"))="" then
FoundErr=True
ErrMsg=ErrMsg & "
模板名称不能为空!
"
end if
if trim(request("LayoutFileName"))="" then
FoundErr=True
ErrMsg=ErrMsg & "
模板文件名不能为空!
"
end if
if trim(request("PicUrl"))="" then
FoundErr=True
ErrMsg=ErrMsg & "
模板预览图地址不能为空!
"
end if
if trim(request("DesignerName"))="" then
FoundErr=True
ErrMsg=ErrMsg & "
模板设计者姓名不能为空!
"
end if
if trim(request("DesignerEmail"))="" then
FoundErr=True
ErrMsg=ErrMsg & "
模板设计者邮箱不能为空!
"
end if
end sub
sub SaveLayout()
rs("LayoutType")=LayoutType
rs("LayoutName")=trim(request("LayoutName"))
rs("LayoutFileName")=trim(request("LayoutFileName"))
rs("PicUrl")=trim(request("PicUrl"))
rs("DesignerName")=trim(request("DesignerName"))
rs("DesignerEmail")=trim(request("DesignerEmail"))
rs("DesignerHomePage")=trim(request("DesignerHomepage"))
rs.update
end sub
sub DelLayout()
'********************新增加的代码********************
dim LayoutType
'********************新增代码结束********************
if LayoutID="" then
FoundErr=True
ErrMsg=ErrMsg & "
请指定LayoutID
"
exit sub
else
LayoutID=Clng(LayoutID)
end if
sql="select * from Layout where LayoutID=" & LayoutID
Set rs=Server.CreateObject("Adodb.RecordSet")
rs.Open sql,conn,1,3
if rs.bof and rs.eof then
FoundErr=True
ErrMsg=ErrMsg & "
找不到指定的版面设计模板!
"
else
if rs("DesignType")=0 then
FoundErr=True
ErrMsg=ErrMsg & "
不能删除系统自带的模板!
"
elseif rs("IsDefault")=True then
FoundErr=True
ErrMsg=ErrMsg & "
当前模板为默认模板,不能删除。请先将默认模板改为其他模板后再来删除此模板。
"
else
'********************新增加的代码********************
LayoutType=rs("LayoutType")
'********************新增代码结束********************
rs.delete
rs.update
dim trs
'********************原始代码屏蔽********************
' set trs=conn.execute("select LayoutID from Layout where IsDefault=True and LayoutType=" & rs("LayoutType"))
'********************新增加的代码********************
set trs=conn.execute("select LayoutID from Layout where IsDefault=True and LayoutType=" & LayoutType)
'********************新增代码结束********************
conn.execute("update ArticleClass set LayoutID=" & trs(0) & " where LayoutID=" & LayoutID)
conn.execute("update Article set LayoutID=" & trs(0) & " where LayoutID=" & LayoutID)
set trs=nothing
end if
end if
rs.close
set rs=nothing
if FoundErr=True then exit sub
call WriteSuccessMsg("成功删除选定的模板。并将使用此模板的栏目和文章改为使用默认模板。")
end sub
%>