home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freesoft 1997 June
/
Freesoft_1997-06_cd.bin
/
nerecenz
/
programmers
/
FOXWEB
/
DATA.Z
/
customer.PRG
< prev
next >
Wrap
Text File
|
1996-12-19
|
10KB
|
308 lines
******************************************
* CUSTOMER.PRG *
* *
* Sample Code for FoxWeb *
* *
* Written by Pandelis Tiritas 9/6/95 *
******************************************
******************************************
* NOTES:
*
* MergeTxt is included in FoxWeb. It takes
* the contents of the parameter passed to it,
* performs a text merge and returns the results
*
* Every procedure includes the variables
* ProcFile and MergeFile. These variables
* are used for the [Display Source Code] and
* [Display Merge Code] options. They are
* not integral to the functionality of the
* application
* The two procedures: send_prg and send_memo
* are also used for the same purpose
*
* All links in the merge table HTML_Frm have
* a question mark (?) as the last character.
* This is not necessary in most cases, but is
* included as a work-around to a limitation of
* EMWAC HTTPS
******************************************
******************************************
PROCEDURE customer
* Sends the main menu
PRIVATE FormTxt
ProcFile='customer' && Used to display source code
MergeFile='cust_menu' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_menu' INTO ARRAY FormTxt
html_out = MergeTxt(M.FormTxt)
RETURN
******************************************
PROCEDURE cust_list
* Creates a list of all customers
PRIVATE ListTxt, FormTxt
* Create the table if it does not exist
DO chk_table
SELECT cust_no, lname, fname, UPPER(lname+fname) AS name;
FROM customer;
ORDER BY name;
INTO CURSOR cur_cust
ProcFile='cust_list' && Used to display source code
IF RECCOUNT() > 0
M.ListTxt = '<SELECT NAME="customer" SIZE="10"><OPTION SELECTED VALUE="'+cust_no+'">'+TRIM(lname)+', '+TRIM(fname)
SKIP
SCAN REST
M.ListTxt = M.ListTxt+'<OPTION VALUE="'+cust_no+'">'+TRIM(lname)+', '+TRIM(fname)
ENDSCAN
M.ListTxt = M.ListTxt+'</SELECT>'
MergeFile='cust_list' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_list' INTO ARRAY FormTxt
ELSE
MergeFile='no_cust' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'no_cust' INTO ARRAY FormTxt
ENDIF
* See description of MergeTxt at the beginning of this file
html_out = MergeTxt(M.FormTxt)
RETURN
******************************************
PROCEDURE cust_opt
* Displays custumer record and offers
* different options for action
PRIVATE FormTxt, cust_no
* Read customer number
M.cust_no = formField('customer')
* If there was no selection
SELECT * FROM customer;
WHERE cust_no = M.cust_no;
INTO CURSOR cur_cust
ProcFile='cust_opt' && Used to display source code
MergeFile='cust_opt' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_opt' INTO ARRAY FormTxt
* See description of MergeTxt at the beginning of this file
html_out = MergeTxt(M.FormTxt)
RETURN
******************************************
PROCEDURE cust_form
* Decodes data from form REG_NEW.HTM
PRIVATE FormTxt, cust_no, fname, lname, address, city,;
state, zip, error_txt, mode
STORE '' TO M.error_txt, M.cust_no, M.fname, M.lname, M.address,;
M.city, M.state, M.zip
ProcFile='cust_form' && Used to display source code
MergeFile='cust_form' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_form' INTO ARRAY FormTxt
* See description of MergeTxt at the beginning of this file
html_out = MergeTxt(M.FormTxt)
RETURN
******************************************
PROCEDURE cust_result
* Decodes data from form REG_NEW.HTM
PRIVATE FormTxt, cust_no, fname, lname, address, city, state, zip,;
error_txt, max_no, mode
error_txt = ''
* Read field contents
M.cust_no = formField('cust_no')
M.fname = formField('fname')
M.lname = formField('lname')
M.address = formField('address')
M.city = formField('city')
M.state = formField('state')
M.zip = formField('zip')
* Check the validity of the data
IF EMPTY(M.fname)
error_txt = M.error_txt + '<LI><I>The first name was left blank</I><BR>'
ENDIF
IF EMPTY(M.lname)
error_txt = M.error_txt + '<LI><I>The last name was left blank</I><BR>'
ENDIF
ProcFile='cust_result' && Used to display source code
* If there were errors return the form
IF !EMPTY(M.error_txt)
error_txt = '<UL>'+M.error_txt+'</UL>'
MergeFile='cust_form' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_form' INTO ARRAY FormTxt
* See description of MergeTxt at the beginning of this file
html_out = MergeTxt(M.FormTxt)
ELSE
* Create the table if it does not exist
DO chk_table
* If new customer record
IF EMPTY(M.cust_no)
* Find the next available cust_no
DIMENSION max_no[1]
max_no='0'
SELECT MAX(cust_no) FROM customer INTO ARRAY max_no
cust_no = RIGHT('00'+LTRIM(STR(VAL(M.max_no)+1,3,0)),3)
* Save the data
INSERT INTO customer (cust_no, fname, lname, address, city, state, zip);
VALUE (M.cust_no, M.fname, M.lname, M.address, M.city, M.state, M.zip)
ELSE
UPDATE customer;
SET fname = M.fname,;
lname = M.lname,;
address = M.address,;
city = M.city,;
state = M.state,;
zip = M.zip;
WHERE cust_no = M.cust_no
ENDIF
MergeFile='cust_result' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_result' INTO ARRAY FormTxt
* See description of MergeTxt at the beginning of this file
html_out = MergeTxt(M.FormTxt)
ENDIF
RETURN
******************************************
PROCEDURE cust_edit
* Places customer data in form for editing
PRIVATE FormTxt, cust_no, fname, lname, address, city,;
state, zip, error_txt
error_txt = ''
cust_no = FormField('cust_no')
SELECT * FROM customer INTO CURSOR cur_cust;
WHERE cust_no LIKE M.cust_no
SCATTER MEMVAR
ProcFile='cust_edit' && Used to display source code
MergeFile='cust_form' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_form' INTO ARRAY FormTxt
* See description of MergeTxt at the beginning of this file
html_out = MergeTxt(M.FormTxt)
RETURN
******************************************
PROCEDURE cust_del
* Deletes a customer
PRIVATE FormTxt, cust_no
cust_no = FormField('cust_no')
SELECT TRIM(fname)+' '+TRIM(lname) FROM customer;
WHERE cust_no LIKE M.cust_no;
INTO ARRAY cust_name
DELETE FROM customer WHERE cust_no LIKE M.cust_no
ProcFile='cust_del' && Used to display source code
MergeFile='cust_del' && Used to display merge code
* Find the merge text in the html_frm table
SELECT form_text FROM html_frm WHERE form_id LIKE 'cust_del' INTO ARRAY FormTxt
* See description of MergeTxt at the beginning of this file
html_out = MergeTxt(M.FormTxt)
RETURN
******************************************
PROCEDURE chk_table
* Creates customer table if it does not exist
IF !FILE('CUSTOMER.DBF')
CREATE TABLE customer FREE;
(cust_no C(3), fname C(12), lname C(12), address C(30),;
city C(15), state C(2), zip C (10))
IF !FILE('CUSTOMER.CDX')
INDEX ON cust_no TAG cust_no
INDEX ON lname+fname TAG name
ENDIF
ENDIF
RETURN
******************************************
PROCEDURE send_prg
* Creates HTML with the source code of a
* specified program
* This procedure assumes that all
* procedures start with "PROCEDURE".
* It is not meant to be an example of
* good programming.
PRIVATE FormTxt, ProcName, SourceCode, count
CREATE CURSOR cr_proc (memo m)
APPEND BLANK
APPEND MEMO memo FROM customer.prg
ProcName = UPPER(CGI.QueryString)
* If procedure exists
IF CHR(13)+CHR(10)+'PROCEDURE '+M.ProcName $ UPPER(memo)
* Get text from the beginning of the procedure
* to the end of the file
SourceCode = SUBSTR(memo, ATC(CHR(13)+CHR(10)+'PROCEDURE '+M.ProcName, memo)+2)
* If our procedure is not the last one in the file
IF CHR(13)+CHR(10)+'PROCEDURE' $ M.SourceCode
* Remove the rest of the procedures
SourceCode = LEFT(M.SourceCode, ATC(CHR(13)+CHR(10)+'PROCEDURE', M.SourceCode)-1)
ENDIF
ELSE
SourceCode = memo
ENDIF
SELECT form_text FROM html_frm WHERE form_id LIKE 'source_code' INTO ARRAY FormTxt
html_out = MergeTxt(M.FormTxt)
* Replace '<' and '>' with '<' and '>' in
* the preformatted portion of html_txt
html_out = LEFT(M.html_out, ATC('<PRE>', M.html_out)+4);
+ STRTRAN(STRTRAN(SUBSTR(M.html_out, ATC('<PRE>', M.html_out)+5, RAT('</PRE>', M.html_out)-ATC('<PRE>', M.html_out)-5), '<', '<'), '>', '>');
+ SUBSTR(M.html_out, RAT('</PRE>', M.html_out))
RETURN
******************************************
PROCEDURE send_memo
* Creates HTML with the merge code of a
* specified program
PRIVATE FormTxt
SELECT form_text FROM html_frm WHERE form_id LIKE CGI.QueryString INTO ARRAY FormTxt
MergeCode = M.FormTxt
SELECT form_text FROM html_frm WHERE form_id LIKE 'merge_code' INTO ARRAY FormTxt
html_out = MergeTxt(M.FormTxt)
* Replace '<' and '>' with '<' and '>' in
* the preformatted portion of html_txt
html_out = LEFT(M.html_out, ATC('<PRE>', M.html_out)+4);
+ STRTRAN(STRTRAN(SUBSTR(M.html_out, ATC('<PRE>', M.html_out)+5, RAT('</PRE>', M.html_out)-ATC('<PRE>', M.html_out)-5), '<', '<'), '>', '>');
+ SUBSTR(M.html_out, RAT('</PRE>', M.html_out))
RETURN