by Mark Trescowthick - GUI Computing
Every web site worth its salt has at least one links page. In fact, there are far too many sites, in this correspondent's opinion, that consist of not much more than 100% links. And every link is a potential broken link, and every link is, therefore, a maintenance headache.
We'd had this particular headache for quite some time at GUI central, until I decided that some ASP and a small Access database made some sense. The application allows anyone to add a link, or to search for one, but only allows the privileged to rate submitted sites (we use a 1 - 5 rating, but you could use pretty much whatever you wanted) or to delete sites.
We're currently developing a generic utility to check from ASP whether a URL is valid (and to return parsed information from it, for other reasons) and that will be added to this application at some stage in the not-too-distant future, but for now link checking is up to you.
There's not much to this tiny application, but given the response (for which thanks!) I had to my equally simple Discussion Forum in our last issue, I felt that maybe there was someone out there who might see some value in it. So, with out further ado…
The application consists of a whopping three files (other than the database), and we need to look at each of them in turn to get an idea of how things hang together. They are CHARACTER.INC, PAGESTYLE.INC and LINK.ASP.
As with all of my "drop in" ASP applications, I like to control the look and feel (and any other character-specific information) in a separate include file, CHARACTER.INC. In this case, this file really doesn't have much to to, as you can see :
incPageName = "Links Demo" ' Links Name incODBCDSN = "Links" ' DSN Name incPrivateSwitch = "AVDF" ' Switch to allow Update Mode Dim incInterfaceOptions(1) ' Possible Interface styles Dim incExitURL(1) ' Exit points to here Dim incEmailAddress(1) ' Email address for queries ' Set up these arrays here incStyleDefault = 1 ' GUI is the default style
All my include file variables I preface with "inc", for what I hope are obvious reasons, and this file merely sets them up on entry to the application - in fact, on each entry to the page. I could have them all contained in Session variables, but I prefer to have them in this format purely for ease of maintenance - especially when I am "sharing" this application between various sites or when I am adding it to a new site.
IncPageName simply provides a title for the application, while
incODBCDSN should be set to the DSN you have created for your links database.
Of interest is
incPrivateSwitch, which is used to determine whether or not I am a privileged user (i.e. I can Rate and Delete links) or whether I am a normal user, in which case I can search and add links, but not rate or delete them. The way this is used is that I link to the application with
sLinkPrivate=<the private switch> and this puts us into maintenance mode. It's a pretty simple, some might say simplistic, approach, but it does the job.
You'll also note that three arrays are defined. I used these because I wanted the Links Manager to be used by both people searching from GUI Computing's home site and from AVDF's Links page. This is of course extensible, and you can add as many different "looks" to one Links Manager application as you need. They will, however, share all the links and link categories.
In this case,
incExitURL work together to provide "style" and exit point, and
incEmailAddress provides the feedback address. We determine which look to use from the URL from which the application is originally called. Of course, just in case I or someone else links to this page from a URL not containing one of these options,
incStyleDefault is the array position of the default style I'd like to use - in this case, some "GUI Computing" corporate branding is in order.
We'll see how these get used a little later, but first for the main event.
This, again, is a very simple piece of work, and most of it is pretty meat and potatoes stuff, and of little interest. However, the way I chose to manage navigation may be of some interest.
The initialisation section of LINK.ASP is quite long, and provides all the controlling logic for the application. It could use a Case statement rather than the long series of Ifs that I actually chose to employ, but I find that ifs provide a slightly neater method of navigating, especially when I want to "peel off" a few of the options, then work with the rest, as I do in this case.
First, though, I need to determine whether we're in "Update" mode, using the switch described above, and then, if this is our first time here, to set up the interface style that has been requested.
' determine what mode we're in and action it bAction = 0 ' if this isn't set, we just display search if request.querystring("sLinkPrivate") = incPrivateSwitch then ' Private (Update) Session("LinkPrivate") = 1 end if if Session("InterfaceStyle") = "" then ' set up styles sRefer = request.servervariables("HTTP_REFERER") for iLoop = 0 to uBound(incInterfaceOptions) if Instr(sRefer,incInterfaceOptions(iLoop)) <> 0 then Session("InterfaceStyle") = iLoop end if next if Session("InterfaceStyle") = "" then Session("InterfaceStyle") = incStyleDefault ' no match - use default end if end if
Now, I want to catch the options that lead to us exiting again, for one reason or another. In this case, they are if we exit the application or if we want to navigate off to a link. I catch these as they are the only two options that don't require a database connection and it's just easier and more efficient to get them out of the way up front.
' First catch direct exits if request.form("cmdCancel") <> "" then ' Exit application bAction = 1 ExitApplication end if if request.querystring("LinkID") then ' A Link has been clicked bAction = 1 if session("LinkPrivate") then ' Link Maintenance bAction = 2 else NavigateLink ' go to the link end if end if
Having got them out of the way, we can set up our connection and then work on finding out what needs to be done. Again, here, I could have used a case statement, but again that actually complicates matters in this case (no pun intended) so my old favourite If is employed.
' Set up DSN (never trust global.asa!) ' We now know we need it... Session("ConnectionString") = incODBCDSN Set OBJdbConnection = Server.CreateObject("ADODB.Connection") OBJdbConnection.Open Session("ConnectionString") if bAction = 2 then MaintainLink ' Link Maintenance requested if request.form("cmdnew") <> "" then ' Add a Link Requested bAction = 1 AddLink end if if request.form("cmdACancel") <> "" then ' Add a Link Cancelled bAction = 1 SearchLink end if if request.form("cmdAdd") <> "" then ' Add Link to Database Requested bAction = 1 dbAddLink end if if request.form("cmdSearch") <> "" then ' Search Requested. bAction = 1 SearchLink end if if request.form("cmdUpdateLink") <> "" then ' Update Link Requested (Private) bAction = 1 dbUpdateLink end if if request.form("cmdDelete") <> "" then ' Delete Link Requested (Private) bAction = 1 dbDeleteLink end if if bAction <> 1 then ' Gate for refresh, delete and first time in SearchLink End if ' Tidy Up OBJdbConnection.Close set objdbConnection = Nothing
As you can see, the application calls itself to perform each function, using either buttons or querystring setting to determine (above) what action to take.
The actual code for the application is so very simple I'll leave you to have a look at it in the source available for download. It really isn't much over ASP 101.
In simple terms, and you can see this from the way the demo application works (click here for normal user mode, and here for privileged user mode), if you are a privileged user then the application automatically lists unrated sites when you enter it. Normal users see nothing. You may then select the search criteria you want, or add a site.
Privileged users, when they click on a site in the site list, go not to the site itself, but to the site maintenance section of the application. Normal users whizz straight off to their selected site. Nothing could be simpler.
The other file that goes to make up the application is PAGESTYLE.INC. It is here that the "look" of each style must be specified, and I've included in the source a version which handles a GUI and AVDF look. Obviously, you'll want to add your own HTML here to get the look and feel you want. Here, I do use Case statements, as they make much more sense.
Really, for our use, I only needed to output page Headers, as the Footers just consist of
"</body></html>" but obviously your look and feel might require considerably more in the way of footers. I'd point out, too, that it may be that you wish to (or need to) add "look and feel" code into the way the Links Manager presents its links. In this case, it would be a simple matter to add additional routines to PAGESTYLE.INC to accommodate this as required.
This is another handy "drop in" component we use a lot, and the fact that it can present multiple looks easily means that it is fast to set up and easy to expand if you need to add a new look - it can be done even while users are actually in the application and, even if users link to it from odd places, you can be sure that your "corporate brand" is still going to be there.