Qual: Uniformize code. No useless redirect. use GETPOST.

This commit is contained in:
Laurent Destailleur 2013-09-06 13:25:45 +02:00
parent c151ef7b87
commit 305c1d63a7
16 changed files with 59 additions and 123 deletions

View File

@ -1123,14 +1123,11 @@ else if ($action == 'builddoc') // In get or post
{ {
/* /*
* Generate order document * 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 // Save last template used to generate document
if ($_REQUEST['model']) if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
{
$object->setDocModel($user, $_REQUEST['model']);
}
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
@ -1149,11 +1146,6 @@ else if ($action == 'builddoc') // In get or post
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
// Remove file in doc form // Remove file in doc form

View File

@ -217,35 +217,28 @@ if ($action == 'set_encaisse')
*/ */
if ($action == 'builddoc') if ($action == 'builddoc')
{ {
$donation = new Don($db); $object = new Don($db);
$donation->fetch($id); $object->fetch($id);
if ($_REQUEST['model']) // Save last template used to generate document
{ if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
$donation->setDocModel($user, $_REQUEST['model']);
}
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
$newlang=''; $newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; 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)) if (! empty($newlang))
{ {
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
$result=don_create($db, $donation->id, '', $donation->modelpdf, $outputlangs); $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs);
if ($result <= 0) if ($result <= 0)
{ {
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$donation->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }

View File

@ -1795,7 +1795,8 @@ else if ($action == 'builddoc') // En get ou en post
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $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'); if (GETPOST('fk_bank')) $object->fk_bank=GETPOST('fk_bank');
// Define output language // Define output language
@ -1814,11 +1815,6 @@ else if ($action == 'builddoc') // En get ou en post
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
// Remove file in doc form // Remove file in doc form

View File

@ -211,10 +211,8 @@ if ($action == 'builddoc' && $user->rights->banque->cheque)
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
/*if ($_REQUEST['model']) // Save last template used to generate document
{ //if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
$object->setDocModel($user, $_REQUEST['model']);
}*/
$outputlangs = $langs; $outputlangs = $langs;
$newlang=''; $newlang='';

View File

@ -55,10 +55,10 @@ if ($action == 'builddoc')
$rap = new pdf_paiement($db); $rap = new pdf_paiement($db);
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($_REQUEST['lang_id'])) if (! empty(GETPOST('lang_id')))
{ {
$outputlangs = new Translate("",$conf); $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 // We save charset_output to restore it because write_file can change it if needed for

View File

@ -294,10 +294,9 @@ else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
// Build document // Build document
else if ($action == 'builddoc') // En get ou en post else if ($action == 'builddoc') // En get ou en post
{ {
if (GETPOST('model','alpha'))
{ // Save last template used to generate document
$object->setDocModel($user, GETPOST('model','alpha')); if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
}
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;

View File

@ -225,7 +225,7 @@ if ($step == 1 || $action == 'cleanselect')
if ($action == 'builddoc') if ($action == 'builddoc')
{ {
// Build export file // 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) if ($result < 0)
{ {
setEventMessage($objexport->error, 'errors'); setEventMessage($objexport->error, 'errors');

View File

@ -333,10 +333,8 @@ else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$object->fetch_lines(); $object->fetch_lines();
if (GETPOST('model','alpha')) // Save last template used to generate document
{ if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
$object->setDocModel($user, GETPOST('model','alpha'));
}
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;

View File

@ -628,12 +628,8 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) /
{ {
// Build document // Build document
// Sauvegarde le dernier module choisi pour generer un document // Save last template used to generate document
if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
if (GETPOST('model'))
{
$object->setDocModel($user, GETPOST('model'));
}
$outputlangs = $langs; $outputlangs = $langs;
if (GETPOST('lang_id')) if (GETPOST('lang_id'))
@ -647,11 +643,6 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) /
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
// Delete file in doc form // Delete file in doc form

View File

@ -86,7 +86,7 @@ if ($id > 0 || ! empty($ref))
/* /*
* Actions * Actions
*/ */
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes') if ($action == 'confirm_clone' && $confirm == 'yes')
@ -898,21 +898,22 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
} }
// Build document // Build document
elseif ($action == 'builddoc') elseif ($action == 'builddoc')
{ {
// Save modele used // Save modele used
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
if ($_REQUEST['model'])
{ // Save last template used to generate document
$object->setDocModel($user, $_REQUEST['model']); if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
}
$outputlangs = $langs; $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 = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang($newlang);
} }
$result=supplier_invoice_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); $result=supplier_invoice_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) if ($result <= 0)
@ -920,11 +921,6 @@ elseif ($action == 'builddoc')
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
// Delete file in doc form // Delete file in doc form

View File

@ -135,7 +135,7 @@ if ($action=='downfield' || $action=='upfield')
if ($action == 'builddoc') if ($action == 'builddoc')
{ {
// Build import file // 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) if ($result < 0)
{ {
$mesg='<div class="error">'.$objimport->error.'</div>'; $mesg='<div class="error">'.$objimport->error.'</div>';

View File

@ -184,15 +184,13 @@ if ($action == 'builddoc') // En get ou en post
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
if ($_REQUEST['model']) // Save last template used to generate document
{ if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
$object->setDocModel($user, $_REQUEST['model']);
}
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
$newlang=''; $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 ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang)) if (! empty($newlang))
{ {

View File

@ -233,10 +233,8 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
// Build doc // Build doc
if ($action == 'builddoc' && $user->rights->projet->creer) if ($action == 'builddoc' && $user->rights->projet->creer)
{ {
if (GETPOST('model')) // Save last template used to generate document
{ if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
$object->setDocModel($user, GETPOST('model'));
}
$outputlangs = $langs; $outputlangs = $langs;
if (GETPOST('lang_id')) if (GETPOST('lang_id'))
@ -250,11 +248,6 @@ if ($action == 'builddoc' && $user->rights->projet->creer)
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
// Delete file in doc form // Delete file in doc form

View File

@ -146,30 +146,22 @@ if (! empty($project_ref) && ! empty($withproject))
// Build doc // Build doc
if ($action == 'builddoc' && $user->rights->projet->creer) if ($action == 'builddoc' && $user->rights->projet->creer)
{ {
if ($object->fetch($id,$ref) >= 0 ) $object->fetch($id,$ref);
{
if (GETPOST('model'))
{
$object->setDocModel($user, GETPOST('model'));
}
$outputlangs = $langs; // Save last template used to generate document
if (GETPOST('lang_id')) if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
{
$outputlangs = new Translate("",$conf); $outputlangs = $langs;
$outputlangs->setDefaultLang(GETPOST('lang_id')); if (GETPOST('lang_id'))
} {
$result=task_pdf_create($db, $object, $object->modelpdf, $outputlangs); $outputlangs = new Translate("",$conf);
if ($result <= 0) $outputlangs->setDefaultLang(GETPOST('lang_id'));
{ }
dol_print_error($db,$result); $result=task_pdf_create($db, $object, $object->modelpdf, $outputlangs);
exit; if ($result <= 0)
} {
else dol_print_error($db,$result);
{ exit;
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
} }

View File

@ -333,24 +333,19 @@ abstract class ActionsCardCommon
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
$newlang=''; $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 ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$this->object->default_lang;
if (! empty($newlang)) if (! empty($newlang))
{ {
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang); $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) if ($result <= 0)
{ {
dol_print_error($this->db,$result); dol_print_error($this->db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?socid='.$this->object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
} }
} }

View File

@ -475,17 +475,12 @@ if (empty($reshook))
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang); $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) if ($result <= 0)
{ {
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
else
{
header('Location: '.$_SERVER["PHP_SELF"].'?socid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
} }
} }