1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
5 -------------------------------------------------------------------------------
6 This file is part of meconlib.
8 meconlib is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
13 meconlib is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License; if not,
18 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
20 -------------------------------------------------------------------------------
21 Creado: jue jul 17 15:33:41 ART 2003
22 Autor: Gonzalo Merayo <gmeray@mecon.gov.ar>
23 Leandro Lucarella <llucar@mecon.gov.ar>
24 -------------------------------------------------------------------------------
26 -----------------------------------------------------------------------------*/
28 require_once 'MECON/HTML/Arbol.php';
29 require_once 'DB.php';
36 class MECON_HTML_ArbolDB extends MECON_HTML_Arbol
74 * @var TIPO $id_activo
90 * @var string $link_append
93 var $link_append = '';
122 * @param TIPO $dbdata DESC
123 * @param TIPO $titulo DESC
124 * @param string $link_append DESC
129 function MECON_HTML_ArbolDB($dbdata, $titulo, $link_append = '', $expandir = false)
131 if(isset($dbdata['id_padre']))
132 $this->padre = $dbdata['id_padre'];
133 $this->tabla = $dbdata['tabla'];
134 $this->nombre = $dbdata['nombre'];
135 $this->id = $dbdata['id'];
136 $this->id_activo = @$dbdata['id_activo'];
137 // FIXME - Deprecated!
138 if(isset($dbdata['prepend_link']))
139 $link_append = $dbdata['prepend_link'];
140 if(isset($dbdata['link']))
141 $this->link = $dbdata['link'];
142 if(isset($dbdata['where']))
143 $this->where = $dbdata['where'];
144 if(isset($dbdata['habilitado']))
145 $this->habilitado = $dbdata['habilitado'];
146 if(isset($dbdata['order']))
147 $this->order = ' ORDER BY '.$dbdata['nombre'].' '.$dbdata['order'];
148 $this->db = $dbdata['db'];
152 $this->expandir = array($this->id_activo);
153 if(isset($this->id_activo))
155 $id = $this->id_activo;
158 $sql = "SELECT $this->padre
160 WHERE $this->id = '".$id."'";
161 $id = $this->db->getOne($sql);
162 $this->expandir[] = $id;
167 parent::MECON_HTML_Arbol(array(), $titulo, $link_append);
168 $this->datos = $this->BuscarHijos(0);
174 * @param TIPO $id DESC
179 function BuscarHijos($id)
181 $sql = "SELECT $this->nombre, $this->id ";
183 $sql .= ", $this->link ";
184 $sql .= "FROM $this->tabla ";
185 if($this->padre or $this->where)
188 $sql .= "$this->padre = '$id'";
191 } elseif ($this->where)
192 $sql .= $this->where;
193 if(isset($this->habilitado))
194 $sql .= " AND ".$this->habilitado." = 1 ";
195 $sql .= $this->order;
196 $result = $this->db->query($sql);
197 if(DB::isError($result))
198 die($result->getMessage());
200 while($row = $result->fetchRow())
204 if(!$this->padre || !(!isset($this->expandir) ||
205 in_array($id, $this->expandir)))
207 else $sub = $this->BuscarHijos($id);
208 $link = strval(@$row[2]);
215 if(isset($this->expandir) && in_array($id, $this->expandir) && $id != $this->id_activo)
217 if (!is_null($this->id_activo) and $id == $this->id_activo) {