- <?php
-
-
- /**
- * Menu class file.
- *
- * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
- * @copyright 2005, diemeisterei GmbH. All rights reserved.
- * @author $Author: schmunk $
- * @version $Revision: 128 $ $Date: 2006-04-25 15:50:26 +0000 (Di, 25 Apr 2006) $
- * @package Lithron.LVirtualNodes
- * @subpackage WebControls
- */
-
- /**
- * Displays and manages the CSS menu (sitemap tree)
- *
- * @package System.Web.UI.WebControls
- * @subpackage Admin
- */
-
- class LSitenodeSelection extends TPanel
- {
- public function getMode()
- {
- return $this->getViewState("mode", "select");
- }
-
- public function setMode($mode)
- {
- $this->setViewState("mode", $mode, "select");
- }
-
- public function getSelectedValue()
- {
- return $this->getViewState("sel", "1");
- }
-
- public function setSelectedValue($sel)
- {
- $this->setViewState("sel", $sel, "1");
- }
-
- function onLoad($param)
- {
- parent :: onLoad($param);
- $root = $this->Service->getNodes();
- $this->setStyle("font-family: Andale mono, Courier new, monospace;");
- $this->genTree($root);
- }
-
-
- private function genTree($node, $level = 0, $first = true)
- {
-
- // generate tree-like prefix
- $trace = $node;
- $prefix = "";
- for ($i = 0; $i < $level; $i++)
- {
- $trace = $trace->getParentNode();
- if ($trace->getSiblingNode() || $this->Mode == "insert")
- $prefix = "| ".$prefix;
- else
- $prefix = " ".$prefix;
- }
- if ($level != 0) $prefix .= ($node->getSiblingNode() || $this->Mode == "insert" ? "|" : "+")."--";
- $prefix = substr($prefix, $this->Mode == "insert" ? 13 : 18);
-
- // generate Insert-Before-Box
- if ($this->Mode == "insert" && $level != 0 && $first)
- {
- $rb = Prado::createComponent("LSitenodeRadioButton");
- $rb->setGroupName($this->getClientID(false));
- $rb->setParameter($node->getPath());
- $rb->OnCheckedChanged[] = array($this, "radioToggled");
- $this->Controls[] = $prefix;
- $this->Controls[] = $rb;
- $this->Controls[] = "<br/>";
- if (!$this->Page->IsPostBack) $rb->setChecked($node->getPath() == $this->getSelectedValue());
- }
-
- // generate Current-Node-Box
- if ($this->Mode != "select")
- {
- $this->Controls[] = $prefix.$node->getAlias();
- $this->Controls[] = "<br/>";
- }
- else
- {
- $rb = Prado::createComponent("LSitenodeRadioButton");
- $rb->setGroupName($this->getClientID(false));
- $rb->setParameter($node->getPath());
- $rb->OnCheckedChanged[] = array($this, "radioToggled");
- if ($prefix) $this->Controls[] = $prefix;
- $this->Controls[] = $rb;
- $this->Controls[] = $node->getAlias();
- $this->Controls[] = "<br/>";
- if (!$this->Page->IsPostBack) $rb->setChecked($node->getPath() == $this->getSelectedValue());
- }
-
- // generate Children
- $subnode = $node->getFirstChildNode();
- $fn = $subnode;
- if (!$subnode && $this->Mode == "insert")
- {
- // generate Node-Child-Insertion-Box
- $rb = Prado::createComponent("LSitenodeRadioButton");
- $rb->setGroupName($this->getClientID(false));
- $otherprefix = substr($prefix, 0, strlen($prefix)-2);
- $rb->setParameter($node->getPath().".1");
- $rb->OnCheckedChanged[] = array($this, "radioToggled");
- $this->Controls[] = $otherprefix." +--";
- $this->Controls[] = $rb;
- $this->Controls[] = "<br/>";
- }
- while ($subnode)
- {
- $this->genTree($subnode, $level+1, $fn == $subnode);
- $subnode = $subnode->getSiblingNode();
- }
-
- // generate Insert-After-Box
- if ($this->Mode == "insert" && $level != 0)
- {
- $parr = explode(".", $node->getPath());
- $parr[count($parr)-1]++;
- $p = implode(".", $parr);
- if (!$node->getSiblingNode()) $prefix[strlen($prefix)-3] = "+";
- $rb = Prado::createComponent("LSitenodeRadioButton");
- $rb->setGroupName($this->getClientID(false));
- $rb->setParameter($p);
- $rb->OnCheckedChanged[] = array($this, "radioToggled");
- $this->Controls[] = $prefix;
- $this->Controls[] = $rb;
- $this->Controls[] = "<br/>";
- if (!$this->Page->IsPostBack) $rb->setChecked($p == $this->getSelectedValue());
- }
- }
-
-
- public function radioToggled($sender, $param)
- {
- //echo "toggle from ".$sender->Parameter." to ".($sender->getChecked()?"on":"off")."<br>";
- $this->setSelectedValue($sender->Parameter);
- }
-
- }
- ?>