<?php
/*
 * This file is part of the easy-CMS project.
 * easy-CMS 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.
 * 
 * easy-CMS 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 easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *  
 */

/**
 * @package    Core
 * @subpackage Contents
 */
 
include_once('config.inc.php');
include_once('classes/core/DBAccessorObject.class.php');
include_once('classes/core/DBManipulator.class.php');
include_once('classes/core/types/Type.class.php');
include_once('classes/core/types/TypesManager.class.php');
include_once('classes/core/contents/Content.class.php');
include_once('classes/core/versions/ContentVersionsManager.class.php');

include_once('classes/types/Bool.class.php');
include_once('classes/types/Color.class.php');
include_once('classes/types/Date.class.php');
include_once('classes/types/Document.class.php');
include_once('classes/types/Image.class.php');
include_once('classes/types/Integer.class.php');
include_once('classes/types/Float.class.php');
include_once('classes/types/Reference.class.php');
include_once('classes/types/String.class.php');
include_once('classes/types/ShortText.class.php');
include_once('classes/types/Link.class.php');
include_once('classes/types/Text.class.php');
include_once('classes/types/Time.class.php');


/**
 * ContentsManager Class
 *
 * Manages instances of Content
 *
 * @access     public
 * @author	   Cedric Francoys <cedric.francoys@easy-cms.org>
 * @version	   ContentsManager.class, Sun Apr 03 11:11:13 CEST 2005
 * @package    Core
 * @subpackage Contents
 */
class ContentsManager extends DBAccessorObject {
	/**
	 * TypesManager
	 *
	 * @var object
	 */
	var $typesManager;
	
	/**
	 * ACLManager
	 *
	 * @var object
	 */
	var $aclManager;
	
	/**
	 * @var array
	 */
	var $contentsDescr;
	
	/**
	 * 
	 */
	var $typesArray;
	
	/**
	 * Content Objects Table
	 *
	 * @var array
	 */
	var $contentsTable;
	

	/**
	 * Class constructor
	 *
	 * @param object  $dbManipulator instance of DBManipulator
	 * @param object  $aclManager instance of ACLManager
	 * @param object  $typesManager instance of TypesManager
	 * @param integer $langId current language
	 */
  function ContentsManager(&$dbManipulator, &$aclManager, &$typesManager) {
    $this->debug('ContentsManager::ContentsManager, status : function invoked', 10, DBG_OPEN);
		parent::DBAccessorObject($dbManipulator);
		$this->aclManager = &$aclManager;
		$this->typesManager = &$typesManager;
		$this->contentsTable = array();
		$this->contentsDescr = array();
    $this->debug('ContentsManager::ContentsManager, status : function completed', 10, DBG_CLOSE);
  }

	/**
	 * Gets ACLManager
	 *
	 * @return object
	 */ 
	function &getAclManager() {
		return $this->aclManager;
	}

	/**
	 * Gets TypesManager
	 *
	 * @return object
	 */
	function &getTypesManager() {
		return $this->typesManager;
	}


	function &getContentTypesFields() {
    $this->debug('ContentsManager::getContentTypesFields, status : function invoked', 10, DBG_OPEN);
    $db = &$this->getDBManipulator();
		$prefix = TYPE_TABLES_PREFIX;
		$len = strlen($prefix);
		$result = &$db->getTables($prefix);
    $contentTypesFieldsArray = array();
		while($row = &$db->fetchRow($result)){
      $typeName = substr($row[0], $len);
			$contentTypesFieldsArray[$typeName] = $db->getFieldsArray($row[0]);
		}
    $this->debug('ContentsManager::getContentTypesFields, status : function completed', 10, DBG_CLOSE);
    return $contentTypesFieldsArray;
  }

	function &getContentTypesTemplates() {
    $this->debug('ContentsManager::getContentTypesTemplates, status : function invoked', 10, DBG_OPEN);
    $db = &$this->getDBManipulator();
		$prefix = TYPE_TABLES_PREFIX;
		$len = strlen($prefix);
		$result = &$db->getTables($prefix);
    $contentTypesTemplatesArray = array();
		while($row = &$db->fetchRow($result)){
      $typeName = substr($row[0], $len);
			$contentTypesTemplatesArray[$typeName] = array();
		  $result1 = &$db->getRecord(TEMPLATES_TABLE, -1, "type='$typeName'");
		  while($row1 = &$db->fetchArray($result1)){
        $contentTypesTemplatesArray[$typeName][$row1['id']] = $row1['name'];
      }
		}
    $this->debug('ContentsManager::getContentTypesTemplates, status : function completed', 10, DBG_CLOSE);
    return $contentTypesTemplatesArray;
  }

