
<!--#INCLUDE FILE="fupload.inc"-->
<!--#include file="../SQLconn.asp"-->

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<link rel="stylesheet" href="css/css.css">
<title>保存文件</title>


<link rel="stylesheet" type="text/css" href="../css/style.css" />
<style type="text/css">
<!--
.STYLE2 {color: #000000}
.STYLE3 {color: #3399FF}
-->
</style>
</head>
<body topmargin="5" leftmargin="5">

<p>
<%
if Request.ServerVariables("REQUEST_METHOD") = "POST" Then
'---------------------------
'response.write "开始发送<br>"
'---------------------------
Dim Fields
UploadSizeLimit=21212121
Set Fields = GetUpload()
dim Field
For Each Field In Fields.Items
if Field.name="id" then id=BinaryToString(Field.value)
if Field.name="send" then send=BinaryToString(Field.value)
if Field.name="title" then title=BinaryToString(Field.value)
if Field.name="sendto" then sendto=BinaryToString(Field.value)
if Field.name="rbnchaosong" then rbnchaosong=BinaryToString(Field.value)
if Field.name="content" then content=BinaryToString(Field.value)


if Field.name="file1" then
filename1=field.FileName
fileContentType1=field.ContentType
filevalue1=field.value
flength1=field.Length/1024/1024
end if

if Field.name="file2" then
filename2=field.FileName
fileContentType2=field.ContentType
filevalue2=field.value
flength2=field.Length/1024/1024
end if

if Field.name="file3" then
filename3=field.FileName
fileContentType3=field.ContentType
filevalue3=field.value
flength3=field.Length/1024/1024
end if

if Field.name="file4" then
filename4=field.FileName
fileContentType4=field.ContentType
filevalue4=field.value
flength4=field.Length/1024/1024
end if

if Field.name="file5" then
filename5=field.FileName
fileContentType5=field.ContentType
filevalue5=field.value
flength5=field.Length/1024/1024
end if


next


if flength1>CINT(request.cookies("filelength"))  or flength2>CINT(request.cookies("filelength")) or flength3>CINT(request.cookies("filelength")) or flength4>CINT(request.cookies("filelength")) or flength5>CINT(request.cookies("filelength"))  then
 %>  
<div align="center" class="STYLE1" title="提示信息框">
                <span style="BACKGROUND:#EEEEFF;COLOR:#FF6633;margin: 10px;border:1px dotted #FF6633;
				 font-weight:bold;padding:18px;width=540">
                单个附件太大，系统设定单个附件不能上传大于 <%=request.cookies("filelength")%> M的文件。</span>                 </div>
<%   
else

dim rsgonggaosql
dim rsgonggao

dim filename

'dim strtype 
dim strdateandtime
if  dateandtime<>"" then
   strdate=cdate(dateandtime)
else  
   strNow=now()
 end if
 
 
 
'检查系统有无收信人名单 
if send<>"" then
dim mysendto1
mysendto1=split(sendto,"|",-1,1)
for each sendtoinf in mysendto1
      set rscheck=server.createobject("adodb.recordset")
      rscheckSQL="select * from teachers where TName ='"&sendtoinf&"'" 
      rscheck.open rscheckSQL,conn,1,3
	  if  rscheck.eof and  rscheck.bof then
	      response.redirect   "FindError.asp?tname="&sendtoinf
	  end if 
next
end if
 
 
 
 
 
'取得最后一个ID   从存储过程取得gonggaoid

			dim fid 
			Set cmd = server.CreateObject("ADODB.Command")
			set Cmd.ActiveConnection = conn
			with Cmd
			   .CommandText = "incid"
			   .CommandType = 4
			   .parameters.Refresh
			   .parameters("@name") ="emailid"
			   .execute
			   fid = .parameters("@id")
			end with

'发送文件到数据库
set rsgonggao=server.createobject("adodb.recordset")
rsgonggaosql="select * from email where (id is null)" 
rsgonggao.open rsgonggaosql,conn,1,3
rsgonggao.addnew

rsgonggao("id")=fid
rsgonggao("sendto")=sendto
rsgonggao("title")=title
rsgonggao("content")=content
rsgonggao("Author")=request.cookies("tname")
rsgonggao("updateandtime")=strdate
if send="" then
rsgonggao("iscaogao")="1"    '标志为草稿
end if

rsgonggao("isChaoSong")=rbnchaosong

rsgonggao("updatetime")=now()
rsgonggao("upname")=request.cookies("tname")
strip=Request.ServerVariables("REMOTE_ADDR")
rsgonggao("upip")=strip
rsgonggao.update
rsgonggao.close



'原来的附件复制
 sql="INSERT INTO emailfile(fID, FileName, FileContentType,FileValue,FileLength)   SELECT '"&fid&"', FileName, FileContentType,FileValue,FileLength FROM emailfile WHERE fID='"&id&"'" 
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,3
rs.close 			
		
			
'多个附件

IF  filename1<>"" THEN
	  	    sql="select * from emailfile where (id is null)"
	        Set rs= Server.CreateObject("ADODB.Recordset")
			rs.open sql,conn,1,3
			rs.addnew 
			rs("fid")=fid
			rs("filename")=filename1
			rs("fileContentType")=fileContentType1
			rs("filevalue").appendchunk filevalue1
			rs("FileLength")=flength1
			rs.update 
			rs.close 
end if 


IF  filename2<>"" THEN
	  	    sql="select * from emailfile where (id is null)"
	        Set rs= Server.CreateObject("ADODB.Recordset")
			rs.open sql,conn,1,3
			rs.addnew 
			rs("fid")=fid
			rs("filename")=filename2
			rs("fileContentType")=fileContentType2
			rs("filevalue").appendchunk filevalue2
			rs("FileLength")=flength2
			rs.update 
			rs.close 
end if 

IF  filename3<>"" THEN
	  	    sql="select * from emailfile where (id is null)"
	        Set rs= Server.CreateObject("ADODB.Recordset")
			rs.open sql,conn,1,3
			rs.addnew 
			rs("fid")=fid
			rs("filename")=filename3
			rs("fileContentType")=fileContentType3
			rs("filevalue").appendchunk filevalue3
			rs("FileLength")=flength3
			rs.update 
			rs.close 
end if 


IF  filename4<>"" THEN
	  	    sql="select * from emailfile where (id is null)"
	        Set rs= Server.CreateObject("ADODB.Recordset")
			rs.open sql,conn,1,3
			rs.addnew 
			rs("fid")=fid
			rs("filename")=filename4
			rs("fileContentType")=fileContentType4
			rs("filevalue").appendchunk filevalue4
			rs("FileLength")=flength4
			rs.update 
			rs.close 
end if 

IF  filename5<>"" THEN
	  	    sql="select * from emailfile where (id is null)"
	        Set rs= Server.CreateObject("ADODB.Recordset")
			rs.open sql,conn,1,3
			rs.addnew 
			rs("fid")=fid
			rs("filename")=filename5
			rs("fileContentType")=fileContentType5
			rs("filevalue").appendchunk filevalue5
			rs("FileLength")=flength5
			rs.update 
			rs.close 
end if 






if send<>"" then

'标记发送文件给个人
set rssended=server.createobject("adodb.recordset")
rssendedsql="select * from emailsee where (sid is null)" 
rssended.open rssendedsql,conn,1,3

dim mysendto
mysendto=split(sendto,"|",-1,1)
for each sendtoinf in mysendto
    rssended.addnew
    rssended("fid")=fid
    rssended("ShouName")=sendtoinf
    rssended.update
next


rssended.close
end if 




conn.close

%>

 
</p>
<p>&nbsp;</p>
<div align="center">
  <table width="700" border="1" align="center" cellpadding="10" cellspacing="0" bgcolor="#F7FCFF" style="border-collapse:collapse">
    <tr>
      <td width="100%" height="20">
      <p align="center" class="STYLE1 STYLE2">成功--<%=send%></td>
    </tr>
    <tr>
      <td width="100%">
        <p align="center"><br>
          <span class="STYLE1 STYLE2">
          <%response.write title%>
          </span> <span class="STYLE3">已经成功发送或保存！</span></p>
        <p align="left"><span class="STYLE1 STYLE2"><br>
          新附件为：<br>
          <br>
          <%response.write filename1%>
          <br>
          <%response.write filename2%>
          <br>
          <%response.write filename3%>
          <br>
          <%response.write filename4%>
          <br>
          <%response.write filename5%>
          <br>
          
          
        </span></p>
        <center>
        <div align="center">
          <input name="button" type="button" class="topanniu"  onClick="location='sendfile.asp'"  value="继续发件" />
         
          <br>
        </div></td>
    </tr>
  </table>
</div>
 <%end if
 end if
 %>
</body>  
  
</html>  


