BR Web Scripting Bridge: Difference between revisions
m (1 revision) |
|||
Line 944: | Line 944: | ||
<noinclude> | <noinclude> | ||
[[Category:Third Party | [[Category:Utilities Third Party]] | ||
[[Category:Open Source]] | [[Category:Open Source]] | ||
[[Category:HTTP]] | [[Category:HTTP]] | ||
</noinclude> | </noinclude> |
Revision as of 18:19, 17 July 2013
The BR Web Scripting Bridge is a PHP class that has the ability to run BR! programs and display the resulting output on a website. Using the BR Web Scripting Bridge, it is easy to create web interfaces to your BR data, and you don't have to know a thing about PHP. Simply drop the BR Web Scripting Bridge and a copy of BR on your web server and start writing your code in BR.
See also:
The Method
When a page is requested from your web server, your BR code is executed with a bit of PHP script.
To use the BR Web Scripting Bridge, you simply write BR programs that print to standard out. This output is then returned to the web browser.
We created a reusable PHP file that will call a BR program of the same name. Then you copy the included PHP template file and rename it to match your program name. The php file tells the web server to run your BR program and display the resulting output.
Input to your programs is provided in the form of a set of predefined variables. These variables contain all data that is sent when a form is submitted by the users web browser.
Using these methods, virtually any web application or http service can be built entirely in BR. Your pages can utilize any of the technologies currently seen in web pages such as Flash, JavaScript, and AJAX.
Requirements
Examples
Here are some examples of the BR Web Scripting Bridge in action:
- Example 1: http://www.sageax.com/bridgedemo/adapter.php?BR_SOURCE=src/webcrawl.brs
- Example 2: http://www.sageax.com/bridgedemo/adapter.php?BR_SOURCE=src/csscrawl.brs
- Example 3: http://www.sageax.com/bridgedemo/adapter.php?BR_SOURCE=src/itemlist.brs
- Example 4: http://www.sageax.com/bridgedemo/adapter.php?BR_SOURCE=src/select.brs
Each of the above examples are simple web applications created and controlled by a single BR program.
Each Example consists of a simple three line php file, the BR Web Scripting Bridge, and a single BR program. The .php file is a completely generic .php file. The only thing it does is to find and launch the .br file of the same name. All you have to do is rename it so the name matches the name of your br program.
We named our first example webcrawl, and created a br program called webcrawl to run the example web page. The second example is called itemlist, and it and all the others are identical to webcrawl.
<?PHP include('class.brphp.php'); $br = new brphp(); $br->RunBrCodeBehind($_SERVER['PHP_SELF']); ?>
The generic php code above simply launches the br code below and displays the output in your browser.
Example 1
http://www.sageax.com/bridgedemo/webcrawl.php
The above website is created from a simple BR program shown below. This example program uses the FileIO Library (not shown) to read data out of my data files in my suite of sample programs and sample data. You choose the data file to view from the drop down. When you press the "View File" button, the php server calls BR and returns the results of the file you chose.
01000 ! WebCrawl - Copyright August 2008 By Gabriel Bakker #Autonumber# 1000,10 01010 ! 01020 ! Created August 4th, 2008 01030 ! 01040 ! This Program Dynamically Generates Html From Your Br Internal Data Files. 01050 ! 01060 ! This Program Requires Fileio To Function And Only Works With Br Internal 01070 ! Data Files That Are Described In A Fileio Compatable File Layout Format. 01080 ! 01090 ! This Program Was Designed To Be Called From A Php Web Site, As An Example 01100 ! Of The New Ability To Expose Your Br Data To The Web Using These Tools. 01110 ! This Program Is An Example Of A Br "CodeBehind" For Php. It Is A Complete 01120 ! Br Powered Web Site 01130 ! 01170 ! 01180 ! 01190 ! With The BR Web Scripting Bridge Your Program Runs In Response To The User 01200 ! Clicking On A Php Web Object Such As A Button. The Button Tells The Php 01210 ! To Reload With The Newly Entered Data, And The Php Server Calls Your Br 01220 ! Program. Mat _Post$ Contains All The Data The User May Have Entered In 01230 ! Your Web Site. 01240 ! 01250 ! You Interpret Mat Post$ And Decide What Needs To Be Done. 01260 ! 01270 ! This Example Is Quite Simple: 01280 ! 01300 ! 01310 if Trim$(_Post$(1))="" then ! If The User Did Not Select A File Layout From The List Then 01320 let Fnreadlayoutfolder ! Display The File Layout List In A Table 01330 else 01340 let Fnreadfileio(Trim$(_Post$(1))) ! But If They Did Select A File, Then Show It 01350 end if 01360 ! 01370 stop 01380 ! 01390 ! 01400 ! 10000 ! #Autonumber# 10000,10 10010 READFILEIO: ! ***** Generate Html From Br Internal Data Files 10020 def Fnreadfileio(Layoutname$*80;Keynum,Path$*255,_Inputfile,_Index) 10030 ! 10040 dim F$(1)*255, F(1) 10050 dim Forms$(1)*255 10060 dim Descr$(1)*255, Widths(1) 10070 ! 10080 library "fileio" : Fnopenfile, Fngetfilenumber,Fnreadlayouts 10090 dim Directorylist$(1)*255 10100 ! 10110 let Fnreadlayouts(Mat Directorylist$) 10120 ! 10130 let _Inputfile=Fnopen(Layoutname$,Mat F$,Mat F,Mat Forms$,1,Keynum,0,Path$,Mat Descr$) 10140 if Udim(Mat Directorylist$) then 10150 ! 10170 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10180 print '<head>' 10190 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 10200 print '</head>' 10210 print '<body>' 10220 print ' <form id="FileData" name="FileData" method="post" action="">' 10230 print ' <label>' 10240 print ' <p><div align="center">File Layout:' 10250 print ' <select name="FileLayout">' 10260 print ' <option value="">All...</option>' 10270 for _Index=1 to Udim(Mat Directorylist$) 10280 print ' <option value="' &Trim$(Directorylist$(_Index))&'">'&Trim$(Directorylist$(_Index))&'</option>' 10290 next _Index 10300 print ' </select>' 10310 print ' <p><input type="submit" name="Submit" value="View File" />' 10320 print ' </div>' 10330 print ' </label>' 10340 print ' </form>' 10350 ! 10360 end if 10370 ! 10380 ! 10390 if _Inputfile then 10400 ! 10410 print '<title>HTML View for '&Layoutname$&' file.</title>' 10420 print '<p align="center"><b>HTML View for '&Layoutname$&' file.</b></p>' 10430 print '' 10440 print '<table align="center" border="1">' 10450 ! 10460 print ' <tr>' 10470 for _Index=1 to Udim(Mat Descr$) 10480 print ' <th scope="col">'&Descr$(_Index)&'</th>' 10490 next _Index 10500 print ' </tr>' 10510 ! 10520 do 10530 read #_Inputfile, using Forms$(_Inputfile): Mat F$, Mat F eof IGNORE 10540 if File(_Inputfile)=0 then ! Read Successful 10550 print ' <tr>' 10560 for _Index=1 to Udim(Mat F$) 10570 print ' <td>'&F$(_Index)&'</td>' 10580 next _Index 10590 for _Index=1 to Udim(Mat F) 10600 print ' <td>'&Str$(F(_Index))&'</td>' 10610 next _Index 10620 print ' </tr>' 10630 end if 10640 loop While File(_Inputfile)=0 10650 ! 10660 print '</table>' 10670 print '</body>' 10680 print '</html>' 10690 ! 10700 close #_Inputfile: 10710 end if 10720 fnend 10730 ! 11000 ! #Autonumber# 11000,10 11010 READLAYOUTFOLDER: ! Generate A Table Listing The Names Of All Your File Layouts 11020 def Fnreadlayoutfolder(;_Index) 11030 ! 11040 library "fileio" : Fnreadlayouts, Fngetfilenumber 11050 dim Directorylist$(1)*255 11060 ! 11070 let Fnreadlayouts(Mat Directorylist$) 11080 ! 11090 if Udim(Mat Directorylist$) then 11100 ! 11120 print '<html xmlns="http://www.w3.org/1999/xhtml">' 11130 print '<head>' 11140 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 11150 print '</head>' 11160 print '<body>' 11170 print ' <form id="FileData" name="FileData" method="post" action="">' 11180 print ' <label>' 11190 print ' <p><div align="center">File Layout:' 11200 print ' <select name="FileLayout">' 11210 print ' <option value="">All...</option>' 11220 for _Index=1 to Udim(Mat Directorylist$) 11230 print ' <option value="'& Trim$(Directorylist$(_Index))&'">'&Trim$(Directorylist$(_Index))&'</option>' 11240 next _Index 11250 print ' </select>' 11260 print ' <p><input type="submit" name="Submit" value="View File" />' 11270 print ' </div>' 11280 print ' </label>' 11290 print ' </form>' 11300 print ' <p align="center"><b>Layout Files</b></p>' 11310 print '' 11320 print ' <table align="center" border="1">' 11330 ! 11340 print ' <tr>' 11350 print ' <th scope="col">Layout</th>' 11360 print ' </tr>' 11370 ! 11380 for _Index=1 to Udim(Mat Directorylist$) 11390 print ' <tr>' 11400 print ' <td><div align="center">'&Directorylist$(_Index)&'</div></td>' 11410 print ' </tr>' 11420 next _Index 11430 ! 11440 print ' </table>' 11450 print '</body>' 11460 print '</html>' 11470 ! 11480 end if 11490 fnend 11500 ! 99000 ! #Autonumber# 99000,10 99010 OPEN: ! ***** Function To Call Library Openfile And Proc Subs 99020 def Fnopen(Filename$, Mat F$, Mat F, Mat Form$; Inputonly, Keynum, Dont_Sort_Subs, Path$*255, Mat Descr$, Mat Field_Widths) 99030 let Fnopen=Fnopenfile(Filename$, Mat F$, Mat F, Mat Form$, Inputonly, Keynum, Dont_Sort_Subs, Path$, Mat Descr$, Mat Field_Widths) 99040 execute ("*proc subs.$$$") 99050 fnend 99060 ! 99980 ! #Autonumber# 99980,10 99990 IGNORE: continue
Example 2
http://www.sageax.com/bridgedemo/csscrawl.php
Our first example was simple and exciting but the web page didn't look very nice. For our next example, we're going to take the same program, and apply a Cascading Style Sheet to make it look a little bit nicer.
Cascading Style Sheets, or CSS files, are replaceable templates that affect the overall look, or style, of a web page. When you design a web site, if you put all your style settings in a CSS file, you can change them all later by simply replacing the CSS file, without having to modify the site itself.
Additionally, you can find many CSS files online that you can just drop into your applications.
For this example, we'll be taking a CSS file called style.css that contains a bunch of nice styles for tables. We'll be using it to spruce up the appearance of the tables from the example before.
To use CSS, all we have to do is modify the header to include the style sheet, and modify the tables to use it.
10160 print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' 10170 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10180 print '<head>' 10190 print ' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 10200 print ' <link href="style.css" rel="stylesheet" type="text/css">' 10210 print '</head>'
In line 10160, we declare the file as an xhtml file as opposed to a regular html file. In line 10200, we include the style sheet.
10450 print '<table id="hor-minimalist-b" align="center">' 10470 print ' <thead>' 10480 print ' <tr>' 10490 for _Index=1 to Udim(Mat Descr$) 10500 print ' <th scope="col">'&Descr$(_Index)&'</th>' 10510 next _Index 10520 print ' </tr>' 10530 print ' </thead>'
Line 10450 tells the table to use the CSS style "hor-minimalist-b" from the included file.
Notice the <thead> and </thead> tags above. We also need to specify a <thead> and a <tbody>, so that the style knows what to apply to each part of the table.
10550 print ' <tbody>' 10610 print ' <td>'&F$(_Index)&'</td>' 10640 print ' <td>'&Str$(F(_Index))&'</td>' 10700 print ' </tbody>' 10710 print '</table>' 10720 print '</body>' 10730 print '</html>'
We draw the body of the table just like before, adding the <tbody> and </tbody> tags.
Here is the full example. The code is almost identical to Example 1 but looks a lot nicer when you run it.
01000 ! CssCrawl - Copyright August 2008 By Gabriel Bakker #Autonumber# 1000,10 01010 ! 01020 ! Created August 4th, 2008 01030 ! 01040 ! This Program Dynamically Generates Html From Your Br Internal Data Files. 01050 ! 01060 ! This Program Requires Fileio To Function And Only Works With Br Internal 01070 ! Data Files That Are Described In A Fileio Compatable File Layout Format. 01080 ! 01090 ! This Program Was Designed To Be Called From A Php Web Site, As An Example 01100 ! Of The New Ability To Expose Your Br Data To The Web Using These Tools. 01110 ! This Program Is An Example Of A Br "CodeBehind" For Php. It Is A Complete 01120 ! Br Powered Web Site 01130 ! 01140 ! This Library Is Intended To Be Implemented With The Br Phprun System And 01150 ! The Fileio Library. 01160 ! 01170 ! 01180 ! 01190 ! With Br Php, Your Program Runs In Response To The User Clicking On 01200 ! A Php Web Object Such As A Button. The Button Tells The Php To Reload 01210 ! With The Newly Entered Data, And The Php Server Calls Your Br Program. 01220 ! Mat _Post$ Contains All The Data The User May Have Entered In Your Web 01230 ! Site. 01240 ! 01250 ! You Interpret Mat Post$ And Decide What Needs To Be Done. 01260 ! 01270 ! This Example Is Quite Simple: 01280 ! 01290 ! 01300 if Trim$(_Post$(1))="" then ! If The User Did Not Select A File Layout From The List Then 01310 let Fnreadlayoutfolder ! Display The File Layout List In A Table 01320 else 01330 let Fnreadfileio(Trim$(_Post$(1))) ! But If They Did Select A File, Then Show It 01340 end if 01350 ! 01360 stop 01370 ! 01380 ! 01390 ! 10000 ! #Autonumber# 10000,10 10010 READFILEIO: ! ***** Generate Html From Br Internal Data Files 10020 def Fnreadfileio(Layoutname$*80;Keynum,Path$*255,_Inputfile,_Index) 10030 ! 10040 dim F$(1)*255, F(1) 10050 dim Forms$(1)*255 10060 dim Descr$(1)*255, Widths(1) 10070 ! 10080 library "fileio" : Fnopenfile, Fngetfilenumber,Fnreadlayouts 10090 dim Directorylist$(1)*255 10100 ! 10110 let Fnreadlayouts(Mat Directorylist$) 10120 ! 10130 let _Inputfile=Fnopen(Layoutname$,Mat F$,Mat F,Mat Forms$,1,Keynum,0,Path$,Mat Descr$) 10140 if Udim(Mat Directorylist$) then 10150 ! 10160 print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' 10170 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10180 print '<head>' 10190 print ' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 10200 print ' <link href="style.css" rel="stylesheet" type="text/css">' 10210 print '</head>' 10220 print '<body>' 10230 print ' <form id="FileData" name="FileData" method="post" action="">' 10240 print ' <label>' 10250 print ' <p><div align="center">File Layout:' 10260 print ' <select name="FileLayout">' 10270 print ' <option value="">All...</option>' 10280 for _Index=1 to Udim(Mat Directorylist$) 10290 print ' <option value="'& Trim$(Directorylist$(_Index))&'">'&Trim$(Directorylist$(_Index))&'</option>' 10300 next _Index 10310 print ' </select>' 10320 print ' <p><input type="submit" name="Submit" value="View File" />' 10330 print ' </div>' 10340 print ' </label>' 10350 print ' </form>' 10360 ! 10370 end if 10380 ! 10390 ! 10400 if _Inputfile then 10410 ! 10420 print '<title>HTML View for '&Layoutname$&' file.</title>' 10430 print '<p align="center"><b>HTML View for '&Layoutname$&' file.</b></p>' 10440 print '' 10450 print '<table id="hor-minimalist-b" align="center">' 10460 ! 10470 print ' <thead>' 10480 print ' <tr>' 10490 for _Index=1 to Udim(Mat Descr$) 10500 print ' <th scope="col">'&Descr$(_Index)&'</th>' 10510 next _Index 10520 print ' </tr>' 10530 print ' </thead>' 10540 ! 10550 print ' <tbody>' 10560 do 10570 read #_Inputfile, using Forms$(_Inputfile): Mat F$, Mat F eof IGNORE 10580 if File(_Inputfile)=0 then ! Read Successful 10590 print ' <tr>' 10600 for _Index=1 to Udim(Mat F$) 10610 print ' <td>'&F$(_Index)&'</td>' 10620 next _Index 10630 for _Index=1 to Udim(Mat F) 10640 print ' <td>'&Str$(F(_Index))&'</td>' 10650 next _Index 10660 print ' </tr>' 10670 end if 10680 loop While File(_Inputfile)=0 10690 ! 10700 print ' </tbody>' 10710 print '</table>' 10720 print '</body>' 10730 print '</html>' 10740 ! 10750 close #_Inputfile: 10760 end if 10770 fnend 10780 ! 11000 ! #Autonumber# 11000,10 11010 READLAYOUTFOLDER: ! Generate A Table Listing The Names Of All Your File Layouts 11020 def Fnreadlayoutfolder(;_Index) 11030 ! 11040 library "fileio" : Fnreadlayouts, Fngetfilenumber 11050 dim Directorylist$(1)*255 11060 ! 11070 let Fnreadlayouts(Mat Directorylist$) 11080 ! 11090 if Udim(Mat Directorylist$) then 11100 ! 11110 print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' 11120 print '<html xmlns="http://www.w3.org/1999/xhtml">' 11130 print '<head>' 11140 print ' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 11150 print ' <link href="style.css" rel="stylesheet" type="text/css">' 11160 print '</head>' 11170 print '<body>' 11180 print ' <form id="FileData" name="FileData" method="post" action="">' 11190 print ' <label>' 11200 print ' <p><div align="center">File Layout:' 11210 print ' <select name="FileLayout">' 11220 print ' <option value="">All...</option>' 11230 for _Index=1 to Udim(Mat Directorylist$) 11240 print ' <option value="'& Trim$(Directorylist$(_Index))&'">'&Trim$(Directorylist$(_Index))&'</option>' 11250 next _Index 11260 print ' </select>' 11270 print ' <p><input type="submit" name="Submit" value="View File" />' 11280 print ' </div>' 11290 print ' </label>' 11300 print ' </form>' 11310 print ' <p align="center"><b>Layout Files</b></p>' 11320 print '' 11330 print ' <table id="hor-minimalist-b" align="center">' 11340 ! 11350 print ' <thead>' 11360 print ' <tr>' 11370 print ' <th scope="col">Layout</th>' 11380 print ' </tr>' 11390 print ' </thead>' 11400 ! 11410 print ' <tbody>' 11420 for _Index=1 to Udim(Mat Directorylist$) 11430 print ' <tr>' 11440 print ' <td><div align="center">'&Directorylist$(_Index)&'</div></td>' 11450 print ' </tr>' 11460 next _Index 11470 ! 11480 print ' </tbody>' 11490 print ' </table>' 11500 print '</body>' 11510 print '</html>' 11520 ! 11530 end if 11540 fnend 11550 ! 99000 ! #Autonumber# 99000,10 99010 OPEN: ! ***** Function To Call Library Openfile And Proc Subs 99020 def Fnopen(Filename$, Mat F$, Mat F, Mat Form$; Inputonly, Keynum, Dont_Sort_Subs, Path$*255, Mat Descr$, Mat Field_Widths) 99030 let Fnopen=Fnopenfile(Filename$, Mat F$, Mat F, Mat Form$, Inputonly, Keynum, Dont_Sort_Subs, Path$, Mat Descr$, Mat Field_Widths) 99040 execute ("*proc subs.$$$") 99050 fnend 99060 ! 99980 ! #Autonumber# 99980,10 99990 IGNORE: continue
Example 3
http://www.sageax.com/bridgedemo/itemlist.php
Example 3 demonstrates how to dynamically ask the user for information from your BR program.
This simple BR program reads a list of groceries from the items file and generates a web form where a grocer could order items directly over the internet. The grocer enters quantities in the quantities field for any items he wishes to purchase and presses the "Ok" button when done. The page is submitted again to our program, this time with the MAT _POST$ array populated with all the data the grocer entered into the form. The program processes the data, adding up the quantities and prints out a "Congratulations, your order was successful!" page.
If this were a real life program, you would simply save the new order back into your BR data files.
10000 ! Itemlist - Copyright August 2008 By Sage Ax #Autonumber# 10000,10 10010 ! 10020 ! Created August 20th, 2008 10030 ! 10040 ! This Program Dynamically Generates Html From Your Br Internal Data Files. 10050 ! 10060 ! This Program Requires Fileio To Function And Only Works With Br Internal 10070 ! Data Files That Are Described In A Fileio Compatable File Layout Format. 10080 ! 10090 ! This Program Was Designed To Be Called From A Php Web Site, As An Example 10100 ! Of The New Ability To Expose Your Br Data To The Web Using These Tools. 10110 ! This Program Is An Example Of A Br "CodeBehind" For Php. It Is A Complete 10120 ! Br Powered Web Site 10130 ! 10140 ! This Library Is Intended To Be Implemented With The Br Phprun System And 10150 ! The Fileio Library. 10160 ! 10170 ! 10180 ! 10190 ! With Br Php, Your Program Runs In Response To The User Clicking On 10200 ! A Php Web Object Such As A Button. The Button Tells The Php To Reload 10210 ! With The Newly Entered Data, And The Php Server Calls Your Br Program. 10220 ! Mat _Post$ Contains All The Data The User May Have Entered In Your Web 10230 ! Site. 10240 ! 10250 ! You Interpret Mat Post$ And Decide What Needs To Be Done. 10260 ! 10270 ! This Example Is Quite Simple: 10280 ! 10290 ! 10300 ! 10310 dim Subs(4) 10320 dim Subn(3) 10330 dim Item$(1)*255, Item(1) 10340 dim Forms$(1)*255 10350 dim Descr$(1)*255, Widths(1) 10360 ! 10370 if udim(_post$)>10 then goto DisplayResults 10380 ! 10390 library "fileio" : Fnopenfile, Fngetfilenumber 10400 ! 10410 let _Inputfile=Fnopen("opditem",Mat Item$,Mat Item,Mat Forms$,1,0,0,"",Mat Descr$) 10420 ! 10430 let Subs(1)=It_Item 10440 let Subs(2)=It_Desc 10450 let Subs(3)=It_Um 10460 let Subs(4)=It_Size 10470 let Subn(1)=It_Cost 10480 let Subn(2)=It_Price 10490 let Subn(3)=It_Retail 10500 ! 10510 if _Inputfile then 10520 ! 10540 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10550 print '<head>' 10560 print '<title>Sample Order Entry</title>' 10570 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 10580 print '</head>' 10590 print '<body>' 10600 print '<p align="center"><b>Sample Order Entry</b></p>' 10610 print '<br><br>' 10620 print '<form id="FileData" name="FileData" method="post" action="">' 10630 print '<table align="center" border="1">' 10640 print ' <tr>' 10650 print ' <th scope="col">Qty Ordered</th>' 10660 for _Index=1 to Udim(Mat Subs) ! Print String Captions 10670 print ' <th scope="col">'&Descr$(Subs(_Index))&'</th>' 10680 next _Index 10690 for _Index=1 to Udim(Mat Subn) ! Print Numeric Captions 10700 print ' <th scope="col">'&Descr$(Subn(_Index)+Udim(Mat Item$))&'</th>' 10710 next _Index 10720 print ' </tr>' 10730 ! 10740 do 10750 read #_Inputfile, using Forms$(_Inputfile): Mat Item$, Mat Item eof IGNORE 10760 ! 10770 if File(_Inputfile)=0 then ! Read Successful 10780 print ' <tr>' 10790 print ' <td><label>' 10800 print ' Qty: <input type="text" name="Qty'& Item$(It_Item)&'" id="Qty'&Item$(It_Item)&'" />' 10810 print ' </label></td>' 10820 for _Index=1 to Udim(Mat Subs) 10830 print ' <td>'&Item$(Subs(_Index))&'</td>' 10840 next _Index 10850 for _Index=1 to Udim(Mat Subn) 10860 print ' <td>'&Str$(Item(Subn(_Index)))&'</td>' 10870 next _Index 10880 print ' </tr>' 10890 end if 10900 loop While File(_Inputfile)=0 10910 ! 10920 print '</table>' 10930 ! 10940 print '<p align="center"><label>Submit Order: <input type="submit" name="button" id="cow" value="Ok" /></label></p>' 10950 ! 10960 print '</form>' 10970 print '</body>' 10980 print '</html>' 10990 ! 11000 close #_Inputfile: 11010 end if 11020 ! 11030 Goto EndProgram 11040 ! 11050 DisplayResults: ! Display results 11060 ! 11070 For Index=1 to udim(mat _post$) 11080 if Index<>p_button then 11090 TotalQty+=val(_post$(Index)) conv Ignore 11100 end if 11110 next Index 11120 ! 11130 print '...........' ! Extra spaces in case of parsing differences 11140 print '<html xmlns="http://www.w3.org/1999/xhtml">' 11150 print '<head>' 11160 print '<title>Order Submitted!</title>' 11170 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 11180 print '</head>' 11190 print '<body>' 11200 print '<b><p align="center">Congratulations!!!</p>' 11210 print '<br><br>' 11220 print '<p align="center">Your order for '&str$(TotalQty)&' items has been recieved.' 11230 print '</body>' 11240 print '</html>' 11250 ! 11260 EndProgram: ! End program 11270 stop 11280 ! 11290 ! 99000 ! #Autonumber# 99000,10 99010 OPEN: ! ***** Function To Call Library Openfile And Proc Subs 99020 def Fnopen(Filename$, Mat F$, Mat F, Mat Form$; Inputonly, Keynum, Dont_Sort_Subs, Path$*255, Mat Descr$, Mat Field_Widths) 99030 let Fnopen=Fnopenfile(Filename$, Mat F$, Mat F, Mat Form$, Inputonly, Keynum, Dont_Sort_Subs, Path$, Mat Descr$, Mat Field_Widths) 99040 execute ("*proc subs.$$$") 99050 fnend 99060 ! 99980 ! #Autonumber# 99980,10 99990 IGNORE: continue
Example 4
http://www.sageax.com/bridgedemo/select.php
Our next example demonstrates both data entry and multi-program applications.
This example is in three parts, each controlled by a separate BR program.
The first br program and php file are called "select". This BR program simply displays the contents of the colorcat file and ask's a user to select a record from it using radio buttons.
The second BR program and php file are called "edit". This BR program presents the contents of the record the user selected, allowing the user to edit them in a web form.
The third BR program and PHP file are called "save". This BR program saves the changes the user made and prints a confirmation message.
select.brs:
10000 ! Select - Copyright August 2008 By Sage Ax #Autonumber# 10000,10 10010 ! 10020 ! Created August 21st, 2008 10030 ! 10040 ! This Program Dynamically Generates Html From Your Br Internal Data Files. 10050 ! 10060 ! This Program Requires Fileio To Function And Only Works With Br Internal 10070 ! Data Files That Are Described In A Fileio Compatable File Layout Format. 10080 ! 10090 ! This Program Was Designed To Be Called From A Php Web Site, As An Example 10100 ! Of The New Ability To Expose Your Br Data To The Web Using These Tools. 10110 ! This Program Is An Example Of A Br "CodeBehind" For Php. It Is A Complete 10120 ! Br Powered Web Site 10130 ! 10140 ! This Library Is Intended To Be Implemented With The Br Phprun System And 10150 ! The Fileio Library. 10160 ! 10170 ! 10180 ! 10190 ! This Program Is The First Part In A Three Part Demonstration Showing How 10200 ! You Can Use A Seperate Program For Each "Step" In The Process. 10210 ! 10220 ! In This Stage In The Process, The User Is Presented With A Selection Screen 10230 ! On Which They Can Select A Colorcat Record To Edit. We'll also show the 10240 ! Entire Contents Of The Colorcat File On The Screen For Review. 10250 ! 10260 ! 10270 dim Colorcat$(1)*255, Colorcat(1) 10280 dim Forms$(1)*255 10290 dim Descr$(1)*255, Widths(1) 10300 ! 10310 library "fileio" : Fnopenfile, Fngetfilenumber 10320 ! 10330 let _Inputfile=Fnopen("colorcat",Mat Colorcat$,Mat Colorcat,Mat Forms$,1,0,0,"",Mat Descr$) 10340 ! 10360 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10370 print '<head>' 10380 print '<title>Select a record</title>' 10390 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 10400 print '</head>' 10410 print '<body>' 10420 print '<br>' 10430 print '<br>' 10440 print '<form id="Colorcat" name="colorcat" method="post" action="edit.php">' 10450 ! 10460 print ' <p align="center">Select a record and press Edit.<br>' 10470 print ' <input type="submit" name="button" value="Edit" />' 10480 print ' </p>' 10490 ! 10500 print '<table align="center" border="1">' 10510 print ' <tr>' 10520 print ' <th scope="col">Select</th>' 10530 for _Index=1 to Udim(Mat Descr$) ! Print String Captions 10540 print ' <th scope="col">'&Descr$(_Index)&'</th>' 10550 next _Index 10560 print ' </tr>' 10570 ! 10580 do 10590 read #_Inputfile, using Forms$(_Inputfile): Mat Colorcat$, Mat Colorcat eof IGNORE 10600 if File(_Inputfile)=0 then ! Read Successful 10610 print ' <tr bgcolor="'&Colorcat$(Cc_Html)&'">' 10620 print '<td> <input name="key" type="radio" value="'&Colorcat$(Cc_Code)&'" /></td>' 10630 for _Index=1 to Udim(Mat Colorcat$) 10640 print ' <td>'&Colorcat$(_Index)&'</td>' 10650 next _Index 10660 print ' </tr>' 10670 end if 10680 loop While File(_Inputfile)=0 10690 ! 10700 print '</table>' 10710 ! 10720 print '</form>' 10730 print '</body>' 10740 print '</html>' 10750 ! 10760 close #_Inputfile: 10770 ! 10780 stop 10790 ! 10800 ! 99000 ! #Autonumber# 99000,10 99010 OPEN: ! ***** Function To Call Library Openfile And Proc Subs 99020 def Fnopen(Filename$, Mat F$, Mat F, Mat Form$; Inputonly, Keynum, Dont_Sort_Subs, Path$*255, Mat Descr$, Mat Field_Widths) 99030 let Fnopen=Fnopenfile(Filename$, Mat F$, Mat F, Mat Form$, Inputonly, Keynum, Dont_Sort_Subs, Path$, Mat Descr$, Mat Field_Widths) 99040 execute ("*proc subs.$$$") 99050 fnend 99060 ! 99980 ! #Autonumber# 99980,10 99990 IGNORE: continue
edit.brs:
10000 ! Edit - Copyright August 2008 By Sage Ax #Autonumber# 10000,10 10010 ! 10020 ! Created August 21st, 2008 10030 ! 10040 ! 10050 ! This Program Is The Second Part In A Three Part Demonstration Showing How 10060 ! You Can Use A Seperate Program For Each "Step" In The Process. 10070 ! 10080 ! In This Stage In The Process, The User Is Presented With The Data For 10090 ! A Colorcat Record So That They Can Change It And Save It. 10100 ! 10110 ! 10120 dim Colorcat$(1)*255, Colorcat(1) 10130 dim Forms$(1)*255 10140 dim Descr$(1)*255, Widths(1) 10150 ! 10160 library "fileio" : Fnopenfile, Fngetfilenumber 10170 ! 10180 if P_Key then 10190 let _Inputfile=Fnopen("colorcat",Mat Colorcat$,Mat Colorcat,Mat Forms$,1,0,0,"", Mat Descr$) 10200 if _Inputfile then 10210 read #_Inputfile, using Forms$(_Inputfile), key=_Post$(P_Key) : Mat Colorcat$, Mat Colorcat nokey IGNORE 10220 close #_Inputfile: 10230 end if 10240 end if 10250 ! 10260 ! 10270 if Cc_Code=0 Or Trim$(Colorcat$(Cc_Code))="" then ! If Record Not Found 10280 ! 10290 print '............' 10300 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10310 print '<head>' 10320 print '<title>Error</title>' 10330 print '<meta http-equiv="REFRESH" content="4;url=select.php"/>' 10340 print '</head>' 10350 print '<body>' 10360 print '<br>' 10370 if P_Key=0 then 10380 print '<p align="center">Please select a record and <A HREF="select.php"> try again</a>.</p>' 10390 else 10400 print '<p align="center">The record could not be found. Please <A HREF="select.php"> try again</a>.</p>' 10410 end if 10420 print '</body>' 10430 print '</html>' 10440 ! 10450 stop 10460 ! 10470 end if 10480 ! 10490 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10500 print '<head>' 10510 print '<title>Edit the record</title>' 10520 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 10530 print '</head>' 10540 print '<body>' 10550 print '<br>' 10560 print '<br>' 10570 print '<form id="Colorcat" name="colorcat" method="post" action="save.php">' 10580 print ' <p align="center">Edit the data and press Save.<br><br>' 10590 print ' Key: '&Colorcat$(Cc_Code)&'<input type="hidden" name="key" value="'& Colorcat$(Cc_Code)&'"/>' 10600 print ' Description: <input type="text" name="Description" value="'&Colorcat$(Cc_Name) &'" />' 10610 print ' Color: <input type="text" name="Color" value="'&Colorcat$(Cc_Html)&'" /><br>' 10620 print ' <br><input type="submit" name="button" value="Save" />' 10630 print ' </p>' 10640 print '</form>' 10650 print '</body>' 10660 print '</html>' 10670 ! 10680 stop 10690 ! 10700 ! 99000 ! #Autonumber# 99000,10 99010 OPEN: ! ***** Function To Call Library Openfile And Proc Subs 99020 def Fnopen(Filename$, Mat F$, Mat F, Mat Form$; Inputonly, Keynum, Dont_Sort_Subs, Path$*255, Mat Descr$, Mat Field_Widths) 99030 let Fnopen=Fnopenfile(Filename$, Mat F$, Mat F, Mat Form$, Inputonly, Keynum, Dont_Sort_Subs, Path$, Mat Descr$, Mat Field_Widths) 99040 execute ("*proc subs.$$$") 99050 fnend 99060 ! 99980 ! #Autonumber# 99980,10 99990 IGNORE: continue
save.br:
10000 ! Save - Copyright August 2008 By Sage Ax #Autonumber# 10000,10 10010 ! 10020 ! Created August 21st, 2008 10030 ! 10040 ! 10050 ! This Program Is The Second Part In A Three Part Demonstration Showing How 10060 ! You Can Use A Seperate Program For Each "Step" In The Process. 10070 ! 10080 ! In This Stage In The Process, The data is saved and a confirmation is printed. 10100 ! 10110 ! 10120 dim Colorcat$(1)*255, Colorcat(1) 10130 dim Forms$(1)*255 10150 ! 10160 library "fileio" : Fnopenfile, Fngetfilenumber 10170 print Mat _Post$ 10180 ! 10190 if P_Key then 10200 let _Inputfile=Fnopen("colorcat",Mat Colorcat$,Mat Colorcat,Mat Forms$) 10210 if _Inputfile then 10220 read #_Inputfile, using Forms$(_Inputfile), key=_Post$(P_Key) : Mat Colorcat$, Mat Colorcat nokey IGNORE 10230 let Colorcat$(cc_code)=_post$(p_key) 10240 let Colorcat$(cc_name)=_post$(p_description) 10250 let Colorcat$(cc_html)=_post$(p_color) 10260 rewrite #_Inputfile, using forms$(_Inputfile) : mat colorcat$, mat colorcat 10270 let found=1 10280 end if 10290 end if 10300 ! 10310 if not found then ! If Record Not Found 10320 ! 10330 print '............' 10340 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10350 print '<head>' 10360 print '<title>Error</title>' 10370 print '<meta http-equiv="REFRESH" content="4;url=select.php">' 10380 print '</head>' 10390 print '<body>' 10400 print '<br>' 10410 print '<p align="center">The record could not be found. Please <A HREF="select.php"> try again</a>.</p>' 10420 print '</body>' 10430 print '</html>' 10440 ! 10450 stop 10460 ! 10470 end if 10480 ! 10485 PRINT "########[BEGINHTML]########................." 10490 print '<html xmlns="http://www.w3.org/1999/xhtml">' 10500 print '<head>' 10510 print '<title>Success</title>' 10520 print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' 10530 print '</head>' 10540 print '<body>' 10550 print '<br>' 10560 print '<br>' 10570 print '<form id="Colorcat" name="colorcat" method="post" action="select.php">' 10580 print ' <p align="center">Your record has been saved!<br><br>' 10590 print ' <input type="submit" name="button" value="Show Me" />' 10600 print ' </p>' 10610 print '</form>' 10620 print '</body>' 10630 print '</html>' 10640 ! 10650 stop 10660 ! 10670 ! 99000 ! #Autonumber# 99000,10 99010 OPEN: ! ***** Function To Call Library Openfile And Proc Subs 99020 def Fnopen(Filename$, Mat F$, Mat F, Mat Form$; Inputonly, Keynum, Dont_Sort_Subs, Path$*255, Mat Descr$, Mat Field_Widths) 99030 let Fnopen=Fnopenfile(Filename$, Mat F$, Mat F, Mat Form$, Inputonly, Keynum, Dont_Sort_Subs, Path$, Mat Descr$, Mat Field_Widths) 99040 execute ("*proc subs.$$$") 99050 fnend 99060 ! 99980 ! #Autonumber# 99980,10 99990 IGNORE: continue
User Guide
This page will be updated with the documentation as soon as it is released.