13 Commits

Author SHA1 Message Date
67a7080e59 Fix escape string deprectaed method 2024-04-24 12:44:52 +02:00
e1151343bd Fix charset view problem 2024-04-24 11:37:10 +02:00
08122054ce README.md edited online with Bitbucket 2017-03-28 07:22:53 +00:00
c033d788a0 Añadida línea en blanco para probar el editor del iPhone 2016-11-07 19:58:21 +01:00
335674a0bc Merge branch 'release/1.17'
* release/1.17:
  Eliminados los mensajes de aviso de php en todos los archivos php, actualizada la versión y el changelog
  Modificado el README para eliminar los saltos de línea introducidos por el editor online
  Modificado el README para eliminar los saltos de línea introducidos por el editor online
  Modificado el README para eliminar los saltos de línea introducidos por el editor online
  Modificados los programas para eliminar todos los "warnings" de php
2014-07-29 21:41:51 +02:00
2488b7943d Cambiados los saltos de línea en README.md 2014-07-29 21:41:24 +02:00
453045eee2 Merge branch 'release/1.16' 2014-07-29 17:12:26 +02:00
da1fccf1fd README.md edited online with Bitbucket 2014-07-15 11:38:59 +00:00
dcc0662dfb README.md edited online with Bitbucket 2014-07-15 11:38:05 +00:00
f47e1e5cd1 README.md edited online with Bitbucket 2014-07-15 09:37:12 +00:00
5484495d5a README.md edited online with Bitbucket 2014-07-15 09:36:51 +00:00
7272e2b85a Merge branch 'release/1.15'
* release/1.15:
  Actualizado el número de versión a 1.15
  Corregido codificación/decodificación de la cadena de búsqueda en la URL
  Fix #40 Crear la opción de clonar registro en Mantenimiento. -Crear iconos de clonado en todos los estilos. -Corregido determinaAccion en Imagen para aceptar el clonado
  Corregido que aparezca el código de artículo en las etiquetas qr del inventario de Artículos Añadida la creación del directorio de imágenes en las instrucciones de instalación del README
2014-06-29 21:22:57 +02:00
6148593c7c Merge branch 'release/1.14.1'
* release/1.14.1:
  Actualizado el CHANGELOG
  Añadido la v para indicar la versión en la cabecera de los informes Acortado el nombre de la aplicación en la página principal para que en dispositivos pequeños se visualice bien con el icono nuevo del manual
  Añadidos enlaces a manual y a aplicación de ejemplo en readme.md
  Arreglado que los créditos salgan centrados en lugar de alineados a la derecha
2014-06-02 19:44:52 +02:00
4 changed files with 102 additions and 95 deletions

View File

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

View File

