-
Notifications
You must be signed in to change notification settings - Fork 4
/
browsing.php
141 lines (115 loc) · 5.35 KB
/
browsing.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sharing Project</title>
<link href="styles.css" media="all" rel="Stylesheet" type="text/css"/>
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("searchbar").innerHTML="";
document.getElementById("searchbar").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("searchbar").innerHTML=this.responseText;
document.getElementById("searchbar").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","search.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=Sharing user=postgres password=12345678")
or die('Could not connect: ' . pg_last_error());
//$currObjectID = 20;
session_start();
$user = $_SESSION['user'];
if ( isset($_SESSION['user'])=="" ) {
header("Location: FirstPage.php");
exit;
}
?>
<div class="sect1">
<h1>Find something to buy!</h1>
</div>
<div class="sect2">
<a href="stuffSharingObject.php"><button type="button">Add Item</button></a><br>
<form>
<input type="text" name="searchbar" placeholder="What do you want?" onkeyup="showResult(this.value)"/>
<div id="searchbar"></div>
</form>
<!--search bar and other crap included here -->
</div>
<div class="sect3">
<ul>
<?php $query = 'SELECT distinct o.category, o.itemname, o.description, o.price, o.owner, a.auctionid
from object o, auction a where o.availability=TRUE and a.objectid = o.productid';
//'SELECT distinct o.category, o.itemname, o.description, o.price, o.owner, a.auctionid, b.price
//FROM object o, auction a, bid b group by o.itemname';
// -- WHERE a.objectid = o.productid AND b.auctionid = a.auctionid AND a.objectid = o.productid
// -- AND b.price >=ALL (SELECT bi.price from bid bi WHERE bi.auctionid = a.auctionid)
// -- UNION
// -- SELECT o.category, o.itemname, o.description, o.price, o.owner, a.auctionid, b.price
// -- FROM object o, auction a, bid b
// -- WHERE a.objectid = o.productid AND b.auctionid = a.auctionid AND a.objectid = o.productid';
//this needs to be changed in order to show the maximum bid price at the moment instead of just price.
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
while ($row = pg_fetch_row($result)){
echo "<hr></hr>";
echo "<div><li>".$row[0].": ".$row[1]."<a href=\"#id".$row[5]."\"><button type=\"button\">Go to Item</button></a>
</li></div>";
$price = $row[3] > $row[6] ? $row[3] : $row[6];
echo "<div id=\"id".$row[5]."\" class=\"modal\">
<div><a href=\"#\" title=\"Close\" class=\"close\">X</a>
".$row[1].": ".$row[2]." <br> Current Bid: $".$price."<br>
<img src=\"img/884856436.jpg\" width=\"100px\" height=\"100px\"/>
<form>
<input id=\"auctionID\" name=\"auctionID\" type=\"hidden\" value=\"".$row[5]."\"></input>
<input type=\"text\" name = \"bidPrice\" id = \"bidPrice\"> <input type=\"submit\" name=\"bidSubmit\" value=\"Bid for it!\">
</form>
</div>
</div>";
}
if(isset($_GET['bidSubmit'])){
//echo "auction ID : ".$_GET['auctionID']."";
$insertQuery = "INSERT INTO bid values('".$_GET['bidPrice']."', '".$_SESSION['user']."', '".$_GET['auctionID']."');";
$insertResult = pg_query($insertQuery) or die('query fucked up: '. pg_last_error());
if(!insertResult){
echo "we dun fucked up";
} else {
header("Location:browsing.php");
exit;
}
}
?>
</ul>
</div>
<div class="sect4">
<!-- List of Loans:<br> -->
<?php
// $query = 'SELECT * FROM loan';
//
// $result = pg_query($query) or die ('Query failed fml '. pg_last_error());
// while($row = pg_fetch_row($result)){
// echo "ItemID: ".$row[0]." Buyer:".$row[1]." Seller:".$row[2]." ".$row[3]." ".$row[4]."<br>";
// }
?>
</div>
<a href="AccountPage.php"><button>Go to Account Page</button></a><br>
<div class="copyright">
Copyright © VYMMS
</div>
<script src="./jquery-2.1.3.min/index.js"></script>
</body>
</html>