Server Setup and Configuration Test
The first thing to test was that the PHP was installed and functioning correctly and that the web server could be reached from the internet. To test the server configuration a test page was created.
The following PHP page was created and connected to in the var\www folder as PHPtest.php.
<?
mysql_connect ("localhost", "testaccount", "password") or die (mysql_error());
echo "Success.. Connected to MySQL...<br />";
mysql_select_db("UG") or die(mysql_error());
echo "Success.. Connected to Database... ";
?>
WinSCP and Expressions Web
WinSCP and Expressions web were configured to write to NAS (network attached storage) that is RAID 1 mirrored to protect against any data loss during the coding of the project. The NAS also has a USB offload to an external hard disk. If there is a hardware failure on the NAS, a backup runs daily to capture any data changes.
The server does not have redundancy on the hard disks so it was an important risk to mitigate.
To mirror the content from the development pages stored on the NAS to the Apache/Ubuntu server, WinSCP was used to transfer content when required. To avoid any code alterations running between the site locally and on the server a new site within Expressions Web was created, this prevents any UNC path change considerations. For example "Z:\..." on the NAS to "/var/www" on the server. Figure 39 shows how the WinSCP client is configured with NAS and remote server drive for simple page uploading.
Figure 39 - WinSCP Client Configured with the NAS and Remote Server Drive
MySQL Database configuration
A new database instance was created in PHP My Admin called UG as shown in the screenshot in Figure 40.
PHP My Admin is a web based frontend for database administration that comes with MySQL.
Figure 40 - Screenshot Displaying the "ug" Database and all Rows from a Table Called "businessroles"
The Business Roles Table and PHP code
The business role page will be created first, as stated in the first development sprint. The table design from the PoC was recreated in MySQL using the following code in PHP My Admin to create a table called "businessroles" and the associated table columns and properties.
SQL Code
CREATE TABLE IF NOT EXISTS `businessroles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`businessrole` text NOT NULL,
`description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
The resulting table is shown in figure 2 however as an empty table without any row entries present.
PHP Code
A basic PHP page was created within the Business_Roles_dev2.php page, one of many development pages leading up to this final version. The page has been purposely left with this name to demonstrate in the conclusions of this project report the learning stages to make this page possible.
The code below provides a breakdown of the PHP code only (separated from the HTML) to make it easier to read. The full code can be found in the subpage to this section here:
<?php
// Connection String to the Userguardian database
mysql_connect("localhost", "ugapp", "_Ugapp_1");
mysql_select_db("ug");
//Uncomment to see values passed for SQL query in $result
//var_dump($_POST);
if (isset($_POST["action"]))
{
switch($_POST["action"])
//
{
case "removeBusinessRoles":
$result = mysql_query("SELECT id, businessrole, description FROM businessroles WHERE 1=1;");
//Uncomment to see values passed for SQL query in $result
//var_dump($result);
//echo mysql_error();
if ($result && mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_object($result))
{
if (isset($_POST["businessrole_".$row->id]))
{
// $row->id was selected before submitting the form
mysql_query("DELETE FROM businessroles WHERE id=".$row->id.";");
}
}
}
break;
case "addBusinessRoles":
if (isset($_POST["newrole"]))
{
mysql_query("INSERT INTO businessroles VALUES ('','".$_POST["newrole"]."','".$_POST["description"]."');");
}
break;
}
}
function generateHtmlTableBusinessRoles()
{
$htmltablestr = "";
$result = mysql_query("SELECT id, businessrole, description FROM businessroles WHERE 1=1 ORDER BY businessrole;");
if ($result && mysql_num_rows($result) > 0)
{
$htmltablestr .= "<table>";
while ($row = mysql_fetch_object($result))
{
$htmltablestr .= "<tr><td><input type=\"checkbox\" name=\"businessrole_".$row->id."\" value=\"businessrole_".$row->id."\" id=\"businessrole_".$row->id."\" /></td>";
$htmltablestr .= "<td>".$row->businessrole." ".$row->description."</td>";
$htmltablestr .= "</tr>";
}
$htmltablestr .= "</table>";
}
return $htmltablestr;
}
?>
The explanation of the code and decisions leading up to this point can be found in the conclusions Section 6.3 of this website.