-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreview.php
More file actions
101 lines (86 loc) · 3.47 KB
/
review.php
File metadata and controls
101 lines (86 loc) · 3.47 KB
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
<?php
require 'includes/dbhandler.php';
require 'includes/header.php';
require 'includes/review-helper.php';
?>
<main>
<span id="testAvg"></span>
<div class="container" align= "center" style="max-width: 800px">
<div class="my-auto">
<form id="review-form" action="includes/review-helper.php" method="post">
<div class="container">
<i class="fa fa-star fa-2x star-rev" data-index="1"></i>
<i class="fa fa-star fa-2x star-rev" data-index="2"></i>
<i class="fa fa-star fa-2x star-rev" data-index="3"></i>
<i class="fa fa-star fa-2x star-rev" data-index="4"></i>
<i class="fa fa-star fa-2x star-rev" data-index="5"></i>
</div>
<div class = "form-group" style="margin-top: 15px;">
<label claass="title-label" for="review-title" style="font-size: 16px; font-weight: bold;">Title</label>
<input type="text" name="review-title" id="review-title" style="width: 100%; margin-bottom: 10px;">
<textarea class="form-control" id="review-text" name="review" cols="50" rows="3" placeholder="Enter a comment..."></textarea>
<input type="hidden" name="rating" id="rating">
<input type="hidden" name="item_id" value="<?php echo $_GET['id'];?>">
</div>
<div class="form-group">
<button class="btn btn-outline-danger" id="review-submit" name="review-submit" type="submit" style="width: 100%;">Review</button>
</div>
</form>
</div>
</div>
<span id="review_list"></span>
</main>
<script type="text/javascript">
var rateIndex = -1;
var id = <?php echo $_GET['id'];?>
$(document).ready(function() {
reset_star();
// get reviews
xhr_getter('display-reviews.php?id=', "review_list");
//avg();
xhr_getter('includes/get-ratings.php?id=', "testAvg");
if (localStorage.getItem('rating') != null) {
setStars(parseInt(localStorage.getItem('rating')));
}
$('.star-rev').on('click', function() {
rateIndex = parseInt($(this).data('index'));
localStorage.setItem('rating', rateIndex);
});
$('.star-rev').mouseover(function() {
reset_star();
var currIndex = parseInt($(this).data('index'));
setStars(currIndex);
});
$('.star-rev').mouseleave(function() {
reset_star();
if (rateIndex != -1) {
setStars(rateIndex);
}
});
function reset_star() {
$('.star-rev').css('color', 'grey');
}
function setStars(max){
for(var i=0; i < max; i++)
{
$('.star-rev:eq('+i+')').css('color', 'goldenrod');
}
document.getElementById('rating').value = parseInt(localStorage.getItem('rating'));
console.log(id);
}
//Used to interchangeably send GET requests for review display data.
function xhr_getter(prefix, element)
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200)
{
document.getElementById(element).innerHTML = this.responseText;
}
};
url = prefix+id;
xhttp.open("GET", url, true);
xhttp.send();
}
});
</script>