	/**
	 * Returns instance of "simple type" class
	 *
	 * @param  integer $type
	 * @param  value   $mixed
	 * @return mixed  object or null if error
	 * @todo discuss deprecation (private method?)
	 */
	function &createFieldObject($type, $value) {
		return $this->typesManager->createTypeObject($type, $value);
	}
	
	/**
	 * Load content
	 *
	 * Load content from content_type_* table. First tries to get
	 * instance of complex type $typeName. Then tries to get record from
	 * corresponding table in database where $id is the record id. 
	 * If successful, create instance of content object with values from record 
	 * and add content to contents manager.
	 *
	 * @param  integer $id
	 * @param  string  $typeName
	 * @param  boolean $loadDeleted
	 * @return boolean
	 */
	function loadContent($id, $typeName, $loadDeleted=false, $loadAcl=true, $langId=LOAD_ALL_LANGUAGES) {
    $this->debug('ContentsManager::loadContent, status : function invoked', 10, DBG_OPEN);
    $result = true;
		if (!isset($id) || $id == null || $id == '' || (is_array($id) && count($id) == 0)) {
      $this->debug('ContentsManager::loadContent, warning : no id specified', 4);
      $result = false;
    }
    else {
  		$db = &$this->getDBManipulator();
  		$tableName = TYPE_TABLES_PREFIX.$typeName;

  		if (!isset($this->contentsDescr[$typeName])) {
  			$this->contentsDescr[$typeName] = $db->getFieldsArray($tableName);
  		}

  		if($langId != LOAD_ALL_LANGUAGES) {
  			$cond = '`lang_id`= '.$langId;
  		}
      else {
        $cond = '';
      }

  		if (is_array($id)) {
  		  if(count($id) > 0) {
  				$csv = implode(',', $id);
  	      if(strlen($cond)) {
            $cond .= ' and `id` in ('.$csv.')';
  	      }
  	      else {
            $cond = ' `id` in ('.$csv.')';
  	      }
  				$res = $db->getRecord($tableName, -1, $cond);
  			}
  			else {
  			  $res = 0;
  			}
  		}
  		else {
  			$csv = $id;
  			$res = $db->getRecord($tableName, $id, $cond);
  		}

  		if (!$res || !$db->getNumRows()) {
  			$this->debug('ContentsManager::loadContent, error : unable to load Content(id='.$csv.' type_name="'.$typeName.'")', 4);
  			$result = false;
  		}
  		else {
    		while ($record = $db->fetchArray($res)) {
    			$contentId   = $record['id'];
    			$aclId       = $record['acl_id'];
    			$deleted     = $record['deleted'];
    			$published   = $record['published'];
    			$langId			 = $record['lang_id'];
    			$authorId		 = $record['author_id'];
    			
    			if($deleted == 0 || $loadDeleted) {
    				$valuesTable = array();
    				foreach ($this->contentsDescr[$typeName] as $field => $fieldType) {
    					switch ($fieldType) {
    						case EASY_CMS_TYPE_INTEGER:
    							$valuesTable[$langId][$field] = &new Integer($record[$field]);
    							break;
    						case EASY_CMS_TYPE_FLOAT:
    							$valuesTable[$langId][$field] = &new Float($record[$field]);
    							break;
    						case EASY_CMS_TYPE_BOOL:
    							$valuesTable[$langId][$field] = &new Bool($record[$field]);
    							break;
    						case EASY_CMS_TYPE_STRING:
    							$valuesTable[$langId][$field] = &new String($record[$field]);
    							break;
    						case EASY_CMS_TYPE_SHORTTEXT:
    							$valuesTable[$langId][$field] = &new ShortText($record[$field]);
    							break;
    						case EASY_CMS_TYPE_TEXT:
    							$valuesTable[$langId][$field] = &new Text($record[$field]);
    							break;
    						case EASY_CMS_TYPE_COLOR:
    							$valuesTable[$langId][$field] = &new Color($record[$field]);
    							break;
    						case EASY_CMS_TYPE_LINK:
    							$valuesTable[$langId][$field] = &new Link($record[$field]);
    							break;
    						case EASY_CMS_TYPE_DATE:
    							$valuesTable[$langId][$field] = &new Date($record[$field]);
    							break;
    						case EASY_CMS_TYPE_TIME:
    							$valuesTable[$langId][$field] = &new Time($record[$field]);
    							break;
    						case EASY_CMS_TYPE_DOCUMENT:
    							$valuesTable[$langId][$field] = &new Document($record[$field]);
    							break;
    						case EASY_CMS_TYPE_IMAGE:
    							$valuesTable[$langId][$field] = &new Image($record[$field]);
    							break;
    						case EASY_CMS_TYPE_REFERENCE:
    							$valuesTable[$langId][$field] = &new Reference($record[$field]);
    							break;
    					}
    				}

    	      if ($this->checkContent($contentId, $typeName)) {
    	        $this->contentsTable[$typeName][$contentId]->setContentValuesTable($valuesTable);
    	      }
    	      else {
    	  			$content = &new Content($contentId, $typeName, $valuesTable, $deleted, $aclId);
    					$content->setContentPublished($published);
    					$content->setContentAuthorId($authorId);
    					
    	  			if ($loadAcl) {
    	  				if ($acl = &$this->getContentAcl($aclId)) {
    	  					$content->setContentAcl($acl);
    	  				}
    	  			}

    	  			$this->addContent($content);
    	      }
    			}
    		}
      }
    }

    $this->debug('ContentsManager::loadContent, status : function completed', 10, DBG_CLOSE);
		return $result;
	}
	
