Split activities into pages in the admin interface

and other trivial fixes
This commit is contained in:
Markus Wang Halvorsen 2017-10-08 03:33:42 +02:00
parent 56f71eb9ab
commit d8f5dd4ad9
4 changed files with 43 additions and 8 deletions

View File

@ -9,5 +9,7 @@ $query = 'DELETE FROM events WHERE id=\'' . $eventID . '\'';
$statement = $pdo->prepare($query);
$statement->execute();
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
<a href=".?page=1">Om du ikke ble automatisk omdirigert tilbake klikk her</a>

View File

@ -8,8 +8,11 @@ require __DIR__ . '/../../../sql_config.php';
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$customActivity = new \pvv\side\DBActivity($pdo);
$page = $_GET['page'];
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../../css/normalize.css">
<link rel="stylesheet" href="../../css/style.css">
<link rel="stylesheet" href="../../css/events.css">
@ -32,13 +35,23 @@ $customActivity = new \pvv\side\DBActivity($pdo);
<p class="subnote">Gjentagende aktiviteter vises ikke</p>
<ul class="event-list">
<?php foreach($customActivity->getAllEvents() as $event){
<?php
$counter = 0;
$pageLimit = 4;
$events = $customActivity->getAllEvents();
for($i = ($pageLimit * ($page - 1)); $i < count($events) ;$i++){
if($counter == $pageLimit){
break;
}
$event = $events[$i];
$eventID = $event->getID();
?>
<li>
<div class="event admin">
<div class="event-info">
<h3 class="no-chin"><?= $event->getName() . " (" . $eventID . ")"; ?></h3>
<h3 class="no-chin"><?= $event->getName() . " (ID: " . $eventID . ")"; ?></h3>
<p class="subnote"><?= $event->getStart()->format("(Y-m-d H:i:s)") . " - " . $event->getStop()->format("(Y-m-d H:i:s)"); ?></p>
<p><?= implode($event->getDescription(), "</p>\n<p>"); ?></p>
</div>
@ -46,13 +59,23 @@ $customActivity = new \pvv\side\DBActivity($pdo);
<div class="event-actions">
<a href="/">🖊</a> <!-- emojis are for big boys -->
<?php
echo '<a href="./delete.php?id=' . $eventID . '" onclick="return confirm(\'Knallsikker? (ID: ' . $eventID . ')\');">🗑</a>';
echo '<a href="delete.php?id=' . $eventID . '" onclick="return confirm(\'Knallsikker? (ID: ' . $eventID . ')\');">🗑</a>';
?>
</div>
</div>
</li>
<?php } ?>
<?php $counter++; } ?>
</ul>
<?php
if($page != 1){
echo '<a class="btn float-left" href="?page=' . ($page - 1) . '">Forrige side</a>';
}
if(($counter == $pageLimit) and (($pageLimit * $page) < count($events))){
echo '<a class="btn float-right" href="?page=' . ($page + 1) . '">Neste side</a>';
}
?>
</div>
<div class="gridr">

View File

@ -1,3 +1,4 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../css/events.css">
@ -16,8 +17,9 @@
<article>
<h2>Verktøy</h2>
<a class="btn adminbtn" href="admin/aktiviteter/">Aktiviteter/Hendelser</a>
<a class="btn adminbtn" href="admin/aktiviteter?page=1">Aktiviteter/Hendelser</a>
<a class="btn adminbtn" href="admin/prosjekter/">Prosjekter</a>
</article>
</main>
</main>

View File

@ -75,3 +75,11 @@ header.admin {
font-size: .7em;
font-style: italic;
}
.float-right {
float: right;
}
.float-left {
float: left;
}