2013-09-18 01:38:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Returns messages from session and removes them from the stack
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function msg()
|
|
|
|
{
|
2017-08-30 19:57:01 +02:00
|
|
|
$session = session();
|
|
|
|
|
|
|
|
$message = $session->get('msg', '');
|
|
|
|
$session->set('msg', '');
|
|
|
|
|
|
|
|
return $message;
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Renders an information message
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
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);
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* 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
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
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);
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Renders a success message
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
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);
|
2016-09-29 09:49:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Renders an alert message with the given alert-* class.
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
2017-08-31 12:25:06 +02:00
|
|
|
* @return string
|
2016-09-29 09:49:25 +02:00
|
|
|
*/
|
2017-01-03 03:22:48 +01:00
|
|
|
function alert($class, $msg, $immediately = false)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-08-30 19:57:01 +02:00
|
|
|
$session = session();
|
|
|
|
|
2017-08-31 12:25:06 +02:00
|
|
|
if (empty($msg)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
if ($immediately) {
|
2017-01-02 03:57:23 +01:00
|
|
|
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
|
2016-09-29 09:49:25 +02:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-08-30 19:57:01 +02:00
|
|
|
$message = $session->get('msg', '');
|
|
|
|
$message .= alert($class, $msg, true);
|
|
|
|
$session->set('msg', $message);
|
2017-01-03 03:22:48 +01:00
|
|
|
|
2017-08-31 12:25:06 +02:00
|
|
|
return '';
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|