Customer Maintenance - democent.bbx
This program generates a customer maintenance form. By default, the
form contains no customer data and can be used to create a new customer
record. However, if the CGI field "cust_id" is filled in with
a valid customer number, that customer record can be edited and updated.
Unlike the prior examples, an HTML document template is not used. Instead,
the HTML text is created in the program.
0001 SETERR ERRTRAP
0010 REM "democent.bbx - BASIC Web Utility demo customer entry form
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 - Get customer record
If the CGI field, "cust_id" contains a valid customer number,
and the customer record is loaded into the data template CUST$. Otherwise,
the template is initialized from the startup program.
0110 LET CUSTCHAN=UNT;
OPEN (CUSTCHAN)"GENSMPL1"
0120 READ RECORD(CUSTCHAN, KEY=FIELD(CGI$,"cust_id",ERR=0200),
ERR=0200)CUST$
An entry form is generated from the CUST$ data template. The cust_id field is hidden and cannot be edited, though it is passed to the democupd.bbx program. Fields indicated with a "show" option are display-only. The program utfrmgn2.wbb constructs the complete form, including Submit, Reset buttons, and a form tag to start the demobbw.sh script into the variable CUSTFORM$. The non-template field "pgm" is specified as a hidden field. As in URL links, this must be specified for the startup program to run the correct program. The democupd.bbx program is used to update the customer file from the contents of the form.
0200 REM ^100 - create entry form, with update link to
democupd.bbx
0210 LET FLDS$=FLDS$+"cust_id hidden, name, addr1, addr2, city, state,zip,
phone, slsp,
: date_last_sale show, date_last_pmt show, credit_limit show, mtd_sales
show, ytd_sales show,
: <input type=hidden name=pgm value=democupd.bbx>"
0220 CALL "utfrmgn2.wbb",CUST$,FLDS$, "", "table
border", "", ENV.SCRIPT_NAME$,"Update record",
"Reset form", 0, CUSTFORM$
Multiple calls to uttags.wbb build the HTML$ document body. Body tags are added, a header is generated, and the complete document is generated into DOCUMENT$. The result is sent to the user, and the program exits. In addition, it is necessary to shuffle HTML$ values with a temporary variable to add surrounding tags, such as <center> and </center> and not double up the text in HTML$ because uttags.wbb always appends to the last argument.
0300 REM ^100 - Use uttags.wbb to generate the rest of
the document
0310 CALL "uttags.wbb","h1","Customer Entry Form",HTML$
0320 CALL "uttags.wbb","hr","Enter new customer
information, or use the Customer List link",HTML$
0330 CALL "uttags.wbb","","to select a customer
record to edit.",HTML$
0340 CALL "uttags.wbb","p,href " + ENV.SCRIPT_NAME$
+ "?pgm=democlst.bbx&linkto=democent.bbx", "Customer
List", HTML$
0350 CALL "uttags.wbb",""," - ",HTML$
0360 CALL "uttags.wbb","href "+ENV.SCRIPT_NAME$,"Return
to the Menu", HTML$
0370 REM "msg$ can be sent from democupd.bbx if there is an error
0380 IF MSG$>"" THEN CALL "uttags.wbb","h3",MSG$,HTML$
0390 LET WORK$=HTML$,HTML$="";
CALL "uttags.wbb","center",WORK$,HTML$
0400 CALL "uttags.wbb","hr",CUSTFORM$,HTML$
0410 CALL "uttags.wbb","body bgcolor=#E8E8E8",HTML$,BODY$
0420 CALL "uttags.wbb","head,title","BASIC Web
Utility Demo Customer Entry Form",HEADING$
0430 CALL "uttags.wbb","html",HEADING$+BODY$,DOCUMENT$
0500 REM ^100 - Send it to the user
0510 CALL "utsend.wbb",DOCUMENT$
1000 DONE:
REM ^1000 - Clean up and exit
1010 CALL "utexit.wbb",CGI$
1020 IF RETURN_TO_WATCH
THEN
RUN "utwatch.wbb"
1030 RELEASE
2000 ERRTRAP:
REM ^1000 - generic error trap
2010 CALL "uterr.wbb",ERR,TCB(5),PGM(-2)
2020 GOTO DONE