From 337f41c8e1c4b2d1262587f196b2fe4c6f2c780e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 17 Jun 2011 22:24:52 +0000 Subject: [PATCH] Uniformize code --- htdocs/adherents/fiche.php | 2 +- htdocs/admin/facture.php | 2 +- htdocs/comm/mailing/fiche.php | 5 ++-- htdocs/commande/fiche.php | 12 ++++----- htdocs/compta/bank/ligne.php | 3 +-- htdocs/compta/deplacement/fiche.php | 2 +- htdocs/compta/facture.php | 3 +-- htdocs/compta/paiement.php | 2 +- htdocs/compta/paiement/cheque/fiche.php | 2 +- htdocs/contrat/fiche.php | 4 +-- htdocs/expedition/fiche.php | 33 +++++++++++-------------- htdocs/fichinter/fiche.php | 4 ++- htdocs/lib/functions.lib.php | 31 +++++++++++++---------- htdocs/product/fournisseurs.php | 4 +-- htdocs/user/fiche.php | 3 +-- 15 files changed, 55 insertions(+), 57 deletions(-) diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 2ee79ab04d7..2ce29a0bdef 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -622,7 +622,7 @@ if ($action == 'create') print_fiche_titre($langs->trans("NewMember")); - dol_htmloutput_errors($errmsg,$errmsgs); + dol_htmloutput_mesg($errmsg,$errmsgs,'error'); dol_htmloutput_mesg($mesg,$mesgs); if ($conf->use_javascript_ajax) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index e91b8b307c0..9cc8ee4191e 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -365,7 +365,7 @@ foreach ($conf->file->dol_document_root as $dirroot) if ($conf->global->FACTURE_ADDON.'.php' == $file) // If module is the one used, we show existing errors { - if (! empty($module->error)) dol_htmloutput_errors($module->error,'',1); + if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1); } print ''; diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index 9c12415ac55..e00a44ab5d8 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -612,9 +612,8 @@ if ($_GET["action"] == 'create') print_fiche_titre($langs->trans("NewMailing")); - if (preg_match('/class="error"/i',$message)) dol_htmloutput_errors($message); - else dol_htmloutput_mesg($message); - + dol_htmloutput_mesg($message); + print ''; print ''; print ''; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 80664161455..9c6d71ead2f 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -104,7 +104,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes') } else { - $mesg=$object->error; + $mesg='
'.$object->error.'
'; $action=''; } } @@ -124,7 +124,7 @@ if ($action == 'reopen' && $user->rights->commande->creer) } else { - $mesg='
'.$fac->error.'
'; + $mesg='
'.$object->error.'
'; } } } @@ -143,7 +143,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') } else { - $mesg=$object->error; + $mesg='
'.$object->error.'
'; } } } @@ -173,7 +173,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes') } else { - print $object->error; + $mesg='
'.$object->error.'
'; } } Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); @@ -1124,7 +1124,7 @@ if ($action == 'create' && $user->rights->commande->creer) { print_fiche_titre($langs->trans('CreateOrder')); - dol_htmloutput_errors($mesg,$mesgs); + dol_htmloutput_mesg($mesg,$mesgs,'error'); $soc = new Societe($db); if ($socid) $res=$soc->fetch($socid); @@ -1424,7 +1424,7 @@ else if ($id > 0 || ! empty($ref)) { - dol_htmloutput_errors($mesg,$mesgs); + dol_htmloutput_mesg($mesg,$mesgs); $product_static=new Product($db); diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php index 7f812bb2c1e..a3f656eff39 100644 --- a/htdocs/compta/bank/ligne.php +++ b/htdocs/compta/bank/ligne.php @@ -215,8 +215,7 @@ $h++; dol_fiche_head($head, $hselected, $langs->trans('LineRecord'),0,'account'); -if (! preg_match('/class="error"/i',$mesg)) dol_htmloutput_mesg($mesg); -else dol_htmloutput_errors($mesg); +dol_htmloutput_mesg($mesg); $sql = "SELECT b.rowid,b.dateo as do,b.datev as dv, b.amount, b.label, b.rappro,"; $sql.= " b.num_releve, b.fk_user_author, b.num_chq, b.fk_type, b.fk_account, b.fk_bordereau as receiptid,"; diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index 27d813d531c..4f7737c5f30 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -184,7 +184,7 @@ if ($_GET["action"] == 'create') { print_fiche_titre($langs->trans("NewTrip")); - if ($mesg) dol_htmloutput_errors($mesg); + dol_htmloutput_errors($mesg); $datec = dol_mktime(12, 0, 0, $_POST["remonth"], diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 5e4cc1f59df..fe73e96e1dd 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1841,8 +1841,7 @@ else */ if ($id > 0 || ! empty($ref)) { - if (preg_match('/class="error"/',$mesg)) dol_htmloutput_errors($mesg); - else dol_htmloutput_mesg($mesg); + dol_htmloutput_mesg($mesg); $result=$object->fetch($id,$ref); if ($result > 0) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 3e77bdfab70..96203d9c39f 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -227,7 +227,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer"); print_fiche_titre($title); - if ($errmsg) dol_htmloutput_errors($errmsg); + dol_htmloutput_errors($errmsg); // Bouchon if ($facture->type == 2) diff --git a/htdocs/compta/paiement/cheque/fiche.php b/htdocs/compta/paiement/cheque/fiche.php index 06ba2ded7ee..5194ba5cc61 100644 --- a/htdocs/compta/paiement/cheque/fiche.php +++ b/htdocs/compta/paiement/cheque/fiche.php @@ -286,7 +286,7 @@ else } } -//if ($mesg) print $mesg.'
'; + dol_htmloutput_errors($mesg); diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 3d050ec2b55..7a25b945269 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -480,7 +480,7 @@ if ($action == 'create') { dol_fiche_head($head, $a, $langs->trans("AddContract"), 0, 'contract'); - dol_htmloutput_errors($mesg); + dol_htmloutput_errors($mesg,''); $soc = new Societe($db); $soc->fetch($socid); @@ -583,7 +583,7 @@ else exit; } - dol_htmloutput_errors($mesg); + dol_htmloutput_errors($mesg,''); $nbofservices=sizeof($object->lines); diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 3d6ed3cf92b..a4a7bd01900 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -835,12 +835,7 @@ else if ($object->id > 0) { - if ($mesg) - { - print '
'.$mesg.'
'; - } - - dol_htmloutput_mesg(); + dol_htmloutput_mesg($mesg); if (!empty($object->origin)) { @@ -1236,13 +1231,13 @@ else print ''.$langs->trans("Validate").''; } } - + // TODO add alternative status /* if ($object->statut == 1 && $user->rights->expedition->valider) { print ''.$langs->trans("ReOpen").''; }*/ - + // Send if ($object->statut == 1) { @@ -1257,7 +1252,7 @@ else else print ''.$langs->trans('SendByMail').''; } } - + // Create bill and Classify billed if ($conf->facture->enabled && $object->statut > 0 && ! $object->billed) { @@ -1267,7 +1262,7 @@ else //print ''.$langs->trans("CreateBill").''; print ''.$langs->trans("CreateBill").''; } - + // TODO add alternative status if ($user->rights->expedition->creer && $object->statut > 2) { @@ -1309,17 +1304,17 @@ else $somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); if ($genallowed && ! $somethingshown) $somethingshown=1; - + print '
'.$langs->trans("MailTitle").'
'.$langs->trans("MailFrom").'
'; - + // List of actions on element include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); $formactions=new FormActions($db); $somethingshown=$formactions->showactions($object,'shipping',$socid); - + print '
'; } - + /* * Action presend * @@ -1328,10 +1323,10 @@ else { $ref = dol_sanitizeFileName($object->ref); $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; - + print '
'; print_titre($langs->trans('SendShippingByEMail')); - + // Cree l'objet formulaire mail include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'); $formmail = new FormMail($db); @@ -1358,17 +1353,17 @@ else $formmail->param['models']='shipping_send'; $formmail->param['shippingid']=$object->id; $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - + // Init list of files if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') { $formmail->clear_attached_files(); $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); } - + // Show form $formmail->show_form(); - + print '
'; } diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 9e11f15fd91..61ddcc6ba9d 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -702,7 +702,9 @@ elseif ($fichinterid) $societe=new Societe($db); $societe->fetch($fichinter->socid); - if ($mesg) dol_htmloutput_errors($mesg)."
"; + + dol_htmloutput_errors($mesg); + $head = fichinter_prepare_head($fichinter); diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index de7cd699f35..bfb074c71af 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -102,7 +102,7 @@ function dol_getprefix() * To link to a module file from a module file, use include('./mymodulefile'); * To link to a module file from a core file, then this function can be used. * @param relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...) - * @return int Result + * @return int false if include fails. */ function dol_include_once($relpath) { @@ -3711,11 +3711,11 @@ function monthArrayOrSelected($selected=0) /** * Get formated messages to output (Used to show messages on html output) - * @param mesgstring Message + * @param mesgstring Message string * @param mesgarray Messages array - * @param style Style of message output + * @param style Style of message output ('ok' or 'error') + * @param keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) * @return string Return html output - * @return $keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) * @see dol_print_error * @see dol_htmloutput_errors */ @@ -3727,12 +3727,12 @@ function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb $out=''; $divstart=$divend=''; + // Use session mesg if (isset($_SESSION['mesg'])) { $mesgstring=$_SESSION['mesg']; unset($_SESSION['mesg']); } - if (isset($_SESSION['mesgarray'])) { $mesgarray=$_SESSION['mesgarray']; @@ -3790,7 +3790,7 @@ function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb * Get formated error messages to output (Used to show messages on html output) * @param mesgstring Error message * @param mesgarray Error messages array - * @return keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) + * @param keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) * @return html Return html output * @see dol_print_error * @see dol_htmloutput_mesg @@ -3801,18 +3801,24 @@ function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0) } /** - * print formated messages to output (Used to show messages on html output) + * Print formated messages to output (Used to show messages on html output) * @param mesgstring Message * @param mesgarray Messages array - * @param style Style of message output - * @return string Return html output - * @return $keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) + * @param style Which style to use ('ok', 'error') + * @param keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) * @see dol_print_error * @see dol_htmloutput_errors */ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0) { - print get_htmloutput_mesg($mesgstring,$mesgarray,$style,$keepembedded); + if (empty($mesgstring) && (! is_array($mesgarray) || sizeof($mesgarray) == 0)) return; + + $iserror=0; + if (preg_match('/class="error"/i',$mesgstring)) $iserror++; + if ($style=='error') $iserror++; + + if ($iserror) print get_htmloutput_mesg($mesgstring,$mesgarray,'error',$keepembedded); + else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded); } /** @@ -3820,13 +3826,12 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb * @param mesgstring Error message * @param mesgarray Error messages array * @return keepembedded Set to 1 in error message must be kept embedded into its html place (this disable jnotify) - * @return html Return html output * @see dol_print_error * @see dol_htmloutput_mesg */ function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0) { - print get_htmloutput_errors($mesgstring, $mesgarray,$keepembedded); + dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded); } /** diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 1c5f7d93e7f..110482c829e 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -235,8 +235,8 @@ if ($_GET["id"] || $_GET["ref"]) print "\n"; - if (preg_match('/class="error"/',$mesg)) dol_htmloutput_errors($mesg); - else dol_htmloutput_mesg($mesg); + + dol_htmloutput_mesg($mesg); // Form to add or update a price diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 55cdb0c025d..908a9ee5485 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -894,8 +894,7 @@ else if ($ret == 'html') print '
'; } - if (! preg_match('/class="error"/',$message)) dol_htmloutput_mesg($message); - else dol_htmloutput_errors($message); + dol_htmloutput_mesg($message); /* * Fiche en mode visu