---------CMSClass.php----------------
getPageContent
\n");
$content = $pageDB->getPageContent( $page );
echo ("called pageDB->getPageContent
\n");
if ($content == null){
$error = true;
return $content;
}
else
{
$error = false;
return $content;
}
}
}
function setPageContent( $page, $content, &$error){
if ( (!isset( $page )) or (!isset( $content ))){
$error=true;
return 'Error setPageContent() pageid or content not set';
}
else{
$result = $pageDB->setPageContent($page, $content);
if ( !$result == 'DB_OK' ){
$error = true;
return null;
}
else{
$error = false;
return;
}
}
}
}
echo ("Creating CMSClass() in file CMSClass.php
\n");
$CMS = new CMSClass();
?>
-------contentdb.php-----------
\n");
$this->conn =& DB::connect( $this->dsn );
if (DB::isError( $this->conn )){
$this->connected = false;
$this->error="In constructor error connecting to database";
}
else{
$this->connected = true;
}
echo("Leaving contentdb constructor
\n");
}
/**
*Takes a page identifier and returns the content for
*that page
*/
function getPageContent( $page ){
if (!isset( $page )){
$this->error = "Error a page id was not provided to getPageContent()";
return null;
}
if ( $this->connected==false ){
return null;
}
else{
$stmt = 'SELECT content FROM pages WHERE pageid='.$page;
$result =& $this->conn->query( $stmt );
if ( DB::isError( $result )){
$this->error = $this->conn->getMessage();
return null;
}
else{
//Everything seemed to go OK return the content
//TODO not sure i can return the data like this yet??
//TODO what happens if no records
if ( $result->numRows() == 0 ){
return "vsCMS No Content yet...";
}
else{
$rwo = $result->fetchRow();
$content = $row[0];
$result->free();
echo ('About to return');
return $content;
}
}
}
}
/**
*Takes an identifier and content and writes the
*content to the database returns null on error
*and DB_OK on success.
*/
function setPageContent( $page, $content ){
if ( !(isset( $page ) and isset( $content ))){
$error = "Error setPageContent called either ".
"without a pageid or content";
return null;
}
if ( $connected == false ){
$error = "Error Not connected to a database";
return null;
}
else{
if (pageidexist($page)){
//Page id exists so we are doing an update
$stmt = 'UPDATE pages SET content='.$content.
'WHERE pageid='.$page;
$result =& $conn->query( $stmt );
if ( DB::isError( $result )){
$error = $conn->getMessage();
$result->free();
return null;
}
else{
$result->free();
return 'DB_OK';
}
}
else{
//Page id does not exist lets insert it
$stmt = 'INSERT INTO pages (pageid, content) '.
'VALUES ('.$page.', '.$content.')';
$result =& $conn->query( $stmt );
if ( DB::isError( $result )){
$error = $conn->getMessage();
$result->free();
return null;
}
else{
$result->free();
return 'DB_OK';
}
}
}
}
/**
*Returns boolean true if the page id is already used
*and returns false if not. Also returns null on error.
*/
function pageidexist( $page ){
if ( !isset( $page )){
$error="Error pageidexist() called without page";
return null;
}
if ( $connected == false ){
$error = "Error Not connected to a database";
return null;
}
else{
$stmt='SELECT pageid FROM pages WHERE '.
'pageid='.$pageid;
$result =& $conn->query( $stmt );
if ( DB::isError( $result )){
$error = $conn->getMessage();
$result->free();
return null;
}
if ( $result->numRows() > 0 ){
$result->free();
return true;
}
else{
return false;
}
}
}
}
//Create pageDB object for use after file has been included.
echo ("About to create pageDB in file contentdb.php
\n");
$pageDB = new contentdb();
//Basic error check
if ( $pageDB->connected == false ){
echo "Error Connecting to Database";
}
else
{
echo ( "pageDB exists fine here?
");
}
?>
The main file where i call the function getPageContent() in CMSclass.php contains the following
include( "CMSClass.php" );
//This section of code attempts to fetch the pages content
//from the CMS system, by including the CMSClass.php file
//at the top of this file we create a CMS object we can acces
//via $CMS
echo ("About to call CMS->getPageContent
\n");
$myContent = $CMS->getPageContent('index_php', $error);
if ( $error == true ){
echo('