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

@@ -350,8 +350,6 @@ if ($mode == 'desc') {
$text .= '<br><span class="opacitymedium">'.$langs->trans("IdModule").':</span> '.$objMod->numero; $text .= '<br><span class="opacitymedium">'.$langs->trans("IdModule").':</span> '.$objMod->numero;
$text .= '<br><span class="opacitymedium">'.$langs->trans("Version").':</span> '.$version;
$textexternal = ''; $textexternal = '';
if ($objMod->isCoreOrExternalModule() == 'external') { if ($objMod->isCoreOrExternalModule() == 'external') {
$tmpdirofmoduletoshow = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', (string) $dirofmodule); $tmpdirofmoduletoshow = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', (string) $dirofmodule);
@@ -381,8 +379,10 @@ if ($mode == 'desc') {
} elseif (!empty($objMod->enabled_bydefault)) { } elseif (!empty($objMod->enabled_bydefault)) {
$text .= ' &nbsp; <span class="italic opacitymedium">('.$langs->trans("EnabledByDefaultAtInstall").')</span>'; $text .= ' &nbsp; <span class="italic opacitymedium">('.$langs->trans("EnabledByDefaultAtInstall").')</span>';
} }
$text .= '<br>';
} }
$text .= '<br><span class="opacitymedium">'.$langs->trans("Version").':</span> '.$version;
$text .= '<br>'; $text .= '<br>';
$moduledesclong = $objMod->getDescLong(); $moduledesclong = $objMod->getDescLong();

View File

@@ -1113,7 +1113,7 @@ if ($mode == 'common' || $mode == 'commonkanban') {
if ($action == 'checklastversion') { if ($action == 'checklastversion') {
if ($foundoneexternalmodulewithupdate) { if ($foundoneexternalmodulewithupdate) {
setEventMessages($langs->trans("ModuleUpdateAvailable"), null, 'warnings'); setEventMessages($langs->trans("ModuleUpdateAvailable"), null, 'warnings', '', 0, 1);
} else { } else {
setEventMessages($langs->trans("NoExternalModuleWithUpdate"), null, 'mesgs'); setEventMessages($langs->trans("NoExternalModuleWithUpdate"), null, 'mesgs');
} }

View File

@@ -9832,10 +9832,11 @@ function dolGetFirstLastname($firstname, $lastname, $nameorder = -1)
* @param string|string[] $mesgs Message string or array * @param string|string[] $mesgs Message string or array
* @param string $style Which style to use ('mesgs' by default, 'warnings', 'errors') * @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 $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 * @return void
* @see dol_htmloutput_events() * @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 //dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING); This is not deprecated, it is used by setEventMessages function
if (!is_array($mesgs)) { if (!is_array($mesgs)) {
@@ -9845,8 +9846,12 @@ function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0)
if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesgs, $_SESSION['dol_events'][$style])) { if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesgs, $_SESSION['dol_events'][$style])) {
return; return;
} }
if ($attop) {
array_unshift($_SESSION['dol_events'][$style], $mesgs);
} else {
$_SESSION['dol_events'][$style][] = $mesgs; $_SESSION['dol_events'][$style][] = $mesgs;
} }
}
} else { } else {
// If mesgs is an array // If mesgs is an array
foreach ($mesgs as $mesg) { foreach ($mesgs as $mesg) {
@@ -9855,11 +9860,15 @@ function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0)
if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesg, $_SESSION['dol_events'][$style])) { if (!empty($noduplicate) && isset($_SESSION['dol_events'][$style]) && in_array($mesg, $_SESSION['dol_events'][$style])) {
return; return;
} }
if ($attop) {
array_unshift($_SESSION['dol_events'][$style], $mesgs);
} else {
$_SESSION['dol_events'][$style][] = $mesg; $_SESSION['dol_events'][$style][] = $mesg;
} }
} }
} }
} }
}
/** /**
* Set event messages in dol_events session object. Will be output by calling dol_htmloutput_events. * Set event messages in dol_events session object. Will be output by calling dol_htmloutput_events.
@@ -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 $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 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 $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 * @return void
* @see dol_htmloutput_events() * @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)) { if (empty($mesg) && empty($mesgs)) {
dol_syslog("Try to add a message in stack, but value to add is empty message", LOG_WARNING); 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 // TODO
$mesg .= ''; $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'))) { if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) {
dol_print_error(null, 'Bad parameter style='.$style.' for setEventMessages'); dol_print_error(null, 'Bad parameter style='.$style.' for setEventMessages');
} }
if (empty($mesgs)) { if (empty($mesgs)) {
setEventMessage($mesg, $style, $noduplicate); setEventMessage($mesg, $style, $noduplicate, $attop);
} else { } else {
if (!empty($mesg) && !in_array($mesg, $mesgs)) { 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);
} }
} }
} }