<!--#include file="conn.asp" -->
<!--#include file="Connections/conn_news.asp" -->
<!--#include file="yns_config.asp" -->

<!--#include file="yns_chklogin.asp" -->
<% chk_user_login(2) %>
<!--#include file="yns_chkerror.asp" -->
<% if request.Form("n_content") = "" then %>
<script language=javascript>
alert( "请输入新闻内容 ！"  );
location.href = "javascript:history.back()"
</script>
<% end if %>
<%
Dim rst__MMColParam
rst__MMColParam = "1"
If (Request.Form("n_tid") <> "") Then
  rst__MMColParam = Request.Form("n_tid")
  else
  response.Write yns_err_null
  response.End()
End If
%>
<%
Dim rst
Dim rst_numRows

Set rst = Server.CreateObject("ADODB.Recordset")
rst.ActiveConnection = MM_conn_news_STRING
rst.Source = "SELECT * FROM t_type WHERE t_id = " + Replace(rst__MMColParam, "'", "''") + ""
rst.CursorType = 0
rst.CursorLocation = 2
rst.LockType = 1
rst.Open()
rst_numRows = 0
%>
<%
Dim rsts__MMColParam
rsts__MMColParam = "1"
If (Request.Form("n_tsid") <> "") Then
  rsts__MMColParam = Request.Form("n_tsid")
  else
  response.Write yns_err_null
  response.End()
End If
%>
<%
Dim rsts
Dim rsts_numRows

Set rsts = Server.CreateObject("ADODB.Recordset")
rsts.ActiveConnection = MM_conn_news_STRING
rsts.Source = "SELECT * FROM t_type_son WHERE ts_id = " + Replace(rsts__MMColParam, "'", "''") + ""
rsts.CursorType = 0
rsts.CursorLocation = 2
rsts.LockType = 1
rsts.Open()

rsts_numRows = 0
%>
<%
If rst.EOF And rst.BOF Then
response.Write yns_err_rseof
response.End()
End If

If rsts.EOF And rst.BOF Then
response.Write yns_err_rseof
response.End()
End If
if request.Form("n_fpath") = "" then
response.Write yns_err_null
response.End()
End If
%>
<%
Dim n_title
Dim n_content
Dim n_date
Dim fname
Dim fpath
Dim postpath
Dim author
dim mpic

dim mm_path
dim mm_path1
dim mm_type_path
dim mm_type_son_path
dim mm_folder_path
dim mm_template_path


mm_path = server.MapPath((rst.Fields.Item("t_dir").Value)&"/"&(rsts.Fields.Item("ts_dir").Value)&"/"&request.Form("n_fpath")&"/" & conn.execute("select n_fname from t_news where n_id="&request("n_id"))(0))
mm_path1 = server.MapPath(request.Form("n_tdir")&"/"&request.Form("n_tsdir")&"/"&request.Form("n_fpath1")&"/"&request.Form("n_fname1"))
mm_type_path = server.MapPath(rst.Fields.Item("t_dir").Value)
mm_type_son_path = server.MapPath((rst.Fields.Item("t_dir").Value)&"/"&(rsts.Fields.Item("ts_dir").Value))
mm_folder_path = server.MapPath((rst.Fields.Item("t_dir").Value)&"/"&(rsts.Fields.Item("ts_dir").Value)&"/"&request.Form("n_fpath"))
mm_template_path = server.MapPath("templates/type_template/type_son_template/detail_template.htm")
'response.Write mm_path1
'response.End()
author=Request.Form("n_author")
fname = Request.Form("n_fname") 
hname = Request.Form("n_fname") 
N_Title=Request.Form("n_title")
n_content=Request.Form("n_content")
n_date=Request.Form("n_date")
fpath=Request.Form("n_tid")
author=Request.Form("n_author")
mpic=Request.Form("n_mpic")
rpic=Request.Form("n_rpic")

Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not(fso.FileExists(mm_template_path))  then%>
<script language=javascript>  
alert( "生成失败,模板文件不存在！"  );
location.href = "javascript:history.back()"   
</script>
<%
else
set fso_line = fso.opentextfile(mm_template_path,1,True) 
pencat=fso_line.readall
end if
pencat=replace(pencat,"t_title",n_title)
pencat=replace(pencat,"t_author",author)
pencat=replace(pencat,"t_content",n_content)
pencat=replace(pencat,"t_date",n_date)
pencat=replace(pencat,"t_mimg",mpic)
pencat=replace(pencat,"t_rimg",rpic)
pencat=replace(pencat,"t_name",hname)

if not fso.FolderExists(mm_type_path) then
fso.CreateFolder (mm_type_path)
end if
if not fso.FolderExists(mm_type_son_path) then
fso.CreateFolder (mm_type_son_path)
end if
if not fso.FolderExists(mm_folder_path) then
fso.CreateFolder (mm_folder_path)
end if
Set fout = fso.CreateTextFile(mm_path1)
fout.WriteLine pencat
fout.close
fso_line.close
fso.MoveFile mm_path1, mm_path
set fso = nothing

%>

<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

  MM_editConnection = MM_conn_news_STRING
  MM_editTable = "t_news"
  MM_editColumn = "n_id"
  MM_recordId = "" + Request.Form("MM_recordId") + ""
  MM_editRedirectUrl = ""
  MM_fieldsStr  = "n_tid|value|n_tsid|value|n_commend|value|n_index|value|n_sid|value|n_title|value|n_author|value|n_date|value|n_mpic|value|n_rpic|value|n_fpath|value|n_fname|value|n_content|value"
  MM_columnsStr = "n_tid|none,none,NULL|n_tsid|none,none,NULL|n_commend|none,1,0|n_index|none,1,0|n_sid|none,none,NULL|n_title|',none,''|n_author|',none,''|n_date|',none,NULL|n_mpic|',none,''|n_rpic|',none,''|n_fpath|',none,''|n_fname|',none,''|n_content|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")

  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

  ' create the sql update statement

  If (Not MM_abortEdit) Then
    ' execute the update
	dim rsAA
	set rsAA=server.CreateObject("adodb.recordset")
	rsAA.open "select * from t_news where n_id="&request("n_id"),conn,1,3
	if rsAA.eof then
		response.write "<script>alert('修改失败！');history.go(-1)</script>"
		response.end
	else
		rsAA("n_tid")=clng(request("n_tid"))
		rsAA("n_tsid")=clng(request("n_tsid"))
		rsAA("n_author")=request("n_author")
		rsAA("n_title")=request("n_title")
		rsAA("n_content")=request("n_content")
		rsAA.update
	end if
	rsAA.close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>湖南百润医药有限公司-------康曼德www.hnicp.com</title>
<meta http-equiv="refresh" content="1;URL=yns_nlist.asp?t_id=<%=trim(request("n_tid"))%>&ts_id=<%=trim(request("n_tsid"))%>">
</head>

<body>
更新成功, 等待返回...
</body>
</html>
<%
rst.Close()
Set rst = Nothing
%>
<%
rsts.Close()
Set rsts = Nothing
%>