<!--#include file="conn.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="inc/class_upload.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/editor/class_fckeditor.asp"-->
<%
Dim act,uScore,xShang
act=Trim(Request.QueryString("act"))
Dim AskD,inHtml
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	AskD.GetUserRole()
	siteinfo=AskD.siteinfo
	setting=AskD.setting
	UserRole=AskD.UserRole
if act="askupfileF" then
   call saveask()
else
	AskD.GetTemplate("T-myask.html")
    inHtml=RexHtml(AskD.tempbody)
    inHtml=RexHtml_IF(inHtml)
    Response.Write(inHtml)
end if
set AskD.myConn =Nothing
closedb
Set AskD = Nothing

Sub saveask()
Dim UpFile,sSavePath,UstrFtyp,ufl,pSavePath,Role,fck
Dim oFSO,oFile,Fso
	sSavePath ="UploadFile/"&Year(date())&Right("0"&Month(date()),2)&"/"
    pSavePath=replace(sSavePath,"UploadFile/","")
	oFile=server.MapPath(sSavePath)
	Set oFSO = server.CreateObject("Scripting.FileSystemObject")
	if oFSO.FolderExists(oFile)=false then
	   oFSO.CreateFolder(oFile)
	end if
	Set oFSO = Nothing
	set UpFile = New UpLoadClass
	UpFile.AutoSave = 2
	UpFile.MaxSize =  Int(setting(28) * 1024) '# (1024*1024=1M) SESSION里的单位为KB
	UpFile.FileType = setting(29)
	UpFile.SavePath = sSavePath
	UpFile.Open()
	If UpFile.Save("upfile",0) Then
	    UstrFtyp=Ucase(UpFile.strFtyp)
		IF UstrFtyp="TEXT/PLAIN" Then
		Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""注意，请上传正确文件！"");</script>"
		Response.End()
		End IF
	Else
		Select Case UpFile.Form("upfile_Err")
		Case -1 : Response.Write ""  '允许不上传文件
		Case 1 : Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""文件大小超出限制，请返回重新上传"");</script>":Response.End()
		Case 2 : Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""不允许上传的文件类型，请返回重新上传"");</script>":Response.End()
		Case 3 : Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""文件大小超出限制并且是不允许上传的文件类型，请返回重新上传"");</script>":Response.End()
		Case Else : Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""未知错误，请返回重新上传"");</script>":Response.End()
		End Select
	End If
	

Dim Title,Content,sClass,xShang,upfiles,addurl,userid,userpass,niming,nid,nscore,nltime,verycode
Dim rs,sql
Title=UpFile.Form("Title")
Content=UpFile.Form("Content")
Title=AskD.chkAllow(Title,1)
Content=AskD.chkAllow(Content,2)

verycode=UpFile.Form("verycode")
If verycode<>Cstr(session("SafeCode")) or verycode&""="" or session("SafeCode")&""=""  then
	Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""注意，请正确填写验证码！"");</script>"
	Response.End()
End IF

IF Title<>"" And Content<>"" Then

  IF UpFile.Form("select4")<1 Then
       IF UpFile.Form("select3")<1 Then
             IF UpFile.Form("select2")<1 Then
				IF UpFile.Form("select1")<1 Then
					Response.Write("请选择所属类别！")
					Response.End()
				Else
					sClass=UpFile.Form("select1")
				End If 
             Else
                sClass=UpFile.Form("select2")
             End If
       Else
             sClass=UpFile.Form("select3")
       End If
  Else
      sClass=UpFile.Form("select4")
  End If
xShang=UpFile.Form("xShang")
upfiles=UpFile.Form("upfile")
addurl=UpFile.Form("addurl")
userid=UpFile.Form("userid")
userpass=UpFile.Form("userpass")
niming=UpFile.Form("niming")
fck=UpFile.Form("fck")

Title=AskD.RemoveHTML(Title)
Content=AskD.ScriptHtml(Content,"iframe",2)
Content=AskD.ScriptHtml(Content,"script",2)
IF fck<>"1" Then Content=AskD.HTMLcode(Content)

Set UpFile = Nothing
IF niming="" Then niming=0

