-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
235 lines (205 loc) · 13.2 KB
/
index.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
require "php/db.php";
include_once 'php/functions.php';
$data = $_GET;
$sort_values = array('date', 'deadline');
$order_values = array('asc', 'desc');
$qty_values = array('10', '20', '30');
$sort_by = (isset($data['s']) and in_array($data['s'], $sort_values)) ? $data['s'] : 'date';
$order = (isset($data['o']) and in_array($data['o'], $order_values)) ? $data['o'] : 'desc';
$quantity_per_page = (isset($data['q']) and in_array($data['q'], $qty_values)) ? $data['q'] : 10;
$request = '';
foreach (array_keys($data) as $key) {
if ($key != 'page') {
$request .= $key . '=' . $data[$key];
if (key(array_slice($data, -1, 1, true)) != $key)
$request .= '&';
}
}
$total = intval((count_actual_announcements() - 1) / $quantity_per_page) + 1;
if (isset($data['page']) and $data['page'] > 0) {
if ($data['page'] > $total) {
$page = $total;
} else {
$page = $data['page'];
}
} else {
$page = 1;
}
$start = ($page - 1) * $quantity_per_page;
$announcements = get_actual_announcements_with_filter($sort_by, $order, $start, $quantity_per_page);
?>
<!DOCTYPE html>
<html lang="ua">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>StepHub</title>
<link rel="shortcut icon" href="favicon.ico">
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Google Material Design Icons -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Font Awesome Icons -->
<link href="vendor/fontawesome-free-5.9.0-web/css/all.css" rel="stylesheet">
<!--load all styles -->
<link href="css/main.css" rel="stylesheet">
</head>
<body class="text-center">
<!-- Preloader -->
<?php include_once 'templates/preloader.html'; ?>
<!-- Back to top button -->
<a id="back-to-top-button"></a>
<!-- Navigation -->
<?php include_once 'templates/navbar.php'; ?>
<!-- Toasts -->
<?php if (isset($data['activate']) and $data['activate'] == 'true') {
include_once 'templates/toasts.php';
}; ?>
<!-- Header-->
<?php if (!array_key_exists('logged_user', $_SESSION)) :
include_once 'templates/intro.php'; ?>
<?php else :
include_once 'templates/header.php'; ?>
<!-- Page Content -->
<div class="container px-0 px-md-3">
<div class="row mx-0 mx-md-5">
<div class="col px-0 px-md-2">
<div class="row my-3 mx-0 d-none d-md-flex">
<form class="form-inline small float-right ml-md-auto" action="index.php" method="GET">
<div class="form-group mr-2">
<label for="sort_by">Сортування</label>
<select class="form-control-sm ml-2" name="s" id="sort_by">
<option value="date" <?php if (!isset($data['s']) or (isset($data['s']) and $data['s'] == 'date')) echo "selected" ?>>Дата створення</option>
<option value="deadline" <?php if (isset($data['s']) and $data['s'] == 'deadline') echo "selected" ?>>Дедлайн</option>
</select>
<select class="form-control-sm ml-2" name="o" id="order" style="font-family: 'FontAwesome', serif !important;">
<option value="asc" <?php if (isset($data['o']) and $data['o'] == 'asc') echo "selected" ?>></option>
<option value="desc" <?php if (!isset($data['o']) or ($data['o'] and $data['o'] == 'desc')) echo "selected" ?>></i></option>
</select>
</div>
<div class="form-group mr-2">
<label for="qty">Оголошень на сторінці</label>
<select class="form-control-sm ml-2 " name="q" id="announcement_qty">
<option value="10" <?php if (!isset($data['q']) or (isset($data['q']) and $data['q'] == '10')) echo "selected" ?>>10</option>
<option value="20" <?php if (isset($data['q']) and (isset($data['q']) and $data['q'] == '20')) echo "selected" ?>>20</option>
<option value="30" <?php if (isset($data['q']) and (isset($data['q']) and $data['q'] == '30')) echo "selected" ?>>30</option>
</select>
</div>
<button type="submit" class="btn btn-sm btn-outline-secondary"><i class="fas fa-filter mr-2"></i>Фільтрувати</button>
</form>
</div>
<div class="card border-xs-0">
<div class="card-body shadow-sm bg-light pb-0 pt-4 pt-md-3 px-2 px-md-3">
<?php if ($announcements) :
foreach ($announcements as $announcement) : ?>
<div class="card text-left mb-2 mb-md-3 clickable bg-white announcement-card" onclick="location.href='announcement.php?id=<?= $announcement['id'] ?>'">
<div class="card-body p-2 p-md-3">
<h5 class="card-title"><?= $announcement['title'] ?></h5>
<p class="card-text mb-4"><?= $announcement['details'] ?></p>
<div class="row">
<div class="col-md-8">
<div class="row pt-2 px-2">
<p class="card-text text-muted small mx-2"><i class="far fa-calendar mr-2"></i><?= show_date($announcement['date']) ?></p>
<?php if ($announcement['deadline']) : ?>
<p class="card-text text-muted small mx-2"><i class="far fa-calendar-times mr-2"></i><?= show_date($announcement['deadline']) ?></p>
<?php endif;
if (count_comments_by_announcement_id($announcement['id']) > 0) : ?>
<p class="card-text text-muted small mx-2"><i class="far fa-comments mr-2"></i><?= count_comments_by_announcement_id($announcement['id']) ?></p>
<?php endif;
if ($announcement['file']) : ?>
<p class="card-text text-muted small mx-2"><i class="fa fa-paperclip mr-2"></i><?= $announcement['file'] ?></p>
<?php endif; ?>
</div>
</div>
<div class="col align-self-end">
<a href="announcement.php?id=<?= $announcement['id'] ?>" class="btn my-btn-blue float-right">Детальніше</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<!-- Pagination-->
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center mt-3 mt-md-0 mb-3">
<?php if ($page == 1) : ?>
<li class="page-item disabled">
<span class="page-link">«</span>
</li>
<?php else : ?>
<li class="page-item">
<a class="page-link" href="index.php?page=<?= ($page - 1) . '&' . $request ?>">«</a>
</li>
<li class="page-item"><a class="page-link" href="index.php?page=1&<?= $request ?>">1</a></li>
<?php if ($page > 4) : ?>
<li class="page-item disabled"><a class="page-link">...</a></li>
<li class="page-item"><a class="page-link" href="index.php?page=<?= ($page - 3) . '&' . $request ?>"><?= $page - 3 ?></a></li>
<?php endif; ?>
<?php if ($page > 3) : ?>
<li class="page-item"><a class="page-link" href="index.php?page=<?= ($page - 2) . '&' . $request ?>"><?= $page - 2 ?></a></li>
<?php endif; ?>
<?php if ($page > 2) : ?>
<li class="page-item"><a class="page-link" href="index.php?page=<?= ($page - 1) . '&' . $request ?>"><?= $page - 1 ?></a></li>
<?php endif; ?>
<?php endif; ?>
<li class="page-item active">
<span class="page-link"><?= $page ?><span class="sr-only">(current)</span></span>
</li>
<?php if ($page != $total) : ?>
<?php if ($page + 1 < $total) : ?>
<li class="page-item"><a class="page-link" href="index.php?page=<?= ($page + 1) . '&' . $request ?>"><?= $page + 1 ?></a></li>
<?php endif; ?>
<?php if ($page + 2 < $total) : ?>
<li class="page-item"><a class="page-link" href="index.php?page=<?= ($page + 2) . '&' . $request ?>"><?= $page + 2 ?></a></li>
<?php endif; ?>
<?php if ($page + 3 < $total) : ?>
<li class="page-item"><a class="page-link" href="index.php?page=<?= ($page + 3) . '&' . $request ?>"><?= $page + 3 ?></a></li>
<?php if ($page + 3 != $total - 1) : ?>
<li class="page-item disabled"><a class="page-link">...</a></li>
<?php endif; ?>
<?php endif; ?>
<li class="page-item"><a class="page-link" href="index.php?page=<?= $total . '&' . $request ?>"><?= $total ?></a></li>
<li class="page-item">
<a class="page-link" href="index.php?page=<?= ($page + 1) . '&' . $request ?>">»</a>
</li>
<?php else : ?>
<li class="page-item disabled">
<span class="page-link">»</span>
</li>
<?php endif; ?>
</ul>
</nav>
<?php else : ?>
<div class="card border-danger">
<div class="card-body shadow-sm">
<h5 class="card-title mb-0 text-center text-danger"><i class="fas fa-exclamation-circle mr-3"></i>Не знайдено оголошень</h5>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<!-- Footer -->
<?php include_once 'templates/footer.php'; ?>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Navbar scroll animation -->
<script src="js/navbar.js"></script>
<!-- Main sctipt -->
<script src="js/script.js"></script>
<!-- Back to top button -->
<script src="js/top.js"></script>
<!-- Activate toasts -->
<script>
$(window).on('load', function() {
$('#activate').toast('show');
});
</script>
</body>
</html>