' Web Editor by Paul Ventura ' January 2008 ' copyright Paul Ventura ' revised March 9, 2008. '------------------------ ' This web pages uses xml technology to provide server side calls behind the seen ' and minimize the page refereshes. ' The key page that is called is commands.asp '------------------------ ' Portability issues ' if you move this page to a different site, then you must modify the following global constant. dim startpath dim starturl startpath = "\\nawinfs02\home\users\web\b471\rh.timothywgray\" starturl = "http://www.texasskiesdistrict.org/" '---------------------- '----- Global Variables for Moveable divs dim oldelm,lastrecordnumber,objField,gFindText,gFindCount bEdit = false bHTML = false bStartScroll = false bScrollCount = 0 dim cr cr = chr(13) & chr(10) dim gObj dim bEdit bEdit = false '-------'---------- sub window_onload() xmldso.src = "contacts.xml?tm=" & now() showlastupdate end sub '---------------- Sub tblData_onreadystatechange() if tblData.readystate="complete" then ' set the color of every other row for i = 1 to tblData.rows.length-2 step 2 tbldata.rows(i).style.backgroundcolor = "lightblue" tbldata.rows(i+1).style.backgroundcolor = "white" next end if end sub '---------------- Sub editrec() window.event.returnvalue = false window.event.cancelbubble = true set oElm = window.event.srcelement t= oElm.innertext if t = "save" then savedata oElm.innertext = "edit" else ans = Inputbox("Enter District Admin Password","TSD Password","*****") if ans <> "pass" then exit sub oElm.innertext = "save" end if set row = window.event.srcelement do while row.tagname<>"TR" set row = row.parentelement loop ' replace the objects with editable cells for each tag in row.all.tags("SPAN") if t="save" then tag.style.border="" tag.contenteditable = false tag.detachevent "onblur",getref("checksave") tag.style.backgroundcolor="" tag.detachevent "onfocus",getref("selectme") else tag.style.border="2px inset silver" tag.style.backgroundcolor="white" tag.contenteditable = true tag.attachevent "onblur", getref("checksave") tag.attachevent "onfocus", getref("selectme") tag.attachevent "onkeydown", getref("handlekey") end if next end sub '------------ function savedata() path = "\\nawinfs02\home\users\web\b471\rh.timothywgray\contacts.xml" text = xmldso.xml s = "cmd=SAVE" s = s & "&txtfile=" & escape(path) s = s & "&txtdata=" & escape(text) msg = sendcommand(s) window.status = msg msgbox "Conctacts saved at " & now end function '------------------ function handlekey() key = window.event.keycode window.status = key end function '------------------ function checksave() set elm = window.event.srcelement fldname = elm.datafld set par = elm do while par.tagname<>"TD" set par = par.parentelement loop ' now save the data to the datafld for each tag in par.all.tags("INPUT") if tag.datafld = fldname then tag.value = elm.innertext end if next end function '---------------- function selectme() set elm = window.event.srcelement set rng = document.body.createtextrange() rng.movetoelementtext elm rng.select end function '---------------- function ConvertPathToURL(path) ' this converts the file path to a url dim cmd,s ' convert folder and file to a url by replacing startpath with starturl url = replace(path,startpath,starturl) ConvertPathToURL = url end function '----------------- Function SendCommand(data) ' this will send a server side command. ' the syntax of the command ' cmd = server command ' defined in the command file ' path = file to be operated on ' text = data to be transmitted. ' note that the command should be a string of form data appended to it err.clear on error goto 0 on error resume next Dim xmlhttp,t Set xmlhttp = CreateObject("Microsoft.XMLHTTP") ' you have to escape the form data otherwise the spaces disappear. ' data = "txtdata=" & escape(text) & "&cmd=SAVE&txtfile=" & escape(path) ' Notice the two changes in the next two lines: ' command.asp location should be in same folder as webeditor page.(this page) window.status = "Please wait...." url="http:\\texasskiesdistrict.org\derby\command.asp" ' xmlhttp.async = false ' oXMLHttpRequest.open bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword xmlhttp.Open "POST", url,False xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.send data sendcommand = xmlhttp.responsetext if err.number<>0 then msgbox "Error " & err.number & cr & err.source & err.description else window.status = "done" end if end function '------------------ function mailit() window.event.returnvalue = false window.event.cancelbubble = true set elm = window.event.srcelement t = elm.innertext fldname = elm.datafld h = "mailto:" & t window.open h end function '---------------- function showlastupdate() 'Display the last modified date of the file. url = "contacts.xml" Set xmlhttp = CreateObject("Microsoft.XMLHTTP") xmlhttp.open "HEAD", URL, False xmlhttp.send sDate = xmlhttp.getResponseHeader("Last-Modified") dt1 = convertGMTdate(sDate) spModified.innertext = "Updated: " & dt1 end function '---------------- Function ConvertGMTDate(GMT) ' returns a date from a GMT date string ' ex Sat, 31 Oct 2009 20:40:56 GMT" dim ar,sDate ' parse the date string on the spaces ar = split(GMT," ") ' make familiar dd-mmm-yyyy format sDate = ar(1) & "-" & ar(2) & "-" & ar(3) ' convert to date ConvertGMTDate= cdate(sdate) end function '--------------- Function ConvertGMTTime(GMT) ' returns a date from a GMT date string ' ex Sat, 31 Oct 2009 20:40:56 GMT" dim ar ' parse the date string on the spaces ar = split(gmt," ") ' make familiar dd-mmm-yyyy format sDate = ar(1) & "-" & ar(2) & "-" & ar(3) ' convert to date ConvertGMTTime= cdate(ar(4)) end function