diff --git a/dist/pvv.sql b/dist/pvv.sql index 4ad5fa9..1df0f67 100644 --- a/dist/pvv.sql +++ b/dist/pvv.sql @@ -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); diff --git a/dist/pvv_mysql.sql b/dist/pvv_mysql.sql index fe001fc..ae02dc5 100644 --- a/dist/pvv_mysql.sql +++ b/dist/pvv_mysql.sql @@ -31,6 +31,7 @@ CREATE TABLE users ( ); CREATE TABLE motd ( +`id` INTEGER PRIMARY KEY AUTO_INCREMENT, `title` TEXT, `content` TEXT ); diff --git a/src/pvv/side/motd.php b/src/pvv/side/motd.php index c5fb3dd..4a71a6c 100644 --- a/src/pvv/side/motd.php +++ b/src/pvv/side/motd.php @@ -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; } -} \ No newline at end of file + + 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; + } + +} diff --git a/www/admin/motd/index.php b/www/admin/motd/index.php index 7695025..704d162 100644 --- a/www/admin/motd/index.php +++ b/www/admin/motd/index.php @@ -54,7 +54,7 @@ $motd = $motdfetcher->getMOTD();

Innhold

- +

@@ -63,4 +63,6 @@ $motd = $motdfetcher->getMOTD();
- \ No newline at end of file + + + diff --git a/www/admin/motd/update.php b/www/admin/motd/update.php index a7af78b..ee1eae0 100644 --- a/www/admin/motd/update.php +++ b/www/admin/motd/update.php @@ -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: .'); ?> -Om du ikke ble automatisk omdirigert tilbake klikk her \ No newline at end of file +Om du ikke ble automatisk omdirigert tilbake klikk her