Edit Page fixes

This commit is contained in:
Nick Yeoman 2025-11-08 10:28:13 -08:00
parent a459b86169
commit 869c3a8d6a
4 changed files with 147 additions and 51 deletions

View File

@ -50,7 +50,7 @@ EOSQL;
if (empty($pageid)) { if (empty($pageid)) {
// New page: set default values for all fields // New page: set default values for all fields
$data['rows'] = [ $data['rows'] = [
'id' => '', 'id' => 'newpage',
'title' => '', 'title' => '',
'heading' => '', 'heading' => '',
'description' => '', 'description' => '',

View File

@ -43,21 +43,7 @@ if (empty($title) || empty($slug) || empty($body)) {
} }
try { try {
if (!empty($id)) { if ($id == 'newpage') {
// Update existing page
$query = "UPDATE `pages` SET
`title` = ?, `heading` = ?, `description` = ?, `keywords` = ?, `author` = ?,
`slug` = ?, `path` = ?, `intro` = ?, `body` = ?, `notes` = ?,
`draft` = ?, `changefreq` = ?, `priority` = ?, `updated` = NOW()
WHERE `id` = ?";
$params = [
$title, $heading, $description, $keywords, $author,
$slug, $path, $intro, $body, $notes,
$draft, $changefreq, $priority, $id
];
$db->query($query, $params);
$messages->notice('Page Updated');
} else {
// Create new page // Create new page
$query = "INSERT INTO `pages` $query = "INSERT INTO `pages`
(`title`, `heading`, `description`, `keywords`, `author`, (`title`, `heading`, `description`, `keywords`, `author`,
@ -72,7 +58,26 @@ try {
$db->query($query, $params); $db->query($query, $params);
$id = $db->lastid; // Get new page ID $id = $db->lastid; // Get new page ID
$messages->notice('Page Created'); $messages->notice('Page Created');
$newpage = true;
} else {
$newpage = false;
} }
if (!empty($id) && !$newpage) {
// Update existing page
$query = "UPDATE `pages` SET
`title` = ?, `heading` = ?, `description` = ?, `keywords` = ?, `author` = ?,
`slug` = ?, `path` = ?, `intro` = ?, `body` = ?, `notes` = ?,
`draft` = ?, `changefreq` = ?, `priority` = ?, `updated` = NOW()
WHERE `id` = ?";
$params = [
$title, $heading, $description, $keywords, $author,
$slug, $path, $intro, $body, $notes,
$draft, $changefreq, $priority, $id
];
$db->query($query, $params);
$messages->notice('Page Updated');
}
} catch (Exception $e) { } catch (Exception $e) {
$messages->error($e->getMessage()); $messages->error($e->getMessage());
$redirect->url($url_error); $redirect->url($url_error);

View File

@ -112,3 +112,63 @@ div#debug {
.pages-table th { .pages-table th {
font-weight: bold; font-weight: bold;
} }
/* ============================================================
DARK MODE STYLES edit-page-form-novaconium
============================================================ */
@media (prefers-color-scheme: dark) {
#edit-page-form-novaconium input[type="text"],
#edit-page-form-novaconium input[type="number"],
#edit-page-form-novaconium textarea,
#edit-page-form-novaconium select {
background: #2a2a2a;
border: 1px solid #444;
color: #eee;
}
#edit-page-form-novaconium input:focus,
#edit-page-form-novaconium textarea:focus,
#edit-page-form-novaconium select:focus {
border-color: #3399ff;
box-shadow: 0 0 0 3px rgba(51, 153, 255, 0.25);
}
#edit-page-form-novaconium input[type="checkbox"] {
accent-color: #3399ff;
}
#edit-page-form-novaconium button[type="submit"] {
background: #3399ff;
color: #fff;
}
#edit-page-form-novaconium button[type="submit"]:hover {
background: #1d7fd4;
}
#edit-page-form-novaconium p {
color: #aaa;
}
#edit-page-form-novaconium a {
color: #66b3ff;
}
#edit-page-form-novaconium a:hover {
color: #99ccff;
}
#edit-page-form-novaconium .form-group {
margin-bottom: 1.2rem;
}
#edit-page-form-novaconium .form-group.fullwidth textarea {
width: 100%;
resize: vertical;
}
#edit-page-form-novaconium .checkbox-group {
margin-top: 1.5rem;
}
}

View File

