From c54f604b47f43fe9a43b49aa0a4e6a95c0df2b8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?=
Date: Fri, 14 Feb 2014 00:18:47 +0100
Subject: [PATCH] =?UTF-8?q?-Cambiado=20el=20alineamiento=20del=20fuente=20?=
=?UTF-8?q?en=20varios=20archivos=20-Cambiado=20el=20men=C3=BA=20para=20po?=
=?UTF-8?q?der=20elegir=20si=20se=20abre=20en=20la=20misma=20hoja=20en=20u?=
=?UTF-8?q?na=20diferente=20-Mantenimiento=20ahora=20el=20contenido=20se?=
=?UTF-8?q?=20centra=20en=20la=20p=C3=A1gina.=20-El=20fichero=20pdf=20ahor?=
=?UTF-8?q?a=20se=20puede=20grabar=20en=20disco=20y=20se=20puede=20visuali?=
=?UTF-8?q?zar=20en=20una=20ventana=20nueva.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
AportaContenido.php | 176 +++----
Informe.pdf | Bin 0 -> 4521 bytes
InformeInventario.php | 297 ++++++-----
InformePDF.php | 14 +
Inventario.php | 151 +++---
Mantenimiento.php | 892 +++++++++++++++++-----------------
Menu.php | 8 +-
inc/inventario.menu | 18 +-
plant/principal.html | 20 +-
sql/inv2.sql | 168 +++++++
sql/setup.sql | 117 +++++
tmp/inventarioArticulo.xml | 4 +-
tmp/prueba.pdf | Bin 4076 -> 0 bytes
xml/mantenimientoUsuarios.xml | 27 +-
14 files changed, 1098 insertions(+), 794 deletions(-)
create mode 100644 Informe.pdf
create mode 100644 sql/inv2.sql
create mode 100644 sql/setup.sql
delete mode 100644 tmp/prueba.pdf
diff --git a/AportaContenido.php b/AportaContenido.php
index a71ceb0..34ff22e 100644
--- a/AportaContenido.php
+++ b/AportaContenido.php
@@ -1,64 +1,73 @@
.
- *
- */
-
-define ('PIE',' '.
- ' '.
- ' '.
- ' ');
-define ('FORMULARIO_ACCESO','');
-define ('MENSAJE_DEMO','Puede Iniciar sesión con usuario demo contraseña demo ');
-define ('USUARIO_INCORRECTO','Usuario y clave incorrectos! ');
+
+/**
+ * @package Inventario
+ * @copyright Copyright (c) 2008, Ricardo Montañana Gómez
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ * This file is part of Inventario.
+ * Inventario 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Inventario 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
+ * along with Inventario. If not, see .
+ *
+ */
+define('PIE', ' ' .
+ ' ' .
+ ' ' .
+ ' ');
+define('FORMULARIO_ACCESO', '');
+define('MENSAJE_DEMO', 'Puede Iniciar sesión con usuario demo contraseña demo ');
+define('USUARIO_INCORRECTO', 'Usuario y clave incorrectos! ');
+
// Esta clase aportará el contenido a la plantilla
class AportaContenido {
+
/**
*
* @var boolean Aporta información sobre si el usuario está registrado o no.
*/
private $registrado;
+
/**
* @var string Nombre del usuario
*/
- private $usuario=NULL;
- /**
+ private $usuario = NULL;
+
+ /**
* @var Menu Menú de la página.
*/
private $miMenu;
+
/**
* @var database Controlador de la base de datos
*/
private $bdd;
+
/**
* @var string Opción elegida por el usuario
*/
private $opcionActual;
- /**
+
+ /**
* @var boolean Usuario y clave incorrectos?
*/
- private $usuario_inc=false;
+ private $usuario_inc = false;
+
/**
* @var array Permisos del usuario
*/
private $perfil;
+
// El constructor necesita saber cuál es la opción actual
/**
* Constructor de la clase.
@@ -68,40 +77,36 @@ class AportaContenido {
* @param array $perfil Permisos de acceso del usuario
* @param String $opcion Opción elegida por el usuario
*/
- public function __construct($baseDatos,$registrado,$usuario,$perfil,$opcion)
- {
- $this->bdd=$baseDatos;
- $this->miMenu=new Menu('inc/inventario.menu');
- $this->registrado=$registrado;
- $this->usuario=$usuario;
- $this->perfil=$perfil;
- $this->opcionActual=$opcion;
+ public function __construct($baseDatos, $registrado, $usuario, $perfil, $opcion) {
+ $this->bdd = $baseDatos;
+ $this->miMenu = new Menu('inc/inventario.menu');
+ $this->registrado = $registrado;
+ $this->usuario = $usuario;
+ $this->perfil = $perfil;
+ $this->opcionActual = $opcion;
}
+
/**
* Devuelve la fecha actual
* @param string $formato formato de devolución de la fecha
* @param string $idioma idioma para formatear la fecha, p.ej. es_ES
* @return string
*/
- public function fechaActual($formato='',$idioma='es_ES')
- {
- if ($formato=='')
- $formato="%d-%b-%Y %H:%M";
- setlocale(LC_TIME,$idioma);
+ public function fechaActual($formato = '', $idioma = 'es_ES') {
+ if ($formato == '')
+ $formato = "%d-%b-%Y %H:%M";
+ setlocale(LC_TIME, $idioma);
return strftime($formato);
}
+
/**
*
* @return string Mensaje el usuario debe registrarse.
*/
- private function mensajeRegistro()
- {
- /**
- * @todo: tarea de prueba
- */
+ private function mensajeRegistro() {
return 'Debe registrarse para acceder a este apartado';
}
-
+
// Procesaremos todas las invocaciones a métodos en
// la función __call()
/**
@@ -110,9 +115,8 @@ class AportaContenido {
* @param string $parametros Parámetros del método
* @return string Contenido devuelto por el método
*/
- public function __call($metodo,$parametros)
- {
- switch($metodo) { // Dependiendo del método invocado
+ public function __call($metodo, $parametros) {
+ switch ($metodo) { // Dependiendo del método invocado
case 'titulo': // devolvemos el título
return APLICACION;
case 'usuario':
@@ -126,7 +130,7 @@ class AportaContenido {
if ($this->registrado) {
return $this->miMenu->insertaMenu();
} else {
- $salida=FORMULARIO_ACCESO;
+ $salida = FORMULARIO_ACCESO;
if ($this->usuario_inc) {
$salida.=USUARIO_INCORRECTO;
}
@@ -134,8 +138,8 @@ class AportaContenido {
return $salida;
}
case 'opcion':
- list($opcion,$parametro)=explode("&",$this->opcionActual);
- switch($opcion) {
+ list($opcion, $parametro) = explode("&", $this->opcionActual);
+ switch ($opcion) {
case 'bienvenido':
return "Menú Principal";
case 'principal':
@@ -145,7 +149,7 @@ class AportaContenido {
case 'ubicaciones':
case 'usuarios':
case 'test':
- return "Mantenimiento de ".ucfirst($opcion).".";
+ return "Mantenimiento de " . ucfirst($opcion) . ".";
case 'configuracion':
return 'Configuración y Preferencias.';
case 'informeInventario':return "Informe de Inventario";
@@ -160,70 +164,70 @@ class AportaContenido {
// Para incluir el contenido central de la página
case 'contenido':
// tendremos en cuenta cuál es la opción actual
- /*echo "opcActual=$this->opcActual ";
- echo "Metodo=$Metodo ";
- print_r($Parametros);*/
+ /* echo "opcActual=$this->opcActual ";
+ echo "Metodo=$Metodo ";
+ print_r($Parametros); */
// if (!$this->registrado) {
// return $this->mensajeRegistro();
// }
- list($opcion,$parametro)=explode("&",$this->opcionActual);
- switch($opcion) {
+ list($opcion, $parametro) = explode("&", $this->opcionActual);
+ switch ($opcion) {
case 'principal': // contenido inicial
- return ' '.
- ''.PROGRAMA.' '.PIE;
+ return ' ' .
+ '' . PROGRAMA . ' ' . PIE;
case 'articulos':
case 'ubicaciones':
case 'test':
case 'elementos':
if ($this->perfil['Consulta']) {
- $ele=new Mantenimiento($this->bdd,$this->perfil,$opcion);
+ $ele = new Mantenimiento($this->bdd, $this->perfil, $opcion);
return $ele->ejecuta();
} else {
return $this->mensajePermisos(ucfirst($opcion));
}
case 'usuarios':
if ($this->perfil['Usuarios']) {
- $ele=new Mantenimiento($this->bdd,$this->perfil,$opcion);
+ $ele = new Mantenimiento($this->bdd, $this->perfil, $opcion);
return $ele->ejecuta();
} else {
return $this->mensajePermisos('Usuarios');
}
-
+
case 'bienvenido': // El usuario quiere iniciar sesión
- return 'Bienvenido '.$this->usuario.' '.
- ''.PROGRAMA.' '.PIE;
+ return 'Bienvenido ' . $this->usuario . ' ' .
+ '' . PROGRAMA . ' ' . PIE;
case 'configuracion':
if ($this->perfil['Config']) {
- $conf=new Configuracion();
+ $conf = new Configuracion();
return $conf->ejecuta();
} else {
return $this->mensajePermisos('Configuracion');
}
case 'informeInventario':
if ($this->perfil['Informe']) {
- $info=new InformeInventario($this->bdd);
+ $info = new InformeInventario($this->bdd);
return $info->ejecuta();
} else {
return $this->mensajePermisos('Informes');
}
case 'descuadres':
if ($this->perfil['Informe']) {
- $enlace='xml/informe'.ucfirst($opcion).'.xml';
- $informe=new InformePDF($this->bdd,$enlace,$this->registrado);
- $informe->imprimeInforme();
- return;
+ $enlace = 'xml/informe' . ucfirst($opcion) . '.xml';
+ $informe = new InformePDF($this->bdd, $enlace, $this->registrado);
+ $informe->imprimeInforme();
+ return;
} else {
return $this->mensajePermisos('Informes');
}
} // Fin del contenido
case 'usuario_incorrecto':
- $this->usuario_inc=true;
- return;
+ $this->usuario_inc = true;
+ return;
case 'registro': // Si está registrado mostrar bienvenida
// si no, un enlace
- if($this->bEstaRegistrado) {
- return "Bienvenido $this->sUsuario ".
- 'Cerrar sesión ';
+ if ($this->bEstaRegistrado) {
+ return "Bienvenido $this->sUsuario " .
+ 'Cerrar sesión ';
} else {
return '';
}
@@ -231,14 +235,16 @@ class AportaContenido {
return "Marca {$metodo} queda sin procesar";
}
}
+
/**
*
* @param string $tipo
* @return string
*/
- public function mensajePermisos($tipo)
- {
- return "No tiene permiso para acceder a ".$tipo." ";
+ public function mensajePermisos($tipo) {
+ return "No tiene permiso para acceder a " . $tipo . " ";
}
+
}
+
?>
diff --git a/Informe.pdf b/Informe.pdf
new file mode 100644
index 0000000000000000000000000000000000000000..54361da73ec7cb47ff4ea3cc4ebb1e412abcb1a2
GIT binary patch
literal 4521
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 .
- *
- */
- class InformeInventario {
- private $bdd;
- public function __construct($baseDatos)
- {
- $this->bdd=$baseDatos;
- }
- public function ejecuta()
- {
- $opc=$_GET['opc'];
- switch ($opc) {
- case 'Ubicacion':return $this->formularioUbicacion();
- case 'listarUbicacion':return $this->listarUbicacion();
- case 'listarArticulo':return $this->listarArticulo();
- case 'Articulo':return $this->formularioArticulo();
- case 'Total':return $this->inventarioTotal();
- }
- }
- private function listarUbicacion()
- {
- $fichero="xml/inventarioUbicacion.xml";
- $salida="tmp/inventarioUbicacion.xml";
- $plantilla=file_get_contents($fichero)
- or die('Fallo en la apertura de la plantilla '.$fichero);
- $comando="select * from Ubicaciones where id='".$_POST['id']."';";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->bdd->mensajeError($comando);
- }
- $fila=$this->bdd->procesaResultado();
- $plantilla=str_replace("{id}",$_POST['id'],$plantilla);
- $plantilla=str_replace("{Descripcion}",utf8_encode($fila['Descripcion']),$plantilla);
- file_put_contents($salida,$plantilla)
- or die('Fallo en la escritura de la plantilla '.$salida);
- $informe=new InformePDF($this->bdd,$salida,true);
- $informe->imprimeInforme();
- }
- private function listarArticulo()
- {
- $fichero="xml/inventarioArticulo.xml";
- $salida="tmp/inventarioArticulo.xml";
- $plantilla=file_get_contents($fichero)
- or die('Fallo en la apertura de la plantilla '.$fichero);
- $comando="select * from Articulos where id='".$_POST['id']."';";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->bdd->mensajeError($comando);
- }
- $fila=$this->bdd->procesaResultado();
- $plantilla=str_replace("{id}",$_POST['id'],$plantilla);
- $plantilla=str_replace("{Descripcion}",utf8_encode($fila['descripcion']),$plantilla);
- $plantilla=str_replace("{Marca}",utf8_encode($fila['marca']),$plantilla);
- $plantilla=str_replace("{Modelo}",utf8_encode($fila['modelo']),$plantilla);
- file_put_contents($salida,$plantilla)
- or die('Fallo en la escritura de la plantilla '.$salida);
- $informe=new InformePDF($this->bdd,$salida,true);
- $informe->imprimeInforme();
- }
- private function listaUbicaciones()
- {
- $salida="\n";
- $comando="select * from Ubicaciones order by Descripcion";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->bdd->mensajeError($comando);
- }
- while($fila=$this->bdd->procesaResultado()) {
- $salida.="".$fila['Descripcion']." \n";
- }
- $salida.=" \n";
- return $salida;
- }
- private function listaArticulos()
- {
- $salida="\n";
- $comando="select * from Articulos order by descripcion, marca, modelo";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->bdd->mensajeError($comando);
- }
- while($fila=$this->bdd->procesaResultado()) {
- $salida.="".$fila['descripcion']."-".$fila['marca']."-".$fila['modelo']." \n";
- }
- $salida.=" \n";
- return $salida;
- }
- private function formulario($accion,$etiqueta,$lista)
- {
- $salida='
";
- }
- }
- //$salida.=print_r($this->perfil);
- while($fila=$this->bdd->procesaResultado()) {
- $salida.="";
- foreach ($fila as $clave => $valor) {
- if ($clave=="id") {
- $id=$valor;
- }
-
- $salida.="$valor \n";
- }
- //Añade el icono de editar
- if ($this->perfil['Modificacion']) {
- $salida.=' ';
- }
- //Añade el icono de eliminar
- if ($this->perfil['Borrado']) {
- $salida.=' '."\n";
- }
- }
- $salida.="";
- //Añade botones de comandos
- $enlace=' \n";
- $siguiente=$enlace.$pagSigte.$sufijoEnlace."\"> \n";
- $fwd=$enlace.$pagFwd.$sufijoEnlace."\"> \n";
- $rew=$enlace.$pagRew.$sufijoEnlace."\"> \n";
- if (strlen($orden)>0) {
- $az=' ';
- $za=' ';
- } else {
- $az=$za='';
- }
- if ($this->perfil['Informe']) {
- $informe=' ';
- } else {
- $informe="";
- }
- }
- if ($this->perfil['Alta']) {
- $anadir=''.
- ' ';
- } else {
- $anadir="";
- }
- $salida.=''.
- "$rew  $anterior  $az  $anadir  $informe  $za  $siguiente  $fwd
";
- return $salida;
- }
- private function enlaceBusqueda()
- {
- $salida='';
- $salida.='
';
- $salida.='';
- return $salida;
- }
- protected function borrar($id)
- {
- $comando="delete from ".$this->tabla." where id=\"$id\"";
- if (!$this->bdd->ejecuta($comando)) {
- return $this->errorBD($comando);
- }
- header('Location: '.$this->url);
- return;
- }
- protected function insertar()
- {
- $comando="insert into ".$this->tabla." (";
- $lista=explode("&",$_POST['listacampos']);
- $primero=true;
- //Añade la lista de campos
- foreach ($lista as $campo) {
- if ($campo=="") {
- continue;
- }
- if ($primero) {
- $primero=false;
- $coma=" ";
- } else {
- $coma=",";
- }
- $comando.="$coma $campo";
- }
- $comando.=") values (";
- //Añade la lista de valores
- $primero=true;
- foreach ($lista as $campo) {
- if ($campo=="")
- continue;
- if ($primero) {
- $primero=false;
- $coma=" ";
- } else {
- $coma=",";
- }
- $comando.="$coma \"$_POST[$campo]\"";
- }
- $comando.=")";
- if (!$this->bdd->ejecuta($comando)) {
- return $this->errorBD($comando);
- }
- list($enlace,$resto)=explode("&",$this->url);
- $enlace.="&opc=inicial";
- return "";
- }
- protected function modificar($id,$pag,$orden,$sentido)
- {
- //Los datos a utilizar para actualizar la tupla vienen en $_POST.
- //La lista de atributos de la tupla viene en el campo oculto listacampos
- //print_r($_GET);
- //echo "id=$id pag=$pag orden=$orden sentido=$sentido";die();
- $comando="update ".$this->tabla." set ";
- $lista=explode("&",$_POST['listacampos']);
- $primero=true;
- foreach ($lista as $campo) {
- if ($campo=="id" || $campo=="")
- continue;
- if ($primero) {
- $primero=false;
- $coma=" ";
- } else
- $coma=",";
- if (strlen(trim($_POST[$campo]))==0)
- $comando.="$coma $campo=null";
- else
- $comando.=$coma.' '.$campo.'="'.$_POST[$campo].'"';
- }
- $comando.=" where id=\"$id\"";
- if (!$this->bdd->ejecuta($comando)) {
- return $this->errorBD($comando);
- }
-
- list($enlace,$resto)=explode("&",$this->url);
- $enlace.="&opc=inicial&orden=".$orden."&sentido=".$sentido."&id=".$pag;
- header('Location: '.$enlace);
- return;
- }
- protected function muestra($id,$tipoAccion,$pag="",$orden="",$sentido="")
- {
- if (isset($id)) {
- $comando="select * from ".$this->tabla." where id='$id'";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->errorBD("","No se han podido encontrar datos del identificador $id");
- }
- $fila=$this->bdd->procesaResultado();
- } else {
- $fila=null;
- }
- //list($tipo,$valor)=explode($columna["Type"]);
- $accion="index.php?".strtolower($this->tabla)."&id=$id&opc=";
- switch ($tipoAccion) {
- case EDICION:
- $accion.="modificar";
- $accion.=isset($pag)?"&pag=$pag":'';
- $accion.=isset($orden)?"&orden=$orden":'';
- $accion.=isset($sentido)?"&sentido=$sentido":'';
- break;
- case BORRADO:
- $accion.="borrar";
- break;
- case ANADIR:
- $accion.="insertar";
- break;
- }
- //Genera un formulario con los datos de la tupla seleccionada.
- return $this->formularioCampos($accion,$tipoAccion,$fila);
- }
- //Función que genera un campo de lista con los valores de descripción de la
- //tabla a la cual pertenece la clave foránea.
- protected function generaLista($datos,$campo,$valorInicial,$modo)
- {
- $salida="\n";
- list($tabla,$atributos)=explode(",",$datos);
- $atributos=str_replace("/",",",$atributos);
- // Elimina las llaves
- $atributos=substr($atributos,1,-1);
- $comando="select id,$atributos from $tabla order by $atributos";
- $resultado=$this->bdd->ejecuta($comando);
- if (!$resultado) {
- return $this->errorBD($comando);
- }
- $modoEfectivo=$modo=="readonly" ? "disabled" : "";
- $primero=true;
- while($fila=$this->bdd->procesaResultado()) {
- foreach ($fila as $clave => $valor) {
- if ($clave=="id") {
- if ($primero) {
- $primero=false;
- } else {
- $salida=substr($salida,0,-1);
- $salida.="\n";
- }
- $seleccionado=$valor==$valorInicial ? " selected " : "";
- $salida.='';
- } else {
- $salida.=$valor."-";
- }
- }
- }
- $salida.=" \n ";
- return $salida;
- }
- /**
- * @todo Hay que hacer lo de las búsquedas automatizadas. Buscar el comment de buscar.
- * @todo Hay que hacer lo de las ordenaciones automatizadas. Buscar el comment de ordenable.
- */
- private function obtenerCampos()
- {
- //Si hay un fichero de descripción xml lo utiliza.
- $nombre="xml/mantenimiento".$this->tabla.".xml";
- if (file_exists($nombre)) {
- $def=simplexml_load_file($nombre);
- foreach($def->Campos->Col as $columna) {
- $this->campos[(string)$columna['Nombre']]=array("Field" => (string)$columna['Titulo'],"Comment" =>(string)$columna['Varios'],
- "Type"=> (string) $columna['Tipo'],"Editable" => (string) $columna['Editable'],"Campo"=>(string) $columna['Campo']);
- }
- $this->comandoConsulta=$def->Consulta;
- } else {
- //Toma los datos de la tabla.
- $datos=$this->bdd->estructura($this->tabla);
- for ($i=0;$icampos[$datos[$i]["Field"]][]=$datos[$i];
- $this->campos[$datos[$i]["Field"]]=$this->campos[$datos[$i]["Field"]][0];
- $this->campos[$datos[$i]["Field"]]["Campo"]=$datos[$i]["Field"];
- $this->campos[$datos[$i]["Field"]]["Editable"]="si";
- }
- $this->comandoConsulta="select * from ".$this->tabla." {buscar} {orden} limit {inferior},{superior}";
- }
- }
- private function cabeceraTabla()
- {
- $salida='
';
- foreach ($this->campos as $clave => $datos) {
- $comen=explode(",",$datos["Comment"]);
- $ordenable=false;
- foreach ($comen as $co) {
- if (strstr($co,"ordenable")) {
- $ordenable=true;
- break;
- }
- }
- if ($ordenable) {
- $salida.="url&orden=".strtolower($clave)."\"> $clave \n";
- } else {
- $salida.=''.$clave.' '."\n";
- }
- }
+/**
+ * @package Inventario
+ * @copyright Copyright (c) 2008, Ricardo Montañana Gómez
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ * This file is part of Inventario.
+ * Inventario 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Inventario 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
+ * along with Inventario. If not, see .
+ *
+ */
+//Clase que se encargará de manejar los elementos del modelo de datos.
+define('EDICION', 'Edición');
+define('BORRADO', 'Borrado ');
+define('ANADIR', 'Inserción');
- $salida.="Acción \n";
- return $salida;
- }
- /**
- *
- * @param string $accion URL de la acción del POST
- * @param string $tipo ANADIR,EDITAR,BORRAR
- * @param array $datos Vector con los datos del registro
- * @return array lista de campos y formulario de entrada
- */
- private function formularioCampos($accion,$tipo,$datos)
- {
- $modo=$tipo==BORRAR?"readonly":"";
- $salida.='
";
+ //Añade botones de comandos
+ $enlace = ' \n";
+ $siguiente = $enlace . $pagSigte . $sufijoEnlace . "\"> \n";
+ $fwd = $enlace . $pagFwd . $sufijoEnlace . "\"> \n";
+ $rew = $enlace . $pagRew . $sufijoEnlace . "\"> \n";
+ if (strlen($orden) > 0) {
+ $az = ' ';
+ $za = ' ';
+ } else {
+ $az = $za = '';
+ }
+ if ($this->perfil['Informe']) {
+ $informe = ' ';
+ } else {
+ $informe = "";
+ }
+ }
+ if ($this->perfil['Alta']) {
+ $anadir = '' .
+ ' ';
+ } else {
+ $anadir = "";
+ }
+ $salida.='' .
+ "$rew  $anterior  $az  $anadir  $informe  $za  $siguiente  $fwd
";
+ return $salida;
+ }
+
+ private function enlaceBusqueda() {
+ $salida = '';
+ $salida.='
';
+ $salida.='';
+ return $salida;
+ }
+
+ protected function borrar($id) {
+ $comando = "delete from " . $this->tabla . " where id=\"$id\"";
+ if (!$this->bdd->ejecuta($comando)) {
+ return $this->errorBD($comando);
+ }
+ header('Location: ' . $this->url);
+ return;
+ }
+
+ protected function insertar() {
+ $comando = "insert into " . $this->tabla . " (";
+ $lista = explode("&", $_POST['listacampos']);
+ $primero = true;
+ //Añade la lista de campos
+ foreach ($lista as $campo) {
+ if ($campo == "") {
+ continue;
+ }
+ if ($primero) {
+ $primero = false;
+ $coma = " ";
+ } else {
+ $coma = ",";
+ }
+ $comando.="$coma $campo";
+ }
+ $comando.=") values (";
+ //Añade la lista de valores
+ $primero = true;
+ foreach ($lista as $campo) {
+ if ($campo == "")
+ continue;
+ if ($primero) {
+ $primero = false;
+ $coma = " ";
+ } else {
+ $coma = ",";
+ }
+ $comando.="$coma \"$_POST[$campo]\"";
+ }
+ $comando.=")";
+ if (!$this->bdd->ejecuta($comando)) {
+ return $this->errorBD($comando);
+ }
+ list($enlace, $resto) = explode("&", $this->url);
+ $enlace.="&opc=inicial";
+ return "";
+ }
+
+ protected function modificar($id, $pag, $orden, $sentido) {
+ //Los datos a utilizar para actualizar la tupla vienen en $_POST.
+ //La lista de atributos de la tupla viene en el campo oculto listacampos
+ //print_r($_GET);
+ //echo "id=$id pag=$pag orden=$orden sentido=$sentido";die();
+ $comando = "update " . $this->tabla . " set ";
+ $lista = explode("&", $_POST['listacampos']);
+ $primero = true;
+ foreach ($lista as $campo) {
+ if ($campo == "id" || $campo == "")
+ continue;
+ if ($primero) {
+ $primero = false;
+ $coma = " ";
+ }
+ else
+ $coma = ",";
+ if (strlen(trim($_POST[$campo])) == 0)
+ $comando.="$coma $campo=null";
+ else
+ $comando.=$coma . ' ' . $campo . '="' . $_POST[$campo] . '"';
+ }
+ $comando.=" where id=\"$id\"";
+ if (!$this->bdd->ejecuta($comando)) {
+ return $this->errorBD($comando);
+ }
+
+ list($enlace, $resto) = explode("&", $this->url);
+ $enlace.="&opc=inicial&orden=" . $orden . "&sentido=" . $sentido . "&id=" . $pag;
+ header('Location: ' . $enlace);
+ return;
+ }
+
+ protected function muestra($id, $tipoAccion, $pag = "", $orden = "", $sentido = "") {
+ if (isset($id)) {
+ $comando = "select * from " . $this->tabla . " where id='$id'";
+ $resultado = $this->bdd->ejecuta($comando);
+ if (!$resultado) {
+ return $this->errorBD("", "No se han podido encontrar datos del identificador $id");
+ }
+ $fila = $this->bdd->procesaResultado();
+ } else {
+ $fila = null;
+ }
+ //list($tipo,$valor)=explode($columna["Type"]);
+ $accion = "index.php?" . strtolower($this->tabla) . "&id=$id&opc=";
+ switch ($tipoAccion) {
+ case EDICION:
+ $accion.="modificar";
+ $accion.=isset($pag) ? "&pag=$pag" : '';
+ $accion.=isset($orden) ? "&orden=$orden" : '';
+ $accion.=isset($sentido) ? "&sentido=$sentido" : '';
+ break;
+ case BORRADO:
+ $accion.="borrar";
+ break;
+ case ANADIR:
+ $accion.="insertar";
+ break;
+ }
+ //Genera un formulario con los datos de la tupla seleccionada.
+ return $this->formularioCampos($accion, $tipoAccion, $fila);
+ }
+
+ //Función que genera un campo de lista con los valores de descripción de la
+ //tabla a la cual pertenece la clave foránea.
+ protected function generaLista($datos, $campo, $valorInicial, $modo) {
+ $salida = "\n";
+ list($tabla, $atributos) = explode(",", $datos);
+ $atributos = str_replace("/", ",", $atributos);
+ // Elimina las llaves
+ $atributos = substr($atributos, 1, -1);
+ $comando = "select id,$atributos from $tabla order by $atributos";
+ $resultado = $this->bdd->ejecuta($comando);
+ if (!$resultado) {
+ return $this->errorBD($comando);
+ }
+ $modoEfectivo = $modo == "readonly" ? "disabled" : "";
+ $primero = true;
+ while ($fila = $this->bdd->procesaResultado()) {
+ foreach ($fila as $clave => $valor) {
+ if ($clave == "id") {
+ if ($primero) {
+ $primero = false;
+ } else {
+ $salida = substr($salida, 0, -1);
+ $salida.="\n";
+ }
+ $seleccionado = $valor == $valorInicial ? " selected " : "";
+ $salida.='';
+ } else {
+ $salida.=$valor . "-";
+ }
+ }
+ }
+ $salida.=" \n ";
+ return $salida;
+ }
+
+ /**
+ * @todo Hay que hacer lo de las búsquedas automatizadas. Buscar el comment de buscar.
+ * @todo Hay que hacer lo de las ordenaciones automatizadas. Buscar el comment de ordenable.
+ */
+ private function obtenerCampos() {
+ //Si hay un fichero de descripción xml lo utiliza.
+ $nombre = "xml/mantenimiento" . $this->tabla . ".xml";
+ if (file_exists($nombre)) {
+ $def = simplexml_load_file($nombre);
+ foreach ($def->Campos->Col as $columna) {
+ $this->campos[(string) $columna['Nombre']] = array("Field" => (string) $columna['Titulo'], "Comment" => (string) $columna['Varios'],
+ "Type" => (string) $columna['Tipo'], "Editable" => (string) $columna['Editable'], "Campo" => (string) $columna['Campo']);
+ }
+ $this->comandoConsulta = $def->Consulta;
+ } else {
+ //Toma los datos de la tabla.
+ $datos = $this->bdd->estructura($this->tabla);
+ for ($i = 0; $i < count($datos); $i++) {
+ $this->campos[$datos[$i]["Field"]][] = $datos[$i];
+ $this->campos[$datos[$i]["Field"]] = $this->campos[$datos[$i]["Field"]][0];
+ $this->campos[$datos[$i]["Field"]]["Campo"] = $datos[$i]["Field"];
+ $this->campos[$datos[$i]["Field"]]["Editable"] = "si";
+ }
+ $this->comandoConsulta = "select * from " . $this->tabla . " {buscar} {orden} limit {inferior},{superior}";
+ }
+ }
+
+ private function cabeceraTabla() {
+ $salida = '
';
+ foreach ($this->campos as $clave => $datos) {
+ $comen = explode(",", $datos["Comment"]);
+ $ordenable = false;
+ foreach ($comen as $co) {
+ if (strstr($co, "ordenable")) {
+ $ordenable = true;
+ break;
+ }
+ }
+ if ($ordenable) {
+ $salida.="url&orden=" . strtolower($clave) . "\"> $clave \n";
+ } else {
+ $salida.='' . $clave . ' ' . "\n";
+ }
+ }
+
+ $salida.="Acción \n";
+ return $salida;
+ }
+
+ /**
+ *
+ * @param string $accion URL de la acción del POST
+ * @param string $tipo ANADIR,EDITAR,BORRAR
+ * @param array $datos Vector con los datos del registro
+ * @return array lista de campos y formulario de entrada
+ */
+ private function formularioCampos($accion, $tipo, $datos) {
+ $modo = $tipo == BORRAR ? "readonly" : "";
+ $salida.='