	/**
	 * Gets Content ACL
	 *
	 * @param  integer $aclId ACL Id
	 * @return object
	 */
	function &getContentAcl($aclId) {
    $this->debug('ContentsManager::getContentAcl, status : function invoked', 10, DBG_OPEN);
		$acl = &$this->aclManager->getACL($aclId);
    $this->debug('ContentsManager::getContentAcl, status : function completed', 10, DBG_CLOSE);
		return $acl;
	}

	/**
	 * Sets Content
	 *
	 * @param  integer $id
	 * @param  string  $typeName
	 * @param  array   $array Associative array [lang][type] => value
	 * @return boolean
	 * @todo approve modifications
	 */
	function setContent($id, $typeName, $array) {
    $this->debug('ContentsManager::setContent, status : function invoked', 10, DBG_OPEN);
		// to change : type and typesManager calls should be removed (require some additional functions)
		$result = true;
		if (!($type = &$this->typesManager->getType($typeName))) {
			$this->debug("ContentsManager::setContent, error : type '".$typeName."'unknown.", 2);
			$result = false;
		}
		else {
  		if (!($content = &$this->getContent($id, $typeName))) {
			   $this->debug("ContentsManager::setContent, error : unable to get content ($id)", 2);
  			$result = false;
  		}
      else {
    		if (!($simpleTypesArray = $type->getFieldsTable())) {
          $this->debug("ContentsManager::setContent, error : unable to get fields table for type '".$typeName."'", 2);
    			$result = false;
    		}
    		else {
      		$valuesTable = array();

      		$langsArray = &$this->getLangsArray();

      		foreach ($langsArray as $langId => $langName) {
      			if(isset($array[$langId])) {
      				foreach ($simpleTypesArray as $name => $valueType) {
                if(!isset($array[$langId][$name])) {
                  // error : invalid array was submitted
                }
                else {
        					$valuesTable[$langId][$name] = $this->typesManager->createTypeObject($valueType, $array[$langId][$name]);
                }
      				}
      			}
      		}
      		if(isset($array['deleted'])) {
      			$content->setContentDeleted($array['deleted']);
      		}
      		if(isset($array['published'])) {
      			$content->setContentPublished($array['published']);
      		}
      		if(isset($array['acl_id'])) {
      			$content->setContentAclId($array['acl_id']);
      		}
      		$content->setContentValuesTable($valuesTable);
        }
      }
    }
    $this->debug('ContentsManager::setContent, status : function completed', 10, DBG_CLOSE);
		return $result;
	}
    
