by Jack Wheeler and Dr. Peter Wayne
|
Jack has developed clever techniques to interface Alpha tables with Microsoft's Personal Web Server. In this article I show you how his techniques work and show how they can be extended to use the open source Apache Web Server. Finally we show you how Alpha Five v.6 will make this (almost) easy! |
Jack's goal: The contractor should be able to create her own catalog of light fixtures that she wants to promote. She should be able to display the different fixtures to the client on the spot, She should then be able to bid a project rapidly.
Solution: Jack decided that displaying thumbnails of each item offered by each manufacturer would help the contractor and the client zero in on suitable fixtures. Once the contractor clicked on a thumbnail, then Alpha Five would read from a catalog database and place the cost, manufacturer, catalog number, and estimated man-hours needed to install into the bidding application. Alpha Five would also prompt for information that the contractor needed to enter by hand, namely, the desired finish, bulb wattage, and quantity.
First hurdle: Jack thought this would be a perfect use for an ActiveX control. He created a page of thumbnails using the Kodak imaging application. He then created a table with 4 image fields and developed a form to display them. Unfortunately he found that using ActiveX and image fields was too slow.
As luck would have it, Jack came across a web page with great looking pictures displayed 8 across and 20 rows down: 160 images in all. He was amazed at how quickly the web page loaded. [Editor's note: I didn't ask Jack what kinds of images were on that web page.] Not only were the images clear and vibrant, but he could click on an image and the web page would then take him somewhere else. Jack wondered if he could do the same within Alpha Five.
Jack is nothing if not patient. As he writes, "After 2 years I figured it out."
Microsoft supplied a "Personal Web Server" or
"PWS" on Windows 98 and Windows ME. [ Editor's note: The
PWS is not supported on Windows XP. I will show you later how to use
Jack's ideas in Windows XP.] PWS allows you to display html files
stored on your computer, but it does more than that: it allows you to
create "active server pages", or ASP pages. ASP
pages let you pass information from one web page to another. If your
Web server can support it, ASP pages can contain scripts written in a
number of Web-host scripting languages, including PERL, Vbscript,
Javascript, and others.
When you set up a web server, you
decide that a single directory is the "Document Root"
directory, and that is where your web server will start searching for
files to display. Jack chose the default directory that PWS prefers,
namely, c:\inetpub\wwwroot. PWS looks in that directory
whenever you type http://localhost or http://127.0.0.1
in your web browser window.
Now, I don't have a Windows 98 or Windows ME computer to play with, so I haven't been able to use PWS to run Jack's application. But bear with me. I will show you some of what Jack's application does, and then show you how I recoded it for use, first with the open-source (read "free") Apache web server, and then with Alpha Five v.6's web server.
When a contractor opens up the "Lighting Contract" form, she sees this:

She then presses on "Thumbnail View" in the toolbar, and chooses a supplier:

Alpha
Five then launches Internet Explorer with thumbnails showing the
different products offered by the manufacturer, shown alongside the
Lighting Contract form:


Notice that the URL in the browser window starts with "http:/127.0.0.1". This catalog is coming from our own web server!
Clicking on an image in the catalog causes the web server to dynamically construct and open a new "Orders.asp" web page:

I only presented a little bit of Jack's application, which is complex, vast, and deucedly clever. I can't get his whole application to work, because I don't have PWS. However, I was able to get parts to work by using the Apache web server and then Alpha Five's own web server.
If you are going to use PWS or Apache, you need to set up ODBC. ODBC stands for "Open Database Connect" and is a Microsoft strategy for allowing applications to read from a variety of database formats using standard SQL (Structured Query Language) syntax. Notice that later on, when I discuss using Alpha Five's v6 Web Server, you won't need to know anything about ODBC, because Alpha Five can read its own tables without any special translation!
Here's how to set up ODBC on a Win XP computer:
From the Windows Control Panel, choose Administrative Tools:

Then
choose "Data Sources (ODBC)":

Under the "System" tab, click on "Add" to add a new data source:

Select
the Microsoft Visual Foxpro Driver. Make sure you choose the VFP
driver, and not a dBase driver or a regular Foxpro driver:

Click
on Finish, and then configure the driver:

I
wanted to set up a driver for the lighting catalog. I created a Data
Source Name (DSN) of "Lighting", selected "Free Table
Directory" as the database type, and chose the directory where I
put Jack's application:

Make
sure you choose "Free Table directory." Alpha Five
tables share the same structure as Visual Foxpro tables, but Alpha
Five databases are not the same as VFP databases!
When you click on OK, you should see a new system DSN has been added:

What
have you accomplished? Now any application that can speak ODBC, which
includes scripting languages like Vbscript and php, can
read and write to your Alpha Five tables.
Please do NOT use these paragraphs as a guide to setting up Apache on the public internet! This guide is only intended to show you how to set up Apache on your own personal computer or on your own intranet.
You can download the Apache web server for free from http://httpd.apache.org. When you run the Apache set-up, you will be asked a few questions. For Network Domaikn, you can put in anything you want (assuming you are running this on your own computer). For Server Name, put in whatever is the name your computer has on your network. For Administrator's email, you can leave it blank or put in your email. Then run the installation.
It is easiest if you allow Apache to run as a service, that is, a task that will start automatically every time you start Windows.
You can test that Apache is running by going to your web browser and type http://localhost. You will see this:

Wow! You are almost there. Now you have to make 2 changes to the Apache web server's configuration. The configuration file is the "httpd.conf" text file found in the "conf" subdirectory wherever you installed Apache (on my computer, "c:\program files\Apache Group\Apache 2").
Edit the line
DocumentRoot
"C:/Program Files/Apache Group/Apache2/htdocs"
to
DocumentRoot
"C:/inetpub/wwwroot"
Change the line
DirectoryIndex
index.html
to
DirectoryIndex
index.html index.php index.php3 index.phtml index.shtml index.htm
Add this line after the LoadModule section in the
configuration file:
LoadModule
php4_module "c:/program files/php/sapi/php4apache2.dll"
and
then add
AddType
application/x-httpd-php .php .php3 .php4 .phtml
after the
line reading #AddType text/html
.shtml
Now you are ready to download PHP. PHP is one of those cutesy Open Source recursive names, standing for "PHP – Hypertext Preprocessor." Well, I suppose we have to bear with their sense of humor; after all, they are making this work available for free. You can download the latest and greatest from http://www.php.net/downloads.php. I wouldn't advise downloading any beta versions; we're still amateurs here, let's stick with what works. I've successfully used php verson 4.3.6 with Apache 2.0.49, both downloaded in May 2004.
After you unzip PHP, copy php.ini-dist as php.ini from the \php\ directory to your Windows system directory (c:\windows for 98, ME, and XP). In the php.ini file, find the line,
extension_dir = ""
and change it to
extension_dir = "c:/program files/php/extensions"
Similarly, change the lines
;extension=php_dba.dll ;extension=php_dbase.dll ;extension=php_dbx.dll
and remove the semicolon from in front of the php_dbase.dll extension:
;extension=php_dba.dll extension=php_dbase.dll ;extension=php_dbx.dll
Then copy php4ts.dll to c:\windows\system32 (for XP), c:\winnt\system32 (for NT, 2000), or c:\windows\system (for 98, ME).
A useful guide to installing Apache on Windows can be found at http://www.mjmwired.net/resources/apache-windows.html
We're just about ready to do some serious shopping. Remember, we have a database of manufacturers and lighting fixtures and several directories full of images. Jack placed jpegs of the fixtures in separate directories, one for each manufacturer. And now comes the brilliant part, for those of you who weren't already impressed with Jack's versatility: he uses Xbasic to create the active server pages for the PWS.
I modified Jack's code slightly to make it possible to create ASP files (for Microsoft servers), PHP files (for Apache), and A5W files (for the Alpha web server). Here is the code:
'Date Created: 29-Feb-2004 10:00:21 PM
'Last Updated: 06-Jun-2004 09:08:10 AM
'Created By : Jack Wheeler
'Updated By : Peter Wayne
reply=ui_dlg_box("Select Web Server type",<<%dlg%
Server type: ;
{region}(server:Alpha Five v.6);
(server:Apache);
(server:Personal Web Server);{endregion};
{line=1,0};
<*OK> ;
%dlg%)
if reply="Cancel" then
end
else
select
case server="Alpha Five v.6"
extension="a5w"
case server="Apache"
extension="php"
case server="Personal Web Server"
extension="asp"
end select
end if
supplier_list=<<%lst%
AO
CO
DB
FO
RS
VS
%lst%
*for_each(supplier, make_thumbnails(supplier,extension), supplier_list)
ui_msg_box("Thumbnails are Compiled"," Thumbnails Can only be viewed on order Form")
end
function make_thumbnails as v (supplies as c, extension as c)
dim t as p
dim i as n
dim filename[1500] as c
dim name as c
DIM THUMBS[1500] AS C
DIM PRICE[1500] AS C
DIM CAT[1500] AS C
DIM locat[1500] AS C
dim network_path as c
network_path=trim(lookup("server",".t.","Root_file"))
dir_put(network_path+"Lights"+chr(92)+supplies)
fn="TH."+extension
if file.exists(fn) then
file.remove(fn)
end if
Name=alltrim(lookupC("F",supplies,"Supplier_name","Lit_MU","Supplier"))
t=table.open("lightcat")
T.INDEX_PRIMARY_PUT("CAT_NO")
dir_put(network_path+"Lights"+CHR(92)+alltrim(Supplies))
humbs=filefind.first("*.jpg")
i=1
nbr=0
While .not.humbs.eof()
if right(humbs.name(),3)="jpg".or.right(humbs.name(),3)="bmp" then
filename[i]=network_path+"Lights"+CHR(92)+alltrim(supplies)+chr(92)+humbs.name()
THUMBS[I]=LEFT(HUMBS.NAME(),LEN(HUMBS.NAME())-4)
locat[i]="http://127.0.0.1/Lights/"+alltrim(supplies)+chr(47)+humbs.name()
REC=T.FETCH_FIND(THUMBS[I])
IF REC>0 THEN
VALUE=T.CHRG_EA
cat[i]=trim(t.cat_no)
PRICE[I]=ALLTRIM(STR(VALUE,8,2))
END IF
end if
i=i+1
nbr=nbr+1
humbs.next()
end while
fil = file.create(fn, file_rw_exclusive)
fil.write_line("<html>")
fil.write_line("")
fil.write_line("<head>")
fil.write_line("<meta http-equiv="+chr(34)+"Content-type"+chr(34)+"
content="chr(34)+"text/html; charset=iso-8859-1"+chr(34)+">")
fil.write_line("</head>")
fil.write_line("")
fil.write_line("<body bgcolor="+chr(34)+"#EEEEE0"+chr(34)+">")
fil.write_line("")
fil.write_line("<Script Language="+chr(34)+"Javascript"+chr(34)+">")
fil.write_line("<!--")
fil.write_line("function DOTest(CatNO, Thumb){")
fil.write_line("document.Lights.Cat.value=CatNO;")
fil.write_line("document.Lights.Supply.value="+chr(34)+supplies+chr(34)+";")
fil.write_line("document.Lights.Thumb.value=Thumb;")
fil.write_line("}")
fil.write_line("-->")
fil.write_line("</Script>")
fil.write_line("")
fil.write_line("<Form name="+chr(34)+"Shop"+chr(34)+" method="+chr(34)+"post"+chr(34)+
"action="+chr(34)+"http://127.0.0.1"+chr(92)+"Shop_cart."+extension+chr(34)+">")
fil.write_line("<table border="+chr(34)+"0"+chr(34)+" cellpadding="+chr(34)+"0"+chr(34)+" align=center>")
fil.write_line("<font size="+chr(34)+"2"+chr(34)+" face="+chr(34)+"Arial"+chr(34)+">")
fil.write_line("<Input type="+chr(34)+"submit"+chr(34)+" align="+chr(34)+"middle"+chr(34)+" name="+chr(34)+"Shopping Cart"+chr(34)+" Value="+chr(34)+"See Shop Cart"+chr(34)+">")
fil.write_line("<Input type="+chr(34)+"hidden"+chr(34)+" name="+chr(34)+"location"+chr(34)+">")
fil.write_line("</table></form>")
fil.write_line\
("<Form name="+chr(34)+"Lights"+CHR(34)+" method="+CHR(34)+"post"+CHR(34)+\
" action="+CHR(34)+"http://127.0.0.1"+chr(92)+\
"order."+extension+chr(34)+">")
fil.write_line("<table border="+chr(34)+"0"+chr(34)+" cellpadding="+chr(34)+"0"+chr(34)+" align=center>")
fil.write_line("<tr><th><font size="+chr(34)+"2"+chr(34)+" face="+chr(34)+"Arial"+chr(34)+">"+NAME+" Catalog"+"</th></tr>")
fil.write_line("<tr>")
fil.write_line("<td>")
fil.write_line("<TABLE ALIGN=CENTER border=0 width=240 bgcolor="+chr(34)+"#EEEEEO"+chr(34)+">")
fil.write_line("<TR>")
fil.write_line("<TD ALIGN=CENTER>")
i=1
NR=0
for i= i to nbr
if cat[i]="".or.val(Price[i])<.10 then
goto over
end if
NR=NR+1
fil.write_line("<Input Type="+chr(34)+"Image"+chr(34)+" IMG SRC="+CHR(34)+FILENAME[I]+CHR(34)+" WIDTH="+chr(34)+"50"+chr(34)+" HEIGHT="+chr(34)+"70"+chr(34)+" BORDER=2 onmouseover="+chr(34)+"DOTest("+chr(39)+cat[i]+chr(39)+","+chr(39)+locat[i]+chr(39)+")"+chr(34)+">")
If mod(NR,4)=0 then
fil.write_line("<font size="+chr(34)+"1"+chr(34)+" face="+CHR(34)+"ARIAL"+chr(34)+">"+thumbs[i]+"<BR>"+"$"+price[i]+"</FONT></TD>")'</TD>
fil.write_line("</TR>")
fil.write_line("<TR>")
fil.write_line("<TD ALIGN=CENTER>")
else
fil.write_line("<font size="+chr(34)+"1"+chr(34)+" face="+CHR(34)+"ARIAL"+chr(34)+">"+thumbs[i]+"<BR>"+"$"+price[i]+"</FONT></TD>")'</TD>
fil.write_line("<TD ALIGN=CENTER>")
end if
over:
NEXT I
fil.write_line("<Input type="+chr(34)+"hidden"+chr(34)+" name="+chr(34)+"Cat"+chr(34)+">")
fil.write_line("<Input type="+chr(34)+"hidden"+chr(34)+" name="+chr(34)+"location"+chr(34)+">")
fil.write_line("<Input type="+chr(34)+"hidden"+chr(34)+" name="+chr(34)+"Thumb"+chr(34)+">")
fil.write_line("<Input type="+chr(34)+"hidden"+chr(34)+" name="+chr(34)+"Supply"+chr(34)+">")
fil.write_line("<Script>")
fil.write_line("document.Lights.location.value=this.location")
fil.write_line("document.Shop.location.value=this.location")
fil.write_line("</Script>")
fil.write_line("</Form>")
fil.flush()
fil.close()
t.close()
end functionThis is one long script, however, what it does is conceptually simple: it writes a file, either called th.asp, th.php, or th.a5w, to each manufacturer's separate image directory. The choice of suffix is determined by the web server. In this example, I let the user choose the web server, but in Jack's application, the only web server is a Microsoft server so all scripts are asp scripts.
An example is in order. Here is the th.asp script prepared for one of the manufacturers:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#EEEEEO">
<Script Language="JavaScript">
<!--
function DOTest(CatNO,Thumb){
document.Lights.Cat.value=CatNO;
document.Lights.Supply.value="AO";
document.Lights.Thumb.value=Thumb;
}
-->
</Script>
<Form name="Shop" method="post" action="http://127.0.0.1\Shop_cart.asp">
<table border="0" cellpadding="0" align=center>
<font size="2" face="Arial">
<Input type="submit" align="middle" name="Shopping Cart" Value="See Shop Cart">
<Input type="hidden" name="location">
</table></form>
<Form name="Lights" method="post" action="http://127.0.0.1\order.asp">
<table border="0" cellpadding="0" align=center>
<tr><th><font size="2" face="Arial">Aurora Lighting Catalog</th></tr>
<tr>
<td>
<TABLE ALIGN=CENTER border=0 width=240 bgcolor="#EEEEEO">
<TR>
<TD ALIGN=CENTER>
<Input Type="Image" IMG SRC="C:\inetpub\wwwroot\Lights\AO\DL1120.jpg" WIDTH="50" HEIGHT="70" BORDER=2 onmouseover="DOTest('DL1120','http://127.0.0.1/Lights/AO/DL1120.jpg')">
<font size="1" face="ARIAL">DL1120<BR>$147.03</FONT></TD>
<TD ALIGN=CENTER>
<Input Type="Image" IMG SRC="C:\inetpub\wwwroot\Lights\AO\DL1620.jpg" WIDTH="50" HEIGHT="70" BORDER=2 onmouseover="DOTest('DL1620','http://127.0.0.1/Lights/AO/DL1620.jpg')">
<font size="1" face="ARIAL">DL1620<BR>$139.03</FONT></TD>
...
...
<TD ALIGN=CENTER>
<Input type="hidden" name="Cat">
<Input type="hidden" name="location">
<Input type="hidden" name="Thumb">
<Input type="hidden" name="Supply">
<Script>
document.Lights.location.value=this.location
document.Shop.location.value=this.location
</Script>
</Form>In the actual script, there are many image references, but I took out most of them. Even if you don't know any HTML, you can get some of the logic of this script. It displays a page with 2 HTML “forms”. HTML forms should not be confused with Alpha Five forms: an HTML form is an object that can acquire input from the user and take an action. The web page coded for by this asp script has 2 forms. The first form only contains a button that lets the user examine her shopping cart: we'll ignore that one. The second and more interesting form displays images of each fixture, along with the catalog number and the price. When the user passes her mouse over an image, the browser's OnMouseover event fires, setting the values of the document's “Thumb”, “Supply”, and “Cat” variables. When the user actually double-clicks on one of the images, the page closes and calls on the form's Action, which is to call the “order.asp” page.
Now here's the best part: when the asp page calls the “order.asp” page, the input variables acquired by th.asp are now available to order.asp! Only one order.asp file is required by the application:
<% @Language="VBScript"%>
<% Option Explicit%>
<%Dim ObjConn
Set ObjConn =Server.Createobject("ADODB.Connection")
ObjConn.open "LitCat"%>
<HTML>
<Title>Your Order Form</Title>
<Head><H2>Be Sure to pick Quantity and Finish</H2></Head>
<%
Dim LitCat
dim supp
dim CatNO
Dim Local
Dim Charge
Dim Order_no
Dim Thumb_pic
Set LitCat=Server.CreateObject("ADODB.Recordset")
LitCat.open "SELECT * FROM dummy",objconn,,3
%>
ORDER#: <%response.write LitCat.fields("Order1")%><BR>
<%
Order_no=LitCat.fields("Order")
LitCat.close%>
<Form method="post" action="http://127.0.0.1/Order_Continue.asp">
<body bgcolor="#EEEEEO">
<TABLE width="10%" cellspacing="5" border="0" bordercolor="#9c0031">
<TR valign="center">
<TD width="5%">
<DL>
<H3>
<li>Finish</li>
<li>Quantity</li>
<li>Wattage</li>
<li>Fixture</li>
<li>Cost</li>
</H3>
</DL>
</TD>
<TD width="30%">
<DL>
<select name="finish" size="1" style="background-color:#EEEEEO" >
<%
Set LitCat=Server.CreateObject("ADODB.Recordset")
supp=Request.form("Supply")
CatNO=Request.form("Cat")
Local=Request.form("location")
Thumb_pic=Request.form("Thumb")
LitCat.open "SELECT * FROM finish_table WHERE Man='"&supp&"'",objconn,,3
Do While Not LitCat.BOF and Not LitCat.eof%>
<OPTION value="<%=LitCat.fields("Fin")%>"><%=LitCat.fields("finish")%></OPTION>
<%LitCat.MoveNext
Loop%>
</select>
<%LitCat.close
LitCat.open "SELECT * FROM Lightcat WHERE Cat_no ='"&CatNO&"' AND supplier='"&supp&"'",objconn,,3%>
<Input type="text" Name="Qty" Maxlength="3" Size="7"><BR>
<Input Type="text" Name="Watt" Maxlength="3" Value="<%=LitCat.fields("Watts")%>" Maxlength="3" Size="7"><BR>
<%response.write LitCat.fields("Cat_no")%><BR>
<%response.write LitCat.fields("chrg_ea")
Charge=LitCat.fields("chrg_ea")%><BR>
</DL>
</TD>
</table>
<%LitCat.close
objconn.close
set LitCat = Nothing
Set objconn=Nothing
%>
<Input Type="Image" name="Thumb" IMG SRC="<%=request.form("Thumb")%>">
<%
response.write("<INPUT TYPE=""Button"" Name=""Button"" Value=""Cancel"" style=""Background-color:#EEEEEO"" onclick=""window.location='"&Local&"'"">")
%>
<Input type="Submit" Name="Add" Value="Add This">
<Input Type="hidden" name="Locat" Value="<%=Request.form("location")%>">
<Input Type="hidden" name="chrg" Value="<%=Charge%>">
<Input Type="hidden" name="Cat" Value="<%=CatNO%>">
<Input Type="hidden" name="Order" Value="<%=Order_no%>">
<Input Type="hidden" name="supp" Value="<%=supp%>">
<Input Type="hidden" name="Thumb" Value="<%=Thumb_pic%>">
</Form>
</body>
</HTML>This script is a mixture of pure HTML and VBScript. The VBScript is marked off by <% and %>, and when a Microsoft web server encounters VBScript delineated in that fashion, it interprets the code before sending the Web page out to the user's browser. So, for example, an ASP page consisting of
<html> <%dim your_name your_name=”George”%> Your name is <%response.write(your_name)%> </html>
when fed to a Microsoft web server would actually send the following, interpreted html to the browser:
<html> Your name is George </html>
Note to all you critical readers: I don't have a Microsoft web server to experiment with, so I can't guarantee that I have the syntax of asp pages down pat. But I'm trying to give you the general idea of how the asp pages interact with the web server to generate dynamic HTML content.
Back to our shopping cart. The lines
<%Dim ObjConn
Set ObjConn =Server.Createobject("ADODB.Connection")
ObjConn.open "LitCat" %>establish a connection between your Web server and Jack's “LitCat” ODBC connection (don't get confused: on my computer, I created a “Lighting” DSN connection, but Jack apparently created one called “LitCat” on his.) The remaining VBScript reads from the “dummy.dbf” table in Jack's application, the “finish_table.dbf” table and the “LightCat.dbf” table, and uses the values obtained to present a form to the user.
There's one major drawback to ASP, and it is spelled M-I-C-R-O-S-O-F-T. Unless you are running a Microsoft web server, your web server can't interpret ASP pages. Fortunately, the open source community has no end of tools for generating HTML on-the-fly. PHP is not hard to set up and the lingo is sufficiently similar to VBScript and Xbasic to make it relatively easy to modify Jack's work.
I'm going to spend a little more time on “order.php” because this is code I was able to write and test myself. The only change, by the way, between “th.asp” and “th.php” is that “th.asp” can call on “order.asp” and “shop_cart.asp” while “th.php” calls on the same forms with the php extension.
Here is order.php. The php code is in between <?php and ?>, and is interpreted by the Apache web server, just like the Microsoft web server interprets VBScript. I put in lots of comments (in Unix/Linux fashion, comment lines in PHP begin with #).
<HTML>
<Title>Your Order Form</Title>
<Head><H2>Be Sure to pick Quantity and Finish</H2></Head>
<?php
# open the connection to the Lighting Data Source
# variable names in PHP all begin with a dollar sign
# and every line of PHP code ends with a semicolon
$LitCat=odbc_connect('Lighting','','');
# let's check to see if the ODBC connection went through
# in syntax borrowed from C, writing, as below, if (!Litcat) means “if LitCat is FALSE”
# and the “then...end if” that we are familiar with is replaced by the curly braces, { and }
if (!$LitCat){
exit('Connection failed: '.$LitCat);
}
# get the variables passed by the originating form "th.php"
# they are available to us by name in the “superglobal” $_REQUEST[]
$Supply=$_REQUEST['Supply'];
$CatNo=$_REQUEST['Cat'];
$Locat=$_REQUEST['location'];
$Thumb_pic=$_REQUEST['Thumb'];
# at this point we have local variables containing all the info from the calling form
# query the (single) record in dummy.dbf
$query="SELECT * FROM dummy";
# the next line executes the SQL string in $query and returns a result “recordset”
$rs=odbc_exec($LitCat,$query);
# now, get the first record (there's only one, actually) in $rs
odbc_fetch_row($rs,1);
# and get the value of the “order” field in the recordset
$Order_no=odbc_result($rs,"Order");
# and now we'll JUMP out of PHP and return to regular HTML, and see how we JUMP right
# back into PHP in the middle of the next line
?>
ORDER#: <?php echo odbc_result($rs,"Order1"); ?><BR>
<Form method="post" action="http://127.0.0.1/Order_Continue.php">
<body bgcolor="#EEEEEO">
<TABLE width="10%" cellspacing="5" border="0" bordercolor="#9c0031">
<TR valign="center">
<TD width="5%">
<DL>
<H3>
<li>Finish</li>
<li>Quantity</li>
<li>Wattage</li>
<li>Fixture</li>
<li>Cost</li>
</H3>
</DL>
</TD>
<TD width="30%">
<DL>
<SELECT name="finish" size="1" style="background-color:#EEEEEO">
<?php
# let's get the choices of finish for the item
$query="SELECT * FROM finish_table WHERE Man='".$Supply."'";
$rs=odbc_exec($LitCat,$query);
while (odbc_fetch_row($rs)) {
echo '<OPTION VALUE="'.rtrim(odbc_result($rs,"Fin")).'">'.rtrim(odbc_result($rs,"finish"))."</OPTION>\n";
}
?>
</SELECT>
<?php
#and let's get price and wattage
$query="SELECT * from Lightcat WHERE Cat_no='".$CatNo."' AND supplier='".$Supply."'";
#echo $query.'<br>';
$rs=odbc_exec($LitCat,$query);
#odbc_fetch_row($rs,1);
$Watts=odbc_result($rs,"Watts");
?>
<INPUT TYPE="Text" NAME="Qty" Maxlength="3" Size="7"><br>
<INPUT TYPE="Text" NAME="Watt" Maxlength="3"
Value="<?php echo $Watts;?>" MaxLength="3" Size="7"><BR>
<?php echo rtrim(odbc_result($rs,"Cat_no"));?><BR>
<?php echo odbc_result($rs,"chrg_ea");
$Charge=odbc_result($rs,"chrg_ea")?><BR>
</DL>
</TD>
</table>
<?php odbc_close($LitCat); ?>
<INPUT TYPE="Image" Name="Thumb" IMG SRC="<?php echo $Thumb_pic;?>">
<?php echo '<BR><INPUT TYPE="BUTTON" NAME="BUTTON" Value="Cancel" style=
"Background-color:#EEEEE0" onclick="window.location='."'".$Locat."'".'">' ?>
<Input type="Submit" Name="Add" Value="Add This">
<Input type="hidden" NAME="Locat" Value="<?php echo $Locat; ?>">
<Input type="hidden" NAME="chrg" Value="<?php echo $Charge; ?>">
<Input type="hidden" NAME="Cat" Value="<?php echo $CatNo; ?>">
<Input type="hidden" name="Order" value=<?php echo $Order_no; ?>">
<INPUT type="hidden" name="supp" value=<?php echo $Supply; ?>">
<Input type="hidden" name="Thumb" value="<?php echo $Thumb_pic; ?>">
</Form>
</body>
</HTML>Once again, you should remember that this is the code that goes to the web server, not the browser. After the Apache server and PHP interpret this code, Apache sends HTML like the following out to the user's browser:
<HTML> <Title>Your Order Form</Title> <Head><H2>Be Sure to pick Quantity and Finish</H2></Head> ORDER#: <BR> <Form method="post" action="http://127.0.0.1/Order_Continue.php"> <body bgcolor="#EEEEEO"> <TABLE width="10%" cellspacing="5" border="0" bordercolor="#9c0031"> <TR valign="center"> <TD width="5%"> <DL> <H3> <li>Finish</li> <li>Quantity</li> <li>Wattage</li> <li>Fixture</li> <li>Cost</li> </H3> </DL> </TD> <TD width="30%"> <DL> <SELECT name="finish" size="1" style="background-color:#EEEEEO"> <OPTION VALUE="C">Copper</OPTION> </SELECT> <INPUT TYPE="Text" NAME="Qty" Maxlength="3" Size="7"><br> <INPUT TYPE="Text" NAME="Watt" Maxlength="3" Value="20" MaxLength="3" Size="7"><BR> DL1120<BR> 147.03<BR> </DL> </TD> </table> <INPUT TYPE="Image" Name="Thumb" IMG SRC="http://127.0.0.1/Lights/AO/DL1120.jpg"> <BR><INPUT TYPE="BUTTON" NAME="BUTTON" Value="Cancel" style= "Background-color:#EEEEE0" onclick="window.location='http://localhost/Lights/AO/th.php'"><Input type="Submit" Name="Add" Value="Add This"> <Input type="hidden" NAME="Locat" Value="http://localhost/Lights/AO/th.php"> <Input type="hidden" NAME="chrg" Value="147.03"> <Input type="hidden" NAME="Cat" Value="DL1120"> <Input type="hidden" name="Order" value=96240"> <INPUT type="hidden" name="supp" value=AO"> <Input type="hidden" name="Thumb" value="http://127.0.0.1/Lights/AO/DL1120.jpg"> </Form> </body> </HTML>
The above code was generated when I clicked on “DL1120.jpg” from the Aurora lighting catalog. The browser then shows me this:

By now, maybe your head is spinning, or maybe you are ready to give up, but don't! If you have more or less followed me this far, it gets easier, because A5v6 comes with its own web server. That means you can dispense completely with ODBC connections.
Alpha's web server follows the same general design as Microsoft's and the Apache/PHP duo, but instead of interpreting VBSCript or PHP scripts, Alpha's web server speaks the same language you and I speak, namely, Xbasic!
If you are going to run the A5v6 web server, you first should stop any other web server running on your computer. It's possible to run more than one web server at a time by having the servers listen to different “ports” on the computer, but remember, we're small fry here, let's get it working first and then if you want to run two web services simultaneously, I say, more power to you.
Under Alpha Five v. 6's toolbar, under Tools, is a selection for the Web Application Server. This opens up the WAS Control Panel:

Notice
I changed A5's Document Root to the same one that I used for Apache.
Then to start the server, click on “Start Server” . That
wasn't hard, was it?
Now look at how simple, relatively, is the code for “order.a5w”, called after I click on a fixture's image:
<HTML>
<Title>Your Order Form</Title>
<Head><H2>Be Sure to pick Quantity and Finish</H2></Head>
<%A5
' get the variables passed by the originating form "th.a5w"
CatNo=Request.variables.Cat
Supply=Request.variables.Supply
Thumb_pic=Request.variables.Thumb
Locat=Request.variables.location
' query the (single) record in dummy.dbf
t=table.open("dummy")
Order_no=t.Order
%>
ORDER#: <%A5 ? t.Order1; t.close() %><BR>
<Form method="post" action="http://127.0.0.1/Order_Continue.a5w">
<body bgcolor="#EEEEEO">
<TABLE width="10%" cellspacing="5" border="0" bordercolor="#9c0031">
<TR valign="center">
<TD width="5%">
<DL>
<H3>
<li>Finish</li>
<li>Quantity</li>
<li>Wattage</li>
<li>Fixture</li>
<li>Cost</li>
</H3>
</DL>
</TD>
<TD width="30%">
<DL>
<SELECT name="finish" size="1" style="background-color:#EEEEEO">
<%A5
query.filter="Man="+quote(Supply)
query.order="finish"
query.options="T"
tf=table.open("finish_table",file_ro_shared)
tf.query_create()
tf.fetch_first()
while .not. tf.fetch_eof()
? "<OPTION VALUE="+quote(trim(tf.Fin))+">"+trim(tf.finish)+"</OPTION>"
tf.fetch_next()
end while
tf.close()
%>
</SELECT>
<%A5
LC=table.open("Lightcat",file_ro_shared)
query.filter="Cat_no="+quote(CatNo)+" .AND. supplier="+quote(Supply)
query.order=""
query.options="T"
LC.query_create()
LC.fetch_first()
Watts=str(LC.Watts,3,0)
chrg_ea=str(LC.chrg_ea,6,2)
Cat_no=trim(LC.Cat_no)
LC.close()
%>
<INPUT TYPE="Text" NAME="Qty" Maxlength="3" Size="7"><br>
<INPUT TYPE="Text" NAME="Watt" Maxlength="3"
Value="<%A5 ? Watts %>" MaxLength="3" Size="7"><BR>
<%A5 ? Cat_no %><BR>
<%A5 ? chrg_ea
Charge=val(chrg_ea) %><BR>
</DL>
</TD>
</table>
<INPUT TYPE="Image" Name="Thumb" IMG SRC="<%A5 ? Thumb_pic %>">
<BR>
<INPUT TYPE="BUTTON" NAME="BUTTON" Value="Cancel"
style="Background-color:#EEEEE0"
onclick="window.location='<%a5 ? Locat %>'">
<Input type="Submit" Name="Add" Value="Add This">
<Input type="hidden" NAME="Locat" Value="<%a5 ? Locat %>">
<Input type="hidden" NAME="chrg" Value="<%a5 ? Charge %>">
<Input type="hidden" NAME="Cat" Value="<%A5 ? CatNo %>">
<Input type="hidden" name="Order" value="<%A5 ? Order_no %>">
<INPUT type="hidden" name="supp" value="<%A5 ? Supply %>">
<Input type="hidden" name="Thumb" value="<%a5 ? Thumb_pic %>">
</Form>
</body>
</HTML>Now we're playing in exactly the same sandlot as VBScript and PHP. Indeed, if you are using a browser, you won't know whether the code is coming from a Microsoft IIS server, from a Linux system running Apache, or from your own humble little Alpha Five Web Server. The difference is all at the server end: we are now inserting Xbasic code into our HTML instead of VBScript or PHP. The Xbasic is delineated by <%A5 ... %> , and using Xbasic we can open tables, query them and update them, just like we always have.
I have posted a zip of Jack's application here. Be aware that it is 25 Megs zipped up, so even with a fast connection, there's time for a lunch break. And Jack's application only works on Microsoft servers, though I have included a few PHP and A5W scripts in the download.
You can reach Jack at jwl13@socal.rr.com. Thanks, Jack!
6/6/2004 - pkw
Don't forget, we need your feedback to make this site better!