<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/function.asp" -->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<HTML>
<HEAD>
<TITLE>修改内容</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<link href="css.css" rel="stylesheet" type="text/css">
<%
'''''''''''''''''''''''''''''''''''''''''''''''
'if(checkIfHasPrevilege(Session("Name"),"p02") or checkIfHasPrevilege(Session("Name"),"pext01")) then
'else
	
'end if
'''''''''''''''''''''''''''''''''''''''''''''''
%>
<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.10/js/jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript">
function OpenWindowAndSetValue(Url,Width,Height,WindowObj,SetObj)
{
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:no;help:no;scroll:no;');
	if (ReturnStr!='') SetObj.value=ReturnStr;
	return ReturnStr;
}
</script>
</HEAD>
<BODY>
<%
dim moduleid,modulename,tablename,ftitle,classid,lastid,classtemplet,id
dim templetname,catalogdir,savedir
id=Clng(request.QueryString("id"))
moduleid=Cint(request.QueryString("moduleid"))
ftitle=request.Form("title")
if(len(ftitle)<1) then
	call alertstr("标题不能为空",1)
end if
classid=Cint(request.Form("classid"))
set rs=server.createobject("adodb.recordset")
rs.open "select Title,TableName from t_module where id="&moduleid,conn,3,1
if not rs.eof then
	modulename=rs(0)
	tablename=rs(1)
end if
rs.close
set rs=nothing

dim fieldsarr
set rs=server.createobject("adodb.recordset")
rs.open "select FName,FTitle,FormType,FormTitle,FStyle,FormDefault,IsBindTable,BindPara from t_fields where moduleid="&moduleid&" order by FSort",conn,3,1
if not rs.eof then
	fieldsarr=rs.getrows()
end if
rs.close
set rs=nothing

set rs=server.createobject("adodb.recordset")
rs.open "select templet.content,templet.templetname,catalogs.savedir from catalogs,templet where catalogs.TempletId=templet.id and catalogs.id="&classid,conn,3,1
if not rs.eof then
	classtemplet=rs(0)
	templetname=rs(1)
	catalogdir=rs(2)
else
	classtemplet=""
end if
rs.close
set rs=nothing
'
lastid=id
set rs=server.createobject("adodb.recordset")
rs.open "select SaveDir from "&TableName&" where id="&id,conn,3,1
if not rs.eof then
	savedir=rs(0)
end if
rs.close
set rs=nothing

set rs=server.createobject("adodb.recordset")
rs.open "select * from "&TableName&" where id="&id,conn,3,3
if not rs.eof then
	rs("Title")=ftitle
	rs("ClassId")=classid
	rs("PubDate")=now()
	rs("SaveDir")=savedir
	if isarray(fieldsarr) then
		for j=0 to ubound(fieldsarr,2)
			rs(fieldsarr(0,j))=request.Form(fieldsarr(0,j))
		next
	end if
end if
rs.update
rs.close
set rs=nothing
'标签替换

'
folderCategory=server.MapPath("/")	
folderArr=split(savedir,"/")
for fi=1 to ubound(folderArr)-1
	tempFolder=tempFolder&"\"&folderArr(fi)
	'response.Write(folderCategory&tempFolder&"<br>")
	call MakeDir(folderCategory&tempFolder)
next	

if(classtemplet<>"") then
	classtemplet=replace(classtemplet,"$id$",lastid)
	classtemplet=replace(classtemplet,"$Title$",ftitle)
	classtemplet=replace(classtemplet,"$ClassId$",ClassId)
	classtemplet=replace(classtemplet,"$PubDate$",now())
	classtemplet=replace(classtemplet,"$SaveDir$",savedir)
	for j=0 to ubound(fieldsarr,2)
		classtemplet=replace(classtemplet,"$"&fieldsarr(0,j)&"$",request.Form(fieldsarr(0,j)))
	next
	classtemplet=ReplaceAllLabel(classtemplet,ClassId)
	call SaveTextFile(server.MapPath(savedir),classtemplet)
else
	response.Write("模板："&templetname&"内容为空，无法生成HTM。")
end if
set fieldsarr=nothing
%>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<%
	response.Write("<p align=""center"">成功修改</p><p align=""center""><a href=""javascript:history.go(-2);"">继续修改</a></p>")
%>
</BODY>
</HTML>
<%
call connclose()
%>