The last piece of the application puzzle for this example is the browser support. A browser needs input in the way of HTML and script in order to provide the user with a display. In days past, it would have been possible to create individual Web pages using HTML and links to allow the user to navigate from one portion of the Web site to another. A help-desk application, however, provides too much information of a changeable nature to make individual Web pages a viable solution. That's why you need a combination of HTML, client-side scripting, and server-side scripting to make this type of solution work. As mentioned earlier, I made the design decision to use ASP to provide an easy-to-understand presentation. You could also implement this example using ASP.NET using Code Behind.
This script provides several features that might not be apparent at first. The script allows access to any page in the database using the same URL. The only thing that will change is the variables supplied to the script. If the user passes a Title variable, the script will initiate a search of the recordset for a help- desk title. On the other hand, if the user passes a Topic variable, the script will initiate a search for that topic number within the recordset. The interface allows the user to save in their Favorites folder help pages that get used a lot, but the use of a consistent URL reduces the chance that broken links will render those Favorites folder entries invalid.
Listing 11-3 contains the ASP code for this example. You can also find the listing in the Chapter 11\SimpleHelpDesk folder of the source code.
<%@Language="VBScript"%> <HTML> <HEAD> <!-Createthehelpdeskobjectandobtain-> <!-thecurrenttopicortitle.-> <% DimstrTopic DimstrTitle DimstrContents DimDataQuery SetDataQuery=Server.CreateObject("HelpAccess.HelpAccess") 'Determineifwe'relookingforatitleoratopicnumber. 'Usetherightcomponentmethodforthetypeofcall. IfLen(Request.QueryString("Title"))>0Then strTitle=Request.QueryString("Title") DataQuery.GetTitlestrTopic,strTitle,strContents Else strTopic=Request.QueryString("Topic") 'Makesurethetopicstringissetcorrectly. ifLen(strTopic)=0then strTopic="00000" EndIf DataQuery.GetTopicstrTopic,strTitle,strContents EndIf %> <!-Displaythecurrenttopictitleinthetitlebar.-> <TITLE> Thecurrenttopicis:<%Response.WritestrTitle%> </TITLE> </HEAD> <BODYID="ThisPage"> <!-Createaformtodisplayourpushbuttons.-> <FORMNAME="MyForm"> <!-Createtheappropriateheadings.-> <H1ALIGN=center>WelcometotheHelpDesk</H1> <H2ALIGN=center><B><%Response.WritestrTitle%></B></H2> <!-Displaythecontent.-> <% Response.WritestrContents %> <!-Provideaplacetosearchbytopic.-> <P><B>SearchbyTopic:</B><BR> <INPUTTYPE=textNAME="SearchValue"SIZE=40><P> <!-Allowtheusertosearchforthetopic.-> <INPUTTYPE=button VALUE="Search" ONCLICK="window.location.href='HelpDesk.asp?Title='+ MyForm.SearchValue.value"> <!-Makeiteasyfortheusertogetbacktothemainpage.-> <% IfNotRTrim(strTopic)="00000"Then Response.Write"<P>GoBacktothe" Response.Write"<AHREF=HelpDesk.ASP>MainPage</A>" EndIf %> </FORM> </BODY> </HTML>
As you can see, the code begins with the usual HTML tags. One problem ASP.NET solves is the mixture of code and tags shown in this listing. However, given the simplicity of this example, the mixture isn't a problem.
The first scripting task the code will perform is to create three variables to hold the contents of the database fields and make queries. The code also creates an object to hold the HelpAccess interface pointer. The CreateObject() method instantiates the object and allows the code to make further calls to the component, which will in turn interact with the database we created earlier in the chapter.
The code next determines whether the user has requested the main page by checking for a Title variable. If there isn't a title, there must be a Topic variable. Even if we're at the main Web page and there isn't any topic number to worry about, the code will create a default topic number value. Notice that the script uses the GetTitle() method for a title search and GetTopic() for everything else.
After the call to the component completes, we can start displaying information. The title bar will contain the Title field of the table, along with some additional descriptive text. The code uses the Response.Write() method to send data to the browser. Because this data is within the <TITLE> tag, it will appear in the title bar.
Creating a form and appropriate headings comes next. Notice that we're using a combination of standard HTML and scripting code here as well.
Finally, the code displays the body of the page. This includes writing the information from the Content field of the database. Remember that this field contains tags that will format the data on screen. Two <INPUT> tags allow us to display a text box and push button for the user to make queries. If this isn't the main Web page, we also want to provide the user with some way to get back to the main Web page. Notice we can use a simple HREF to accomplish this task.