Skip to content

Commit

Permalink
correction ajout de produit
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2choiz committed Apr 22, 2015
1 parent 6f151d1 commit 1530095
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions Application/Controllers/Produit.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getProduit($params) {
var_dump($res);

if( !empty( $res ) ) {
return $this->setApiResult( $res);
return $this->setApiResult( $res[0]);
}else{
return $this->setApiResult(false, true, "erreur pendant la recuperation des produit");
}
Expand Down Expand Up @@ -80,22 +80,38 @@ public function insertProduit($params) {
$this->setMode("brut"); //pour pouvoir lancer une fonction js du webservice




//verification des champs
echo "prix avant = ".$params['prix'];
$params['top']="0";
$params['prix']=floatval($params['prix']);
if(($params['prix']+0)>2000000){
$error="le prix est trop elevé";
echo '
<script type="text/javascript">
window.top.window.finUpload("'.$error.'", 0);
</script>';
return $this->setApiResult(false, true, "le prix est trop elevé");
}


//###################################################### reste a 10 pas

$targetpath='';
$error = NULL;
$filename = NULL;
var_dump($_FILES);
var_dump("dolfile",$_FILES);
if ( isset($_FILES['img']) && $_FILES['img']['error'] === 0 ) {
echo 'dans le if<BR>';
//echo 'dans le if<BR>';
$filename = $this->retirerCaractereSpeciaux($params['value']);
$targetpath = IMG_ROOT."produit/". $filename.'.jpg'; // On stocke le chemin où enregistrer le fichier
echo $filename."<BR>".$targetpath."<br>".$_FILES['img']['tmp_name']."<br>";
// On déplace le fichier depuis le répertoire temporaire vers $targetpath

if (@move_uploaded_file($_FILES['img']['tmp_name'], $targetpath)) { // Si ça fonctionne
$error = 'non';
$params['img']="/img/produit/". $filename.'.jpg';
$params['img']="produit/". $filename.'.jpg';
}else{ // Si ça ne fonctionne pas
$error = "Échec de l'enregistrement !";
}
Expand All @@ -109,18 +125,16 @@ public function insertProduit($params) {





var_dump("params",$params);
$res=$modelProduit->insert($params);
//echo $res;
echo "DLD".$res."##";




if( $res ) {
if( $res>0 ) {

echo '
'.$res.'
<script type="text/javascript">
window.top.window.finUpload("'.$error.'", '.$modelProduit->getLast().');
</script>';
Expand Down Expand Up @@ -192,6 +206,8 @@ public function deleteProduit($params) { //delete une recette




/*
public function recupererScriptNewProduit($params){
unset($params['method']);
Expand Down Expand Up @@ -243,7 +259,7 @@ public function recupererScriptNewProduit($params){
}else{
return $this->setApiResult(false, true, "Le produit n'existe pas");
}
}
}*/



Expand Down

0 comments on commit 1530095

Please sign in to comment.