Skip to content

Commit e7cde0d

Browse files
committed
create rating
1 parent 991f333 commit e7cde0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3810
-75
lines changed

.htaccess

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RewriteEngine On
2+
RewriteRule "index" "index.php"
3+
RewriteRule "^([a-zA-Z-]+)$" "index.php?page=$1"
4+

Controller/Customer/Customer_c.php

+23
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,33 @@ public function Customer() {
1515
$id = $_SESSION['id_cus'];
1616
$customer = $this->customer->getCustomerInfo($id);
1717
$history = $this->customer->getCustomerOrder($id);
18+
1819
if (isset($_GET['id'])) {
1920
$id = $_GET['id'];
2021
$detail = $this->customer->getCustomerOrderDetail($id);
2122
}
23+
24+
if (isset($_GET['idu'])) {
25+
$id = $_GET['idu'];
26+
$user = $this->customer->getUserInfo($id);
27+
$rating = $this->customer->getUserRate($id);
28+
$user_feedback = $this->customer->getUserFeedback($id,3);
29+
$count_feedback = $this->customer->countFeedback($id);
30+
}
31+
32+
if (isset($_GET['ido'])) {
33+
$order_id = $_GET['ido'];
34+
$checkfb = $this->customer->checkFeedback($order_id);
35+
}
36+
if (isset($_POST['submit'])) {
37+
$rate = $_POST['score'];
38+
$feedback = htmlspecialchars($_POST['feedback']);
39+
$user_id = $_POST['submit'];
40+
$customer_id = $_SESSION['id_cus'];
41+
42+
$add = $this->customer->addFeedback($user_id, $customer_id, $rate, $feedback);
43+
header("refresh: 0;");
44+
}
2245
include_once 'View/profile.php';
2346
}
2447

Model/Customer/Customer_m.php

