2 Commits

Author SHA1 Message Date
6829495ca9 *Corregido que no aparecía el mensaje de bienvenida al hacer login en la aplicación 2014-10-23 19:28:38 +02:00
12ff042c1d Merge branch 'release/1.17' into develop
* release/1.17:
  Eliminados los mensajes de aviso de php en todos los archivos php, actualizada la versión y el changelog
2014-07-29 21:41:51 +02:00
5 changed files with 98 additions and 103 deletions

View File

@@ -1,5 +1,4 @@
<?php <?php
/** /**
* @package Inventario * @package Inventario
* @copyright Copyright (c) 2008, Ricardo Montañana Gómez * @copyright Copyright (c) 2008, Ricardo Montañana Gómez
@@ -26,11 +25,10 @@ require_once 'Sql.php';
$ajax = new Ajax(); $ajax = new Ajax();
echo $ajax->procesa(); echo $ajax->procesa();
class Ajax class Ajax {
{
private $sql; private $sql;
private $tabla; private $tabla;
public function __construct() public function __construct()
{ {
$this->sql = new Sql(SERVIDOR, USUARIO, CLAVE, BASEDATOS); $this->sql = new Sql(SERVIDOR, USUARIO, CLAVE, BASEDATOS);
@@ -48,10 +46,8 @@ class Ajax
{ {
$opc = $_GET['opc']; $opc = $_GET['opc'];
switch ($opc) { switch ($opc) {
case "get": case "get": return $this->obtiene();
return $this->obtiene(); case "put": return $this->actualiza();
case "put":
return $this->actualiza();
} }
} }
private function mensaje($exito, $texto) private function mensaje($exito, $texto)
@@ -60,18 +56,18 @@ class Ajax
} }
private function actualiza() private function actualiza()
{ {
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$comando = "update " . $this->sql->filtra($this->tabla) . " set " . $this->sql->filtra($_POST['name']) . " = '" . $this->sql->filtra($_POST['value']) . "' where id = '" . $this->sql->filtra($_POST['pk']) . "';"; $comando = "update " . mysql_escape_string($this->tabla) . " set " . mysql_escape_string($_POST['name']) . " = '" . mysql_escape_string($_POST['value']) . "' where id = '" . mysql_escape_string($_POST['pk']). "';";
$this->sql->ejecuta($comando); $this->sql->ejecuta($comando);
$exito = !$this->sql->error(); $exito = !$this->sql->error();
$mensaje = $this->sql->mensajeError(); $mensaje = $this->sql->mensajeError();
$resp = $this->mensaje($exito, $mensaje); $resp = $this->mensaje($exito, $mensaje);
return $this->respuesta($resp); return $this->respuesta($resp);
} }
} }
private function obtiene() private function obtiene()
{ {
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$comando = "select id, descripcion from " . $this->tabla . " order by descripcion asc;"; $comando = "select id, descripcion from " . $this->tabla . " order by descripcion asc;";
$this->sql->ejecuta($comando); $this->sql->ejecuta($comando);
$exito = !$this->sql->error(); $exito = !$this->sql->error();
@@ -80,11 +76,13 @@ class Ajax
return $this->respuesta($this->mensaje($exito, $mensaje)); return $this->respuesta($this->mensaje($exito, $mensaje));
} }
$filas = array(); $filas = array();
while ($r = $this->sql->procesaResultado()) { while($r = $this->sql->procesaResultado()) {
$filas[] = array($r['id'] => $r['descripcion']); $filas[] = array($r['id'] => $r['descripcion']);
} }
$resp = json_encode($filas); $resp = json_encode($filas);
return $this->respuesta($resp); return $this->respuesta($resp);
} }
} }
} }
?>

View File

@@ -258,7 +258,9 @@ class AportaContenido {
$mensaje = '<div class="alert alert-success">'; $mensaje = '<div class="alert alert-success">';
$mensaje .= 'Bienvenid@ ' . $this->usuario . '</div>'; $mensaje .= 'Bienvenid@ ' . $this->usuario . '</div>';
case 'principal': // contenido inicial case 'principal': // contenido inicial
$mensaje = ""; if (!isset($mensaje)) {
$mensaje = "";
}
$creditos = "$('#creditos').modal({keyboard: false});"; $creditos = "$('#creditos').modal({keyboard: false});";
$centro = '<div class="well well-sm">' . CENTRO . '</div>'; $centro = '<div class="well well-sm">' . CENTRO . '</div>';
$tabla = $this->creaTablaAcercaDe(); $tabla = $this->creaTablaAcercaDe();

View File

@@ -70,7 +70,6 @@ class Csv {
private $cantidadReal; private $cantidadReal;
private $nSerie; private $nSerie;
/** /**
// El constructor necesita saber cuál es la opción actual // El constructor necesita saber cuál es la opción actual
/** /**

View File

@@ -15,7 +15,7 @@ Utiliza:
[Manual de Usuario](http://rmontanana.gitbooks.io/inventario2/) [Manual de Usuario](http://rmontanana.gitbooks.io/inventario2/)
[Instalación de ejemplo](https://inventario.rmontanana.es) [Instalación de ejemplo](http://inventario2.rmontanana.es)
[Estadísticas del proyecto](https://www.ohloh.net/p/inventario2) [Estadísticas del proyecto](https://www.ohloh.net/p/inventario2)

168
Sql.php
View File

@@ -1,57 +1,55 @@
<?php <?php
/**
/** * Gestión de una base de datos MySQL
* Gestión de una base de datos MySQL * @author Ricardo Montañana <rmontanana@gmail.com>
* @author Ricardo Montañana <rmontanana@gmail.com> * @version 1.0
* @version 1.0 * @package Inventario
* @package Inventario * @copyright Copyright (c) 2008, Ricardo Montañana Gómez
* @copyright Copyright (c) 2008, Ricardo Montañana Gómez * @license http://www.gnu.org/licenses/gpl-3.0.txt
* @license http://www.gnu.org/licenses/gpl-3.0.txt * This file is part of Inventario.
* This file is part of Inventario. * Inventario is free software: you can redistribute it and/or modify
* Inventario is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or
* the Free Software Foundation, either version 3 of the License, or * (at your option) any later version.
* (at your option) any later version. *
* * Inventario is distributed in the hope that it will be useful,
* Inventario is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details.
* GNU General Public License for more details. *
* * You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License * along with Inventario. If not, see <http://www.gnu.org/licenses/>.
* along with Inventario. If not, see <http://www.gnu.org/licenses/>. *
* */
*/ class Sql {
class Sql
{
/** /**
* @var mixed Manejador de la base de datos. * @var mixed Manejador de la base de datos.
*/ */
private $bdd = NULL; private $bdd=NULL;
/** /**
* @var string Mensaje del último mensaje de error generado * @var string Mensaje del último mensaje de error generado
*/ */
private $mensajeError = ''; private $mensajeError='';
/** /**
* @var boolean Almacena el estado de error o no de la última acción. * @var boolean Almacena el estado de error o no de la última acción.
*/ */
private $error = false; private $error=false;
/** /**
* @var boolean Estado de la conexión con la base de datos. * @var boolean Estado de la conexión con la base de datos.
*/ */
private $estado = false; private $estado=false;
/** /**
* @var mixed Objeto que alberga la última consulta ejecutada. * @var mixed Objeto que alberga la última consulta ejecutada.
*/ */
private $peticion = NULL; private $peticion=NULL;
/** /**
* @var integer Número de tuplas afectadas en la última consulta. * @var integer Número de tuplas afectadas en la última consulta.
*/ */
private $numero = 0; private $numero=0;
/** /**
* @var string vector de cadenas con los resultados de la petición. * @var string vector de cadenas con los resultados de la petición.
*/ */
private $datos = array(); private $datos=array();
/** /**
* Id del último registro insertado * Id del último registro insertado
* @var integer mysql_ * @var integer mysql_
@@ -63,21 +61,20 @@ class Sql
* @param string $usuario * @param string $usuario
* @param string $baseDatos * @param string $baseDatos
*/ */
public function __construct($servidor, $usuario, $clave, $baseDatos) public function __construct($servidor,$usuario,$clave,$baseDatos)
{ {
$this->bdd = @new mysqli($servidor, $usuario, $clave, $baseDatos); $this->bdd = @new mysqli($servidor,$usuario,$clave,$baseDatos);
if (mysqli_connect_errno()) { if (mysqli_connect_errno()) {
$this->mensajeError = '<h1>Fallo al conectar con el servidor MySQL.</h1>'; $this->mensajeError='<h1>Fallo al conectar con el servidor MySQL.</h1>';
$this->mensajeError .= "Servidor [" . $servidor . "] base de datos [" . $baseDatos . "]"; $this->mensajeError.="Servidor [".$servidor ."] base de datos [".$baseDatos."]";
$this->error = true; $this->error=true;
$this->estado = false; $this->estado=false;
} else { } else {
$this->mensajeError = ''; $this->mensajeError='';
$this->error = false; $this->error=false;
$this->estado = true; $this->estado=true;
} }
$this->peticion = NULL; $this->peticion=NULL;
$this->bdd->set_charset("latin1");
return $this; return $this;
} }
public function __destruct() public function __destruct()
@@ -91,69 +88,68 @@ class Sql
$this->bdd->close(); $this->bdd->close();
} }
} }
public function filtra($cadena) public function filtra($cadena)
{ {
return $this->bdd->real_escape_string($cadena); return $this->bdd->real_escape_string($cadena);
} }
public function ejecuta($comando) public function ejecuta($comando)
{ {
if (!$this->estado) { if (!$this->estado) {
$this->error = true; $this->error=true;
$this->mensajeError = 'No est&aacute; conectado'; $this->mensajeError='No est&aacute; conectado';
return false; return false;
} }
if (!$this->peticion = $this->bdd->query($comando)) { if (!$this->peticion=$this->bdd->query($comando)) {
$this->error = true; $this->error=true;
$this->mensajeError = 'No pudo ejecutar la petici&oacute;n: ' . $comando; $this->mensajeError='No pudo ejecutar la petici&oacute;n: '.$comando;
return false; return false;
} }
$this->numero = $this->bdd->affected_rows; $this->numero=$this->bdd->affected_rows;
$this->id = $this->bdd->insert_id; $this->id=$this->bdd->insert_id;
$this->error = false; $this->error=false;
$this->mensajeError = ''; $this->mensajeError='';
return true; return true;
} }
public function procesaResultado() public function procesaResultado()
{ {
if (!$this->estado) { if (!$this->estado) {
$this->error = true; $this->error=true;
$this->mensajeError = 'No está conectado a una base de datos'; $this->mensajeError='No está conectado a una base de datos';
return NULL; return NULL;
} }
if (!$this->peticion) { if (!$this->peticion) {
$this->error = true; $this->error=true;
$this->mensajeError = 'No hay un resultado disponible'; $this->mensajeError='No hay un resultado disponible';
return NULL; return NULL;
} }
$datos = $this->peticion->fetch_assoc(); $datos=$this->peticion->fetch_assoc();
$this->error = false; $this->error=false;
$this->mensajeError = ''; $this->mensajeError='';
return ($datos); return ($datos);
} }
public function camposResultado() public function camposResultado()
{ {
if (!$this->estado) { if (!$this->estado) {
$this->error = true; $this->error=true;
$this->mensajeError = 'No está conectado a una base de datos'; $this->mensajeError='No está conectado a una base de datos';
return NULL; return NULL;
} }
if (!$this->peticion) { if (!$this->peticion) {
$this->error = true; $this->error=true;
$this->mensajeError = 'No hay un resultado disponible'; $this->mensajeError='No hay un resultado disponible';
return NULL; return NULL;
} }
$datos = $this->peticion->fetch_field(); $datos=$this->peticion->fetch_field();
$this->error = false; $this->error=false;
$this->mensajeError = ''; $this->mensajeError='';
return ($datos); return ($datos);
} }
/** /**
* Devuelve el número de tuplas afectadas en la última petición. * Devuelve el número de tuplas afectadas en la última petición.
* @return integer Número de tuplas. * @return integer Número de tuplas.
*/ */
public function numeroTuplas() public function numeroTuplas() {
{
return $this->numero; return $this->numero;
} }
/** /**
@@ -161,32 +157,30 @@ class Sql
* con SELECT SQL_CALC_FOUND_ROWS * ... * con SELECT SQL_CALC_FOUND_ROWS * ...
* @return integer Número de tuplas. * @return integer Número de tuplas.
*/ */
public function numeroTotalTuplas() public function numeroTotalTuplas()
{ {
$comando = "select found_rows();"; $comando = "select found_rows();";
if (!$peticion = $this->bdd->query($comando)) { if (!$peticion=$this->bdd->query($comando)) {
$this->error = true; $this->error=true;
$this->mensajeError = 'No pudo ejecutar la petici&oacute;n: ' . $comando; $this->mensajeError='No pudo ejecutar la petici&oacute;n: '.$comando;
return false; return false;
} }
$numero = $peticion->fetch_row(); $numero = $peticion->fetch_row();
return $numero[0]; return $numero[0] ;
} }
/** /**
* Devuelve la condición de error de la última petición * Devuelve la condición de error de la última petición
* @return boolean condición de error. * @return boolean condición de error.
*/ */
public function error() public function error() {
{
return $this->error; return $this->error;
} }
/** /**
* Devuelve el mensaje de error de la última petición * Devuelve el mensaje de error de la última petición
* @return <type> * @return <type>
*/ */
public function mensajeError() public function mensajeError() {
{ return $this->mensajeError.$this->bdd->error;
return $this->mensajeError . $this->bdd->error;
} }
/** /**
* Devuelve la estructura de campos de una tabla. * Devuelve la estructura de campos de una tabla.
@@ -198,12 +192,12 @@ class Sql
if ($this->peticion) { if ($this->peticion) {
$this->peticion->free_result(); $this->peticion->free_result();
} }
$comando = "show full columns from $tabla"; $comando="show full columns from $tabla";
if (!$this->ejecuta($comando)) { if (!$this->ejecuta($comando)) {
return false; return false;
} }
while ($dato = $this->procesaResultado()) { while ($dato=$this->procesaResultado()) {
$salida[] = $dato; $salida[]=$dato;
} }
return $salida; return $salida;
} }
@@ -223,7 +217,7 @@ class Sql
{ {
$codigo = $this->bdd->rollback(); $codigo = $this->bdd->rollback();
$this->bdd->autocommit(true); $this->bdd->autocommit(true);
return $codigo; return $codigo;
} }
public function confirmaTransaccion() public function confirmaTransaccion()
{ {
@@ -233,3 +227,5 @@ class Sql
return $codigo; return $codigo;
} }
} }
?>