engelsystem/includes/helper/message_helper.php

78 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/**
* Gibt zwischengespeicherte Fehlermeldungen zurück und löscht den Zwischenspeicher
2017-01-03 03:22:48 +01:00
*
* @return string
*/
2017-01-02 03:57:23 +01:00
function msg()
{
2017-01-02 15:43:36 +01:00
if (!isset($_SESSION['msg'])) {
2017-01-02 03:57:23 +01:00
return "";
}
$msg = $_SESSION['msg'];
$_SESSION['msg'] = "";
return $msg;
}
/**
* Rendert eine Information
2017-01-03 03:22:48 +01:00
*
* @param string $msg
* @param bool $immediately
* @return string
*/
2017-01-03 03:22:48 +01:00
function info($msg, $immediately = false)
2017-01-02 03:57:23 +01:00
{
2017-01-03 03:22:48 +01:00
return alert('info', $msg, $immediately);
}
/**
* Rendert eine Fehlermeldung
2017-01-03 03:22:48 +01:00
*
* @param string $msg
* @param bool $immediately
* @return string
*/
2017-01-03 03:22:48 +01:00
function error($msg, $immediately = false)
2017-01-02 03:57:23 +01:00
{
2017-01-03 03:22:48 +01:00
return alert('danger', $msg, $immediately);
}
/**
* Rendert eine Erfolgsmeldung
2017-01-03 03:22:48 +01:00
*
* @param string $msg
* @param bool $immediately
* @return string
*/
2017-01-03 03:22:48 +01:00
function success($msg, $immediately = false)
2017-01-02 03:57:23 +01:00
{
2017-01-03 03:22:48 +01:00
return alert('success', $msg, $immediately);
}
/**
* Renders an alert with given alert-* class.
2017-01-03 03:22:48 +01:00
*
* @param string $class
* @param string $msg
* @param bool $immediately
* @return string|null
*/
2017-01-03 03:22:48 +01:00
function alert($class, $msg, $immediately = false)
2017-01-02 03:57:23 +01:00
{
2017-01-03 03:22:48 +01:00
if ($immediately) {
2017-01-02 03:57:23 +01:00
if ($msg == "") {
return "";
}
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
}
2017-01-02 15:43:36 +01:00
if (!isset($_SESSION['msg'])) {
2017-01-02 03:57:23 +01:00
$_SESSION['msg'] = "";
}
$_SESSION['msg'] .= alert($class, $msg, true);
2017-01-03 03:22:48 +01:00
return null;
}