[Top] [Prev] [Next] [Bottom] [Contents]

Finishing the Bookstore

Adding Bookstore HTML

The first thing you will do is add more HTML documents to your project. Select the Document Manager and Add the following documents from $SAPPHIRE/tutorials/tutorial2/html:

addpub.html
author_detail.html
authors.html
authors_add.html
publishers.html
publishers_detail.html

Finishing the Bookstore: Author Pages

Each paragraph in this section describes a binding that must be made in order to display the author pages. It is left to you to decide how to create each binding.

When you click the link See the Authors on home.html, the template authors.html should be displayed and populated with a list of authors' names broken down by their home states. The DSQL object BD_Authors selects the authors' names, ID numbers, and home states from the database, then orders them by state, last name, and first name. All of this information is placed in the data site AuthorHotList. The data is formatted with the population callback SaPopulateMasDetHotList-click Help to see the details of any population callback function. In order to format by home state, you must set Client Data when you select the callback. In this case, enter (void*)3 in the Client Data text field of the Results Detail Editor.

When you click an author's name in the authors.html Hotlist, the template author_detail.html should appear, populated with information about the selected author. The DSQL object BD_AuthorsDetail will get all the information about an author from the database if it is given the author's ID number. Therefore, you should set the value of the argument au_id to SaGetNArg(0). The function SaGetNArg(N) will pass the Nth input argument from an anchor. In this case, it will pass au_id, the 0th argument.

Defining the display of results is easy-each result column goes to an associated data site (state to State, for example), with the exception of au_snd_url, which does not have a data drop site in the HTML template. If you like, you can edit author_detail.html and add a data site for au_snd_url. No further formatting is needed for the results columns, although you can apply any population callbacks that appeal to you.

Each author's page should display a Hotlist of that author's books. When a AuthorHotList entry is clicked on authors.html, the author_detail.html template should be populated with data from the DSQL object BD_TitleByAuid. The argument au_id should be given the value SaGetNArg(0), so that the au_id of the Hotlist item clicked will be passed to BD_TitleByAuid, which will return a list of books by that author. The results columns should all populate the data site TitleHotList, formatted with the callback SaPopulateHotList.

Each author's page should also display a Hotlist of the author's publishers. When an author's Hotlist entry is clicked, the template author_detail.html should be populated with data from the DSQL object BD_PublisherByAuid. The argument au_id should again be given the value SaGetNArg(0), and the result columns should be used to populate PublisherHotList. PublisherHotList should be formatted with SaPopulateHotList.

If you test your project now, you will notice that the Hotlists in author_detail.html don't point to anything. You have already built much of the Bookstore, so you will use aliases to take advantage of the bindings you've made. Alias author_detail.html<A>TitleHotList to book_results.html<A>TitleDetail - clicking a book's title on an author's page should return the same results as clicking the title on the page of book search results. The activator author_detail.html<A>PublisherHotList should do the same thing as the activator publishers.html<A>PublisherHotList, but no publisher pages have been defined yet, so you will alias this activator later.

At the bottom of each author page and of the author Hotlist page, there is a link called Back to Home. The Install scripts for the previous tutorials rewrote these pages, replacing the HTML_test_URL_PLACEHOLDER tag with the URL of the project directory. For this project, you will make these changes yourself. You may either edit each document and change HTML_test_URL_PLACEHOLDER to the project directory URL, or you can use the Object Bind Editor to make a NULL binding from one of these anchors to home.html, then alias the other anchors to this binding. The second method has one advantage over the first - if you ever choose a new home page for your project, you will only have to change one binding and all of your pages will be referenced to the new home page.

Note: When you bind to the HTML_test_URL_PLACEHOLDER/home.html anchor, you will have to change the anchor name, as / and . are not valid characters for an anchor name.

Finishing the Bookstore: Publisher Pages

Each paragraph in this section describes a binding that must be made in order to display the author pages. It is left to you to decide how to create each binding.

When you click on the Publishers Information link on the project home page, the template publishers.html is displayed and populated with data from the DSQL object BD_Publishers. All of the results should be placed in the data site PublisherHotList and formatted with SaPopulateHotList.

