- <?php
-
-
- /**
- * TCssDropDownMenuNode class file
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the BSD License.
- *
- * Copyright(c) 2004 by Scott Fuelberth.
- *
- * To contact the author write to {@link mailto:skot@bastardcat.org Scott Fuelberth}
- * The latest version of PRADO can be obtained from:
- * {@link http://prado.sourceforge.net/}
- *
- * =================================================
- * NOTICE: This is an pre-alpha version for PRADO v3
- * author: Tobias Munk <webmaster@lithron.de>
- * =================================================
- *
- * @author Scott Fuelberth <skot@bastardcat.org>
- * @version $Revision: 188 $ $Date: 2006-05-11 10:50:16 +0200 (Do, 11 Mai 2006) $
- * @package Lithron.LCssDropDownMenu
- * @subpackage WebControls
- */
-
- /**
- * TCssDropDownMenuNode class
- *
- * TCssDropDownMenuNode displays a css driven menu item. You can set the link through the
- * through the <b>LinkUrl</b> property. You can set the Text displayed for the item through the <b>Text</b> property.
- * You can set the roles that are allowed to access the item through the <b>Roles</b> property.
- *
- * Example: <code><com:TCssDropDownMenuNode ID="ViewUsers" LinkUrl="?page=ViewUsersPage"
- * Text="View Users" Roles="root,admin" BorderColor="green" BorderStyle="solid" BorderWidth="1" BackColor="white"/></code>
- *
- * Namespace: Lithron.Web.UI.WebControls
- *
- * Properties
- * - <b>LinkUrl</b>, string, kept in viewstate
- * <br/>Set the link for the item.
- * - <b>Text</b>, string, kept in viewstate
- * <br/>Set the text for the item.
- * - <b>Roles</b>, string, kept in viewstate
- * <br/>The user roles allowed to view the item.
- *
- * @package System.Web.UI.WebControls
- */
- class LCssDropDownMenuNode extends TWebControl
- {
-
- /**
- * top parent flag
- * @var boolean
- */
- private $isTopParent= false;
-
- /**
- * top parent css class name
- * @var string
- */
- private $topParentNodeCssClass= '';
-
- /**
- * parent node css class name
- * @var string
- */
- private $parentNodeCssClass= '';
-
- /**
- * node css class name
- * @var string
- */
- private $nodeCssClass= '';
-
- /**
- * disabled node css class name
- * @var string
- */
- private $disabledNodeCssClass= '';
-
- private $_tagName;
-
- protected function getTagName()
- {
- return $this->_tagName;
- }
-
- function setTagName($value)
- {
- $this->_tagName= $value;
- }
-
- /**
- * Constructor.
- * Sets TagName property to 'li'
- */
- function __construct()
- {
- parent :: __construct();
- $this->setTagName('li');
- }
-
- /**
- * @return string the Roles allowd to view this element
- */
- public function getRoles()
- {
- return $this->getViewState('Roles', '');
- }
-
- /**
- * @param string the Roles allowed to view this element
- */
- public function setRoles($value)
- {
- $this->setViewState('Roles', $value, '');
- }
-
- /**
- * @return string the LinkUrl of the node
- */
- public function getLinkUrl()
- {
- return $this->getViewState('LinkUrl', '');
- }
-
- /**
- * @param string the LinkUrl of the node
- */
- public function setLinkUrl($value)
- {
- $this->setViewState('LinkUrl', $value, '');
- }
- /**
- * @return string the LinkId of the node (service)
- */
- public function getLinkId()
- {
- return $this->getViewState('LinkId', '');
- }
-
- /**
- * @param string the LinkId of the node (service)
- */
- public function setLinkId($value)
- {
- $this->setViewState('LinkId', $value, '');
- }
-
- /**
- * @return string the Text of the node
- */
- public function getText()
- {
- return $this->getViewState('Text', '');
- }
-
- /**
- * @param string the Text of the node
- */
- public function setText($value)
- {
- $this->setViewState('Text', $value, '');
- }
-
- /**
- * @return string the link Target
- */
- public function getTarget()
- {
- return $this->getViewState('Target', '');
- }
-
- /**
- * @param string the link target
- */
- public function setTarget($value)
- {
- $this->setViewState('Target', $value, '');
- }
-
- /**
- * @return bool top parent flag
- */
- public function isTopParent()
- {
- return $this->isTopParent;
- }
-
- /**
- * @param bool the top parent flag
- */
- public function setTopParent($value)
- {
- $this->isTopParent= $value;
- }
-
- /**
- * @return string the top parent css class
- */
- public function getTopParentNodeCssClass()
- {
- return $this->topParentNodeCssClass;
- }
-
- /**
- * #param string the top parent css class
- */
- public function setTopParentNodeCssClass($value)
- {
- $this->topParentNodeCssClass= $value;
- }
-
- /**
- * @return string the parent css class
- */
- public function getParentNodeCssClass()
- {
- return $this->parentNodeCssClass;
- }
-
- /**
- * @param string the parent css class
- */
- public function setParentNodeCssClass($value)
- {
- $this->parentNodeCssClass= $value;
- }
-
- /**
- * @param string the node css class
- */
- public function setNodeCssClass($value)
- {
- $this->nodeCssClass= $value;
- }
-
- /**
- * @return string the node css class
- */
- public function getNodeCssClass()
- {
- return $this->nodeCssClass;
- }
-
- /**
- * @param string the node css class
- */
- public function setDisabledNodeCssClass($value)
- {
- $this->disabledNodeCssClass= $value;
- }
-
- /**
- * @return string the node css class
- */
- public function getDisabledNodeCssClass()
- {
- return $this->disabledNodeCssClass;
- }
-
- /**
- * @param sets selected status
- */
- public function setSelectedPath($value)
- {
- $this->setViewState("SelectedPath", $value);
- if ($this->Parent instanceof LCssDropDownMenuNode)
- {
- #echo "parent";
- $this->Parent->setSelectedPath($value);
- }
- }
-
- /**
- * @return gets selected status
- */
- public function getSelectedPath()
- {
- return $this->getViewState("SelectedPath");
- }
-
- /**
- * Renders the menu.
- * Will go through all TCssDropDownMenuNode children and render them
- * at the correct place.
- * @return void
- */
- public function renderContents($writer)
- {
-
- $user= $this->getPage()->getUser();
- if (!is_null($user))
- {
- if (!$user->isInRole($this->getRoles()))
- {
- #return null; TEMP HACK - TODO
- //return $content;
- }
- }
-
- if ($this->getEnabled())
- {
- if ($this->isTopParent())
- {
- $cssClass= $this->getTopParentNodeCssClass();
- }
- elseif ($this->getControls()->getCount())
- {
- $cssClass= $this->getParentNodeCssClass();
- $cssClass .= $this->getNodeCssClass() . "parent"; // TODO
- }
- else
- {
- $cssClass= $this->getNodeCssClass();
- }
- }
- else
- {
- $this->setLinkUrl(false);
- $cssClass= $this->getDisabledNodeCssClass();
- }
-
- $style= $this->getStyle();
- if (($width= $this->getWidth()) > 0)
- $style['width']= $width . 'px';
- if (($height= $this->getHeight()) > 0)
- $style['height']= $height . 'px';
- $foreColor= $this->getForeColor();
- if (strlen($foreColor))
- $style['color']= $foreColor;
- $s= '';
- if (count($style) > 0)
- {
- foreach ($style as $k => $v)
- $s .= "$k:$v;";
- }
-
- if ($s == null || $s == "")
- {
- $styleString= "";
- }
- else
- {
- $styleString= 'style="' . $s . '"';
- }
-
- #TODO -------------------------------------
- $_id= $this->getLinkId();
- #$_id = 22;
- if (empty ($_id))
- {
- $_p= $_url= $this->getLinkUrl();
- preg_match("/=(.*)&?/", $_url, $match);
- if (isset ($match[0]))
- {
- $_p= str_replace("=", "", $match[0]);
- $_p= str_replace(strstr($_p, "&"), "", $_p);
- }
- $link= $this->Service->constructUrl($_p);
- }
- else
- $link= $this->Service->constructUrl($_id);
-
- $page= $this->Service->constructUrl($this->Service->getServicePage());
- #echo $link . "<hr>" . $page;
- if ($link == $page)
- {
- $cssClass= $cssClass . " selected";
- $this->setSelectedPath(true);
- }
- if ($this->getSelectedPath() === true)
- {
- $cssClass= $cssClass . " selectedPath"; # TODO does not work, we are already in render :( FIXME
- }
-
- if ($cssClass == null || $cssClass == "")
- {
- $cssString= '';
- }
- else
- {
- $cssString= 'class="' . $cssClass . '"';
- }
-
- if (strlen($this->getLinkUrl()))
- {
- if (strlen($this->getTarget()))
- {
-
- $link= '<a href="' . $this->getLinkUrl() . '" ' . $styleString . ' ' . $cssString . ' target="' . $this->getTarget() . '" >' . $this->getText() . '</a>';
- }
- else
- {
- $link= '<a href="' . $this->getLinkUrl() . '" ' . $styleString . ' ' . $cssString . ' >' . $this->getText() . '</a>';
- }
- }
- else
- {
- $link= '<span ' . $styleString . ' ' . $cssString . ' >' . $this->getText() . '</span>';
- }
- $writer->write($link);
-
- $body= $this->getControls()->getCount();
- if ($body)
- {
- $writer->renderBeginTag('ul');
- foreach ($this->getControls() as $item)
- {
- if ($item instanceof LCssDropDownMenuNode)
- {
-
- $item->setTopParent(false);
- $item->setTopParentNodeCssClass($this->getTopParentNodeCssClass());
- $item->setParentNodeCssClass($this->getParentNodeCssClass());
- $item->setNodeCssClass($this->getNodeCssClass());
- $item->setDisabledNodeCssClass($this->getDisabledNodeCssClass());
- if ($item->getVisible())
- {
- $item->render($writer);
- }
- }
- }
- $writer->renderEndTag('ul');
- }
- #Prado :: trace("Returning node children content", 'Lithron.LCssDrownDownMenu');
- }
- }
- ?>