2
0
forked from Wavyzz/dolibarr

NeW Can add the info messages (error, waring...) at the top of the stack

This commit is contained in:
Laurent Destailleur
2024-09-30 14:30:28 +02:00
parent 182c90da69
commit 6f7b0c1815
3 changed files with 22 additions and 12 deletions

View File

@@ -9832,10 +9832,11 @@ function dolGetFirstLastname($firstname, $lastname, $nameorder = -1)
* @param string|string[] $mesgs Message string or array
* @param string $style Which style to use ('mesgs' by default, 'warnings', 'errors')
* @param int $noduplicate 1 means we do not add the message if already present in session stack
* @param int $attop Add the message in the top of the stack (at bottom by default)
* @return void
* @see dol_htmloutput_events()
*/
function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0)
function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0, $attop = 0)
{
//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING); This is not deprecated, it is used by setEventMessages function
if (!is_array($mesgs)) {
@@ -9845,7 +9846,11 @@ function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0)
if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesgs, $_SESSION['dol_events'][$style])) {
return;
}
$_SESSION['dol_events'][$style][] = $mesgs;
if ($attop) {
array_unshift($_SESSION['dol_events'][$style], $mesgs);
} else {
$_SESSION['dol_events'][$style][] = $mesgs;
}
}
} else {
// If mesgs is an array
@@ -9855,7 +9860,11 @@ function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0)
if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesg, $_SESSION['dol_events'][$style])) {
return;
}
$_SESSION['dol_events'][$style][] = $mesg;
if ($attop) {
array_unshift($_SESSION['dol_events'][$style], $mesgs);
} else {
$_SESSION['dol_events'][$style][] = $mesg;
}
}
}
}
@@ -9870,10 +9879,11 @@ function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0)
* @param string $style Which style to use ('mesgs' by default, 'warnings', 'errors')
* @param string $messagekey A key to be used to allow the feature "Never show this message during this session again"
* @param int $noduplicate 1 means we do not add the message if already present in session stack
* @param int $attop Add the message in the top of the stack (at bottom by default)
* @return void
* @see dol_htmloutput_events()
*/
function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $noduplicate = 0)
function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $noduplicate = 0, $attop = 0)
{
if (empty($mesg) && empty($mesgs)) {
dol_syslog("Try to add a message in stack, but value to add is empty message", LOG_WARNING);
@@ -9883,17 +9893,17 @@ function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $no
// TODO
$mesg .= '';
}
if (empty($messagekey) || empty($_COOKIE["DOLHIDEMESSAGE".$messagekey])) {
if (empty($messagekey) || empty($_COOKIE["DOLUSER_HIDEMESSAGE".$messagekey])) {
if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) {
dol_print_error(null, 'Bad parameter style='.$style.' for setEventMessages');
}
if (empty($mesgs)) {
setEventMessage($mesg, $style, $noduplicate);
setEventMessage($mesg, $style, $noduplicate, $attop);
} else {
if (!empty($mesg) && !in_array($mesg, $mesgs)) {
setEventMessage($mesg, $style, $noduplicate); // Add message string if not already into array
setEventMessage($mesg, $style, $noduplicate, $attop); // Add message string if not already into array
}
setEventMessage($mesgs, $style, $noduplicate);
setEventMessage($mesgs, $style, $noduplicate, $attop);
}
}
}