	/**
	 * Stores Content
	 *
	 * @param  integer $contentId
	 * @param  string  $contentType
	 * @return integer Content ID or <0 if error
	 */
	function storeContent($id, $typeName) {
    $this->debug('ContentsManager::storeContent, status : function invoked ('.$id.', '.$typeName.')', 10, DBG_OPEN);
    $result = 0;
		if (!($type = &$this->typesManager->getType($typeName))) {
      $this->debug('ContentsManager::storeContent, error : unable to get type object', 2);
		}
		else {
  		if (!($content = &$this->getContent($id, $typeName))) {
        $this->debug('ContentsManager::storeContent, error : unable to get content', 2);
  		}
  		else {
    		$aclId   = $content->getContentAclId();
    		$deleted = $content->getContentDeleted();
    		$published = $content->getContentPublished();

    		$fieldsArray = array();
    		$valuesTableLang = &$content->getContentValuesTable();

    		foreach($valuesTableLang as $langId => $valuesTable) {
          foreach($valuesTable as $name => $value) {
              $fieldsArray[$name] = $value->toSQL();
          }

  				// control fields
  				$fieldsArray['lang_id'] = $langId;
  				$fieldsArray['acl_id']  = $aclId;
  				$fieldsArray['deleted'] = $deleted;
  				$fieldsArray['published'] = $published;

          if(isset($content->authorId)) {
    				$fieldsArray['author_id'] = $content->getContentAuthorId();
          }
          else {
            $site = &Site::getInstance();
    				$fieldsArray['author_id'] = $site->getCurrentUserId();
          }

  				if(isset($_GET['mailing_list_id']) && is_numeric($_GET['mailing_list_id'])) {
  					$fieldsArray['mailing_list_id'] = $_GET['mailing_list_id'];
  				}

  				if(!$id || !$type->recordExists($id, $langId)){
  					if (!($newId = $type->addRecord($id, $fieldsArray, $langId))) {
  						$this->debug('ContentsManager::storeContent, error : unable to add record to `'.TYPE_TABLES_PREFIX.$typeName.'` table', 3);
  						return 0;
  					}
  					$id = $newId;
  					$content->setContentId($newId);
  					$this->addContent($content);

  					unset($this->contentsTable[0]);
  					$this->contentsTable[0] = null;
  				}
  				else {
  					$type->setRecord($id, $fieldsArray, $langId);
  				}
        }
        $result = $id;
  		}
    }

    $this->debug('ContentsManager::storeContent, status : function completed', 10, DBG_CLOSE);
		return $result;
	}
	
	/**
	 * Removes Content
	 *
	 * @param  integer $id
	 * @param  string  $typeName
	 * @return boolean
	 */
	function removeContent($id, $typeName) {
    $this->debug('ContentsManager::removeContent, status : function invoked ('.$id.', '.$typeName.')', 10, DBG_OPEN);
    $result = true;
		if (!($content = &$this->getContent($id, $typeName))){
			$this->debug("ContentsManager::removeContent, error : trying to remove unexisting content", 2);
			$result = false;
		}
		else {
  		$content->setContentDeleted(1);
      if (!$this->storeContent($id, $typeName)) {
        $this->debug("ContentsManager::removeContent, error : unable to store modified content", 2);
        $result = false;
		  }
    }
    $this->debug('ContentsManager::removeContent, status : function completed', 10, DBG_CLOSE);
		return $result;
	}

	/**
	 * Restores Content
	 *
	 * @param  integer $id
	 * @param  string  $typeName
	 * @return boolean
	 */
	function restoreContent($id, $typeName) {
    $this->debug('ContentsManager::restoreContent, status : function invoked ('.$id.', '.$typeName.')', 10, DBG_OPEN);
    $result = true;
		if (!($content = &$this->getContent($id, $typeName, LOAD_ALL_LANGUAGES, true))){
			$this->debug("ContentsManager::restoreContent, error : trying to restore unexisting content", 2);
			$result = false;
		}
		else {
  		$content->setContentDeleted(0);
      if (!$this->storeContent($id, $typeName)) {
        $this->debug("ContentsManager::restoreContent, error : unable to store modified content", 2);
        $result = false;
		  }
    }
    $this->debug('ContentsManager::restoreContent, status : function completed', 10, DBG_CLOSE);
		return $result;
	}

	/**
	 * Check for instance of content object
	 *
	 * @param  integer $id content id
	 * @param  string  $typeName content type
	 * @return boolean
	 */
  function checkContent($id, $typeName) {
    return isset($this->contentsTable[$typeName][$id]);
  }
	
