Location: PHPKode > projects > Community Learning Network > cln/lib/CLN/Cln_Page.php
<?php
/*
 * Page Class
 *
 * Copyright (c) 2003-4 St. Christopher House
 *
 * Developed by The Working Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * @version $Id: Cln_Page.php,v 1.118 2004/11/19 05:27:37 cbooth7575 Exp $
 *
 */

require_once('Cln_Module.php');

class Cln_Page extends Cln_Module
{

	/*
	 *
	 * Class Attributes:  Cln_Page
	 *
	 * 		The attributes for this class are:
	 *
	 *		TBD
	 *
	 */
	var $pageId;
	var $layoutId;
	var $layout;



	/***********************************************************************************
	 *
	 * Externally accessed methods
	 *
	 **********************************************************************************/

	/*
	 *
	 * Function:  Cln_Page()
	 *
	 * 		Class Constructor
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function Cln_Page($pageId, $passedData = FALSE)
	{
		d('PageId: ' . $pageId . ': Cln_Page Constructor');
		$this->pageId = $pageId;

		if ($passedData && isset($passedData['layoutId'])) {
			$this->layoutId = $passedData['layoutId'];
			$this->loadModuleData();
		}
		else if ($passedData && isset($passedData['layout'])) {
			$this->layout = $passedData['layout'];
			$this->loadModuleData();
		}
		else {
			$this->layoutId = FALSE;
			// it would be nice if this were based upon a koId (for a page) set in the config - dwc
			$this->layout = '<page><layout></layout></page>';
		}

	}


	/*
	 *
	 * Function: getContent()
	 *
	 * To get content for body of page
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getContent()
	{
		d('PageId: ' . $this->pageId . ': Cln_Page getContent');
		return $this->getParsedContent();
	}


	/*
	 *
	 * Function:  getEditPanelGeneral()
	 *
	 * 		Returns the general edit panel components
	 *
	 * @access public
	 * @return String 		$message
	 *
	 */
	function getEditPanelGeneral()
	{
		$generalParts[0]['title'] = 'Change Layout';
		$generalParts[0]['description'] = 'Change the layout of objects on this page';
		$generalParts[0]['subprocess'] = 'EditLayout';

		$generalParts[1]['title'] = 'Add a block';
		$generalParts[1]['description'] = 'Add a block to this page';
		$generalParts[1]['subprocess'] = 'AddBlock';

		$generalParts[2]['title'] = 'Remove a block';
		$generalParts[2]['description'] = 'Remove a block from this page';
		$generalParts[2]['subprocess'] = 'DeleteBlock';

		return $generalParts;
	}


	/*
	 *
	 * Function:  getEditPanelLanguages()
	 *
	 * 		Returns the language specific edit panel components
	 *
	 * @access public
	 * @return String 		$message
	 *
	 */
	function getEditPanelLanguages()
	{
		$specificParts[0]['title'] = 'Change Details';
		$specificParts[0]['description'] = 'Change the details (such as the title) for this page';
		$specificParts[0]['subprocess'] = 'EditDetails';

		return $specificParts;
	}


