/
controller.php
181 lines (149 loc) · 4.66 KB
/
controller.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
<?php
require('descriptions.php');
// Login function
function checkLogin($LinkID) {
if($_SESSION['custID'] > 0){
//$_SESSION['custID']=$_SESSION['custID'];
$custName = "";
$query = 'SELECT FName, LName FROM Customers WHERE CustID = ' . $_SESSION['custID'] . ';';
mysql_select_db("c199grp10", $LinkID);
$result = mysql_query( $query ,$LinkID);
$value4=mysql_fetch_row($result);
foreach ($value4 as $v) {
$custName .= ($v." ") ;
}
echo "Logged in as: " . $custName;
}
else{
$_SESSION['custID']="";
@$email = $_REQUEST[ 'login' ];
@$password = $_REQUEST[ 'password' ];
//$getHash = 'SELECT Hash FROM Customers WHERE Email LIKE "' . $email . '";';
//mysql_select_db("c199grp10", $LinkID);
//$result = mysql_query( $getHash ,$LinkID);
//$returnedHash=mysql_fetch_row($result);
//foreach ($returnedHash as $h) {
// $hash = $h;
// }
//$validPass = password_verify($password, $hash);
//$validPass = true;
$custID = "";
//if($validPass){
$query = 'SELECT CustID FROM Customers WHERE Email LIKE "' . $email . '" And Hash LIKE "'.$password.'";';
mysql_select_db("c199grp10", $LinkID);
$result = mysql_query( $query ,$LinkID);
$value3=mysql_fetch_row($result);
if($value3){
foreach ($value3 as $v) {
$custID = $v;
}
echo "Login Successful!";
$_SESSION['custID']=$custID;
echo "<br>";
if(isset($_SESSION['custID'])){
$custName = "";
$query = 'SELECT FName, LName FROM Customers WHERE CustID = ' . $_SESSION['custID'] . ';';
mysql_select_db("c199grp10", $LinkID);
$result = mysql_query( $query ,$LinkID);
$value=mysql_fetch_row($result);
foreach ($value as $v) {
$custName .= ($v." ") ;
}
echo "Logged in as: " . $custName;
}
else{
echo "Please login.";
}
}
else{
echo "Please login.";
}
//}
//else{
// echo "Invalid password.";
//}
}
}
// Product display from database query
/*function productDisplay($results){
$count = 1;
while ($x=mysql_fetch_row($results)){
if(($count + 2) % 2 == 1){
print '<div id="productBoxLeft">';
}else{
print '<div id="productBoxRight">';
}
print "<br>";
print "Name: ".$x[1]."<br>";
print "Price: ".$x[3]."<br>";
print "Description: ".matchDesc($x[1])."<br>";
//Add "Add to Cart" buttons to each product, set the id of each button to the product id
echo '<button type="button" id="'.$x[0].'"> Add To Cart </button>';
print "<br></div><br>";
$count += 1;
}
}*/
function productDisplay($results, $type){
while ($x=mysql_fetch_row($results)){
print '<div id="grid" >';
print "<br>";
print "Name: ".$x[1]."<br>";
print "Price: ".$x[3]."<br>";
print "Description: ".matchDesc($x[1])."<br>";
$value = $x[0];
//echo '<form id="addToCart">';
if($type == 'beans'){
echo '<form method="post" action="coffeeBeans.php">';
}
if($type == 'products'){
echo '<form method="post" action="coffeeProducts.php">';
}
//(Works)echo '<button class="add_to_cart">Add To Cart</button>';
echo '<input type="hidden" name="productID" id="productID" value="'.$value.'" />';
echo 'Quantity:<input type="text" placeholder= "1-99"name="quantity" id="quantity" pattern="\d{1}|\d{2}"size="1" maxlength="2"/>';
echo '<button class="add_to_cart" name="add" onclick="addToCart()">Add To Cart</button>';
//echo '<button class="add_to_cart" name="add" onclick="addToCart2()">Add To Cart</button>';
echo '</form>';
//Add "Add to Cart" buttons to each product, set the id of each button to the product id
//echo '<button type="button" id="add'.$value.'" name="add'.$value.'" value="'.$value.'" onclick="addToCart()" > Add To Cart </button>';
//echo 'ProductID = ' . $x[0];
print "<br></div>";
}
}
// Query the database for products
function fetchProducts($type){
// Connect to the MySQL server.
require('../LinkID.php');
// Die if no connect
if (!$LinkID) {
die('Could not connect: ' . mysql_error());
}
// Choose the DB and run a query.
mysql_select_db("c199grp10", $LinkID);
// Report error if encountered
echo mysql_error($LinkID);
if($type == "beans"){
$postFields = "SELECT * FROM Products WHERE ProductType LIKE 'Beans';";
}
if($type == "products"){
$postFields = "SELECT * FROM Products WHERE ProductType NOT LIKE 'Beans';";
}
$result1 = mysql_query($postFields ,$LinkID);
return $result1;
}
function startSession() {
session_start();
if(isset($_SESSION['custID']))
$_SESSION['custID']=$_SESSION['custID'];
else
$_SESSION['custID']="";
if(isset($_SESSION['cart']))
$_SESSION['cart']=$_SESSION['cart'];
else
$_SESSION['cart'] = array();
include '../LinkID.php';
if (!$LinkID) {
die('Could not connect: ' . mysql_error());
}
}
?>