Chapter 3. PHP-Code

This chapter deals with the PHP-Code of the template-files of Layout Standard. While probably not that many people have Delphi or Kylix installed. the PHP-source-code will hopefully interest more people. Moreover it is necessary to include the PHP-soure in every binary distribution whereas this is not necessary for the Delphi/Kylix code of the program.

You can find all of the PHP-source files in Data/Plugins/SimpleWebFront/Standard.

You should already know that there are four PHP source-files, each one responsible for one specific webpage. (indexpage, Grid-View, Insert and Update-Popup Windows) The file commonFunctions.php contains common functions that are used in several of the other files.

Moreover you should know that the PHP-files are pretty much self-contained. One could say that the interface to the SWF-program consists only of string patterns of the form /*[[PATTERN]]*/. The SWF replaces these patterns in the process of creating the webpages. What follows now is a list of all supported patterns for each of the files.

Table 3-1. Patterns replaced in index.php:

PatternDescriptionExample
/*[[HEADING]]*/The heading of the index-page. This is the Web-Title that the user enters."Bookshop";
/*[[IMAGE_NAMES]]*/Will be expanded to an associative array that lists the filename of the icon for each view.array ( "Tables.Customer"=>"icons_02.png","Tables.Publisher"=>"icons_04.png");
/*[[INDEX]]*/Replaced by function calls to the php-function displayGroup for each group. These function calls are put inside html-tables so that the group position is as specified by the user. <table border="0"><tr><td> <?php displayGroup("Tables",array( "Customer"=>"Tables_Customer.php?page=0&mode=normal","Publisher"=>"Tables_Publisher.php?page=0&mode=normal") ); ?> </td></tr></table>

Table 3-2. Patterns replaced in gridTemplate.php:

PatternDescriptionExample
/*[[VIEWNAME]]*/The name that will appear as heading."Book";
/*[[FILENAME]]*/The name of the current file.standard_book.php
/*[[TABLENAME]]*//The name of the Main-Table.book
/*[[DATATYPES]]*/maintains a column=>Datatype mapping for every column of the mainTablearray("name"=>"INTEGER",...)
/*[[TABLEKEY]]*/an array that contains the name of all columns that make up the primary key of the maintablearray("product_id")
/*[[TABLEDISPCOLS]]*/an array that contains the name of all columns that should be displayedarray("product_id", "name","desc")
/*[[JOINTABLENAMES]]*/A normal(numeral) array that lists the names of all Lookup-Tablesarray('testTable1', 'testTable2')
/*[[JOINTABLES_KEY]]*/For each joinTable present in $joinTablenames this associative array keeps an array with the column-names of the keyarray ("product" => array ("productId"), "testTable" => array("Key_part1","Key_part2"))
/*[[JOINTABLES_DISPCOLS]]*/For each joinTable present in $joinTablenames this associative array keeps an array with the names of all columns that should get displayes array( "testTable1" => array( "testTable1Id","comment"), "testTable2" => array( "col1","col2","col3"))
/*[[NMTABLENAMES]]*/A normal(numeral) array that lists the names of all NM-Tablesarray('testTable1', 'testTable2')
/*[[NMTABLES_KEY]]*/For each nmTable present in $joinTablenames this associative array keeps an array with the column-names of the keyarray ("product" => array ("productId"), "testTable" => array("Key_part1","Key_part2"))
/*[[NMTABLES_DISPCOLS]]*/For each nmTable present in $joinTablenames this associative array keeps an array with the names of all columns that should get displayesarray( "testTable1" => array( "testTable1Id","comment"), "testTable2" => array( "col1","col2","col3"))
/*[[NMTABLES_DATATYPES]]*/For each nmTable present in $joinTablenames this associative array keeps an (again associative) array that has the form column=>Datatypearray ("customer" => array ("customerId"=> "INTEGER","Name"=> "VARCHAR"))
/*[[CONNECTIONTABLENAMES]]*/A normal(numeral) array that lists the names of all connection-Tables (tables that are introduced to realize an n:m relationship)array('testTable1', 'testTable2')
/*[[WHERE_CONSTRAINT]]*/The whereConstraint that the user has entered;doesn't begin with WHEREbook.isbn="08850238"
/*[[ROWSPERPAGE]]*/the number of data tuples to be shown on a page20
/*[[GRID_AS_POPUP]]*/a boolean value that tells us if this (grid-)window is shown as a popup or nottrue
/*[[FORMHEIGHT]]*/, /*[[FORMWIDTH]]*/,/*[[FORMX]]*/,/*[[FORMY]]*/the dimensions of the update and insert-window500
/*[[COLUMN_CAPTIONS]]*/An array describing the (user-defined) captions of all columns that will shown to the user instead of the db-names. The qualified db column-name is used to index the arrayarray('product.Name' => 'Name',...)
/*[[COLUMN_WIDTHS]]*/An associative array that lists all columns that have a width specified with their respective width-values in pixels.The qualified db column-name is used to index the arrayarray("testTable1.column1" => 55)
/*[[COLUMN_TRUNCATE_CHARS]]*/An associative array that stores all columns that should truncate their contents to a specified number of characters;The qualified db column-name is used to index the arrayarray("testTable1.column1" => 5)
/*[[KEY_MAPPING]]*/This array stores a mapping of qualified column names to the (qualified) column names they reference. Consequently the index consists only of qualified foreign keynames; their value denotes the column they are refering to;array ( "Book.Publisher_idPublisher"=>"Publisher.idPublisher")

