mirror of
https://github.com/rmontanana/inventario2.git
synced 2025-08-16 07:56:00 +00:00
-Incluido x-editable
-Incluido Ajax incluido campos select
This commit is contained in:
62
Ajax.php
62
Ajax.php
@@ -26,25 +26,61 @@ $ajax = new Ajax();
|
||||
echo $ajax->procesa();
|
||||
|
||||
class Ajax {
|
||||
private function respuesta($exito, $mensaje)
|
||||
private $sql;
|
||||
private $tabla;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->sql = new Sql(SERVIDOR, USUARIO, CLAVE, BASEDATOS);
|
||||
if ($this->sql->error()) {
|
||||
return $this->respuesta($this->mensaje(false, 'Error conectando con la Base de Datos'));
|
||||
};
|
||||
$this->tabla = $_GET['tabla'];
|
||||
}
|
||||
private function respuesta($mensaje)
|
||||
{
|
||||
$resp = json_encode(array("success" => $exito, "msj" => $mensaje));
|
||||
header('Content-Type: application/json', true, 200);
|
||||
return $resp;
|
||||
return $mensaje;
|
||||
}
|
||||
public function procesa()
|
||||
{
|
||||
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
|
||||
$tabla = $_GET['tabla'];
|
||||
$sql = new Sql(SERVIDOR, USUARIO, CLAVE, BASEDATOS);
|
||||
if ($sql->error()) {
|
||||
return $this->respuesta(false, 'Error conectando con la Base de Datos');
|
||||
$opc = $_GET['opc'];
|
||||
switch ($opc) {
|
||||
case "get": return $this->obtiene();
|
||||
case "put": return $this->actualiza();
|
||||
}
|
||||
$comando = "update " . mysql_escape_string($tabla) . " set " . mysql_escape_string($_POST['name']) . " = '" . mysql_escape_string($_POST['value']) . "' where id = '" . mysql_escape_string($_POST['pk']). "';";
|
||||
$sql->ejecuta($comando);
|
||||
$exito = !$sql->error();
|
||||
$mensaje = $sql->mensajeError();
|
||||
return $this->respuesta($exito, $mensaje);
|
||||
}
|
||||
private function mensaje($exito, $texto)
|
||||
{
|
||||
return json_encode(array("success" => $exito, "msj" => $texto));
|
||||
}
|
||||
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']). "';";
|
||||
$this->sql->ejecuta($comando);
|
||||
$exito = !$this->sql->error();
|
||||
$mensaje = $this->sql->mensajeError();
|
||||
$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') {
|
||||
$comando = "select id, descripcion from " . $this->tabla . " order by descripcion asc;";
|
||||
$this->sql->ejecuta($comando);
|
||||
$exito = !$this->sql->error();
|
||||
$mensaje = $this->sql->mensajeError();
|
||||
if (!$exito) {
|
||||
return $this->respuesta($this->mensaje($exito, $mensaje));
|
||||
}
|
||||
$filas = array();
|
||||
while($r = $this->sql->procesaResultado()) {
|
||||
$filas[] = array($r['id'] => $r['descripcion']);
|
||||
}
|
||||
$resp = json_encode($filas);
|
||||
return $this->respuesta($resp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -53,6 +53,7 @@ define('CREDITOS', '<div class="modal fade" tabindex="-1" id="creditos" role="di
|
||||
<tr><td><a href="https://github.com/tkrotoff/jquery-simplecolorpicker" target="_blank">jquery-simplecolorpicker</a></td><td><a target="_blank" href="https://github.com/tkrotoff/jquery-simplecolorpicker/blob/master/LICENSE.txt">MIT</a></td>
|
||||
<tr><td><a href="http://eonasdan.github.io/bootstrap-datetimepicker/" target="_blank">Bootstrap datetimepicker</a></td><td><a target="_blank" href="https://github.com/Eonasdan/bootstrap-datetimepicker/blob/master/src/js/bootstrap-datetimepicker.js">MIT</a></td>
|
||||
<tr><td><a href="http://silviomoreto.github.io/bootstrap-select/" target="_blank">Bootstrap-select</a></td><td><a target="_blank" href="https://github.com/silviomoreto/bootstrap-select">MIT</a></td>
|
||||
<tr><td><a href="https://github.com/vitalets/x-editable" target="_blank">X-editable</a></td><td><a target="_blank" href="https://github.com/vitalets/x-editable/blob/master/LICENSE-MIT">MIT</a></td>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><h5>Copyright © 2008-2014 Ricardo Montañana Gómez</h4>
|
||||
|
@@ -1,3 +1,5 @@
|
||||
-Añadida actualización Ajax en Mantenimiento
|
||||
|
||||
Versión 1.082 09-04-2014
|
||||
-Ahora git tiene en cuenta los directorios tmp e img.data y no tiene en cuenta su contenido
|
||||
-Fix #30. Arreglado el botón de buscar que no enviaba los datos. Cambiado el texto por la lupa.
|
||||
|
@@ -217,12 +217,16 @@ class Mantenimiento {
|
||||
$checked = $valor == '1' ? 'checked' : '';
|
||||
$valor = '<input type="checkbox" disabled ' . $checked . '>';
|
||||
}
|
||||
if ($clave == "cantidad") {
|
||||
if (strstr($this->campos[$clave]['Comment'], "ajax") && $this->perfil['Modificacion']) {
|
||||
$comen = explode(",", $this->campos[$clave]['Comment']);
|
||||
foreach ($comen as $co) {
|
||||
if (strstr($co, "ajax")) {
|
||||
$tmpco = explode("/", $co);
|
||||
$tipo = $tmpco[1];
|
||||
}
|
||||
}
|
||||
$cant++;
|
||||
$opcion = $this->datosURL['opc'];
|
||||
$this->datosURL['opc'] = 'ajax';
|
||||
$valor = $this->campoAjax($id, $clave, $valor, $cant);
|
||||
$this->datosURL['opc'] = $opcion;
|
||||
$valor = $this->campoAjax($id, $clave, $tipo, $valor, $cant, $fila);
|
||||
}
|
||||
$salida.="<td>$valor</td>\n";
|
||||
}
|
||||
@@ -781,16 +785,31 @@ class Mantenimiento {
|
||||
return $mensaje;
|
||||
}
|
||||
|
||||
private function campoAjax($id, $clave, $valor, $cant)
|
||||
private function campoAjax($id, $clave, $tipo, $valor, $num, $datosFila)
|
||||
{
|
||||
//url: 'ajax.php?tabla=". $this->tabla . "',
|
||||
//url: '" . $this->montaURL() . "&tabla=" . $this->tabla "',
|
||||
$mensaje = '<a href="#" id="'.$clave.'" name="'.$clave.$cant.'" data-type="number" data-placement="right" data-pk="'.$id.'">' . $valor . '</a>
|
||||
$formato = $tipo == "combodate" ? 'data-format="YYYY-MM-DD" data-viewformat="DD/MM/YYYY"' : '';
|
||||
$remoto = "";
|
||||
$titulo = $clave;
|
||||
if (strstr($tipo, "select")) {
|
||||
$datos = explode("-", $tipo);
|
||||
$tipo = $datos[0];
|
||||
$tabla2 = $datos[1];
|
||||
$clave = "id_".$clave;
|
||||
$indice = "id".$tabla2;
|
||||
$valorDato = $datosFila[$indice];
|
||||
$valorSelect = 'data-value="'.$valorDato.'" ';
|
||||
$remoto = $valorSelect . ' data-sourceCache="true" data-sourceError="Error cargando datos" data-source="ajax.php?opc=get&tabla='.$tabla2.'"';
|
||||
}
|
||||
|
||||
$mensaje = '<a href="#" title="Modifica '.$titulo.'" id="'.$clave.'" name="'.$clave.$num.'" data-type="'.$tipo.'" data-placement="right" '.$formato.' data-pk="'.$id.'" '.$remoto.' >' . $valor . '</a>
|
||||
<script>
|
||||
$(function(){' . "
|
||||
$('[name=\"".$clave.$cant."\"]').editable({
|
||||
url: 'ajax.php?tabla=". $this->tabla . "',
|
||||
title: 'Cantidad:',
|
||||
$('[name=\"".$clave.$num."\"]').editable({
|
||||
url: 'ajax.php?opc=put&tabla=". $this->tabla . "',
|
||||
title: '" . $titulo . ":',
|
||||
emptytext: 'Vacío',
|
||||
success: function(respuesta, newValue) {
|
||||
if (respuesta.success === false) {
|
||||
return respuesta.msj; //msj will be shown in editable form
|
||||
|
@@ -3,19 +3,19 @@
|
||||
<Titulo>Mantenimiento de Elementos</Titulo>
|
||||
<Consulta>
|
||||
SELECT SQL_CALC_FOUND_ROWS E.id as id,U.Descripcion as ubicacion,A.Descripcion as articulo,A.Marca as marca,A.Modelo as modelo,E.numserie as numserie,
|
||||
DATE_FORMAT(E.fechacompra, '%d/%m/%Y') as fechaCompra,E.cantidad as cantidad, E.imagen as imagen
|
||||
DATE_FORMAT(E.fechacompra, '%d/%m/%Y') as fechaCompra,E.cantidad as cantidad, E.imagen as imagen, A.id as idArticulos, U.id as idUbicaciones
|
||||
FROM Elementos E inner join Articulos A on E.id_articulo=A.id inner join
|
||||
Ubicaciones U on E.id_ubicacion=U.id {buscar} {orden} limit {inferior},{superior};
|
||||
</Consulta>
|
||||
<Campos>
|
||||
<Col Campo="id" Nombre="id" Ancho="5" Ajuste="D" Titulo="id" Tipo="smallint(6)" Varios="ordenable"/>
|
||||
<Col Campo="id_Ubicacion" Nombre="ubicacion" Ancho="40" Ajuste="L" Titulo="Ubicación" Varios="ordenable,foreign(Ubicaciones->id;{Descripcion})" Editable="si"/>
|
||||
<Col Campo="id_Articulo" Nombre="articulo" Ancho="40" Ajuste="L" Titulo="Artículo" Varios="ordenable,buscable/A.Descripcion,foreign(Articulos->id;{Descripcion/Marca/Modelo})" Editable="si"/>
|
||||
<Col Campo="id_Ubicacion" Nombre="ubicacion" Ancho="40" Ajuste="L" Titulo="Ubicación" Varios="ordenable,foreign(Ubicaciones->id;{Descripcion}),ajax/select-Ubicaciones" Editable="si"/>
|
||||
<Col Campo="id_Articulo" Nombre="articulo" Ancho="40" Ajuste="L" Titulo="Artículo" Varios="ordenable,buscable/A.Descripcion,foreign(Articulos->id;{Descripcion/Marca/Modelo}),ajax/select-Articulos" Editable="si"/>
|
||||
<Col Nombre="marca" Ancho="40" Ajuste="L" Titulo="Marca" Varios="ordenable" Editable="no"/>
|
||||
<Col Nombre="modelo" Ancho="40" Ajuste="L" Titulo="Modelo" Varios="ordenable" Editable="no"/>
|
||||
<Col Campo="numserie" Nombre="numserie" Ancho="30" Ajuste="L" Titulo="Nº Serie" Varios="ordenable" Editable="si"/>
|
||||
<Col Campo="fechaCompra" Nombre="fechaCompra" Ancho="25" Ajuste="L" Titulo="Compra" Varios="ordenable" Tipo="fecha" Editable="si"/>
|
||||
<Col Campo="cantidad" Nombre="cantidad" Ancho="15" Ajuste="D" Titulo="Cant." Tipo="Int(11)" Editable="si"/>
|
||||
<Col Campo="numserie" Nombre="numserie" Ancho="30" Ajuste="L" Titulo="Nº Serie" Varios="ordenable,ajax/text" Editable="si"/>
|
||||
<Col Campo="fechaCompra" Nombre="fechaCompra" Ancho="25" Ajuste="L" Titulo="Compra" Varios="ordenable,ajax/combodate" Tipo="fecha" Editable="si"/>
|
||||
<Col Campo="cantidad" Nombre="cantidad" Ancho="15" Ajuste="D" Titulo="Cant." Tipo="Int(11)" Editable="si" Varios="ajax/number"/>
|
||||
<Col Campo="imagen" Nombre="imagen" Ancho="10" Titulo="Imagen" Tipo="imagen" Editable="si" Varios="imagen"/>
|
||||
</Campos>
|
||||
</Mantenimiento>
|
||||
|
@@ -7,9 +7,9 @@
|
||||
</Consulta>
|
||||
<Campos>
|
||||
<Col Campo="id" Nombre="id" Ancho="5" Ajuste="D" Titulo="id" Tipo="int(6)" Varios="ordenable"/>
|
||||
<Col Campo="nombre" Nombre="nombre" Ancho="8" Ajuste="L" Titulo="Nombre" Varios="ordenable,buscable/nombre" Editable="si"/>
|
||||
<Col Campo="clave" Nombre="clave" Ancho="16" Ajuste="L" Titulo="Clave" Tipo="Password" Editable="si"/>
|
||||
<Col Campo="idSesion" Nombre="idSesion" Ancho="32" Ajuste="L" Titulo="id Sesión" Editable="si"/>
|
||||
<Col Campo="nombre" Nombre="nombre" Ancho="8" Ajuste="L" Titulo="Nombre" Varios="ordenable,buscable/nombre,ajax/text" Editable="si"/>
|
||||
<Col Campo="clave" Nombre="clave" Ancho="16" Ajuste="L" Titulo="Clave" Tipo="Password" Editable="si" Varios="ajax/text"/>
|
||||
<Col Campo="idSesion" Nombre="idSesion" Ancho="32" Ajuste="L" Titulo="id Sesión" Editable="si" Varios="ajax/text"/>
|
||||
<Col Campo="alta" Nombre="alta" Ancho="1" Ajuste="R" Tipo="Boolean" Titulo="Altas" Editable="si"/>
|
||||
<Col Campo="modificacion" Nombre="modificacion" Ancho="1" Ajuste="R" Tipo="Boolean" Titulo="Modificaciones" Editable="si"/>
|
||||
<Col Campo="borrado" Nombre="borrado" Ancho="1" Ajuste="R" Tipo="Boolean" Titulo="Borrados" Editable="si"/>
|
||||
|
Reference in New Issue
Block a user