<!--#include file="../Include/Const.Asp" -->
<!--#include file="../Include/ConnSiteData.Asp" -->
<!--#include file="../Include/System_Language.asp" -->
<!--#include file="../Include/Version.Asp" -->
<!--#include file="CheckAdmin.Asp"-->
<%
'*******************************************************
'软件名称：科蚁企业网站内容管理系统（KEYICMS）
'软件开发：成都神笔天成网络科技有限公司
'网   址：http://www.keyicms.com
'本信息不会影响您网站的正常使用，无论免费用户或是收费用户请保留这里的信息.
'神笔(5)天成网络享有软件著作权，如果您擅自删除这里的版权信息,我们将追究法律责任.
'未经公司同意禁止更改以下代码.
'*******************************************************
Call SiteInfo()
dim TemplateIndex, mTemplateIndex, TemplateView, mTemplateView
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="<%=Keyicms_Lang_Copyright(13)%>">
<meta name="author" content="<%=Keyicms_Lang_Copyright(3)%>">
<title><%=Keyicms_Lang_Copyright(1)%> <%=Str_Soft_Version%></title>
<!--#Include file="Keyicms_css.Asp"-->
</head>

<body>
<!--#Include file="Keyicms_Top.Asp"-->
<div id="wrap">
	<!--#Include file="Keyicms_Meun.Asp"-->
	<%
	If InStr(CompanyAdminPurview, "|1,") = 0 Then
		response.Write ("<br /><br /><div style='height:100%; text-align:center' class='main'><font style=""color:red; font-size:14px;"")>"&Keyicms_Lang_System(26)&"</font></div>")
		response.End
	End If
	%>
    <div class="main">
        <div class="row ">
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i> 当前位置</li>
                <li class="active">单页分类</li>
            </ol>	
        </div>
        <div class="row">
            <div class="col-lg-12 hideInIE8">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h2><i class="fa fa-edit"></i><span class="break"></span>单页管理</h2> 
                    </div>
                    <div class="panel-body">
                        <a class="ShortCut1" href="Ky_ApageEdit.Asp?Result=Add">  
                            <i class="fa fa-sign-in"></i>
                            <div class="title">添加单页信息</div>
                        </a>					
                        <a class="ShortCut2" href="Ky_Apage.Asp">  
                            <i class="fa fa-list"></i>
                            <div class="title">单页信息列表</div>
                        </a>				
                        <a class="ShortCut3" href="Ky_ApageSort.Asp">  
                            <i class="fa fa-sitemap"></i>
                            <div class="title">单页分类</div>
                        </a>				
                    </div>
                </div>
            </div>
        </div>
		<%
        Dim Action, FolderName
        Action = request.QueryString("Action")
        Select Case Action
			Case "Add"
				addFolder
				CallFolderView()
			Case "Del"
				Dim rs,sql,SortPath
				SortID = Conn.execute("Select * From keyicms_ApageSort where ID="&request.QueryString("id"))("ID")				
				'删除分类文件夹
				Set rs = server.CreateObject("adodb.recordset")
				rs.open "Select * from keyicms_ApageSort where ID=" & request.QueryString("id"), conn, 1, 2
				do until rs.eof
					FolderName = "/" & rs("FolderName")
					If mStatus Then Call DelFileFolder("/m" & FolderName)
					Call DelFileFolder(FolderName)
					rs.movenext
				loop
				rs.close : set rs = nothing
				'删除分类和信息在数据库里面的数据
				conn.execute("delete from keyicms_ApageSort where ID=" & request.QueryString("id"))
				conn.execute("delete from keyicms_Apage where SortID=" & SortID)
				Call SweetAlert("success", "操作成功", "成功删除本类、子类及所有下属信息条目！", "false", "location.replace('Ky_ApageSort.Asp')")
			Case "Save"
				saveFolder ()
			Case "Edit"
				editFolder ()
				CallFolderView()
			Case Else
				CallFolderView()
        End Select
        %>

        
    </div>
	<!--#Include file="Keyicms_End.Asp"-->
