104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
<?php
|
|
global $c;
|
|
|
|
UserAuth::requirePermission("admin");
|
|
|
|
$strId = Request::getArg(0);
|
|
$strPath = "";
|
|
$strContent = "";
|
|
|
|
if (strlen($strId) > 0)
|
|
{
|
|
$varRows = $c->query("SELECT * from post where id = ?", $strId);
|
|
|
|
if (count($varRows) !== 1)
|
|
{
|
|
BootstrapRender::message("Zero or more than one row returned", "danger");
|
|
Respond::redirect("/edit");
|
|
}
|
|
|
|
$varRow = $varRows[0];
|
|
$strPath = $varRow["path"];
|
|
$strContent = $varRow["content"];
|
|
}
|
|
|
|
|
|
if (Request::posts("path", "content"))
|
|
{
|
|
$strPath = Request::getPosted("path");
|
|
$strContent = Request::getPosted("content");
|
|
|
|
if ($strId == null || strlen($strId) < 1)
|
|
{
|
|
$c->query(
|
|
"INSERT into post (author, path, content)
|
|
values (?, ?, ?)",
|
|
"caharkness@gmail.com",
|
|
$strPath,
|
|
$strContent);
|
|
|
|
$strId = $c->query("SELECT * from post where rowid = last_insert_rowid()")[0]["id"];
|
|
}
|
|
|
|
if (strlen($strContent) < 1)
|
|
{
|
|
$c->query("DELETE from post where id = ?", $strId);
|
|
BootstrapRender::message("Post deleted successfully.", "success");
|
|
Respond::redirect("/edit");
|
|
}
|
|
|
|
$c->query(
|
|
"UPDATE post
|
|
set
|
|
path = ?,
|
|
content = ?,
|
|
updated = current_timestamp
|
|
where
|
|
id = ?",
|
|
$strPath,
|
|
$strContent,
|
|
$strId);
|
|
|
|
Respond::redirect("/edit/{$strId}");
|
|
}
|
|
?>
|
|
|
|
<style>
|
|
textarea {
|
|
font-family: monospace;
|
|
}
|
|
</style>
|
|
|
|
<div class="container my-5">
|
|
<div class="row">
|
|
<div class="col-lg-6">
|
|
|
|
<div class="mb-3">
|
|
<?php BootstrapRender::message(); ?>
|
|
</div>
|
|
|
|
<form method="post">
|
|
|
|
<?php BootstrapRender::input([
|
|
"name" => "path",
|
|
"label" => "Path",
|
|
"value" => $strPath
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::input([
|
|
"name" => "content",
|
|
"label" => "Content",
|
|
"tag" => "textarea",
|
|
"value" => $strContent
|
|
]); ?>
|
|
|
|
<?php BootstrapRender::buttons([
|
|
"buttons" => [[
|
|
"label" => "Submit",
|
|
"icon" => "save"
|
|
]]
|
|
]); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|