Create fn/ directory

This commit is contained in:
Miraty 2022-05-31 19:12:14 +02:00
parent eadc2d44e3
commit fac61531dd
7 changed files with 31 additions and 29 deletions

View File

@ -6,39 +6,17 @@ define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(CONF['common']['p
define("PAGE", basename($_SERVER['PHP_SELF'], '.php'));
define("DB_PATH", CONF['common']['root_path'] . "/db/niver.db"); // Niver's SQLite database
// Service-specific functions and constants
if (SERVICE === "reg" OR SERVICE === "ns")
require CONF['common']['root_path'] . "/dns.php";
if (SERVICE !== "")
require CONF['common']['root_path'] . "/" . SERVICE . ".php";
// Page titles definition
require "pages.php";
require CONF['common']['root_path'] . "/fn/common.php";
// Service-specific functions and constants
if (SERVICE === "reg" OR SERVICE === "ns")
require CONF['common']['root_path'] . "/fn/dns.php";
if (SERVICE !== "")
require CONF['common']['root_path'] . "/fn/" . SERVICE . ".php";
function success($msg) {
echo "<p><strong>Succès</strong> : <em>" . $msg . "</em></p>";
closeHTML();
}
// When the user requests something unexpected
function userError($msg) {
http_response_code(403);
echo "<p><strong>Erreur utilisataire</strong> : <em>" . $msg . "</em></p>";
closeHTML();
}
// When the system did something unexpected
function serverError($msg) {
http_response_code(500);
error_log("Niver internal error: " . strip_tags($msg));
echo "<p><strong>Server error</strong>: The server encountered an error: <em>" . $msg . "</em></p>";
closeHTML();
}
// For use in pages that first display a form and then process it
function switchToFormProcess($requireLogin = true) {
if (empty($_POST))
closeHTML();
if ($requireLogin AND !isset($_SESSION['username']))
userError("Vous devez être connecté·e pour effectuer cette action.");
}

24
fn/common.php Normal file
View File

@ -0,0 +1,24 @@
<?php
// When the user requests something unexpected
function userError($msg) {
http_response_code(403);
echo "<p><strong>Erreur utilisataire</strong> : <em>" . $msg . "</em></p>";
closeHTML();
}
// When the system did something unexpected
function serverError($msg) {
http_response_code(500);
error_log("Niver internal error: " . strip_tags($msg));
echo "<p><strong>Server error</strong>: The server encountered an error: <em>" . $msg . "</em></p>";
closeHTML();
}
// For use in pages that first display a form and then process it
function switchToFormProcess($requireLogin = true) {
if (empty($_POST))
closeHTML();
if ($requireLogin AND !isset($_SESSION['username']))
userError("Vous devez être connecté·e pour effectuer cette action.");
}

View File

View File

View File

View File