ref #22 Terminadas las bajas y las inserciones, faltan las modificaciones

This commit is contained in:
2014-03-22 04:12:03 +01:00
parent fe638850b1
commit db43f56c03
3 changed files with 29 additions and 18 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
nbproject nbproject
tmp/* tmp/*
.DS_Store .DS_Store
/img.data/

View File

@@ -134,7 +134,7 @@ class Imagen {
{ {
$zebra = new Zebra_Image(); $zebra = new Zebra_Image();
$zebra->source_path = $this->archivoSubido; $zebra->source_path = $this->archivoSubido;
$this->archivoComprimido = $id . "." . $this->extension; $this->archivoComprimido = $this->dirData . "/" . $id . "." . $this->extension;
$zebra->target_path = $this->archivoComprimido; $zebra->target_path = $this->archivoComprimido;
$zebra->jpeg_quality = 100; $zebra->jpeg_quality = 100;
@@ -169,8 +169,8 @@ class Imagen {
} }
return false; return false;
} else { } else {
// //Borra el archivo subido
//unlink($this->archivoSubido); unlink($this->archivoSubido);
return true; return true;
} }
} }

View File

@@ -302,6 +302,14 @@ class Mantenimiento {
} }
$this->datosURL['opc'] = 'inicial'; $this->datosURL['opc'] = 'inicial';
$this->datosURL['id'] = null; $this->datosURL['id'] = null;
//Comprueba si existe la imagen en datos para borrarla.
$extensiones = array ("png", "gif", "jpg");
foreach ($extensiones as $extension) {
$archivo = "img.data/" . $id . "." . $extension;
if (file_exists($archivo)) {
unlink ($archivo);
}
}
$url = $this->montaURL(); $url = $this->montaURL();
header('Location: ' . $url); header('Location: ' . $url);
return; return;
@@ -345,17 +353,18 @@ class Mantenimiento {
} }
$valor = $_POST[$campo] == "on" ? '1' : $valor; $valor = $_POST[$campo] == "on" ? '1' : $valor;
} else { } else {
if (stristr("imagen", $this->campos[$campo]['Type'])) { if (stristr($this->campos[$campo]['Type'], "imagen")) {
//procesa el envío de la imagen //procesa el envío de la imagen
$imagen = new Imagen(); $imagen = new Imagen();
$accion = $imagen->determinaAccion($campo); $accion = $imagen->determinaAccion($campo);
if ($accion != NOHACERNADA) { if ($accion != NOHACERNADA) {
// El código 3 es no hacer nada. // El código 3 es no hacer nada.
$mensaje = ""; $mensaje = "";
if (!$imagen->procesaEnvio("insertar", $campo, $mensaje)) { if (!$imagen->procesaEnvio($campo, $mensaje)) {
return $this->panelMensaje($mensaje, "danger", "ERROR PROCESANDO IMAGEN"); return $this->panelMensaje($mensaje, "danger", "ERROR PROCESANDO IMAGEN");
} }
$hayImgen = true; $hayImagen = true;
$campoImagen = $campo;
} }
} else { } else {
@@ -374,7 +383,7 @@ class Mantenimiento {
if (!$imagen->mueveImagenId($id, $mensaje)) { if (!$imagen->mueveImagenId($id, $mensaje)) {
return $this->panelMensaje($mensaje, "danger", "ERROR COMPRIMIENDO IMAGEN"); return $this->panelMensaje($mensaje, "danger", "ERROR COMPRIMIENDO IMAGEN");
} }
$comando = "update " . $this->tabla . " set " . $campo . "='" . $imagen->archivoComprimido . "' where id='" . $id ."';"; $comando = "update " . $this->tabla . " set " . $campoImagen . "='" . $imagen->archivoComprimido . "' where id='" . $id ."';";
if (!$this->bdd->ejecuta($comando)) { if (!$this->bdd->ejecuta($comando)) {
return $this->errorBD($comando); return $this->errorBD($comando);
} }
@@ -598,7 +607,7 @@ class Mantenimiento {
break; break;
} }
$accion = $this->montaURL(); $accion = $this->montaURL();
$salida.='<div class="col-sm-8"><form name="mantenimiento.form" class="form-horizontal" role="form" method="post" action="' . $accion . '">' . "\n"; $salida.='<div class="col-sm-8"><form name="mantenimiento.form" enctype="multipart/form-data" class="form-horizontal" role="form" method="post" action="' . $accion . '">' . "\n";
$salida.="<fieldset style=\"width: 96%;\"><p><legend style=\"color: red;\"><b>$tipo</b></legend>\n"; $salida.="<fieldset style=\"width: 96%;\"><p><legend style=\"color: red;\"><b>$tipo</b></legend>\n";
foreach ($this->campos as $clave => $valor) { foreach ($this->campos as $clave => $valor) {
if ($valor["Editable"] == "no") { if ($valor["Editable"] == "no") {
@@ -661,7 +670,7 @@ class Mantenimiento {
continue; continue;
} }
if ($tipoCampo == "imagen(".$tamano.")") { if ($tipoCampo == "imagen(".$tamano.")") {
$salida .= $this->creaCampoImagen($campo, $valorDato); $salida .= $this->creaCampoImagen($campo, $valorDato, $tipo);
continue; continue;
} }
//Si no es una clave foránea añade un campo de texto normal //Si no es una clave foránea añade un campo de texto normal
@@ -685,7 +694,7 @@ class Mantenimiento {
return $salida; return $salida;
} }
protected function creaCampoImagen($campo, $valor) protected function creaCampoImagen($campo, $valor, $tipoAccion)
{ {
if (file_exists($valor)) { if (file_exists($valor)) {
@@ -704,19 +713,20 @@ class Mantenimiento {
if ($existe) { if ($existe) {
$mensaje .= '<img src="' . $valor . '" onclick="$('."'#mensajeModal1'".').modal();">'; $mensaje .= '<img src="' . $valor . '" onclick="$('."'#mensajeModal1'".').modal();">';
} }
$mensaje .= ' $mensaje .= '</div>';
</div> if ($tipoAccion == ANADIR || $tipoAccion == EDICION) {
<div> $mensaje .= '<div>
<span class="btn btn-default btn-file"><span class="fileinput-new">Añadir</span><span class="fileinput-exists">Cambiar</span><input type="file" name="imagen" /></span> <span class="btn btn-default btn-file" ><span class="fileinput-new">Añadir</span><span class="fileinput-exists">Cambiar</span><input type="file" name="imagen" /></span>
<a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Eliminar</a>'; <a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Eliminar</a>';
}
if ($existe) { if ($existe) {
$mensaje .='<input type="hidden" name="' . $campo . '" value="' . $valor . '">'; $mensaje .='<input type="hidden" name="' . $campo . '" value="' . $valor . '">';
} }
$mensaje .=' $mensaje .='</div>';
</div> if ($tipoAccion == ANADIR || $tipoAccion == EDICION) {
</div>'; $mensaje .= '</div>';
}
$mensaje .= $this->creaModal($valor, 1); $mensaje .= $this->creaModal($valor, 1);
return $mensaje; return $mensaje;