</div>
<!--#Include file="Keyicms_js.Asp"-->
</body>
<%
Function addFolder()
%>
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2><i class="fa fa-gears"></i><span class="break"></span><strong>【添加单页类别】</strong></h2>
            </div>
            <div class="panel-body">
            <form name="FolderForm" method="post" action="?Action=Save&From=Add" class="form-horizontal">
                <div class="form-group">
                    <label class="col-md-2 control-label" for="text-input">单页名称：</label>
                    <div class="col-md-4">
                        <input name="SortName" type="text" id="SortName" class="form-control" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label" for="text-input">文件夹名：</label>
                    <div class="col-md-4">
                        <input type="text" value="" class="form-control" name="FolderName" id="FolderName">
                        <span class="help-block">* 请使用英文、拼音、字母命名文件夹，请勿使用中文</span>
                    </div>
                </div>
                <%If EnableSeo = True Then%>
                <div class="form-group">
                    <label class="col-md-2 control-label">类别关键词：</label>
                    <div class="col-md-5">
                    	<input name="SeoKeywords" type="text" id="SeoKeywords" class="form-control" maxlength="250">
                        <span class="help-block">SEO：多个关键词请用“,”半角逗号分开，栏目页使用</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">类别描述：</label>
                    <div class="col-md-5">
                    	<input name="SeoDescription" type="text" id="SeoDescription" class="form-control" maxlength="250">
                        <span class="help-block">SEO：请填写描述，栏目页使用</span>
                    </div>
                </div>
                <%End If%>
                <div class="form-group">
                    <label class="col-md-2 control-label">PC单页栏目页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="TemplateIndex" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("PC", "Index")%>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">PC单页详细页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="TemplateView" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("PC", "View")%>
                        </select>
                    </div>
                </div>
                <%If mStatus Then%>
                <div class="form-group">
                    <label class="col-md-2 control-label">手机单页栏目页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="mTemplateIndex" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("Mobile", "Index")%>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">手机单页详细页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="mTemplateView" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("Mobile", "View")%>
                        </select>
                    </div>
                </div>
                <%End If%>

                <div class="form-group">
                    <div class="col-md-2 control-label"></div>
                    <div class="col-md-10">
                        <input name="submitSaveEdit" type="submit" id="submitSaveEdit" class="btn btn-danger" value="保存类别">
                        <input type="button" class="btn btn-success" value="<%=Keyicms_Lang_System(32)%>" onClick="history.back(-1)">
                    </div>	
                </div>
            </form>
            </div>  
        </div>
    </div>
</div>
<%
End Function

