You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.6 KiB
PHTML

<?php
/**
* Returns messages from session and removes them from the stack
*
* @return string
*/
8 years ago
function msg()
{
$session = session();
$message = $session->get('msg', '');
$session->set('msg', '');
return $message;
}
/**
* Renders an information message
*
* @param string $msg
* @param bool $immediately
* @return string
*/
function info($msg, $immediately = false)
8 years ago
{
return alert('info', $msg, $immediately);
}
/**
* Renders a warning message
*
* @param string $msg
* @param bool $immediately
* @return string
*/
function warning($msg, $immediately = false)
{
return alert('warning', $msg, $immediately);
}
/**
* Renders an error message
*
* @param string $msg
* @param bool $immediately
* @return string
*/
function error($msg, $immediately = false)
8 years ago
{
return alert('danger', $msg, $immediately);
}
/**
* Renders a success message
*
* @param string $msg
* @param bool $immediately
* @return string
*/
function success($msg, $immediately = false)
8 years ago
{
return alert('success', $msg, $immediately);
}
/**
* Renders an alert message with the given alert-* class.
*
* @param string $class
* @param string $msg
* @param bool $immediately
* @return string
*/
function alert($class, $msg, $immediately = false)
8 years ago
{
if (empty($msg)) {
return '';
}
if ($immediately) {
8 years ago
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
}
8 years ago
$session = session();
$message = $session->get('msg', '');
$message .= alert($class, $msg, true);
$session->set('msg', $message);
return '';
}