When an item from PublisherHotList is clicked, the template publishers_detail.html is displayed and populated with data from BD_PublishersDetail. Be sure that BD_PublishersDetail receives only the publisher's ID number by setting the value of the argument pub_id to SaGetNArg(0). The name, city, and state of the publisher should be placed in the appropriate data sites. pub_id should not be displayed. None of these items need to be formatted with a population callback.

Clicking an item from the PublisherHotList should also populate publishers_detail.html with a list of the authors and the books associated with the publisher. A list of authors with the same pub_id can be generated with BD_AuthorsByPubid. The argument pub_id should again be given the value SaGetNArg(0) so that it will only be passed the first argument from the Hotlist item (pub_id), and not the publisher's name as well. All of the result columns from this DSQL object should be placed in AuthorHotList, and formatted with SaPopulateHotList.

The book Hotlist is created in the same way as the author Hotlist. Use BD_TitlesByPubid to retrieve the relevant titles, and place all the result columns in the data site TitleHotList. Be sure to format this as the other Hotlists.

Each item in the author Hotlist should show a profile of that author. You have already created a binding that does this: authors.html<A>AuthorHotList. Copy this same functionality by making publishers_detail.html<A>AuthorHotList an alias to authors.html<A>AuthorHotList.

Each item in the book Hotlist should show information about that book, just as with the items in the book_results.html<A>TitleDetail Hotlist. Create the appropriate alias.

Now you can finish work on author_detail.html. Alias the activator author_detail.html<A>PublisherHotList to the activator publishers.html<A>PublisherHotList.

At the bottom of each publisher page and of the publishers Hotlist page, there is a link called Back to Home. The Install scripts for the previous tutorials rewrote these pages, replacing the HTML_test_URL_PLACEHOLDER tag with the URL of the project directory. For this project, you will make these changes yourself. You may either edit each document and change HTML_test_URL_PLACEHOLDER to the project directory URL, or you can alias all of anchors to an existing NULL binding to home.html. As stated before, we recommend the second method.

Finishing the Bookstore: Book Pages

You may have noticed that the Hotlists on book_detail.html are not yet functional. Alias the AuthorDetail activator to authors.html<A>AuthorHotList, and alias the activator PublisherDetail to publishers.html<A>PublisherHotList.

If you like, you can now edit all of the book HTML documents and modify the Back to Home anchors. If you remove the current URLs and replace them with something like BACK_TO_HOME, you can then alias them as you did in the book and publisher pages. Feel free to skip this aliasing step and move on to the next section.

Finishing the Bookstore: Adding Authors

The pre-built Bookstore has one more function that has not been added to your Bookstore-a user can add publishers or authors to the database. This functionality can be added quickly and simply using DSQLs that are already in the tutorial database.

First, you will bind the Add an author anchor in authors.html to authors_add.html with a NULL binding. You may have to rename the anchor if it contains illegal characters like . and / .

Use the Document Manager to examine the HTML for authors_add.html, then Display the document in your browser. It contains the form AddAuthor that the user will use to submit information about a new author. When this form is submitted, three things should happen:

1. The author information should be added to the database.
2. The name au_id.gif should be added to the list of author image files in the database. The name au_id.wav should likewise be added to the list of author sound files. If either of these files exist, they will be included on the author's information page.
3. The browser should return to the author Hotlist.
Note: When making multiple bindings to one activator with different data objects, you can save time by clicking Apply after each binding is finished, then clicking the Data Object button to select a new object for the same activator.
The first binding to the AddAuthor form will add author information to the database with the DSQL object BD_AddAuthorInfo. Each argument passed to the DSQL has a corresponding element in the form-for example, the form element LastName is bound to the DSQL argument Lname.

The second binding to the form AddAuthor will add the names of the author's image and sound files to the database, whether or not they exist at present. The DSQL object BD_AddAuthorUrls will perform this operation. All three of the arguments to this DSQL should be bound to the form element SsNum. The gif and wav files will be named SsNum.gif and SsNum.wav.

The third binding to the form AddAuthor will return the user to authors.html. Recall that this page is dynamically generated from the authors.html template and the DSQL object BD_Authors. The author's ID number and name should be placed in the data site AuthorHotList.

The format of the list is up to you. If you would like an author Hotlist organized by home state, be sure to place the state result column in AuthorHotList, and format with the poplation callback SaPopulateMasDetHotList. The population callback should have a Client Data value of (void*)3, so that (counting from zero) the fourth result column (state) will be used to organize the list.

