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
* 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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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='';

View File

@ -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

View File

@ -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;

View File

@ -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');

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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='<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_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))
{

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}