XLiRAD Tutorial
Part 3
Personalization part 1
< Go to Previous Tutorial

Getting Personal

The following shows by example how to create web pages that respond differently to different people. As we cover this topic, we will also touch on some more advanced techniques. As these pages are meant only to teach the techniques themselves, no effort will be made to address the design graphics of the webpages. Use your imagination to fill in what the final pages may be on your own web site.

Example 1: In-house personnel manager.

Here we create a web site to coordinate the employees of various departments within an organization. The idea is to have an employee be directed to the pages that are of importance to his/her department.

The first thing is to create a couple of tables.

personnel
departments

employee_number (int)
name (varchar)
password (varchar)
dept_number (int)

dept_number (int)
dept_name (varchar)
template_name (varchar)

Instead of making separate templates to input dummy test data, we're going to use the remote features of SQL Editor to manually insert data. Start up SQL Editor and click the New SQL icon, This opens up the Command Editor. In the text area at the top entitled SQL Statement type the following:

insert into departments (dept_number, dept_name, template_name)
values
(1, 'Administrative', 'dept_1.groupname')

The .groupname is the name of the group that will be appended to your template when you save it. Now click the Execute button near the lower left hand corner of the Command Editor. The Query Output window should say something like Null result set from query. Thats ok because an insert statement doesn't produce a result set. If you want to see if your insert was indeed successful, just type:

select * from departments

into the SQL Statement text area and hit Execute. This feature of SQL Editor is very handy and serves as a surrogate console for those who are used to UNIX systems. Complete the population of the departments table with the following data:

dept_number
dept_name
template_name
1
Administrative
dept_1.groupname
2
Tech Support
dept_2.groupname
3
Development
dept_3.groupname
4
Sales
dept_4.groupname
5
Marketing
dept_5.groupname
6
Accounting
dept_6.groupname

Once the departments table is populated you mat popluate the personnel table with the following data:

emplyee_number
name
password
dept_number
1001
Joe
what
1
1002
Jack
when
2
1003
John
where
3
1004
Jeb
why
4
1005
Jacques
who
5
1006
Lucy
how
6

Check to see if the data is correct by typing in select * from personnel and then hitting Execute.

The PersonnelLogin Template

This template is a straightforeward collection type page.

<HTML>
<HEAD>
<TITLE>
Personnel Login</TITLE>
</HEAD>

<BODY>
<CENTER>
<H2>
Personnel Login</H2><HR>
<FONT color="red"><H3>
<ERR><ERROR=Previous Template></ERR>
</H3></FONT>
<FORM action="/servlet/engine" method="post">
<INPUT type="hidden" name="TEMPLATE" value="PersonnelVerify.groupname">

<TABLE border>
<TR>
<TD>
NAME</TD>
<TD><INPUT type="text" name="name" value="<REP2>name</REP2>">
</TD>
</TR>
<TR>
<TD>
PASSWORD</TD>
<TD><INPUT type="text" name="password" value="<REP2>password</REP2>">
</TD>
</TR>
<TR><TD
colspan="2" align="center">
<INPUT type="submit" value="submit">
</TD></TR>
</TABLE>
</FORM>


</CENTER>
</BODY>
</HTML>

PersonnelVerify

This page simply verifies the name and passord. If no match is found it is redirected back to PersonnelLogin. If a match is found, the personnel data is extracted. Then the department data is extracted. Once this is done we are redirected to a RedirectionHub which goes to whatever template that was named in the department data extraction. Redirection pages need no have any HTML code because they are not meant to display anything in the browser.

<CMD>{get personnel info}COMMAND=5005&FORMAT=PAIRS&NULLMASK=FALSE
&FAILURE=NULL&ERRORTEMPLATE=PersonnelLogin.groupname
[Could not find a name-password match. Try again.]</CMD>

<CMD>{get department format}COMMAND=5006&FORMAT=PAIRS
&NULLMASK=FALSE&FAILURE=NONE</CMD>

<CMD>{Redirection}COMMAND=ext2&ERRORTEMPLATE=RedirectionHub.groupname</CMD>

We have the first two commands as command numbers 5005 & 5006. They can be whatever number you want as long as they don't conflict with other command numbers in the command list. Don't worry though, if you try to enter a new command in SQL Editor using a number already allocated, you will get an error message from SQL Editor. At any rate, duplicate command number will not exist.

Command 5005 looks like this:

select * from personnel where name='{name:7}' and password='{password:7}'

Command 5006 looks like this:

select * from departments where dept_number={dept_number:8}

The dept_number returned from command 5005 was used to search and return a result set in command 5006. We could have combined the two with a table join in one command like this:

select * from personnel a, departments b where a.name='{name:7}' and a.password='{password:7}' and a.dept_number = b.dept_number

Either way would work. I just wanted to show how each successive command can feed off the result set of the previous command.

RedirectionHub

This page consists of a single command that takes all the data from the previous page and sends it to the proper destination. The page consists of this command:

<CMD>{Redirection}COMMAND=ext2&ERRORTEMPLATE=<REP>template_name</REP></CMD>

The particular template is "REPPED" into the command. At this point the question may be asked as to why we need a separate page for this one command. Why not place this command at the bottom of PersonnelVerify? The answer is that the name-value pair for the redirection has to be available before the CMD tags are executed. The order of operations is:

1 <INC> Include Tags
2 <REP> Replace Tags
3 <CMD> Command Tags
4 <ERR>
<REP2>
Error and/or
Replace2 Tags

From this order of operations we can examine the previous page and see that the template_name is a result from command 5006 and is available only to <ERR> and <REP2> tags on the same page. If we send that data to another page, however, then such data can be "REPPED" into other commands and utilized.

But wait! What was that talk about result sets of commands feeding other commands? Command 5006 above fed off the results of command 5005. What is the difference here?

Command 5006 had the value pipped in the SQL statement itself and assumed that the data would be available for use. The Redirection External command (ext2) does not allow for any tags to be used except <REP> tags and thus creates a problem of priority. When designing your template flow you will frequently deal with this situation of operational order.

There actually is a way to put all the commands on the one page (PersonnelVerify) without going to a redirection hub. And how you might do it will be covered a little later. But for now it is easier to just send all the data to a redirection hub.

dept_1.groupname
dept_2.groupname
dept_3.groupname
dept_4.groupname
dept_5.groupname
dept_6.groupname

We will make sixtemplates that are nearly identical. These are the destinations from the RedirectionHub. The first template dept_1.groupname will look like this:

