<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit
%>
<!--#include file="../Conn.asp"-->
<!--#include file="../HSK_Cls/HSK.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.FileIcon.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.EscapeCls.asp"-->
<!--#include file="Include/Session.asp"-->
<%
response.cachecontrol="no-cache"
response.addHeader "pragma","no-cache"
response.expires=-1
response.expiresAbsolute=now-1
Response.Addheader "Content-Type","text/html; charset=gb2312" 

Dim KSCls
Set KSCls = New Template
KSCls.HSK_Run()
Set KSCls = Nothing

Class Template
        Private KS
		'===========================================================================
		Private I, totalPut, TemplateSql, KS_T_RS
		Private TemplateType, ChannelID,DomainStr,MaxPerPage,CurrentPage,TotalPages
		Private FileItem, CurrPath, ParentPath,InstallDir,Path
		'=============================================================================
		Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  DomainStr=KS.GetDomain
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		End Sub
		Public Sub HSK_Run()
			If Not KS.ReturnPowerResult(0, "KMTL10006") Then                '模板管理的权限检查
			  Call KS.ReturnErr(1, "")
			  Exit Sub
			End If
			
			
			Select Case KS.G("Action")
			 Case "ConfigSave"
			   Call ConfigSave()
			 Case Else
			 	Call ConfigRead()

			End Select
		End Sub
		


	   '读取配置文件
	  Sub ConfigRead()
		Dim Action, TemplateID, ChannelID, TemplateType, TemplateName, FsoFileName, FnameType, TemplateContent, TemplateFileName, TemplateFromFileContent,Action1,FileName
		Dim  InstallDir, TemplateDIr,PageName
        TemplateFromFileContent=KS.ReadFromFile("../Task/TaskConfig.asp")
		
		Response.Write "<html><head><title>任务参数配置</title>"
		Response.Write "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
		Response.Write "<link href=""Include/Admin_Style.CSS"" rel=""stylesheet"" type=""text/css"">"
		Response.Write "<script type=""text/JavaScript"" src=""../HSK_JS/common.js""></script>"
		Response.Write "<script src=""../HSK_JS/jquery.js""></script>"
		%>
                    <script language = 'JavaScript'>
	
									
		            function show_ln(txt_ln,txt_main){
			            var txt_ln  = document.getElementById(txt_ln);
			            var txt_main  = document.getElementById(txt_main);
			            txt_ln.scrollTop = txt_main.scrollTop;
			            while(txt_ln.scrollTop != txt_main.scrollTop)
			            {
				            txt_ln.value += (i++) + '\n';
				            txt_ln.scrollTop = txt_main.scrollTop;
			            }
			            return;
		            }
		            function editTab(){
			            var code, sel, tmp, r
			            var tabs=''
			            event.returnValue = false
			            sel =event.srcElement.document.selection.createRange()
			            r = event.srcElement.createTextRange()
			            switch (event.keyCode){
				            case (8) :
				            if (!(sel.getClientRects().length > 1)){
					            event.returnValue = true
					            return
				            }
				            code = sel.text
				            tmp = sel.duplicate()
				            tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
				            sel.setEndPoint('startToStart', tmp)
				            sel.text = sel.text.replace(/\t/gm, '')
				            code = code.replace(/\t/gm, '').replace(/\r\n/g, '\r')
				            r.findText(code)
				            r.select()
				            break
			            case (9) :
				            if (sel.getClientRects().length > 1){
					            code = sel.text
					            tmp = sel.duplicate()
					            tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top)
					            sel.setEndPoint('startToStart', tmp)
					            sel.text = '\t'+sel.text.replace(/\r\n/g, '\r\t')
					            code = code.replace(/\r\n/g, '\r\t')
					            r.findText(code)
					            r.select()
				            }else{
					            sel.text = '\t'
					            sel.select()
				            }
				            break
			            case (13) :
				            tmp = sel.duplicate()
				            for (var i=0; tmp.text.match(/[\t]+/g) && i<tmp.text.match(/[\t]+/g)[0].length; i++) tabs += '\t'
				            sel.text = '\r\n'+tabs
				            sel.select()
				            break
			            default  :
				            event.returnValue = true
				            break
				            }
			            }
		            //-->
		            </script>
		<%
		Response.Write "</head>"
		Response.Write "<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>"
		Response.Write " <table width='100%' height='25' border='0' cellpadding='0' cellspacing='1' bgcolor='#efefef'>"
        Response.Write " <tr>"
        Response.Write " <td class='sort'><div align='center'><font color='#990000'>修改参数配置</font></div></td>"
        Response.Write "  </tr>"
        Response.Write "</table>"
		 Response.Write "<table width='100%' height=""350"" style=""background-color:#ffffff;padding-right: 2px;padding-left: 2px;padding-bottom: 0px;"" border='0' align='center' cellpadding='0' cellspacing='1' class='ctable'>"
		 Response.Write " <form name=""TemplateForm"" method=""post"" action=""?Action=ConfigSave"" onSubmit=""return(CheckForm())"">"	
		 		

		 Response.Write "   <tr id=""toplabelarea"" class=""clefttitle"">"
		 Response.Write "	<td valign=""top"" style=""text-align:left;color:red""><strong>注意：为了平台安全着想，建议把/Task/TaskConfig.asp 文件及目录设为不可写入权限，但不可以在后台编辑； 如需要在后台编辑，请把TaskConfig.asp文件允许写入权限。</strong></td>"
		 Response.Write "</tr>"
		 
		 Response.Write "   <tr id=""codearea"">"
		 Response.Write "   <td>"
		 Response.Write "     <table border='0' cellspacing='0' cellspadding='0'>"
		 Response.Write "	  <tr>"
		 Response.Write "       <td valign=""top"" width='20'>"
		 %>
		  <textarea name="txt_ln" id="txt_ln" cols="6" style="overflow:hidden;height:423;background-color:highlight;border-right:0px;text-align:right;font-family: tahoma;font-size:12px;font-weight:bold;color:highlighttext;cursor:default;" readonly="">
<% Dim N
For N=1 To 3000
 Response.Write N & vbcrlf
Next
%>
</textarea>
		             </td>
		             <td valign="top"><textarea name="Content" rows="2" cols="30" id="Content" onscroll="show_ln('txt_ln','Content')" onKeyDown="editTab()" onChange="TemplateContent.SetContentIni();" style="height:422px;width:100%;"><%=Server.HTMLEncode(TemplateFromFileContent)%></textarea>
					 <script>if(document.body.clientWidth>1200){
						 document.TemplateForm.Content.style.height=document.body.clientHeight-100;
						 document.TemplateForm.txt_ln.style.height=document.body.clientHeight-100;
						 }</script>
</td>
		             </tr>
					 </table>
					 <%
	 
		 Response.Write " </form>"
		 Response.Write "</table>"
		 Response.Write "</body>"
		 Response.Write "</html>"
			 Conn.Close:Set Conn = Nothing
		Response.Write "<script language=""JavaScript"">" & vbCrLf
		Response.Write "    function copy()" & vbcrlf
		Response.Write "{" & vbcrlf
		Response.Write "document.TemplateForm.Content.value=document.TemplateForm.Content.value;" & vbcrlf
        Response.Write "    document.TemplateForm.Content.select();" & vbcrlf
        Response.Write "    textRange = document.TemplateForm.Content.createTextRange();" & vbcrlf
        Response.Write "    textRange.execCommand(""Copy"");" & vbcrlf
		Response.Write "    alert('恭喜，当前代码已复制到剪贴板!');" & vbcrlf
        Response.Write "}" & vbcrlf
		Response.Write "function LabelInsertCode(Val)" & vbcrlf
		Response.Write "{"
		Response.Write " if (Val==null)" & vbcrlf
		Response.Write "  Val=OpenWindow('Include/LabelFrame.asp?sChannelID=" & ChannelID &"&TemplateType=" & TemplateType &"&url=InsertLabel.asp&pagetitle='+escape('插入标签'),260,350,window);"&vbcrlf
		Response.Write "if (Val!='')"
		Response.Write "{ " & vbcrlf
		If Request("flag")="text" Then
		Response.Write "document.TemplateForm.Content.focus();" & vbcrlf
		Response.Write "  var str = document.selection.createRange();" & vbcrlf
		Response.Write "  str.text = Val;"
		Else
		Response.Write "CKEDITOR.instances.Content.insertHtml(Val);"
		End If
		Response.Write " }" & vbcrlf
		Response.Write "}" & vbcrlf
		Response.Write "function InsertFunctionLabel(Url,Width,Height)" & vbcrlf
        Response.Write "{" & vbcrlf
        Response.Write "var Val = OpenWindow(Url,Width,Height,window);"
		Response.Write "if (Val!=''&&Val!=null)"
		Response.Write "{ document.TemplateForm.Content.focus();" & vbcrlf
		Response.Write "  var str = document.selection.createRange();" & vbcrlf
		Response.Write "  str.text = Val;"
		Response.Write " }" & vbcrlf
        Response.Write "}" & vbcrlf
		Response.Write "function CheckForm()" & vbCrLf
		Response.Write "{  if (confirm('确定要保存吗？\n\n建议保存之前先做好备份！'))"
		Response.Write "     {"
		Response.Write "    document.TemplateForm.submit();"
		Response.Write "    return true;}"
		Response.Write "    else{"
		Response.Write "     return false;"
		Response.Write "     }" & vbCrLf
		Response.Write "}" & vbCrLf
		Response.Write "</script>" & vbCrLf
		
	  End Sub
	  
	  Sub ConfigSave()
	  	Dim TemplateFileName, TemplateContent

		 TemplateContent = Trim(Request("Content"))
		 TemplateFileName = "../Task/TaskConfig.asp"
			 
		  If KS.WriteTOFile(TemplateFileName,TemplateContent) = True Then
			Response.Write "<script src='../HSK_JS/jquery.js'></script>"
			 Response.Write ("<script> alert('保存成功!'); location.href='?';</script>")
		  Else
			Call KS.AlertHistory("错误提示,可能原因:1.保存失败，模板文件不存在;\n2.目录没有写入权限", -1)
			Set KS = Nothing
		  End If
		End Sub

 End Class
%>