/
dashboard.php
188 lines (155 loc) · 5.11 KB
/
dashboard.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
181
182
183
184
185
186
187
188
<?php include('includes/connect.php');
error_reporting(E_ALL);
//session_start();
if(empty($_SESSION['user']))
{
// If they are not, we redirect them to the login page.
header("Location: login.php");
// Remember that this die statement is absolutely critical. Without it,
// people can view your members-only content without logging in.
die("Redirecting to login.php");
}
if(isset($_POST['logout'])){
unset($_SESSION['user']);
header("Location: login.php");
die("Redirecting to login.php");
}
include('includes/head.php');
print_r($_SESSION['user']);
?>
<div class = "container-medium">
<section>
<div class = "jumbotron">
<h1>Dashboard</h1>
<p>Welcome, <?php echo $_SESSION['user']['userName']?></p>
</div>
</section>
<section>
<div class = "row">
<div class = "col-xs-3">
<div class = "panel panel-default">
<div class = "panel-body">
<table class = "table table-hover table-condensed">
<tbody>
<tr>
<td>Name</td>
<td><?php echo $_SESSION['user']['fName']." ".$_SESSION['user']['lName']?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo $_SESSION['user']['email']?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class = "col-xs-9">
<div class = "row">
<div class = "col-xs-6">
<a href="browse.php">
<div class = "fontAwesome">
<span class="fa-stack fa-3x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-shopping-bag fa-stack-1x fa-inverse"></i>
</span>
<h4>Browse auctions</h4>
</div>
</a>
</div>
<div class = "col-xs-6">
<a href="postAuction.php">
<div class = "fontAwesome">
<span class="fa-stack fa-3x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-gavel fa-stack-1x fa-inverse"></i>
</span>
<h4>Post auction</h4>
</div>
</a>
</div>
</div>
<div class = "row">
<div class = "col-xs-6">
<a href="myAuctions.php">
<div class = "fontAwesome">
<span class="fa-stack fa-3x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-book fa-stack-1x fa-inverse"></i>
</span>
<h4>My auctions</h4>
</div>
</a>
</div>
<div class = "col-xs-6">
<a href="myBids.php">
<div class = "fontAwesome">
<span class="fa-stack fa-3x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-check fa-stack-1x fa-inverse"></i>
</span>
<h4>My bids</h4>
</div>
</a>
</div>
</div>
</div>
</div>
<?php
$auction = new Auction($conn);
//index = auctionID,
$auctionList = $auction->recommend($_SESSION['user']['userId']);
//print_r($auctionList);
//create new array that contains all the indexes of auctionList that has value of 2
$auctionIdArray = [];
//key->value because we need the index
foreach ($auctionList as $key=>$val) {
if($val==2){
$auctionIdArray[]=$key;
}
}
?>
<h2>Recommended items</h2><br>
<table class = "table table-hover table-condensed">
<thead>
<th>Item name</th>
<th>Date posted</th>
<th>End date</th>
<th>Starting price</th>
<th>Description</th>
<th>Category</th>
<th>Bids</th>
<th>Highest bid</th>
<th>Place a bid</th>
</thead>
<tbody>
<?php
foreach($auctionIdArray as $aID){
$auctionItemQuery = "SELECT auctionID, datePosted, startPrice, endDate, bids, i.itemName, i.description, i.category FROM `auction` AS a INNER JOIN `items` as i on a.itemID = i.itemID WHERE a.auctionID = '$aID'";
$auctionItemResult = mysqli_query($conn, $auctionItemQuery) or die(mysqli_error($conn));
$row = mysqli_fetch_array($auctionItemResult);
$auctionID = $row['auctionID'];
$highestBidQuery = "SELECT `bidPrice` FROM `bids` WHERE auctionID = '$auctionID' ORDER BY bidPrice DESC LIMIT 1";
$highestBidResult = mysqli_query($conn, $highestBidQuery);
$highestBid = mysqli_fetch_array($highestBidResult);
echo '<tr>';
echo '<td>'.$row['itemName'].'</td>';
echo '<td>'.$row['datePosted'].'</td>';
echo '<td>'.$row['endDate'].'</td>';
echo '<td>'.$row['startPrice'].'</td>';
echo '<td>'.$row['description'].'</td>';
echo '<td>'.$row['category'].'</td>';
echo '<td>'.$row['bids'].'</td>';
echo '<td>'.$highestBid[0].'</td>';
echo '<td><a class = "btn btn-success" href = "placeBid.php?auctionID='.$row['auctionID'].'">Bid</a></td>';
echo '</tr>';
}
?>
</tbody>
</table>
</section>
<form action = "dashboard.php" method = "post">
<input type = "submit" name = "logout" class = "btn btn-default" value = "Logout">
</form>
</div>
</html>