<HTML>
<HEAD>
<TITLE>
Dept. 1 Administrative</TITLE>
<STYLE type="text/css">
<!--
.title { font-family: Arial, Helvetica, sans-serif; font-size: 24pt;
font-style: italic; font-weight: bold; color: #6600CC}
.regular { font-family: Arial, Helvetica, sans-serif; font-size: 14pt;
font-weight: bold; color: #000000}
.small { font-family: Arial, Helvetica, sans-serif; font-size: 9pt;
font-weight: bold}
-->

</STYLE>
</HEAD>


<BODY bgcolor="#FBFDB5" text="#000000" link="#3300CC" vlink="#990099"
alink="#009900">
<DIV id="Layer1" style="position:absolute; left:194px; top:55px;
width:325px; height:45px; z-index:1"
class="title">
Administrative Page
</DIV>

<DIV id="Layer2" style="position:absolute; left:58px; top:115px;
width:571px; height:25px; z-index:2"
>
<HR>
</DIV>


<DIV id="Layer3" style="position:absolute; left:48px; top:165px;
width:263px; height:40px; z-index:3"
class="regular">
Welcome <REP2>name</REP2>
</DIV>

<DIV id="Layer4" style="position:absolute; left:467px; top:206px;
width:247px; height:149px; z-index:4"
>
<P><A href="dummy.htm" class="small">Employee management </A></P>
<P class="small"><A href="dummy.htm">Earnings report</A></P>
<P class="small"><A href="dummy.htm">Travel report</A></P>
<P class="small"><A href="dummy.htm">Investors</A></P>
</DIV>

</BODY>
</HTML>

This is basically just a display page with no commands on it. All the data has been extracted from the PersonnelVerify page and was directed here. On the PersonnelVerify page the template_name was extracted with command 5006 and set it to the RedirectionHub. The template_name was REPPED into the redirection command (ext2) and sent to one of six templates. The above shows dept_1.groupname and pertains to the Administrative department. After you type in the HTML code above into Template Maker you can save it as dept_1, dept_2, dept_3 etc just changing the title header in Layer1.

Template Name
Layer1 Title Header
dept_1.groupname
Administrative
dept_2.groupname
Tech Support
dept_3.groupname
Development
dept_4.groupname
Sales
dept_5.groupname
Marketing
dept_6.groupname
Accounting

Test it out

Check to see if everything is working well. Type in your browser locator bar:

http://www.yoursite.com/ServletAlias?TEMPLATE=PersonnelLogin.groupname

 

RedirectionHub Revisited

Here is a diagram of what we just constructed:

As promised before we will now explain how you can achieve the same flow without using a redirection hub.

Examine the single command on the RedirectionHub.groupname:

<CMD>{Redirection}COMMAND=ext2&ERRORTEMPLATE=<REP>template_name</REP></CMD>

External command 2 (ext2) does only one thing. It throws an exception unconditionally. By utilizing Form Processor's error handling capabilities we are able to direct the flow anywhere we designate.

If we want to get rid of the RedirectionHub then we have to figure out a way to for Form Processor to throw conditional exceptions.

 

Error Banking

To follow a curve or an incline off of an error. Error Banking is a term I coined to describe redirection of a template based on conditional errors. There are different ways of going about it and I'm sure you can create your own methods. Here are a couple of techniques I use.

First, create a table in your database called dummy_table. It has only one field named duh. It matters not if it is a varchar or int, it can be whatever you want. Just make sure that it never has more than one record in it.

Now open up SQL Editor and click on the New SQL icon. Type in the following:

select 'ERROR' from dummy_table where {dept_number:8} = 1

What we're doing here is utilizing SQL's ability to create pseudo columns to return a string if a match occurs, in this case if the department number is 1. Save this command as Command ID 5010.

Place the cursor at the very bottom of PersonnelVerify.groupname and hit the CMD icon. Choose the tab on the left that reads NONE. Type 5010 in the Command ID text box. Type redirect to dept 1 in the CommandName text box. From the Error Condition drop down list select Result Set Exists. For the Error Template text box type in dept_1.groupname. Leave the Error Message text box blank. Hit the Submit button. At the bottom of PersonnelVerify.groupanme template you should see:

<CMD>{redirect to dept 1}COMMAND=5010&FORMAT=NONE&FAILURE=SET&ERRORTEMPLATE=dept_1.groupname</CMD>

This is conditional branching. If command 5005 at the top of PersonnelVerify.groupname returned a value of "1" for dept_number then command 5010 at the bottom would return an error causing the flow to branch to dept_1.groupname. For the other conditions we have to create more SQL statements.

Back in SQL Editor highlight command 5010 on the list. Right-click on it and you will see a little pop-up list. Choose Clone from the pop-up list.The Command Editor will open up with the command already inside the SQL Statement text box. All you want to do is edit the last character changing the "1" to a "2".

...{dept_number:8} = 2

Save this command as Command ID 5011. Go back to Template Maker and add another command to the very bottom of the page. Actually you can just copy and paste the last command and edit it to read:

<CMD>{redirect to dept 1}COMMAND=5011&FORMAT=NONE&FAILURE=SET&ERRORTEMPLATE=dept_2.groupname</CMD>

Repeat this process until you have taken care of all six conditions. When you are done your flow model will look like this:

It works the same as before but you have eliminated one template in the flow. How you want to approach the flow design is up to you. There is hardly any speed difference noticed for the user. However, in the first instance with RedirectionHub we used an external command which did not have to query the database and thereby reduced the load on the system. Sometimes conditional branching is the best solution for the situation, sometimes not.

Summary

By expanding upon these lessons of personalization we can link database lookups with the values of cookies set for particular customers and their ordering/viewing histories. We will cover more on personalization in subsequent tutorials.

Send feedback regarding these
tutorials to gsmith@hhpn.com
< Go to Previous Tutorial