	/**
	 * Tells if content exists in database
	 *
	 * @param  integer $id
	 * @param  string  $typeName
	 * @return boolean
	 */
	function contentExists($id, $typeName) {
    $this->debug('ContentsManager::contentExists, status : function invoked', 10, DBG_OPEN);
		// try to load the container
		$this->getContent($id, $typeName);
		// returns true if the container has been sucessfully loaded
		$result = $this->checkContent($id, $typeName);
    $this->debug('ContentsManager::contentExists, status : function completed', 10, DBG_CLOSE);
		return $result;
	}

  /**
	 * Gets Content
	 *
	 * First checks if instance already exists. If not tries to load it.
	 * 
 	 * @param  integer $id
	 * @param  string $typeName
 	 * @return object
	 */
  function &getContent($id, $typeName, $langId=LOAD_ALL_LANGUAGES, $load_deleted=false) {
    $this->debug('ContentsManager::getContent, status : function invoked ('.$id.', '.$typeName.')', 10, DBG_OPEN);
    $result = null;
    if (!$this->checkContent($id, $typeName)) {
			if (!$this->loadContent($id, $typeName, $load_deleted, true, $langId)) {
				$this->debug("ContentsManager::getContent, error : unable to load content '$id'.", 2);
			}
			else {
        $result = &$this->contentsTable[$typeName][$id];
			}
		}
		else {
		  $result = &$this->contentsTable[$typeName][$id];
		}
    $this->debug('ContentsManager::getContent, status : function completed', 10, DBG_CLOSE);
		return $result;
  }

  /**
	 * Load all Contents for a specified typeName
	 *
	 * @param  string $typeName
 	 * @return object
	 */
  function loadAllContents($typeName, $langId=LOAD_ALL_LANGUAGES) {
    $this->debug('ContentsManager::loadAllContents, status : function invoked', 10, DBG_OPEN);
    $result = true;
		$db = &$this->getDBManipulator();
		$tableName = TYPE_TABLES_PREFIX.$typeName;

		$idList = array();

		$result_array = $db->sendQuery("SELECT distinct(id) FROM `$tableName`;");

		while($row = $db->fetchArray($result_array)){
			$idList[] = $row['id'];
		}

		if (!$this->loadContent($idList, $typeName, $langId)) {
			$this->debug("ContentsManager::loadAllContents, error : unable to load content list.", 2);
			$result = false;
		}
		
    $this->debug('ContentsManager::loadAllContents, status : function completed', 10, DBG_CLOSE);
		return $result;
  }

	/**
	 * Add Content to Manager
	 *
	 * @param  object $content
	 * @return boolean
	 * @todo approve modifications
	 */
  function addContent(&$content) {
    $this->debug('ContentsManager::addContent, status : function invoked', 10, DBG_OPEN);
		$id = $content->getContentId();
		$typeName = $content->getContentTypeName();

		// check if content already exists
    if ($this->checkContent($id, $typeName)){
      $this->debug("ContentsManager::addContent, notice : content already loaded in contents manager.", 4);
		}

    // overwrite anyway
    $this->contentsTable[$typeName][$id] = &$content;

    $this->debug('ContentsManager::addContent, status : function completed', 10, DBG_CLOSE);
		return true;
	}

	/**
	 * Gets New Content
	 *
	 * @param  string  $typeName
	 * @param  integer $aclId
	 * @return mixed   object or <0 if error
	 */
	function &getNewContent($typeName, $aclId=0){
    $this->debug('ContentsManager::getNewContent, status : function invoked', 10, DBG_OPEN);
    $result = null;

		if(!($type = &$this->typesManager->getType($typeName))){
			$this->debug("ContentsManager::getNewContent, error : type '$typeName' unknown", 2);
		}
		else {
  		if (($typesTable = &$type->getFieldsTable()) < 0){
        $this->debug("ContentsManager::getNewContent, errror : unable to get fields for content '".$this->getId()."'.", 2);
      }
      else {
    		$langsArray = $this->getLangsArray();

    		foreach ($langsArray as $langId => $langName) {
    			foreach ($typesTable as $key => $value) {
            $defaultValue = '';
    				$valuesTable[$langId][$key] = &$this->typesManager->createTypeObject($value, $defaultValue);
    			}
        }

    		$id = 0	;
    		$deleted = 0;
    		$this->contentsTable[$typeName][0] = &new Content($id, $typeName, $valuesTable, $deleted, $aclId);
        $this->contentsTable[$typeName][0]->setContentPublished(PUBLICATION_DEFAULT_VALUE);
    		if($acl = &$this->getContentAcl($aclId)) {
    			$this->contentsTable[$typeName][0]->setContentAcl($acl);
    		}
    		else {
          $this->debug('ContentsManager::getNewContent, warning : unable to get acl object ('.$aclId.') for content', 3);
    		}
    		$result = &$this->contentsTable[$typeName][0];
      }
		}

    $this->debug('ContentsManager::getNewContent, status : function completed', 10, DBG_CLOSE);
		return $result;
	}

