novaconium/controllers/editpage.php

74 lines
1.7 KiB
PHP

<?php
$data = array_merge($data, [
'title' => 'Novaconium Edit Page',
'pageclass' => 'novaconium'
]);
// Check if logged in
if (empty($session->get('username'))) {
$messages->error('You are not logged in');
$redirect->url('/novaconium/login');
makeitso();
}
// Get page ID from router parameters
$pageid = $router->parameters['id'] ?? null;
if (!empty($pageid)) {
// Existing page: fetch from database
$query = <<<EOSQL
SELECT
id,
title,
heading,
description,
keywords,
author,
slug,
path,
intro,
body,
notes,
draft,
changefreq,
priority,
created,
updated
FROM pages
WHERE id = ?
EOSQL;
$data['rows'] = $db->getRow($query, [$pageid]);
// If no row is found, treat as new page
if (!$data['rows']) {
$pageid = null;
}
}
if (empty($pageid)) {
// New page: set default values for all fields
$data['rows'] = [
'id' => '',
'title' => '',
'heading' => '',
'description' => '',
'keywords' => '',
'author' => $session->get('username') ?? '',
'slug' => '',
'path' => '',
'intro' => '',
'body' => '',
'notes' => '',
'draft' => 0,
'changefreq' => 'monthly',
'priority' => 0.0,
'created' => date('Y-m-d H:i:s'),
'updated' => date('Y-m-d H:i:s')
];
}
// Render the edit page view
view('@novacore/editpage', $data);