Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
data
/
web
/
vhosts
/
www.taxi-78.com
/
htdocs
/
admin000
/
connected
/
functions
/
/srv/data/web/vhosts/www.taxi-78.com/htdocs/admin000/connected/functions/product-edit.php
<?php if(!isset($_GET['id']) || $_GET['id']<1) header("Location: catalogue"); $idProduct = $_GET['id']; $stmt=$db_client->prepare("SELECT * FROM product WHERE id=? AND id_company=?"); // on prépare notre requête $stmt->execute(array($idProduct,$conf_id_company)); $product = $stmt->fetch(); if(!$product) header("Location: catalogue"); extract(get_object_vars($product)); if(isset($_POST['submitAjout'])){ extract($_POST); $err1=($name=='')?true:false; $err2=(!preg_match("/^[0-9]*([,.][0-9]{1,2})?$/",$price))?true:false; $err3=(!preg_match("/^[0-9]*([,.][0-9]{1,2})?$/",$shipping_cost))?true:false; //$err4=($desc_short=='')?true:false; $err5=($desc_long=='')?true:false; $err6=(!preg_match("/^[0-9]*([,.][0-9]{1,3})?$/",$length))?true:false; $err7=(!preg_match("/^[0-9]*([,.][0-9]{1,3})?$/",$width))?true:false; $err8=(!preg_match("/^[0-9]*([,.][0-9]{1,3})?$/",$height))?true:false; $err9=(!preg_match("/^[0-9]*([,.][0-9]{1,3})?$/",$weight))?true:false; if(!$err1 && !$err2 && !$err3 /*&& !$err4*/ && !$err5 && !$err6 && !$err7 && !$err8 && !$err9){ $ins_length = str_replace(",",".",$length); $ins_width = str_replace(",",".",$width); $ins_height = str_replace(",",".",$height); $ins_weight = str_replace(",",".",$weight); $ins_price = str_replace(",",".",$price); $ins_tax = str_replace(",",".",$tax); $shipping_cost = str_replace(",",".",$shipping_cost); $product=array($name,$reference,$desc_short,$desc_long,$ins_length,$ins_width,$ins_height,$ins_weight,$ins_price,$ins_tax,$shipping_cost,$idProduct); $stmt=$db_client->prepare("UPDATE product SET name=?,reference=?,desc_short=?,desc_long=?,length=?,width=?,height=?,weight=?,price=?,tax=?,shipping_cost=?,update_at=NOW() WHERE id=?"); $stmt->execute($product); header("Location: catalogue"); }else echo "<div id='alert' class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'>×</button>Les champs ne sont pas correctement remplis.</div>"; } //Ajout d'une image if (isset($_POST['formAdd'])){ $title = trim($_POST['title']); $legend=$_POST['legend']; if($_FILES['image']['size']>0){ $dossier = "img/products/"; $image=$dossier.rand(100,999).'-'.basename($_FILES['image']['name']); if(!file_exists($image)) { if(move_uploaded_file($_FILES['image']['tmp_name'], "../../".$image)){ $stmt=$db_client->prepare("INSERT INTO product_image(title,legend,src,product) VALUES (?,?,?,?)"); // on prépare notre requête $stmt->execute(array($title,$legend,$image,$idProduct)); $title = $legend = null; echo "<div class='alert alert-success'> <button type='button' class='close' data-dismiss='alert'>×</button>Votre image a été ajoutée. </div>"; }else echo "<div class='alert alert-danger'> <button type='button' class='close' data-dismiss='alert'>×</button> Votre image n'a pas pu être ajoutée, merci de réessayer. </div>"; }else echo "<div class='alert alert-danger'> <button type='button' class='close' data-dismiss='alert'>×</button> Ce nom de fichier existe déjà. Veuillez renommer votre fichier et le re-uploader, ou supprimer le fichier nommé ".basename($_FILES['image']['name'])." </div>"; }else echo "<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'>×</button>Vous devez choisir une image.</div>"; } //Mise à jour d'une image if (isset($_POST['formUpdate'])) { $id = $_POST['id']; $title = trim($_POST['title']); $legend=$_POST['legend']; $stmt=$db_client->prepare("UPDATE product_image set title=?,legend=? WHERE id=? AND product=?"); // on prépare notre requête $stmt->execute(array($title,$legend,$id,$idProduct)); $title = $legend = $id = null; echo "<div class='alert alert-success'> <button type='button' class='close' data-dismiss='alert'>×</button>Votre image a été mise à jour. </div>"; } //Suppression d'une image if (isset($_POST['formRemove'])) { if(unlink("../../".$_POST['image'])){ $stmt=$db_client->prepare("DELETE FROM product_image WHERE id=? AND product=?"); // on prépare notre requête $stmt->execute(array($_POST['id'],$idProduct)); echo "<div class='alert alert-success'> <button type='button' class='close' data-dismiss='alert'>×</button>Votre image a été supprimée. </div>"; }else{ echo "<div class='alert alert-danger'> <button type='button' class='close' data-dismiss='alert'>×</button>Votre image n'a été supprimée, merci de réessayer. </div>"; } } $stmt=$db_client->prepare("SELECT * FROM product_image WHERE product=?"); // on prépare notre requête $stmt->execute(array($product->id)); $pictures = $stmt->fetchAll();