<!--#include file="conn.asp"-->
<!--#include file="inc/cookies_check.asp"-->
<%
'**************************************
'* 软件名称 乐彼网上开店软件(56770 EShop)
'* 软件开发 http://www.56770.com
'* 版权所有 http://www.56770.com
'* 文件名称 Admin_autosave.asp
'* 最后更新 2012-06-03 by 56770.kingdge
'**************************************
include "lang/"& LangFilePath &"/lang_sys.inc"
If Eshop_Lebi_name="" Then
        adminflag()
End If
Lang =Request.QueryString("Lang")
mode =checknum(Request.QueryString("mode"),0)
IF Request.QueryString("act")="save" Then
        If Lang = "" Then
				SaveContent(0)
		Else
				SaveContent(Lang)
		End If
ElseIf Request.QueryString("act")="edit" Then
        If Lang = "" Then
				ExportAutoSaveJS(0)
		Else
				ExportAutoSaveJS(Lang)
		End If
End IF
Function BytesToBstr(body,Cset)
		On Error Resume Next
		Dim objstream
		Set objstream = Server.CreateObject("adodb.stream")
		objstream.Type = 1
		objstream.Mode =3
		objstream.Open
		objstream.Write body
		objstream.Position = 0
		objstream.Type = 2
		objstream.Charset = Cset
		BytesToBstr = objstream.ReadText
		objstream.Close
		Set objstream = Nothing
