-<?\r
-\r
-require_once 'HTML/Table.php';\r
-require_once 'HTML/Image.php';\r
-\r
-class HTML_Arbol extends HTML_Table\r
-{\r
- var $t_interna;\r
- \r
- function HTML_Arbol($dat, $imagen)\r
- {\r
- parent::HTML_Table(array ('width'=>'132',\r
- 'border' => '0',\r
- 'cellspacing' => '0',\r
- 'cellpadding' => '0',\r
- 'bgcolor' => '#003868'));\r
- $this->t_interna = new HTML_Table(array ('width'=>'132',\r
- 'border' => '0',\r
- 'cellspacing' => '2',\r
- 'cellpadding' => '0',\r
- 'class' => 'bodytext'));\r
- $this->addRow(array(new HTML_Image($imagen,'',array('width'=>'132',\r
- 'height'=>'26',\r
- 'border'=>'0'))));\r
- $this->expandir($dat, 0);\r
- }\r
- \r
- function expandir($dat, $n)\r
- {\r
- $imagen = '';\r
- $bullets = array('',\r
- '/MECON/images/arbol_bullet_1.gif',\r
- '/MECON/images/arbol_bullet_2.gif',\r
- '/MECON/images/arbol_bullet_3.gif');\r
- $tabulados = array(0, 7, 13, 20);\r
- $classes = array('menu', 'menu1', 'menu1', 'menu2');\r
- \r
- $atr = array('border' => '0',\r
- 'width' => $tabulados[$n],\r
- 'height' => '10');\r
- $imagen =& new HTML_Image($bullets[$n], 'bullet', $atr);\r
- foreach($dat as $e)\r
- {\r
- $e['titulo'] = $imagen->toHTML().$e['titulo'];\r
- if(isset($e['activado']) && $e['activado'] != 0) $class = 'menu_activo';\r
- else $class = $classes[$n];\r
- if(!is_null($e['link']))\r
- $e['titulo'] = '<a href="'.$e['link'].'" class="'.$class.'">'.$e['titulo'].'</a>';\r
- $this->t_interna->addRow(array($e['titulo']), array('class' => $class));\r
- if(isset($e['sub']))\r
- $this->expandir($e['sub'], $n+1);\r
- }\r
- }\r
-\r
- function toHTML()\r
- {\r
- echo '<link rel="stylesheet" href="/MECON/css/arbol.css">';\r
- $this->addRow(array($this->t_interna->toHTML()));\r
- return parent::toHTML();\r
- }\r
-};\r
-\r
-?>\r
+<?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
+-------------------------------------------------------------------------------
+ Ministerio de Economía
+ meconlib
+-------------------------------------------------------------------------------
+This file is part of meconlib.
+
+meconlib 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.
+
+meconlib 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; if not,
+write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+Boston, MA 02111-1307 USA
+-------------------------------------------------------------------------------
+Creado: jue jul 17 15:32:52 ART 2003
+Autor: Gonzalo Merayo <gmeray@mecon.gov.ar>
+ Leandro Lucarella <llucar@mecon.gov.ar>
+-------------------------------------------------------------------------------
+$Id$
+-----------------------------------------------------------------------------*/
+
+require_once 'HTML/Table.php';
+require_once 'HTML/Image.php';
+
+class HTML_Arbol extends HTML_Table
+{
+ var $datos;
+ var $titulo;
+ var $link_append;
+
+ /**
+ * Constructor.
+ *
+ * @param array $datos Datos con los cuales construir el árbol.
+ * @param string $titulo Título.
+ * @param int $raiz Nodo raíz (de donde empezar a dibujar el árbol).
+ */
+ function HTML_Arbol($datos, $titulo, $link_append = '')
+ {
+ parent::HTML_Table(array(
+ 'width' => '132',
+ 'border' => '0',
+ 'cellspacing' => '0',
+ 'cellpadding' => '0',
+ 'bgcolor' => '#003868'));
+ $this->datos = $datos;
+ $this->titulo = $titulo;
+ $this->link_append = $link_append;
+ }
+
+ function getCSS() {
+ return '/MECON/css/arbol';
+ }
+
+ function expandir($dat, $n, &$tabla)
+ {
+ $bullets = array(
+ '',
+ '/MECON/images/arbol_bullet_1.gif',
+ '/MECON/images/arbol_bullet_2.gif',
+ '/MECON/images/arbol_bullet_3.gif'
+ );
+ $alts = array(
+ '',
+ '*',
+ '-',
+ '·'
+ );
+ $classes = array('menu', 'menu1', 'menu1', 'menu2');
+ $tabulados = 7;
+ $atr = array(
+ 'border' => '0',
+ 'width' => $n * $tabulados,
+ 'height' => '10'
+ );
+ $margen = ' ';
+ if ($n) {
+ $margen = new HTML_Image('/MECON/images/blanco.gif', str_repeat(' ', $n), $atr);
+ $margen = $margen->toHtml();
+ }
+ $imagen = '';
+ if (@$bullets[$n]) {
+ $imagen = new HTML_Image($bullets[$n], @$alts[$n]);
+ $imagen = $imagen->toHtml();
+ }
+ foreach ($dat as $e) {
+ $titulo = $margen.$imagen.$e['titulo'];
+ if(isset($e['activo']) && $e['activo'] != 0) $class = 'menu_activo';
+ else $class = $classes[$n];
+ if(!is_null($e['link'])) {
+ $link = $e['link'];
+ if ($this->link_append and @$e['id']) {
+ $link .= $this->link_append . $e['id'];
+ }
+ $titulo = '<a href="'.$link.'" class="'.$class.'">'.$titulo.'</a>';
+ }
+ $tabla->addRow(array($titulo), array('class' => $class));
+ if(isset($e['sub'])) {
+ $this->expandir($e['sub'], $n+1, $tabla);
+ }
+ }
+ }
+
+ function toHTML()
+ {
+ $this->setRowCount(0);
+ $t_interna = new HTML_Table(array(
+ 'width' =>'132',
+ 'border' => '0',
+ 'cellspacing' => '2',
+ 'cellpadding' => '0',
+ 'class' => 'bodytext'));
+ $titulo = new HTML_Table(array(
+ 'width' => '132',
+ 'height' => '26',
+ 'border' => '0',
+ 'cellspacing' => '0',
+ 'cellpadding' => '0',
+ 'align' => 'center',
+ 'background' => '/MECON/images/arbol_titulo.gif'));
+ $titulo->addRow(array($this->titulo), array(
+ 'align' => 'center',
+ 'class' => 'arboltitulo'));
+ $this->addRow(array($titulo), array('bgcolor' => '#FFFFFF'));
+ $this->expandir($this->datos, 0, $t_interna);
+ $this->addRow(array($t_interna->toHTML()));
+ // FIXME - sacar la style sheet de aca.
+ return '<link rel="stylesheet" href="'.$this->getCSS().'">'.parent::toHTML();
+ }
+
+ function expandirArray($dat, $n, $filtrarActivos)
+ {
+ $array = array();
+ foreach ($dat as $e) {
+ // Si no tiene ID o esta activo y se filtran los activos, se
+ // continua con el proximo item.
+ if (!@$e['id'] or $filtrarActivos and @$e['activo']) {
+ continue;
+ }
+ $array[$e['id']] = str_repeat(' ', $n) . $e['titulo'];
+ if(@$e['sub']) {
+ $array += $this->expandirArray($e['sub'], $n + 1, $filtrarActivos);
+ }
+ }
+ return $array;
+ }
+
+ function toArray($filtrarActivos = true)
+ {
+ return $this->expandirArray($this->datos, 0, $filtrarActivos);
+ }
+
+ function expandirString($dat, $n, $filtrarActivos)
+ {
+ $str = '';
+ $tot = count($dat);
+ for ($i = 0; $i < $tot; $i++) {
+ $e = $dat[$i];
+ // Si no tiene ID o esta activo y se filtran los activos, se
+ // continua con el proximo item.
+ if (!@$e['id'] or $filtrarActivos and @$e['activo']) {
+ continue;
+ }
+ $indent = str_repeat('| ', $n);
+ if ($i == ($tot - 1)) {
+ $indent .= '`- ';
+ } else {
+ $indent .= '|- ';
+ }
+ $str .= $indent . $e['titulo'] . "\n";
+ if(@$e['sub']) {
+ $str .= $this->expandirString($e['sub'], $n + 1, $filtrarActivos);
+ }
+ }
+ return $str;
+ }
+
+ function toString($filtrarActivos = true)
+ {
+ return $this->expandirString($this->datos, 0, $filtrarActivos);
+ }
+
+ /**
+ * Activa un nodo del árbol.
+ *
+ * @param int $id Id del nodo a modificar.
+ * @param bool $activo Nuevo valor, true si está activo, false si no.
+ *
+ * @return bool True si se pudo modificar.
+ */
+ function setActivo($id, $activo = 1) {
+ return $this->modificarNodo($this->datos, $id, 'activo', $activo);
+ }
+
+ /**
+ * Modifica un nodo del array.
+ *
+ * @param array $datos Datos del árbol a modificar.
+ * @param int $id Id del elemento a modificar.
+ * @param string $key Clave del dato a modificar.
+ * @param mixed $val Nuevo valor.
+ *
+ * @return bool True si se pudo modificar.
+ */
+ function modificarNodo(&$datos, $id, $key, $val) {
+ foreach (array_keys($datos) as $k) {
+ if (@$datos[$k]['id'] == $id) {
+ $datos[$k][$key] = $val;
+ return true;
+ } elseif (@$datos[$k]['sub']
+ and $this->modificarNodo($datos[$k]['sub'], $id, $key, $val)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+};
+
+?>