+152-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ protected function getCustomerOrder($id) {
3939
usercare.name AS 'Nhân viên chăm sóc',
4040
tbl_order.total AS 'Đơn giá',
4141
tbl_order.create_at AS 'Thời gian',
42-
tbl_order.id AS 'id'
42+
tbl_order.id AS 'id',
43+
usercare.id AS 'idu'
4344
FROM
4445
tbl_user AS usersell
4546
INNER JOIN tbl_order
@@ -101,4 +102,154 @@ protected function getCustomerOrderDetail($id) {
101102

102103
return $result;
103104
}
105+
106+
protected function addFeedback($user_id, $customer_id, $rate, $feedback) {
107+
108+
$sql = "INSERT INTO tbl_feedback(user_id, customer_id, rate, feedback) VALUES
109+
(:user_id, :customer_id, :rate, :feedback)";
110+
111+
$pre = $this->pdo->prepare($sql);
112+
113+
$pre->bindParam(':user_id', $user_id);
114+
115+
$pre->bindParam(':customer_id', $customer_id);
116+
117+
$pre->bindParam(':rate', $rate);
118+
119+
$pre->bindParam(':feedback', $feedback);
120+
121+
return $pre->execute();
122+
}
123+
124+
protected function getUserInfo($id) {
125+
126+
$sql = "SELECT
127+
*
128+
FROM
129+
tbl_user, tbl_showroom
130+
WHERE
131+
tbl_user.showroom_id = tbl_showroom.showroom_id
132+
AND
133+
id = :id";
134+
135+
$pre = $this->pdo->prepare($sql);
136+
137+
$pre->bindParam(':id', $id);
138+
139+
$pre->execute();
140+
141+
$result = $pre->fetch(PDO::FETCH_ASSOC);
142+
143+
return $result;
144+
}
145+
146+
protected function getUserRate($id) {
147+
148+
$sql = "SELECT
149+
COUNT(tbl_feedback.user_id) AS 'num',
150+
ROUND(
151+
SUM(tbl_feedback.rate) / COUNT(tbl_feedback.user_id),
152+
1
153+
) AS 'avg'
154+
FROM
155+
tbl_feedback
156+
WHERE
157+
tbl_feedback.user_id = :id";
158+
159+
$pre = $this->pdo->prepare($sql);
160+
161+
$pre->bindParam(':id', $id);
162+
163+
$pre->execute();
164+
165+
$result = $pre->fetch(PDO::FETCH_ASSOC);
166+
167+
return $result;
168+
}
169+
170+
protected function getUserFeedback($id, $row) {
171+
172+
if (isset($_GET['pages'])) {
173+
$pages = $_GET['pages'];
174+
}else{
175+
$pages = 1;
176+
}
177+
178+
$from = ($pages - 1) * $row;
179+
180+
$sql = "SELECT
181+
tbl_customer.name,
182+
tbl_customer.avatar,
183+
tbl_feedback.rate,
184+
tbl_feedback.feedback,
185+
tbl_feedback.create_at as 'time'
186+
FROM
187+
tbl_feedback, tbl_customer
188+
WHERE
189+
tbl_feedback.customer_id = tbl_customer.id and tbl_feedback.user_id = 2
190+
ORDER BY
191+
tbl_feedback.create_at DESC
192+
LIMIT
193+
$from,$row";
194+
195+
$pre = $this->pdo->prepare($sql);
196+
197+
$pre->bindParam(':id', $id);
198+
199+
$pre->execute();
200+
201+
$result = array();
202+
203+
while ($row = $pre->fetch(PDO::FETCH_ASSOC)) {
204+
205+
$result[] = $row;
206+
207+
}
208+
209+
return $result;
210+
}
211+
212+
protected function countFeedback($user_id){
213+
214+
$sql = "SELECT COUNT(user_id) as id FROM tbl_feedback WHERE user_id = :user_id";
215+
216+
$pre = $this->pdo->prepare($sql);
217+
218+
$pre->bindParam(':user_id', $user_id);
219+
220+
$pre->execute();
221+
222+
$result = $pre->fetch(PDO::FETCH_ASSOC);
223+
224+
return $result['id'];
225+
}
226+
227+
protected function checkFeedback($order_id) {
228+
229+
$sql = "SELECT
230+
*
231+
FROM
232+
tbl_feedback, tbl_order
233+
WHERE
234+
tbl_feedback.order_id = tbl_order.id
235+
AND
236+
order_id = :order_id";
237+
238+
$pre = $this->pdo->prepare($sql);
239+
240+
$pre->bindParam(':order_id', $order_id);
241+
242+
$pre->execute();
243+
244+
$result = array();
245+
246+
while ($row = $pre->fetch(PDO::FETCH_ASSOC)) {
247+
248+
$result[] = $row;
249+
250+
}
251+
252+
return $result;
253+
}
254+
104255
}

Server/Customer/avatar.php

+1-21
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,11 @@
55

66
$customer = new Customer_c_ajax();
77

8-
function convert_name($str) {
9-
$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
10-
$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
11-
$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
12-
$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
13-
$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
14-
$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
15-
$str = preg_replace("/(đ)/", 'd', $str);
16-
$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
17-
$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
18-
$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
19-
$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
20-
$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
21-
$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
22-
$str = preg_replace("/(Đ)/", 'D', $str);
23-
$str = preg_replace("/(\“|\”|\‘|\’|\,|\!|\&|\;|\@|\#|\%|\~|\`|\=|\_|\'|\]|\[|\}|\{|\)|\(|\+|\^)/", '-', $str);
24-
$str = preg_replace("/( )/", '-', $str);
25-
return $str;
26-
}
27-
288
$id = $_SESSION['id_cus'];
299

3010
$result = $customer->getCustomerInfo($id);
3111

32-
$nameFolder = convert_name($result['name']).$id;
12+
$nameFolder = $id;
3313

