Fix: try to use $mesgs (array) for stock all messages and

$_SESSION['dol_message'] for specific message when a page is reloading
This commit is contained in:
Regis Houssin 2012-07-23 21:31:10 +02:00
parent d5ff308992
commit eba0db736e
4 changed files with 67 additions and 78 deletions

View File

@ -62,7 +62,7 @@ if ($action == 'create')
{
if (! is_array($selected))
{
$mesg='<div class="error">'.$langs->trans('Error_OrderNotChecked').'</div>';
$mesgs[]='<div class="error">'.$langs->trans('Error_OrderNotChecked').'</div>';
}
else
{
@ -80,9 +80,9 @@ $htmlother = new FormOther($db);
/*
* Actions
*/
*/
if (($action == 'create' || $action == 'add') && ! $mesg )
if (($action == 'create' || $action == 'add') && empty($mesgs))
{
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php");
@ -92,8 +92,10 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
require_once(DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php');
require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
if (! empty($conf->projet->enabled)) {
require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
}
$langs->load('bills');
$langs->load('products');
$langs->load('main');
@ -117,7 +119,6 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
$_POST['originid']=$orders_id[0];
}
if (GETPOST('mesg','int',1) && isset($_SESSION['message'])) $mesg=$_SESSION['message'];
$sall=isset($_GET['sall'])?trim($_GET['sall']):trim($_POST['sall']);
$projectid=isset($_GET['projectid'])?$_GET['projectid']:0;
$id =(GETPOST('id')?GETPOST("id"):GETPOST("facid")); // For backward compatibility
@ -242,7 +243,7 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
}
else
{
$mesg=$discount->error;
$mesgs[]=$discount->error;
$error++;
break;
}
@ -310,7 +311,7 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
}
else
{
$mesg=$srcobject->error;
$mesgs[]=$srcobject->error;
$error++;
}
$ii++;
@ -318,7 +319,7 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
}
else
{
$mesg=$object->error;
$mesgs[]=$object->error;
$error++;
}
}
@ -338,7 +339,7 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
$action='create';
$_GET["origin"]=$_POST["origin"];
$_GET["originid"]=$_POST["originid"];
if (! $mesg) $mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
}
}
@ -354,9 +355,10 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
if ($action == 'create')
{
$facturestatic=new Facture($db);
llxHeader();
print_fiche_titre($langs->trans('NewBill'));
dol_htmloutput_mesg($mesg);
$soc = new Societe($db);
if ($socid) $res=$soc->fetch($socid);
if ($res)
@ -474,7 +476,6 @@ if (($action == 'create' || $action == 'add') && ! $mesg )
print "</form>\n";
}
//Mode liste
else
{
@ -669,8 +670,8 @@ else
}
$db->close();
dol_htmloutput_mesg($mesg);
llxFooter();
dol_htmloutput_mesg($mesg,$mesgs);
llxFooter();
$db->close();
?>

View File

