2021-03-25 00:59:28 +01:00
|
|
|
<?php
|
2021-03-27 04:24:16 +01:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use Slim\Views\Twig;
|
|
|
|
|
2021-03-29 00:22:00 +02:00
|
|
|
include "../brain/data/Book.inc.php";
|
2021-03-25 00:59:28 +01:00
|
|
|
|
|
|
|
class DashControl
|
|
|
|
{
|
2021-03-27 04:24:16 +01:00
|
|
|
public static function start(
|
|
|
|
ServerRequestInterface $request,
|
|
|
|
ResponseInterface $response,
|
|
|
|
array $args
|
|
|
|
): ResponseInterface {
|
|
|
|
$view = Twig::fromRequest($request);
|
|
|
|
$pageOptions = [];
|
2021-04-07 23:09:40 +02:00
|
|
|
$template = "";
|
2021-03-27 04:24:16 +01:00
|
|
|
switch (isset($args["second"]) ? $args["second"] : "index") {
|
2021-03-25 00:59:28 +01:00
|
|
|
case "pages":
|
2021-04-14 21:01:49 +02:00
|
|
|
if (Session::active()) {
|
|
|
|
$currentPage = isset($args["fourth"]) ? $args["fourth"] : 1;
|
|
|
|
$filter = isset($args["third"]) ? $args["third"] : "all";
|
|
|
|
$data = (new Book("../content/pages"))->getPages(
|
|
|
|
$currentPage,
|
|
|
|
4,
|
|
|
|
$filter
|
|
|
|
);
|
|
|
|
$template = "dash/book.twig";
|
|
|
|
$pageOptions = [
|
|
|
|
"entryCount" => $data["entryCount"],
|
|
|
|
"numOfPages" => $data["numOfPages"],
|
|
|
|
"currentPage" => $currentPage,
|
|
|
|
"filter" => $data["paginate"]["sort"],
|
|
|
|
"stats" => $data["stats"],
|
|
|
|
"pages" => $data["pages"],
|
|
|
|
"paginate" => $data["paginate"],
|
|
|
|
"status" => Session::active(),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
|
|
|
}
|
2021-03-25 00:59:28 +01:00
|
|
|
break;
|
2021-04-10 22:19:05 +02:00
|
|
|
case "page":
|
|
|
|
if (Session::active()) {
|
|
|
|
$template = "dash/page-edit.twig";
|
|
|
|
$mode = $args["third"];
|
|
|
|
if ($mode == "edit") {
|
|
|
|
$uuid = $args["fourth"];
|
|
|
|
|
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Fipamo | Edit Page",
|
|
|
|
"page" => (new Book("../content/pages"))->findPageById($uuid),
|
|
|
|
"mode" => $mode,
|
2021-04-10 22:44:43 +02:00
|
|
|
"status" => Session::active(),
|
2021-04-10 22:19:05 +02:00
|
|
|
];
|
|
|
|
} else {
|
2021-04-14 21:01:49 +02:00
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
2021-04-10 22:19:05 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$template = "dash/start.twig";
|
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Welcome to Fipamo",
|
|
|
|
"status" => Session::active(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "logout":
|
|
|
|
Session::kill();
|
|
|
|
header("Location: /dashboard");
|
|
|
|
die();
|
|
|
|
break;
|
2021-03-25 00:59:28 +01:00
|
|
|
default:
|
2021-04-07 23:09:40 +02:00
|
|
|
$template = "dash/start.twig";
|
2021-04-02 02:37:12 +02:00
|
|
|
if (Session::active()) {
|
|
|
|
$pageOptions = [
|
2021-04-10 22:19:05 +02:00
|
|
|
"title" => "Welcome Back",
|
2021-04-02 02:37:12 +02:00
|
|
|
"status" => Session::active(),
|
|
|
|
"data" => (new Book("../content/pages"))->getPages(1, 4),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$pageOptions = [
|
|
|
|
"title" => "Welcome to Fipamo",
|
|
|
|
"status" => Session::active(),
|
|
|
|
];
|
|
|
|
}
|
2021-03-25 00:59:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-04-07 23:09:40 +02:00
|
|
|
return $view->render($response, $template, $pageOptions);
|
2021-03-25 00:59:28 +01:00
|
|
|
}
|
|
|
|
}
|