	/*
	 *
	 * Function:  getEditContent()
	 *
	 * 		Returns the edit form for this module
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getEditContent($override = FALSE)
	{
		// another global cancel - does this break anything?  - dwc
		if(isset($_REQUEST['cancel'])) {
			return FALSE;
		}

		d('PageId: ' . $this->pageId . ': Cln_Page getEditContent');
		// Figure out the subprocess we're on
		if (isset($_GET['subprocess'])) {
			$this->currentSubprocess = $_GET['subprocess'];
		}
		if (!isset($this->currentSubprocess)) {
			$this->currentSubprocess = 'EditDetails';
		}

		// Load the language files needed
		includeLangFile('lib/CLN/lang/Page-Process');

		// Do the logic
		switch ($this->currentSubprocess) {

		case 'EditDetails':
			d('Cln_Page: getEditContent (currentSubprocess: EditDetails)',3);
			// If they have submitted the form, deal with it
			if (isset($_POST['editPageDetails'])) {
				// Update the left nav
				if (isset($_SESSION['Room']->currentPart['object'])) {
					$_SESSION['Room']->currentPart['object']->loadNodes();
				}
				// Only save now for existing objects, not new
				if ($this->pageId != 'NEW') {
					$this->saveModuleData();
				}
				if (!$override) {
					PEAR::raiseError('The information for this page has been updated successfully.', E_USER_NOTICE);
					return FALSE;
				}
				else {
					return $this->getInterface('EditDetails');
				}
			}

			// Else, they're just getting here, display the form
			else {
				$this->currentSubprocess = 'EditDetails';
				return $this->getInterface('EditDetails');
			}
		break;

		case 'EditLayout':
			d('Cln_Page: getEditContent (currentSubprocess: EditLayout)',3);
			if (isset($_POST['editLayout'])) {
				$this->layout = strtolower($_POST['editLayout']);

				// :NOTE: in here temporarily to clean up empty rows - dwc
				$this->deleteEmptyRows();

				$this->setOtherLayoutsInMemory();

				// Only save now for existing objects, not new
				if ($this->pageId != 'NEW') {
					$this->saveModuleData();
				}

				PEAR::raiseError('The page layout has been updated successfully.', E_USER_NOTICE);

				// exit this subprocess
				return FALSE;
			}
			else {
				$this->currentSubprocess = 'EditLayout';
				return $this->getInterface('EditLayout');
			}
		break;

		// 2. Add Block
		case 'AddBlock':
			d('Cln_Page: getEditContent (currentSubprocess: AddBlock)',3);
			// Adding a new Block
			if (isset($_POST['AddNewBlock'])) {
				d('------> AddNewBlock');
				$this->currentSubprocess = 'ChooseModType';
				return $this->getInterface('ChooseModType');
			}

			// Else if they want to copy a block
			else if (isset($_POST['copyBlock'])) {
				$this->currentSubprocess = 'CopyBlockFromKB';

				// Create the search, and set it's default values
				include_once('Cln_KB_Search.php');
				$search = new Cln_KB_Search();
				$search->excludedModules = Array(1, 2);

				// Run the search. We don't need to check anythign here, because that happens below
				return $search->getContent();
			}

			// Else if they want to link to an existing block
			else if (isset($_POST['linkToBlock'])) {
				$this->currentSubprocess = 'LinkToBlockInKB';

				// Create the search, and set it's default values
				include_once('Cln_KB_Search.php');
				$search = new Cln_KB_Search();
				$search->excludedModules = Array(1, 2);

				// Run the search. We don't need to check anythign here, because that happens below
				return $search->getContent();
			}

			// Else, just getting here
			else {
				$this->currentSubprocess = 'AddBlock';
				return $this->getInterface('AddBlock');
			}
		break;

		case 'CopyBlockFromKB':
			d('Cln_Page: getEditContent (currentSubprocess: CopyBlockFromKB)',3);
			// Create the search, and set it's default values
			include_once('Cln_KB_Search.php');
			$search = new Cln_KB_Search();
			$search->excludedModules = Array(1,2);
			$search->run();

			if ($search->isComplete()) {
				// Get the blockId
				$blockKoId = $search->userResult;

				$originalBlock = & new $GLOBALS['classes']['ko']['classname']($blockKoId);

				$newBlock = & new $GLOBALS['classes']['ko']['classname']('NEW',$originalBlock->modId);
				$newBlock = $newBlock->copy($blockKoId);
				$newBlock->save();

				$this->addBlockToLayout($newBlock->koId);
				// Only save now for existing objects, not new
				if ($this->pageId != 'NEW') {
					$this->saveModuleData();
				}

				// Go to the block
				PEAR::raiseError('The block was copied and the copied version was added to your page. Please change the title of this block to something different, and then make any additional changes you want.', E_USER_NOTICE);
				$this->currentSubprocess = 'Panel';
				$_SESSION['ProcessManager']->push('editBlock', Array('koId' => $newBlock->koId,
																		'editProcess' => 'Content'));
				$_SESSION['ProcessManager']->goToCurrentProcess();
			}
			else {
				// Return the interface
				$this->currentSubprocess = 'CopyBlockFromKB';
				return $search->getInterface();
			}
		break;

		case 'LinkToBlockInKB':
			d('Cln_Page: getEditContent (currentSubprocess: LinkToBlockInKB)',3);
			// Create the search, and set it's default values
			include_once('Cln_KB_Search.php');
			$search = new Cln_KB_Search();
			$search->excludedModules = Array(1,2);
			$search->run();

			if ($search->isComplete()) {
				// Get the blockId
				$blockKoId = $search->userResult;

				$this->addBlockToLayout($blockKoId);
				PEAR::raiseError('The block you chose was added to this page, and you can edit the layout below.', E_USER_NOTICE);

				// Only save now for existing objects, not new
				if ($this->pageId != 'NEW') {
					$this->saveModuleData();
				}

				$this->currentSubprocess = 'EditLayout';
				return $this->getInterface('EditLayout');

			}
			else {
				// Return the interface
				$this->currentSubprocess = 'LinkToBlockInKB';
				return $search->getInterface();
			}
		break;

		// 2A. Choosing a Module Type
		case 'ChooseModType':
			d('Cln_Page: getEditContent (currentSubprocess: ChooseModType)',3);
			if (isset($_POST['ChooseModType'])) {
				// They didn't choose a module
				if (!isset($_POST['selectedModule']) || empty($_POST['selectedModule'])) {
					PEAR::raiseError(ADMIN_EM_NO_MODULE, E_USER_WARNING);
					$this->currentSubprocess = 'ChooseModType';
					return $this->getInterface('ChooseModType');
				}
				// They did choose a module, create and save the block KO, and then forward them to it
				else {
					if (is_numeric($_POST['selectedModule'])) {
						$newModId = $_POST['selectedModule'];
						$newModVariables = FALSE;
					}
					else {
						$splitValue = explode(' ', $_POST['selectedModule']);
						$newModId = $splitValue[0];
						$newModVariables = $splitValue[1];
					}

					// Make the block
					$newKO = & new $GLOBALS['classes']['ko']['classname']('NEW', $newModId);

					// Give it roles
					$newKO->roles = $this->_super->roles;

					// Load the object
					$newKO->loadPartObject(0);
					$newKO->loadMetadata();
					$newKO->currentPart['title'] = 'New Block';

					// Deal with the newModVariables if needed
					if ($newModVariables) {
						$nameValuePairs = explode('|', $newModVariables);
						foreach ($nameValuePairs as $nameValuePair) {
							$nameValue = explode('=', $nameValuePair);
							$newKO->parts['NEW']['object']->$nameValue[0] = $nameValue[1];
						}
					}

					$newKO->save();
					$this->addBlockToLayout($newKO->koId);
					// Only save now for existing objects, not new
					if ($this->pageId != 'NEW') {
						$this->saveModuleData();
					}
					$this->currentSubprocess = 'Panel';
					$_SESSION['ProcessManager']->push('editBlock', Array('koId' => $newKO->koId,
																		'editProcess' => 'Content'));
					$_SESSION['ProcessManager']->goToCurrentProcess();
				}
			}
			else {
				$this->currentSubprocess = 'ChooseModType';
				return $this->getInterface('ChooseModType');
			}
		break;

		case 'DeleteBlock':
			d('Cln_Page: getEditContent (currentSubprocess: DeleteBlock)',3);
			// Have they chosen one?
			if (isset($_POST['selectBlock']) && isset($_POST['addKoId'])) {
				$this->currentSubprocess = 'DeleteBlockConfirmation';
				return $this->getInterface('DeleteBlockConfirmation');
			}
			// Or didn't they choose
			else if (isset($_POST['selectBlock']) && !isset($_POSST['addKoId'])) {
				PEAR::raiseError('You need to select a block to delete', E_USER_WARNING);
				$this->currentSubprocess = 'DeleteBlock';
				return $this->getInterface('SelectBlock');
			}
			// Or are the just getting here
			else {
				$this->currentSubprocess = 'DeleteBlock';
				return $this->getInterface('SelectBlock');
			}
		break;

		case 'DeleteBlockConfirmation':
			d('Cln_Page: getEditContent (currentSubprocess: DeleteBlockConfirmation)',3);
			// If they've submitted the form
			if (isset($_POST['DeleteBlockConfirmation'])) {
				// Are we deleting it completely from the KB?
				if (isset($_POST['deleteFromKB']) && $_POST['deleteFromKB']) {
					$this->deleteBlockFromLayout($_POST['deleteBlockKoId']);
					$this->deleteBlockFromKB($_POST['deleteBlockKoId']);

					// Only save now for existing objects, not new
					if ($this->pageId != 'NEW') {
						$this->saveModuleData();
					}
					PEAR::raiseError('The block was removed from this page, and from the knowledge base. You should: <ul><li>Check your page layout to make sure it still makes sense without the block you removed</li><li>Be sure to publish your page when you\'re finished making your changes</li></ul>', E_USER_NOTICE);
					return FALSE;
				}
				// Or just from this page
				else {
					$this->deleteBlockFromLayout($_POST['deleteBlockKoId']);
					// Only save now for existing objects, not new
					if ($this->pageId != 'NEW') {
						$this->saveModuleData();
					}
					PEAR::raiseError('The block was removed from this page. You should: <ul><li>Check your page layout to make sure it still makes sense without the block you removed</li><li>Be sure to publish your page when you\'re finished making your changes</li></ul>', E_USER_NOTICE);
					return FALSE;
				}
			}
			// Else if they're cancelling the delete
			else if (isset($_POST['cancel'])) {
				return FALSE;
			}
			// Or they're just getting here
			else {
				$this->currentSubprocess = 'DeleteBlock';
				return $this->getInterface('SelectBlock');
			}
		break;

		default:
			return FALSE;
		break;

		}
	}


	/***********************************************************************************
	 *
	 * Internally accessed methods
	 *
	 **********************************************************************************/

