The administration interface was built according to the common three-tier model. The model is comprised of three basic components:
- Presentation tier (web browser)
- Business logic tier (web server + server-side processing)
- Services tier (database or other back-end services)
The tiers are independent and only communicate to the adjacent tier. Physically the business logic and services tier can run on the same server, but as independent application processes. The browser communicates to the web server through a network, such as the Internet or a local area network. The flow of a typical web application:
- The browser sends a request
- The web server receives the request and starts processing
- The server-side process requests data from the database
- The database returns the requested data
- The web server returns the processed data to the browser
The presentation tier
In the case of web applications, browsers send a HTTP request to the web server, which returns a XHTML file. The file contains the data as well as additional layout information. The browser renders the received file and outputs the data. This is usually done by displaying it on a computer screen, but browsers for the hearing impaired, for example, output it as speech.
The presentation layer of the Marmalade 1.0 system was built using standard XHTML and an external CSS file. The CSS file is used to set the appearance of XHTML documents. Since the interface has a default layout, the business logic tier was built to use a template file for producing the XHTML output. The template file contains calls for content output functions. An example is shown in Example 2.
!-- primary navigation --
Example 2 – Writing the primary navigation to the template by calling the function
By utilizing a template-based business logic tier and external style sheets the layout of the application can be changed conveniently. By modifying the template and the CSS file, each page in the system is affected.
Modern browsers allow applying a different style sheet for a page when the page is printed. An example of a printed bug report page is shown in APPENDIX A.
The business logic tier
The business logic tier comprises the Apache web server and PHP scripting language. Once the server has received a request, it is directed to the PHP engine. The engine processes the application and connects to the service tier as needed. Once the processing is completed, the data is sent to the requester.
The system is built using a number of files that have a specific function. The structure of each file (structure shown in APPENDIX F) in the system is identical. The first step in the application is to make sure the user has the right to access the content. This is done by including the ldap.php file. If the user is not valid or has not yet logged onto the system writes a login form and stops the execution.
If the user is valid and execution is not aborted, the system fetches the config.php file that holds basic system parameters such as the database access details and the base URL of the system. The next step is to include the functions.php file. This file holds the functions for writing the navigation and other standard elements that are processed similarly from page to page.
The write_content function is unique to each page and is used to generate the data to be displayed on the content area. This function typically contains calls to the database according to the parameters given in the URL. The write_content function is called in the template file. The final step is including the template file. The functions called in the template file are executed and appropriate output is generated.
The typical function for a page is to view data. The todo.php, for example, has more functions as users can add and delete items. The identifying of different functions is done by using switch cases. Switch cases allow the program to leap to a certain location in the program code according to a parameter. In the Marmalade system the parameter used for switching is given by the value of the XHTML submit element.
An example of the basic structure of a page in the application is shown in Example 3.
<?php
require_once("./ldap.php");
require_once("./config.php");
require_once("./functions.php");
switch ($GLOBALS[submit]){
default:
// write_content function (called in template)
function write_content(){
##################################### ## # GENERATE AND OUTPUT APPROPRIATE CONTENT # ##
}
include("./templates/default.php");
break; case delete:
##################################### ## # ERASE SELECTED CONTENT AND REDIRECT # ##
break; } ?>
Example 3 – The basic program structure
The services tier
The Marmalade 1.0 system connects two separate services: The MySQL database server The LDAP server
The business logic tier communicates with the MySQL database Structured Query Language (SQL). SQL is a standard syntax for adding, removing and displaying the data in a database. PHP has built in functions for connecting to MySQL databases. An extract of a business logic tier content write function is shown in Example 4.
$select = "
SELECT id, title, description
FROM projects
ORDER BY id DESC
";
$result = mysql_query($select);
while ($dataColumn = mysql_fetch_array($result)) {
extract ( $dataColumn );
############################################# ## # WRITE A ROW OF DATA (ID, TITLE AND DESCRIPTION) # ##
}
Example 4 - Getting data from MySQL using a while loop
The LDAP authentication used by the system was provided through an existing authentication module. This module handles the configuration and connection to the LDAP service. The authentication is implemented by integrating the ready-made module to the flow of the server-application (shown in Example 3). A basic example for testing the LDAP authentication is shown in Example 5.
<?php
require_once("auth_ldap_config.php");
require_once("auth_ldap_functions.php");
$user = "user";
$pass = "password";
if(pwpadm_auth_from_ldap($user,$pass)) {
echo "Authentication ok";
} else {
echo "Authentication failed";
}
?>
Example 5 – Basic LDAP authentication