@ -54,11 +54,6 @@ $langs->load('main');
if (! empty($conf->margin->enabled))
$langs->load('margins');
$mesg='';
$errors=array();
if (GETPOST('mesg','int',1) && isset($_SESSION['message'])) $mesg=$_SESSION['message'];
$sall=trim(GETPOST('sall'));
$projectid=(GETPOST('projectid')?GETPOST('projectid','int'):0);
@ -116,7 +111,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->c
{
if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
{
$mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
$mesgs[]='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
}
else
{
@ -130,7 +125,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->c
}
else
{
$mesg=$object->error;
$mesgs[]=$object->error;
$action='';
}
}
@ -152,7 +147,7 @@ else if ($action == 'reopen' && $user->rights->facture->creer)
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
}
}
}
@ -170,7 +165,7 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fact
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
}
}
@ -206,7 +201,7 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->
}
else
{
$mesg='<div clas="error">'.$object->error.'</div>';
$mesgs[]='<div clas="error">'.$object->error.'</div>';
$action='';
}
}
@ -230,7 +225,7 @@ else if ($action == 'valid' && $user->rights->facture->creer)
// Si avoir, le signe doit etre negatif
if ($object->total_ht >= 0)
{
$mesg='<div class="error">'.$langs->trans("ErrorInvoiceAvoirMustBeNegative").'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorInvoiceAvoirMustBeNegative").'</div>';
$action='';
}
}
@ -239,7 +234,7 @@ else if ($action == 'valid' && $user->rights->facture->creer)
// Si non avoir, le signe doit etre positif
if (empty($conf->global->FACTURE_ENABLE_NEGATIVE) && $object->total_ht < 0)
{
$mesg='<div class="error">'.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").'</div>';
$action='';
}
}
@ -306,7 +301,7 @@ else if ($action == "setabsolutediscount" && $user->rights->facture->creer)
$result=$object->insert_discount($_POST["remise_id"]);
if ($result < 0)
{
$mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
}
}
else
@ -323,7 +318,7 @@ else if ($action == "setabsolutediscount" && $user->rights->facture->creer)
$result=$discount->link_to_invoice(0,$id);
if ($result < 0)
{
$mesg='<div class="error">'.$discount->error.'</div>';
$mesgs[]='<div class="error">'.$discount->error.'</div>';
}
}
}
@ -390,7 +385,7 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->factu
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
}
}
}
@ -486,7 +481,7 @@ else if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $user->righ
}
else
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'</div>';
}
}
// Classify "abandoned"
@ -501,7 +496,7 @@ else if ($action == 'confirm_canceled' && $confirm == 'yes')
}
else
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'</div>';
}
}
@ -560,18 +555,18 @@ else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->righ
$result=$object->set_paid($user);
if ($result > 0)
{
//$mesg='OK'.$discount->id;
//$mesgs[]='OK'.$discount->id;
$db->commit();
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
$db->rollback();
}
}
else
{
$mesg='<div class="error">'.$discount->error.'</div>';
$mesgs[]='<div class="error">'.$discount->error.'</div>';
$db->rollback();
}
}
@ -595,13 +590,13 @@ else if ($action == 'add' && $user->rights->facture->creer)
if (empty($datefacture))
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
}
if (! ($_POST['fac_replacement'] > 0))
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ReplaceInvoice")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ReplaceInvoice")).'</div>';
}
if (! $error)
@ -627,7 +622,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
$object->type = 1;
$id=$object->createFromCurrent($user);
if ($id <= 0) $mesg=$object->error;
if ($id <= 0) $mesgs[]=$object->error;
}
}
@ -637,14 +632,14 @@ else if ($action == 'add' && $user->rights->facture->creer)
if (! $_POST['fac_avoir'] > 0)
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).'</div>';
}
$datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
if (empty($datefacture))
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
}
if (! $error)
@ -696,7 +691,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
if (empty($datefacture))
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
}
if (! $error)
@ -725,7 +720,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
if (empty($datefacture))
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'</div>';
}
if (! $error)
@ -816,7 +811,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
}
else
{
$mesg=$discount->error;
$mesgs[]=$discount->error;
$error++;
break;
}
@ -895,13 +890,13 @@ else if ($action == 'add' && $user->rights->facture->creer)
}
else
{
$mesg=$srcobject->error;
$mesgs[]=$srcobject->error;
$error++;
}
}
else
{
$mesg=$object->error;
$mesgs[]=$object->error;
$error++;
}
}
@ -938,7 +933,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
$action='create';
$_GET["origin"]=$_POST["origin"];
$_GET["originid"]=$_POST["originid"];
if (! $mesg) $mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
}
}
@ -950,27 +945,27 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
if ($_POST['np_price'] < 0 && $_POST["qty"] < 0)
{
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans("ErrorBothFieldCantBeNegative",$langs->transnoentitiesnoconv("UnitPriceHT"),$langs->transnoentitiesnoconv("Qty")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorBothFieldCantBeNegative",$langs->transnoentitiesnoconv("UnitPriceHT"),$langs->transnoentitiesnoconv("Qty")).'</div>';
$result = -1 ;
}
if (empty($_POST['idprod']) && $_POST["type"] < 0)
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
$result = -1 ;
}
if (empty($_POST['idprod']) && (! isset($_POST["np_price"]) || $_POST["np_price"]=='')) // Unit price can be 0 but not ''
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).'</div>';
$result = -1 ;
}
if (empty($_POST['idprod']) && empty($_POST["np_desc"]) && empty($_POST["dp_desc"]))
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'</div>';
$result = -1 ;
}
if (! isset($_POST['qty']) || $_POST['qty']=='')
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Qty')).'</div>';
$mesgs[]='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Qty')).'</div>';
$result = -1 ;
}
if ($result >= 0 && ( ($_POST['np_price']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod'] ) )
@ -1082,7 +1077,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
$pa_ht = $_POST['np_buying_price'];
else
$pa_ht = null;
$info_bits=0;
if ($tva_npr) $info_bits |= 0x01;
@ -1155,7 +1150,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
}
else
{
if (empty($mesg)) $mesg='<div class="error">'.$object->error.'</div>';
$mesgs[]='<div class="error">'.$object->error.'</div>';
}
$action='';
@ -1194,7 +1189,7 @@ else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['sa
// Check parameters
if (! GETPOST('productid') && GETPOST("type") < 0)
{
$mesg = '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
$mesgs[] = '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
$result = -1 ;
}
// Check minimum price
@ -1210,7 +1205,7 @@ else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['sa
if ($object->type!=2 && $price_min && GETPOST('productid') && (price2num($up_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
{
//print "CantBeLessThanMinPrice ".$up_ht." - ".GETPOST('remise_percent')." - ".$product->price_min;
$mesg = '<div class="error">'.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency)).'</div>';
$mesgs[] = '<div class="error">'.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency)).'</div>';
$result=-1;
}
@ -1328,7 +1323,7 @@ if (GETPOST('addfile'))
$vardir=$conf->user->dir_output."/".$user->id;
$upload_dir_tmp = $vardir.'/temp';
$mesg=dol_add_file_process($upload_dir_tmp,0,0);
$mesgs[]=dol_add_file_process($upload_dir_tmp,0,0);
$action='presend';
}
@ -1345,7 +1340,7 @@ if (! empty($_POST['removedfile']))
$upload_dir_tmp = $vardir.'/temp';
// TODO Delete only files that was uploaded from email form
$mesg=dol_remove_file_process($_POST['removedfile'],0);
$mesgs[]=dol_remove_file_process($_POST['removedfile'],0);
$action='presend';
}
@ -1476,8 +1471,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['message'] = $mesg;
Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&mesg=1');
$_SESSION['dol_message'] = $mesg;
Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id);
exit;
}
}
@ -1495,27 +1490,28 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
}
$mesg.='</div>';
$mesgs[]=$mesg;
}
}
/* }
else
{
$langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').'</div>';
$mesgs[]='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').'</div>';
dol_syslog('Recipient email is empty');
}*/
}
else
{
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
$mesgs[]='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
dol_syslog('Failed to read file: '.$file);
}
}
else
{
$langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'</div>';
$mesgs[]='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'</div>';
dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
}
@ -1571,7 +1567,7 @@ else if ($action == 'remove_file')
$upload_dir = $conf->facture->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
dol_delete_file($file,0,0,0,$object);
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
$mesgs[] = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
}
}
@ -1597,11 +1593,11 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
$mesgs[] = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
}
else
{
$mesg = '<div class="error">'.$object->error.'</div>';
$mesgs[] = '<div class="error">'.$object->error.'</div>';
}
}
}
@ -1661,9 +1657,6 @@ if ($action == 'create')
print_fiche_titre($langs->trans('NewBill'));
dol_htmloutput_mesg($mesg);
dol_htmloutput_errors('',$errors);
$soc = new Societe($db);
if ($socid) $res=$soc->fetch($socid);
@ -2109,8 +2102,6 @@ else if ($id > 0 || ! empty($ref))
/*
* Show object in view mode
*/
dol_htmloutput_mesg($mesg);
dol_htmloutput_errors('',$errors);
$result=$object->fetch($id,$ref);
if ($result > 0)
@ -3332,7 +3323,8 @@ else if ($id > 0 || ! empty($ref))
}
}
dol_htmloutput_mesg('',$mesgs);
llxFooter();
$db->close();
?>
?>

View File

@ -38,22 +38,18 @@ require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
require_once(DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php');
require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
if ($conf->projet->enabled)
if (! empty($conf->commande->enabled)) require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
if (! empty($conf->projet->enabled))
{
require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
}
$langs->load('bills');
//print 'ee'.$langs->trans('BillsCustomer');exit;
$langs->load('companies');
$langs->load('products');
$langs->load('main');
if (GETPOST('mesg','int',1) && isset($_SESSION['message'])) $mesg=$_SESSION['message'];
$sall=trim(GETPOST('sall'));
$projectid=(GETPOST('projectid')?GETPOST('projectid','int'):0);

View File

@ -725,7 +725,7 @@ $bcnd=array(0=>'class="impair nodrag nodrop"',1=>'class="pair nodrag nodrop"');
$mesg=''; $mesgs=array();
if (isset($_SESSION['dol_message']))
{
$mesg=$_SESSION['dol_message'];
$mesgs[]=$_SESSION['dol_message'];
unset($_SESSION['dol_message']);
}