From eb1fa7598eab3cc67138fc59cc5dbfad3dd9a066 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 19 Jun 2013 02:28:10 +0200 Subject: [PATCH] Add error and notice flashing --- public_html/includes/base.php | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/public_html/includes/base.php b/public_html/includes/base.php index fa9bec3..7d9b596 100644 --- a/public_html/includes/base.php +++ b/public_html/includes/base.php @@ -19,3 +19,57 @@ require("cphp/base.php"); require("lib/Markdown.php"); require("lib/MarkdownExtra.php"); + +NewTemplater::RegisterVariableHook("errors", "get_errors"); +NewTemplater::RegisterVariableHook("notices", "get_notices"); + +function get_errors($fetch) +{ + if(isset($_SESSION['errors'])) + { + $errors = $_SESSION['errors']; + + if($fetch === true) + { + /* We only want to clear out errors if a call to + * actually retrieve the errors was made, not just + * something like an isempty. */ + $_SESSION['errors'] = array(); + } + + return $errors; + } + else + { + return array(); + } +} + +function get_notices($fetch) +{ + if(isset($_SESSION['notices'])) + { + $notices = $_SESSION['notices']; + + if($fetch === true) + { + $_SESSION['notices'] = array(); + } + + return $notices; + } + else + { + return array(); + } +} + +function flash_error($message) +{ + $_SESSION['errors'][] = $message; +} + +function flash_notice($message) +{ + $_SESSION['notices'][] = $message; +}