related sites: <FREE Help> <ASP> <Asp.net> <worldwide> feedback: <lovethat> <hatethat> <thanks> <credits> <contact us>
Printout Creation <Next>
Content Linking Made Easy
We use the content-linker a lot and have provided a different layer of functionality above it. Here is a sample test script and our expanded libary.
Here is a sample file that calls the library <!--#include file="lib_toc_v4.asp"--> <% ' The Below Code is used to Test The Library if in doubt Call TOCpretty("/learn/learn.toc") ' Call TOC2Joust("/learn/learn.toc") ' Call TOC2Joust("/asplists/asplists.toc") ' x Call TOC2ColumnTable("/learn/learn.toc") ' Call TOCGrabSection("/learn/learn.toc","core.asp") ' Call TOCGrabSectionPretty("/learn/learn.toc","core.asp") ' Call TOCGrabSectionLimit("/learn/learn.toc","core.asp",6) ' Call TOCGrabSectionRandom("/learn/learn.toc","core.asp") ' Call TOCGrabSectionRandomLimit("/learn/learn.toc","core.asp",4) ' Call TOCList("/learn/learn.toc","/library/jump.asp") ' response.write TOCPageType("/learn/core.asp") ' response.write TOCPageType("/learn/dbtable.asp") ' Call TOCSection2ListBox("/learn/learn.toc","core.asp") %>
Here is the library <% ' version 98 ' bug: LimitRandom is sometimes one entry short ' draft: solution to caching issue, each call needs a moniker ' SUB TOCProcess is the Powerhouse here ' Almost every routine calls it ' It can return a string or response.write ' any content linker file and format output ' It can clip number of entries show and/or randomly arrange them FUNCTION printview() printview=False printsession=lcase(session("printview")) printrequest=lcase(request("printstatus")) If printsession="y" OR printrequest="y" then printview=True end if END FUNCTION SUB ShowTOC(parmTOC) Call TOCPretty(parmTOC) END SUB SUB TOC2ColumnTable(parmTOC) Call TOCProcess(parmTOC,"","2coltoc",0,false,false,false) END SUB SUB TOC2Joust(parmTOC) Call TOCProcess(parmTOC,"","joust",0,false,false,false) END SUB SUB TOCGrabSection(parmTOC,parmTarget) Call TOCProcess(parmTOC,parmTarget,"section",0,false,false,false) END SUB SUB TOCGrabSectionLimit(parmTOC,parmTarget,parmHowMany) Call TOCProcess(parmTOC,parmTarget,"section",parmHowMany,false,false,false) END SUB SUB TOCGrabSectionPretty(parmTOC,parmTarget) Call TOCProcess(parmTOC,parmTarget,"sectionpretty",0,false,false,false) END SUB SUB TOCGrabSectionRandom(parmTOC,parmTarget) Call TOCProcess(parmTOC,parmTarget,"sectionplain",0,true,false,false) END SUB SUB TOCGrabSectionRandomLimit(parmTOC,parmTarget,parmHowmany) Call TOCProcess(parmTOC,parmTarget,"sectionplain",parmHowMany,true,false,false) END SUB SUB TOCLevel1(parmTOC) Call TOCPretty(parmTOC) END SUB SUB TOCList(parmTOC,parmForm) Call TOCProcess(parmTOC,parmTarget,"listwhichtopic",0,true,false,false) END SUB SUB TOClistshort(tocname,jumpname) ' Legacy Code, rewrite or ditch Set TL = Server.CreateObject ("MSWC.NextLink") maxi= cint(TL.GetListCount(tocname))-1 adinfo="<a href='http://www.activeserverpages.com/contactus.asp'><strong>Contact Us...</strong></a>" adinfo="" response.write "<FORM ACTION='" & jumpname & "'>" response.write "<a href='/search/'>" response.write "<img src='/images/search.gif' alt='search' border='0' WIDTH='74' HEIGHT='24'></a>" response.write " <a href='/contactus/index.asp'>" response.write "<img src='/images/contact.gif' alt='contact' border='0' WIDTH='74' HEIGHT='24'></a>" response.write " " & adinfo response.write " <SELECT name='whichtopic'><OPTION SELECTED VALUE='/search>Search</option>" for i=1 to maxi desc=TL.GetNthDescription(tocname,i) if mid(desc,1,1)="*" then desc=mid(desc,2) temp="<OPTION value='" & TL.GetNthURL(tocname,i) & "'>" & desc & "</option>" response.write temp end if next set TL=nothing response.write "</SELECT> <INPUT VALUE='go!' TYPE='submit'>" response.write "<a href='http://www.charlescarroll.com'><img src='/images/cc.gif' border='0' width='150' height='27' alt='Charles Carroll'></a></FORM>" END SUB SUB TOCListSection(parmTOC,parmTarget) Call TOCProcess(parmTOC,parmTarget,"listwhichtopic",0,false,false,false) END SUB SUB TOCPretty(parmTOC) allformat=L1format & L2Format Call TOCProcess(parmTOC,"","pretty",0,false,false,false) END SUB SUB TOCSection2ListBox(parmTOC,parmTarget) Call TOCProcess(parmTOC,parmTarget,"listonly",0,false,false,false) END SUB SUB TOCshow(tocname) printer="<img src='http://www.activeserverpages.com/learn/printer.gif' WIDTH='33' HEIGHT='29' BORDER='0'>" printerlink="<a href='/learn/printswitch.asp'>" & printer & "</a> " barcolor="#CCCCFF" title=printer title=title & "<font face='Arial'><small><strong>Tutorial Questions? write <a href='mailto:aspquicklessons@activeserverpages.com'>aspquicklessons@activeserverpages.com</a> for help!" title=title & "</font></small></strong>" sn=request.servervariables("script_name") tocname=lcase(tocname) printstatus=lcase(session("printview")) If request("printstatus")="y" then printstatus="y" end if if printstatus="y" then imgnext="<img src='/learn/arrowright.gif' WIDTH='33' HEIGHT='14' BORDER='0'>" imgprev="<img src='/learn/arrowleft.gif' WIDTH='33' HEIGHT='14' BORDER='0'>" else imgnext="<img src='http://www.activeserverpages.com/learn/next.gif' BORDER='0'>" imgprev="<img src='http://www.activeserverpages.com/learn/previous.gif' BORDER='0'> " end if Set NL = Server.CreateObject ("MSWC.NextLink") thispage=NL.GetListIndex(tocname) lastpage=NL.GetListCount(tocname) 'response.write "thispage=" & thispage & "<br>" If thispage=0 then thisrefdesc="" ELSE thisrefDESC=NL.GetNthDescription(tocname,thispage) END IF If thispage<>lastpage AND thispage<>0 then nextref=NL.GetNextURL(tocname) nextrefdesc=NL.GetNextDescription(tocname) nextreflink="<a href='" & nextref & "'>" & nextrefdesc & " " & imgnext & "</a>" nextlink="<a href='" & nextref & "'>" & imgnext & "</a>" Else imgnext="" nextref="" nextrefdesc="" nextreflink="" end if If (thispage>1) Then prevrefdesc=NL.GetPreviousDescription(tocname) prevref=NL.GetPreviousURL(tocname) prevreflink="<a href='" & prevref & "'>" & imgprev & prevrefdesc & "</a>" prevlink="<a href='" & prevref & "'>" & imgprev & "</a>" else imgprev="" prevref="" prevrefdesc="" prevreflink="" end if SELECT CASE printstatus CASE "y" ' print view! host=request.servervariables("http_host") host="http://www.learnASP.com" response.write "<table border='0' width='100%' bgcolor='#CCCCFF'>" response.write "<tr><td align='center'>" & printerlink response.write "<font face='Arial'> <strong>" response.write host & sn & " by Charles M. Carroll</strong></font><br>" response.write prevlink & " " response.write "<font face='Arial' size='+1'><strong>Page " & thispage & "</strong></font>" response.write nextlink response.write "</td></tr></table>" CASE ELSE response.write "<table border='0' width='100%'>" response.write "<tr><td width='50%' bgcolor='#FFCC66'>" response.write "<font size='+1'><strong>" & thisrefdesc & "</strong>" response.write "</td>" response.write "<td width='50%' bgcolor='#FFCC66'>" response.write "<strong><small>" customTOC=false IF instr(tocname,"learn.toc")>0 THEN customTOC=TRUE%> <!--#include virtual="/learn/toolbar.asp"--> <%END IF IF instr(tocname,"asplists.toc")>0 THEN customTOC=TRUE%> <!--#include virtual="/asplists/toolbar.asp"--> <%END IF if customTOC=false THEN response.write "<a href='toc.asp'>Table of Contents</a> " response.write "<a href='/library/printswitch.asp'>PrintView</a>" END IF response.write "</small></strong></td></tr>" response.write "<tr>" & "<td width='50%' bgcolor='" & barcolor & "'>" response.write "<strong>" & prevreflink & "</strong></td>" response.write "<td width='50%' bgcolor='" & barcolor & "' align='right'>" response.write "<strong>" & nextreflink & "</strong>" response.write "</td></tr></table>" END SELECT set NL=nothing end sub FUNCTION TOCPageType(parmPageURL) ' Returns "page" or "toc" whichfile=server.mappath(parmpageURL) Set fs = CreateObject("Scripting.FileSystemObject") If fs.fileexists(whichfile) THEN ' do nothing ELSE response.write "Error, Non-existent File=" response.write whichfile & "<br>" & vbcrlf exit function END IF Set thisfile = fs.OpenTextFile(whichfile, 1, False) tempSTR=lcase(thisfile.readall) TOCPageType="page" IF instr("tocsubject.asp",tempSTR)>0 THEN TOCpageType="toc" END IF IF instr(tempSTR,"mutanttoc.asp")>0 THEN TOCpageType="toc" END IF IF instr(tempSTR,"mutantsection.asp")>0 THEN TOCpageType="toc" END IF thisfile.Close set thisfile=nothing set fs=nothing END FUNCTION SUB TOCProcess(parmDIR,parmTargets,parmFormat,parmLimit,parmRandom,byref parmString,parmDebug) ' parmDIR can be "/learn" or "/learn/learn.toc" ' parmtarget can be "" or a filename i.e. "test.asp" ' parmFormat ' L1-<b><strong>-</b></strong><p>- ' L2- -<br>- ' parmLimit ' maximum items (0= all) ' parmRandom ' True = Randomize order ' False = original order ' parmString ' True = Assign output to passed variable ' False = DisplayOutput normally DIM count, countmax, FullURL, Issection DIM Level, Linker, LinkDesc, LinkURL, LinkHREF DIM NameSection, pad ' First deal with parmDIR tocname=lcase(parmdir) IF instr(tocname,".toc")=0 THEN tocname=parmDIR & parmDIR & ".toc" TOCDIR=parmDIR ELSE tocname=parmDIR END IF If parmdebug=true THEN response.write "TOCname=" & TOCname & "<br>" END IF ' Now extract TOCDIR TOCDir=replace(TOCDIR,".toc","") findslash=instr(2,TocName,"/") tocDIR=mid(TocName,1,findslash-1) If parmdebug=true THEN response.write "TOCdir=" & tocDIR & "<br>" END IF ' Now extract section target Sectiontarget=lcase(parmTargets) If parmdebug=true THEN response.write "sectiontarget=" & sectiontarget & "<br>" END IF ' Now extract formats %> <!--#include virtual="/library/lib_toc_formats.asp"--> <% IF L1format="" THEN skipL1=TRUE END IF L1emptystring=L1eformat L1string=L1format L2string=L2format IF L1eformat="" THEN L1emptystring=L1string END IF If parmdebug=true THEN response.write "L1string=" & server.htmlencode(L1string) & "<br>" response.write "L2string=" & server.htmlencode(L2string) & "<br>" 'response.end END IF displayoutput=true If parmLimit>0 THEN displayoutput=false ELSE parmLimit=0 END IF If parmString=TRUE OR parmRandom=TRUE THEN displayoutput=false END IF ' Now work on the items Set Linker = Server.CreateObject ("MSWC.NextLink") countmax=cint(Linker.GetListCount(tocname)) redim preserve thelinks(countmax) thelinkscount=0 If displayoutput=TRUE THEN response.write TOCprefix END IF for counter=1 to countmax ' SETUP LinkDesc=Linker.GetNthDescription(tocname,counter) LinkURL =Linker.GetNthURL(tocname,counter) FullURL =TocDir & "/" & LinkURL IF mid(Linkdesc,1,1)="*" THEN linkDesc=mid(linkDesc,2) NameSection=lcase(linkURL) docType="L1" If counter<>countmax THEN LinkDescNext=Linker.GetNthDescription(tocname,counter+1) IF mid(LinkdescNext,1,1)="*" THEN doctype="L1empty" END IF END IF sectioncount=sectioncount+1 ELSE docType="L2" END IF IF SectionTarget="" THEN ' nothing to do ELSE IF SectionTarget<>NameSection THEN doctype="skip" END IF END IF IF doctype="L1" AND skipL1=TRUE THEN doctype="skip" END IF LinkHREF="<a href='" & FullURL & "'>" & linkDesc & "</a>" pagecounter=pagecounter+1 ' Fixes " problem inside Desc linkdesc=replace(linkdesc,"""",""") ' Now stuff the variables L1output=replace(L1string,"%%linkhref%%",LinkHREF) L1output=replace(L1output,"%%linkdesc%%",LinkDesc) L1output=replace(L1output,"%%linkurl%%",LinkURL) L1output=replace(L1output,"%%fullurl%%",fullURL) L1output=replace(L1output,"%%pagecounter%%",pagecounter) L1output=replace(L1output,"%%sectioncount%%",sectioncount) L1emptyoutput=replace(L1emptystring,"%%linkhref%%",LinkHREF) L1emptyoutput=replace(L1emptyoutput,"%%linkdesc%%",LinkDesc) L1emptyoutput=replace(L1emptyoutput,"%%linkurl%%",LinkURL) L1emptyoutput=replace(L1emptyoutput,"%%fullurl%%",fullURL) L1emptyoutput=replace(L1emptyoutput,"%%pagecounter%%",pagecounter) L1emptyoutput=replace(L1emptyoutput,"%%sectioncount%%",sectioncount) L2output=replace(L2string,"%%linkhref%%",LinkHREF) L2output=replace(L2output,"%%linkdesc%%",LinkDesc) L2output=replace(L2output,"%%linkurl%%",LinkURL) L2output=replace(L2output,"%%fullurl%%",fullURL) L2output=replace(L2output,"%%pagecounter%%",pagecounter) L2output=replace(L2output,"%%sectioncount%%",sectioncount) SELECT CASE lcase(doctype) CASE "l1" If displayoutput=TRUE THEN response.write L1output & vbcrlf END IF thelinks(thelinkscount)=L1output thelinkscount=thelinkscount+1 CASE "l1empty" If displayoutput=TRUE THEN response.write L1emptyoutput & vbcrlf END IF thelinks(thelinkscount)=L1emptyoutput thelinkscount=thelinkscount+1 CASE "l2" IF displayoutput=TRUE THEN response.write L2output & vbcrlf END IF thelinks(thelinkscount)=L2output thelinkscount=thelinkscount+1 CASE "skip" ' nothing to do END SELECT NEXT If displayoutput=TRUE THEN response.write TOCsuffix END IF set linker=nothing ' Re-arrange the output array if requested IF parmRandom=TRUE THEN FOR shuffler=1 TO 3 FOR counter=0 to thelinkscount-1 randomize randomnum=int(rnd*thelinkscount) randchoice=thelinks(randomnum) lastchoice=thelinks(thelinkscount) thelinks(thelinkscount)=randchoice thelinks(randomnum)=lastchoice NEXT NEXT END IF If parmString=TRUE THEN displayoutput=false END IF ' some calls want the string set and no display output IF parmstring=TRUE THEN IF parmLimit>0 THEN parmstring=TOCprefix FOR counter=0 TO parmLimit-1 parmString=parmString & thelinks(counter) NEXT parmString=ParmString & TOCsuffix END IF IF parmLimit=0 THEN parmString=TOCprefix FOR counter=0 to thelinkscount-1 parmString=parmString & thelinks(counter) NEXT parmString=ParmString & TOCsuffix END IF EXIT SUB END IF ' Since they don't want a string lets display what they want IF parmLimit>0 AND displayoutput=false THEN response.write TOCprefix FOR counter=0 TO parmLimit-1 response.write thelinks(counter) & vbcrlf NEXT response.write TOCsuffix END IF ' Show All Output If Needed IF parmLimit=0 AND displayoutput=false THEN response.write TOCprefix FOR counter=0 TO thelinkscount-1 response.write thelinks(counter) & vbcrlf NEXT response.write TOCsuffix END IF END SUB %>
Here is a supporting library <% SELECT CASE lcase(parmformat) CASE "xmltree" pad=" " L1format=pad & "<treenode type='folder' text='%%linkdesc%%'>" & vbcrlf L2format=pad & pad & "<treenode type='file' text='%%linkurl%%' />" & vbcrlf L1formatsuffix=vbcrlf & pad & "</treenode>" & vbcrlf L1eformat="" TOCprefix="<treenodes>" & vbcrlf TOCsuffix="</treenodes>" CASE "2coltoc" pad=" " leftcell="<td bgcolor='#99CCFF'>" rightcell="<td bgcolor='#CCCCFF'>" linklook="<strong><B>%%linkhref%%</strong></b>" L1format="<tr>" & leftcell & linklook & "<td></tr>" L2format="<tr><td>" & pad & "%%linkhref%%</td></tr>" L1eformat="<tr>" & rightcell & linklook & "<td></tr>" TOCprefix="<table cols='1' border='1' width='50%'>" TOCsuffix="</table>" CASE "joust" q = chr(34) linebreak=vbcrlf ' & "<br>" TOCprefix="<script language='JavaScript'>" & linebreak TOCprefix=TOCprefix & "function initialise() {" & linebreak TOCprefix=TOCprefix & "// Tell joust where to find the various index files it needs" & linebreak TOCprefix=TOCprefix & "index1 = ""index.htm"";" & linebreak TOCprefix=TOCprefix & "index2 = ""index2.htm"";" & linebreak TOCprefix=TOCprefix & "index3 = ""index3.htm"";" & linebreak TOCprefix=TOCprefix & "theBrowser.hasDHTML=false;" & linebreak TOCprefix=TOCprefix & "// Set up parameters to control menu behaviour" & linebreak TOCprefix=TOCprefix & "theMenu.autoScrolling = true;" & linebreak TOCprefix=TOCprefix & "theMenu.modalFolders = false;" & linebreak TOCprefix=TOCprefix & "theMenu.linkOnExpand = false;" & linebreak TOCprefix=TOCprefix & "theMenu.toggleOnLink = false;" & linebreak TOCprefix=TOCprefix & "theMenu.showAllAsLinks = false;" & linebreak TOCprefix=TOCprefix & "theMenu.focusOnLink = true;" & linebreak TOCprefix=TOCprefix & "theMenu.savePage = true;" & linebreak TOCprefix=TOCprefix & "theMenu.tipText = ""status"";" & linebreak TOCprefix=TOCprefix & "theMenu.name = ""theMenu"";" & linebreak TOCprefix=TOCprefix & "theMenu.container = ""self.menu"";" & linebreak TOCprefix=TOCprefix & "theMenu.reverseRef = ""parent"";" & linebreak TOCprefix=TOCprefix & "theMenu.contentFrame = 'text';" & linebreak TOCprefix=TOCprefix & "theMenu.defaultTarget = 'text';" & linebreak TOCprefix=TOCprefix & "// Initialise all the icons" & linebreak TOCprefix=TOCprefix & "initOutlineIcons(theMenu.imgStore);" & linebreak TOCprefix=TOCprefix & "// Now set up the menu with a whole lot of addMenu and addChild function calls" & linebreak TOCsuffix= "}" & linebreak & "</script>" L1format=linebreak & "var level%%sectioncount%%ID=-1;" & linebreak L1format=L1format & "theMenu.addEntry(-1, " L1format=L1format & q & "folder" & q & "," L1format=L1format & q & "%%linkdesc%%" & q & "," L1format=L1format & q & q & "," L1format=L1format & q & "%%linkdesc%%" & " help" & q & ");" L2format="theMenu.addChild(level%%sectioncount%%" & "ID," L2format=L2format & q & "Document" & q & "," L2format=L2format & q & "%%linkdesc%%" & q & "," L2format=L2format & q & "%%fullurl%%?view=joust" & q & "," L2format=L2format & q & "%%linkdesc%%" & " help" & q & ");" L1eformat=L1eformat & linebreak & "var level%%sectioncount%%ID=-1;" & linebreak L1eformat=L1eformat & "theMenu.addEntry(-1, " L1eformat=L1eformat & q & "document" & q & "," L1eformat=L1eformat & q & "%%linkdesc%%" & q & "," L1eformat=L1eformat & q & "%%fullurl%%?view=joust" & q & "," L1eformat=L1eformat & q & "%%linkdesc%%" & " help" & q & ");" CASE "section" L1format="" L2format=" %%linkhref%%<br>" CASE "sectionpretty" pad=" " L1format="<P><strong><B>%%linkhref%%</strong></b><br>" L2format=pad & "%%linkhref%% (%%linkurl%%)<br>" CASE "sectionplain" L1format="" L2format=" %%linkhref%%<br>" CASE "listwhichtopic" TOCprefix="<form action='/library/where.asp'>" TOCprefix=TOCprefix & "<select name='whichtopic'>" TOCsuffix="</select>" L1format="" L2format="<option value='%%fullurl%%'>%%linkdesc%%</option>" & vbcrlf CASE "listonly" L1format="" L2format="<option value='%%fullurl%%'>%%linkdesc%%</option>" & vbcrlf CASE "pretty" pad=" " L1format="<P><strong><B>%%linkhref%%</strong></b><br>" L2format=pad & "%%linkhref%% (%%linkurl%%)<br>" CASE ELSE response.write "unknown format" END SELECT %>
Here is the sample input file (notice the use of * to indicate hierarchy. This is my expansion of the content linker to deal with 2 level hierarchies).