Nouveaux noms des fichiers images. Correction de la modification de l'image. Enregistrement vide ne peut plus etre enregistre
parent
fe96c595e5
commit
59450c34ef
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
ini_set('display_errors', 0);
|
||||
|
||||
if (isset($_POST['produit']) && isset($_POST['vendeur'])) {
|
||||
if ($_POST['produit']!== '' && $_POST['vendeur']!== null && $_POST['quantite']!==0 && $_POST['prix']!== null) {
|
||||
// Connexion à la base de données
|
||||
include '../../config/conf.php';
|
||||
$bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password);
|
||||
|
|
|
@ -8,13 +8,15 @@ if($_POST['id'] !== null)
|
|||
|
||||
$params['product_id'] = $_POST['id'];
|
||||
$filename = $_POST['nom_image'];
|
||||
$nom_antenne = $_POST['antenne_slug'];
|
||||
// Suppression du bien/service
|
||||
$requete = "DELETE FROM products WHERE id = :product_id";
|
||||
$stmt = $bdd->prepare($requete);
|
||||
$stmt->execute($params);
|
||||
// Suppression de la photo du produit si elle existe
|
||||
if (file_exists('../uploads/products/'.$filename)) {
|
||||
unlink('../uploads/products/'.$filename);
|
||||
$nom_fichier = '../uploads/products/'.$nom_antenne.'/'.$filename;
|
||||
if (file_exists($nom_fichier)) {
|
||||
unlink($nom_fichier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password);
|
|||
<td>$number</td>";
|
||||
|
||||
$data .= '<td>'.$row['name'].'</td>';
|
||||
$data .= '<td><img src="/uploads/products/'.$row['image'].'" width="100" height="100" /></td>';
|
||||
$data .= '<td><img src="/uploads/products/'.$antenne_slug.'/'.$row['image'].'" width="100" height="100" /></td>';
|
||||
$data .= '<td>'.$row['username'].'</td>';
|
||||
$data .= '<td></td>';
|
||||
$data .= '<td>'.$row['quantite'].'</td>';
|
||||
|
@ -50,6 +50,9 @@ $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password);
|
|||
$data .= "'";
|
||||
$data .= ',';
|
||||
$data .= "'$antenne_slug'";
|
||||
$data .= ",'";
|
||||
$data .= $row['image'];
|
||||
$data .= "'";
|
||||
if ($row['username'] == $_GET['nom_connecte'] ) {
|
||||
$data .= ')" class=\'btn btn-primary\'';
|
||||
} else {
|
||||
|
@ -81,7 +84,7 @@ $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password);
|
|||
else
|
||||
{
|
||||
// Il n'y a pas encore de biens/services saisis
|
||||
$data .= "<tr style='text-align:left;color:white;'><td colspan='10'>Aucun enregistrement saisi</td></tr>";
|
||||
$data .= "<tr style='background-color:lightblue;text-align:left;color:black;'><td colspan='10'>Aucun enregistrement saisi</td></tr>";
|
||||
}
|
||||
|
||||
$data .= '</table>';
|
||||
|
|
|
@ -5,20 +5,29 @@ $filename = $_FILES['image']['name'] ?? $_FILES['add_image']['name'];
|
|||
|
||||
// Emplacement
|
||||
$path = str_replace('\\', '/', dirname(realpath(__DIR__)));
|
||||
$location = $path.'/uploads/products/'.$filename;
|
||||
$location2 = '/uploads/products/'.$filename;
|
||||
//$location = $path.'/uploads/products/'.$filename;
|
||||
$location = $path.'/uploads/products/';
|
||||
//$location2 = '/uploads/products/'.$filename;
|
||||
|
||||
// Extension du fichier
|
||||
$file_extension = pathinfo($location, PATHINFO_EXTENSION);
|
||||
$file_extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
$file_extension = strtolower($file_extension);
|
||||
|
||||
// Extensions valides d'image
|
||||
$image_ext = array("jpg","png","jpeg");
|
||||
|
||||
$nom_user = $_POST['nom_user'];
|
||||
$nom_antenne = $_POST['nom_antenne'];
|
||||
$response = 0;
|
||||
if(in_array($file_extension,$image_ext)){
|
||||
$directory = $location.$nom_antenne;
|
||||
if (file_exists($directory) === false) {
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
$nom_fichier = $nom_antenne.'-'.$nom_user.'-'.uniqid("",true).'.'.$file_extension;
|
||||
$location2 = '/uploads/products/'.$nom_antenne.'/'.$nom_fichier;
|
||||
// Upload du fichier
|
||||
if(move_uploaded_file($_FILES['image']['tmp_name'] ?? $_FILES['add_image']['tmp_name'],$location)){
|
||||
if(move_uploaded_file($_FILES['image']['tmp_name']
|
||||
?? $_FILES['add_image']['tmp_name'],$directory.'/'.$nom_fichier)){
|
||||
$response = $location2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
function addRecord(antenne_slug, antenne_id, nom_connecte, id_user) {
|
||||
|
||||
var produit = $("#produit").val();
|
||||
var image = $("#add_image").val();
|
||||
var nom_image = image.substring(image.lastIndexOf("\\")+1);
|
||||
var image = $("#hidden_image_name").val();
|
||||
var nom_image = image.substring(image.lastIndexOf("/")+1);
|
||||
var vendeur = $("#vendeur").val();
|
||||
var cle_pub = $("#cle_pub").val();
|
||||
var quantite = $("#quantite").val();
|
||||
|
@ -88,6 +88,7 @@ function DeleteProduits(id, antenne_slug, nom_image) {
|
|||
if (conf == true) {
|
||||
$.post("/ajax/deleteProduits.php", {
|
||||
id: id,
|
||||
antenne_slug: antenne_slug,
|
||||
nom_image: nom_image
|
||||
},
|
||||
function (data, status) {
|
||||
|
@ -113,10 +114,11 @@ function DeleteRecherches(id) {
|
|||
);
|
||||
}
|
||||
}
|
||||
function GetProduitsDetails(id, antenne_slug) {
|
||||
function GetProduitsDetails(id, antenne_slug, nom_image) {
|
||||
// Add Products ID to the hidden field for future usage
|
||||
$("#hidden_user_id").val(id);
|
||||
$("#hidden_antenne_slug").val(antenne_slug);
|
||||
$("#hidden_image_name").val(nom_image);
|
||||
$.post("/ajax/readProduitsDetails.php", {
|
||||
id: id
|
||||
},
|
||||
|
@ -124,7 +126,7 @@ function GetProduitsDetails(id, antenne_slug) {
|
|||
var produit = JSON.parse(data);
|
||||
// Assign existing values to the modal popup fields
|
||||
$("#update_produit").val(produit.name);
|
||||
$("#preview").html('<img src="/uploads/products/'+produit.image+'" />');
|
||||
$("#preview").html('<img src="/uploads/products/'+antenne_slug+'/'+produit.image+'" />');
|
||||
$("#update_vendeur").val(produit.username);
|
||||
$("#update_quantite").val(produit.quantite);
|
||||
$("#update_prix").val(produit.prix);
|
||||
|
@ -155,8 +157,9 @@ function GetRecherchesDetails(id) {
|
|||
function UpdateProduitsDetails(nom_connecte) {
|
||||
|
||||
var produit = $("#update_produit").val();
|
||||
var image = $("#image").val();
|
||||
var nom_image = image.substring(image.lastIndexOf("\\")+1);
|
||||
var image = $("#hidden_image_name").val();
|
||||
var nom_image = image.substring(image.lastIndexOf("/")+1);
|
||||
//alert('nom_image='+nom_image);
|
||||
var quantite = $("#update_quantite").val();
|
||||
var prix = $("#update_prix").val();
|
||||
// Champs cachés
|
||||
|
@ -219,6 +222,8 @@ $(document).ready(function () {
|
|||
var fd_add = new FormData();
|
||||
var files = $('#add_image')[0].files[0];
|
||||
fd_add.append('add_image',files);
|
||||
fd_add.append('nom_user',nom_connecte);
|
||||
fd_add.append('nom_antenne',antenne_slug);
|
||||
|
||||
// requête AJAX pour copier la photo et l'afficher
|
||||
$.ajax({
|
||||
|
@ -232,6 +237,8 @@ $(document).ready(function () {
|
|||
// Show image preview
|
||||
$('#add_preview').html('');
|
||||
$('#add_preview').append("<img src='"+response+"' width='160' height='160' style='display: inline-block;'>");
|
||||
// get hidden field value
|
||||
$("#hidden_image_name").val(response);
|
||||
} else {
|
||||
alert('L\'image n\'a pu être uploadée');
|
||||
}
|
||||
|
@ -243,7 +250,8 @@ $(document).ready(function () {
|
|||
var fd = new FormData();
|
||||
var files = $('#image')[0].files[0];
|
||||
fd.append('image',files);
|
||||
|
||||
fd.append('nom_user',nom_connecte);
|
||||
fd.append('nom_antenne',antenne_slug);
|
||||
// requête AJAX pour copier la photo et l'afficher
|
||||
$.ajax({
|
||||
url: '/ajax/upload.php',
|
||||
|
@ -256,6 +264,8 @@ $(document).ready(function () {
|
|||
// Show image preview
|
||||
$('#preview').html('');
|
||||
$('#preview').append("<img src='"+response+"' width='160' height='160' style='display: inline-block;'>");
|
||||
// get hidden field value
|
||||
$("#hidden_image_name").val(response);
|
||||
} else {
|
||||
alert('L\'image n\'a pu être uploadée');
|
||||
}
|
||||
|
|
|
@ -137,7 +137,6 @@
|
|||
<div class="col-md-7">
|
||||
<form method='post' action='' enctype="multipart/form-data">
|
||||
Choisir l'image : <input type='file' name='file' id='image' class='form-control' ><br>
|
||||
<!--<input type='button' class='btn btn-info' value='Upload image' id='upload'>-->
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
|
@ -158,6 +157,7 @@
|
|||
<button type="button" class="btn btn-primary" onclick="UpdateProduitsDetails('{{ current_user().username }}')" >Sauvegarder</button>
|
||||
<input type="hidden" id="hidden_user_id">
|
||||
<input type="hidden" id="hidden_antenne_slug">
|
||||
<input type="hidden" id="hidden_image_name">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue