<!--#include file="../Inc/Conn.asp"-->
<!--#include file="../Inc/JMail.asp"-->
<%
If Request.Cookies("UserName")="" Then
	Response.Write("<script language='javascript'>this.parent.location='login.asp';self.close();</script>")
End If
'二次验证与权限判断
Set rs=Conn.Execute("Select * From [AdminUser] Where [UserName]='"&Request.Cookies("UserName")&"'")
If rs.eof And rs.bof Then
    Response.Write("<script language='javascript'>this.parent.location='login.asp';self.close();</script>")
End If
If rs("Support")=False Then
    Response.Write("对不起，您无权限管理该区域！")
    Response.End()
End If
rs.Close
Set rs=Nothing
'-----变量赋值-----
ClassId=Request.QueryString("ClassId")
Action=Request.QueryString("Action")
Id=ReStr(Request.QueryString("Id"))
'-----回复工单-----
If Request.Form("B1")<>"" Then
    '更新主工单状态
    Set rsUp=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support] Where [Id]="&Id&""
    rsUp.Open Sql,Conn,1,3
    If rsUp.eof And rsUp.bof Then
        Msg "对不起，您要回复的工单不存在！","?"
    End If
    rsUp("Status")=1
    rsUp.Update
    '新建子工单
    Set rs=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support]"
    rs.Open Sql,Conn,1,3
    rs.AddNew
    rs("ReplyAuthor")=Request.Cookies("UserName")
    rs("ReplyContent")=Request.Form("ReplyContent")
    rs("SId")=Id
    rs("Status")=0
    rs("ReplyTime")=Now()
    rs.Update
    '邮件通知
    Set rsU=Conn.Execute("Select * From [Users] Where [UserName]='"&rsUp("Author")&"'")
    SendEmail ""&rsU("EMail")&"",""&s("SiteName")&"工单受理通知","您好，您的工单已经受理，请您前去查看客服回复，谢谢！<br/><br/><br/><br/><br/>"&s("SiteName")&"事务组","Jmail"
        Msg "恭喜，回复工单成功！","?Action=Reply&Id="&Id&""
End If
'--------完结工单-----------
If Request.Form("B2")<>"" Then
    Id=ReStr(Request.QueryString("Id"))
    Set rsUp=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support] Where [Id]="&Id&""
    rsUp.Open Sql,Conn,1,3
    If rsUp.eof And rsUp.bof Then
        Msg "对不起，您要完结的工单不存在！","?"
    End If
    rsUp("Status")=0
    rsUp.Update
        Msg "恭喜，您已经成功完结工单！","?"
End If
%>
<!Doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta http-equiv="Content-Language" content="zh-CN" />
    <meta name="author" content="神仙醋°" />
    <meta name="copyright" content="新空网络工作室" />
    <link rel="stylesheet" type="text/css" href="Images/Style.css" />
    <title>Page</title>
    <link rel="stylesheet" href="../KindEditor/themes/default/default.css" />
	<script type="text/javascript" charset="utf-8" src="../KindEditor/kindeditor-min.js"></script>
	<script type="text/javascript" charset="utf-8" src="../KindEditor/lang/zh_CN.js"></script>
	<script type="text/javascript">
	    var editor;
	    KindEditor.ready(function (K) {
	        editor = K.create('textarea[name="ReplyContent"]', {
	            uploadJson: '../KindEditor/asp/upload_json.asp',
	            resizeType: 1,
	            allowPreviewEmoticons: false,
	            allowImageUpload: true,
	            items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', '|', 'emoticons', 'image', 'link']
	        });
	    });
	</script>
</head>

<body>
<%
Select Case Action
    Case "Reply"
%>
<div class="Title">
    <a href="?">工单列表</a><span>工单受理</span>
