<?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
*/
	
include_once('classes/core/parser/tags/Tag.class.php');
include_once('classes/core/Site.class.php');

/**
* Tag element.
*
* @access   public
* @author	Cedric Francoys <cedric.francoys@easy-cms.org>
* @version	ContainerIdTag.class, Sun Dec 26 18:03:59 CET 2004
* @package	Tags
*/
class ContainerIdTag extends Tag{
	
	/**
	* Constructor
	* 
	* @access   public
 	* @param    string  The complete tag syntax (i.e. : <tagname attr1="value1" attr2="value2">, <br />, </a>, ...)
 	* @param    integer The position of the tag in the xml document
 	* @return   void  
	*/	 	
	function ContainerIdTag($tagString, $name, $type, $offset, $length){
		parent::Tag($tagString, $name, $type, $offset, $length);
	}

	/**
	* Performs actions specific to the tag
	* 
	* @access   public
 	* @return   bool Returns the HTML part corresponding to the container.
	*/
	function evaluate(){
		
		$site = &Site::getInstance();
		$frameId = &$this->page->getFrameId();
		
		$containersManager = &$site->getContainersManager();
		$dbManipulator = &$site->getDBManipulator();
		
		$frameContainerName = $this->getAttribute("id");
		

		if (($result = &$dbManipulator->getRecord(FRAME_CONTAINERS_TABLE, $frameId, "container_name = '$frameContainerName' and page_id='".$this->page->getId()."'", "frame_id")) < 0 ){
	      		$this->debug("Frame.getHTML, error : unable to read DB for frame '".$frameId."'.", 2);
			return "";
	    	}
	
		if(!($row = &$dbManipulator->fetchArray($result))){
		      	//container does not exist (yet)
			//then the function returns an empty string
			$this->debug("Frame.getHTML, notice : non-existent container.", 5);
			return "";
		}
		else {        
			$containerId = $row["container_id"];
	    	}
	
		if(($container = $containersManager->getContainer($containerId)) <= 0){
			$this->debug("Frame.getHTML, error : unable to get container '$frameContainerName' for frame '".$this->getId()."'.", 2);
			return "";
		}
	
		$this->debug("ContainerIdTag.evaluate, success.", 10);

		return $containerId;
	}
} 
?>