	/*
	 *
	 * Function:  loadModuleData()
	 *
	 * 		loads all the relevant data about a page into the object
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function loadModuleData()
	{
		d('PageId: ' . $this->pageId . ': Cln_Page loadModuleData');
		// If it's not a new object
		if ($this->pageId != 'NEW' && is_numeric($this->pageId)) {
			$sql = sprintf("SELECT ly.layoutId, ly.layout FROM `%s` as pg, `%s` as ly
							WHERE ly.layoutId=pg.layoutId AND pageId = '%s'",
							PAGE_TABLE, PAGE_LAYOUT_TABLE, $this->pageId);
			$db = &Cln_Db::singleton(MAIN_CLN_DSN);
			$result = $db->query($sql);

			if (PEAR::isError($result))	 {
				PEAR::raiseError("Error on page select: $sql", E_ERROR);
				return FALSE;
			}
			else {
				$page = $result->fetchRow(DB_FETCHMODE_OBJECT);
				$this->layoutId = $page->layoutId;
				$this->layout = stripslashes($page->layout);
				return TRUE;
			}
		}

		// If it's a new object, but uses an existing layout
		else if ($this->pageId == 'NEW' && is_numeric($this->layoutId)) {
			$sql = sprintf("SELECT layout FROM `%s` WHERE layoutId = '%d'",
							PAGE_LAYOUT_TABLE, $this->layoutId);
			$db = &Cln_Db::singleton(MAIN_CLN_DSN);
			$result = $db->query($sql);
		d($sql);
			if (PEAR::isError($result))	 {
				PEAR::raiseError("Error on page select: $sql", E_ERROR);
				return FALSE;
			}
			else {
				$layout = $result->fetchRow(DB_FETCHMODE_OBJECT);
				$this->layout = stripslashes($layout->layout);
				return TRUE;
			}
		}

		// Else it's a new object that doesn't have a layout yet
		else {
			return TRUE;
		}
	}


	/*
	 *
	 * Function:  getInterface()
	 *
	 * 		Returns the edit form for this module
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getInterface($formName)
	{
		ob_start();
		include('lib/CLN/interfaces/Page/' . $formName . '.html');
		$form = ob_get_contents();
		ob_end_clean();
		return $form;
	}


	/*
	 *
	 * Function:  getPublishData()
	 *
	 * Should return an array of all the data from an object that is needed by another
	 * object to publish it.
	 *
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getPublishData()
	{
		$returnVal['layout'] = $this->layout;

		return $returnVal;
	}


	/*
	 *
	 * Function:  publish()
	 *
	 * Should take an array of all the data from an object that is needed by another
	 * object to publish it.
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function publish($publishData = FALSE)
	{
		if ($publishData) {
			$this->layout = $publishData['layout'];
		}

		return $this->saveModuleData();
	}


	/*
	 *
	 * Function:  delete()
	 *
	 * 		Delete the page
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function delete()
	{
		d('Cln_Page delete: pageId: ' . $this->pageId);

		$db = &Cln_Db::singleton(MAIN_CLN_DSN);
		$sql = sprintf("DELETE FROM %s WHERE pageId = '%s';", PAGE_TABLE, $this->pageId);
		$result = $db->query($sql);

		if (PEAR::isError($result))	 {
			PEAR::raiseError(ADMIN_EM_DB_ERROR_DELETE , E_USER_ERROR);
			PEAR::raiseError("Error on page delete: $sql", E_ERROR);
			return FALSE;
		}
		else {
			$sql = sprintf("DELETE FROM %s WHERE layoutId = '%s';", PAGE_LAYOUT_TABLE, $this->layoutId);
			$result = $db->query($sql);
			return TRUE;
		}
	}


	/*
	 *
	 * Function: getFullPagePath()
	 *
	 * Returns the full path to the current page, starting with ./
	 *
	 * @access public
	 * @return HTML formatted navigation bar
	 *
	 */
	function getFullPagePath()
	{
		$thisRoom = new Cln_Room($this->roomId);
		return $thisRoom->getFullRoomPath() . $this->filename . CLN_CONTROL_FILE_EXTENSION;
	}


