forked from Athox/Projet-PHP-Vente-Bio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_commande.php
58 lines (50 loc) · 1.67 KB
/
validation_commande.php
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
<?php
session_start();
include("connection.php");
function cacul_prix_total(){
$prix_total = 0;
if(isset($_SESSION['panier'])){
foreach($_SESSION['panier'] as $produit){
$prix_total += $produit['prix']*$produit['qte_voulu'];
}
}
return $prix_total;
}
if(isset($_SESSION["login"])){
$devis=fopen("devis_".$_SESSION["login"][1]."_".date("d-m-Y").".txt","w+");
fputs($devis,$_SESSION["login"][1]);
fputs($devis,"\r\n");
fputs($devis,date("d-m-Y"));
fputs($devis,"\r\n");
fputs($devis,"\r\n");
foreach($_SESSION['panier'] as $product){
fputs($devis,"\t".$product['name']."\t");
fputs($devis,"\t".$product['qte_voulu']."\t");
fputs($devis,"\r\n");
}
fputs($devis,"\r\n");
fputs($devis," Prix total: ");
fputs($devis,cacul_prix_total());
fputs($devis,"€");
$sujet = 'Commande produit bio';
$message = $devis;
$destinataire = $_SESSION['login'][3];
$headers = "From: \"Cuchet\"<vincent.cuchet@etu.univ-lyon1.fr>\n";
$headers .= "Reply-To: vincent.cuchet@etu.univ-lyon1.fr\n";
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"";
mail($destinataire,$sujet,$message,$headers);
$idcom=connex("p1306716","Myparam");
if(isset($_SESSION['panier'])){
foreach($_SESSION['panier'] as $produit){
$qte_stock=$produit['qte_max']-$produit['qte_voulu'];
$requete="UPDATE `produits` SET `quantity_stock`=".$qte_stock." where `product_id`=".$produit['id'].";";
mysql_query($requete,$idcom);
}
}
mysql_close();
$_SESSION["panier"]=NULL;
header("Location: http://localhost/projetBoutiqueBio/panier.php");
}else{
header("Location: http://localhost/projetBoutiqueBio/connect.php");
}
?>