Function editFolder()
ID = request.QueryString("ID")
set rs = server.CreateObject("adodb.recordset")
rs.open "select * from keyicms_ApageSort where ID=" & ID, Conn, 1, 2
SortName = rs("SortName")
FolderName = rs("FolderName")
TemplateIndex = rs("TemplateIndex")
TemplateView = rs("TemplateView")
mTemplateIndex = rs("mTemplateIndex")
mTemplateView = rs("mTemplateView")
rs.close : set rs = nothing
%>
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2><i class="fa fa-gears"></i><span class="break"></span><strong>【修改单页类别】</strong></h2>
            </div>
            <div class="panel-body">
            <form name="FolderForm" method="post" action="?Action=Save&From=Edit&ID=<%=ID%>" class="form-horizontal">
                <div class="form-group">
                    <label class="col-md-2 control-label" for="text-input">单页名称：</label>
                    <div class="col-md-4">
                        <input name="SortName" type="text" id="SortName" class="form-control" value="<%=SortName%>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label" for="text-input">文件夹名：</label>
                    <div class="col-md-4">
                        <input type="text" value="<%= FolderName %>" class="form-control" name="FolderName" id="FolderName">
                        <span class="help-block"></span>
                    </div>
                </div>
                <%If EnableSeo = True Then%>
                <div class="form-group">
                    <label class="col-md-2 control-label">类别关键词：</label>
                    <div class="col-md-5">
                    	<input name="SeoKeywords" type="text" id="SeoKeywords" class="form-control" maxlength="250">
                        <span class="help-block">SEO：多个关键词请用“,”半角逗号分开</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">类别描述：</label>
                    <div class="col-md-5">
                    	<input name="SeoDescription" type="text" id="SeoDescription" class="form-control" maxlength="250">
                        <span class="help-block">SEO：请填写描述</span>
                    </div>
                </div>
                <%End If%>
                <div class="form-group">
                    <label class="col-md-2 control-label">PC单页栏目页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="TemplateIndex" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("PC", "Index")%>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">PC单页详细页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="TemplateView" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("PC", "View")%>
                        </select>
                    </div>
                </div>
                <%If mStatus Then%>
                <div class="form-group">
                    <label class="col-md-2 control-label">手机单页栏目页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="mTemplateIndex" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("Mobile", "Index")%>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">手机单页详细页模板：</label>
                    <div class="col-md-5">
                        <select id="select" name="mTemplateView" class="form-control" size="1">
                        <option value="">请选择...</option>
                        <%Call CheckAPage("Mobile", "View")%>
                        </select>
                    </div>
                </div>
                <%End If%>

                <div class="form-group">
                    <div class="col-md-2 control-label"></div>
                    <div class="col-md-10">
                        <input name="submitSaveEdit" type="submit" id="submitSaveEdit" class="btn btn-danger btn-lg" value="保存类别">
                    </div>	
                </div>
            </form>
            </div>  
        </div>
    </div>
</div>
<%
End Function

Function CallFolderView()
	datafrom = "Keyicms_ApageSort"
	taxis = "Order by ID desc"
	sql = "select * from ["& datafrom &"] "&taxis