</div>
<div class="Table">
    <%
    Set rs=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support] Where [Id]="&Id
    rs.Open Sql,Conn,1,1
    If rs.eof And rs.bof Then
    %>
    对不起，找不到相关数据！
    <%
    Else
    %>
    <table>
        <tr>
            <td style="padding-left:5px;width:150px;">工单编号：<%=right("0000"&rs("Id"),4)%></td>
            <td style="padding-left:5px;">工单标题：<%=rs("Title")%></td>
        </tr>
        <tr>
            <td style="text-align:center;"><%=rs("Author")%><br /><%=rs("Time")%></td>
            <td style="padding-left:5px;"><%=rs("Content")%></td>
        </tr>
        <%
        Set Re=Server.CreateObject("Adodb.RecordSet")
        Sql="Select * From [Support] Where [SId]="&rs("Id")&""
        Re.Open Sql,Conn,1,1
        Do While Not Re.eof
        %>
        <tr>
            <td style="text-align:center;"><%=Re("Author")%><span style="color:#1D7AD9"><%=Re("ReplyAuthor")%></span><br /><%=Re("Time")%><span style="color:#1D7AD9"><%=Re("ReplyTime")%></span></td>
            <td style="padding-left:5px;"><%=Re("Content")%><span style="color:#1D7AD9"><%=Re("ReplyContent")%></span></td>
        </tr>
        <%
        Re.MoveNext
        Loop
        %>
    </table>
    <%
    If Not rs("Status")=0 Then
    %>
    <form method="post" action="?Id=<%=rs("Id")%>">
    <table style="margin-top:5px;">
        <tr>
            <td style="padding:5px;"><textarea name="ReplyContent" style="height:180px;visibility:hidden;"></textarea></td>
        </tr>
        <tr>
            <td><input class="btn" type="submit" name="B1" value="回复工单" /><input class="btn" type="submit" name="B2" value="完结工单" /></td>
        </tr>
    </table>
    </form>
    <%
    End If
    %>
    <%
    End If
    %>
</div>
<%
    Case Else
%>
<div class="Title">
    <span>工单列表</span>
</div>
<div class="Table">
    <%
    If Request.QueryString("page")="" Then
		Page=1
	Else
	Page=Cint(Request.QueryString("page"))
	End If
	PageListNum=10
	Set rs=Server.CreateObject("Adodb.RecordSet")
    If Not ClassId="" Then
        If Request.Form("B0")<>"" Then
        SQL="Select Top "&(page*pagelistnum)&" * From [Support] Where [Id]="&Request.Form("SO")&" And [sId]=0"
        Else
        SQL="Select Top "&(page*pagelistnum)&" * From [Support] Where [ClassId]="&ClassId&" Order by [Id] Desc"
        End If
    Else
        If Request.Form("B0")<>"" Then
	    SQL="Select Top "&(page*pagelistnum)&" * From [Support] Where [Id]="&Request.Form("SO")&" And [sId]=0"
        Else
        SQL="Select Top "&(page*pagelistnum)&" * From [Support] Where [sId]=0 Order by [Id] Desc"
        End If
    End If
	rs.Open Sql,Conn,1,1
    If rs.eof And rs.bof Then
        Response.Write("对不起，找不到相关数据！")
    Else
    %>
    <div>
        <form method="post" action="">
            按<select name="SoType">
                <option value="1">编号</option>
            </select>
            <input style="width:30%;" class="Input" type="text" name="SO" />
            <input class="btn" type="submit" name="B0" value="查询" />
        </form>
    </div>
    <table>
        <tr>
            <th>编 号</th>
            <th>标 题</th>
            <th>作 者</th>
            <th style="width:17%">时 间</th>
            <th>状 态</th>
            <th></th>
        </tr>
    <%
    rs.PageSize=PageListNum
	rs.AbsolutePage=page
    Do While Not rs.eof
    %>
        <tr style="text-align:center;">
            <td><%=right("0000"&rs("Id"),4)%></td>
            <td style="text-align:left;padding-left:5px;"><a href="?Action=Reply&Id=<%=rs("Id")%>"><%=rs("Title")%></a></td>
            <td><%=rs("Author")%></td>
            <td><%=rs("Time")%></td>
            <td><%If rs("Status")=0 Then%>已完结<%ElseIf rs("Status")=1 Then%>已回复<%Else%>待处理<%End If%></td>
            <td class="link"><a href="?Action=Reply&Id=<%=rs("Id")%>">回复</a> <a href="?Action=Del&Id=<%=rs("Id")%>">删除</a></td>
        </tr>
    <%
    rs.MoveNext
    Loop
    %>
    </table>
    <div class="page">
    <%
    If Not ClassType="" Then
	Link="?ClassId="&ClassId&"&"
	Sql="Select Count (*) As num From [Support] Where [ClassId]='"&ClassId&"' And [sId]=0"
	Fy Sql,Page,Pagelistnum,Link
    Else
    Link="?"
	Sql="Select Count (*) As num From [Support] Where [sId]=0"
	Fy Sql,Page,Pagelistnum,Link
    End If
	%>
    </div>
    <% 
    End If
    rs.Close
    Set rs=Nothing
            %>
</div>
<%
End Select
%>
</body>
</html>
