Fix MOTD
It now won't require there to be at least one entry in the motd table. I also tidied up the motd class
This commit is contained in:
parent
29ac0ece7e
commit
32cc4ec27f
|
@ -31,9 +31,12 @@ CREATE TABLE "users" (
|
|||
);
|
||||
|
||||
CREATE TABLE "motd" (
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"title" TEXT,
|
||||
"content" TEXT
|
||||
);
|
||||
INSERT INTO motd (title, content)
|
||||
VALUES ("MOTD ./dev.sh", "du kan endre motd i admin panelet");
|
||||
|
||||
INSERT INTO users (uname, groups)
|
||||
VALUES ("min_test_bruker", 1);
|
||||
|
|
|
@ -31,6 +31,7 @@ CREATE TABLE users (
|
|||
);
|
||||
|
||||
CREATE TABLE motd (
|
||||
`id` INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||
`title` TEXT,
|
||||
`content` TEXT
|
||||
);
|
||||
|
|
|
@ -10,8 +10,21 @@ class MOTD{
|
|||
$this->pdo = $pdo;
|
||||
}
|
||||
|
||||
public function getMOTD(){
|
||||
$query = 'SELECT * FROM motd LIMIT 1';
|
||||
public function setMOTD($title, $content) {
|
||||
if (is_array($content)) {
|
||||
$content = implode("_", $content);
|
||||
}
|
||||
$query = 'INSERT INTO motd(title, content) VALUES (:title, :content);';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
|
||||
$statement->bindParam(':title', $title, PDO::PARAM_STR);
|
||||
$statement->bindParam(':content', $content, PDO::PARAM_STR);
|
||||
|
||||
$statement->execute();
|
||||
}
|
||||
|
||||
public function getMOTD() {
|
||||
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
|
@ -20,4 +33,17 @@ class MOTD{
|
|||
|
||||
return $motd;
|
||||
}
|
||||
}
|
||||
|
||||
public function getMOTD_history($limit = 5) {
|
||||
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':limit', $limit, PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$data = $statement->fetch();
|
||||
$motd = array("title" => $data[0], "content" => explode("\n", $data[1]));
|
||||
|
||||
return $motd;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ $motd = $motdfetcher->getMOTD();
|
|||
<input type="text" name="title" value="<?= $motd['title'] ?>" class="boxinput" style="width:66%;"><br>
|
||||
|
||||
<p class="subtitle no-chin">Innhold</p>
|
||||
<textarea name="content" style="width:100%" rows="8" class="boxinput"><?= implode($motd["content"], "\n") ?></textarea>
|
||||
<textarea name="content" style="width:100%" rows="8" class="boxinput"><?= implode("\n", $motd["content"]) ?></textarea>
|
||||
|
||||
<div style="margin-top: 2em;">
|
||||
<hr class="ruler">
|
||||
|
@ -63,4 +63,6 @@ $motd = $motdfetcher->getMOTD();
|
|||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</body>
|
||||
|
||||
<?php print_r($motd); ?>
|
||||
|
|
|
@ -25,15 +25,11 @@ if(!$userManager->isAdmin($uname)){
|
|||
exit();
|
||||
}
|
||||
|
||||
$query = 'UPDATE motd SET title=:title, content=:content';
|
||||
$statement = $pdo->prepare($query);
|
||||
|
||||
$statement->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
|
||||
$statement->bindParam(':content', $_POST['content'], PDO::PARAM_STR);
|
||||
|
||||
$statement->execute();
|
||||
$motdfetcher = new \pvv\side\MOTD($pdo);
|
||||
$motdfetcher->setMOTD($_POST['title'], $_POST['content']);
|
||||
|
||||
header('Location: .');
|
||||
?>
|
||||
|
||||
<a href=".">Om du ikke ble automatisk omdirigert tilbake klikk her</a>
|
||||
<a href=".">Om du ikke ble automatisk omdirigert tilbake klikk her</a>
|
||||
|
|
Loading…
Reference in New Issue