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

/**
 * Tag element.
 *
 * @access     public
 * @author	   Cedric Francoys <cedric.francoys@easy-cms.org>
 * @version	   ActionTag.class, Mon Jan 03 23:20:14 CET 2005
 * @package	   Core
 * @subpackage Tags
 */
class ActionTag 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 ActionTag($tagString, $name, $type, $offset, $length){
		parent::Tag($tagString, $name, $type, $offset, $length);
	}

	/**
	* Performs actions specific to the tag
	* 
	* @access   public
 	* @return   bool Returns true if the current user is logged in, false otherwise.
	*/
	function evaluate(){
		$type = $this->getAttribute("type");
						
		switch($type){
			case "logon" :
				if(!$this->user->getUserId()) {
					return "javascript:launchLogonWindow();";
				}
				else {
					return "/index.php?pid=".$this->page->getPageId()."&action=logout";
				}
				break;
			case "mode" :
				if($this->acl->userHasEditRight($this->user)) {
					$html = "/index.php?pid=".$this->page->getPageId()."&mode=";
					$html .= ($this->mode == EDIT_MODE)?"view":"edit";
					return $html;
				}
				break;
			case "admin" :
				if(ENABLE_ADMIN_AREA == 1 && $this->user->checkGroupMembership(GROUP_ID_ADMINS)) {
					$html = "/admin/admin.php";
					return $html;
				}
				break;
			case "add_page" :
				if(ENABLE_PAGES_CREATION == 1 && $this->acl->userHasEditRight($this->user)) {
					$html = "javascript:launchPageEditionWindow('parent_id=".$this->page->getPageId()."');";
					return $html;
				}
				break;
			case "remove_page" :
				if($this->acl->userHasRemoveRight($this->user)) {
					$html = "javascript:launchPageDeletionWindow('page_id=".$this->page->getPageId()."');";
					return $html;
				}
				break;
			default :
				return $this->tagString;
				break;
		}
		
		return "";
	}
	
} 

?>