3414
if (!file_exists('../../assets/images/customer/'.$nameFolder)) {
3515
mkdir('../../assets/images/customer/'.$nameFolder, 0777, true);

Server/Customer/password.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@
2020

2121
$updatePass = $customer->updateCustomerPass($id, $password);
2222
?>
23-
<div class="alert alert-success">
24-
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
25-
<strong>Thành công!</strong> Mật khẩu sẽ được áp dụng ở lần đăng nhập tới
23+
<div class="jq-toast-wrap top-right">
24+
<div class="jq-toast-single jq-has-icon jq-icon-danger">
25+
<span class="close-jq-toast-single">x</span>
26+
<h2 class="jq-toast-heading">Thành công!</h2>
27+
Mật khẩu sẽ được áp dụng ở lần đăng nhập tiếp theo
28+
</div>
2629
</div>
2730
<?php
2831

2932
}else{
3033
?>
31-
<div class="alert alert-danger">
32-
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
33-
<strong>Thất bại!</strong> Mật khẩu không chính xác
34+
<div class="jq-toast-wrap top-right">
35+
<div class="jq-toast-single jq-has-icon jq-icon-danger">
36+
<span class="close-jq-toast-single">x</span>
37+
<h2 class="jq-toast-heading">Thất bại!</h2>
38+
Mật khẩu không chính xác
39+
</div>
3440
</div>
3541
<?php
3642
}
@@ -40,6 +46,6 @@
4046
<script type="text/javascript">
4147
//Hiện thông báo .. giây xong ẩn
4248
$(document).ready(function(){
43-
$(".alert").delay(2000).slideUp();
49+
$(".top-right").delay(2000).fadeOut();
4450
})
4551
</script>

Server/Customer/preview.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function convert_name($str) {
2929

3030
$result = $customer->getCustomerInfo($id);
3131

32-
$nameFolder = convert_name($result['name']).$id;
32+
$nameFolder = $id;
3333

3434
if (!file_exists('../../assets/images/preview/'.$nameFolder)) {
3535
mkdir('../../assets/images/preview/'.$nameFolder, 0777, true);

View/customer/history.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<a href="index.php?page=profile&method=detail&id=<?= $value['id']; ?>">
3434
<button type="button" class="btn btn-icon waves-effect waves-light btn-primary" title="Xem chi tiết"><span><i class="mdi mdi-pencil"></i></span></button>
3535
</a>
36-
<a href="index.php?page=profile&method=detail&id=<?= $value['id']; ?>">
36+
<a href="index.php?page=profile&method=rate&idu=<?= $value['idu']; ?>&ido=<?= $value['id'];?>&pages=1">
3737
<button type="button" class="btn btn-icon waves-effect waves-light btn-warning" title="Đánh giá"><span><i class="mdi mdi-star"></i></span></button>
3838
</a>
3939
</td>

View/customer/info.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
$id = $_SESSION['id_cus'];
3-
$nameFolder = convert_name($customer['name']).$id;
3+
$nameFolder = $id;
44
?>
55
<div class="col-md-9 col-9" style="background-color: #fff; padding-left: 30px;border-radius: 0.25rem; margin: 50px 0 0px 0;float: left;height: 100%">
66
<div class="title-info" style="border-bottom: 1px solid #efefef; width: 100%; height:80px;">
@@ -43,9 +43,21 @@
4343
</div>
4444
<div class="info_right" style="height: 70%; width: 30%; float: left; border-left: 1px solid #efefef">
4545
<div style="text-align: center; margin-bottom: 20px;" id="avatar_cus">
46-
<img src="assets/images/customer/<?php echo $nameFolder ?>/<?php echo $customer['avatar'] ?>" alt="user-image" class="rounded-circle" width="80" height='80' id="avatar">
46+
<?php
47+
if ($customer['avatar'] == 'guest.jpg') {
48+
?>
49+
<img src="assets/images/customer/guest.jpg ?>" alt="user-image" class="rounded-circle" width="80" height='80' id="avatar">
50+
<?php
51+
}else{
52+
?>
53+
<img src="assets/images/customer/<?php echo $nameFolder ?>/<?php echo $customer['avatar'] ?>" alt="user-image" class="rounded-circle" width="80" height='80' id="avatar">
54+
<?php
55+
}
56+
?>
57+
58+
<input type="hidden" name="" value="guest.jpg">
4759
</div>
48-
<form id="form-ava" action="Server/avatar.php" method="post" enctype="multipart/form-data" style="text-align: center;">
60+
<form id="form-ava" action="" method="post" enctype="multipart/form-data" style="text-align: center;">
4961
<label class="custom-file-upload">
5062
<input id="ava-img" type="file" name="image" accept=".jpg,.jpeg,.png"/>
5163
Chọn Ảnh

0 commit comments

Comments
 (0)