This repository was archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
185 lines (163 loc) · 6.67 KB
/
index.php
File metadata and controls
185 lines (163 loc) · 6.67 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
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
<!DOCTYPE html>
<html lang="cs">
<head>
<!-- import of set-up files -->
<?php
include("session/session_start.php");
?>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>>_Open\|/Book - Home</title>
<link rel="shortcut icon" href="logo/icon.png" type="image/x-icon">
<link rel="stylesheet" href="style/style.css" />
<script src="js/script.js"></script>
</head>
<body>
<div class="grid">
<div class="grid-item1"></div>
<div class="grid-item2">
<!-- Logo-->
<div>
>_<a class="logo" href="">Open\|/Book</a></div>
<a href="login.php" class="link">
<h2 id='login' onmouseenter="textAdd('login')" onmouseleave="stop_timeout()">
<?php
if (!empty($_SESSION["logged_in"])) {
if ($_SESSION["logged_in"] == true) {
echo $_SESSION["username"];
}
} else {
echo "log in";
}
?></h2>
</a>
</div>
<div class="grid-item3"></div>
<div class="grid-item4"></div>
<!-- !!POST template!!
<div class="content">
<div class="post_container">
<img src="img/profile/profile_x.png" alt="user_logo" class="profile_logo">
<h3 class="username">username</h3>
<h4>post_descripiton</h4>
<img class="post" src="img/post/post_x.png" alt="post_img">
</div>
-->
<div class="content">
<?php
if (isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page = 1;
}
if (isset($page)) {
#import of mySQL config file
include("db_config/mySQL_config.php");
#mySQL connection and data SELECT
$mySQL = mysqli_connect($host, $user, $password, $database);
$query = "SELECT * FROM post ORDER BY date DESC";
$query_return = mysqli_query($mySQL, $query);
#assign number of posts before data processsing
$postNumber = mysqli_num_rows($query_return);
#setting post limit & counter
$maxPost = $page * 5;
$minPost = $maxPost - 4;
$postId = 0;
#mySQL data output
while ($query_result = mysqli_fetch_assoc($query_return)) {
$postId++;
/* debug
echo "<br>post id: ";echo $postId;
echo "<br> min post:";
echo $minPost;
echo "<br>maxpost:";
echo $maxPost; */
if ($postId >= $minPost && $postId <= $maxPost) {
#get username
$query_user = "SELECT * FROM user WHERE userID = " . $query_result["userID"];
$query_result_user = mysqli_fetch_assoc(mysqli_query($mySQL, $query_user));
#data output
echo "
<div class='post_container'>";
//var_dump($query_result_user);
if (isset($query_result_user["userImgID"])) {
echo "<img src='img/profile/profile_" . $query_result_user["userImgID"];
} else {
echo "<img src='img/profile/profile_0";
}
echo ".png' alt='user_logo' class='profile_logo'>
<h3 class='username'>" . $query_result_user["userName"] . "</h3>
<h4>" . $query_result["postName"] . "</h4>
<img class='post' src='img/post/post_" . $query_result["postID"] . ".png' alt='post_img'>
</div>
";
}
};
mysqli_close($mySQL);
#pageCount declaration
$pageCount = ceil($postNumber / 5);
if ($pageCount > 1) {
echo "<footer>
<div class='pages'>";
#selective declaration of $i
$minPage = $page - 2;
$maxPage = $page + 2;
while ($minPage < 1 || $maxPage > $pageCount) {
#debug
//echo "<br>max:" . $maxPage . "<br>min:" . $minPage;
if ($minPage < 1) {
$minPage++;
}
if ($maxPage > $pageCount) {
$maxPage--;
}
}
if ($page < 3) {
//echo "loloec";
while ($maxPage != $pageCount) {
if ($maxPage - $minPage == 4) {
break;
}
$maxPage++;
}
}
if ($pageCount - $page < 3) {
//echo "trolec";
while ($maxPage - $minPage != 4) {
$minPage--;
if ($minPage == 0) {
$minPage++;
break;
}
}
}
for ($i = $minPage; $i <= $maxPage; $i++) {
#show selected page
if ($i == $page) {
echo "<a class='pages-text' href='/index.php?page=" . $i . "' style=' font-weight: bold'>" . $i . "</a>";
} else {
echo "<a class='pages-text' href='/index.php?page=" . $i . "'>" . $i . "</a>";
}
}
}
echo "</div>
</footer>";
}
?>
<!-- footer template
<footer>
<div class="pages">
<p class="pages-text">lol</p>
<p class="pages-text">lol</p>
<p class="pages-text">lol</p>
<p class="pages-text">lol</p>
<p class="pages-text">lol</p>
</div>
</footer>-->
<a href="/index.php"></a>
</div>
</div>
<div class="grid-item6"></div>
</div>
</body>
</html>