	/*
	 *
	 * Function:  validateData()
	 *
	 * 		Validates the data and returns FALSE with errors, or TRUE
	 *
	 * @access public
	 * @return Boolean 		TRUE or FALSE
	 *
	 */
	function validateData($mode)
	{
		$status = TRUE;

		// Case 1: Layout Info
		if ($mode == 'LayoutOptions') {
			// :ONEDAY: it would be nice to actually validate that the data works in the parser
			if ($this->layout == '') {
				PEAR::raiseError(ADMIN_EM_NO_LAYOUT, E_USER_WARNING);
				$status = FALSE;
			}
		}
		return $status;
	}


	/*
	 *
	 * Function:  saveModuleData()
	 *
	 * 		Saves the KO
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function saveModuleData()
	{
		d('PageId: ' . $this->pageId . ': Cln_Page saveModuleData');
		$db = &Cln_Db::singleton(MAIN_CLN_DSN);

		// If it's a new page
		if ($this->pageId == 'NEW') {

			// If a layout isn't set, we need to create one
			if (!$this->layoutId) {
				$this->layoutId = $db->nextId(PAGE_LAYOUT_TABLE);
				$sql = sprintf("INSERT INTO `%s` SET layoutId = '%d', layout = '%s', created = NOW()",
								PAGE_LAYOUT_TABLE, $this->layoutId, addslashes($this->layout));
			}
			else {
				$sql = sprintf("UPDATE `%s` SET layout = '%s' WHERE layoutId = '%d'",
								PAGE_LAYOUT_TABLE, addslashes($this->layout), $this->layoutId);
			}

			// Call the layout SQL
			$result = $db->query($sql);
			if (PEAR::isError($result)) {
				PEAR::raiseError('ADMIN_EM_DB_ERROR_INSERT', E_USER_ERROR);
				PEAR::raiseError("Error on page layout insert/update: $sql", E_ERROR);
				return FALSE;
			}

			// Then save the page stuff
			$this->pageId = $db->nextId(PAGE_TABLE);
			$sql = sprintf("INSERT INTO `%s` SET pageId = '%d', layoutId = '%d', created = NOW()",
							PAGE_TABLE, $this->pageId, $this->layoutId);
		}

		// Else, it's an existing page, so we only have to save the layout
		else {
			// Build the SQL
			$sql = sprintf("UPDATE `%s` SET layout = '%s' WHERE layoutId = '%s'",
							PAGE_LAYOUT_TABLE, addslashes($this->layout), $this->layoutId);
		}

		// Perform the query
		$result = $db->query($sql);
		if (PEAR::isError($result))	 {
			PEAR::raiseError('ADMIN_EM_DB_ERROR_INSERT', E_USER_ERROR);
			PEAR::raiseError("Error on page insert/update: $sql", E_ERROR);
			return FALSE;
		}
		else {
			$this->updateModified();
			return $this->pageId;
		}
	}


	/*
	 *
	 * Function:  addBlockToLayout()
	 *
	 * 		Adds a block to the layout
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function addBlockToLayout($koId)
	{
		d('PageId: ' . $this->pageId . ': Cln_Page addBlockToLayout');
		$search = '</layout>';
		$replace = '<row><column><block koId="' . $koId . '" /></column></row></layout>';
		$newLayout = str_replace($search, $replace, $this->layout);

		$this->layout = $newLayout;
		$this->setOtherLayoutsInMemory();
	}


	/*
	 *
	 * Function:  deleteEmptyRows()
	 *
	 * 		gets rid of empty row/columns
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function deleteEmptyRows()
	{
		d('.......trying to delete empty rows from layout',1);

		$status = FALSE;

		// Look for empty rows/columns
		$search = '<row><column[a-z="0-9 %]*/></row>';
		$replace = '';
		if($this->layout = eregi_replace($search, $replace, $this->layout)) {
			$status = TRUE;
		}