@ -3,59 +3,90 @@
{% block content %} {% block content %}
<h2>Edit Page - {{ title }}</h2> <h2>Edit Page - {{ title }}</h2>
<form method="post" action="/novaconium/savePage"> <form method="post" action="/novaconium/savePage" id="edit-page-form-novaconium">
<input type="hidden" name="id" value="{{ rows.id }}"> <input type="hidden" name="id" value="{{ rows.id }}">
<input type="hidden" name="token" value="{{ token }}"> <input type="hidden" name="token" value="{{ token }}">
<label for="title">Title:</label> <div class="form-group">
<input type="text" id="title" name="title" value="{{ rows.title }}" required> <label for="title">Title:</label>
<input type="text" id="title" name="title" value="{{ rows.title }}" required>
</div>
<label for="heading">Heading:</label> <div class="form-group">
<input type="text" id="heading" name="heading" value="{{ rows.heading }}"> <label for="slug">
Slug: (<a href="/page/{{ rows.slug }}" target="_new">/page/{{ rows.slug }}</a>)
</label>
<input type="text" id="slug" name="slug" value="{{ rows.slug }}" required>
</div>
<label for="description">Description:</label> <div class="form-group fullwidth">
<input type="text" id="description" name="description" value="{{ rows.description }}"> <label for="body">Body:</label>
<textarea id="body" name="body" rows="10">{{ rows.body }}</textarea>
</div>
<h2>Metadata</h2>
<label for="keywords">Keywords:</label> <div class="form-group">
<input type="text" id="keywords" name="keywords" value="{{ rows.keywords }}"> <label for="description">Description:</label>
<input type="text" id="description" name="description" value="{{ rows.description }}">
</div>
<label for="author">Author:</label> <div class="form-group">
<input type="text" id="author" name="author" value="{{ rows.author }}"> <label for="keywords">Keywords:</label>
<input type="text" id="keywords" name="keywords" value="{{ rows.keywords }}">
</div>
<label for="slug">Slug: (<a href="/page/{{ rows.slug }}" target="_new">/page/{{ rows.slug }}</a>)</label> <div class="form-group">
<input type="text" id="slug" name="slug" value="{{ rows.slug }}" required> <label for="author">Author:</label>
<input type="text" id="author" name="author" value="{{ rows.author }}">
</div>
<label for="path">Path:</label> <h2>CMS Info</h2>
<input type="text" id="path" name="path" value="{{ rows.path }}">
<div class="form-group">
<label for="path">Path:</label>
<input type="text" id="path" name="path" value="{{ rows.path }}">
</div>
<label for="intro">Intro:</label> <div class="form-group">
<textarea id="intro" name="intro" rows="5">{{ rows.intro }}</textarea> <label for="changefreq">Change Frequency:</label>
<select id="changefreq" name="changefreq">
{% set freqs = ['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'] %}
{% for freq in freqs %}
<option value="{{ freq }}" {% if rows.changefreq == freq %}selected{% endif %}>
{{ freq|capitalize }}
</option>
{% endfor %}
</select>
</div>
<label for="body">Body:</label> <div class="form-group">
<textarea id="body" name="body" rows="10">{{ rows.body }}</textarea> <label for="priority">Priority (0.0 - 1.0):</label>
<input type="number" id="priority" name="priority" value="{{ rows.priority }}" step="0.1" min="0" max="1">
</div>
<label for="notes">Notes:</label> <div class="form-group fullwidth">
<textarea id="notes" name="notes" rows="5">{{ rows.notes }}</textarea> <label for="notes">Notes:</label>
<textarea id="notes" name="notes" rows="5">{{ rows.notes }}</textarea>
</div>
<label for="draft"> <h2>Page Data</h2>
<input type="checkbox" id="draft" name="draft" value="1" {% if rows.draft %}checked{% endif %}> <div class="form-group">
Save as Draft <label for="heading">Heading:</label>
</label> <input type="text" id="heading" name="heading" value="{{ rows.heading }}">
</div>
<label for="changefreq">Change Frequency:</label> <div class="form-group fullwidth">
<select id="changefreq" name="changefreq"> <label for="intro">Intro:</label>
{% set freqs = ['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'] %} <textarea id="intro" name="intro" rows="5">{{ rows.intro }}</textarea>
{% for freq in freqs %} </div>
<option value="{{ freq }}" {% if rows.changefreq == freq %}selected{% endif %}>{{ freq|capitalize }}</option>
{% endfor %}
</select>
<label for="priority">Priority (0.0 - 1.0):</label>
<input type="number" id="priority" name="priority" value="{{ rows.priority }}" step="0.1" min="0" max="1">
<p><strong>Created:</strong> {{ rows.created|date("Y-m-d H:i:s") }}</p> <p><strong>Created:</strong> {{ rows.created|date("Y-m-d H:i:s") }}</p>
<p><strong>Last Updated:</strong> {{ rows.updated|date("Y-m-d H:i:s") }}</p> <p><strong>Last Updated:</strong> {{ rows.updated|date("Y-m-d H:i:s") }}</p>
<button type="submit">Save Changes</button> <button type="submit">Save Changes</button>
</form> </form>
{% endblock %} {% endblock %}