@@ -70,6 +70,7 @@ class Csv {
private $cantidadReal;
private $nSerie;
/**
// 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/)
[Instalación de ejemplo](http://inventario2.rmontanana.es)
[Instalación de ejemplo](https://inventario.rmontanana.es)
[Estadísticas del proyecto](https://www.ohloh.net/p/inventario2)

168
Sql.php
View File

@@ -1,55 +1,57 @@
<?php
/**
* Gestión de una base de datos MySQL
* @author Ricardo Montañana <rmontanana@gmail.com>
* @version 1.0
* @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 <http://www.gnu.org/licenses/>.
*
*/
class Sql {
/**
* Gestión de una base de datos MySQL
* @author Ricardo Montañana <rmontanana@gmail.com>
* @version 1.0
* @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 <http://www.gnu.org/licenses/>.
*
*/
class Sql
{
/**
* @var mixed Manejador de la base de datos.
*/
private $bdd=NULL;
private $bdd = NULL;
/**
* @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.
*/
private $error=false;
private $error = false;
/**
* @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.
*/
private $peticion=NULL;
private $peticion = NULL;
/**
* @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.
*/
private $datos=array();
private $datos = array();
/**
* Id del último registro insertado
* @var integer mysql_
@@ -61,20 +63,21 @@ class Sql {
* @param string $usuario
* @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()) {
$this->mensajeError='<h1>Fallo al conectar con el servidor MySQL.</h1>';
$this->mensajeError.="Servidor [".$servidor ."] base de datos [".$baseDatos."]";
$this->error=true;
$this->estado=false;
$this->mensajeError = '<h1>Fallo al conectar con el servidor MySQL.</h1>';
$this->mensajeError .= "Servidor [" . $servidor . "] base de datos [" . $baseDatos . "]";
$this->error = true;
$this->estado = false;
} else {
$this->mensajeError='';
$this->error=false;
$this->estado=true;
$this->mensajeError = '';
$this->error = false;
$this->estado = true;
}
$this->peticion=NULL;
$this->peticion = NULL;
$this->bdd->set_charset("latin1");
return $this;
}
public function __destruct()
@@ -88,68 +91,69 @@ class Sql {
$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)
{
if (!$this->estado) {
$this->error=true;
$this->mensajeError='No est&aacute; conectado';
$this->error = true;
$this->mensajeError = 'No est&aacute; conectado';
return false;
}
if (!$this->peticion=$this->bdd->query($comando)) {
$this->error=true;
$this->mensajeError='No pudo ejecutar la petici&oacute;n: '.$comando;
if (!$this->peticion = $this->bdd->query($comando)) {
$this->error = true;
$this->mensajeError = 'No pudo ejecutar la petici&oacute;n: ' . $comando;
return false;
}
$this->numero=$this->bdd->affected_rows;
$this->id=$this->bdd->insert_id;
$this->error=false;
$this->mensajeError='';
$this->numero = $this->bdd->affected_rows;
$this->id = $this->bdd->insert_id;
$this->error = false;
$this->mensajeError = '';
return true;
}
public function procesaResultado()
{
if (!$this->estado) {
$this->error=true;
$this->mensajeError='No está conectado a una base de datos';
$this->error = true;
$this->mensajeError = 'No está conectado a una base de datos';
return NULL;
}
if (!$this->peticion) {
$this->error=true;
$this->mensajeError='No hay un resultado disponible';
$this->error = true;
$this->mensajeError = 'No hay un resultado disponible';
return NULL;
}
$datos=$this->peticion->fetch_assoc();
$this->error=false;
$this->mensajeError='';
$datos = $this->peticion->fetch_assoc();
$this->error = false;
$this->mensajeError = '';
return ($datos);
}
public function camposResultado()
public function camposResultado()
{
if (!$this->estado) {
$this->error=true;
$this->mensajeError='No está conectado a una base de datos';
$this->error = true;
$this->mensajeError = 'No está conectado a una base de datos';
return NULL;
}
if (!$this->peticion) {
$this->error=true;
$this->mensajeError='No hay un resultado disponible';
$this->error = true;
$this->mensajeError = 'No hay un resultado disponible';
return NULL;
}
$datos=$this->peticion->fetch_field();
$this->error=false;
$this->mensajeError='';
$datos = $this->peticion->fetch_field();
$this->error = false;
$this->mensajeError = '';
return ($datos);
}
/**
* Devuelve el número de tuplas afectadas en la última petición.
* @return integer Número de tuplas.
*/
public function numeroTuplas() {
public function numeroTuplas()
{
return $this->numero;
}
/**
@@ -157,30 +161,32 @@ class Sql {
* con SELECT SQL_CALC_FOUND_ROWS * ...
* @return integer Número de tuplas.
*/
public function numeroTotalTuplas()
public function numeroTotalTuplas()
{
$comando = "select found_rows();";
if (!$peticion=$this->bdd->query($comando)) {
$this->error=true;
$this->mensajeError='No pudo ejecutar la petici&oacute;n: '.$comando;
if (!$peticion = $this->bdd->query($comando)) {
$this->error = true;
$this->mensajeError = 'No pudo ejecutar la petici&oacute;n: ' . $comando;
return false;
}
$numero = $peticion->fetch_row();
return $numero[0] ;
return $numero[0];
}
/**
* Devuelve la condición de error de la última petición
* @return boolean condición de error.
*/
public function error() {
public function error()
{
return $this->error;
}
/**
* Devuelve el mensaje de error de la última petición
* @return <type>
*/
public function mensajeError() {
return $this->mensajeError.$this->bdd->error;
public function mensajeError()
{
return $this->mensajeError . $this->bdd->error;
}
/**
* Devuelve la estructura de campos de una tabla.
@@ -192,12 +198,12 @@ class Sql {
if ($this->peticion) {
$this->peticion->free_result();
}
$comando="show full columns from $tabla";
$comando = "show full columns from $tabla";
if (!$this->ejecuta($comando)) {
return false;
}
while ($dato=$this->procesaResultado()) {
$salida[]=$dato;
while ($dato = $this->procesaResultado()) {
$salida[] = $dato;
}
return $salida;
}
@@ -217,7 +223,7 @@ class Sql {
{
$codigo = $this->bdd->rollback();
$this->bdd->autocommit(true);
return $codigo;
return $codigo;
}
public function confirmaTransaccion()
{
@@ -227,5 +233,3 @@ class Sql {
return $codigo;
}
}
?>