-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatured_hostels.php
More file actions
148 lines (141 loc) · 4.84 KB
/
Copy pathfeatured_hostels.php
File metadata and controls
148 lines (141 loc) · 4.84 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
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
<?php include 'includes/config.php';
if (isset($_GET['submitRating'])) {
$rating = $_COOKIE['rating'];
$hostel_id =$_COOKIE['hid'];
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if ($conn->connect_error) {
trigger_error('Database connection failed: ' .
$conn->connect_error, E_USER_ERROR);
}else{
$sql="INSERT INTO rating(hostel_id,rating) values ('$hostel_id','$rating')";
if($conn->query($sql) === false) {
trigger_error('Wrong SQL: ' . $sql .
' Error: ' . $conn->error, E_USER_ERROR);
} else {
echo "Rating done successfully<br />";
header( "refresh:1;url=featured_hostels.php" );
}
$conn->close();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hostel Tracker</title>
<?php include 'includes/links.php'; ?>
<link rel="stylesheet" href="<?php echo $path ?>css/jquery.rateyo.css" />
<script src="<?php echo $path ?>js/jquery.rateyo.js"></script>
</head>
<body>
<?php include 'includes/header.php' ?>
<main class="main-container">
<div class="section-heading">
<h2>
Featured Hostels
</h2>
</div>
<section class="featured-hostels">
<?php
$query = "SELECT * FROM hostels";
$result = $db->query($query);
$counter = 0;
$image ="";
if (!empty($result)) {
while ($item = mysqli_fetch_assoc($result)) {
$counter++;
?>
<div class="featured-hostel-box">
<?php
if($counter%2==0)
{
$image = './graphics/hostelpic1.jpg';
}
else if($counter%3==0)
{
$image = './graphics/hostelpic2.jpg';
}
else if($counter%5==0)
{
$image = './graphics/hostelpic5.jpg';
}
else
{
$image = './graphics/hostelpic3.jpg';
}
?>
<img class="hostel-feature-image" src="<?php echo $image; ?>" alt="">
<h3><?php echo $item['hostel_name'] ?></h3>
<p><?php echo $item['hostel_type'] ?> Hostel</p>
<p><?php echo $item['hostel_address'] ?></p>
<div class="rateYo"></div>
<?php
if(isset($_SESSION['email'])&&$_SESSION['role']=='user')
{?>
<button class="myBtn" value="<?php echo $item['id']; ?>">Rate Now</button><?php
}
?>
<a class="view-more-button" href="hostel.php?id=<?php echo $item['id']; ?>">View Details</a>
</div>
<?php
}
}
?>
</section>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<h1>Hostel Rating</h1>
<form method="get">
<div class="rateHotel"></div>
<input type="submit" name="submitRating">
</form>
</div>
</div>
</main>
<?php
include 'includes/footer.php';
?>
<script>
$(document).ready(function () {
$(".rateYo:even").rateYo({
rating: 4.8,
readOnly: true
});
$(".rateYo:odd").rateYo({
rating: 3.8,
readOnly: true
});
$(".rateHotel").rateYo({
rating: 3.8,
});
$(".rateHotel").rateYo()
.on("rateyo.set", function (e, data) {
setCookie("rating", data.rating, 1);
});
});
var modal = document.getElementById('myModal');
$('.myBtn').click(function(){
setCookie('hid',$(this).val(),1);
modal.style.display = "block";
});
var span = document.getElementsByClassName("close")[0];
span.onclick = function () {
modal.style.display = "none";
}
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
</script>
</body>
</html>