Remove Post & User

Design fixes
This commit is contained in:
Furentes
2019-05-23 08:56:11 +02:00
parent 76ea941123
commit 61d77ff1a1
10 changed files with 189 additions and 21 deletions

View File

@ -1,3 +1,7 @@
body {
color: #333;
}
section.main { section.main {
text-align: left; text-align: left;
width: 90%; width: 90%;

View File

@ -1 +1 @@
{"version":3,"sourceRoot":"","sources":["../scss/main.scss"],"names":[],"mappings":"AAAA;EACE;EACA;EACA;EACA;EACA","file":"main.css"} {"version":3,"sourceRoot":"","sources":["../scss/main.scss"],"names":[],"mappings":"AAAA;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA","file":"main.css"}

View File

@ -9,6 +9,13 @@
<label for="bmenub" class="burger pseudo button">&#8801;</label> <label for="bmenub" class="burger pseudo button">&#8801;</label>
<div class="menu"> <div class="menu">
<?php
if ($auth->isLoggedIn()){
?>
<span>Hey, <b><?= $auth->getUsernameById($auth->getId()) ?></b>!</span>
<?php
}
?>
<a href="/" class="pseudo button"">Startseite</a> <a href="/" class="pseudo button"">Startseite</a>
<?php <?php
if ($auth->hasRole([ \Bloggr\Roles::ADMIN ])){ if ($auth->hasRole([ \Bloggr\Roles::ADMIN ])){
@ -25,13 +32,13 @@
<?php <?php
if (!$auth->isLoggedIn()){ if (!$auth->isLoggedIn()){
?> ?>
<a href="/login.php" class="pseudo button">Login</a> <a href="/login.php" class="pseudo button">Anmelden</a>
<a href="/register.php" class="button">Registrieren</a> <a href="/register.php" class="button">Registrieren</a>
<?php <?php
} else { } else {
?> ?>
<a href="/settings.php" class="pseudo button">Einstellungen</a> <a href="/settings.php" class="pseudo button">Einstellungen</a>
<a href="/logout.php" class="button">Logout</a> <a href="/logout.php" class="button">Abmelden</a>
<?php <?php
} }
?> ?>

View File

@ -12,7 +12,7 @@ require_once(__DIR__."/inc/head.php");
<body> <body>
<?php require_once(__DIR__."/inc/nav.php"); ?> <?php require_once(__DIR__."/inc/nav.php"); ?>
<section class="main"> <section class="main">
<h2>Posts</h2> <h2>Beiträge</h2>
<?php <?php
if ($posts) { if ($posts) {
foreach($posts as $post) { foreach($posts as $post) {
@ -25,7 +25,7 @@ require_once(__DIR__."/inc/head.php");
<?= substr($post['text'], 0, 512) ?><?= (substr($post['text'], 0, 512) !== $post['text']) ? '... <br><a href="/post.php?view='.$post["id"].'">Weiterlesen...</a>' : '' ?> <?= substr($post['text'], 0, 512) ?><?= (substr($post['text'], 0, 512) !== $post['text']) ? '... <br><a href="/post.php?view='.$post["id"].'">Weiterlesen...</a>' : '' ?>
</p> </p>
<footer> <footer>
<p><small>von <?= $post['user'] ?> am <?= date('H:i d.m.Y', $post['created_at']) ?></small></p> <p><small>von <?= $post['user'] ?> am <?= date('d.m.Y H:i', $post['created_at']) ?></small></p>
</footer> </footer>
</article> </article>
<?php <?php

View File

@ -319,6 +319,89 @@ class Auth
} }
return true; return true;
} }
public function removePost($id) {
if (!$this->isLoggedIn()) return false;
if (!$this->canEditPost($id)) return false;
$errors = array();
try {
$s = $this->pdo->prepare("DELETE FROM posts WHERE id = :id LIMIT 1;");
$r = $s->execute(array(
':id' => $id,
));
if(!$r) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
} catch (\PDOException $e) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
try {
$s = $this->pdo->prepare("DELETE FROM comments WHERE post = :id;");
$r = $s->execute(array(
':id' => $id,
));
if(!$r) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
} catch (\PDOException $e) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
if (count($errors) > 0) {
return $errors;
}
return true;
}
public function deleteUser($id) {
if (!$this->isLoggedIn()) return false;
if (!$this->hasRole([ \Bloggr\Roles::ADMIN ])) {
return false;
}
$errors = array();
try {
$s = $this->pdo->prepare("DELETE FROM users WHERE id = :id;");
$r = $s->execute(array(
':id' => $id,
));
if(!$r) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
} catch (\PDOException $e) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
try {
$s = $this->pdo->prepare("DELETE FROM posts WHERE user = :id;");
$r = $s->execute(array(
':id' => $id,
));
if(!$r) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
} catch (\PDOException $e) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
try {
$s = $this->pdo->prepare("DELETE FROM comments WHERE user = :id;");
$r = $s->execute(array(
':id' => $id,
));
if(!$r) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
} catch (\PDOException $e) {
array_push($errors, 'Da ist etwas schiefgelaufen!');
}
if (count($errors) > 0) {
return $errors;
}
return true;
}
public function getPost($id) { public function getPost($id) {
if (empty($id) || !\is_numeric($id)) { if (empty($id) || !\is_numeric($id)) {
return false; return false;

View File

@ -66,6 +66,16 @@ if ($action == 'edit' && isset($_POST['edit'])) {
} }
} }
if ($action == 'edit' && isset($_POST['delete'])) {
$result = $auth->removePost($_GET['edit']);
if (is_array($result)) {
$errors = $result;
} else {
header("Location: /");
}
}
if ($action == 'edit') { if ($action == 'edit') {
$result = $auth->getPost($_GET['edit']); $result = $auth->getPost($_GET['edit']);
if(!$result) { if(!$result) {
@ -109,16 +119,15 @@ require_once(__DIR__."/inc/head.php");
<section> <section>
<p><?= nl2br($data['text']) ?></p> <p><?= nl2br($data['text']) ?></p>
</section> </section>
<footer><small>von <?= $data['user'] ?> am <?= date('H:i d.m.Y', $data['created_at']) ?><br> <footer><small>von <?= $data['user'] ?> am <?= date('d.m.Y H:i', $data['created_at']) ?><br>
<?php <?php
if($data['updated_by']): if($data['updated_by']):
?> ?>
Zuletzt bearbeitet: <?= date('H:i d.m.Y',$data['updated_at']).' von '.$data['updated_by'] ?> zuletzt bearbeitet: <?= date('d.m.Y H:i',$data['updated_at']).' von '.$data['updated_by'] ?>
</small>
<?php <?php
endif; endif;
if ($auth->canEditPost($data["id"]) == true) echo '<a href="post.php?edit='.$data["id"].'">Edit Post</a>'; if ($auth->canEditPost($data["id"]) == true) echo '<br><a href="post.php?edit='.$data["id"].'">Edit Post</a>';
echo '</footer>'; echo '</small></footer>';
?> ?>
</div> </div>
<?php <?php
@ -158,7 +167,7 @@ require_once(__DIR__."/inc/head.php");
<input type="text" name="title" id="title" value="<?= (isset($_POST['title'])) ? htmlspecialchars($_POST['title']) : ''; ?>"><br> <input type="text" name="title" id="title" value="<?= (isset($_POST['title'])) ? htmlspecialchars($_POST['title']) : ''; ?>"><br>
<label for="text">Text</label> <label for="text">Text</label>
<textarea rows="4" cols="50" name="text" id="text"><?= (isset($_POST['text'])) ? htmlspecialchars($_POST['text']) : ''; ?></textarea> <textarea rows="4" cols="50" name="text" id="text"><?= (isset($_POST['text'])) ? htmlspecialchars($_POST['text']) : ''; ?></textarea>
<input type="submit" name="new" value="new"> <input type="submit" name="new" value="Erstellen">
</form> </form>
<?php <?php
endif; endif;
@ -172,6 +181,27 @@ require_once(__DIR__."/inc/head.php");
<label for="text">Text</label> <label for="text">Text</label>
<textarea rows="4" cols="50" name="text" id="text"><?= (isset($data['text'])) ? $data['text'] : $text; ?></textarea> <textarea rows="4" cols="50" name="text" id="text"><?= (isset($data['text'])) ? $data['text'] : $text; ?></textarea>
<input type="submit" name="edit" value="Speichern"> <input type="submit" name="edit" value="Speichern">
<label for="modal_1" class="button warning">Löschen</label>
<div class="modal">
<input id="modal_1" type="checkbox" />
<label for="modal_1" class="overlay"></label>
<article>
<header>
<h3>Beitrag wirklich löschen?</h3>
<label for="modal_1" class="close">&times;</label>
</header>
<section class="content">
Sicher dass der Beitrag gelöscht werden soll? Das löschen eines Beitrags löscht alle seine Kommentare! <b>Die Daten sind nicht wiederherstellbar!</b>
</section>
<footer>
<input class="dangerous warning" type="submit" name="delete" value="Trotzdem löschen">
<label for="modal_1" class="button">
Abbrechen
</label>
</footer>
</article>
</div>
</form> </form>
<?php <?php
endif; endif;

View File

@ -1,3 +1,7 @@
body {
color: #333;
}
section.main { section.main {
text-align: left; text-align: left;
width: 90%; width: 90%;

View File

@ -33,6 +33,7 @@ require_once(__DIR__."/inc/head.php");
<body> <body>
<?php require_once(__DIR__."/inc/nav.php"); ?> <?php require_once(__DIR__."/inc/nav.php"); ?>
<section class="main"> <section class="main">
<a href="/">Zurück</a>
<h2>Einstellungen</h2> <h2>Einstellungen</h2>
<?php <?php
foreach ($errors as $key=>$value): foreach ($errors as $key=>$value):

View File

@ -35,7 +35,6 @@ if (isset($_POST['check']) || isset($_POST['submit'])) {
if($dbName == "") { if($dbName == "") {
array_push($error, "Bitte gib eine Datenbank an."); array_push($error, "Bitte gib eine Datenbank an.");
} }
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
$config = fopen(__DIR__."/lib/config.php", "w"); $config = fopen(__DIR__."/lib/config.php", "w");
@ -107,7 +106,7 @@ if (isset($_POST['check'])) {
<section class="main"> <section class="main">
<h2>Seiteninformationen</h2> <h2>Seiteninformationen</h2>
<article class="card"> <article class="card">
<header> <section>
<p> <p>
<?php <?php
foreach($error as $err) { foreach($error as $err) {
@ -119,9 +118,9 @@ if (isset($_POST['check'])) {
?> ?>
</p> </p>
<form action="" method="post"> <form action="" method="post">
<div <?= ($success) ? 'style="display: none;' : '' ?>> <div <?= ($success) ? 'style="display: none;"' : '' ?>>
<p> <p>
<label for="SITE_TITLE">Seitentitel</label> <h2>Seitentitel</h2>
<input type="text" name="SITE_TITLE" id="SITE_TITLE" placeholder="z.B. Mein Blog" value="<?= $siteTitle ?>" > <input type="text" name="SITE_TITLE" id="SITE_TITLE" placeholder="z.B. Mein Blog" value="<?= $siteTitle ?>" >
</p> </p>
<h2>Datenbankinformationen</h2> <h2>Datenbankinformationen</h2>
@ -158,11 +157,11 @@ if (isset($_POST['check'])) {
</div> </div>
<p> <p>
<?= (!$viewSubmit) ? '<input type="submit" value="Check" name="check">' : '' ?> <?= (!$viewSubmit) ? '<input type="submit" value="Los!" name="check">' : '' ?>
<?= ($viewSubmit) ? '<input type="submit" value="Submit" name="submit">' : '' ?> <?= ($viewSubmit) ? '<input type="submit" value="Abschließen" name="submit">' : '' ?>
</p> </p>
</form> </form>
</header> </section>
</article> </article>
</section> </section>
</body> </body>

View File

@ -21,6 +21,15 @@ if(isset($_GET['view'])) {
$update = $auth->updateUserRole($view, $_POST['role']); $update = $auth->updateUserRole($view, $_POST['role']);
} }
if(isset($_POST['delete'])) {
$delete = $auth->deleteUser($view);
if (is_array($delete)) {
$errors = $delete;
} else {
header("Location: /users.php");
}
}
} }
$users = $auth->getAllUsers(); $users = $auth->getAllUsers();
@ -34,9 +43,16 @@ require_once(__DIR__."/inc/head.php");
<body> <body>
<?php require_once(__DIR__."/inc/nav.php"); ?> <?php require_once(__DIR__."/inc/nav.php"); ?>
<section class="main"> <section class="main">
<?= ($view) ? '<a href="/users.php">Zurück</a>' : '<a href="/">Zurück</a>' ?>
<h2>Benutzer</h2> <h2>Benutzer</h2>
<?= ($view) ? '<a href="/users.php">Zurück</a><br><br>' : '' ?>
<?php <?php
foreach ($errors as $key=>$value):
?>
<span style="color: red;">
<?= $value ?>
</span><br>
<?php
endforeach;
if($view) { if($view) {
$found = false; $found = false;
foreach ($users as $key => $value) { foreach ($users as $key => $value) {
@ -45,15 +61,39 @@ require_once(__DIR__."/inc/head.php");
?> ?>
<form action="<?= htmlspecialchars($_SERVER['REQUEST_URI']) ?>" method="post"> <form action="<?= htmlspecialchars($_SERVER['REQUEST_URI']) ?>" method="post">
<label for="id"><b>ID:</b> <?= $value['id'] ?></label><br>
<label for="username"><b>Benutzername:</b> <?= $value['username'] ?></label><br> <label for="username"><b>Benutzername:</b> <?= $value['username'] ?></label><br>
<label for="email"><b>E-Mail:</b> <?= $value['email'] ?></label><br> <label for="email"><b>E-Mail:</b> <?= $value['email'] ?></label><br>
<label for="registered"><b>Mitglied seit:</b> <?= date('d.m.Y H:i', $value['registered']) ?></label><br>
<label for="last_login"><b>Letzter login:</b> <?= date('d.m.Y H:i', $value['last_login']) ?></label><br>
<label for="roles_mask"><b>Rolle</b></label> <label for="roles_mask"><b>Rolle</b></label>
<select name="role" id="role"> <select name="role" id="role">
<option value="0" <?= ($value['roles_mask'] == 0) ? 'selected' : '' ?>>Gast</option> <option value="0" <?= ($value['roles_mask'] == 0) ? 'selected' : '' ?>>Gast</option>
<option value="1" <?= ($value['roles_mask'] == 1) ? 'selected' : '' ?>>Admin</option> <option value="1" <?= ($value['roles_mask'] == 1) ? 'selected' : '' ?>>Admin</option>
<option value="2" <?= ($value['roles_mask'] == 2) ? 'selected' : '' ?>>Author</option> <option value="2" <?= ($value['roles_mask'] == 2) ? 'selected' : '' ?>>Author</option>
</select><br> </select><br>
<input type="submit" name="update" value="Update"> <input type="submit" name="update" value="Speichern">
<label for="modal_1" class="button warning">Löschen</label>
<div class="modal">
<input id="modal_1" type="checkbox" />
<label for="modal_1" class="overlay"></label>
<article>
<header>
<h3>Benutzer wirklich löschen?</h3>
<label for="modal_1" class="close">&times;</label>
</header>
<section class="content">
Sicher dass der Benutzer gelöscht werden soll? Das löschen eines Benutzers löscht alle seine Beiträge und Kommentare! <b>Die Daten sind nicht wiederherstellbar!</b>
</section>
<footer>
<input class="error dangerous" type="submit" name="delete" value="Trotzdem löschen">
<label for="modal_1" class="button">
Abbrechen
</label>
</footer>
</article>
</div>
</form> </form>
<?php <?php
} }
@ -62,7 +102,7 @@ require_once(__DIR__."/inc/head.php");
} else { } else {
$count = 0; $count = 0;
foreach ($users as $key => $value) { foreach ($users as $key => $value) {
echo '<a href="/users.php?view='.$value['id'].'">'.$value['id'].' - '.$value['username'].'</a><br>'; echo '<a href="/users.php?view='.$value['id'].'">['.$value['id'].'] '.$value['username'].'</a><br>';
$count++; $count++;
} }
} }