-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartreport.php
executable file
·95 lines (83 loc) · 2.64 KB
/
cartreport.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
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
<?php
header("Content-Type: text/html; charset=utf-8");
require_once("session.php");
require_once("class.user.php");
require_once("mycart.php");
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT *
FROM users
WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if(isset($_POST["customername"]) && ($_POST["customername"]!="")){
// Shopping cart
$cart = unserialize($_SESSION['cart']);
if(!is_object($cart))
{
$cart = new myCart();
}
// Order summary
$total = $cart->total;
$deliverfee = $cart->deliverfee;
$grandtotal = $cart->grandtotal;
$cname = $_POST["customername"];
$cmail = $_POST["customeremail"];
$caddress = $_POST["customeraddress"];
$ctel = $_POST["customerphone"];
$cpaytype = $_POST["paytype"];
try
{
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$auth_user->neworder($user_id,$total,$deliverfee,$grandtotal,$cname,$cmail,$caddress,$ctel,$cpaytype);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
$corder_id = unserialize($_SESSION['orderid']);
// Order detail
if($cart->itemcount > 0) {
foreach($cart->get_contents() as $item) {
$detail_id = $item['id'];
$detail_info = $item['info'];
$detail_price = $item['price'];
$detail_qty = $item['qty'];
$auth_user->orderdetail($corder_id,$detail_id,$detail_info,$detail_price,$detail_qty);
}
}
// Email
$mailcontent=<<<msg
Dear $cname,
Thanks for visiting NCTU E-Store!
Order Detail:
--------------------------------------------------
Order #: $corder_id
Customer Name:$cname
Email: $cmail
Phone: $ctel
Shipping address: $caddress
Payment type: $cpaytype
Order total: $grandtotal
--------------------------------------------------
We hope to see you again soon.
NCTU E-Store
msg;
$mailFrom="=?UTF-8?B?" . base64_encode("NCTU E-Store") . "?= <tingkailiu.nu@gmail.com>";
$mailto = $_POST["customeremail"];
$mailSubject="=?UTF-8?B?" . base64_encode("Your NCTU E-Store Order"). "?=";
$mailHeader="From:".$mailFrom."\r\n";
$mailHeader.="Content-type:text/html;charset=UTF-8";
if(!@mail($mailto,$mailSubject,nl2br($mailcontent),$mailHeader)) die("Email Failure!");
// Clear cart
unset($_SESSION['cart']);
unset($_SESSION['orderid']);
$cart = new myCart();
$_SESSION['cart'] = serialize($cart);
}
?>
<script language="javascript">
alert("Thank you for shopping with us. We will send a confirmation when your item ships");
window.location.href="homepage.php";
</script>