%>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div data-original-title="" class="panel-heading">
				<h2><i class="fa fa-user"></i><span class="break"></span>单页分类 &nbsp;&nbsp;&nbsp;&nbsp; <a href="?Action=Add&ParentID=0" class="btn btn-danger btn-sm">添加分类</a></h2>
            </div>
			<div class="panel-body">
                <table id="datatable" class="table table-striped table-bordered bootstrap-datatable">
                <thead>
                <tr role="row">
                    <th>ID</th>
                    <th>标题</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
				<%	
                set rs = server.createobject("adodb.recordset")
                rs.open sql,conn,1,2
                do until rs.eof
                    Response.Write "<tr role='row'>" & vbCrLf
                    Response.Write "<td>"&rs("ID")&"</td>" & vbCrLf
                    Response.Write "<td><a href='?Result=Modify&ID="&rs("ID")&"' title="""&rs("SortName")&""">"&StrLeft(rs("SortName"),28)&"</a></td>"& vbCrLf
                    Response.Write "<td>"
                    Response.Write "<a title='修改' href='?Action=Edit&ID="&rs("ID")&"' class='btn btn-info'><i class='fa fa-edit'></i></a>"
					Response.Write "<a href='JavaScript:ConfirmDelSort(""Ky_ApageSort"","&rs("id")&")' class='btn btn-danger' title='删除'><i class='fa fa-trash-o '></i></a>"
                    Response.Write "</td>" & vbCrLf
                    Response.Write "</tr>" & vbCrLf
                    rs.movenext
                loop
                %>
                </tbody>
                </table>
			</div>
        </div>
    </div>
</div>
<%
End Function

Function CheckAPage(Ke01, TemType)
	If Ke01 = "PC" and TemType = "Index" Then Tem = TemplateIndex
	If Ke01 = "PC" and TemType = "View" Then Tem = TemplateView
	If Ke01 = "Mobile" and TemType = "Index" Then Tem = mTemplateIndex
	If Ke01 = "Mobile" and TemType = "View" Then Tem = mTemplateView

	TemplatePath = Conn.execute("select * from keyicms_Template where SortName='"&Ke01&"' and UseFlag")("TemplatePath")
	Set FSO = CreateObject("Scripting.FileSystemObject")
	Set File = FSO.GetFolder(Server.MapPath(TemplatePath&"/html"))
	For Each File_Item in File.Files
		FileName = File_Item.name
		If instr(FileName, "Apage_") = 1 Then
			If Tem = FileName Then
				response.Write "<option value='"&FileName&"' selected>"&FileName&"</option>"
			Else
				response.Write "<option value='"&FileName&"'>"&FileName&"</option>"
			End If
		End If
	Next
	Set Folder = nothing
	Set FSO = nothing
End Function

Sub saveFolder()
    Dim rs, sql
	From = request.QueryString("From")
	ID = request.QueryString("ID")
	Set rs = server.CreateObject("adodb.recordset")
	If Len(Trim(request.Form("SortName")))<1 Then
		Call SweetAlert("warning", "友情提示", "请填写信息标题！", "false", "history.back(-1)")
		response.End
	End If
	If Trim(request.Form("TemplateView")) = "" Then
		Call SweetAlert("warning", "友情提示", "请选择PC单页详细页！", "false", "history.back(-1)")
		response.End
	End If
	If Trim(request.Form("mTemplateView")) = "" and mStatus Then
		Call SweetAlert("warning", "友情提示", "请选择手机单页详细页！", "false", "history.back(-1)")
		response.End
	End If

	FolderName = Trim(request.Form("FolderName"))
	If FolderName = "" Then
		Call SweetAlert("warning", "友情提示", "请填写文件夹名！", "false", "history.back(-1)")
		response.End
	End If

	If From = "Add" Then
		If Conn.execute("select Count(*) from keyicms_ApageSort where FolderName='"&FolderName&"'")(0) > 0 Then
			Call SweetAlert("warning", "友情提示", "请填写文件夹名已存在，请重新填写！", "false", "history.back(-1)")
			response.End
		End If
		
		FolderName = "/" & FolderName
		If mStatus Then Call CreateFolder("/m" & FolderName)
		Call CreateFolder(FolderName)
		
		sql = "select * from keyicms_ApageSort"
		rs.Open sql, conn, 1, 3
		rs.addnew
		rs("SortName")=trim(Request.Form("SortName"))
		rs("FolderName") = RTrim(Request.Form("FolderName"))
		rs("SeoKeywords") = request.Form("SeoKeywords")
		rs("SeoDescription") = request.Form("SeoDescription")
		rs("TemplateIndex") = RTrim(Request.Form("TemplateIndex"))
		rs("TemplateView") = RTrim(Request.Form("TemplateView"))
		rs("mTemplateIndex") = RTrim(Request.Form("mTemplateIndex"))
		rs("mTemplateView") = RTrim(Request.Form("mTemplateView"))
		rs.update
		rs.close : set rs = nothing
	End If
	If From = "Edit" Then
		sql = "select * from keyicms_ApageSort where ID="&ID
		FolderName = "/" & FolderName
		NowPath = "/" & Conn.execute(sql)("FolderName")
		NewPath = FolderName

		If NowPath <> NewPath Then
			If mStatus Then Call fldrename("/m" & NowPath, "/m" & NewPath)
			Call fldrename(NowPath, NewPath)
		End If

		rs.Open sql, conn, 1, 3
		rs("SortName") = Trim(Request.Form("SortName"))
		rs("FolderName") = RTrim(Request.Form("FolderName"))
		rs("SeoKeywords") = request.Form("SeoKeywords")
		rs("SeoDescription") = request.Form("SeoDescription")
		rs("TemplateIndex") = RTrim(Request.Form("TemplateIndex"))
		rs("TemplateView") = RTrim(Request.Form("TemplateView"))
		rs("mTemplateIndex") = RTrim(Request.Form("mTemplateIndex"))
		rs("mTemplateView") = RTrim(Request.Form("mTemplateView"))
		ID = rs("ID")
		rs.update
		rs.close : set rs = nothing
	End If    
	Call SweetAlert("success", "操作成功", "设置成功！", "false", "location.replace('Ky_ApageSort.Asp')")
End Sub
%>