From fbd262236b4e93929723a84718f734afd427c736 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 28 Aug 2023 07:40:44 +0200 Subject: [PATCH 1/3] FIX Accountancy - List of accounts - Compatibility left column checkbox + Search id_import + Hooks + Undefined variable --- htdocs/accountancy/admin/account.php | 201 ++++++++++++++++++++------- 1 file changed, 154 insertions(+), 47 deletions(-) diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index c5db08e73e7..1dc461b8ae6 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2020 Alexandre Spangaro + * Copyright (C) 2013-2023 Alexandre Spangaro * Copyright (C) 2016-2018 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify @@ -142,10 +142,13 @@ if (empty($reshook)) { $search_labelshort = ""; $search_accountparent = ""; $search_pcgtype = ""; + $search_import_key = ""; $search_array_options = array(); } if ((GETPOST('valid_change_chart', 'alpha') && GETPOST('chartofaccounts', 'int') > 0) // explicit click on button 'Change and load' with js on || (GETPOST('chartofaccounts', 'int') > 0 && GETPOST('chartofaccounts', 'int') != getDolGlobalInt('CHARTOFACCOUNTS'))) { // a submit of form is done and chartofaccounts combo has been modified + $error = 0; + if ($chartofaccounts > 0 && $permissiontoadd) { // Get language code for this $chartofaccounts $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_country as c, '.MAIN_DB_PREFIX.'accounting_system as a'; @@ -218,14 +221,13 @@ if (empty($reshook)) { /* * View */ - $form = new Form($db); $formaccounting = new FormAccounting($db); llxHeader('', $langs->trans("ListAccounts")); if ($action == 'delete') { - $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1); print $formconfirm; } @@ -234,11 +236,24 @@ $pcgver = getDolGlobalInt('CHARTOFACCOUNTS'); $sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.account_number, aa.account_parent, aa.label, aa.labelshort, aa.fk_accounting_category,"; $sql .= " aa.reconcilable, aa.active, aa.import_key,"; $sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2"; + +// Add fields from hooks +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; +$sql = preg_replace('/,\s*$/', '', $sql); + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".((int) $conf->entity); $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".((int) $conf->entity); + +// Add table from hooks +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; + $sql .= " WHERE asy.rowid = ".((int) $pcgver); -//print $sql; + if (strlen(trim($search_account))) { $lengthpaddingaccount = 0; if (getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT') || getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT')) { @@ -285,6 +300,15 @@ if (strlen(trim($search_accountparent)) && $search_accountparent != '-1') { if (strlen(trim($search_pcgtype))) { $sql .= natural_search("aa.pcg_type", $search_pcgtype); } +if (strlen(trim($search_import_key))) { + $sql .= natural_search("aa.import_key", $search_import_key); +} + +// Add where from hooks +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; + $sql .= $db->order($sortfield, $sortorder); //print $sql; @@ -299,16 +323,6 @@ if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { } } -// List of mass actions available -if ($user->hasRight('accounting', 'chartofaccount')) { - $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); -} -if (in_array($massaction, array('presend', 'predelete', 'closed'))) { - $arrayofmassactions = array(); -} - -$massactionbutton = $form->selectMassAction('', $arrayofmassactions); -$arrayofselected = is_array($toselect) ? $toselect : array(); $sql .= $db->plimit($limit + 1, $offset); dol_syslog('accountancy/admin/account.php:: $sql='.$sql); @@ -317,6 +331,8 @@ $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); + $arrayofselected = is_array($toselect) ? $toselect : array(); + $param = ''; if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { $param .= '&contextpage='.urlencode($contextpage); @@ -339,13 +355,18 @@ if ($resql) { if ($search_pcgtype) { $param .= '&search_pcgtype='.urlencode($search_pcgtype); } - if ($optioncss != '') { + if ($search_import_key) { $param .= '&search_import_key='.urlencode($search_import_key); } if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } + // Add $param from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $param .= $hookmanager->resPrint; + if (!empty($conf->use_javascript_ajax)) { print ' '; } + // List of mass actions available + if ($user->hasRight('accounting', 'chartofaccount')) { + $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); + } + if (in_array($massaction, array('presend', 'predelete', 'closed'))) { + $arrayofmassactions = array(); + } + + $massactionbutton = $form->selectMassAction('', $arrayofmassactions); + $newcardbutton = ''; + $newcardbutton = dolGetButtonTitle($langs->trans('Addanaccount'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/accountancy/admin/card.php?action=create', '', $permissiontoadd); + print '
'; if ($optioncss != '') { @@ -372,10 +405,10 @@ if ($resql) { print ''; print ''; - $newcardbutton .= dolGetButtonTitle($langs->trans("New"), $langs->trans("Addanaccount"), 'fa fa-plus-circle', './card.php?action=create'); - include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accounting_account', 0, $newcardbutton, '', $limit, 0, 0, 1); + include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; + // Box to select active chart of account print $langs->trans("Selectchartofaccounts")." : "; print ''; } @@ -452,6 +499,12 @@ if ($resql) { if (!empty($arrayfields['categories']['checked'])) { print ''; } + + // Fields from hook + $parameters = array('arrayfields'=>$arrayfields); + $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Import key if (!empty($arrayfields['aa.import_key']['checked'])) { print ''; @@ -464,44 +517,78 @@ if ($resql) { if (!empty($arrayfields['aa.active']['checked'])) { print ' '; } - print ''; - $searchpicto = $form->showFilterButtons(); - print $searchpicto; - print ''; - print ''; + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print ''; + } + print ''."\n"; + + $totalarray = array(); + $totalarray['nbfield'] = 0; + + // Fields title label + // -------------------------------------------------------------------- print ''; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn '); + $totalarray['nbfield']++; + } if (!empty($arrayfields['aa.account_number']['checked'])) { print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['aa.label']['checked'])) { print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['aa.labelshort']['checked'])) { print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } if (!empty($arrayfields['aa.account_parent']['checked'])) { print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left '); + $totalarray['nbfield']++; } if (!empty($arrayfields['aa.pcg_type']['checked'])) { print_liste_field_titre($arrayfields['aa.pcg_type']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_type,aa.account_number', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.pcg_type']['help'], 1); + $totalarray['nbfield']++; } if (!empty($arrayfields['categories']['checked'])) { print_liste_field_titre($arrayfields['categories']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '', $arrayfields['categories']['help'], 1); + $totalarray['nbfield']++; } + + // Hook fields + $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); + $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (!empty($arrayfields['aa.import_key']['checked'])) { print_liste_field_titre($arrayfields['aa.import_key']['label'], $_SERVER["PHP_SELF"], 'aa.import_key', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.import_key']['help'], 1); + $totalarray['nbfield']++; } if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { if (!empty($arrayfields['aa.reconcilable']['checked'])) { print_liste_field_titre($arrayfields['aa.reconcilable']['label'], $_SERVER["PHP_SELF"], 'aa.reconcilable', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; } } if (!empty($arrayfields['aa.active']['checked'])) { print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder); + $totalarray['nbfield']++; + } + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); + $totalarray['nbfield']++; } - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print "\n"; + // Loop on record + // -------------------------------------------------------------------- $i = 0; while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -512,6 +599,22 @@ if ($resql) { print ''; + // Action column + if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } + print ''; + } + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Account number if (!empty($arrayfields['aa.account_number']['checked'])) { print ""; @@ -589,6 +692,11 @@ if ($resql) { } } + // Fields from hook + $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Import id if (!empty($arrayfields['aa.import_key']['checked'])) { print ""; @@ -600,7 +708,7 @@ if ($resql) { } if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { - // Activated or not reconciliation on accounting account + // Activated or not reconciliation on an accounting account if (!empty($arrayfields['aa.reconcilable']['checked'])) { print ''; if (empty($obj->reconcilable)) { @@ -637,28 +745,20 @@ if ($resql) { } } - // Action - print ''; - if ($user->hasRight('accounting', 'chartofaccount')) { - print ''; - print img_edit(); - print ''; - print ' '; - print ''; - print img_delete(); - print ''; - print ' '; + // Action column + if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { + print ''; if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; if (in_array($obj->rowid, $arrayofselected)) { $selected = 1; } - print ''; + print ''; + } + print ''; + if (!$i) { + $totalarray['nbfield']++; } - } - print ''."\n"; - if (!$i) { - $totalarray['nbfield']++; } print "\n"; @@ -675,9 +775,16 @@ if ($resql) { print ''.$langs->trans("None").''; } - print ""; - print ""; - print '
'; + $db->free($resql); + + $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); + $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + print ''."\n"; + print ''."\n"; + + print ''."\n"; } else { dol_print_error($db); } From c311086c9de0fbebf3e9cbb6287abeaf5e7dd584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Thu, 31 Aug 2023 23:59:14 +0200 Subject: [PATCH 2/3] clean code --- htdocs/product/stock/productlot_card.php | 118 +++++++++++------------ 1 file changed, 54 insertions(+), 64 deletions(-) diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 2da298d7b37..42adc0a471a 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -34,6 +34,8 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; +global $conf, $db, $langs, $user; + // Load translation files required by the page $langs->loadLangs(array('stocks', 'other', 'productbatch')); @@ -69,9 +71,9 @@ if (empty($action) && empty($id) && empty($ref)) { $action = 'view'; } -$batch = GETPOST('batch', 'alpha'); -$productid = GETPOST('productid', 'int'); -$ref = GETPOST('ref', 'alpha'); // ref is productid_batch +$batch = GETPOST('batch', 'alpha'); +$productid = GETPOST('productid', 'int'); +$ref = GETPOST('ref', 'alpha'); // ref is productid_batch $search_entity = GETPOST('search_entity', 'int'); $search_fk_product = GETPOST('search_fk_product', 'int'); @@ -106,13 +108,13 @@ if ($id || $ref) { $hookmanager->initHooks(array('productlotcard', 'globalcard')); -$permissionnote = $user->rights->stock->creer; // Used by the include of actions_setnotes.inc.php -$permissiondellink = $user->rights->stock->creer; // Used by the include of actions_dellink.inc.php -$permissiontoadd = $user->rights->stock->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissionnote = $user->hasRight('stock', 'creer'); // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->hasRight('stock', 'creer'); // Used by the include of actions_dellink.inc.php +$permissiontoadd = $user->hasRight('stock', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php -$usercanread = $user->rights->produit->lire; -$usercancreate = $user->rights->produit->creer; -$usercandelete = $user->rights->produit->supprimer; +$usercanread = $user->hasRight('produit', 'lire'); +$usercancreate = $user->hasRight('produit', 'creer'); +$usercandelete = $user->hasRight('produit', 'supprimer'); $upload_dir = $conf->productbatch->multidir_output[$conf->entity]; @@ -121,7 +123,7 @@ $permissiontoadd = $usercancreate; $permissiontodelete = $usercandelete; // Security check -if (empty($conf->productbatch->enabled)) { +if (!isModEnabled('productbatch')) { accessforbidden('Module not enabled'); } $socid = 0; @@ -130,7 +132,9 @@ if ($user->socid > 0) { // Protection if external user accessforbidden(); } //$result = restrictedArea($user, 'productbatch'); -if (!$permissiontoread) accessforbidden(); +if (!$permissiontoread) { + accessforbidden(); +} /* @@ -148,7 +152,7 @@ if (empty($reshook)) { $backurlforlist = dol_buildpath('/product/stock/productlot_list.php', 1); - if ($action == 'seteatby' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { + if ($action == 'seteatby' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int')); $result = $object->setValueFrom('eatby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -159,7 +163,7 @@ if (empty($reshook)) { } } - if ($action == 'setsellby' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setsellby' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int')); $result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -170,7 +174,7 @@ if (empty($reshook)) { } } - if ($action == 'seteol_date' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { + if ($action == 'seteol_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('eol_datemonth', 'int'), GETPOST('eol_dateday', 'int'), GETPOST('eol_dateyear', 'int')); $result = $object->setValueFrom('eol_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -181,7 +185,7 @@ if (empty($reshook)) { } } - if ($action == 'setmanufacturing_date' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setmanufacturing_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('manufacturing_datemonth', 'int'), GETPOST('manufacturing_dateday', 'int'), GETPOST('manufacturing_dateyear', 'int')); $result = $object->setValueFrom('manufacturing_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -192,7 +196,7 @@ if (empty($reshook)) { } } - if ($action == 'setscrapping_date' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setscrapping_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('scrapping_datemonth', 'int'), GETPOST('scrapping_dateday', 'int'), GETPOST('scrapping_dateyear', 'int')); $result = $object->setValueFrom('scrapping_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -203,7 +207,7 @@ if (empty($reshook)) { } } - /* if ($action == 'setcommissionning_date' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { + /* if ($action == 'setcommissionning_date' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { $newvalue = dol_mktime(12, 0, 0, GETPOST('commissionning_datemonth', 'int'), GETPOST('commissionning_dateday', 'int'), GETPOST('commissionning_dateyear', 'int')); $result = $object->setValueFrom('commissionning_date', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { @@ -214,7 +218,7 @@ if (empty($reshook)) { } } */ - if ($action == 'setqc_frequency' && $user->rights->stock->creer && ! GETPOST('cancel', 'alpha')) { + if ($action == 'setqc_frequency' && $user->hasRight('stock', 'creer') && ! GETPOST('cancel', 'alpha')) { $result = $object->setValueFrom('qc_frequency', GETPOST('qc_frequency'), '', null, 'int', '', $user, 'PRODUCT_MODIFY'); if ($result < 0) { // Prévoir un test de format de durée setEventMessages($object->error, null, 'errors'); @@ -229,20 +233,17 @@ if (empty($reshook)) { // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; /* - if ($action == 'update_extras') - { + if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); if ($ret < 0) $error++; - if (!$error) - { + if (!$error) { // Actions on extra fields $result = $object->insertExtraFields('PRODUCT_LOT_MODIFY'); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } @@ -254,10 +255,8 @@ if (empty($reshook)) { } // Action to add record - if ($action == 'add') - { - if (GETPOST('cancel', 'alpha')) - { + if ($action == 'add') { + if (GETPOST('cancel', 'alpha')) { $urltogo = $backtopage ? $backtopage : dol_buildpath('/stock/list.php', 1); header("Location: ".$urltogo); exit; @@ -272,17 +271,14 @@ if (empty($reshook)) { $object->fk_user_modif = GETPOST('fk_user_modif', 'int'); $object->import_key = GETPOST('import_key', 'int'); - if (empty($object->ref)) - { + if (empty($object->ref)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors'); } - if (!$error) - { + if (!$error) { $result = $object->create($user); - if ($result > 0) - { + if ($result > 0) { // Creation OK $urltogo = $backtopage ? $backtopage : dol_buildpath('/stock/list.php', 1); header("Location: ".$urltogo); @@ -303,8 +299,7 @@ if (empty($reshook)) { if ($action == 'update' && GETPOST('cancel', 'alpha')) $action = 'view'; // Action to update record - if ($action == 'update' && !GETPOST('cancel', 'alpha')) - { + if ($action == 'update' && !GETPOST('cancel', 'alpha')) { $error = 0; $object->entity = GETPOST('entity', 'int'); @@ -314,17 +309,14 @@ if (empty($reshook)) { $object->fk_user_modif = GETPOST('fk_user_modif', 'int'); $object->import_key = GETPOST('import_key', 'int'); - if (empty($object->ref)) - { + if (empty($object->ref)) { $error++; setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors'); } - if (!$error) - { + if (!$error) { $result = $object->update($user); - if ($result > 0) - { + if ($result > 0) { $action = 'view'; } else { // Creation KO @@ -338,11 +330,9 @@ if (empty($reshook)) { } // Action to delete - if ($action == 'confirm_delete') - { + if ($action == 'confirm_delete') { $result = $object->delete($user); - if ($result > 0) - { + if ($result > 0) { // Delete OK setEventMessages("RecordDeleted", null, 'mesgs'); header("Location: ".dol_buildpath('/stock/list.php', 1)); @@ -468,9 +458,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Sell by if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { print ''; - print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker'); + print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->hasRight('stock', 'creer'), 'datepicker'); print ''; - print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker', '', null, null, '', 1, '', 'id', 'auto', array(), $action); + print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->hasRight('stock', 'creer'), 'datepicker', '', null, null, '', 1, '', 'id', 'auto', array(), $action); print ''; print ''; } @@ -478,35 +468,35 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Eat by if (empty($conf->global->PRODUCT_DISABLE_EATBY)) { print ''; - print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker'); + print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->hasRight('stock', 'creer'), 'datepicker'); print ''; - print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker', '', null, null, '', 1, '', 'id', 'auto', array(), $action); + print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->hasRight('stock', 'creer'), 'datepicker', '', null, null, '', 1, '', 'id', 'auto', array(), $action); print ''; print ''; } if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABILITY)) { - print ''.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).''; - print ''.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').''; + print ''.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->hasRight('stock', 'creer')).''; + print ''.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->hasRight('stock', 'creer'), 'datepicker').''; print ''; - // print ''.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).''; - // print ''.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').''; + // print ''.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->hasRight('stock', 'creer')).''; + // print ''.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->hasRight('stock', 'creer'), 'datepicker').''; // print ''; - print ''.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).''; - print ''.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').''; + print ''.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->hasRight('stock', 'creer')).''; + print ''.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->hasRight('stock', 'creer'), 'datepicker').''; print ''; } // Quality control if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) { - print ''.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).''; - print ''.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').''; + print ''.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->hasRight('stock', 'creer')).''; + print ''.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->hasRight('stock', 'creer'), 'datepicker').''; print ''; - print ''.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).''; - print ''.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'string').''; + print ''.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->hasRight('stock', 'creer')).''; + print ''.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->hasRight('stock', 'creer'), 'string').''; print ''; - print ''.$form->editfieldkey($langs->trans('Lifetime'), 'lifetime', $object->lifetime, $object, $user->rights->stock->creer).''; - print ''.$form->editfieldval($langs->trans('Lifetime'), 'lifetime', $object->lifetime, $object, $user->rights->stock->creer, 'string').''; + print ''.$form->editfieldkey($langs->trans('Lifetime'), 'lifetime', $object->lifetime, $object, $user->hasRight('stock', 'creer')).''; + print ''.$form->editfieldval($langs->trans('Lifetime'), 'lifetime', $object->lifetime, $object, $user->hasRight('stock', 'creer'), 'string').''; print ''; } @@ -539,8 +529,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } if (empty($reshook)) { - /*TODO if ($user->rights->stock->lire) - { + /*TODO + if ($user->hasRight('stock', 'lire')) { print ''."\n"; } */ From 2f698f8521e74c4ec35c772b7f1fed31385c9943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Fri, 1 Sep 2023 00:01:43 +0200 Subject: [PATCH 3/3] clean code --- htdocs/product/stock/productlot_document.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/htdocs/product/stock/productlot_document.php b/htdocs/product/stock/productlot_document.php index 38c5b0503d8..0f4cb68df98 100644 --- a/htdocs/product/stock/productlot_document.php +++ b/htdocs/product/stock/productlot_document.php @@ -26,7 +26,7 @@ /** * \file htdocs/product/stock/productlot_document.php * \ingroup product - * \brief Page of attached documents for porudct lots + * \brief Page of attached documents for product lots */ // Load Dolibarr environment @@ -38,11 +38,13 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; +global $conf, $db, $langs, $user; + // Load translation files required by the page $langs->loadLangs(array('other', 'products')); -$id = GETPOST('id', 'int'); -$ref = GETPOST('ref', 'alpha'); +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); @@ -97,9 +99,9 @@ if ($id || $ref) { } } -$usercanread = $user->rights->produit->lire; -$usercancreate = $user->rights->produit->creer; -$usercandelete = $user->rights->produit->supprimer; +$usercanread = $user->hasRight('produit', 'lire'); +$usercancreate = $user->hasRight('produit', 'creer'); +$usercandelete = $user->hasRight('produit', 'supprimer'); if (empty($upload_dir)) { $upload_dir = $conf->productbatch->multidir_output[$conf->entity]; @@ -111,7 +113,7 @@ $permtoedit = $user->rights->produit->creer; //$permissiontodelete = $usercandelete; // Security check -if (empty($conf->productbatch->enabled)) { +if (!isModEnabled('productbatch')) { accessforbidden('Module not enabled'); } $socid = 0;