Scrolling Customer Listing - democlst.bbx

This program is used by both sample applications and is the lead program in the Customer Inquiry application in which customers are listed. Each customer has a link to a detailed invoice page. It is also used to select a customer to edit in the Customer Maintenance application.

The program reads up to 10 customer records, in name order, from the customer master file, using key chain 1 (the Name sort key). If additional records are available (there are about 30 in the file), a "More records..." link is provided to continue the list.

0001 SETERR ERRTRAP
0010 REM "democlst.bbx - BASIC Web Utility Customer Listing Demo
0020 REM "Copyright 1996 by Allen Miglore. All rights reserved.
0030 REM "Permission to derive programs from this is hereby granted,
0040 REM "provided said programs utilize licensed copies of the BASIC Web Utility.
0100 REM ^100 - If restarting this list, the CGI field "startwith"
0110 REM will contain the starting point. This can come
0120 REM either from the form contained at the end of the
0130 REM democlst.txt HTML template, or from the "more records"
0140 REM continuation link.

A CGI variable "startwith" is passed to this program in two cases. If the current execution is a continuation of the list, then the "more records" URL will contain this field In addition, at the bottom of the HTML display is a form with a "startwith" entry field to allow the user to restart the list at any time.

0150 LET STARTWITH$="", STARTWITH$=CVS(FIELD(CGI$,"startwith",ERR=0200),4)

These lines set the values for the uthtmfil.wbb program, identifying the key chain, records per page, and record structure. The HTML template file, democlst.txt, contains a place marker between the "<ul>" and "</ul>" (unordered list) tags. The structure includes a "<li>" (list element) tag so that each record becomes another bullet item in the document. The name field is treated as a link, and the link is specified in the variable LINKEXPR$, which is constructed to run a program with the CGI value, "cust_id", set to the customer number of any given record. The program defaults to the sample invoice list "demoilst.bbx" but can be specified in the CGI value "linkto". The Customer Maintenance application uses the "linkto" value to load and edit a customer record.

0200 REM ^100 - Initialize other values
0210 LET KNUM=1,MAXRECS=10
0220 LET STRUCTURE$="<li> [name @link] ([cust_id]), [city], [state] [zip], [phone]"
0300 REM ^100 - Construct a link expression, used to link each customer
0310 REM to a specified program for further display/edit
0320 LET LINKEXPR$=ENV.SCRIPT_NAME$+"?cust_id=[cust_id @encode]"
0330 LET LINKTO$="demoilst.bbx",LINKTO$=FIELD(CGI$,"linkto",ERR=0340)
0340 LET LINKEXPR$=LINKEXPR$+"&pgm="+LINKTO$
0400 REM ^100 - Open Customer Data File
0410 LET CUSTCHAN=UNT;
OPEN (CUSTCHAN)"GENSMPL1"

After opening the customer master file, the uthtmfil.wbb program generates a list of records in the CUSTLIST$ variable and lists up to MAXRECS records. The list starts with the value in STARTWITH$ and continues until the end of the file. If the variable CURKEY$ is returned with a value, the end of the file was not reached, and a "More records" URL is constructed to continue where the list ended. This URL is placed in the global string $MOREURL, which is referenced in the HTML text template democlst.txt.

0500 REM ^100 - Construct List
0510 REM uthtmfil.wbb reads from a channel, and builds list of
0520 REM records, using a particular structure, into a string
0530 CALL "uthtmfil.wbb", CUSTCHAN, STARTWITH$, "", KNUM, MAXRECS, COUNT, CURKEY$, CUST$, STRUCTURE$, CUSTLIST$,LINKEXPR$
0600 REM ^100 - If there are more records in the file, add a "more records"
0610 REM link URL to continue. curkey$ contains the key to the
0620 REM next record required. By placing this in a STBL, the
0630 REM uthtmout.wbb program that loads the HTML template can
0640 REM conditionally place it after the list.
0650 LET X$=STBL("$MOREURL","");
IF CURKEY$=""
THEN
GOTO 0680
0660 CALL "utencode.wbb",0,CURKEY$,NEXT_STARTWITH$
0670 LET MOREURL$=STBL("$MOREURL",ENV.SCRIPT_NAME$+"?pgm=democlst.bbx&startwith="+NEXT_STARTWITH$)

The HTML file, democlst.txt, is loaded and parsed into the variable HTML$. In that file is a comment "<!-- List Here -->", which is substituted with the contents of the CUSTLIST$ variable, generated above. The full text of HTML$ is sent with the utsend.wbb program, and the program exits. In version 1.1, two global string values are created automatically by uthtmfil: $list contains the record list returned in custlist$, and $moreurl contains either null (if the end of file is reached), or a URL to continue the list. These can be referenced in democlst.txt as [$list] and [$moreurl], respectively.

0680 REM ^100 - Load the HTML template, and add the list to it
0690 CALL "uthtmout.wbb",CGI$,"{include democlst.txt}",HTML$,""
0700 CALL "utsub.wbb",HTML$,"<!-- List Here -->",CUSTLIST$
0800 REM ^100 - Send it to the user
0810 CALL "utsend.wbb",HTML$
1000 DONE:
REM ^1000 - Clean up and exit
1010 CALL "utexit.wbb",CGI$
1020 IF RETURN_TO_WATCH
THEN
RUN "utwatch.wbb"
1030 RELEASE

It is important to trap all errors because BASIC Web Utility programs run in background mode.

2000 ERRTRAP:
REM ^1000 - generic error trap
2010 CALL "uterr.wbb",ERR,TCB(5),PGM(-2)
2020 GOTO DONE