If you would rather that the user see a plain list of authors so that he or she can quickly check that the author was added correctly, do not include the state result column in the data site, and format with a simple SaPopulateHotList.

The last binding you will make to authors_add.html is a link to home.html. As before, you can either edit the HTML document and add the URL or can alias the current Back to Home anchor to an existing NULL binding to home.html.

Finishing the Bookstore: Adding Publishers

The bindings to addpub.html are more powerful than the author bindings you have completed. With 5 more bindings and a few lines of C code, users will be able to add, delete, and modify publisher information.

The first two bindings are simple NULL bindings. Bind the Back to Home anchor in addpub.html to home.html (use an alias if you like). Then bind the Goto Publisher Maintenance anchor in publishers.html to addpub.html.

The Publisher form in addpub.html has three functions-it can add a publisher, delete a publisher, and update a publisher. One object binding will be made for each of these functions. You will also enter a few lines of C code to control which of the three bindings is executed.

The DSQL object BD_ADD_PUBLISHER takes the publisher information supplied by the user and inserts it into the database. Each DSQL argument should be given the value of the appropriate form element-PublisherName is bound to pub_name, etc.

The DSQL object BD_Delete_Publisher will remove a publisher from the database if it is passed the publisher's 4-digit ID number. PublisherID should be passed along as pub_id. You can find out any publisher's ID number by choosing the View->Source browser command when the publisher Hotlist is displayed. The ID number is the last argument field. Beware that any Web user in the world can also view this number, and that you cannot rely upon it for security. In this project, a user must also have a username and password for the database before changes can be made.

The DSQL object BD_UPDATE_PUBLISHER will update publisher information if it is given the publisher's 4-digit ID number and the current publisher information. Once again, the form elements should be bound to the appropriate DSQL arguments.

You have bound three different objects to the same form. You must provide the project with some way of knowing which option the user selects, or else your project will try to add, delete, and modify each publisher entered, regardless of the user's wishes. The project will parse the user's form selections with the help of some functions included in the Sapphire/Web distribution.

Figure 5-1 Activator Code interface

Once you have specified the three Publisher form bindings completed, use the Object Bind Editor to edit the addpub.html<FORM>Publisher activator. Click on the Object Code icon (Fig. 5-2) in the Object Bind Editor to add C code to this binding.

Figure 5-2 Object Code icon

Then the lines of code you will be adding will seem very simple. You can do many powerful things using Sapphire/Web with only a basic knowledge of programming.

The names of the three bindings will appear in the section of the Object Code interface (Fig. 5-1) called Object Binding Execution Code. Select one of the three. The relevant lines of code will be displayed in the other window sections. Currently, there should be no code except for the bindings themselves.

Begin by selecting the binding that performs the "add publisher" function. We will refer to this binding as Add, although yours probably has a name like bind21.

Click in the Function Initialization Code text window and add the following lines:

SaSetDefaultUser(SaGetInputValue("DBUser"));
SaSetDefaultPass(SaGetInputValue("DBPassword"));
For Object Binding Execution Code, add:

if (SaIsSubmitName("Add Publisher"))
{
This line of code gets the name of the button the user clicked, and, if it was the Add button, executes the relevant code-in this case, your Add binding.

For After Object Binding Execution Code, add:

SaPrintf("Done adding publisher");
return;
}
These lines tell the user that the publisher has been successfully added.

For Function Final Code, add:

SaPopulateMsgBox(NULL,"Error",NULL);
This is the error message that the user will see if something went wrong.

Now select the name of the "delete publisher" binding. Notice that the code from the "add publisher" binding applies to this binding as well. You will change a few lines so that Delete will be handled only if it was the function selected by the user.

Change Object Binding Execution Code to:

if (SaIsSubmitName("Delete Publisher"))
{
and change After Object Binding Execution Code to:

SaPrintf("Deleted %d rows",SaGetAffectedRowCount());
return;
}
Now select the "update publisher" binding.

Change Object Binding Execution Code to:

if (SaIsSubmitName("Update Publisher"))
{
and change After Object Binding Execution Code to:

SaPrintf("Updated %d rows",SaGetAffectedRowCount());
return;
}
Click Ok when you are done.



[Top] [Prev] [Next] [Bottom] [Contents]

info@bluestone.com
Copyright © 1997, Bluestone. All rights reserved.