1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
4 -------------------------------------------------------------------------------
5 This file is part of mlib.
7 mlib is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your option)
12 mlib is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License; if not,
17 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------
20 Creado: jue jul 17 15:33:41 ART 2003
21 Autor: Gonzalo Merayo <gmeray@mecon.gov.ar>
22 Leandro Lucarella <llucar@mecon.gov.ar>
23 -------------------------------------------------------------------------------
25 -----------------------------------------------------------------------------*/
27 require_once 'MLIB/HTML/Arbol.php';
28 require_once 'DB.php';
35 class MLIB_HTML_ArbolDB extends MLIB_HTML_Arbol
73 * @var TIPO $id_activo
89 * @var string $link_append
92 var $link_append = '';
121 * @param TIPO $dbdata DESC
122 * @param TIPO $titulo DESC
123 * @param string $link_append DESC
128 function MLIB_HTML_ArbolDB($dbdata, $titulo, $link_append = '', $expandir = false)
130 if(isset($dbdata['id_padre']))
131 $this->padre = $dbdata['id_padre'];
132 $this->tabla = $dbdata['tabla'];
133 $this->nombre = $dbdata['nombre'];
134 $this->id = $dbdata['id'];
135 $this->id_activo = @$dbdata['id_activo'];
136 // FIXME - Deprecated!
137 if(isset($dbdata['prepend_link']))
138 $link_append = $dbdata['prepend_link'];
139 if(isset($dbdata['link']))
140 $this->link = $dbdata['link'];
141 if(isset($dbdata['where']))
142 $this->where = $dbdata['where'];
143 if(isset($dbdata['habilitado']))
144 $this->habilitado = $dbdata['habilitado'];
145 if(isset($dbdata['order']))
146 $this->order = ' ORDER BY '.$dbdata['nombre'].' '.$dbdata['order'];
147 $this->db = $dbdata['db'];
151 $this->expandir = array($this->id_activo);
152 if(isset($this->id_activo))
154 $id = $this->id_activo;
157 $sql = "SELECT $this->padre
159 WHERE $this->id = '".$id."'";
160 $id = $this->db->getOne($sql);
161 $this->expandir[] = $id;
166 parent::MLIB_HTML_Arbol(array(), $titulo, $link_append);
167 $this->datos = $this->BuscarHijos(0);
173 * @param TIPO $id DESC
178 function BuscarHijos($id)
180 $sql = "SELECT $this->nombre, $this->id ";
182 $sql .= ", $this->link ";
183 $sql .= "FROM $this->tabla ";
184 if($this->padre or $this->where)
187 $sql .= "$this->padre = '$id'";
190 } elseif ($this->where)
191 $sql .= $this->where;
192 if(isset($this->habilitado))
193 $sql .= " AND ".$this->habilitado." = 1 ";
194 $sql .= $this->order;
195 $result = $this->db->query($sql);
196 if(DB::isError($result))
197 die($result->getMessage());
199 while($row = $result->fetchRow())
203 if(!$this->padre || !(!isset($this->expandir) ||
204 in_array($id, $this->expandir)))
206 else $sub = $this->BuscarHijos($id);
207 $link = strval(@$row[2]);
214 if(isset($this->expandir) && in_array($id, $this->expandir) && $id != $this->id_activo)
216 if (!is_null($this->id_activo) and $id == $this->id_activo) {