Edit page working
This commit is contained in:
30
controllers/editpage.php
Normal file
30
controllers/editpage.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
$data['title'] = 'Novaconium Edit Page';
|
||||
|
||||
if ( empty($session->get('username'))) {
|
||||
$redirect->url('/novaconium/login');
|
||||
$messages->error('You are not loggedin');
|
||||
makeitso();
|
||||
}
|
||||
|
||||
$pageid = $router->parameters['id'];
|
||||
$query=<<<EOSQL
|
||||
SELECT
|
||||
id,
|
||||
title,
|
||||
intro,
|
||||
slug,
|
||||
body,
|
||||
draft,
|
||||
created,
|
||||
updated
|
||||
FROM pages
|
||||
WHERE id = '$pageid'
|
||||
EOSQL;
|
||||
|
||||
$data['rows'] = $db->getRow($query);
|
||||
$data = array_merge($data, [
|
||||
'tinymce' => true,
|
||||
'pageid' => 'admin-edit-page'
|
||||
]);
|
||||
view('@novacore/editpage', $data);
|
||||
@@ -88,7 +88,7 @@ $result = $db->query($query);
|
||||
if ($result->num_rows === 0) {
|
||||
$query = <<<EOSQL
|
||||
CREATE TABLE `pages` (
|
||||
`id` int(11) NOT NULL,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`heading` varchar(255) NOT NULL,
|
||||
`description` varchar(255) NOT NULL,
|
||||
|
||||
16
controllers/pages.php
Normal file
16
controllers/pages.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$data['title'] = 'Novaconium Pages';
|
||||
|
||||
if ( empty($session->get('username'))) {
|
||||
$redirect->url('/novaconium/login');
|
||||
$messages->error('You are not loggedin');
|
||||
makeitso();
|
||||
}
|
||||
|
||||
// Get the pages
|
||||
$query = "SELECT id, title, created, updated, draft FROM pages";
|
||||
$matched = $db->getRows($query);
|
||||
|
||||
$data['pages'] = $matched;
|
||||
|
||||
view('@novacore/pages', $data);
|
||||
55
controllers/savepage.php
Normal file
55
controllers/savepage.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use Nickyeoman\Validation;
|
||||
$v = new Nickyeoman\Validation\Validate();
|
||||
|
||||
$url_success = '/dashboard';
|
||||
$url_error = '/novaconium/page/edit/' . $post->get('id'); // Redirect back to the page edit form on error
|
||||
|
||||
if ( empty($session->get('username'))) {
|
||||
$redirect->url('/novaconium/login');
|
||||
$messages->error('You are not loggedin');
|
||||
makeitso();
|
||||
}
|
||||
|
||||
// Check Token
|
||||
if ($session->get('token') != $post->get('token')) {
|
||||
$redirect->url('/novaconium/pages');
|
||||
$messages->error('Invalid Token');
|
||||
makeitso();
|
||||
}
|
||||
|
||||
$id = $post->get('id');
|
||||
$slug = $post->get('slug');
|
||||
$title = $_POST['title'];
|
||||
$body = $_POST['body']; // We want it dirty
|
||||
$intro = $_POST['intro']; // We want it dirty
|
||||
|
||||
if ( empty( $post->get('draft') ) ) {
|
||||
$draft = 0;
|
||||
} else {
|
||||
$draft = 1;
|
||||
}
|
||||
|
||||
if ( empty($id) || empty($slug) || empty($body) ) {
|
||||
$messages->error('One of the fields was empty.');
|
||||
$redirect->url($url_fail);
|
||||
makeitso();
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$query = "UPDATE `pages` SET `title` = ?, `slug` = ?, `body` = ?, `intro` = ?, `draft` = ?, `updated` = NOW() WHERE `id` = ?";
|
||||
$params = [$title, $slug, $body, $intro, $draft, $id];
|
||||
|
||||
$db->query($query, $params);
|
||||
|
||||
$messages->notice('Page Saved');
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
$messages->notice($e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
$redirect->url('/novaconium/page/edit/' . $id);
|
||||
Reference in New Issue
Block a user