1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
/**
* Returns messages from session and removes them from the stack
*
* @return string
*/
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)
{
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)
{
return alert('danger', $msg, $immediately);
}
/**
* Renders a success message
*
* @param string $msg
* @param bool $immediately
* @return string
*/
function success($msg, $immediately = false)
{
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)
{
$session = session();
if (empty($msg)) {
return '';
}
if ($immediately) {
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
}
$message = $session->get('msg', '');
$message .= alert($class, $msg, true);
$session->set('msg', $message);
return '';
}
|