Web Assistant for Dummies
By Jonathan Baltazar, 4D, Inc. Technical Support
Technical Note 00-54
Technical Notes for Technical Notes for 00-11 November 2000
Introduction
The purpose of this tech note is to give 4D users a general idea of how to use the Web Assistant. The Web Assistant was designed for 4D developers and users who need to publish their data on the Internet or intranet without spending their time programming. This tech note will cover the areas of installation, basic functionality, and a demo database of what the Web Assistant can do.
Note: If you wish to use the Web Assistant, it can only be used with 4D v6.7 products.
Installation
The Web Assistant is a component that contains complete code for the 4D Web Assistant. The Web Assistant can be used with either 4D Standalone v6.7 or 4D Server v6.7. In the application folder (4D Standalone or 4D Server), you need to have the "4D Extensions" folder. This folder will contain the Web Assistant.
Modifying an Existing Database
If you have an existing database and wish to use the Web Assistant, you will have to install the Web Assistant component using 4D Insider. Open the existing database with 4D Insider and add the Web Assistant component by using the Install/Update option from the Components menu.
Now that you have installed the Web Assistant to the existing database, you will have to make some modifications to the following methods:
On Web Connection
Add the following line:
WbaOnWebConnect
On Web Authentication
Add the following lines:
C_TEXT($1; $2; $3; $4; $5; $6) C_BOOLEAN($0) $0:=wbaOnWebAuthentication($1; $2; $3; $4; $5; $6)
If you are using 4D Server, the following methods will have to edited as well:
On Server Startup
Add the following line:
wbaStartWeb
On Server Shutdown
Add the following line:
wbaQuitWeb
In order for the Web Assistant to work properly, a few settings from the two Web Server tabs of the Database Properties must be set correctly.
Web Server I
Uncheck "Publish Database at Startup"
Check "Start without context"
Web Server II
Check "Use Passwords"
New Database
If you wish to use include the Web Assistant for a new database, it is much easier to do so than to include it to an existing database. When creating a new database (4D Standalone or 4D Server v6.7), all that needs to be done is simply click the "Install 4D Web Assistant" option. By selecting this option as a new database is created, you will no longer have to edit the methods mentioned previously when adding the Web Assistant to an existing database. Simply selecting this option takes care of all methods and web serving options in "Database Properties".
Note: If the option is not selectable, it is because the Web Assistant was not installed properly for that specific application.
Basics of Web Assistant
Once the Web Assistant has been installed, execute the wbaPalette method from the User environment. By executing this method, the Web Assistant floating palette will appear.
The Web Assistant Palette provides access to all of 4D Web Assistant's features. The Web Assistant has four buttons to choose from, Start Web Service, Set Tables and Fields, HTML Editor and Appearance Editor.
Start Web Service
This button is a toggle button. Click it once, and it starts the Web service. Once the Web service is started the button changes to "Stop Web Services". Click on this button to stop the Web service.
Set Tables and Fields
When this button is selected, the User Access section is opened. The User Access section has three lists. The list to the left is a list of users that have permission to access the database. The center list displays all of the visible tables in the database. The list on the very right displays all the tables available to the selected user.
If your database is not set up with users and groups, 4D automatically sets up a Guest user. Web browsers are assigned guest access unless they login using a valid user name.
The list in the center displays all the tables in the database, while the list to the very right contains the tables that the Web browsers can display. Therefore, not all tables within the database must be displayed on the Web browser. In order to make a table from the database visible to the Web browser, select a table from the center list, and use the Insert or Append button to move it to the list to the very right. To make a table invisible from the Web browser, select a table from the list to the very right, and use the Remove button to remove it from that list.
The letters to the right of each table lets the developer know the type of access the user has for that specific table. The default access to the table is set to Read Only, this is denoted by the letter "r". Other letters that are used to denote the users access are, "a", "m" and "d".
r – Read only – The user only gets read access
a – Add – The user is allowed to read and add records
m – Modify – The user can read, add, and modify records
d – Delete – The user can create new records, modify existing records, and delete records
The List view allows the developer the ability to specify how the list of records will appear on the Web browser. From the List view, you can set the default sort field by clicking to the right of a field in the far right list. An "A" indicates the records being displayed will be sorted on this field in ascending order. If you wish to change the sort from ascending order to descending order, click on the "A", and change it to "D". The List view also allows you to set the number of records per page to be displayed to the user on the HTML page.
The Detail view allows the developer to specify how a single record should appear to the Web browsers. The first list displays the visible tables in the database. Click on a table in the list to select it. The second list displays the fields associated with that table. Use the Append, Insert, and Remove buttons to specify which fields you would like to be displayed to the users.
The Format button allows the developer to modify the appearance of the tables and fields. If you wish to modify a table or field, select it and click on the Format button. A dialog box will appear allowing you to set the appearance of the table/field when it is viewed by the Web browser.
Search Fields allows the developer to specify which fields will be available for searching. The list to the very right displays all fields that are searchable from the Web browser. To determine which fields are to be searchable, select a table from the table list, then select a field from the fields list, and then use Append, Insert, and Remove to determine which fields are to searched.
HTML Editor
Although every page created by the Web Assistant is created on-the-fly, sections of each page are always the same. These parts are stored as text documents in the 4D Web Assistant preferences folder. The Edit HTML dialog box allows you to edit these documents directly from your database.
The HTML Editor allows the developer to edit HTML headers and footers for the following pages:
Home Page
Login Page
List View Page
Detail View Page
Search Screen Page
Message Page – This page is used when errors occur.
Appearance Editor
The Appearance Editor is where the developer can modify the preferences of the HTML tables created by the 4D Web Assistant.
Quick Demo
Now that you have learned the basics about the Web Assistant, it is time to put it to work. The demo database I am using is the Music_Library database, which can be downloaded from:
http://www.4d.com/downloads/beginner_examples.html#new_beginner_examples
By following the steps for using the Web Assistant with an existing database, I had to install the Web Assistant using 4D Insider. After the Web Assistant was installed, I had to edit the On Web Connection and On Web Authentication methods, as well as change some settings in the database properties. Once the initial settings were completed, I could begin to use the Web Assistant. You will notice that by adding the Web Assistant, it adds the "wbaDialogs" table to the structure file.
From the User Access, the Guest values need to be set. For this demo, the tables that will be displayed to the Web browser are the Album, Artist, and Tracks tables. The default value of "r", read-only has been changed to "d". The "d" will allow the user to create new records, modify existing records, and delete records.
From the List View, the Guest values for each table need to be set. For the Album table, the fields that will be shown to the users are Artist_ID, Title, Year, Format, and Category. If you do not wish to show all these fields, you can choose which fields are to be displayed using the Append, Insert, and Remove buttons. To make things easy, all fields were selected and all records are shown in a list. In the Fields in List View, the "A" to the right of the Artist_ID has been set to be displayed in ascending order. The Artist table is set to display the Name of the artist field. The Tracks table is set to display the Album_ID, Track Number, and Track Title fields.
From the Detail View, the Guest values for each table also need to be set. For every record displayed for the Albums, Artist, and Tracks tables, all the fields for each have been selected. Therefore, for the Album table, the Artist_ID, Title, Year, Format, and Category fields will be displayed for each record. For the Artist table, the Name field will be displayed. From the Tracks table, the Album_ID, Track Number, and Track Title fields will be displayed.
Note: The same fields for each table were selected in both the List and Detail Views. The difference between each view is that the List View displays a list of records where as the Detail View displays a single record. So, the List and Detail views will display the exact same fields.
From the Search View, the Guest can only search specific fields. The fields that are set to searchable from the Album table are, Artist_ID, Title, and Category. From the Artist table, the searchable field is Name. From the Tracks table, the only searchable field is, Track Title.
After making these minor adjustments to the database, it is now ready to serve the Music Library database to the Web. To put the Web Assistant to work once more, click the "Start Web service" button. Notice that the button changes to "Stop Web service".
If you go to a Web browser and type in 127.0.0.1, you will notice that there is a default banner which reads, "Music_Library". Just beneath the banner, the user is able to select which table they wish to view. In this case, they have the option of choosing from the Album, Artist, or Tracks table.
Selecting the Album table, the user will be able to search for an album within the database. The search can be narrowed down by selecting one of the following options provided in the drop-down list, "Starts with", "Greater than", "Less than" and "Is exactly". There are three options provided to the users, they can either:
1. Search an album by "Artist_ID"
2. If an "Artist_ID" is not known, then, the users can view all records
3. Users have the option of adding a new record into the Album table. If a user decides to add a new record, a new Artist_ID will be assigned, and information such as Title, Year, Format and Category will need to be provided.
Selecting the Artist table, the user will be able to search for an album within the database. The search can be narrowed down by selecting one of the following options provided in the drop-down list, "Starts with", "Greater than", "Less than" and "Is exactly".
There are three options provided to the users:
1. Search an album by Name.
2. If the name is not known, the user can view all records.
3. Users have the option of adding a new record into the Artist table. If the user decides to add a new record, he will prompted to input an Artist's name.
Selecting the "Tracks" table, the user will be able to search for a Track Title within the database. The search can be narrowed down by selecting one of the following options provided in the drop-down list, "Starts with", "Greater than", "Less than" and "Is exactly".
There are three options provided to the users:
1. Search an album by Track Title.
2. If a "Title" is not known, the user can view all records
3. Users have the option of adding a new record into the Tracks table. If the user decides to add a new record, he will prompted to input an Album_ID, Track Number, and Track Title.
Note: Currently, the "New Record" option does not work on Windows 98.
The HTML Editor was used to edit the header and footer of the Home page. From the HTML Editor, some minor changes were made to the Web Assistants default display. These changes were made to show the basic functionality of the HTML Editor.
The Message tag was used (in the header) to insert the following message just below the Home page banner, "By the use of the 4D Web Assistant, you are able to view this database through a Web browser."
This was the code used to display the message:
<!--Message--><br><B> By the use of the 4D Web Assistant, you are able to view
this database through a Web browser.</B><br>
In the footer, the "NavBar" tag was used to insert a navigation bar at the bottom of the Home page. The "NavBar" tag places a navigation bar that allows the user to go directly to the Home, Album, Artist or Tracks page.
In the List of the HTML Editor, I placed the "Database Name" tag in the footer. Therefore, in each of the list views of any table (Album, Artist, or Tracks) the name of the database will appear at the very bottom. The name will be displayed like, "Music_Library". The tag is as follows:
<!--DatabaseName-->
Tags that are used by the Web Assistant and are not demonstrated in any other places other than where they should be are:
"4D Pict" – This tag inserts a 4D Logo. It is used in the footer of the Home page. Its tag is as follows:
<!--Another4Dsolution-->
"Login" – This tag is used in the header of the Homepage. It is used for users other than "Guest". Its tag is as follows:
<!--Login-->
"Login Pict" – This is used in the header of the Home page. This tag will display a picture of a key, representing the login link for users. The tag is as follows:
<!--LoginPict-->
"Search Pict" – This tag is used in header of the Search page. It displays a picture of a magnifying glass. Its tag is as follows:
<!--SearchPict-->
If you know HTML, you might want to give the database a look and feel of you own instead of using the default page setup by the Web Assistant. If you wish to redesign the Web pages, you may do so, only in the header and footers. Simply because there are predefined tags in the Web Assistant, does not mean that basic HTML can't be used. If you don't want to use the predefined tags in the Web Assistant, you do not have to, and can use standard HTML.
To show some functionality of what the Appearance Editor can do, the border number has been changed in the List and Detail views. The default settings for the borders is 0. Having the borders default to 0 means that there are no borders. By changing this number to something other than 0, you will add borders to the tables in the List and Detail views.
Conclusion
In conclusion, the 4D Web Assistant is a great component if you wish to have your database served over the Intranet or Internet. It is great for developers who have no experience or little experience with HTML. With its easy-to-use palette, it gives developers the ability to publish databases over the Internet, and then, allow them to make modifications willingly. It is a great tool for development and for quick, easy demos such as the sample database provided.
Now that we have covered the basics of the 4D Web Assistant, you are now ready to take an existing database, or create a new database, and publish it over the Internet.