'判断登陆	
IF Request.Cookies("Muser")="" then
   set rs = Server.CreateObject("adodb.recordset")
   sql="select * from "&predb&"user where userid='"&userid&"' and userpass='"&md5(userpass,16)&"' and isLock=0"
   rs.open sql,conn,1,3
   IF rs.bof and rs.eof then
      Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""您没有发布的权限，请重新填写！"");</script>")
      IF upfiles<>"" Then 
      Set FSO = server.CreateObject("Scripting.FileSystemObject")
	    IF FSO.FileExists(Server.mappath(sSavePath&upfiles)) Then
           FSO.DeleteFile server.MapPath(sSavePath&upfiles),True
	    End IF
      Set FSO = Nothing
	  End IF
	  Response.End()
   Else
	  
      IF rs("Score")<Clng(xShang) Then
      Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""你目前的积分<font color=red><b>"&rs("Score")&"</b></font>小于您的悬赏分<font color=red><b>"&xShang&"</b></font>，请重新选择悬赏分值！"");</script>")
      IF upfiles<>"" Then 
      Set FSO = server.CreateObject("Scripting.FileSystemObject")
	    IF FSO.FileExists(Server.mappath(sSavePath&upfiles)) Then
           FSO.DeleteFile server.MapPath(sSavePath&upfiles),True
	    End IF
      Set FSO = Nothing
	  End IF
	  Response.End()
	  End IF
	  
	  nid=rs("id")
	  nscore=rs("score")
	  nltime=rs("lasttime")
	  
	dim cip
	CIP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
	If CIP="" then
	   CIP=Request.ServerVariables("REMOTE_ADDR")
	End If
      rs("PreviousIP")=rs("Lastip")
	  rs("PreviousTime")=rs("Lasttime")
	  rs("Lastip")=cip
	  rs("Lasttime")=now()
	  rs.update
	  
	  IF nscore=0 Then
	     Call AskD.Score(nid,setting(11),"首次登陆") '第一次登陆加20分
	  End If
      If DateDiff("h",nltime,now())>Hour(now()) Then
	     Call AskD.Score(nid,setting(12),"每天第一次登陆")  '每天第一次登陆加5分
	  End If
	  
	  Response.Cookies("Muser")=Rs("ID")
	  Response.Cookies("Musername")=Rs("userID")
	  Response.Cookies("Grade")=Rs("grade")
	  Response.Cookies("islock")=Rs("islock")
	End IF
	rs.close
    Set rs=nothing
Else
    IF Request.Cookies("islock")<>"0" Then 
       Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""您还未通过审核，无提问权限！"");</script>")
	   Response.End()
	End IF
End IF

dim c
set c=conn.execute("select count(asktime),min(asktime) from (select top 5 asktime from "&predb&"ask where askuser="&Request.Cookies("Muser")&" order by askid desc) a")
    if not(c.bof and c.eof) then
	   if datediff("n",c(1),now)<=c(0)*1.5 then
		     Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""请稍息 提问也太快了吧！"");</script>"
			 Response.End()
	   end if
	end if
set c=nothing

'权限判断
Role=UserRole(Request.Cookies("Grade"))
IF Instr(Role,",1,")=0 and upfiles<>"" Then 
   Set FSO = server.CreateObject("Scripting.FileSystemObject")
	 IF FSO.FileExists(Server.mappath(sSavePath&upfiles)) Then
	    FSO.DeleteFile server.MapPath(sSavePath&upfiles),True
	 End IF
   Set FSO = Nothing
   Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""您没有上传文件权限，请返回清除！"");</script>")
   Response.End()
End IF
IF Instr(Role,",2,")=0 and addurl<>"" Then 
   Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""您没有参考资料权限，请返回清除！"");</script>")
   Response.End()
End IF
IF Instr(Role,",3,")=0 and fck="1" Then 
   Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""您没有图文问答权限，请返回选择标准问答！"");</script>")
   Response.End()
End IF

IF niming="1" Then
   set rs = Server.CreateObject("adodb.recordset")
   sql="select Score from "&predb&"user where ID="&Request.Cookies("Muser")
   rs.open sql,conn,1,1
   if rs("Score")<clng(setting(23)) then
      Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""你目前的积分<font color=red><b>"&rs("Score")&"</b></font>小于您的匿名扣分<font color=red><b>"&setting(23)&"</b></font>，请取消匿名！"");</script>")
      IF upfiles<>"" Then 
      Set FSO = server.CreateObject("Scripting.FileSystemObject")
	    IF FSO.FileExists(Server.mappath(sSavePath&upfiles)) Then
           FSO.DeleteFile server.MapPath(sSavePath&upfiles),True
	    End IF
      Set FSO = Nothing
	  End IF
	  Response.End()
   rs.close
   Set rs=nothing
   end if
   Call AskD.Score(Request.Cookies("Muser"),-clng(setting(23)),"匿名提问")
End IF
	
'记入数据库
	Set rs=Server.CreateObject("Adodb.recordset")
	sql="select top 1 * from "&predb&"Ask order by Askid desc"		
	rs.open sql,Conn,1,3
		rs.AddNew
		rs("Title")=Title
		rs("Content")=Content
		if upfiles<>"" then
		rs("upfile")=pSavePath&upfiles
		end if
        rs("addurl")=addurl
		rs("sClass")=sClass
		rs("xShang")=xShang
		rs("AskUser")=Request.Cookies("Muser")
		rs("ansUser")=""
		IF setting(26)=0 Then
		rs("IsPass")=1
		End IF
		rs("AskTime")=Now()
		rs("niming")=niming
		rs.Update
	rs.Close
	Set rs=Nothing
	conn.execute("update "&predb&"user set askNum=askNum+1 where id="&Request.Cookies("Muser"))
	Call AskD.Score(Request.Cookies("Muser"),setting(13),"提交提问")
	Response.Write("<script runat=""server"">parent.refreshimg();</script>")
    Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""恭喜，发布提问成功！<br><br><center><a href='?'><font color='#598400'>继续提问</font></a> &nbsp;  &nbsp;  &nbsp; <a href='./'><font color='#598400'>返回首页</font></a></center>"");parent.document.frm.S3.disabled =true;setTimeout(""window.parent.location.reload()"",2000);</script>")
Else
    Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""请正确填写相应内容！"");</script>")
End If
end sub
%>