<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("canaws")="" Then
	ef=True
	ec="您没有此操作的权限。"
ElseIf Request.Form ("title")=""  and Request("op")="" Then
	ef=True
	ec="标题没填！"
ElseIf Request.Form ("con")="" and Request("op")="" Then
	ef=True
	ec="内容没填！"
ElseIf Request("id")<>"" and not IsNumeric(Request("id")) Then
	ef=True
	ec="编号必须是数字"
ElseIf Request("type1")<>"" and not IsNumeric(Request("type1")) Then
	ef=True
	ec="编号必须是数字"
ElseIf Request.Form ("Submit")="修改" and request.Form ("id")="" Then
	ef=True
	ec="编号ID没填！"
end if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_online_aws where id='"&Request("id")&"'"
		ds.Open Sql,conn,1,3
if Request("Submit")="继续发表" and ds.Eof then
	ef=True
	ec="没找到要继续发表的ID！"
end if
end if

if not ef then
if ds.Eof then
	ef=True
	ec="只能答复已有的问题！"
end if
end if

if not ef then
	Set dsuser = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&ds ("username")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsuser.Open Sql,conn,1,3
if dsuser.eof then
	ef=True
	ec="用户不存在!"
end if
end if

if not ef then
if Request("Submit")<>"继续发表" And Request("Submit")<>"again" then
Response.Redirect "e.asp?e=用户或代理才能发表新问题。"
ds.AddNew
ds("username")=session("username")
ds("title")=trim(request.Form ("title"))
ds("con")=Request.Form ("con")
ds("status")="新问题"
ds("agent1")=session("agentusername")
else
if Request("op")<>"close" then
'ds("username")=session("username")
'ds("title")=trim(request.Form ("title"))
ds("con")=ds("con")&vbcrlf&"-------工作人员 回复("&now&")-------"&vbcrlf&Request.Form ("con")
ds("status")="已回复"

if Request("sendit")="y" Then
ret=Send2Mail(conn,dsuser("username"),"您的问题已有回复",ds("con"))
ret="邮箱发送返回:"&ret
end If

if Request("sendsms")="y" then
Dim username
username=session("admusername")
ret2=SendSms(Request("SendNum"),Request("Content"),0,Now,"")
ret=ret&"短信发送返回:"&ret2
end if

ds("status")=request.Form ("status")

if ds("status")="处理中" then ds("status")="已回复"

else
ds("status")="已结束"
ds.Update
end if
end if
ds("type1")=Request.Form ("type1")
ds("posttime")=Now

username=ds ("username")

if Request("op2")="del" then
ds.delete
Response.Redirect "aws.asp?&soft=lsoft&pn="&Request("pn")&"&type1="&Request("typeX1")
end if
ds.Update
'ds.Close
'set ds=nothing
'conn.Close 
'set conn=nothing
Response.Redirect "aws.asp?&soft=lsoft&pn="&Request("pn")&"&type1="&Request("typeX1")&"&op="&Request("opX")&"&smsret="&ret&"&username="&username
end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>