-
Notifications
You must be signed in to change notification settings - Fork 0
/
favourite.php
214 lines (170 loc) · 7 KB
/
favourite.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
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
$_SESSION['PrevPage'] = "favourite.php?";
if(!isset($_SESSION['username'])) {
header("location: index.php");
}
if(isset($_GET['page']))
$actualPage = $_GET['page'];
else
$actualPage = 1;
$_SESSION['PrevPage'] = "favourite.php??user=page=".$actualPage;
?>
<head>
<title>STARTSAW</title>
<meta charset="utf-8">
<!-- icon webpage ----------------------------------------->
<link rel="icon" href="favicon.ico" type="image" sizes="16x16">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" media="all" href="css/footer.css" />
<link rel="stylesheet" media="all" href="css/common.css" />
<link rel="stylesheet" media="all" href="css/profileStyle.css" />
<link rel="stylesheet" media="all" href="css/paging.css" />
<script src="js/common.js"></script>
<!-- new message? sse utente è loggato-->
<?php
if(isset($_SESSION['username'])) {
echo '<script src="js/message_updates.js"></script>';
}
?>
</head>
<body>
<?php
require "navbar.php";
?>
<div class="content">
<br>
<h1 class="title text-center">Wish List</h1>
<br>
<?php
require "db/mysql_credentials.php";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_SESSION['username'])){
$user = $_SESSION['username'];
$sql1 = "SELECT book.* FROM book, wishlist
WHERE Book=Id and Username ='$user'";
$result1 = mySQLi_query($conn, $sql1) or die("Error query1");
$bookPublished = $result1->num_rows;
if($bookPublished > 0){
$bookPerPage = 2;
$maxPage = ceil(($bookPublished)/$bookPerPage);
//check, if page number >> max --> show last page
if($actualPage > $maxPage)
$actualPage = $maxPage;
else if($actualPage < 1)
$actualPage = 1;
$firstToView = ($actualPage-1)*$bookPerPage;
$cont = -1;
echo"<div id='BooksPublished'>";
while($row1 = mySQLi_fetch_array($result1)){
$cont ++;
//echo "Cont ".$cont;
if($cont < $firstToView){
continue;
}
else if($cont >= $firstToView + $bookPerPage)
break;
else{
echo"
<div class='book-content' onclick='goToPageBook(".$row1['ID'].");'>
<div class='cover'>
<img src='data:image/jpeg;base64,".base64_encode($row1['Cover'])."' alt='cover'/>
</div>
<div class='description'>
<h3>".$row1['Author']." - ".$row1['Title']."</h3>
</div>
<div class='description'>
<p>".$row1['Description']."</p>
</div>
</div>";
if($cont < $firstToView+$bookPerPage-1){
echo"<div class='separation-line'></div>";
}
}
}
if($actualPage-1 < 1)
$prev="#";
else
$prev="favourite.php?page=".($actualPage-1);
if($actualPage+1 > $maxPage)
$next="#";
else
$next="favourite.php?page=".($actualPage+1);
echo"
<div class='pagination-position'>
<ul class='pagination'>
<li class='page-item'><a class='page-link' href='".$prev."'>Previous</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=1'>1</a></li>";
//if there are less than 6 pages -> show them
if($maxPage < 6)
for ($i = 2; $i <= $maxPage; $i++)
echo"<li class='page-item'><a class='page-link' href='favourite.php?page=".$i."'>".$i."</a></li>";
//otherwise if there are more than 5 pages --> ...
else if($maxPage > 5)
{
if($actualPage == 1)
echo"<li class='page-item'><a class='page-link'
href='favourite.php?page=2'>2</a></li>
<li class='page-item'><p class='page-link'>...</p></li>";
else if($actualPage == $maxPage)
echo"<li class='page-item'><p class='page-link'>...</p></li>
<li class='page-item'><a class='page-link'href='favourite.php?page=".($maxPage-1)."'>".($maxPage-1)."</a></li>";
else if($actualPage == 2)
echo"<li class='page-item'><a class='page-link' href='favourite.php?page=2'>2</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=3'>3</a></li>
<li class='page-item'><p class='page-link'>...</p></li>";
else if($actualPage == 3)
echo"<li class='page-item'><a class='page-link' href='favourite.php?page=2'>2</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=3'>3</a></li><li class='page-item'><a class='page-link' href='favourite.php?page=4'>4</a></li>
<li class='page-item'><p class='page-link'>...</p></li>";
else if($actualPage == $maxPage-2)
echo"<li class='page-item'><p class='page-link'>...</p></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".($maxPage-3)."''>".($maxPage-3)."</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".($maxPage-2)."''>".($maxPage-2)."</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".($maxPage-1)."''>".($maxPage-1)."</a></li>";
else if($actualPage == $maxPage-1)
echo"<li class='page-item'><p class='page-link'>...</p></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".($maxPage-2)."''>".($maxPage-2)."</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".($maxPage-1)."''>".($maxPage-1)."</a></li>";
else
echo"<li class='page-item'><p class='page-link'>...</p></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".($actualPage-1)."'>".($actualPage-1)."</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".$actualPage."'>".$actualPage."</a></li>
<li class='page-item'><a class='page-link' href='favourite.php?page=".($actualPage+1)."'>".($actualPage+1)."</a></li>
<li class='page-item'><p class='page-link'>...</p></li>";
//page max
echo"<li class='page-item'><a class='page-link' href='favourite.php?page=".$maxPage."''>".$maxPage."</a></li>";
}
echo"<li class='page-item'><a class='page-link' href='".$next."'>Next</a></li>
</ul>
</div>
</div>";
}
else
echo"<br><br><br><br><br><br><br><br><br><br><br><br><br>
<div class='alert alert-warning' role='alert'>
<h2><center>Your list is empty !!</center></h2>
</div><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";
}
else
header("location: index.php");
?>
</div>
<?php
require "footer.php";
?>
</body>
</html>