AGORASCRIPT Steve Kneizys (Copyright 2000) 20-FEB-2000 15-JUL-2000 update Use PERL script right in your productPage.inc and HTML files! ------------------------------------------------------------- Implementation: Store Headers, Footers, productPage files, and full HTML pages loaded from the html directory tree. The use of such code does represent a few risks if you choose to use it. Although it is not much more dangerous than altering the code in the libraries, you should keep in mind that if you change a global variable value in the script then it is changed for the main program as well! Using local variables is easy to do as required. Code is executed using Perl's "eval" mechanism. Pages are read in from your html directory tree, then parsed for code. This parsed code is the un-tainted, and sent to the "eval" command. This code will stop executing if there is an error, write a message to the error log with which script died (starting at zero), if it was "pre" or "post", the page it came from, and the $@ error returned by eval. One advantage of using this scripting option is that if you choose to use this for your customizations, you may not have to plug them back in for upgrades of agora.cgi. By virtue of them being in the script .inc and /main and /product pages, they will remain where you put them with your customized HTML. Here is how it works. There are two types of scripts, pre- and postsubstitution scripts. You must decide if you want the script to run before the %% tokens are substituted, or after. Any "print" statements will be executed immediately, and any value returned from a script will be placed in the page at the place the script was found. Unless you really, really know what you are doing, use of the "print" statement is not recommended! Intead, just keep accumulating what you want to be displayed inside a string, and use that variable to return the value back to the software. Consider this sample script: In that script, the string returned is the token %%cart_id%%, not its value, because it was executed before the substitutions were made (the -pre part of the script header specifies that.) However, after the script has run, the token %%cart_id%% is not embedded in the working version of the HTML. The token will be substituted for it's actual value for display purposes in the next step of processing. So, if need the value of the cart, product number, category, etc. inside the script, you would want to run the script after the substitution. Also, the global values of $my_string and $test_val were altered. To have your own local variables, it is easy enough to declare them as local. Now consider this example: The -post part of the script header tells agora.cgi to run it after substitution of %% tokens. This script will return the value of the $my_string, which is the actual value of the cart_id for this session. Of course this is a lot of work to get just the cart_id, but the possibilities for customization are almost unlimited. For safety, if you need global variables to store information between invocations of such scripts, it is suggested that you use variables that begin with $ags_ (such as $ags_been_here) simply because no variables appear in the agora.cgi package that begin that way. There is an agorascript example in the hmtl-templates directory called productPage-agorascript_example.inc and displays the database contents in a somewhat raw form. To see it work in the sample store, type in: agoracgi?keywords=html&ppinc=agorascript_example The contents of productPage-agorascript_example.inc are: