-<?
-
+<?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:33:41 ART 2003
+Autor: Gonzalo Merayo <gmeray@mecon.gov.ar>
+-------------------------------------------------------------------------------
+$Id$
+-----------------------------------------------------------------------------*/
+require_once 'MECON/HTML/Arbol.php';
+require_once 'DB.php';
class HTML_ArbolDB extends HTML_Arbol
{
- function ArbolDB()
+ var $padre = null;
+ var $tabla;
+ var $nombre;
+ var $id;
+ var $link = null;
+ var $prepend_link = null;
+ var $where = '';
+ var $order = '';
+ var $db;
+
+ function HTML_ArbolDB($dbdata, $imagen)
+ {
+ if(isset($dbdata['id_padre']))
+ $this->padre = $dbdata['id_padre'];
+ $this->tabla = $dbdata['tabla'];
+ $this->nombre = $dbdata['nombre'];
+ $this->id = $dbdata['id'];
+ if(isset($dbdata['prepend_link']))
+ $this->prepend_link = $dbdata['prepend_link'];
+ if(isset($dbdata['link']))
+ $this->link = $dbdata['link'];
+ if(isset($dbdata['where']))
+ $this->where = $dbdata['where'];
+ if(isset($dbdata['order']))
+ $this->order = ' ORDER BY '.$dbdata['nombre'].' '.$dbdata['order'];
+ $this->db = $dbdata['db'];
+ $dat = $this->BuscarHijos(0);
+ parent::HTML_Arbol($dat, $imagen);
+ }
+
+ function BuscarHijos($id)
{
- $dat = array(
- array(
- 'titulo' => 'Nivel0a',
- 'link' => 'blabla',
- 'sub' => array(//sub0
- array(
- 'titulo' => 'Nivel1a',
- 'link' => 'blabla',
- 'sub' => array(//sub1
- array(
- 'titulo' => 'Nivel3a',
- 'link' => 'blabla',
- 'activado' => 1
- ),
- array(
- 'titulo' => 'Nivel3b',
- 'link' => 'blabla',
- 'sub' => array(//sub2
- array(
- 'titulo' => 'Nivel4',
- 'link' => 'blabla'
- )
- )//sub2
- ),
- array(
- 'titulo' => 'Nivel3c',
- 'link' => 'blabla'
- )
- )//sub1
- ),
- array(
- 'titulo' => 'Nivel1b',
- 'link' => 'blabla',
- 'activado' => 1
- ),
- array(
- 'titulo' => 'Nivel1c',
- 'link' => 'blabla'
- )
- )//sub0
- ),
- array(
- 'titulo' => 'Nivel0b',
- 'link' => 'blabla'
- ),
- array(
- 'titulo' => 'Nivel0c',
- 'link' => 'blabla'
- )
- );
+ $sql = "SELECT $this->nombre, $this->id ";
+ if(!is_null($this->link))
+ $sql .= ", $this->link ";
+ $sql .= "FROM $this->tabla ";
+ if(!is_null($this->padre) or $this->where)
+ $sql .= 'WHERE ';
+ if(!is_null($this->padre)) {
+ $sql .= "$this->padre = '$id'";
+ if ($this->where)
+ $sql .= ' AND';
+ } elseif ($this->where)
+ $sql .= $this->where;
+ $sql .= $this->order;
+ $result = $this->db->query($sql);
+ if(DB::isError($result))
+ die($result->getMessage());
+ $dat = array();
+ while($row = $result->fetchRow())
+ {
+ $titulo = $row[0];
+ $id = $row[1];
+ if(is_null($this->padre)) $sub = array();
+ else $sub = $this->BuscarHijos($id);
+ if(!is_null($this->link)) $link = $this->prepend_link.$row[2];
+ else $link = $this->prepend_link.$id;
+ $dat[] = array(
+ 'titulo'=> $titulo,
+ 'link' => $link,
+ 'sub' => $sub
+ );
+ }
+ return $dat;
- parent::Arbol($dat);
}
-}
+}
?>