*/ /* * Require files and ensure environment. */ require_once __DIR__ . "/inc/functions.php"; ensureEnvironment(); // Ensure existence of system files. $translations = loadLanguage($settings['defaultLang']); // Load translations. ensureBackendEnv(); // Ensure session is started etc. $pages = loadPages(); // Load overview of pages. /* * Load contents */ // Check for vars. loadHttpToGlobals(["id", "task", "title", "content", "higher", "public"]); if (isset($task) and !isset($public)) $public = false; // Load from ID if (isset($id) and is_numeric($id) and $id) { $existent = json_decode(file_get_contents(__DIR__ . "/../data/static/$id.json"), true); foreach (["title", "content", "higher", "public"] as $var) { if (!isset($$var) and isset($existent[$var])) $$var = $existent[$var]; } } // Set page title if (!isset($id)) $pageTitle = $translations['newPage']; else $pageTitle = $translations['edit'] . ': ' . $title; /* * Store if need be */ if (isset($task)) { if ($task == "update") { if (!isset($title)) $title = ""; if (!isset($content)) $content = ""; if (!isset($higher) or !is_numeric($higher)) $higher = "0"; if (!isset($id)) $id = "0"; $targetID = storePage($pages, ["title" => (string)$title, "content" => (string)$content, "higher" => $higher, "public" => (bool)$public], (int)$id); $_SESSION["editHistory"] = ["changesStored", $translations['storedEditsToPage'] . " $title"]; header('Location: page.php?id=' . $targetID); return; } else if ($task == "delete") { if (!isset($id)) { echo printErrorPage($settings, $translations['specifyToDelete']); return; } unlink(__DIR__ . "/../data/static/$id.json"); generateStaticPgCaches(); $_SESSION["editHistory"] = ["changesAborted", $translations['deletedPage'] . " $title"]; header('Location: pages.php'); return; } } /* * Output */ if (!isset($public)) $public = false; echo printBackendHead($settings, $pageTitle, $pageTitle, $settings['logo']); echo printBackendHeader($pageTitle, $translations['helpSinglePage']); echo '
'; echo printBackendNav($translations); echo '
'; echo printBackendEnd(); ?>