		// Look for empty rows/columns
		$search = '<row><column[a-z="0-9 %]*></column></row>';
		$replace = '';
		if($this->layout = eregi_replace($search, $replace, $this->layout)) {
			$status = TRUE;
		}

		if($status) {
			return TRUE;
		} else {
			return FALSE;
		}
	}


	/*
	 *
	 * Function:  deleteBlockFromLayout()
	 *
	 * 		Deletes a block from the layout
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function deleteBlockFromLayout($koId)
	{
		// Look for the block
		$search = '<block koId="' . $koId . '"[a-z="0-9 ]* />';
		$replace = '';
		if($this->layout = eregi_replace($search, $replace, $this->layout)) {
			// :TODO: this does not work yet
			$this->deleteEmptyRows();

			if($this->setOtherLayoutsInMemory()) {
				return TRUE;
			} else {
				return FALSE;
			}
		} else {
			return FALSE;
		}
	}


	/*
	 *
	 * Function:  deleteBlockFromKB()
	 *
	 * 		Deletes a block from all pages. This function probably shouldn't be here, but I wasn't sure where
	 *		else it would work better, so here it is for now.
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function deleteBlockFromKB($koId)
	{
		// First, delete it from all pages it appears on.
		$sql  = 'SELECT layoutId, layout FROM `' . PAGE_LAYOUT_TABLE . '` ';
		$sql .= 'WHERE layout LIKE \'%block koid=\"' . $koId . '\"%\'';

		$db = &Cln_Db::singleton(MAIN_CLN_DSN);
		$result = $db->query($sql);

		if (PEAR::isError($result))	 {
			PEAR::raiseError(ADMIN_EM_DB_ERROR_DELETE , E_USER_ERROR);
			PEAR::raiseError("Error on block select from all pages for delete: $sql", E_ERROR);
			return FALSE;
		}

		while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
			$layoutId = $row['layoutId'];
			$layout = $row['layout'];

			// Look for the block anywhere.
			$search = '<block koId="' . $koId . '"[a-z="0-9 ]* />';
			$replace = '';
			$layout = eregi_replace($search, $replace, $layout);

			$sql = sprintf("UPDATE `%s` SET layout = '%s' WHERE layoutId = '%d'",
							PAGE_LAYOUT_TABLE, addslashes($layout), $layoutId);

			$deleteResult = $db->query($sql);
			if (PEAR::isError($deleteResult))	 {
				PEAR::raiseError(ADMIN_EM_DB_ERROR_DELETE , E_USER_ERROR);
				PEAR::raiseError("Error on block delete from page: $sql", E_ERROR);
				return FALSE;
			}
		}

		// Then delete it from the KB itself
		$ko = & new $GLOBALS['classes']['ko']['classname']($koId);
		$ko->delete();
	}


	/*
	 *
	 * Function:  getBlockIds()
	 *
	 * 		returns an array of blockIds for the blocks that are on this page
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getBlockIds()
	{
		$search = '/block koid="([0-9]+)/i';
		preg_match_all($search, $this->layout, $blockStrings);

		return $blockStrings[1];
	}


	/*
	 *
	 * Function: getParsedContent()
	 *
	 * runs layout through xml parser
	 *
	 * @access public
	 * @return String	  content of body
	 *
	 */
	function getParsedContent() {
		require_once('LayoutParser.php');

		$xml_parser = new LayoutParser();
		$layoutToParse = $this->layout;

		if (isset($_REQUEST['viewKoId']) && is_numeric($_REQUEST['viewKoId'])) {
			$layoutToParse = '<page><layout><row><column width="100%" type="proportional"><block koId="' . $_REQUEST['viewKoId'] . '" /></column></row></layout></page>';
		}

		if($content = $xml_parser->parse($layoutToParse)) {
			if(isset($this->_super->currentPart['title'])) {
				$GLOBALS['CLN_PAGE_TITLE'] = $this->_super->currentPart['title'];
			}

			//if(isset($GLOBALS['MYHOUSE']) && !empty($_SESSION['User']->userId)) {
			//	$myHouseController = $_SESSION['User']->getInterface('myHouseController');
			//} else {
			//	$myHouseController = '';
			//}

			//return $myHouseController.$content;
			return $content;
		}
		else {
			PEAR::raiseError('LayoutParser could not process layout', E_WARNING);
			return FALSE;
		}
	}


	/*
	 *
	 * Function: getNewTranslationData()
	 *
	 * To get general stuff that is needed when creating a translation version
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getNewTranslationData()
	{
		$data['layoutId'] = $this->layoutId;
		return $data;
	}


	/*
	 *
	 * Function: setOtherLayoutsInMemory()
	 *
	 * Makes an attempt to cycle through the other layouts in memory that are the same, and updates their layouts
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function setOtherLayoutsInMemory()
	{
		$currentStatus = $this->_super->currentPart['status'];

		if (isset($this->_super->parts) ) {
			foreach ($this->_super->parts as $key => $part) {
				if ($part['status'] == $currentStatus) {
					if ($part['objectId'] != $this->pageId && is_object($part['object'])) {
						$otherObjectId = $part['objectId'];
						$this->_super->parts[$otherObjectId]['object']->layout = $this->layout;
					}
				}
			}
		}
	}

}

?>
Return current item: Community Learning Network