From 1abb7813a81c0cd6c1cf1b806fed1437aa5aafdd Mon Sep 17 00:00:00 2001 From: halworsen Date: Thu, 12 Oct 2017 00:38:28 +0200 Subject: [PATCH] Add event editing to admin interface --- src/pvv/side/dbactivity.php | 20 ++++++ www/admin/aktiviteter/delete.php | 2 +- www/admin/aktiviteter/edit.php | 101 +++++++++++++++++++++++++++++++ www/admin/aktiviteter/index.php | 22 ++++--- www/admin/aktiviteter/update.php | 57 +++++++++++++++++ www/css/admin.css | 34 +++++++++++ www/css/style.css | 23 +++++++ 7 files changed, 251 insertions(+), 8 deletions(-) create mode 100644 www/admin/aktiviteter/edit.php create mode 100644 www/admin/aktiviteter/update.php diff --git a/src/pvv/side/dbactivity.php b/src/pvv/side/dbactivity.php index 7c7d58d..0a90f70 100644 --- a/src/pvv/side/dbactivity.php +++ b/src/pvv/side/dbactivity.php @@ -32,6 +32,26 @@ class DBActivity implements Activity { return $events; } + public function getEventByID($id) { + $query = 'SELECT * FROM events WHERE id=:id LIMIT 1'; + $statement = $this->pdo->prepare($query); + $statement->bindParam(':id', $id, PDO::PARAM_INT); + $statement->execute(); + + $dbEvent = $statement->fetch(); + $event = new SimpleEvent( + $dbEvent['id'], + $dbEvent['name'], + DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']), + DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']), + $dbEvent['organiser'], + $dbEvent['location'], + $dbEvent['description'] + ); + + return $event; + } + public function getNextEventFrom(DateTimeImmutable $date) { $query = 'SELECT name,start,stop,organiser,location,description FROM events WHERE start > :date ORDER BY start ASC LIMIT 1'; diff --git a/www/admin/aktiviteter/delete.php b/www/admin/aktiviteter/delete.php index 2f8ab95..decc81c 100644 --- a/www/admin/aktiviteter/delete.php +++ b/www/admin/aktiviteter/delete.php @@ -9,7 +9,7 @@ $query = 'DELETE FROM events WHERE id=\'' . $eventID . '\''; $statement = $pdo->prepare($query); $statement->execute(); - +header('Location: ' . $_SERVER['HTTP_REFERER']); ?> Om du ikke ble automatisk omdirigert tilbake klikk her \ No newline at end of file diff --git a/www/admin/aktiviteter/edit.php b/www/admin/aktiviteter/edit.php new file mode 100644 index 0000000..43fde74 --- /dev/null +++ b/www/admin/aktiviteter/edit.php @@ -0,0 +1,101 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +$customActivity = new \pvv\side\DBActivity($pdo); + +$new = 0; +if(isset($_GET['new'])){ + $new = $_GET['new']; +} + +$eventID = 0; +if(isset($_GET['id'])){ + $eventID = $_GET['id']; +}else if($new == 0){ + echo "\nID not set"; + exit(); +} + +$today = new DateTimeImmutable; +$defaultStart = $today->format("Y-m-d H:00:00"); +$inOneHour = $today->add(new DateInterval('PT1H')); +$defaultEnd = $inOneHour->format("Y-m-d H:00:00"); + +$event = new \pvv\side\SimpleEvent( + 0, + 'Kul Hendelse', + $today, + $inOneHour, + 'PVV', + 'Norge et sted', + 'her skjer det noe altså' +); +if($new == 0){ + $event = $customActivity->getEventByID($eventID); +} +?> + + + + + + + + + +
Aktivitets­administrasjon
+ +
+ +
+

+ +
+
+

Tittel

+ getName(). '" class="boxinput">' ?>
+ +

Beskrivelse

+ + +

Starttid (YYYY-MM-DD HH:MM:SS)

+ getStart()->format('Y-m-d H:00:00') . '">
' ?> + +

Sluttid (YYYY-MM-DD HH:MM:SS)

+ getStop()->format('Y-m-d H:00:00') . '">
' ?> +
+ +
+

Organisert av

+ getOrganiser(). '" class="boxinput">' ?>
+ +

Hvor?

+ getLocation(). '" class="boxinput">' ?>
+
+ + getID() . '" />' ?> + +
+
+ + +
+
+ + + +

+

+ +
\ No newline at end of file diff --git a/www/admin/aktiviteter/index.php b/www/admin/aktiviteter/index.php index 13fa155..358707b 100644 --- a/www/admin/aktiviteter/index.php +++ b/www/admin/aktiviteter/index.php @@ -9,7 +9,10 @@ $pdo = new \PDO($dbDsn, $dbUser, $dbPass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $customActivity = new \pvv\side\DBActivity($pdo); -$page = $_GET['page']; +$page = 1; +if(isset($_GET['page'])){ + $page = $_GET['page']; +} ?> @@ -48,6 +51,7 @@ $page = $_GET['page']; $event = $events[$i]; $eventID = $event->getID(); ?> +
  • @@ -57,14 +61,17 @@ $page = $_GET['page'];
    - 🖊 - 🗑'; - ?> + + 🖊'; ?> + 🗑'; ?>
  • - + +

    Verktøy

    - Legg inn ny aktivitet + Legg inn ny aktivitet + test diff --git a/www/admin/aktiviteter/update.php b/www/admin/aktiviteter/update.php new file mode 100644 index 0000000..f1dc8fd --- /dev/null +++ b/www/admin/aktiviteter/update.php @@ -0,0 +1,57 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +if(!isset($_POST['title']) or !isset($_POST['desc']) or !isset($_POST['start']) or !isset($_POST['end']) or !isset($_POST['organiser']) or !isset($_POST['location'])){ + header('Location: ' . $_SERVER['HTTP_REFERER']); + exit(); +} + +$id = 0; +if(isset($_POST['id'])){ + $id = $_POST['id']; +} + +$title = $_POST['title']; +$desc = $_POST['desc']; +$start = $_POST['start']; +$stop = $_POST['end']; +$organiser = $_POST['organiser']; +$location = $_POST['location']; + +$statement; +if($id == 0){ + $query = 'INSERT INTO events (name, start, stop, organiser, location, description) VALUES (:title, :start, :stop, :organiser, :loc, :desc)'; + $statement = $pdo->prepare($query); + + $statement->bindParam(':title', $title, PDO::PARAM_STR); + $statement->bindParam(':desc', $desc, PDO::PARAM_STR); + $statement->bindParam(':start', $start, PDO::PARAM_STR); + $statement->bindParam(':stop', $stop, PDO::PARAM_STR); + $statement->bindParam(':organiser', $organiser, PDO::PARAM_STR); + $statement->bindParam(':loc', $location, PDO::PARAM_STR); +}else{ + $query = 'UPDATE events SET name=:title, start=:start, stop=:stop, organiser=:organiser, location=:loc, description=:desc WHERE id=:id'; + $statement = $pdo->prepare($query); + + $statement->bindParam(':title', $title, PDO::PARAM_STR); + $statement->bindParam(':desc', $desc, PDO::PARAM_STR); + $statement->bindParam(':start', $start, PDO::PARAM_STR); + $statement->bindParam(':stop', $stop, PDO::PARAM_STR); + $statement->bindParam(':organiser', $organiser, PDO::PARAM_STR); + $statement->bindParam(':loc', $location, PDO::PARAM_STR); + $statement->bindParam(':id', $id, PDO::PARAM_INT); +} + +$statement->execute(); + +header('Location: .'); +?> + +Om du ikke ble automatisk omdirigert tilbake klikk her \ No newline at end of file diff --git a/www/css/admin.css b/www/css/admin.css index ffe4a35..7269e54 100644 --- a/www/css/admin.css +++ b/www/css/admin.css @@ -56,6 +56,11 @@ header.admin { grid-template-columns: 75% 25%; } +.gridsplit5050 { + display: grid; + grid-template-columns: 50% 50%; +} + .gridl { height: 100%; grid-column: 1; @@ -69,6 +74,14 @@ header.admin { grid-column: 2; } +.allgrids { + grid-column: 1 / -1; +} + +.noborder { + border: none; +} + .subnote { margin-top: 0; color: gray; @@ -82,4 +95,25 @@ header.admin { .float-left { float: left; +} + +.btn { + text-decoration: none; + border: 1px solid #048; + color: #048; + padding: .2em 1em; + border-radius: .2em; + white-space: nowrap; + display: inline-block; + margin-bottom: .25em; +} +.btn:hover { + border-color: #084; + background: #eee; + color: #084; +} +.btn:active { + border-color: #084; + background: #084; + color: white; } \ No newline at end of file diff --git a/www/css/style.css b/www/css/style.css index 6e5c7b9..b5b6686 100644 --- a/www/css/style.css +++ b/www/css/style.css @@ -81,6 +81,17 @@ main:before { display: table-cell; } +.subtitle { + font-weight: bold; +} + +.ruler { + border-style: inset; + height: 1px; + border-width: 0px; + background-color: black; +} + a.btn { text-decoration: none; border: 1px solid #048; @@ -102,6 +113,18 @@ a.btn:active { color: white; } +.boxinput { + text-decoration: none; + border: 1px solid #048; + color: #048; + padding: .2em .4em; + border-radius: .2em; + white-space: nowrap; + display: inline-block; + margin-bottom: .25em; + resize: none; +} + .icon.subscribe { color: white; background: #082;