GenieInterface class
This class extends the GenieDataReader class and acts as an decorator to the main php code and the database reader. In doing so it adds presentation to the returned data including links and tables. The class also captures the logon information passed as cookies and passes this on to the parent object through its constructor.
Part of GenieInterface.class showing the constructor function
function __construct()
{
$host = $_COOKIE['hostname'];
$user = $_COOKIE['username'];
$pass = $_COOKIE['password'];
parent::__construct($host, $user, $pass);
}
Along with the constructor there are three function listDatabases(), listTables() and listData() each doing what their names suggest; listing databases, tables and the data in the selected table.
Part of GenieInterface.class showing the creation of a link
$newData[] = "<a href=\"\" onClick=\"listData('$link'); return false;\"> $dataLine</a>";
The data returned to the calling application is in the form of lists of data or a table. In the case of the lists they are in the form of HTML links, however the links have no destination and rely on javascript commands in the onClick event, for the user's selection.
Full source code for GenieInterface.class
<?php
require_once "GenieDataReader.class";
class GenieInterface extends GenieDataReader{
function __construct()
{
$host = $_COOKIE['hostname'];
$user = $_COOKIE['username'];
$pass = $_COOKIE['password'];
parent::__construct($host, $user, $pass);
}
function listDatabases()
{
$data = parent::listDatabases();
foreach($data as $dataLine)
{
$newData[] = "<a href=\"\" onClick=\"listTables('$dataLine'); return false;\">"
. $dataLine . "</a>";
}
return $newData;
}
function listTables($database)
{
if($data = parent::listTables($database))
{
foreach($data as $dataLine)
{
$link = $database . "." . $dataLine;
$newData[] = "<a href=\"\" onClick=\"listData('$link'); return false;\">"
. $dataLine . "</a>";
}
return $newData;
}
}
function listData($dataLine)
{
list($database, $table) = explode(".", $dataLine, 2);
$data = parent::listData($database, $table);
$newData = "<table style=\"border-style: solid\"><tr>";
foreach ($data['titles'] as $title)
{
$newData .= "<td style=\"font-weight: bold; border-style: solid \"><label>"
. $title . "</label></td>";
}
$newData .= "</tr>";
if($data['rows'])
{
foreach ($data['rows'] as $rows)
{
$newData .= "<tr>";
foreach($rows as $row)
{
$newData .= "<td style=\"border-style: solid \">"
. htmlEntities($row) . "</td>";
}
$newData .= "</tr>";
}
}
$newData .= "</table>";
return $newData;
}
}
?>


