baseportal | ||
Start | ||
baseportal Documentation |
Introduction | Up |
Databases are needed to arrange data. This can be done, for example, by writing a telephone-book, or using a PC (which collects data). All sorts of things can be considered as data and everybody uses them. Addresses, products of a company, basketball results, entries in a diary, shopping notes, etc.
To be able to use this data, it has to be organised. The most common, and in many cases, the most useful way of doing this is by creating a table. Here for instance is an address table:
Name | Street | City |
---|---|---|
Robert Miller | Duff Drive. | Winston-Salem, NC 27105 |
Nancy Douglas | National Blvd. | Seattle, WA 98198 |
George Smith | Kelly Ave. | New York, NY 10016 |
Tiffany Gray | Jim Bob Rd. | Bloomington, IN 47404 |
The data is organised in rows and columns. A field is a specific column located in a specific row. The first line is obviously very important. It labels the individual columns but is not part of the data itself.
Regarding this configuration, we asked the following question: What does the all the data have in common? How can we group this information in a clever way?
This must be carefully considered when creating a database: Before we can enter any data, we must think about what kind of data we actually want to collect.
There are basically three different things which can be done with data:
The last point is the main reason why databases are used: For a computer its a piece of cake to output data in many different ways. Even if there are millions of entries in which the field "Name" begins with "a" and the field "City" is Washington D.C, the computer will be able to find the right entries extremely quickly!
baseportal actually provides a database for the internet. You can get access to your data via the internet from anywhere in the world. Or, you can create a website by using databases. Modifications, like the ones constantly used at onlineshops, for example, can be executed very conviniently with the baseportal user-interface. That makes the complicated editing of the html code obsolete. Recurrent types of data, like addresses, can be generated automatically in your website through baseportal. You specify the way the output has to be sorted.
In order to understand the concepts of a web database better, go to Easy Start and create your first baseportal database yourself.
Templates and Tags | Up |
Output pages are normal web pages on which you can use certain new html commands, which are called tags.
baseportal modifies the pages before the actual output and replaces those special Tags eg. by the current content of a database, by another page or the results of a calculation.
Since these pages are used as models for the output, they are called templates.
Example:
<html></head><title>Highscore</title></head> <body bgcolor=ffffff> <h2>Highscore</h2> <include src=introduction> <do action=all> <center> <table width=90% border=1> <tr><td>Name</td><td>Score</td> <loop sort=- range=0,10> <tr> <td><b>$Name</b></td> <td>$Score</td> </tr> </loop> </table> </center> </body></html> |
Black tags are all normal HTML commands.
Red = New, basportal-specific tags.
Like with standard HTML, baseportal tags begin with the less than sign < and end with the greater than sign >. Some tags can be used by themselves, like <include...>, and some enclose the area they are influencing. The end of the area has to be marked with the finishing tag. That tag has the same name the start tag except it must begin with a slash /, like, for example: <loop> ... </loop>. It doesn't matter whether you use upper or lower case, but everything is usually written in lower case.
Blue = Parameters that influence the execution of commands.
Some tags require further data, also called parameters, in order to run properly. Like, for example: needs to be given the name of the file that is supposed to be embedded here. Other tags do not necessarily need parameters but, however, they enable us to use slightly different executions of commands. Like, for example the use of different sorting techniques or having a different background color. Tags and Parameters are separated from one another by one space. Sequenced parameters are similarly kept apart. Caution: Quotation marks are interpreted as an element of a variable. They do not enclose a variable as they do in HTML. So, it's better not to use any quotation marks...
Green = Variables that will be replaced by current data.
Variables are simply "placeholders" where another value will be inserted. They always begin (like in the programming languages Perl or PHP) with the dollar sign $. There is a variety of special variables that contain, for example, the amount of read entries or the name of the database which is giving output. But they are, more often than not, fields of a database, and contain the value of their respective data sets.
Quite often, certain texts are repeated in several HTML pages.In baseportal you don‘t have to repeat everything in each file anymore. You can store texts that you need in separate files. When you need them, you just paste them onto other pages. Changing separate files automatically affects all the other pages that include that file.
Definition:
<include src=Templatename[Parameter]> |
Example:
The template mypage contains the following:
Here comes the introduction:<p> <include src=head> That’s it... |
A second template head in the same path looks like this:
<b>Nice... </b><p> <i>...that you are surfing on my page.</i><br> Special thanks to all the people i know!<p> |
If the page mypage is accessed now, the following output appears:
Here comes the introduction: Nice... ...that you are surfing on my page. That’s it... |
include is especially useful in menus that mostly stay constant on every page. Variables offer the possibility to customise them in different ways.
Nestings are possible and easy: If a third file contains the command...
<include src=mypage> |
...the complete output of the above entry will be inserted at the specified position. Furthermore, a fourth file can include the third file, and so on. baseportal deals with infinite loops (file 1 includes file 2, file 2 includes file 3 which includes file 1) and aborts them.
When referring to templates in other paths, you need path-name specifications. These are possible as relative...
<include src=project2/finishing> |
...or absolute path-names:
<include src=/AxelS/menues/standard> |
includes the template standard in path menus of the user AxelS
The tag do makes the execution of several functions possible.Therefore, it is controllable by a multitude of parameters. For example, the parameter language=de outputs the text in German. Click here for the list of all possible parameters.
Definition:
<do action=Command[Parameter]> |
Possible values for Command are: input, list or all.
all handles the complete output of the database, allows you to search for special entries, checks on the permissions, and, if permitted, outputs the input form as well. And you may control it with many parameters.
Examples:
This is my address list:<p> <do action=all db=addresses sort=-Name border=1 datasize=4> |
Here, all the entries of the database addresses will be sorted by name, in reverse alphabetical order (from Z to A.) The table will be framed, and the text will be displayed in font size 4.
This is my address list:<p> <do action=all listfields=Name,Street,Place keyfield=Place> |
In this case, all entries will be sorted by their Id (that means the order in which they were stored in the database). Only the fields Name, Street and Place will be displayed, and the link for the remaining information will be available under the field Place.
To learn more parameters, click here.
<do action=input> |
This processes user entries with regard to adding, modifying or deleting entries (if the necessary permissions are set). If you do not use this tag, no changes will be made in the database even though you may have succesfully filled out an input form and have the necessary permissions.
list is needed in order to control the output of the templates more precisely.
<do action=list listtype=add db=user> |
outputs the input form of the database user.
<do action=list listtype=all db=user> |
outputs everything in the database user (form, tabs, search, content)
<do action=list listtype=list db=user> |
outputs only the content of the database user.
<do action=list listtype=search db=user> |
outputs the search form of the database user.
Different parameters are possible depending on the list type.
A complete template with a less-structured design, like the one provided with the function all, could look like this:
<html><head><title>Bug-List</title></head> <body> <do action=input> Do you want to add something? Just go ahead:<p> <do action=list listtype=add><p> <hr size=1><p> The entries:<p> <do action=list listtype=list databack=ffffff spacing=1 gridcolor=808080 dataface=arial datasize=2 listfields=Title,Author,Date,Comments> </body></html> |
A possible Output:
Do you want to add something? Just go ahead: The entries:
|
Although <do action=all> or <do action=list> provides you with a lot of features, in many cases you probably won't be satisfied with the way the output is standardised. If you want to define the output of the fields yourself, loop enables you to do that. It will go through all entries of a database and provide all fields as variables for each column.
Definition:
<loop[Parameter]> ...[$Fieldname]... </loop> |
Example:
<b>Latest News:</b> <loop db=news sort=-> <h3><a href="$URL">$Title</a></h3> <ul>$Text</ul> <i>by $Author</i> <p> </loop> |
This example could be part of an editorial system: loop runs through all entries of the database news. Since no field was specified for sorting, the output will be chronologic - but in reverse order, due to the minus sign which is after the equal sign (sort=-). The latest entries are displayed on the top of the page, which is certainly desirable for a news system.
The variables which have a dollar sign $ before them, correspond, in each case, to the name of a field determined in the database definition (be careful about upper and lower case). If a non-existent fieldname is used, nothing will be added on.
The access to fields such as Price in $ or Question / Answer is a little more difficult, since in these cases names cannot be used as variables. Due to the spaces, and the special characters ($, and / respectively,) a direct query is not possible. Instead, you have to type this:
$_loop{"Price in $"} $_loop{"Question / Answer"} |
And here is a possible output of the news page:
Latest News: Madonna goes South Park
|
(Please note that this is only used as an example and does not reflect reality! ;-) )
This is probably one of the most impressive baseportal features... ;-) What if you need complex functions, like calculations, text manipulation, conditions, or loops? baseportal provides you with a comprehensive, well-established programming language: Perl, which offers everything you would ever need for programming... and more! Variables, loops, conditions, very elaborate text functions, and so on.
baseportal extends Perl with new commands for database access and easier creation of websites.
Using Perl on your page is remarkably easy:
Definition:
<perl[Parameter]> ... </perl> |
Examples:
<b>Times Table:</b><p> <perl> for($i=1; $i<=10; $i++) { out "$i * $i = ",$i*$i,"<br>"; } </perl> |
If you have no programming experience until now, this may seem quite confusing, but do not fret: programming isn't as difficult as it seems. The above program creates a series from 1 to 10 and calculates the result.
And this is how it will look:
Times Table: 1 x 1 = 1 2 x 2 = 4 3 x 3 = 9 4 x 4 = 16 5 x 5 = 25 6 x 6 = 36 7 x 7 = 49 8 x 8 = 64 9 x 9 = 81 10 x 10 = 100 |
Important: Make sure that the output is done by out instead of print, which is how it is usually done in Perl. out completely replaces the function print. Using print is not permitted and will create an error in your programming.
In order to display many lines at the same time, just type this:
out <<EOF; You can write a lot of text... Variables can also be used: $Text As well as empty lines: <b>And, of course, HTML tags!</b> and so on... EOF |
Please note the two less than signs << and the semi-colon ; after the EOF. The second EOF must be completely by itself in one line, without a semicolon after it. Everything between the two EOF's will be output, and the variables will be replaced by their content.
A comprehensive explanation of Perl would exceed the limits of this document, but we invite you to discover the many books that exist about the subject, as well as the instructions that appear on the net.
Query and Fetch Databases | Up |
You may control a wide range of posibilities of baseportal through URL's. In fact, you can use all the parameters that are possible in any template, in URL's as well. Templates have priority over declarations in the URL, meaning that if you have a parameter in a certain template, it will replace the same thing in the URL. When needed, you may reverse this precedence in a template.
Definition:
http://baseportal.com/baseportal[/user/path/template?Parameter] |
Examples:
http://baseportal.com/baseportal |
This will call the baseportal login page. It will ask you for your user id and password, and if both are correct, you'll be able to access your private area.
http://baseportal.com/baseportal/JohnDoe/appointments |
This will call the template appointments of user JohnDoe.
http://baseportal.com/baseportal/JohnDoe/code/complete?db=/JohnDoe/Project1/songs |
This will call the template complete located in the directory code of user JohnDoe The name for the database being used is songs and is located in the directory Project1 (starting from the top level directory).
A parameter set in templates usually replaces a parameter in a URL with the same name. If you do not want this to happen, you have to type a ^ before the equal sign =. This will work with all parameters.
<do action=all db^=test> |
This will set the database to test, if no database was given via the URL
You can query databases in any combination of fields and conditions. For example: Retrieve all entries where the field Name begins with the letter "a" (upper or lower case), the field Sum is less than 100 and the field VIP is the letter x - that's no problem!
Definition:
<field><operator><value>[<conjuncation>...] |
field = name of a field which must be defined in the database
operator = determines the type of match:
Operator | Description |
---|---|
~= | Looks for the beginning of value; ignores upper/lower case |
== | Looks for an exact value; ignores upper/lower case |
~=! | Looks for the beginning of value; pays attention to upper/lower cases |
==! | Looks for an exact value; pays attention to upper/lower cases |
< <= <> >= > | Looks for smaller than, smaller than or equal to, unequal to, greater than or equal to, and greater than values; ignores upper/lower case |
! >=! >! | Looks for smaller than, smaller than or equal to, unequal to, greater than or equal to, and greater than values; pays attention to upper/lower cases |
~<= ~<> ~> | Looks for smaller than or equal to, unequal, and greater than beginning values; ignores upper/lower case |
~<=! ~<>! ~>! | Looks for smaller than or equal to, unequal, and greater than beginning values; pays attention to upper/lower cases |
~< ~>= ~=! | Redundant; same as < >= =! |
value = the value you are looking for.
Some values have special meanings:
Character | Description |
---|---|
* | Matches everything. All entries will be returned, sorted in the given field. |
# | Matches the last entry of the given field, for example, with entries that need to be sorted like "a", "b", "c" , it would be "c". |
? | Matches to any random entry. Possible operators: ==, < and >. |
conjunction = How to join different parts of a result:
Character | Conjunction | Description |
---|---|---|
& | AND | Only the entries that exist in both parts. |
| | OR | All the entries that exist in one or both of both parts. |
° | NOT | Only the entries that exist in the first part, but not in the second. |
Please note: You can only retrieve fields for which you have chosen a sorting technique in the corresponding database definition.
Examples:
Name~=c |
This will return all entries where the field Name starts with "c" (upper or lower case).
Name==andrea |
Returns all entries where the field Name contains the exact name andrea, whether it is in upper or lower case.
Age<30&City==!Boston |
Returns all entries where the field Age is less than 30 AND the field City corresponds exactly to Boston (with upper case B, the rest in lower case).
Profession==Programmer|Profession==Administrator&Zip-Code~=1 |
Returns all the entries where the field Profession contains the value "Programmer" OR "Administrator" AND the field Zip-Code begins with "1".
Title>=!d&Title<!k°Title~=!h |
Returns the entries in which the field Title begins with a lower case "d", "e", "f", "g", "i" or "j".
Id==? |
Returns any random entry.
You can easily use the above queries in a URL:
http://baseportal.com/baseportal/urxi/out1?db=test&Name>t&Street~=crescent+str |
A database output in the template out1 of the user urxi receives all the entries of the database test where the field Name begins with the upper case letter "t" and the field Street with the value "crescent str". Please note that a space is replaced with a plus sign + in an URL.
You can apply the above queries also as parameters for baseportal tags:
<do action=all Category==Thriller or Category==Romance not Language==English and Available==1> |
This will return all entries where the field Category contains the value "Thriller" OR "Romance" AND the field Language is NOT "English" AND the field Avaiable is set to "1". You could leave out the "and", since it is the standard conjunction.
<do action=all Company==Sony Product~=tv> |
This will give you all the entries that contain the value "Sony" in the field Company and that begin with "tv" in the field Product.
Some problems can arise when dealing with a few special characters that are part of a request, for example with the space, since it separates one parameter from another, or also with the "greater than" character > which identifies the end of a tag. Therefore, these special characters that characterize requests, should be dealt with by using a backslash before them:
<loop Name==John\ Doe Age\>21> |
This will return all entries with the Name "John Doe" whose age is greater than 21.
|
Definition:
sort=[-]Field[,[-]Field...] |
You can only sort according to fields which are set to sorting in the database definition. Mind about the difference between a numerical and a lexical sorting:
Number | Text |
---|---|
1 | 1 |
7 | 10 |
10 | 115 |
13 | 13 |
22 | 22 |
76 | 7 |
115 | 76 |
The unusual sequence of the above sorting shows that texts are compared character by character and not have specific values depending on their specific positions, unlike numbers.
Example:
By not setting query conditions, all the data will be sorted chronologically, so the first data which was entered will also be the first one in the order. If you do set query conditions, sorting will be executed in relation to the first field entered:
<do action=all Family_Name~=ba> |
This will sort all the entries in the field Family_Name which begin with "ba" eg: "Backman", "Barber", "Barker", "Baxter", and so on. If the output is required to be sorted by other conditions than the ones stated in the query, you can set it using sort.
<loop Family_Name~=ba sort=First_Name>$Family_Name, $First_Name<br></loop> |
This will output all the entries in the field Family_Name that start with "ba" and will be sorted by First_Name, eg: "Barker, Allison", "Baxter, Bill", "Backman, Christina", "Barber, Dennis" and so on.
|
If you want the data in reverse order, then, all you need to do is put a minus sign - before the field:
This will output all the entries in the field Family_Name which begin with "ba" but, in this case, it will sort the entries in First_Name from "Z" to "A", eg.: "Barber, Dennis", "Backman, Christina", "Baxter, Bill", "Barker, Allison", and so on.
If you just want all the entries in the opposite direction, it's enough to do a "sort=-":
<loop sort=->$Family_Name<br></loop> |
This will output all the entries in reverse chronological order.
You can also do this in conjunction with a query:
<loop Family_Name~=b sort=->$Family_Name<br></loop> |
This will output all the entries that begin with "b" in the field Family_Name in reverse alphabetical order as follows: "Baxter", "Barker", "Barber", "Backman", and so on.
You can also declare more than one field to be sorted. In this case, the first field will be sorted first, the second, next, the third, after that, etc.
<loop Family_Name~=ba sort=Family_Name,First_Name,-Age> $Family_Name, $First_Name ($Age)<br> </loop> |
This will output all the entries in the field Family_Name which begin with "ba", sorted by the fields Family_Name, First_Name and Age, the latter being in reverse order, eg.: "Backman, Christina (35)", "Barber, Dennis (31)","Barber, Dennis (12)", "Barker, Allison (44)", "Barker, Brian (62)", "Baxter, Bill (55)", "Baxter, Bill (28)", and so on.
All of the above examples can also be used in URL, eg:
http://baseportal.com/baseportal/tom/addresses?Family_Name==*&sort=- |
This will sort all the entries in the field Family_Name in reverse order. (This is faster than sort=-Family_Name)
Definition:
range=[-]Start[,Amount] |
This will define how many of the matching entries will be output.
Examples:
<do action=all sort=- range=0,10> |
This will output the 10 most recent entries, beginning with the most recent one.
<do action=all Famliy_Name~=a range=5,4> |
This will output the 5th to the 9th entries in which the field Famliy_Name begins with "a".
<do action=all range=10> |
This will output all the entries starting with the tenth-to-last entry, and going until the end.
<do action=all Famliy_Name==* sort=- range=-20,10> |
This will output 10 of the last 20 entries, sorted by Famliy_Name in reverse order.
All of the above examples can also be used in URL, eg:
http://baseportal.com/baseportal/tom/addresses?Family_Name==*&range=-18 |
This will output the last eighteen entries sorted by Family_Name.
Programming | Up |
baseportal offers special commands to handle databases. This allows records to be called up, added to, changed or deleted. Since these commands are set in Templates, and only you have access to change them, you will always be able to access all of your databases, regardless of the rights set on those databases.
Definition:
get query, database, result; |
All the fields are optional. If you don't enter anything, the parameters from the URL will be used. If these do not exist either, the database with the same name as the template, will be completely read.
query corresponds to a database query by using "loop", "do" or by URL and can be handed over as a string or as a reference to a list.
database indicates the name of the database.
result signifies a "hash" in which a resulting record should be saved; the name of the database is used here as default.
The first matching entry is saved as variables with their respective field names (exactly like loop).
Examples:
get "Client_Number==32631", "addresses"; out "Family_Name: $Family_Name, City: $City, Telephone:$Telephone"; |
This fetches the all the records in the database "addresses" in which the Client_Number has the value "32631", then outputs those first few entries.
With the following, you can easily create a password protected database:
get "User==!$entered_user", "user"; if($Password ne "" && $Password eq $entered_password) { # the output of the actual database # eg. with get_next (see below) } { out "Access Denied!"; } |
This will get the User out of the database user matching to $entered_name (given either through the URL or a form). The value of the field Password will then be compared to $entered_password (given through the URL or a form). When both values match, a database will be accessed, for example. When not, then the message "Access Denied!" will show up on the screen. Please make sure that the database user doesn't have any permissions for others!
To fetch more matching entries, you need another command:
Definition:
get_next Result; |
This fetches the next record from Result and saves it in variables with the respective field name. If Result has no entries, the last database which was called up will be used.
Examples:
get; while (get_next) { out "Name: $Name - Car: $Car<br>"; } |
This will fetch and output all the records of the given database.
get and get_next commands can be interlaced:
get "Id==*", "client"; while (get_next "client") { out "Client: $Name<br>"; get "Name==$Car", "cars"; out "Car: $Name<br>" out "Description: $Description<p>"; } |
In the above statement, there was a relation created between the databases client and cars. Each client record contains an entry in the field car with the type of car they own. This value will be used to retrieve the matching entry in the database cars and to output the description of this car.
You can also save various queries from the same database. The Result parameter serves the function of differentiating these queries:
get "Name~=a", "client"; get "Name~=b", "client", "cwithb"; out "All clients with a:<p>"; while (get_next "client") { out "Client: $Name<br>"; } out "<hr>All clients with b:<p>"; while (get_next "cwithb") { out "Client: $Name<br>"; } |
First, the records which begin with "a" in the database client will be fetched and saved under the same name. Then all the records which begin with "b" will be saved in the result "kwithb". Finally, both results will be output and respectively looped with "get_next".
Adds new records to a database.
Definition:
put values, database; |
All parameters are optional. If there are no parameters, they will be taken from URL or a form.
values itemizes the records to be stored and can be assigned in different forms.
database indicates the name of the database.
Examples:
put ["Name", "Gus Graves", "Car", "BMW"], "client"; |
This creates a new record in the database client. "Gus Graves" is inserted into the field Name and "BMW" is inserted into the field Car. The itemized values alternate quoting the name of the field and the data content to be stored. It is not necessary that all available fields be quoted (this corresponds to a blank field in a form). Furthermore, it doesn't matter in which order the field entries are made (it's also alright to first enter the car, and then the name).
It is also possible to add many records at once simply by repeating a field name which has already been stated:
put ["Name", "Gus Graves", "Car", "BMW", "Name", "Harry Hathaway", "Car", "Volkswagen Golf"], "client"; |
This will create two new data records in the database client. Specifically, one entry under the name "Gus Graves" and the car "BMW" and the other entry under the name "Harry Hathaway" and the car "Volkswagen Golf".
This mode is not particularly convenient for many data records for some reasons: First, it can lead to problems if a field is omitted, and second, the field names must continuously be repeated. It is better to simply use the following:
put { Name = > ["Harry", "Thomas", "Gloria"], Car = > ["Mercedes", undef, "Ford"] }, "client"; |
This will create three new records in the database client: The first entry under the name "Harry", car "Mercedes", entry 2 under the name "Thomas", no entry under car and entry 3 under the name "Gloria", car "Ford".
This modifies or changes existing data records.
Definition:
mod query, value, database |
All fields are optional. If there are no parameters, they will be taken from URL or a form.
query corresponds to the database queries by "get", "loop", or "do".
value are the records to be stored and corresponds to the parameter by "put".
database indicates the name of the database.
Examples:
mod "Name==!Harry", ["Name", "Steven", "Car", "Honda"], "client"; |
This modifies the entry under the name "Harry" in the database client: The field Name gets the new value "Steven" and the field "Car" gets the new value "Honda". If the data record in the query do not match (eg: if the user "Harry" does not exist), then, nothing will happen.
Unspecified fields remain unchanged:
mod "Name==!Gloria", ["Car", "Golf"], "client"; |
This changes the field "Car" of the entry to "Golf" under the name "Gloria" in the database client. The name "Gloria" remains unchanged.
In order to delete a field, an empty string must be entered:
mod "Name==!Gloria", ["Car", ""], "client"; |
This will delete the field Car of the entry under the name "Gloria" in the database client.
Many changes can be made simultaneously:
mod "Id==3 or Id==4 or Id==7", {Name = > [ "Frank", "Thomas", "Carla"], Car = > ["Mercedes", "Chrysler", "Toyota" ] }, "client"; |
This changes the entries with the Id's 3, 4, and 7 of the database client. The entry with the Id 3 will be changed to Name="Frank" and Car="Mercedes", the entry with the Id 4 will be changed to Name="Thomas" and Car="Chrysler". The entry with the Id 4 will be changed to Name="Carla" and Car="Toyota". Please notice the use of the conjuncation or.
When more than one data record applies to the query for the values to be replaced, the values will be used repeatedly:
mod "Name~=s", ["Car", "BMW"], "client";
This will modify the field Car to "BMW" in all entries in the field Name which begin with "s".
Deletes data records in a database.
Definition:
del query, database |
All fields are optional. If there are parameters, they will be taken from URL or a form.
query corresponds to the database queries by "get", "mod", "loop", or "do".
database indicates the name of the database.
Examples:
del "Name==!Harry", "client"; |
This will delete the entry under the name "Harry" in the database client. If this entry does not exist, nothing will happen.
Many entries can be deleted at the same time:
del "Age<18", "client"; |
This will delete all the entries in the database client in which the value of the field Age is less than 18.
do_all generates all the output of the tag <do action=all>. Parameters, as well as additional values which were obtained by links and should remain as is, can be passed on.
Definition:
do_all parameter, values; |
Examples:
do_all "db=addresses maxlistlength=100", "username=sepp", "password"; |
This will output all the database entries in the database addresses. The length of the output list will be limited to 100 characters. The parameter username with the value "sepp" will be passed on, as well as the parameter "password".
You can also use perl code inside the loop tag.
Definition:
<loop code=perl [parameter]> ... </loop> |
Example:
<b>All in upper case. . . </b><p> <loop code=perl> out "Number: ",++$cnt, "<br>"; out "Name: ",uc ($Name), "<br>"; out "Street: ",uc ($Street), "<br>"; out "City: ",uc ($City), "<p>"; </loop> |
The given Perl code execute every entry in the database. The content of the variables will be taken from the respective field-names. Furthermore, we are using a counter variable $cnt which will appear before every entry as a consecutive number. The Perl function uc() changes all the characters into upper case.
This is a possible output:
All in upper case... Number: 1 Name: CHRISTINA RIDER Street: CRESCENT DRIVE 32 City: ST-LOUIS Number: 2 Name: GABRIEL LEXINGTON Street: PARC PLACE 154 City: BOSTON Number: 3 Name: HARRY HATHAWAY Street: BRIDGE STREET EAST 1156 City: NEW YORK |
In baseportal we have to deal with a lot of special characters that come from different languages and standards and have to be dealt with in different ways. As an example, an < in HTML stands for < (less than), and a quotation mark has to be circumscribed with a "
In URLs one must deal with the special characters completely differently. There may not be any blank spaces, instead you must use a + (plus-sign). But what you want to indicate a plus-sign? Then you type: %2b. And the %-sign also has a special meaning, it too has to be coded using %25
Perl or Javascript have different usage for special characters as well.
Therefore, baseportal has prepared a series of conversion routines:
Name | Description |
---|---|
convert_br | changes a newline into the HTML-code <br> |
convert_html | changes &, ", <, > into the HTML counterparts &, ", <, > |
convert_quote | changes quotation marks ", the apostrophe ' and the backslash \ into ", \', and \\. |
convert_url | changes %, \, |, &, ", + into the respective %xx-code, as well as changing the space into a + |
Example:
<do action=input> <loop code=perl> out convert_html($Name)." - " ; out '<a href="/baseportal/name/page&cmd=del&Id=$_id" onclick="return confirm (\'Really delete '.convert_quote($Name).'\')">Delete?</a>'; out "<p>"; </loop> |
Escapes all HTML special characters in the field Name and outputs it along with a "Delete?" link. When you click on this link, a Javascript query appears asking if you really want this action to take place. If the content of the link contains any apostrophes, these will be changed, so that no Javascript error will appear.
Date and Time | Up |
A few thousand years of culture have left their mark: Even though it doesn't seem like it, since we have gotten accustomed to these things, the use of time and date is a complex thing. baseportal tries to let the user feel as little of this complexity as possible, and at the same time leaving all the options open.
The query of the date can be handled in two ways: Query fragments or direct.
There must be an underscore _ right at the beginning, in front of the fieldname, as well as in front of the date fragment (day, month, year, etc.):
_date_year==2000 |
This type of query is mainly to make options available in a form. Here are two examples, one as a search with pop-up menus...
<form action="/baseportal/name/page" method="post" enctype="multipart/form-data"> <select name="_birthday_year~="><option>1960<option>1961<option>1962<option>1963...etc.</select> <select name="_birthday_month~="><option>1<option>2<option>3<option>4...etc.</select> <select name="_birthday_day~="><option>1<option>2<option>3<option>4...etc.</select> </form> |
... or as a search query with text fields:
<form action="/name/page" method="post" enctype="multipart/form-data"> day: <input type=text name"_birthday_day~="> month: <input type=text name"_birthday_month~="> year: <input type=text name"_birthday_year~="> </form> |
If you control the query yourself, by using a loop tag, a "get" command or with a URL, the second type of entry is more user-friendly:
Date==1.3.2000,20:15 |
baseportal is smart enough to recognize the different entries. Here are some examples:
Date | Month | Day | Year | Hour | Minute | Second | |
---|---|---|---|---|---|---|---|
1 June 2002, 23:45.09 | 6 (June) | 1 | 2002 | 23 | 45 | 09 | |
1 December 2002, 23:45 | 12 (December) | 1 | 2002 | 23 | 45 | ||
06.01.02, 1:00 | 6 (June) | 1 | 2002 | 01 | 00 | ||
Mar.5.2000 | 3 (March) | 5 | 2000 | ||||
March 2.01 | 3 (March) | 2 | 2001 | ||||
12:57 | 12 | 57 | |||||
AUGUST.2005 | 8 (August) | 2005 | |||||
3.7 | 3 (March) | 7 | |||||
nov. | 11 (November) | ||||||
10 | 10 |
The punctuation in between is very important: The period "." (which separates the day, month and year, as well as minute and second), the comma "," (which separates date and time), and the colon ":" (which separates the hour and the minute).
The operators ~= and == have the same meaning.
Whereas the < sign works the same way as one would think, the > sign has a different function than the one we would imagine at first glance: The query...
Date>2000 |
...does NOT mean that all entries from (and including) the year 2001 are shown, but rather, only those from the 1st second of the year 2000. To get the entries from and including the year 2001, following query must be made:
Date>=2001 |
With the word "now", the current date can be recalled.
Date>now |
Finds all the entries with a date in the future.
Starting from the current date, you can search for points in time in the past or in the future:
Date>-14 |
Finds all entries, that are 14 days old, at the most.
Date<+24:00 |
Finds all entries that are 24 hours in the future, at the most.
Here too, baseportal recognizes a set of different entries:
Request | Description |
---|---|
-7,3:13.11 | 7 days, 3 hours, 12 minutes, and 11 seconds in the past |
+100 | 100 days in the future |
-14:00 | 14 hours in the past |
+.3153600 | 31536000 seconds in the future (=365 days) |
Again, the characters which separate the information are important: The period"." (separates minutes and seconds) the comma"," (separates day and time) and the colon":" (separates hours and minutes).
Warning: when doing a query which incorporates a + sign with URL, it has to be replaced using %2b, since + in URL stands for a blank space. A complete query using URL could look like this:
http://baseportal.com/baseportal/name/page&date>-10&date<%2b10 |
Queries about the "middle" of a date are not possible, since these are always worked out from the "top". The order is:
Year.Month.Day,Hour:Minute.Second |
In other words, one can't simply enter a month, such as June, and receive all the entered data for June for any year into a "normal" date field. A query like...
Date~=June |
... is possible but will only give entries for June of the current year.
These limitations can be consciously avoided, by defining individual formats.
An individual format can be used for the definition of a date field. The following statement can be made:
Statement | Description |
---|---|
Day | Day of the month (1 to 31) |
Month | Month as a Number (1 to 12) |
MonthName | Name of Month (January until December) |
MonthShort | Name of Month, short (Jan to Dec) |
Year | four-digit Year (1920 to 2019) |
Year2 | two-digit Year (00 to 19) |
Hour | Hour (00 to 23) |
Minute | Minute (00 to 59) |
Second | Second (00 to 59) |
All other characters are shown without change. The format...
Day / MonthName |
... leads to the following two pop-up menus when entering a data record or searching at a later point in time:
But there is another meaning: Since the year is not included in the input format, it is not saved, therefore a query of months can be independent of the year:
Birthday~=April |
Gives us all entries with birthdays in April.
|
As with the data entry, you can also define your own output format for the date fields. The following input is possible:
Input | Meaning |
---|---|
Weekday | Weekday (Monday to Sunday) |
WeekdayShort | Weekday short (Mon to Sun) |
WeekdayNumber | Weekday by number (1 to 7) |
Day | Day of the month (1 to 31) |
Day0 | day preceded by a zero (01 to 31) |
Month | Month as a number (1 to 12) |
Month0 | Month preceded by a zero (01 to 12) |
MonthName | Name of month (January to December) |
MonathNameShort | Name of month, short (Jan to Dec) |
Year | four digit year (1920 to 2019) |
Year2 | two digit year (00 to 19) |
Hour | hour (00 to 23) |
Hour1 | hour without preceding 0 (0 to 23) |
Hour12 | hour „analog" (1 to 12) |
Hour012 | hour „analog" with preceding 0 (01 to 12) |
Minute | minute (00 to 59) |
Minute1 | minute without preceding 0 (0 to 59) |
Second | second (00 to 59) |
Second1 | second without preceding 0 (0 to 59) |
All other characters are displayed without changes. The format...
MonthName Day0, Year (Weekday) |
... would lead to following output:
December 06, 2000 (Wednesday) |
Saving data records with a date is executed similar to the query. Individual date fragments of a row can be entered:
put ["_date_year", "2000", "_date_month", "August"]; |
This type of assignment is mainly in order to make a date entry in a form possible:
<form action="/baseportal/htx=/name?page&cmd=add" method="post" enctype="multipart/form-data"> <select name="_Birthday-year:="> <option>1960<option>1961<option>1962<option>1963...etc.</select> <select name="_Birthday-month:="> <option>1<option>2<option>3<option>4...etc.</select> <select name="_Birthday-day:="> <option>1<option>2<option>3<option>4...etc.</select> </form> |
Or enter the entire datein one shot:
put "Date:=2002-07-01"; |
In order to save the current date, you must use the special value "now":
put "Date:=now"; |
One can also use the date formats in the program code. Baseportal offers the subroutine date:
Date (point of time, format); |
The point of time can be, a) defined as in the query of the date field, b) can be displayed in seconds since the 1.1.1970 (number > 1000000), c) "now" for the current point in time, or d) can be a value from a database.
The format complies with the entry of a definition of the own output format. The line...
out date("2000-02-01", "Weekday, Day. MonthName.Year"); |
...outputs the following:
Tuesday, 1. February.2000 |
Some common formats can be addressed under a unique name:
Output | format |
---|---|
no entry | Day.Month.Year, Hour:Minute |
long | Weekday, Day.MonthName.Year, Hour:Minute |
short | Day.Month.Year2, Hour:Minute |
internal | Year.Month0.Day0,Hour:Minute.Second#WeekdayNumber |
Here too the entry "now" can be used for the current point in time...
out date("now", "long"); |
...results in the following output
Friday, 8. December.2000, 17:03 |
The relative entries can be displayed as well:
out date ("+10"); |
...displays the date in ten days in the standard format Day.Month.Year, Hour:Minute.
If you want to output a date from a database in a different format, set the variable, in which the date is saved, to point of time:
out date($Date, "short"); |
In this example the date comes from the field "Date" in the database. The output results as Day.Month.Year2, Hour:Minute
If you want to compare a date in the database with the current date, this can be achieved by using the command:
if($Date lt date ("now", "internal")) { ... } |
The saved date comes from the field Date and shall be smaller than the present date. Since the date in the $Date field is unformatted, if you fetched it with the get command, the present date must also be in the internal format.
A date can only be compared by using text comparison.
The comparison can also be made using a while... loop in perl. Since loop converts the $Date in the right format automatically, the hash %_raw must be used in order to enable a comparison.
<loop code=perl> if($_raw(date) lt date ("now", "internal")) { ... } </loop> |
Miscellaneous | Up |
In every programming language there are certain characters that have special meanings. In this document we have already gotten to know the $ - it is not displayed at it is, but is found in front of variables.
But what if, instead of the contents of the variable test you want to output $test, meaning: a $ followed by test? It is necessary to mask the $, so it will be displayed in its normal form. Like in in Perl. this is achieved with the \-character, also known as backslash, or escape-character:
Value of \$test:$test |
Assuming the variable $test contains the text "Hello", then the following is written:
Value of $test: Hello |
Sometimes a character has an unexpected special meaning, like, for example a space. When using the tag...
<do action=all Name~=a lifefields=Name,Street> |
the space acts as the separation between parameters. If you now want to use a field that has one or more spaces, the \-character is needed:
<do action=all Name\ or\ firm~=a listfields=Name\ or\ firm,Street> |
Variables are "placeholders" for values and are used in many programming languages. Simple variables start with the $-character and then continue with a letter, followed by more letters, numbers, or underscores (Examples: $text, $my_name, $urx_123). The contents of variables can be arbitrarily long, and consist of numbers, texts, or any other characters.
The parameters entered by URL or a baseportal tag, are automatically made accessible as variables.
Examples:
<perl> out "Counter: $cnt<p>"; $cnt++; out '<a href="/cgi-bin/baseportal.pl?htx=/counter&cnt='.$cnt.'">continue</a>'; </perl> |
This code functions as a counter. Every click on continue raises the number by 1. This happens because of the variable $cnt, whose value is passed on by the parameters in URL and is then accessible in the template.
Using variables is a smart thing to do to adapt individual text or code blocks:
<font face=arial,helvetica color=red size=4><b>$text</b></font> |
The variable $text is now substituted by the current value. Assuming that the above stated lines are saved as the template Title, then incliuding the template in another side using
<include src=title text=introduction> |
...leads to following output:
Introduction |
baseportal offers a set of values in special variables. These always begin with an underscore _. Although it is possible, avoid own variables starting with an underscore.
Database query
Name | Description |
---|---|
$_db | Name of the Databank last used |
$_range | Start of the range of output |
$_range_length | Amount of the range of output |
$_amount | Amount of records, that were fetched with the last query |
$_amount_query | Amount of records that would have been fetched with the last query without a range |
$_amount_all | Amount of total records that are contained in the last used database. |
Parameters and output values
Name | Description |
---|---|
%_cgi | Values that were transferred with CGI (GET or POST) using "=" (e.g. Color=red) |
%_get | Values that were placed in tags, transferred with CGI or used in a database query (eg. Color=red) |
%_sel | Values of a query (e.g. Name==a) |
%_put | Values to be written (e.g. Name:=Harry) |
With the associated arrays ("hashes") %_cgi and %_get you can retrieve parameters that aren't accessible with normal variables, because they contain invalid characters (e.g. spaces, special characters, etc.) or because they were overridden with other variables. Examples: $_get{"my name"}; $cgi{"12345"};
Design:
Parameter | Description | Default |
---|---|---|
border=<number> | Thickness of table border | 0 |
gridcolor=<color>/- | Color of table grid | f0f0f0 (use - to clear default value) |
padding=<number> | Distance of table content : border | 4 |
spacing=<number> | Thickness of table grid | 2 |
dataface=<font> | Text font of a data field | |
datacolor=<color> | Text color of a data field | |
datasize=<number> | Text size of a data field | |
databack=<color> | Background color of a data field | d0d0d0 (use - to clear default value) |
dataalign=left/middle/right | Alignment of a data field | |
headface=<font> | Text font of the field name | (Default = Value of dataface) |
headcolor=<color> | Text color of a field name | (Default = Value of datacolor) |
headsize=<number> | Text size of a field name | (Default = Value of datasize) |
headback=<color> | Background color of a field name | d0d0f0 (use - to clear default value) |
headalign=left/middle/right | Alignment of a field name |
sort and range:
Parameter | Description |
---|---|
<field>==* | Sort according to field |
sort=- | Reverse order |
sort=<(-)field1,(-)field2,...> | Sort according to field1, then field2... (- = reverse order) |
showsort=<field1,field2,.../*> | Fieldnames with a link to sort (*=all fields, that are sorted) |
range=(-)<start>(,<amount>) | From start (when using - fetch from the end), Amount (or to the end if omitted) |
Browse:
Parameter | Description |
---|---|
showamount=no/all/sel/all,sel | Amount of matching entries: Do not show / On total, not on a selection / On a selection, not on total / Display selection, total |
selectbrowse=no/top/bottom | (All, New, Detail, ...) No / Top / Bottom / Top and bottom |
buttonbrowse=no/top/bottom | (>, >>...) No / Top / Bottom / Top and bottom |
pagebrowse=no/(0)top/bottom/top,bottom | (1, 21, etc.) with menu bar / (0 in the beginning=start menu bar with 0), Menu bar at the top, Menu bar at the bottom / Top and bottom |
indexfield=<field> | No menu bar for fields / According to field (if it is an option field, then use values, if not: a,b,c,...z) |
indexbrowse=no/top/bottom |
Output:
Parameter | Description |
---|---|
listfields=<(-)field1,field2,field3..>/#<amount> | Fields that should appear in the specified order of the list output (or by using - those that should not appear) #<amount>=max. number of fields |
allfields=<(-)field1,field2,field3..>/#<amount> | Fields, that should appear in the specified order of the detailed output (or by using - those that should not appear) #<amount>=max. number of fields |
formfields=<(-)field1,field2,field3..>/#<amount> | Fields, that should appear in the specified order of the entry form (or using - those that should not appear) #<amount>=max. number of fields |
searchfields=<(-)field1,field2,field3..>/#<amount> | Fields, that should appear in the specified order of the search form (or by using - those that should not appear) #<amount>=max. number of fields |
keyfields=<field> | Field that should link to the detailed output (default=first field) |
listtype=list/all/add/search | Type of output |
tdparam=<html-code> | Supplement to the table cells <td> (e.g. with "nowrap" - no word wrap) |
detail=no/link/linktop/linkbottom/top/bottom | Detailed output: Not possible/After link alone,top,bottom/Top/Bottom |
search=no/link/linktop/linkbottom/top/bottom | Search output: Not possible/After link alone,top,bottom/Top/Bottom |
input=no/link/linktop/linkbottom/top/bottom | Entry form: Not possible/After link alone,top,bottom/Top/Bottom |
maxlistlength=0/<number> | Maximum length of text of the list output. Linebreaks are not converted. 0=Do not convert linebreaks, Length unlimited |
convert_br=<field1,field2...>/- | Fields, in which linebreaks are converted to <br> -=No field (without a default: All fields) |
convert_html=<field1,field2...>/* | Fields, in which HTML is converted into the HTML substitutions *=All fields |
convert_quote=<field1,field2...>/* | Fields, in which ", ' and \ are converted *=All fields |
convert_html=<field1,field2...>/* | Fields, that are converted for a URL query *=All fields |
language=en/de/es/fr/pl/it/tr/el/no/ja/ko/zh/id/sr/ca | Outputs texts in English, German, Spanish, French, Polish, Italian, Turkish, Greek, Norwegian, Japanese, Korean, Chinese, Indonesian, Serbian, Catalan (Default=in English) |
Query:
Parameter | Description |
---|---|
db=database | Database to work with |
htx=template | Output template |
Examples | Up |
In some special cases, it is necessary to have the baseportal form available on the homepage (e.g. for a voting system). For the data you want to query, you use the names of the fields defined in the database. The following style is used. Observe the := characters after the field name. The hidden fields are absolutely necessary, so that all browsers can access it.
<form action="/baseportal/YourName/Directory/Template" method="post" enctype="multipart/form-data"> <input type="hidden"name="cmd="value="add"> <input type="hidden"name="htx=" value="/YourName/Directory/Template"> |
Now use the field names depending on the database:
Please enter your first name: <input type="text" name="firstname:="><p> Please enter your last name: <input type="text" name="lastname:="><p> <input type="submit" value="send"> </form> |
The data is now sent to the template. In order to save it in the database
<do action=input> |
must be used. Example:
<html> <head></head> <body> <do action=input> <p>Thank you for your entry...</p> <body> </html> |
If all the entries should be output, use the following:
<html> <head></head> <body> <do action=input> <do action=list listtype=list> <body> </html> |
When you have created an output page for yourself (without <do action=all...), and control the amount of records for the output with range=x,y, you also need links for browsing in order to fetch the next records.
Insert this code in your template:
<perl> my $newrange=$_range+$_range_length; my $oldrange=$_range-$_range_length; $oldrange=0 if $oldrange<0 && $oldrange>-$_range_length; out "<< <a href=\"$_link&range=$oldrange,$_range_length\">Back</a> " if $oldrange>=0; out "<a href=\"$_link&range=$newrange,$_range_length\">Forward</a> >>" if $newrange<$_amount_query; </perl> |
Depending on the amount of actual fetched records the following will appear:
In order to have a better overview of the list output, it is a good idea to switch the background color in every line. Here, we use the internal counter 17.
<table cellpadding=2 border=1 cellspacing=0> <tr><td><b>Name</b></td><td><b>Age</b></td></tr> <loop code=perl> if($_loop % 2==0) { out '<tr bgcolor="#a0a0a0">'; } else { out '<tr bgcolor="#e0e0e0">'; } out "<td>$name</td><td>$alter</td></tr>"; </loop> </table> |
This code will lead to following output:
Name | Alter |
Bill Gates | 45? |
Madonna | Too old |
Liz Taylor | Doesn't tell |
Britney Spears | 18 |
Often times, it is important to know the exact amount of records in a database. You only need to insert one line of perl code, then you could use the variable $_amount_all:
<perl> init "dbname"; </perl> In this database there are $_amount_all entries. |
You only have to change dbname to the name of your database.
© baseportal.com. All rights reserved. Terms of use |