End Function
Function SaveContent(Lang)
        If Lang = "0" Then Lang = ""
		On Error Resume Next
		Dim objStream
		Set objStream = Server.CreateObject("ADODB.Stream")
		With objStream
		.Type = 2
		.Mode = 3
		.Open
		.Charset = "utf-8"
		.Position = objStream.Size
		.WriteText=BytesToBstr(Request.BinaryRead(Request.TotalBytes),"UTF-8")
		.SaveToFile Server.MapPath("temp/auto_"&server.urlencode(Eshop_Lebi_name) &"_"& Request.QueryString("type") & Lang &".txt"),2
		.Close
		End With
		Set objStream = NoThing
		If Err.Number=0 then
		Response.Write "<span style=""background-color: #FFDD3E;"">"&formatdatetime(now,4)&"<a href="""&auto_filename&""" target=""_blank"" style=""text-decoration: none;"">"& Lang_sys(53) &"</a>&nbsp;</span>"
		Else
		Response.Write "<span style=""background-color: #FFDD3E;"">"&formatdatetime(now,4)&""& Lang_sys(54) &"&nbsp;"&Err.Number&Err.description&"</span>"
		End If
		Response.End
End Function
Function ExportAutoSaveJS(Lang)
        If Lang = "0" Then Lang = ""
		Response.Clear
		Response.Write "function init"& Lang &"(){"
		If Request.QueryString("type")="normal"& Lang &"" Then 
				Response.Write "init_edit"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_edit"& Lang &""")){return CKEDITOR.instances.edit"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="brand"& Lang &"" Then 
				Response.Write "init_brand"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_b_content"& Lang &""")){return CKEDITOR.instances.b_content"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="news"& Lang &"" Then 
				Response.Write "init_news"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_content"& Lang &""")){return CKEDITOR.instances.content"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="help"& Lang &"" Then
				Response.Write "init_help"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_message"& Lang &""")){return CKEDITOR.instances.message"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="help_default"& Lang &"" Then
				Response.Write "init_help_default"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_help_content"& Lang &""")){return CKEDITOR.instances.help_content"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="gift"& Lang &"" Then 
				Response.Write "init_gift"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_info"& Lang &""")){return CKEDITOR.instances.info"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="product"& Lang &"" Then
				Response.Write "init_product"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_details"& Lang &""")){return CKEDITOR.instances.details"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="msg"& Lang &"" Then 
				Response.Write "init_msg"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_msg_content"& Lang &""")){return CKEDITOR.instances.msg_content"& Lang &".getData();}else{return postForm"& Lang &".value;}"
		End If 
		If Request.QueryString("type")="msgsend" Then 
				Response.Write "init_msgsend();"
				Response.Write "return postForm.value;"
		End If 
		Response.Write "  }"
		Response.Write "  function restore"& Lang &"(obj){"
		If Request.QueryString("type")="normal"& Lang &"" Then 
				Response.Write "init_edit"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_edit"& Lang &""")){CKEDITOR.instances.edit"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		If Request.QueryString("type")="brand"& Lang &"" Then 
				Response.Write "init_brand"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_b_content"& Lang &""")){CKEDITOR.instances.b_content"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		If Request.QueryString("type")="news"& Lang &"" Then 
				Response.Write "init_news"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_content"& Lang &""")){CKEDITOR.instances.content"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		If Request.QueryString("type")="help"& Lang &"" Then 
				Response.Write "init_help"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_message"& Lang &""")){CKEDITOR.instances.message"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		If Request.QueryString("type")="help_default"& Lang &"" Then 
				Response.Write "init_help_default"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_help_content"& Lang &""")){CKEDITOR.instances.help_content"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		If Request.QueryString("type")="gift"& Lang &"" Then
				Response.Write "init_gift"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_info"& Lang &""")){CKEDITOR.instances.info"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		If Request.QueryString("type")="msg"& Lang &"" Then 
				Response.Write "init_msg"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_msg_content"& Lang &""")){CKEDITOR.instances.msg_content"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		If Request.QueryString("type")="msgsend" Then 
				Response.Write "init_msgsend();"
				Response.Write "postForm.value=obj;"
		End If 
		If Request.QueryString("type")="product"& Lang &"" Then
				Response.Write "init_product"& Lang &"();"
				Response.Write "if (document.getElementById(""cke_details"& Lang &""")){CKEDITOR.instances.details"& Lang &".setData(obj);}else{postForm"& Lang &".value=obj;}"
		End If 
		Response.Write "  }"

		Response.Write "  var AutoSaveTime"& Lang &"=60;"
		Response.Write "  var FileName"& Lang &"=""temp/auto_"&server.urlencode(Eshop_Lebi_name) &"_"& Request.QueryString("type") & Lang &".txt"";"
		Response.Write "  var postForm"& Lang &" = null; "
		Response.Write "  var msg"& Lang &" = null; "
		Response.Write "  function init_edit"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.edit.txaContent;"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "  function init_brand"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.getElementById(""b_content"& Lang &""");"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "  function init_news"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.getElementById(""content"& Lang &""");"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "  function init_help"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.getElementById(""message"& Lang &""");"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "  function init_help_default"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.getElementById(""help_content"& Lang &""");"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "  function init_gift"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.getElementById(""info"& Lang &""");"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "  function init_msg"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.getElementById(""msg_content"& Lang &""");"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "  function init_msgsend(){"
		Response.Write "  postForm = document.getElementById(""msg_content"");"
		Response.Write "  msg = document.getElementById(""msg"");"
		Response.Write "  }"

		Response.Write "  function init_product"& Lang &"(){"
		Response.Write "  postForm"& Lang &" = document.getElementById(""details"& Lang &""");"
		Response.Write "  msg"& Lang &" = document.getElementById(""msg"& Lang &""");"
		Response.Write "  }"

		Response.Write "var ti"& Lang &"=AutoSaveTime"& Lang &";"
		Response.Write "function savedraft"& Lang &"()"
		Response.Write "{	 init"& Lang &"();"
		Response.Write "	if (postForm"& Lang &"!=null&&typeof(postForm"& Lang &")!=undefined){"
		Response.Write "		var url"& Lang &" = ""Admin_autosave.asp?act=save&type="& Request.QueryString("type") &"&lang="& lang &""";"
		Response.Write "		var postStr"& Lang &" = init"& Lang &"();"
		Response.Write "		if (postStr"& Lang &"){"
		Response.Write "		var ajax"& Lang &" = getHTTPObject"& Lang &"();"
		Response.Write "		ajax"& Lang &".open('POST', url"& Lang &", true); "
		Response.Write "		ajax"& Lang &".setRequestHeader(""Content-Type"",""application/x-www-form-urlencoded""); "
		Response.Write "		ajax"& Lang &".onreadystatechange = function(){if (ajax"& Lang &".readyState == 4 && ajax"& Lang &".status == 200) msg"& Lang &".innerHTML = ajax"& Lang &".responseText;};"
		Response.Write "		ajax"& Lang &".send(postStr"& Lang &");"
		Response.Write "		ti"& Lang &"=-1000;"
		Response.Write "		}else{"
		Response.Write "		msg"& Lang &".innerHTML = """& Lang_sys(55) &""";ti"& Lang &"=-1000;}"
		Response.Write "	}else{msg"& Lang &".innerHTML = """& Lang_sys(56) &""";ti"& Lang &"=-1000;}"
		Response.Write "}"
		Response.Write "function restoredraft"& Lang &"()"
		Response.Write "{ init"& Lang &"();"
		Response.Write "if (window.confirm('"& Lang_sys(57) &"'))"
		Response.Write "{"
		Response.Write "	if (postForm"& Lang &"!=null&&typeof(postForm"& Lang &")!=undefined){"
		Response.Write "		var url"& Lang &" = FileName"& Lang &";"
		Response.Write "		var ajax"& Lang &" = getHTTPObject"& Lang &"();"
		Response.Write "		ajax"& Lang &".open(""GET"", url"& Lang &"+'?random='+Math.random(), true); "
		Response.Write "		ajax"& Lang &".onreadystatechange = function() { "
		Response.Write "		if (ajax"& Lang &".readyState == 4 && ajax"& Lang &".status == 200) { "
		Response.Write "		restore"& Lang &"(ajax"& Lang &".responseText);"
		Response.Write "		msg"& Lang &".innerHTML ="""& Lang_sys(58) &"""; } } ;"
		Response.Write "		ajax"& Lang &".send(null); "
		Response.Write "		ti"& Lang &"=-1000;"
		Response.Write "	}else{msg"& Lang &".innerHTML = """& Lang_sys(56) &""";ti"& Lang &"=-1000;}"
		Response.Write ""
		Response.Write "}"
		Response.Write "}"
		Response.Write "function Viewdraft"& Lang &"()"
		Response.Write "{ "
		Response.Write "window.open(FileName"& Lang &",'','');"
		Response.Write "}"
		Response.Write "document.getElementById(""msg2"& Lang &""").innerHTML =""<a href='javascript:try{Viewdraft"& Lang &"()}catch(e){};' style='cursor:hand;'>"& Lang_sys(59) &"</a> <a href='javascript:try{restoredraft"& Lang &"()}catch(e){};' style='cursor:hand;'>"& Lang_sys(60) &"</a> <a href='javascript:try{savedraft"& Lang &"()}catch(e){};' style='cursor:hand;'>"& Lang_sys(61) &"</a>"";"
		Response.Write "function timer"& Lang &"() { "
		Response.Write "ti"& Lang &"=ti"& Lang &"-1;"
		Response.Write "var timemsg"& Lang &"=document.getElementById(""timemsg"& Lang &""");timemsg"& Lang &".innerHTML = ""<font color=red>""+ti"& Lang &"+""</font> "& Lang_sys(62) &""";"
		Response.Write "if (ti"& Lang &">=0){window.setTimeout(""timer"& Lang &"()"", 1000);}else{if (ti"& Lang &"<=-1000)"
		Response.Write "{ti"& Lang &"=AutoSaveTime"& Lang &";timer"& Lang &"();}else{timemsg"& Lang &".innerHTML = """& Lang_sys(63) &""";savedraft"& Lang &""
		Response.Write "();ti"& Lang &"=AutoSaveTime"& Lang &";timer"& Lang &"();}} }"
		Response.Write "window.setTimeout(""timer"& Lang &"()"", 0);"
		Response.Write "    function getHTTPObject"& Lang &"() {"
		Response.Write "	var xmlhttprequest=false; "
		Response.Write "    try {"
		Response.Write "	  xmlhttprequest = new XMLHttpRequest();"
		Response.Write "	} catch (trymicrosoft) {"
		Response.Write "	  try {"
		Response.Write "		xmlhttprequest = new ActiveXObject(""Msxml2.XMLHTTP"");"
		Response.Write "	  } catch (othermicrosoft) {"
		Response.Write "		try {"
		Response.Write "		  xmlhttprequest = new ActiveXObject(""Microsoft.XMLHTTP"");"
		Response.Write "		} catch (failed) {"
		Response.Write "		  xmlhttprequest = false;"
		Response.Write "		}"
		Response.Write "	  }"
		Response.Write "	}"
		Response.Write "	return xmlhttprequest;"
		Response.Write "    }"
		Response.Write "function killerrors() {return true;}window.onerror = killerrors;dd"
End Function
%>