-<?\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
-/* $titulo = new HTML_Table(array('width'=>'132',\r
- 'height'=>'26',\r
- 'border' => '0',\r
- 'cellspacing' => '0',\r
- 'cellpadding' => '0',\r
- 'align'=>'center',\r
- 'background'=>'/MECON/images/arbol_titulo.gif'));\r
- $titulo->addRow(array('<font size="2"><b class="arbol_titulo">aa</b></font>'), array('align'=>'center'));\r
- $this->addRow(array($titulo));*/\r
- $this->addRow(array('<table width="132" border="0" cellspacing="0" cellpadding="0" background="/MECON/images/arbol_titulo.gif" height="26">\r
- <tr align="center"> \r
- <td><font size="2"><b class="arbol_titulo">NOTICIAS</b></font></td>\r
- </tr>\r
- </table>'));\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 'MECON/HTML/Image.php';
+
+/**
+ * DESC
+ *
+ * @access public
+ */
+class MECON_HTML_Arbol extends HTML_Table
+{
+
+ /**
+ * DESC
+ *
+ * @var TIPO $datos
+ * @access public
+ */
+ var $datos;
+
+ /**
+ * DESC
+ *
+ * @var TIPO $titulo
+ * @access public
+ */
+ var $titulo;
+
+ /**
+ * DESC
+ *
+ * @var string $link_append
+ * @access public
+ */
+ var $link_append;
+
+ /**
+ * Constructor.
+ *
+ * @param array $datos Datos con los cuales construir el árbol.
+ * @param string $titulo Título.
+ * @param string $link_append DESC.
+ *
+ * @return void
+ * @access public
+ */
+ function MECON_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;
+ }
+
+ /**
+ * Devuelve el path del stylesheet de esta clase
+ *
+ * @retur string
+ * @access public
+ */
+ function getCSS() {
+ return '/MECON/css/arbol';
+ }
+
+ /**
+ * DESC
+ *
+ * @param TIPO $dat DESC
+ * @param TIPO $n DESC
+ * @param TIPO &$tabla DESC
+ *
+ * @return TIPO
+ * @access public
+ */
+ 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' => '1'
+ );
+ $margen = ' ';
+ if ($n) {
+ $margen = new MECON_HTML_Image('/MECON/images/blanco.gif', str_repeat(' ', $n), $atr);
+ $margen = $margen->toHtml();
+ }
+ $imagen = '';
+ if (@$bullets[$n]) {
+ $imagen = new MECON_HTML_Image($bullets[$n], @$alts[$n]);
+ $imagen = $imagen->toHtml();
+ }
+ foreach ($dat as $e) {
+ $titulo = $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>';
+ }
+ $titulo = '<table border=0 cellpadding=0 cellspacing=0><tr><td valign="top">'.$margen.$imagen.'</td><td>'.$titulo.'</td></tr></table>';//TODO
+ $tabla->addRow(array($titulo), array('class' => $class));
+ if(isset($e['sub'])) {
+ $this->expandir($e['sub'], $n+1, $tabla);
+ }
+ }
+ }
+
+ /**
+ * Devuelve el html a imprimir
+ *
+ * @return string
+ * @access public
+ */
+ 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()));
+ return parent::toHTML();
+ }
+
+ /**
+ * DESC
+ *
+ * @param TIPO $dat DESC
+ * @param TIPO $n DESC
+ * @param TIPO $filtarActivos DESC
+ *
+ * @return array
+ * @access public
+ */
+ 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;
+ }
+
+ /**
+ * DESC
+ *
+ * @param bool $filtrarActivos DESC
+ *
+ * @return array
+ * @access public
+ */
+ function toArray($filtrarActivos = true)
+ {
+ return $this->expandirArray($this->datos, 0, $filtrarActivos);
+ }
+
+ /**
+ * DESC
+ *
+ * @param TIPO $dat DESC
+ * @param TIPO $n DESC
+ * @param TIPO $filtarActivos DESC
+ *
+ * @return string
+ * @access public
+ */
+ 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;
+ }
+
+ /**
+ * DESC
+ *
+ * @param bool $filtrarActivos DESC
+ *
+ * @return string
+ * @access public
+ */
+ 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.
+ * @access public
+ */
+ 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.
+ * @access public
+ */
+ 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;
+ }
+
+};
+
+?>