<!--#include file="../Inc/Conn.asp"-->
<!--#include file="../Inc/JMail.asp"-->
<%
If Session("UserName")="" Then
	Response.redirect("Login.asp")
End If
'--------提交工单-----------
If Request.Form("B1")<>"" Then
    Set rs=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support]"
    rs.Open Sql,Conn,1,3
    rs.AddNew
    rs("Title")=Request.Form("Title")
    rs("Author")=Session("UserName")
    rs("Content")=Request.Form("Content")
    rs("ClassId")=Request.Form("ClassId")
    rs("Time")=Now()
    rs.Update
    rs.Close
    Set rs=Nothing
    '邮件通知管理员
    SendEmail ""&s("AdminMail")&"",""&s("SiteName")&"工单通知","您好，有客户在平台上提交了工单，请您尽快前去处理，谢谢！<br/><br/><br/><br/><br/>"&s("SiteName")&"事务组","Jmail"
        Msg "恭喜，您提交工单成功，请耐心等待客服回复！","?"
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")=2
    rsUp.Update
    '新建子工单
    Set rs=Server.CreateObject("Adodb.RecordSet")
    Sql="Select * From [Support]"
    rs.Open Sql,Conn,1,3
    rs.AddNew
    rs("Author")=Session("UserName")
    rs("Content")=Request.Form("Content")
    rs("SId")=Id
    rs("Status")=0
    rs("Time")=Now()
    rs.Update
    rs.Close
    Set rs=Nothing
    '邮件通知管理员
    SendEmail ""&s("AdminMail")&"",""&s("SiteName")&"追加工单通知","您好，有客户在平台上对工单内容进行了追加，请您尽快前去处理，谢谢！<br/><br/><br/><br/><br/>"&s("SiteName")&"事务组","Jmail"
        Msg "恭喜，您追加工单成功，请耐心等待客服回复！","?"
End If
'--------完结工单-----------
If Request.Form("B3")<>"" 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/Style2.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="Content"]', {
	            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>
<div class="Border">
    <%
    Action=Request.QueryString("Action")
    ClassId=ReStr(Request.QueryString("ClassId"))
    Select Case Action
        Case "AddNew"
    %>
    <b class="Title">提交工单</b>
    <div class="TableInput">
        <form method="post" action="">
        <table>
            <tr>
                <td style="text-align:right;width:120px;">标 题：</td>
                <td><input class="Input" size="50" type="text" name="Title" /></td>
            </tr>
            <tr>
                <td style="text-align:right;">类 型：</td>
                <td style="padding-left:5px;">
                    <%
                    Set rs=Conn.Execute("Select * From [Support-Class]")
                    %>
                    <select name="ClassId">
                    <%
                    Do While Not rs.eof 
                    %>
                        <option value="<%=rs("ClassId")%>"><%=rs("ClassName")%></option>
                    <%
                    rs.MoveNext
                    Loop
                    rs.Close
                    Set rs=Nothing
                    %>
                    </select>
                </td>
            </tr>
            <tr>
                <td style="text-align:right;">内 容：</td>
                <td style="padding-left:5px;"><textarea name="Content" style="height:180px;visibility:hidden;"></textarea></td>
            </tr>
            <tr>
                <td></td>
                <td><input class="btnInput" type="submit" name="B1" value="提交工单" /></td>
            </tr>
        </table>
        </form>
    </div>
    <%
    Case "Show"
    %>
    <b class="Title"><span class="fl">工单详情</span><span class="fr"><a href="?">工单列表</a></span></b>
    <%
    Id=ReStr(Request.QueryString("Id"))
    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
    %>
    <div class="Sorry">对不起，找不到相关数据！</div>
    <%
    Else
    %>
    <div class="Table">
        <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
            %>
            <%
            If rs("Status")=2 Then
            %>
            <tr>
                <td style="text-align:center;">工单状态<br /><%=Now()%></td>
                <td style="padding-left:5px;">正在处理中(请您耐心等待，谢谢！)</td>
            </tr>
            <%
            End If
            %>
        </table>
    </div>
        <%
        If Not rs("Status")=0 Then
        %>
    <b class="Title">追加工单</b>
    <div class="TableInput">
        <form method="post" action="?Id=<%=rs("Id")%>">
        <table>
            <tr>
                <td><textarea name="Content" style="height:180px;visibility:hidden;"></textarea></td>
            </tr>
            <tr>
                <td><input style="margin-left:0px;" class="btnInput" type="submit" name="B2" value="继续提交" /><input class="btnInput" type="submit" name="B3" value="完结工单" /></td>
            </tr>
        </table>
        </form>
    </div>
        <%
        End If
        %>
    <%
    End If
        Case Else
    %>
    <b class="Title">工单列表</b>
    <%
    If Request.QueryString("page")="" Then
		Page=1
	Else
	Page=Cint(Request.QueryString("page"))
	End If
	PageListNum=10
	Set rs=Server.CreateObject("Adodb.RecordSet")
        SQL="Select Top "&(page*pagelistnum)&" * From [Support] Where [Author]='"&Session("UserName")&"'And [SId]=0 Order By Id Desc"
	rs.Open Sql,Conn,1,1
	If rs.eof And rs.bof Then
    %>
    <div class="Sorry">对不起，找不到相关数据！</div>
    <%
    Else
    %>
    <div class="Table">
        <table>
            <tr>
                <th>编 号</th>
                <th>标 题</th>
                <th style="width:160px;">时 间</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=Show&Id=<%=rs("Id")%>"><%=rs("Title")%></a></td>
                <td><%=rs("Time")%></td>
                <td><%If rs("Status")=0 Then%>已完结<%ElseIf rs("Status")=1 Then%>已回复<%Else%>处理中<%End If%></td>
            </tr>
    <%
    rs.MoveNext
    Loop
    rs.Close
    Set rs=Nothing
    %>
        </table>
        <div class="Page">
    <%
    Link="?"
	Sql="Select Count (*) As num From [Support]"
	Fy Sql,Page,Pagelistnum,Link
    %>
        </div>
    </div>
    <%
	End If
    End Select
    %>
</div>
</body>
</html>
