%
SnippetFolder = request("SnippetFolder")
'SnippetFolder = "/Public/Snippets"
SnippetFileName = "snippets.xml"
if right(SnippetFolder,1)<>"/" then
SnippetFolder = SnippetFolder & "/"
end if
SnippetPath = server.MapPath(SnippetFolder & SnippetFileName)
'response.Clear()
'response.write SnippetPath
'response.end
set Fs = server.CreateObject("Scripting.FileSystemObject")
VerifyFileExists()
if request.Form("saveSnippet")<>"" then
set objSnippets = getSnippetsList()
newXml = "" & vbcrlf
newXml = newXml & "" & vbcrlf
if request.Form("delete")<>"" then
for J=0 to objSnippets(0).childNodes.length - 1
if cstr(J) <> request.Form("IdSnippet") then
newXml = newXml & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & objSnippets(0).childNodes(J).childNodes(0).text & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & "" & vbcrlf
end if
next
elseif request.form("IdSnippet")<>"" then
'Update
for J=0 to objSnippets(0).childNodes.length - 1
if cstr(J) = request.Form("IdSnippet") then
newXml = newXml & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & replaceSpecialChar(request("description")) & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & "" & vbcrlf
else
newXml = newXml & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & objSnippets(0).childNodes(J).childNodes(0).text & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & "" & vbcrlf
end if
next
else
'Insert
for J=0 to objSnippets(0).childNodes.length - 1
newXml = newXml & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & objSnippets(0).childNodes(J).childNodes(0).text & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & "" & vbcrlf
next
newXml = newXml & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & replaceSpecialChar(request("description")) & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & vbtab & "" & vbcrlf
newXml = newXml & vbtab & "" & vbcrlf
end if
newXml = newXml & "" & vbcrlf
WriteSnippets(newXml)
response.Redirect("SnippetsBrowse.asp?Back=yes&SnippetFolder=" & request("SnippetFolder"))
elseif request.QueryString("IdSnippet") <> "" then
set objSnippets = getSnippetsList()
IdSnippet = clng(request.QueryString("IdSnippet"))
Title = objSnippets(0).childNodes(IdSnippet).getAttribute("title")
Desc = objSnippets(0).childNodes(IdSnippet).childNodes(0).text
Html = objSnippets(0).childNodes(IdSnippet).childNodes(1).childNodes(0).text
end if
function replaceSpecialChar(str)
replaceSpecialChar = replace(str,chr(34),"''")
end function
function WriteSnippets(XmlCont)
set myFile = Fs.OpenTextFile(SnippetPath,2,true)
myFile.write(XmlCont)
myFile.close
set myFile = nothing
end function
function getSnippetsList()
dim objXML
on error resume next
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
if err <> 0 then
response.Clear()
response.write "You need XML services installed on this server...See http://www.microsoft.com/xml for more information..."
response.end
end if
on error goto 0
objXML.validateOnParse = True
objXML.async = False
objXML.load(SnippetPath)
set getSnippetsList = objXML.getElementsByTagName("Snippets")
set objXML = nothing
end function
function VerifyFileExists()
if not Fs.FileExists(SnippetPath) then
set myFile = Fs.OpenTextFile(SnippetPath,2,true)
myFile.writeLine("" & vbcrlf)
myFile.writeLine("" & vbcrlf)
myFile.writeLine("" & vbcrlf)
myFile.close
set myFile = nothing
end if
end function
%>