From 305c1d63a735ffb19216faff108124404e8d0331 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Sep 2013 13:25:45 +0200 Subject: [PATCH] Qual: Uniformize code. No useless redirect. use GETPOST. --- htdocs/commande/fiche.php | 16 ++------ htdocs/compta/dons/fiche.php | 19 +++------- htdocs/compta/facture.php | 8 +--- htdocs/compta/paiement/cheque/fiche.php | 6 +-- htdocs/compta/paiement/rapport.php | 4 +- htdocs/expedition/fiche.php | 7 ++-- htdocs/exports/export.php | 2 +- htdocs/fichinter/fiche.php | 6 +-- htdocs/fourn/commande/fiche.php | 15 ++------ htdocs/fourn/facture/fiche.php | 24 +++++------- htdocs/imports/import.php | 2 +- htdocs/livraison/fiche.php | 8 ++-- htdocs/projet/fiche.php | 11 +----- htdocs/projet/tasks/task.php | 38 ++++++++----------- .../canvas/actions_card_common.class.php | 9 +---- htdocs/societe/soc.php | 7 +--- 16 files changed, 59 insertions(+), 123 deletions(-) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index edac096c8f0..6bc2d02f25e 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1123,14 +1123,11 @@ else if ($action == 'builddoc') // In get or post { /* * Generate order document - * define into /core/modules/commande/modules_commande.php - */ + * define into /core/modules/commande/modules_commande.php + */ - // Sauvegarde le dernier modele choisi pour generer un document - if ($_REQUEST['model']) - { - $object->setDocModel($user, $_REQUEST['model']); - } + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; @@ -1149,11 +1146,6 @@ else if ($action == 'builddoc') // In get or post dol_print_error($db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } // Remove file in doc form diff --git a/htdocs/compta/dons/fiche.php b/htdocs/compta/dons/fiche.php index 95f5985b56f..b9cf534f8a5 100644 --- a/htdocs/compta/dons/fiche.php +++ b/htdocs/compta/dons/fiche.php @@ -217,35 +217,28 @@ if ($action == 'set_encaisse') */ if ($action == 'builddoc') { - $donation = new Don($db); - $donation->fetch($id); + $object = new Don($db); + $object->fetch($id); - if ($_REQUEST['model']) - { - $donation->setDocModel($user, $_REQUEST['model']); - } + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$donation->client->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - $result=don_create($db, $donation->id, '', $donation->modelpdf, $outputlangs); + $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$donation->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 7e82e4d38d3..1251ad4fe0e 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1795,7 +1795,8 @@ else if ($action == 'builddoc') // En get ou en post $object->fetch($id); $object->fetch_thirdparty(); - if (GETPOST('model')) $object->setDocModel($user, GETPOST('model')); + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); if (GETPOST('fk_bank')) $object->fk_bank=GETPOST('fk_bank'); // Define output language @@ -1814,11 +1815,6 @@ else if ($action == 'builddoc') // En get ou en post dol_print_error($db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } // Remove file in doc form diff --git a/htdocs/compta/paiement/cheque/fiche.php b/htdocs/compta/paiement/cheque/fiche.php index d7e9b4f0946..c860e04ecd6 100644 --- a/htdocs/compta/paiement/cheque/fiche.php +++ b/htdocs/compta/paiement/cheque/fiche.php @@ -211,10 +211,8 @@ if ($action == 'builddoc' && $user->rights->banque->cheque) { $result = $object->fetch($id); - /*if ($_REQUEST['model']) - { - $object->setDocModel($user, $_REQUEST['model']); - }*/ + // Save last template used to generate document + //if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); $outputlangs = $langs; $newlang=''; diff --git a/htdocs/compta/paiement/rapport.php b/htdocs/compta/paiement/rapport.php index ce4a3b7cb7f..b3a8939482f 100644 --- a/htdocs/compta/paiement/rapport.php +++ b/htdocs/compta/paiement/rapport.php @@ -55,10 +55,10 @@ if ($action == 'builddoc') $rap = new pdf_paiement($db); $outputlangs = $langs; - if (! empty($_REQUEST['lang_id'])) + if (! empty(GETPOST('lang_id'))) { $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); + $outputlangs->setDefaultLang(GETPOST('lang_id')); } // We save charset_output to restore it because write_file can change it if needed for diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 78db51c9620..82f3bf64867 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -294,10 +294,9 @@ else if ($action == 'settrackingnumber' || $action == 'settrackingurl' // Build document else if ($action == 'builddoc') // En get ou en post { - if (GETPOST('model','alpha')) - { - $object->setDocModel($user, GETPOST('model','alpha')); - } + + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 99ebd02c094..c152895c0d7 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -225,7 +225,7 @@ if ($step == 1 || $action == 'cleanselect') if ($action == 'builddoc') { // Build export file - $result=$objexport->build_file($user, $_POST['model'], $datatoexport, $array_selected, $array_filtervalue); + $result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue); if ($result < 0) { setEventMessage($objexport->error, 'errors'); diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 1ec1fe22c3d..902db499004 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -333,10 +333,8 @@ else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou $object->fetch_thirdparty(); $object->fetch_lines(); - if (GETPOST('model','alpha')) - { - $object->setDocModel($user, GETPOST('model','alpha')); - } + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 68467939a10..e5bc8d81926 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -628,13 +628,9 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) / { // Build document - // Sauvegarde le dernier module choisi pour generer un document - - if (GETPOST('model')) - { - $object->setDocModel($user, GETPOST('model')); - } - + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); + $outputlangs = $langs; if (GETPOST('lang_id')) { @@ -647,11 +643,6 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) / dol_print_error($db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } // Delete file in doc form diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 4fe504870cb..7289972c004 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -86,7 +86,7 @@ if ($id > 0 || ! empty($ref)) /* * Actions -*/ + */ // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes') @@ -898,21 +898,22 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P } // Build document -elseif ($action == 'builddoc') +elseif ($action == 'builddoc') { - // Save modele used + // Save modele used $object->fetch($id); $object->fetch_thirdparty(); - if ($_REQUEST['model']) - { - $object->setDocModel($user, $_REQUEST['model']); - } + + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); $outputlangs = $langs; - if (! empty($_REQUEST['lang_id'])) + $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) { $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); + $outputlangs->setDefaultLang($newlang); } $result=supplier_invoice_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result <= 0) @@ -920,11 +921,6 @@ elseif ($action == 'builddoc') dol_print_error($db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } // Delete file in doc form diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index efe15744079..c6ada78322a 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -135,7 +135,7 @@ if ($action=='downfield' || $action=='upfield') if ($action == 'builddoc') { // Build import file - $result=$objimport->build_file($user, $_POST['model'], $datatoimport, $array_match_file_to_database); + $result=$objimport->build_file($user, GETPOST('model','alpha'), $datatoimport, $array_match_file_to_database); if ($result < 0) { $mesg='
'.$objimport->error.'
'; diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index ab455616d74..44c0bc91166 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -184,15 +184,13 @@ if ($action == 'builddoc') // En get ou en post $object->fetch($id); $object->fetch_thirdparty(); - if ($_REQUEST['model']) - { - $object->setDocModel($user, $_REQUEST['model']); - } + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); // Define output language $outputlangs = $langs; $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index 831e7ac2246..a07e3755fa5 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -233,10 +233,8 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer) // Build doc if ($action == 'builddoc' && $user->rights->projet->creer) { - if (GETPOST('model')) - { - $object->setDocModel($user, GETPOST('model')); - } + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); $outputlangs = $langs; if (GETPOST('lang_id')) @@ -250,11 +248,6 @@ if ($action == 'builddoc' && $user->rights->projet->creer) dol_print_error($db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } // Delete file in doc form diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 4a995edb0e4..7e46e1c169c 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -146,30 +146,22 @@ if (! empty($project_ref) && ! empty($withproject)) // Build doc if ($action == 'builddoc' && $user->rights->projet->creer) { - if ($object->fetch($id,$ref) >= 0 ) - { - if (GETPOST('model')) - { - $object->setDocModel($user, GETPOST('model')); - } + $object->fetch($id,$ref); + + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); - $outputlangs = $langs; - if (GETPOST('lang_id')) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang(GETPOST('lang_id')); - } - $result=task_pdf_create($db, $object, $object->modelpdf, $outputlangs); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } + $outputlangs = $langs; + if (GETPOST('lang_id')) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang(GETPOST('lang_id')); + } + $result=task_pdf_create($db, $object, $object->modelpdf, $outputlangs); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; } } diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index 96ce4976665..6d30e8e760c 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -333,24 +333,19 @@ abstract class ActionsCardCommon // Define output language $outputlangs = $langs; $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id') ) $newlang=GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$this->object->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - $result=thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model'), $outputlangs); + $result=thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model','alpha'), $outputlangs); if ($result <= 0) { dol_print_error($this->db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?socid='.$this->object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } } } diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 82a79db9d2f..8682058091d 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -475,17 +475,12 @@ if (empty($reshook)) $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - $result=thirdparty_doc_create($db, $object, '', $_REQUEST['model'], $outputlangs); + $result=thirdparty_doc_create($db, $object, '', GETPOST('model','alpha'), $outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?socid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } } }