-<?php
-// vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
-// +----------------------------------------------------------------------+
-// | PHP Version 4 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2003 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available at through the world-wide-web at |
-// | http://www.php.net/license/2_02.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Created: Thu Jun 19 16:54:08 2003
-// | Author: Gonzalo Merayo <gmeray@mecon.gov.ar>
-// +----------------------------------------------------------------------+
-//
-// $Id$
-// $Author$
-// $URL$
-// $Date$
-// $Rev$
-//
+<?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: Thu Jun 19 16:54:08 2003
+Autor: Gonzalo Merayo <gmeray@mecon.gov.ar>
+-------------------------------------------------------------------------------
+$Id$
+-----------------------------------------------------------------------------*/
#require_once 'PEAR.php';
require_once 'MECON/Agente.php';
require_once 'DB.php';
-
-
-// +X2C Class 145 :dependencia
+// +X2C Class 145 :MECON_Dependencia
/**
* @access protected
*/
-class dependencia {
- /**
- * @var int $codep
- * @access public
- */
- var $codep;
-
- // ~X2C
-
- // +X2C Operation 147
- /**
- * @param int $codep
- *
- * @return void
- * @access public
- */
- function dependencia($codep) // ~X2C
- {
- $this->codep = $codep;
- }
- // -X2C
-
- // +X2C Operation 148
- /**
- * @return void
- * @access public
- */
- function getAgentes() // ~X2C
- {
-//Planta y becarios
- $agentes = array();
- $dsn = 'mysql://intranet:intranet@intranet-db/novedades';
- $db = DB::connect($dsn);
- if (DB::isError($db)) die ($db->getMessage("No pudo conectarse a la base"));
- $sql = "SELECT nrodoc
- FROM web003
- WHERE codep = $this->codep";
- $result = $db->query($sql);
- if(DB::isError($result))
- die($result->getMessage("query mal hecho"));
- while($row = $result->fetchRow())
- $agentes[] = new Agente($row[0]);
-//Contratados
- $dsn = 'mysql://intranet:intranet@intranet-db/Contratados';
- $db = DB::connect($dsn);
- if (DB::isError($db)) die ($db->getMessage("No pudo conectarse a la base"));
- $sql = "SELECT *
- FROM Contratados
- WHERE codep = $this->codep";
- $result = $db->query($sql);
- if(DB::isError($result))
- die($result->getMessage("query mal hecho"));
- while($row = $result->fetchRow())
- $agentes[] = new Agente($row[0]);
- return $agentes;
- }
- // -X2C
-
-} // -X2C Class :dependencia
-?>
+class MECON_Dependencia {
+ /**
+ * @var int $codep
+ * @access public
+ */
+ var $codep;
+
+ /**
+ * @var int $nombre
+ * @access public
+ */
+ var $nombre;
+
+ /**
+ * @var int $nombre_breve
+ * @access public
+ */
+ var $nombre_breve;
+
+ /**
+ * Id de la dependencia en la base.
+ *
+ * @var int $dependencia_id
+ * @access public
+ */
+ var $dependencia_id = null;
+
+ // ~X2C
+
+ // +X2C Operation 147
+ /**
+ * @param int $codep
+ *
+ * @return void
+ * @access public
+ */
+ function MECON_Dependencia($codep) // ~X2C
+ {
+ $this->codep = $codep;
+ $dsn = 'mysql://intranet:intranet@intranet-db.mecon.ar/CODEP';
+ $db = DB::connect($dsn);
+ if (DB::isError($db))
+ die ($db->getMessage("No pudo conectarse a la base"));
+ $sql = "SELECT nombre, nombre_breve, dependencia_id
+ FROM Dependencias
+ WHERE codigo_actual = '$this->codep' AND
+ dependencia_esta_activa = 1";
+ $result = $db->query($sql);
+ if(DB::isError($result))
+ die($result->getMessage("query mal hecho"));
+ if($result->numRows() > 0) {
+ $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
+ $this->nombre = $row['nombre'];
+ $this->nombre_breve = $row['nombre_breve'];
+ $this->dependencia_id = $row['dependencia_id'];
+ }
+ }
+ // -X2C
+
+ // +X2C Operation 148
+ /**
+ * @return void
+ * @access public
+ */
+ function getAgentes() // ~X2C
+ {
+ //Planta y becarios
+ $agentes = array();
+ $dsn = 'mysql://intranet:intranet@intranet-db.mecon.ar/novedades';
+ $db = DB::connect($dsn);
+ if (DB::isError($db))
+ die ($db->getMessage("No pudo conectarse a la base"));
+ $sql = "SELECT nrodoc
+ FROM web003
+ WHERE codep = '$this->codep'";
+ $result = $db->query($sql);
+ if(DB::isError($result))
+ die($result->getMessage("query mal hecho"));
+ while($row = $result->fetchRow())
+ $agentes[] = new MECON_Agente($row[0]);
+ //Contratados
+ $dsn = 'mysql://intranet:intranet@intranet-db.mecon.ar/Contratados';
+ $db = DB::connect($dsn);
+ if (DB::isError($db))
+ die ($db->getMessage("No pudo conectarse a la base"));
+ $sql = "SELECT nrodoc
+ FROM Contratados
+ WHERE codep = '$this->codep'";
+ $result = $db->query($sql);
+ if(DB::isError($result))
+ die($result->getMessage("query mal hecho"));
+ while($row = $result->fetchRow())
+ $agentes[] = new MECON_Agente($row[0]);
+ return $agentes;
+ }
+ // -X2C
+
+ // +X2C Operation 150
+ /**
+ * @return dependencia
+ * @access public
+ * @static
+ */
+ function getDependencias() // ~X2C
+ {
+ $dsn = 'mysql://intranet:intranet@intranet-db.mecon.ar/CODEP';
+ $db = DB::connect($dsn);
+ if (DB::isError($db))
+ die ($db->getMessage("No pudo conectarse a la base"));
+ $sql = "SELECT codigo_actual
+ FROM Dependencias
+ WHERE dependencia_esta_activa = 1";
+ $result = $db->query($sql);
+ if(DB::isError($result))
+ die($result->getMessage("query mal hecho"));
+ $dependencias = array();
+ while($row = $result->fetchRow())
+ $dependencias[] = $row[0];
+ return $dependencias;
+ }
+ // -X2C
+
+ // +X2C Operation 165
+ /**
+ * @return void
+ * @access public
+ */
+ function getNombre() // ~X2C
+ {
+ return $this->nombre;
+ }
+ // -X2C
+
+ // +X2C Operation 166
+ /**
+ * @return void
+ * @access public
+ */
+ function getNombreBreve() // ~X2C
+ {
+ return $this->nombre_breve;
+ }
+ // -X2C
+
+ // +X2C Operation 167
+ /**
+ * Buscar dependencias por el codep.
+ *
+ * @param db &$dbh Base de Datos
+ * @param string $codep COdigo de dependencia, o parte del mismo seguido del comodIn (*)
+ *
+ * @return array
+ * @access public
+ * @static
+ */
+ function buscarPorCodigo(&$dbh, $codep) // ~X2C
+ {
+ //Reemplazar el comodIn
+ $codep = preg_replace ('/\*/', '%', $codep);
+
+ $sql = " SELECT codigo_actual, codigo_comdoc, nombre, dependencia_id
+ FROM CODEP.Dependencias
+ WHERE dependencia_esta_activa = 1
+ AND codigo_actual LIKE '$codep'
+ ORDER BY codigo_actual ";
+
+ $dbh->setFetchMode(DB_FETCHMODE_ASSOC);
+ $result = $dbh->query($sql);
+
+ return $result;
+ }
+ // -X2C
+
+ // +X2C Operation 168
+ /**
+ * @param db &$dbh Base de Datos
+ * @param string $clave Cadena de palabras clave del nombre de la dependencia.
+ *
+ * @return array
+ * @access public
+ * @static
+ */
+ function buscarPorNombre(&$dbh, $clave) // ~X2C
+ {
+ //ReducciOn de espacios en blanco
+ $clave = preg_replace ('/\s+/', ' ', $clave);
+
+ $sql = " SELECT codigo_actual, codigo_comdoc, nombre, dependencia_id
+ FROM CODEP.Dependencias
+ WHERE dependencia_esta_activa = 1 ";
+
+ //Separar la cadena de palabras clave
+ $items = split(' ', $clave);
+ foreach ($items as $i){
+ $sql.= " AND nombre like '%$i%' ";
+ }
+
+ $sql.= " ORDER BY codigo_actual";
+
+ $dbh->setFetchMode(DB_FETCHMODE_ASSOC);
+ $result = $dbh->query($sql);
+
+ return $result;
+ }
+ // -X2C
+
+} // -X2C Class :MECON_Dependencia
+?>
\ No newline at end of file