-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfood_details.php
188 lines (154 loc) · 5.3 KB
/
food_details.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
require_once('food_galaxy_fns.php');
session_start();
$food_id = $_GET['food_id'];
do_html_header();
$food_info = get_food_details($food_id);
display_food_details($food_info);
display_food_reviews($food_info);
do_html_footer();
?>
<?php
function display_food_details($food_info){
echo "<div class=\"panel panel-default\">
<div class=\"panel-heading\">Food information</div>
<div class=\"panel-body\">
<p><b>Food description:</b>".$food_info[0]['description']."</p>
</div>
<table class=\"table\">
<tbody>
<tr>
<td>Name: </td> <td>".$food_info[0]['food_name']."</td>
</tr>
<tr>
<td>Category: </td> <td>".$food_info[0]['catogery_name']."</td>
</tr>
<tr>
<td>Merchant Name: </td> <td>".$food_info[0]['merchant_name']."</td>
</tr>
<tr>
<td>Price: </td> <td>".$food_info[0]['price']."</td>
</tr>
<tr>
<td>Popularity Level: </td> <td>".$food_info[0]['popularity_level']." star</td>
</tr>
</tbody>
</table>
</div>";
}
function display_food_reviews($food_info){
session_start(); $id = $_SESSION['valid_user'];
$food_id = $food_info[0]['food_id'];
echo "<div class=\"form-group form-horizontal\">
<a href=\"write_food_review.php?food_id=".$food_id."\" class=\"btn btn-primary\" role=\"button\">Write Review</a>
<a href=\"write_complaints.php?food_id=".$food_id."&customer_id=".$id."\" class=\"btn btn-primary\" role=\"button\">Write Complaints</a>
</div>
";
echo "<h3>Reviews made by customers:</h3>";
$conn = db_connect();
$query = "select * from review where type = 0 and target_id = '".$food_id."' ORDER BY review_id desc";
//echo $query;
$result = @$conn->query($query);
//echo $result->num_rows;
while($row = $result->fetch_assoc()){
$query2 = "select name from customer where customer_id = '".$row['author_id']."'";
$result2 = @$conn->query($query2);
$row2 = $result2->fetch_assoc();
$name = $row2['name'];
echo "<div class=\"blog-post\">
<h4 class=\"blog-post-title\">".$row['title']."</h2>
<p class=\"blog-post-meta\">".$row['date']." by <a href=\"#\">".$name."</a></p>
<p>".$row['content']."</p>
</div>";
echo "<hr>";
}
echo "<hr>";
echo "<div class=\"form-group form-horizontal\">
<a href=\"write_food_review.php?food_id=".$food_id."\" class=\"btn btn-primary\" role=\"button\">Write Review</a>
<a href=\"write_complaints.php?food_id=".$food_id."&customer_id=".$id."\" class=\"btn btn-primary\" role=\"button\">Write Complaints</a>
</div>
";
/*
echo "<hr>";
echo "<form role=\"form\" >
<div class=\"form-group\">
<label for=\"name\">Write youre reveiw:</label>
<textarea class=\"form-control\" rows=\"3\" id = \"review_content\"></textarea>
</div>
<div class=\"form-group\">
<button onclick=\"review_write(".$food_info[0]['food_id'].")\" class=\"btn btn-primary\">Submit</button>
</div>
</form>";
*/
}
function get_food_details($food_id) {
// query database for the books in a category
if ((!$food_id) || ($food_id == '')) {
return false;
}
$conn = db_connect();
// $query = "select * from food where food_id = '".$food_id."'";
$query = "select food_id, description, food.name as food_name, catogery_name, merchant.name as merchant_name, price, food.popularity_level as popularity_level
from food, merchant
where food.merchant_id = merchant.merchant_id and food_id = '".$food_id."'";
$result = @$conn->query($query);
if (!$result) {
return false;
}
$num_books = @$result->num_rows;
if ($num_books == 0) {
return false;
}
$result = db_result_to_array($result);
return $result;
}
?>
<script type="text/javascript">
function review_write(food_id){
var action = "action=getText";
var url = "write_food_review.php";
var foodid = food_id;
var review_content = document.getElementById("review_content").value;
//type = 0; 0 食物; 1 厂家
var author_id = 1;
post = "food_id="+foodid+"&review_content="+review_content+"&type=0"+"&author_id="+author_id;
//alert("1");
//使用GET方法提交数据
xmlHttp.open("POST",url+"?"+action,false);
//发送HTTP头信息
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//发送请求,此处与GET方法不同
//alert("2");
xmlHttp.send(post);
//alert("3");
//指定回调函数
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
//alert("3.1");
var text = xmlHttp.responseText;
//alert("content: " + text);
if(text == "success"){
alert("success");
}
else
alert("text: " + text);
/*
if(text == "success"){
var r=confirm("Press a button!");
if (r==true){
alert("You pressed OK!");
}
els{
alert("You pressed Cancel!");
}
alert("success!");
}
else
alert("Failed!");
*/
//document.getElementById("show_content").innerHTML = text;
}
}
//alert("5");
}
</script>