mirror of
https://github.com/p08dev/Bloggr.git
synced 2026-06-17 04:33:56 +02:00
Remove Post & User
Design fixes
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
body {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
section.main {
|
||||
text-align: left;
|
||||
width: 90%;
|
||||
|
||||
@ -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"}
|
||||
11
inc/nav.php
11
inc/nav.php
@ -9,6 +9,13 @@
|
||||
<label for="bmenub" class="burger pseudo button">≡</label>
|
||||
|
||||
<div class="menu">
|
||||
<?php
|
||||
if ($auth->isLoggedIn()){
|
||||
?>
|
||||
<span>Hey, <b><?= $auth->getUsernameById($auth->getId()) ?></b>!</span>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<a href="/" class="pseudo button"">Startseite</a>
|
||||
<?php
|
||||
if ($auth->hasRole([ \Bloggr\Roles::ADMIN ])){
|
||||
@ -25,13 +32,13 @@
|
||||
<?php
|
||||
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>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<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
|
||||
}
|
||||
?>
|
||||
|
||||
@ -12,7 +12,7 @@ require_once(__DIR__."/inc/head.php");
|
||||
<body>
|
||||
<?php require_once(__DIR__."/inc/nav.php"); ?>
|
||||
<section class="main">
|
||||
<h2>Posts</h2>
|
||||
<h2>Beiträge</h2>
|
||||
<?php
|
||||
if ($posts) {
|
||||
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>' : '' ?>
|
||||
</p>
|
||||
<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>
|
||||
</article>
|
||||
<?php
|
||||
|
||||
@ -319,6 +319,89 @@ class Auth
|
||||
}
|
||||
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) {
|
||||
if (empty($id) || !\is_numeric($id)) {
|
||||
return false;
|
||||
|
||||
42
post.php
42
post.php
@ -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') {
|
||||
$result = $auth->getPost($_GET['edit']);
|
||||
if(!$result) {
|
||||
@ -109,16 +119,15 @@ require_once(__DIR__."/inc/head.php");
|
||||
<section>
|
||||
<p><?= nl2br($data['text']) ?></p>
|
||||
</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
|
||||
if($data['updated_by']):
|
||||
?>
|
||||
Zuletzt bearbeitet: <?= date('H:i d.m.Y',$data['updated_at']).' von '.$data['updated_by'] ?>
|
||||
</small>
|
||||
zuletzt bearbeitet: <?= date('d.m.Y H:i',$data['updated_at']).' von '.$data['updated_by'] ?>
|
||||
<?php
|
||||
endif;
|
||||
if ($auth->canEditPost($data["id"]) == true) echo '<a href="post.php?edit='.$data["id"].'">Edit Post</a>';
|
||||
echo '</footer>';
|
||||
if ($auth->canEditPost($data["id"]) == true) echo '<br><a href="post.php?edit='.$data["id"].'">Edit Post</a>';
|
||||
echo '</small></footer>';
|
||||
?>
|
||||
</div>
|
||||
<?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>
|
||||
<label for="text">Text</label>
|
||||
<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>
|
||||
<?php
|
||||
endif;
|
||||
@ -172,6 +181,27 @@ require_once(__DIR__."/inc/head.php");
|
||||
<label for="text">Text</label>
|
||||
<textarea rows="4" cols="50" name="text" id="text"><?= (isset($data['text'])) ? $data['text'] : $text; ?></textarea>
|
||||
<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">×</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>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
body {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
section.main {
|
||||
text-align: left;
|
||||
width: 90%;
|
||||
|
||||
@ -33,6 +33,7 @@ require_once(__DIR__."/inc/head.php");
|
||||
<body>
|
||||
<?php require_once(__DIR__."/inc/nav.php"); ?>
|
||||
<section class="main">
|
||||
<a href="/">Zurück</a>
|
||||
<h2>Einstellungen</h2>
|
||||
<?php
|
||||
foreach ($errors as $key=>$value):
|
||||
|
||||
13
setup.php
13
setup.php
@ -35,7 +35,6 @@ if (isset($_POST['check']) || isset($_POST['submit'])) {
|
||||
if($dbName == "") {
|
||||
array_push($error, "Bitte gib eine Datenbank an.");
|
||||
}
|
||||
|
||||
if (isset($_POST['submit'])) {
|
||||
$config = fopen(__DIR__."/lib/config.php", "w");
|
||||
|
||||
@ -107,7 +106,7 @@ if (isset($_POST['check'])) {
|
||||
<section class="main">
|
||||
<h2>Seiteninformationen</h2>
|
||||
<article class="card">
|
||||
<header>
|
||||
<section>
|
||||
<p>
|
||||
<?php
|
||||
foreach($error as $err) {
|
||||
@ -119,9 +118,9 @@ if (isset($_POST['check'])) {
|
||||
?>
|
||||
</p>
|
||||
<form action="" method="post">
|
||||
<div <?= ($success) ? 'style="display: none;' : '' ?>>
|
||||
<div <?= ($success) ? 'style="display: none;"' : '' ?>>
|
||||
<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 ?>" >
|
||||
</p>
|
||||
<h2>Datenbankinformationen</h2>
|
||||
@ -158,11 +157,11 @@ if (isset($_POST['check'])) {
|
||||
</div>
|
||||
<p>
|
||||
|
||||
<?= (!$viewSubmit) ? '<input type="submit" value="Check" name="check">' : '' ?>
|
||||
<?= ($viewSubmit) ? '<input type="submit" value="Submit" name="submit">' : '' ?>
|
||||
<?= (!$viewSubmit) ? '<input type="submit" value="Los!" name="check">' : '' ?>
|
||||
<?= ($viewSubmit) ? '<input type="submit" value="Abschließen" name="submit">' : '' ?>
|
||||
</p>
|
||||
</form>
|
||||
</header>
|
||||
</section>
|
||||
</article>
|
||||
</section>
|
||||
</body>
|
||||
|
||||
46
users.php
46
users.php
@ -21,6 +21,15 @@ if(isset($_GET['view'])) {
|
||||
$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();
|
||||
@ -34,9 +43,16 @@ require_once(__DIR__."/inc/head.php");
|
||||
<body>
|
||||
<?php require_once(__DIR__."/inc/nav.php"); ?>
|
||||
<section class="main">
|
||||
<?= ($view) ? '<a href="/users.php">Zurück</a>' : '<a href="/">Zurück</a>' ?>
|
||||
<h2>Benutzer</h2>
|
||||
<?= ($view) ? '<a href="/users.php">Zurück</a><br><br>' : '' ?>
|
||||
<?php
|
||||
foreach ($errors as $key=>$value):
|
||||
?>
|
||||
<span style="color: red;">
|
||||
<?= $value ?>
|
||||
</span><br>
|
||||
<?php
|
||||
endforeach;
|
||||
if($view) {
|
||||
$found = false;
|
||||
foreach ($users as $key => $value) {
|
||||
@ -45,15 +61,39 @@ require_once(__DIR__."/inc/head.php");
|
||||
|
||||
?>
|
||||
<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="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>
|
||||
<select name="role" id="role">
|
||||
<option value="0" <?= ($value['roles_mask'] == 0) ? 'selected' : '' ?>>Gast</option>
|
||||
<option value="1" <?= ($value['roles_mask'] == 1) ? 'selected' : '' ?>>Admin</option>
|
||||
<option value="2" <?= ($value['roles_mask'] == 2) ? 'selected' : '' ?>>Author</option>
|
||||
</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">×</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>
|
||||
<?php
|
||||
}
|
||||
@ -62,7 +102,7 @@ require_once(__DIR__."/inc/head.php");
|
||||
} else {
|
||||
$count = 0;
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user