-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResProfile.php
210 lines (202 loc) · 7.19 KB
/
ResProfile.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
session_start();
if(!isset($_SESSION['username']))
{
header("Location: login.php");
}
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FoodRec | Restaurant Profile</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrap">
<div id="main">
<?php
//slope one recommendations
//pick a user (typically will already be logged in)
//find all restaurants a user has not rated
include("db_connect.php");
$current_user = $_SESSION['userid'];
//$query1 = "SELECT * FROM restaurants WHERE resID not in (SELECT resID FROM user_res WHERE userID = $current_user);";
$resID = $_GET['id'];
//echo "resID: ".$resID." ";
$query1 = "SELECT * FROM restaurants WHERE userID = $current_user and resID = $resID;";
$results1 = mysqli_query($db,$query);
if ($results1 == NULL){
//unrated restaurant = x
$first_res = $resID;
//for each restaurant user has rated
$query2 = "SELECT resID FROM user_res WHERE userID = $current_user;";
$results2 = mysqli_query($db,$query2);
//echo $results2;
while($row2 = mysqli_fetch_array($results2)){
//echo "in nested while ";
//rated restaurant = y
$second_res = $row2['resID'];
//get the entry from res_res for x,y
$res_res_query = "SELECT * FROM res_res WHERE res1ID = $first_res AND res2ID = $second_res;";
$res_res_results = mysqli_query($db,$res_res_query);
//get the entry from user_res for user,y
$user_res_query = "SELECT * FROM user_res WHERE resID = $second_res;";
$user_res_results = mysqli_query($db,$user_res_query);
$num_people_query = "SELECT resA.userID, resA.resID, resB.resID, resA.userRating as resArating, resB.userRating
as resBrating from user_res as resA join user_res as resB where resA.resID=$first_res and
resB.resID=$second_res and resA.userID=resB.userID;";
$num_people_results = mysqli_query($db,$num_people_query);
$c = mysqli_num_rows($num_people_results);
//echo "c: ".$c." ";
while ($rowA = mysqli_fetch_array($res_res_results) and $rowB = mysqli_fetch_array($user_res_results)){
$deviation = $rowA['deviations'];
//echo "deviation: ".$deviation." ";
$userRating = $rowB['userRating'];
///echo "userRating: ".$userRating." ";
$numerator += ($deviation + $userRating) * $c;
//echo "numerator: ".$numerator." ";
$denominator += $c;
//echo "denominator: ".$denominator." ";
$predictedUserRating = $numerator / $denominator;
//$rating = number_format($predictedUserRating, 2)
}
}
//echo "We think you would rate this restaurant (1-5): ".$predictedUserRating;
}
?>
<?php
echo "<p><span style=\"color:red\"><b>Restaurant Profile:</B></span><br/>";
include("header.php");
include("db_connect.php");
$loggedin=isset($_SESSION['userid']);
if ($loggedin){
$userID=$_SESSION['userid'];
}else{
$userID=-1;
}
//$band_link = "bandprofile.php?id=$bandID";
//$bandID = $_GET['id'];
$resID=$_GET['id'];
$updated=$_GET['updated'];
$query="select * from restaurants where resID=$resID";
$user_res_Query="select * from user_res where userID=$userID and resID=$resID";
$results=mysqli_query($db,$query);
$user_res_Results=mysqli_query($db,$user_res_Query);
$usRow=mysqli_fetch_array($user_res_Results);
while ($row=mysqli_fetch_array($results)){
$apost=substr($row['name'],strlen($row['name'])-2,strlen($row['name']));
if($apost=="'s" or $apost=="'S"){
echo "<h2>Viewing ".$row['name']." Profile:</h2><br>";
if ($predictedUserRating != NULL)
{
echo "<h3>Your predicted rating is: ".$predictedUserRating."<h3><br>";
}
}else{
echo "<h2>Viewing ".$row['name']."'s Profile:</h2><br>";
if ($predictedUserRating != NULL)
{
echo "<h3>Your predicted rating is: ".$predictedUserRating."</h3><br>";
}
}
echo "<table bgcolor='black' width=500 border=1 style=\"color:red\">";
echo " <tr>";
echo " <td>";
echo " <table width=250 style=\"color:red\">";
echo " <tr>";
echo " <td>";
if ($row['picture']==NULL){
echo "Sorry! No picture for <br><h4>".$row['name']."</h4>";
}else{
echo "<img src='ResPics/".$row['picture']."' width=245 alt=\"".$row['name']."'s Logo or Picture\">";
}
echo "<hr>";
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td>";
if ($row['rating']==NULL){
echo $row['name']." Has yet to be rated!";
}else{
echo $row['name']."'s Rating is: ".$row['rating'];;
}
echo " </td>";
echo " </tr>";
echo " </table>";
echo " </td>";
echo " <td>";
echo $row['name']." is a <font color=yellow><br>".$row['type']." Restaurant</font><hr width=120 color=darkred>";
if($row['']!=NULL){
echo "Price Rating (1-5):<font color=yellow> ".$row['price']."</font><hr width=120 color=darkred>";
}else{
echo "Price Rating (1-5); <font color=yellow>Not Rated!</font><hr width=120 color=darkred>";
}
echo "Do they serve Alchohol?:";
if($row['alcohol']==1){
echo"<font color=yellow> Yes.</font><hr width=120 color=darkred>";
}else{
echo"<font color=yellow> No.</font><hr width=120 color=darkred>";
}
echo "Click <a href='".$row['website']."'target='_blank'>here</a> to visit ".$row['name']."'s website.<hr width=120 color=darkred>";
if ($loggedin){
echo "<form method='post' action='takemehere.php?resID=$resID&userID=$userID'>";
//echo "<form method='post' action='takemehere.php?resID=$resID&userID=$userID'>";
echo "<p>";
echo "<p><input style='display:block; margin-left:auto; margin-right:auto;' type='submit' ";
echo "value=' Take Me Here! ' /></p></form>";
echo "</p>\n";
if($updated){
echo "<fieldset style='border:2px solid red; background-color:lightblue;'>";
echo "<p style='color:black; font-weight:bold; text-align:center;'>";
echo "Your Information Has Been Updated!";
echo "</p></fieldset>";
}
}
echo " </td>";
echo " </tr>";
echo "</table>";
if($loggedin){
$frequency+=$usRow['breakfast'];
$frequency+=$usRow['lunch'];
$frequency+=$usRow['dinner'];
echo "<table bgcolor='black' width=500 border=1 style=\"color:red\">";
echo " <tr>";
echo " <td>";
//$usRow
echo "How many times you've been here: ";
if($frequency>0){
echo "<font color=yellow>".$frequency."</font>";
}else{
echo "<br><font color=yellow> You have not been here yet.</font>";
}
echo " </td>";
echo " </tr>";
echo " <tr>";
echo " <td>";
echo "How you've rated this restaurant:";
if($usRow['userRating']==0){
echo "<br><font color=yellow>You have not rated this restaurant yet.</font>";
}else{
echo"<font color=yellow>".$usRow['userRating']."</font>";
}
echo " </td>";
echo " </tr>";
echo "</table>";
}
echo "<center>";
}
?>
<!--
<table bgcolor=grey>
<tr>
<td><image src="image.gif" alt="tgif image" height=100 width=200></image></td>
<td><font color=black><b>This is a test food place picture! Eat here!</b></font></td>
</tr>
</table>
-->
</div>
<?php include("projectSideBar.php"); ?>
<?php include("footer.html");?>
</div>
</div>
</body>
</html>