-
Notifications
You must be signed in to change notification settings - Fork 0
/
reservation2.php
180 lines (164 loc) · 5.91 KB
/
reservation2.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!doctype html>
<?php
if(!isset($_COOKIE["username"])){
printf("<script>location.href='login.php'</script>");
}
else{
$username = $_COOKIE["username"];
echo "<div class='welcome'>Welcome $username</div>";
}
?>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="Springtea.css">
<script src="files/jquery.min.js"></script>
<script src="files/jquery.validate.min.js"></script>
<script src="files/validation.js"></script>
<script src="files/login.js"></script>
<title>Spring Tea - Your Reservation</title>
</head>
<body>
<h1><em>Spring Tea - Your Reservation</em></h1>
<div class ="navbar">
<ul>
<li><a href="Springtea.php">Home</a></li>
<li class="confirm"><a href="account.php">Your Account</a>
<ul class="subnavbar">
<li><a href="confirmation.php">Your Orders</a></li>
</ul>
</li>
<li><a href="teainfo.php">Tea Info</a>
<ul class="subnavbar">
<li><a href="regular_tea.php">Regular Tea</a></li>
<li><a href="pu-erh_tea.php">Pu-erh Tea</a></li>
<li><a href="teapot.php">Teapot</a></li>
</ul>
</li>
<li class="order"><a href="cart.php" class="here">Cart</a>
</li>
<li><a href="contact_info.php">Contact Info</a></li>
</ul>
</div>
<br><br><br><br><br>
<fieldset>
<form action="reservation2.php" method="get">
<h1 class="info">Reservation</h1>
<a class="input" href="cart.php">Click to Check Your Orders</a><br><br>
<p class="redp">
First Name:
<input type="text" name="firstname" size="10" maxlength="20" value="<?=$_GET['firstname']?>" readonly="readonly"/><br>
Last Name:
<input type="text" name="lastname" size="10" maxlength="20" value="<?=$_GET['lastname']?>" readonly="readonly"/><br>
Delivery Date:
<input type="date" name="date" value="<?=$_GET['date']?>" /></p>
<?php
// to count the recommended shipping speed
$todaydate = date('m/d/Y', time());
$todaycount = strtotime(date('m/d/Y', time()));
$duedaycount = strtotime($_GET['date']);
$count = ($duedaycount - $todaycount) / 86400;
// to count and recommended shipping days
$count2 = 0;
echo "<p class= 'red'>Today's date: " . $todaydate . "<br>";
if($count < 0){
echo "<p class = 'red'>Please enter the correct delivery date</p>";
}
else if($count < 1){
echo "<p class = 'red'>It is too late, please change another date</p>";
}
else if($count < 2){
$count2 = 1;
echo "<p class = 'red'>Recommend Shipping Speed: One Day Shipping</p>";
}
else if($count < 6){
$count2 = 2;
echo "<p class = 'red'>Recommend Shipping Speed: Two Days Shipping</p>";
}
else if($count < 11){
$count2 = 5;
echo "<p class = 'red'>Recommend Shipping Speed: Standard Shipping</p>";
}
else{
$count2 = 10;
echo "<p class = 'red'>Recommend Shipping Speed: Economy Shipping</p>";
}
?>
<p>Shipping Speed: <select name="shippingspeed" value="<?=$_GET['shippingspeed']?>" />
<option value="1">One Day Shipping $50</option>
<option value="2">Two Days Shipping $25</option>
<option value="5">Standard Shipping $15</option>
<option value="10">Economy Shipping $10</option>
</select><br>
Address: <input type="text" name="address" size="30" maxlength="50" value="<?=$_GET['address']?>" readonly="readonly"/>
City: <select name="city" value="<?=$_GET['city']?>" readonly="readonly">
<option value="Boston">Boston</option>
<option value="Quincy">Quincy</option>
<option value="Cambridge">Cambridge</option>
<option value="Malden">Malden</option>
<option value="Newton">Newton</option>
</select><br>
ZipCode: <input type="text" name="zipcode" size="5" maxlength="5" value="<?=$_GET['zipcode']?>" readonly="readonly"/></p>
<input type="submit" name="submit" value="submit" /><br>
<?php
// The information for date
$todaydate = date('m/d/Y', time());
$todaycount = strtotime(date('m/d/Y', time()));
$duedaycount = strtotime($_GET['date']);
$count = ($duedaycount - $todaycount) / 86400;
// Connect to MySQL.
require ('mysql_connect.php');
// to get the email
$d = "bardwangsql";
$q = "SELECT * FROM $d.user WHERE username = '".$_COOKIE['username']."'";
$r = mysql_query ($q); // Run the query.
// Fetch and print all the records:
while ($row = mysql_fetch_array($r, MYSQLI_ASSOC)) {
$email = $row['email'];
}
// The information for email
$to = $email;
$subject = "Reservation From Springtea.com";
$message = "Dear " . $_GET['firstname'] . " " . $_GET['lastname'] . ",\n\nThank you for your reservation!\n
Your order will be delivered to " . $_GET['address'] . " in " . $_GET['city'] . " on " . $_GET['date'] . ".\n
Please email us if you have any question.\n
Check your orders at http://www.bardwang.com/Springtea/confirmation.php \n
Springtea.com";
$headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
$message2 = "" . $_GET['address'] . " in " . $_GET['city'] . "<br>Date: " . $_GET['date'] . "";
// database
$d = "bardwangsql";
$q = "SELECT * FROM $d.order2 WHERE username = '".$_COOKIE['username']."' AND confirm = 0";
$r = mysql_query ($q); // Run the query.
// to check if there is no order
$flag = 0;
if(mysql_fetch_array($r, MYSQLI_ASSOC) <= 0){
echo "<p class = 'red'>Sorry, you have no orders</p>";
}
else{
$flag = 1;
}
if($count >= 1 && $count >= $_GET['shippingspeed'] && $_GET['shippingspeed'] == $count2 && $flag == 1){
mail($to, $subject, $message, $headers);
// to update order information
$q = "UPDATE $d.order2
SET order_date = CURRENT_TIMESTAMP
WHERE username = '".$_COOKIE['username']."' AND confirm = 0";
$r = mysql_query ($q); // Run the query.
$q = "UPDATE $d.order2
SET confirm = confirm + 1
WHERE username = '".$_COOKIE['username']."'";
$r = mysql_query ($q); // Run the query.
$q = "INSERT INTO $d.reservation2 (username, speed, deliver_date, address)
VALUES ('".$_COOKIE['username']."', '".$_GET['shippingspeed']."', '".$_GET['date']."', '".$message2."')";
$r = mysql_query ($q);
printf("<script>location.href='confirmation.php'</script>");
}
?>
</form>
</fieldset>
<hr>
<p class="red"><a href="Credit.html">Credits</a>
</p>
</body>
</html>