Clean code

This commit is contained in:
Laurent Destailleur 2021-06-14 18:45:02 +02:00
parent dd27d38d5e
commit 8b0c2d997c
3 changed files with 27 additions and 10 deletions

View File

@ -109,6 +109,7 @@ if ($action == 'set_default') {
}
}
/*
* View
*/

View File

@ -66,6 +66,11 @@ $id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'purchaseordercard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
$socid = GETPOST('socid', 'int');
$projectid = GETPOST('projectid', 'int');
$cancel = GETPOST('cancel', 'alpha');
@ -151,12 +156,16 @@ if ($reshook < 0) {
}
if (empty($reshook)) {
if ($cancel) {
if (!empty($backtopage)) {
header("Location: ".$backtopage);
exit;
$backurlforlist = DOL_URL_ROOT.'/fourn/commande/list.php'.($socid > 0 ? '&socid='.((int) $socid) : '');
if (empty($backtopage) || ($cancel && empty($id))) {
if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
$backtopage = $backurlforlist;
} else {
$backtopage = DOL_URL_ROOT.'/fourn/commande/card.php?id='.($id > 0 ? $id : '__ID__');
}
}
$action = '';
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
@ -1573,10 +1582,16 @@ if ($action == 'create') {
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
print '<input type="hidden" name="remise_percent" value="'.$soc->remise_supplier_percent.'">';
print '<input type="hidden" name="origin" value="'.$origin.'">';
print '<input type="hidden" name="originid" value="'.$originid.'">';
if ($backtopage) {
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
}
if ($backtopageforcancel) {
print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
}
if (!empty($currency_tx)) {
print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.'">';
}
@ -1592,9 +1607,9 @@ if ($action == 'create') {
print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
print '<td>';
if ($socid > 0) {
if ($societe->id > 0) {
print $societe->getNomUrl(1);
print '<input type="hidden" name="socid" value="'.$socid.'">';
print '<input type="hidden" name="socid" value="'.$societe->id.'">';
} else {
print img_picto('', 'company').$form->select_company((empty($socid) ? '' : $socid), 'socid', 's.fournisseur=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300');
// reload page to retrieve customer informations

View File

@ -892,8 +892,9 @@ if ($resql) {
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
$url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
if (!empty($socid)) {
$url .= '&socid='.$socid;
if ($socid > 0) {
$url .= '&socid='.((int) $socid);
$url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid));
}
$newcardbutton = dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer));