function saveContent($nodeID, $languageID, $notes, $noCache, $entityArray, $sectionInstances)
 {
     // Returned by the insert - TODO remove?
     $contentID = 0;
     $createdBy = 0;
     $created = 0;
     $userID = $_SESSION['userID'];
     // Stores the content to the DB
     $db = DBCxn::Get();
     // TO DO Validate that the user has access to this node?
     try {
         $db->beginTransaction();
         // 1A. get the last versionID and template (perhaps this is changeable?)
         $sql = "SELECT version AS versionID, created, createdBy  \n\t\t\t\t\t\t\tFROM `cms_content` AS c \n\t\t\t\t\t\t\tWHERE c.nodeID = :nodeID\n\t\t\t\t\t\t\tAND c.languageID = :languageID\n\t\t\t\t\t\t\tORDER BY ID DESC\t\t\n\t\t\t\t\t\t\tLIMIT 1\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t;";
         $query = $db->prepare($sql);
         $query->bindParam(':nodeID', $nodeID, PDO::PARAM_INT);
         $query->bindParam(':languageID', $languageID, PDO::PARAM_INT);
         $query->execute();
         // If we have a row
         if ($query->rowCount() != 0) {
             $result = $query->fetch();
             $version = $result['versionID'] + 1;
             $created = $result['created'];
             $createdBy = $result['createdBy'];
         } else {
             // new
             $version = 1;
             $createdBy = $userID;
         }
         // 1B. get the templateID (perhaps this is changeable?)
         $sql = "SELECT templateID  \n\t\t\t\t\t\t\tFROM `cms_content` AS c \n\t\t\t\t\t\t\tWHERE c.nodeID = :nodeID\n\t\t\t\t\t\t\tORDER BY ID DESC\t\t\n\t\t\t\t\t\t\tLIMIT 1\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t;";
         $query = $db->prepare($sql);
         $query->bindParam(':nodeID', $nodeID, PDO::PARAM_INT);
         $query->execute();
         // If we have a row
         if ($query->rowCount() != 0) {
             $result = $query->fetch();
             $templateID = $result['templateID'];
             // TO DO actually get this from the admin interface?! Is it possible to change this ever?
         } else {
             // TO DO -- I'm guessing this would be new content. Check that this is right? TemplateID would then be passed in by the admin interface?
             // error_log('getting here: nodeID = ' . $nodeID);
         }
         // 2a - set the published flag to false on all other content entries
         // TO DO - eventually the publish and save functions will be separate so this will need to be moved to the publish event
         $query = $db->prepare("UPDATE cms_content \n\t\t\t\t\t\t\t\t\tSET published = 0 \n\t\t\t\t\t\t\t\t\tWHERE nodeID = :nodeID AND languageID = :languageID\n\t\t\t\t\t\t\t\t\t;");
         $query->bindParam(':nodeID', $nodeID, PDO::PARAM_INT);
         $query->bindParam(':languageID', $languageID, PDO::PARAM_INT);
         $query->execute();
         // 2b. - get the parent node IDs to reduce load on page loads we store a comma separated list against the content of what the page path in node IDs are (for main nav etc to look up the tree)
         $this->parentIDs = implode(', ', $this->getParentNodes($nodeID));
         // 2c. - store the record in the content table to get a contentID for later use
         // TO DO published is always true ATM
         $query = $db->prepare("INSERT INTO cms_content (nodeID, version, created, createdBy, lastUpdated, lastUpdatedBy, notes, templateID, published, languageID, noCache, parentIDs) \n\t\t\t\t\t\t\t\t\tVALUES (:nodeID, :version, :created, :createdBy, NOW(), :lastUpdatedBy, :notes, :templateID, TRUE, :languageID, :noCache, :parentIDs)\n\t\t\t\t\t\t\t\t\t;");
         $query->bindParam(':nodeID', $nodeID, PDO::PARAM_INT);
         $query->bindParam(':version', $version, PDO::PARAM_INT);
         $query->bindParam(':created', $created, PDO::PARAM_STR);
         $query->bindParam(':createdBy', $createdBy, PDO::PARAM_INT);
         $query->bindParam(':lastUpdatedBy', $userID, PDO::PARAM_INT);
         $query->bindParam(':notes', $notes, PDO::PARAM_STR);
         $query->bindParam(':templateID', $templateID, PDO::PARAM_INT);
         $query->bindParam(':languageID', $languageID, PDO::PARAM_INT);
         $query->bindParam(':noCache', $noCache, PDO::PARAM_INT);
         $query->bindParam(':parentIDs', $this->parentIDs, PDO::PARAM_STR);
         $query->execute();
         $contentID = $db->lastInsertId();
         // 3. get the template - so we know where to store the content to
         self::getTemplate($nodeID, $languageID);
         // 4 Store the content
         // 4a - Loop through the section instances (with sort order) and store these to the table with the content ID and get hte new Section Instance ID so we know where to store this too later.
         foreach ($sectionInstances as $key => $value) {
             // For each row.. insert and get last insert id and add this to the array
             $query = $db->prepare("INSERT INTO `cms_section_instance`\n\t\t\t\t\t\t\t\t\t\t\t(`contentID`, `sectionID`, `sort_order`) \t\t\t\n\t\t\t\t\t\t\t\t\t\t\tVALUES (:contentID, :sectionID, :sort_order)\n\t\t\t\t\t\t\t\t\t;");
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':sectionID', $value['sectionID'], PDO::PARAM_INT);
             $query->bindParam(':sort_order', $value['sortOrder'], PDO::PARAM_INT);
             //		error_log("INSERTING: contentID: " . $contentID. " sectionID: " . $value['sectionID'] . " sort: " . $value['sortOrder']);
             $query->execute();
             $newSectionInstanceID = $db->lastInsertId();
             $sectionInstances[$key]['newSectionInstanceID'] = $newSectionInstanceID;
         }
         // 4b. match each entity to a type
         $intArray = array();
         $moneyArray = array();
         $shortTextArray = array();
         $longTextArray = array();
         $richTextArray = array();
         $dateArray = array();
         $nodeArray = array();
         $mediaArray = array();
         // used to store any nodes that will need to be pulled back in the content (e.g. referenced in the content pickers)
         $nodeDependencyArray = array();
         foreach ($entityArray as $key => $value) {
             // TO DO - make this generic so that we can map multiple types in some config setting somewhere (or perhaps make that config always
             // choose the raw underlying data type.. probably that.
             $sectionInstanceID = null;
             // look up the new section ID
             if ($value['sectionInstanceID'] !== null) {
                 // find the new ID
                 foreach ($sectionInstances as $siKey => $siValue) {
                     if ($siValue['sectionInstanceID'] === $value['sectionInstanceID']) {
                         //	error_log("Found - " . $siValue['newSectionInstanceID'] . " for : " . $siValue['sectionInstanceID'] . " : " . $value['sectionInstanceID']);
                         $sectionInstanceID = $siValue['newSectionInstanceID'];
                         // break;
                     }
                 }
                 // TO DO handle!
             }
             // Get the entity type by looking it up from the template
             $entityType = false;
             foreach ($this->template as $tkey => $tvalue) {
                 if ($tvalue['entityID'] == $value['entityID']) {
                     $entityType = $tvalue['entity_type'];
                     break;
                 }
             }
             if ($entityType === false) {
                 // Throw exception
                 error_log('Entity ' . $tvalue['entityID'] . ' NOT found in the template');
                 throw new Exception('Entity ' . $tvalue['entityID'] . ' NOT found in the template');
             }
             switch ($entityType) {
                 case 1:
                     $intArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 case 2:
                     $moneyArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 case 3:
                     $shortTextArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 case 4:
                     $longTextArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 case 5:
                     $richTextArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 case 6:
                     $dateArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                 case 7:
                     $dateArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 case 8:
                     // bug with empty newly created fields store " " instead of false
                     $boolValue = 'false';
                     if ($value['value'] == 'true' || $value['value'] == 'TRUE') {
                         $boolValue = true;
                     }
                     $shortTextArray[] = array('entityID' => $value['entityID'], 'value' => $boolValue, 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 case 10:
                     $nodeArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     // decode the JSON and store all nodes to the dependencies
                     // (so that the content is available when the page is built)
                     $jsonObj = json_decode($value['value'], true);
                     foreach ($jsonObj as $key => $node) {
                         $nodeDependencyArray[$node['nodeID']] = $node['nodeID'];
                         if (count($node['children']) > 0) {
                             $this->getChildNodeDependencies($node['children'], $nodeDependencyArray);
                         }
                     }
                     break;
                 case 11:
                     $mediaArray[] = array('entityID' => $value['entityID'], 'value' => $value['value'], 'sectionInstanceID' => $sectionInstanceID);
                     break;
                 default:
                     //  add it to the blob...  TO DO
                     // FOr now just going into long text
             }
             /* for debugging
             			error_log("INT:");
             			error_log(print_r($intArray,1));
             			error_log("MONEY:");
             			error_log(print_r($moneyArray,1));
             			error_log("SHORTTEXT:");
             			error_log(print_r($shortTextArray,1));
             			error_log("LONGTEXT:");
             			error_log(print_r($longTextArray,1)); */
         }
         // 4. store each bit of content data into the relevant table
         // 4.1 // entity_value_int
         // TO DO review duplicate key update here
         foreach ($intArray as $key => $value) {
             $intValue = intval($value['value']);
             //	error_log("key = " . $value['entityID'] . " - " . $value['sectionInstanceID'] . " - Value=: " . $intValue);
             $query = $db->prepare("INSERT INTO cms_entity_value_int \n\t\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\t;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $intValue, PDO::PARAM_INT);
             $query->execute();
         }
         // 4.2 // entity_value_money
         foreach ($moneyArray as $key => $value) {
             //	error_log("key = " . $key . " - " . $value);
             $query = $db->prepare("INSERT INTO cms_entity_value_money \n\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE value=:value;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $value['value'], PDO::PARAM_STR);
             $query->execute();
         }
         // 4.3 // entity_value_shorttext
         foreach ($shortTextArray as $key => $value) {
             //	error_log("key = " . $key . " - " . $value);
             $query = $db->prepare("INSERT INTO cms_entity_value_shorttext \n\t\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE value=:value;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $value['value'], PDO::PARAM_STR, 255);
             $query->execute();
         }
         // 4.4 //	entity_value_longtext
         foreach ($longTextArray as $key => $value) {
             //	error_log("key = " . $key . " - " . $value);
             $query = $db->prepare("INSERT INTO cms_entity_value_longtext \n\t\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE value=:value;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $value['value'], PDO::PARAM_STR);
             $query->execute();
         }
         // 4.5 //	entity_value_richtext stored in longtext
         foreach ($richTextArray as $key => $value) {
             //	error_log("key = " . $key . " - " . $value);
             $query = $db->prepare("INSERT INTO cms_entity_value_longtext \n\t\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE value=:value;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $value['value'], PDO::PARAM_STR);
             $query->execute();
         }
         // 4.6  & 4.7 //	entity_value_date & entity_value_date_time
         foreach ($dateArray as $key => $value) {
             //	error_log("key = " . $key . " - " . $value);
             $query = $db->prepare("INSERT INTO cms_entity_value_date \n\t\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE value=:value;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $value['value'], PDO::PARAM_STR);
             // not sure what to do with blank dates?
             //	if($value['value'] == "0000-00-00 00:00:00" || $value['value'] == "0000-00-00") {
             //		$query->bindValue(':value', null, PDO::PARAM_INT);
             //	} else {
             //		$query->bindParam(':value', $value['value'], PDO::PARAM_STR);
             //	}
             $query->execute();
         }
         // 4.10 //	entity_value_nodepicker JSON
         foreach ($nodeArray as $key => $value) {
             //	error_log("key = " . $key . " - " . $value);
             $query = $db->prepare("INSERT INTO cms_entity_value_longtext\n\t\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE value=:value;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $value['value'], PDO::PARAM_STR);
             $query->execute();
         }
         // 4.11 //	entity_value_media
         foreach ($mediaArray as $key => $value) {
             //	error_log("key = " . $key . " - " . $value);
             $query = $db->prepare("INSERT INTO cms_entity_value_longtext\n\t\t\t\t\t\t\t\t\t\t\t(entityID, contentID, section_instanceID, value) \n\t\t\t\t\t\t\t\t\t\tVALUES (:entityID, :contentID, :section_instanceID, :value)\n\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE value=:value;");
             $query->bindParam(':entityID', $value['entityID'], PDO::PARAM_INT);
             $query->bindParam(':contentID', $contentID, PDO::PARAM_INT);
             $query->bindParam(':section_instanceID', $value['sectionInstanceID'], PDO::PARAM_INT);
             $query->bindParam(':value', $value['value'], PDO::PARAM_STR);
             $query->execute();
         }
         $db->commit();
     } catch (PDOException $e) {
         $db->rollBack();
         error_log("Saving Content failed.\n");
         error_log("getCode: " . $e->getCode() . "\n");
         error_log("getMessage: " . $e->getMessage() . "\n");
         return false;
     }
     // close the conn
     $db = null;
     // update the dependencies table
     $this->updateDependencies($nodeID, $nodeDependencyArray);
     // clear all cache files on publish - quick and dirty
     $cache = new CMSCache();
     $cache->dropAllCache();
     return true;
 }
 function __construct()
 {
     // for the page execution time in the debug.
     $this->time_start = microtime(true);
     $this->requestData = RestUtils::processRequest();
     // get the path array - e.g. /home/about-us/welcome
     $this->pathArray = $this->requestData->getPathArray();
     $this->requestVars = $this->requestData->getRequestVars();
     $this->pageRequested = end($this->pathArray);
     // TO DO - merge in the REST UTILS? It's not rest anymore too!?
     /* 
     1.  First check if we have an entry for the page path 
     2.  If exists then check the cache - TODO
     3.  Otherwise build the page from the DB
     4.  Write this out and add to cache if cacheable - TODO
     
     Creating a page
     1.  Get the template 
     2.  Get all data for the page
     3.  Run it through the template engine
     */
     // 1. Check cache
     if (CACHE_ENABLED) {
         $cache = new CMSCache($this->pathArray);
         if ($cache->inCache) {
             $outputContent = $cache->cacheItem->content;
             $debug = false;
             if (isset($this->requestVars['debug']) && DEBUG) {
                 $debug = TRUE;
             }
             if ($debug === TRUE) {
                 // Get time for page creation execution time
                 $time_end = microtime(true);
                 $timeTaken = $time_end - $this->time_start;
                 $debugText = "\t<div id='debug' style='background: #ffdd00; color: #333; font-size: 12px !important; line-height: 1.62em;'>\n\t\t\t\t\t\t<table>\n\t\t\t\t\t\t<tr><td><b>CACHE HIT:</b></td><td>" . htmlentities(print_r($this->pathArray, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Cache created:</b></td><td>" . $cache->cacheItem->created . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Cache expires:</b></td><td>" . $cache->cacheItem->expiry . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Path Requested:</b></td><td>" . htmlentities(print_r($this->pathArray, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Page Requested:</b></td><td>" . htmlentities($this->pageRequested, ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Request Variable:</b></td><td>" . htmlentities(print_r($this->requestVars, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Time Taken:</b></td><td>{$timeTaken}</td></tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</div>";
                 $outputContent = $this->addDebugToBody($outputContent, $debugText);
             }
             RestUtils::sendResponse(200, $outputContent, 'text/html');
         }
     }
     $cms = new CMSHelper();
     $cms->checkPage($this->pathArray);
     switch ($cms->pageType) {
         case 'notfound':
             // Gets the 404 from a text file (not using a CMS node for added safety ? - Perhaps this needs changing)
             $fourohfour = file_get_contents('fourohfour.html', true);
             RestUtils::sendResponse(404, $fourohfour, 'text/html');
             break;
         case '301redirect':
             RestUtils::sendResponse(301, $cms->pagePath, 'text/html');
             break;
         case '302redirect':
             RestUtils::sendResponse(302, $cms->pagePath, 'text/html');
             break;
         case 'module':
             $module = new Module($cms->module);
             $output = $module->output;
             RestUtils::sendResponse(200, $output, 'text/html');
             break;
         case 'sitemap':
             // this might need to be done differently with different languages
             $sitemapBody = $cms->getSitemap();
             RestUtils::sendResponse(200, $sitemapBody, 'text/xml');
             break;
             //case 'cached':
             //	$replacedOutput =
         //case 'cached':
         //	$replacedOutput =
         case 'wildcard':
             // pretty much the same logic as the default normal pages but cached differently?
             // normal pages assumed!
         // pretty much the same logic as the default normal pages but cached differently?
         // normal pages assumed!
         default:
             // get the data and build the page
             // if getPage returns false it's a new page not yet published - 404 instead of error
             if (!$cms->getPage($this->pathArray, $this->requestVars)) {
                 // Gets the 404 from a text file (not using a CMS node for added safety ? - Perhaps this needs changing)
                 $fourohfour = file_get_contents('fourohfour.html', true);
                 RestUtils::sendResponse(404, $fourohfour, 'text/html');
             }
             $debug = false;
             if (isset($this->requestVars['debug']) && DEBUG) {
                 $debug = TRUE;
             }
             $replacedOutput = $cms->createPage();
             // store to cache// TODO - check if the page is allowed to be cacheable
             $pageCacheable = !$cms->page['noCache'];
             if (CACHE_ENABLED && $pageCacheable) {
                 $cache->writeCache($replacedOutput);
             }
             if ($debug === TRUE) {
                 // Get time for page creation execution time
                 $time_end = microtime(true);
                 $timeTaken = $time_end - $this->time_start;
                 $debugText = "\t<div id='debug' style='background: #ffdd00; color: #333; font-size: 12px !important; line-height: 1.62em;'>\n\t\t\t\t<table>\n\t\t\t\t<tr><td><b>Path Requested:</b></td><td>" . htmlentities(print_r($this->pathArray, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Requested:</b></td><td>" . htmlentities($this->pageRequested, ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Node:</b></td><td>" . htmlentities($cms->nodeID, ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Data:</b></td><td>" . htmlentities(print_r($cms->page, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Request Variable:</b></td><td>" . htmlentities(print_r($this->requestVars, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Fields in template:</b></td><td>" . htmlentities(print_r($cms->fieldsFound, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Content:</b></td><td>" . htmlentities(print_r($cms->page, 1)) . "</td></tr>\n\t\t\t\t<tr><td><b>Related Pages:</b></td><td>" . substr(htmlentities($cms->relatedNodeIDsStr, ENT_QUOTES, 'ISO-8859-1'), 0, 1000) . "</td></tr>\n\t\t\t\t<tr><td><b>Other Page Content:</b></td><td>" . substr(htmlentities(print_r($cms->relatedContent, 1), ENT_QUOTES, 'ISO-8859-1'), 0, 1000) . "</td></tr>\n\t\t\t\t<tr><td><b>Page Sections:</b></td><td>" . htmlentities(substr(print_r($cms->sections, 1), 0, 1000), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Time Taken:</b></td><td>{$timeTaken}</td></tr>\n\t\t\t\t</table>\n\t\t\t</div>";
                 $replacedOutput = $this->addDebugToBody($replacedOutput, $debugText);
             }
             RestUtils::sendResponse(200, $replacedOutput, 'text/html');
             break;
     }
 }