1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| <?php
session_start();
setlocale(LC_TIME, 'fr_FR.ISO_8859-1');
date_default_timezone_set('Europe/Paris');
include_once('../includes/fonctions.php');
$nomsite = "Ultra Code Discount";
$debug = true;
$errors = array(); //To store errors
$form_data = array(); //Pass back the data to `form.php`
$id_prod = array();
$id_vendeur = array();
/* Validate the form on server side */
if ($_POST['id_prod']) { //Name cannot be empty
$id_prod = intval($_POST['id_prod']);
$id_vendeur = intval($_POST['id_vendeur']);
$info101 = $db->prepare('SELECT * FROM codetyp WHERE id = :id_prod');
$info101->bindValue('id_prod',$id_prod, PDO::PARAM_INT);
$info101->execute();
$membre101=$info101->fetch(PDO::FETCH_OBJ);
$codes2 = $db->prepare('SELECT * FROM codes WHERE type = :id_code AND id_vendeur = :id_vendeur AND utilisation = :util ');
$codes2->bindValue('id_code',$membre101->id_code, PDO::PARAM_INT);
$codes2->bindValue('id_vendeur',$id_vendeur, PDO::PARAM_INT);
$codes2->bindValue('util','0', PDO::PARAM_INT);
$codes2->execute();
$nbentrees = $codes2->rowCount();
if($nbentrees != ''){
$errors['id_prod'] = $nbentrees.'-'.$id_prod;
}else{
$errors['id_prod'] = "Stock Insufissant";
}
}
if (!empty($errors)) { //If errors in validation
$form_data['success'] = false;
$form_data['errors'] = $errors;
} else { //If not, process the form, and return true on success
$form_data['success'] = true;
if($form_data['success'] == true){
$info = $db->prepare('SELECT * FROM membres WHERE id_membre = ?');
$info->bindValue(1,$_POST['id_membre'], PDO::PARAM_INT);
$info->execute();
$membre=$info->fetch(PDO::FETCH_OBJ);
$info10 = $db->prepare('SELECT * FROM codetyp WHERE id = ?');
$info10->bindValue(1,$_POST['id_prod'], PDO::PARAM_INT);
$info10->execute();
$membre10=$info10->fetch(PDO::FETCH_OBJ);
$quantite = intval($_POST['qte']);
$total = $quantite * $membre10->prix;
$codes = $db->prepare('SELECT * FROM codes WHERE type = ? AND id_vendeur = ? AND utilisation = ? LIMIT ' . $quantite);
$codes->bindValue(1,$membre10->id_code, PDO::PARAM_INT);
$codes->bindValue(2,$_POST['id_vendeur'], PDO::PARAM_INT);
$codes->bindValue(3,'0', PDO::PARAM_INT);
$codes->execute();
$nbentrees = $codes->rowCount();
while($codeach=$codes->fetch(PDO::FETCH_OBJ)) {
$coderip1[] = $codeach->code;
$coderip12[] = $codeach->id_code;
for($i=0;$i<$nbentrees;$i++) {
$nouvdemande1 = $db->prepare('UPDATE codes SET utilisation=:utilisation, id_membre=:id_membre where code=:code');
$nouvdemande1->bindValue('utilisation','1', PDO::PARAM_INT);
$nouvdemande1->bindValue('id_membre',$_POST['id_membre'], PDO::PARAM_INT);
$nouvdemande1->bindValue('code',$codeach->code, PDO::PARAM_INT);
$nouvdemande1->execute();
$form_data['posted'] = $coderip1;
}
}
$addClient1 = $db->prepare("INSERT INTO achat_codes (id_membre,id_vendeur,timetemps,id_code,codes,montant,nbr_code) VALUES (:id_membre,:id_vendeur,:timetemps,:id_code,:codes,:montant,:nbr_code)");
$addClient1->bindParam('id_membre',$_SESSION['id_membre'], PDO::PARAM_INT);
$addClient1->bindParam('id_vendeur',$_POST['id_vendeur'], PDO::PARAM_INT);
$addClient1->bindParam('timetemps',time(), PDO::PARAM_INT);
$addClient1->bindParam('id_code',$_POST['id_prod'], PDO::PARAM_INT);
$addClient1->bindParam('codes',implode(',',array_values($coderip1)), PDO::PARAM_INT);
$addClient1->bindParam('montant',$total, PDO::PARAM_INT);
$addClient1->bindParam('nbr_code',$_POST['qte'], PDO::PARAM_INT);
//$addClient1->execute();
}
}
//Return the data back to form.php
echo json_encode($form_data);
?> |
Partager