<!--#include file="../checkLoginPhone.asp"-->
<!--#include file="../SQLconn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>保存邮件文件</title>

<link rel="stylesheet" type="text/css" href="../images/<%=request.cookies("imgdir")%>/css/style.css" media="all"/>
</head>
<body  topmargin="5" leftmargin="5">

<p>
<%
		Set Upload=Server.createobject("Persits.Upload.1") 
		uploadlimitsize=request.cookies("filelength")                             '改变这个设置可以改变上传文件的大小限制，单位兆。
		Upload.SetMaxSize uploadlimitsize*1024*1024, True 
		Upload.Save  

		if err.number <> 0 then 
		response.write  "出现错误: " & err.number & "、" & err.description &"" 
		end if 
		if err.number = 8 then 
		  response.write " 你上传的文件超过限制（"& uploadlimitsize &"兆）<a href=""javascript:history.go(-1)"">重新上传</a>" 
		  response.end 
		end if 
         
		 
		send=Upload.Form("send").value
		title=Upload.Form("title").value
		sendto=Upload.Form("sendto").value
		rbnchaosong=Upload.Form("rbnchaosong").value
		content=Upload.Form("content").value
		checkboxDuanxin=Upload.Form("checkboxDuanxin").value
		
		if trim(title)="" then 
		     response.write  "出现错误,请输入有效标题！" 
			 response.end 
		end if 
		
		
		set FileObj1=Upload.Files("file1") 
		set FileObj2=Upload.Files("file2") 
		set FileObj3=Upload.Files("file3") 
		set FileObj4=Upload.Files("file4") 
		set FileObj5=Upload.Files("file5") 
 

 


				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") ="AllID"
							   .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
				
				
				'多个附件
				
				FileName1=FileObj1.FileName
				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")=FileObj1.FileName
							rs("fileContentType")=FileObj1.ContentType
							rs("filevalue").appendchunk FileObj1.Binary
							rs("FileLength")= FormatNumber(FileObj1.Size/1024/1024,2)
							rs.update 
							rs.close 
				end if 
				
				
				FileName2=FileObj2.FileName
				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")=FileObj2.FileName
							rs("fileContentType")=FileObj2.ContentType
							rs("filevalue").appendchunk FileObj2.Binary
							rs("FileLength")= FormatNumber(FileObj2.Size/1024/1024,2)
							rs.update 
							rs.close 
				end if 
				
				FileName3=FileObj3.FileName
				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")=FileObj3.FileName
							rs("fileContentType")=FileObj3.ContentType
							rs("filevalue").appendchunk FileObj3.Binary
							rs("FileLength")= FormatNumber(FileObj3.Size/1024/1024,2)
							rs.update 
							rs.close 
				end if 
				
				
				FileName4=FileObj4.FileName
				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")=FileObj4.FileName
							rs("fileContentType")=FileObj4.ContentType
							rs("filevalue").appendchunk FileObj4.Binary
							rs("FileLength")= FormatNumber(FileObj4.Size/1024/1024,2)
							rs.update 
							rs.close 
				end if 
				
				FileName5=FileObj5.FileName
				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")=FileObj5.FileName
							rs("fileContentType")=FileObj5.ContentType
							rs("filevalue").appendchunk FileObj5.Binary
							rs("FileLength")= FormatNumber(FileObj5.Size/1024/1024,2)
							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
					
					set Rscheck=Conn.Execute("select * from emailsee where  fid='"&fid&"' and  ShouName='"&sendtoinf&"'")
					if   Rscheck.eof and   Rscheck.bof then  '检查是否重发
							rssended.addnew
							rssended("fid")=fid
							rssended("ShouName")=sendtoinf
							if checkboxDuanxin="1" then 
								rssended("短信提醒")="已短信提醒"
							end if
							rssended.update
					end if
				next
				
				
				rssended.close
				end if 


              Upload.Dispose ' 释放内存 
              Set Upload = Nothing 

              conn.close

             Set MyOAASPObj = Server.CreateObject("YFSchoolOApro.YFSchoolDll")
           call  MyOAASPObj.SendToOAJingLing("邮件",fid)
		     set MyOAASPObj=nothing
			 
			 
			  '发送短信到手机
    if checkboxDuanxin="1" then
        Set MyOAASPObj = Server.CreateObject("YFSchoolOApro2.YFSchoolDll2")
        call     MyOAASPObj.EmailSendtoPhone(fID,title,request.cookies("tname"))
        set MyOAASPObj=nothing
	end if


         
%>

 
</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="继续发件" />
          &nbsp;&nbsp;&nbsp;
          
		 
          <br>
        </div></td>
    </tr>
  </table>
</div>
 
</body>  
  
</html>  