Table 3-3. Patterns replaced in updateTemplate.php and insertTemplate.php:

PatternDescriptionExample
/*[[TABLENAME]]*//The name of the Main-Table.book
/*[[DATATYPES]]*/maintains a column=>Datatype mapping for every column of the mainTablearray("name"=>"INTEGER",...)
/*[[TABLEKEY]]*/an array that contains the name of all columns that make up the primary key of the maintablearray("product_id")
/*[[TABLEDISPCOLS]]*/an array that contains the name of all columns that should be displayedarray("product_id", "name","desc")
/*[[JOINTABLENAMES]]*/A normal(numeral) array that lists the names of all Lookup-Tablesarray('testTable1', 'testTable2')
/*[[JOINTABLES_KEY]]*/For each joinTable present in $joinTablenames this associative array keeps an array with the column-names of the keyarray ("product" => array ("productId"), "testTable" => array("Key_part1","Key_part2"))
/*[[JOINTABLES_DISPCOLS]]*/For each joinTable present in $joinTablenames this associative array keeps an array with the names of all columns that should get displayes array( "testTable1" => array( "testTable1Id","comment"), "testTable2" => array( "col1","col2","col3"))
/*[[NMTABLENAMES]]*/A normal(numeral) array that lists the names of all NM-Tablesarray('testTable1', 'testTable2')
/*[[NMTABLES_KEY]]*/For each nmTable present in $joinTablenames this associative array keeps an array with the column-names of the keyarray ("product" => array ("productId"), "testTable" => array("Key_part1","Key_part2"))
/*[[NMTABLES_DISPCOLS]]*/For each nmTable present in $joinTablenames this associative array keeps an array with the names of all columns that should get displayesarray( "testTable1" => array( "testTable1Id","comment"), "testTable2" => array( "col1","col2","col3"))
/*[[NMTABLES_DATATYPES]]*/For each nmTable present in $joinTablenames this associative array keeps an (again associative) array that has the form column=>Datatypearray ("customer" => array ("customerId"=> "INTEGER","Name"=> "VARCHAR"))
/*[[CONNECTIONTABLENAMES]]*/A normal(numeral) array that lists the names of all connection-Tables (tables that are introduced to realize an n:m relationship)array('testTable1', 'testTable2')
/*[[COLUMN_CAPTIONS]]*/An array describing the (user-defined) captions of all columns that will shown to the user instead of the db-names. The qualified db column-name is used to index the arrayarray('product.Name' => 'Name',...)
/*[[COLUMN_WIDTHS]]*/An associative array that lists all columns that have a width specified with their respective width-values in pixels.The qualified db column-name is used to index the arrayarray("testTable1.column1" => 55)
/*[[KEY_MAPPING]]*/This array stores a mapping of qualified column names to the (qualified) column names they reference. Consequently the index consists only of qualified foreign keynames; their value denotes the column they are refering to;array ( "Book.Publisher_idPublisher"=>"Publisher.idPublisher")