  function compareContents(&$contentObj1, &$contentObj2, $langId) {
    $this->debug('ContentsManager::compareContents, status : function invoked', 10, DBG_OPEN);
    $result = 0;
    if($contentObj1->getContentTypeName() != $contentObj2->getContentTypeName() || $contentObj1->getContentPublished() != $contentObj2->getContentPublished() || $contentObj1->getContentDeleted() != $contentObj2->getContentDeleted()) {
      $result = -1;
    }
    else {
      $typeName = $contentObj1->getContentTypeName();
  		if (!isset($this->contentsDescr[$typeName])) {
  		  $db = &$this->getDBManipulator();
  			$this->contentsDescr[$typeName] = $db->getFieldsArray(TYPE_TABLES_PREFIX.$typeName);
  		}
      foreach($this->contentsDescr[$typeName] as $field => $value) {
        if(($compare_result = $contentObj1->compareTo($contentObj2, $field, $langId)) != 0) {
          $result = $compare_result;
          break;
        }
      }
    }
    $this->debug('ContentsManager::compareContents, status : function completed', 10, DBG_CLOSE);
    return $result;
  }

	/**
	 * Gets Languages
	 *
	 * Returns associative array of available languages
	 *
	 * @return array
	 * @todo discussion about the right place for this function (managers interface ? / dbManipulator ?)
	 */
	function getLangsArray() {
		$dbManipulator = &$this->getDBManipulator();	
		$result        = $dbManipulator->getRecord(LANGUAGES_TABLE, -1, '', 'id', '`name`');
		if (!$result) {
			return null;
		}
		$langsArray = array();
		while ($row = $dbManipulator->fetchArray($result)) {
			$langId = (int )$row['id'];
			$langsArray[$langId] = $row['name'];
		}
		return $langsArray;
	}
	
	/**
	 * @param  integer $contentId
	 * @param  string  $typeName
	 * @return array
	 * @todo   discussion
	 */
	function getParentObjectValuesArray($contentId, $typeName) {
    $this->debug('ContentsManager::getParentObjectValuesArray, status : function invoked ('.$contentId.', '.$typeName.')', 10, DBG_OPEN);
    $result = null;
		$result_array = $this->dbManipulator->queryGetContainerOfContent($contentId, $typeName);
		
		if (!$result_array || !$this->dbManipulator->getNumRows()) {
      $this->debug('ContentsManager::getParentObjectValuesArray, warning : unable to get parent container of content', 3);
		}
		else {
  		$result = $this->dbManipulator->fetchArray($result_array);
    }
    $this->debug('ContentsManager::getParentObjectValuesArray, status : function completed', 10, DBG_CLOSE);
		return $result;
	}
	
	/**
	 * Updates Content `acl_id` field
	 *
	 * @param  integer $contentId Content ID
	 * @param  string $typeName Content Type
	 * @param  integer $aclId ACL ID
	 * @return boolean
	 */
	function updateContentACL($contentId, $typeName, $aclId) {
    $this->debug('ContentsManager::updateContentACL, status : function invoked', 10, DBG_OPEN);
    $result = true;
    $db = &$this->getDBManipulator();
    $fields = array('acl_id' => $aclId);

    if(!$db->setRecord(TYPE_TABLES_PREFIX.$typeName, -1, $fields, "`id` = '$contentId'")){
      $this->debug('ContentsManager::updateContentACL, error : unable to update modified content', 2);
			$result = false;
    }
    $this->debug('ContentsManager::updateContentACL, status : function completed', 10, DBG_CLOSE);
    return $result;
	}
	
} 
?>