diff --git a/htdocs/adherents/document.php b/htdocs/adherents/document.php
index bf4d9085349..8904c9b77c9 100644
--- a/htdocs/adherents/document.php
+++ b/htdocs/adherents/document.php
@@ -113,7 +113,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
$langs->load("other");
$file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file);
- $_SESSION['dol_events']['mesgs'] = '
'.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php
index 4c97bcefd58..a4bfa25786e 100644
--- a/htdocs/comm/addpropal.php
+++ b/htdocs/comm/addpropal.php
@@ -343,9 +343,7 @@ if ($action == 'create')
print "";
}
-dol_htmloutput_events($mesgs,$errors,$warnings);
llxFooter();
-
$db->close();
?>
diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index af88f6fdde8..596e18b9032 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -554,9 +554,7 @@ if ($action == 'confirm_valid' && $confirm == 'yes')
if ($object->id > 0)
{
$object->valid($user);
-
- $_SESSION['dol_events']['mesgs']=''.$langs->trans("MailingSuccessfullyValidated").'
';
-
+ setEventMessage($langs->trans("MailingSuccessfullyValidated"));
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 327fb087794..2f636d47475 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -281,8 +281,7 @@ else if ($action == 'add' && $user->rights->propale->creer)
if (empty($datep))
{
- $errors[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date"));
- $_SESSION['dol_events']['errors']=$errors;
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create');
exit;
}
diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php
index 75546f01fb1..406453a432b 100644
--- a/htdocs/comm/propal/document.php
+++ b/htdocs/comm/propal/document.php
@@ -125,7 +125,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
$upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
@@ -147,7 +147,6 @@ if ($object->id > 0)
$head = propal_prepare_head($object);
dol_fiche_head($head, 'document', $langs->trans('Proposal'), 0, 'propal');
-
// Construit liste des fichiers
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$totalsize=0;
diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php
index 509990efb80..39f83d3f6b9 100644
--- a/htdocs/commande/document.php
+++ b/htdocs/commande/document.php
@@ -122,7 +122,7 @@ else if ($action == 'confirm_deletefile' && $confirm == 'yes')
$upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 87e313237f7..18327d85e4b 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1444,8 +1444,6 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$result=$mailfile->sendfile();
if ($result)
{
- $mesgs[]=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
-
$error=0;
// Initialisation donnees
@@ -1471,7 +1469,8 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
{
// Redirect here
// This avoid sending mail twice if going out and then back to page
- $_SESSION['dol_events']['mesgs'] = $mesgs;
+ $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
+ setEventMessage($mesg);
Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id);
exit;
}
diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php
index 47314839959..358fd3477bc 100644
--- a/htdocs/compta/facture/document.php
+++ b/htdocs/compta/facture/document.php
@@ -125,7 +125,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
$upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php
index 1f5fb6859f6..fdcf3e77922 100644
--- a/htdocs/contrat/document.php
+++ b/htdocs/contrat/document.php
@@ -122,7 +122,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$ret=dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index a49a1637c34..36350e1fb4c 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -3448,52 +3448,43 @@ function get_date_range($date_start,$date_end,$format = '',$outputlangs='')
return $out;
}
+/**
+ * Set event message in dol_events session
+ *
+ * @param string $mesgstring Message
+ * @param string $style Which style to use ('mesgs', 'warnings', 'errors')
+ * @return void
+ * @see dol_htmloutput_events
+ */
+function setEventMessage($mesgstring, $style='mesgs')
+{
+ $_SESSION['dol_events'][$style][] = $mesgstring;
+}
+
/**
* Print formated messages to output (Used to show messages on html output).
*
- * @param array $mesgs Messages array
- * @param array $errors Errors array
- * @param array $warnings Warnings array
* @return void
- *
* @see dol_htmloutput_mesg
*/
-function dol_htmloutput_events($mesgs=array(),$errors=array(),$warnings=array())
+function dol_htmloutput_events()
{
// Show mesgs
- if (is_array($mesgs) && ! empty($mesgs)) {
- if (isset($_SESSION['dol_events']['mesgs'])) {
- if (! is_array($_SESSION['dol_events']['mesgs'])) {
- $_SESSION['dol_events']['mesgs']=array($_SESSION['dol_events']['mesgs']); // For backward compatibility
- }
- $mesgs = array_merge($mesgs, $_SESSION['dol_events']['mesgs']);
- unset($_SESSION['dol_events']['mesgs']);
- }
- dol_htmloutput_mesg('',$mesgs);
+ if (isset($_SESSION['dol_events']['mesgs'])) {
+ dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
+ unset($_SESSION['dol_events']['mesgs']);
}
// Show errors
- if (is_array($errors) && ! empty($errors)) {
- if (isset($_SESSION['dol_events']['errors'])) {
- if (! is_array($_SESSION['dol_events']['errors'])) {
- $_SESSION['dol_events']['errors']=array($_SESSION['dol_events']['errors']); // For backward compatibility
- }
- $errors = array_merge($errors, $_SESSION['dol_events']['errors']);
- unset($_SESSION['dol_events']['errors']);
- }
- dol_htmloutput_mesg('',$errors, 'error');
+ if (isset($_SESSION['dol_events']['errors'])) {
+ dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
+ unset($_SESSION['dol_events']['errors']);
}
// Show warnings
- if (is_array($warnings) && ! empty($warnings)) {
- if (isset($_SESSION['dol_events']['warnings'])) {
- if (! is_array($_SESSION['dol_events']['warnings'])) {
- $_SESSION['dol_events']['warnings']=array($_SESSION['dol_events']['warnings']); // For backward compatibility
- }
- $warnings = array_merge($warnings, $_SESSION['dol_events']['warnings']);
- unset($_SESSION['dol_events']['warnings']);
- }
- dol_htmloutput_mesg('',$warnings, 'warning');
+ if (isset($_SESSION['dol_events']['warnings'])) {
+ dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
+ unset($_SESSION['dol_events']['warnings']);
}
}
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 97a1a923fe4..d57bc9823eb 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -437,8 +437,6 @@ if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile'
$result=$mailfile->sendfile();
if ($result)
{
- $_SESSION['dol_events']['mesgs']=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
-
$error=0;
// Initialisation donnees
@@ -466,6 +464,8 @@ if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile'
{
// Redirect here
// This avoid sending mail twice if going out and then back to page
+ $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
+ setEventMessage($mesg);
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
diff --git a/htdocs/fichinter/document.php b/htdocs/fichinter/document.php
index e928eb91233..5364fb1f0e2 100644
--- a/htdocs/fichinter/document.php
+++ b/htdocs/fichinter/document.php
@@ -121,7 +121,7 @@ else if ($action == 'confirm_deletefile' && $confirm == 'yes')
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
diff --git a/htdocs/fourn/commande/document.php b/htdocs/fourn/commande/document.php
index 76363f33f61..1c087f956ac 100644
--- a/htdocs/fourn/commande/document.php
+++ b/htdocs/fourn/commande/document.php
@@ -122,7 +122,7 @@ else if ($action == 'confirm_deletefile' && $confirm == 'yes')
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index 420055a89a7..ecc7f13edf9 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -722,24 +722,9 @@ $bcdd=array(0=>'class="impair drag drop"',1=>'class="pair drag drop"');
$bcnd=array(0=>'class="impair nodrag nodrop"',1=>'class="pair nodrag nodrop"');
// Define messages variables
-$mesg=''; $mesgs=array(); $warning=''; $warnings=array(); $error=0; $errors=array();
-
-// TODO For backward compatibility, see dol_htmloutput_events() in functions.lib.php
-if (isset($_SESSION['dol_events']))
-{
- if (is_array($mesgs) && isset($_SESSION['dol_events']['mesgs'])) {
- $mesgs = array_merge($mesgs, $_SESSION['dol_events']['mesgs']);
- }
- if (is_array($errors) && isset($_SESSION['dol_events']['errors'])) {
- $errors = array_merge($errors, $_SESSION['dol_events']['errors']);
- $mesgs = array_merge($mesgs, $_SESSION['dol_events']['errors']); // For backward compatibility
- }
- if (is_array($warnings) && isset($_SESSION['dol_events']['warnings'])) {
- $warnings = array_merge($warnings, $_SESSION['dol_events']['warnings']);
- }
-
- unset($_SESSION['dol_events']);
-}
+$mesg=''; $warning=''; $error=0;
+// deprecated, see setEventMessage() and dol_htmloutput_events()
+$mesgs=array(); $warnings=array(); $errors=array();
// Constants used to defined number of lines in textarea
if (empty($conf->browser->firefox))
@@ -1670,6 +1655,9 @@ if (! function_exists("llxFooter"))
{
global $conf, $langs, $dolibarr_auto_user, $micro_start_time;
+ // Global html output events ($mesgs, $errors, $warnings)
+ dol_htmloutput_events();
+
// Core error message
if (defined("MAIN_CORE_ERROR") && constant("MAIN_CORE_ERROR") == 1)
{
diff --git a/htdocs/projet/document.php b/htdocs/projet/document.php
index 81850566fb5..74efec961bd 100644
--- a/htdocs/projet/document.php
+++ b/htdocs/projet/document.php
@@ -115,7 +115,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->projet->s
$upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
diff --git a/htdocs/projet/tasks/document.php b/htdocs/projet/tasks/document.php
index c0b0119f475..8e88ba814c4 100644
--- a/htdocs/projet/tasks/document.php
+++ b/htdocs/projet/tasks/document.php
@@ -112,7 +112,7 @@ if ($action=='delete')
$langs->load("other");
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php
index b9ea0e4150a..cf27d4948a1 100644
--- a/htdocs/societe/document.php
+++ b/htdocs/societe/document.php
@@ -124,7 +124,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
$file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
- $_SESSION['dol_events']['mesgs'] = ''.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'
';
+ setEventMessage($langs->trans("FileWasRemoved",GETPOST('urlfile')));
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}