From 1f38e54e7814a01a76c6557e32d706fa5940cc93 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 15 Oct 2023 15:32:35 +0200 Subject: [PATCH] Clean code --- htdocs/admin/modules.php | 2 +- htdocs/api/admin/explorer_withredoc.php | 2 +- htdocs/api/class/api_login.class.php | 2 +- htdocs/api/index.php | 2 +- htdocs/asset/class/asset.class.php | 2 +- htdocs/asset/tpl/linkedobjectblock.tpl.php | 2 +- htdocs/barcode/printsheet.php | 2 +- htdocs/blockedlog/admin/blockedlog.php | 2 +- htdocs/blockedlog/ajax/check_signature.php | 2 +- htdocs/blockedlog/class/authority.class.php | 2 +- htdocs/bom/bom_card.php | 6 +- htdocs/bom/bom_list.php | 2 +- htdocs/bom/class/bom.class.php | 2 +- htdocs/bookcal/class/availabilities.class.php | 2 +- htdocs/bookmarks/admin/bookmark.php | 2 +- htdocs/bookmarks/bookmarks.lib.php | 8 +- htdocs/categories/card.php | 6 +- htdocs/categories/edit.php | 2 +- htdocs/categories/index.php | 6 +- htdocs/categories/photos.php | 10 +- htdocs/categories/traduction.php | 4 +- htdocs/categories/viewcat.php | 20 ++-- htdocs/comm/mailing/card.php | 18 ++-- htdocs/comm/propal/card.php | 2 +- htdocs/commande/card.php | 8 +- htdocs/commande/class/commande.class.php | 22 ++-- htdocs/commande/class/commandestats.class.php | 12 +-- htdocs/commande/customer.php | 8 +- htdocs/commande/index.php | 18 ++-- htdocs/commande/list.php | 4 +- htdocs/commande/list_det.php | 8 +- htdocs/commande/stats/index.php | 10 +- htdocs/compta/bank/bankentries_list.php | 20 ++-- htdocs/compta/bank/bilan.php | 2 +- htdocs/compta/bank/card.php | 8 +- htdocs/compta/bank/categ.php | 2 +- htdocs/compta/bank/class/account.class.php | 2 +- htdocs/compta/bank/info.php | 2 +- htdocs/compta/bank/line.php | 34 +++--- htdocs/compta/bank/list.php | 4 +- htdocs/compta/bank/releve.php | 4 +- htdocs/compta/bank/transfer.php | 4 +- htdocs/compta/bank/various_payment/card.php | 4 +- .../compta/bank/various_payment/document.php | 2 +- htdocs/compta/bank/various_payment/info.php | 2 +- htdocs/compta/bank/various_payment/list.php | 2 +- .../compta/cashcontrol/cashcontrol_list.php | 2 +- htdocs/compta/cashcontrol/report.php | 2 +- htdocs/compta/charges/index.php | 4 +- htdocs/compta/clients.php | 6 +- htdocs/compta/deplacement/card.php | 38 +++---- htdocs/compta/deplacement/index.php | 8 +- htdocs/compta/deplacement/list.php | 6 +- htdocs/compta/deplacement/stats/index.php | 8 +- htdocs/compta/facture/card-rec.php | 4 +- htdocs/compta/facture/card.php | 4 +- htdocs/compta/facture/class/facture.class.php | 18 ++-- .../facture/class/facturestats.class.php | 16 +-- .../compta/facture/invoicetemplate_list.php | 2 +- htdocs/compta/facture/list.php | 10 +- htdocs/compta/facture/prelevement.php | 2 +- htdocs/compta/facture/stats/index.php | 4 +- htdocs/compta/index.php | 14 +-- htdocs/compta/localtax/list.php | 2 +- htdocs/compta/paiement/cheque/card.php | 26 ++--- .../cheque/class/remisecheque.class.php | 10 +- htdocs/compta/paiement/cheque/list.php | 2 +- .../compta/paiement/class/paiement.class.php | 6 +- htdocs/compta/paiement/list.php | 4 +- htdocs/compta/paiement/rapport.php | 2 +- htdocs/compta/payment_sc/card.php | 2 +- htdocs/compta/payment_vat/card.php | 4 +- htdocs/compta/paymentbybanktransfer/index.php | 4 +- htdocs/compta/prelevement/card.php | 16 +-- htdocs/compta/prelevement/demandes.php | 4 +- htdocs/compta/prelevement/index.php | 4 +- htdocs/compta/prelevement/line.php | 4 +- htdocs/compta/sociales/card.php | 22 ++-- htdocs/compta/sociales/document.php | 6 +- htdocs/compta/sociales/info.php | 6 +- htdocs/compta/sociales/note.php | 4 +- htdocs/compta/tva/card.php | 38 +++---- htdocs/compta/tva/document.php | 4 +- htdocs/compta/tva/info.php | 6 +- htdocs/contact/agenda.php | 2 +- .../default/tpl/contactcard_view.tpl.php | 4 +- htdocs/contact/card.php | 12 +-- htdocs/contact/class/contact.class.php | 34 +++--- htdocs/contact/consumption.php | 4 +- htdocs/contact/list.php | 4 +- htdocs/contact/perso.php | 2 +- htdocs/core/actions_massactions.inc.php | 20 ++-- htdocs/core/actions_printing.inc.php | 2 +- htdocs/core/actions_sendmails.inc.php | 6 +- htdocs/core/bookmarks_page.php | 2 +- htdocs/core/class/CMailFile.class.php | 10 +- htdocs/core/class/commonobject.class.php | 30 +++--- htdocs/core/class/html.form.class.php | 18 ++-- htdocs/core/class/html.formadmin.class.php | 2 +- htdocs/core/class/html.formfile.class.php | 2 +- htdocs/core/class/html.formmail.class.php | 4 +- htdocs/core/class/html.formmargin.class.php | 2 +- htdocs/core/class/html.formother.class.php | 4 +- htdocs/core/class/html.formprojet.class.php | 8 +- htdocs/core/class/html.formsetup.class.php | 32 ++++-- htdocs/core/class/ldap.class.php | 2 +- htdocs/core/class/timespent.class.php | 2 +- htdocs/core/class/translate.class.php | 2 +- htdocs/core/class/utils.class.php | 4 +- htdocs/core/lib/admin.lib.php | 2 +- htdocs/core/lib/agenda.lib.php | 10 +- htdocs/core/lib/company.lib.php | 8 +- htdocs/core/lib/contact.lib.php | 6 +- htdocs/core/lib/cron.lib.php | 8 +- htdocs/core/lib/emailing.lib.php | 2 +- htdocs/core/lib/files.lib.php | 24 ++--- htdocs/core/lib/functions.lib.php | 14 +-- htdocs/core/lib/invoice.lib.php | 28 ++--- htdocs/core/lib/member.lib.php | 4 +- htdocs/core/lib/payments.lib.php | 24 ++--- htdocs/core/lib/pdf.lib.php | 4 +- htdocs/core/lib/product.lib.php | 10 +- htdocs/core/lib/project.lib.php | 12 +-- htdocs/core/lib/propal.lib.php | 10 +- htdocs/core/lib/security.lib.php | 102 +++++++++--------- htdocs/core/lib/sendings.lib.php | 4 +- htdocs/core/lib/stock.lib.php | 2 +- htdocs/core/lib/usergroups.lib.php | 12 +-- htdocs/core/lib/website.lib.php | 2 +- htdocs/core/lib/website2.lib.php | 2 +- htdocs/core/menus/standard/auguria.lib.php | 8 +- .../asset/doc/pdf_standard_asset.modules.php | 2 +- .../cheque/mod_chequereceipt_thyme.php | 2 +- .../commande/doc/pdf_einstein.modules.php | 2 +- .../contract/doc/pdf_strato.modules.php | 2 +- .../delivery/doc/pdf_storm.modules.php | 2 +- .../delivery/doc/pdf_typhon.modules.php | 2 +- .../expedition/doc/pdf_espadon.modules.php | 2 +- .../expedition/doc/pdf_merou.modules.php | 2 +- .../expedition/doc/pdf_rouget.modules.php | 2 +- .../doc/pdf_standard.modules.php | 2 +- .../modules/facture/doc/pdf_crabe.modules.php | 2 +- .../facture/doc/pdf_sponge.modules.php | 2 +- .../fichinter/doc/pdf_soleil.modules.php | 2 +- .../modules/member/doc/pdf_standard.class.php | 4 +- htdocs/core/modules/modAgenda.class.php | 2 +- htdocs/core/modules/modCommande.class.php | 4 +- htdocs/core/modules/modDeplacement.class.php | 6 +- htdocs/core/modules/modExpedition.class.php | 4 +- htdocs/core/modules/modFacture.class.php | 8 +- htdocs/core/modules/modFournisseur.class.php | 12 +-- htdocs/core/modules/modPropale.class.php | 4 +- htdocs/core/modules/modReception.class.php | 4 +- htdocs/core/modules/modSociete.class.php | 6 +- .../movement/doc/pdf_standard.modules.php | 2 +- .../modules/mrp/doc/pdf_vinci.modules.php | 2 +- .../oauth/stripelive_oauthcallback.php | 2 +- .../oauth/stripetest_oauthcallback.php | 2 +- .../product/doc/pdf_standard.modules.php | 2 +- .../project/doc/pdf_baleine.modules.php | 2 +- .../project/doc/pdf_beluga.modules.php | 2 +- .../project/doc/pdf_timespent.modules.php | 2 +- .../modules/propale/doc/pdf_azur.modules.php | 2 +- .../modules/propale/doc/pdf_cyan.modules.php | 2 +- .../modules/rapport/pdf_paiement.class.php | 8 +- .../reception/doc/pdf_squille.modules.php | 2 +- .../societe/mod_codecompta_aquarium.php | 10 +- .../societe/mod_codecompta_digitaria.php | 12 +-- .../stock/doc/pdf_standard.modules.php | 2 +- .../stocktransfer/doc/pdf_eagle.modules.php | 2 +- .../doc/pdf_eagle_proforma.modules.php | 2 +- .../doc/pdf_canelle.modules.php | 2 +- .../supplier_order/doc/pdf_cornas.modules.php | 2 +- .../doc/pdf_muscadet.modules.php | 2 +- .../doc/pdf_standard.modules.php | 2 +- .../doc/pdf_aurore.modules.php | 2 +- .../doc/pdf_zenith.modules.php | 2 +- .../core/modules/syslog/mod_syslog_file.php | 2 +- htdocs/core/photos_resize.php | 16 +-- htdocs/core/tpl/contacts.tpl.php | 6 +- htdocs/core/tpl/login.tpl.php | 4 +- htdocs/core/tpl/objectline_create.tpl.php | 24 ++--- htdocs/core/tpl/objectline_edit.tpl.php | 14 +-- htdocs/core/tpl/objectline_title.tpl.php | 6 +- htdocs/core/tpl/objectline_view.tpl.php | 6 +- htdocs/core/tpl/passwordforgotten.tpl.php | 4 +- htdocs/core/tpl/passwordreset.tpl.php | 4 +- ...ntOrganization_EventOrganization.class.php | 4 +- ...interface_50_modLdap_Ldapsynchro.class.php | 2 +- ...terface_50_modTicket_TicketEmail.class.php | 6 +- 190 files changed, 696 insertions(+), 680 deletions(-) mode change 100755 => 100644 htdocs/core/class/timespent.class.php diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index f3b6dfcf5fb..2314007b8c9 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -1158,7 +1158,7 @@ if ($mode == 'marketplace') { - global->API_RESTRICT_ON_IP)) { $allowedip = explode(' ', $conf->global->API_RESTRICT_ON_IP); $ipremote = getUserRemoteIP(); if (!in_array($ipremote, $allowedip)) { - dol_syslog('Remote ip is '.$ipremote.', not into list '.$conf->global->API_RESTRICT_ON_IP); + dol_syslog('Remote ip is '.$ipremote.', not into list ' . getDolGlobalString('API_RESTRICT_ON_IP')); print 'APIs are not allowed from the IP '.$ipremote; header('HTTP/1.1 503 API not allowed from your IP '.$ipremote); //session_destroy(); diff --git a/htdocs/api/class/api_login.class.php b/htdocs/api/class/api_login.class.php index e69de5f62fc..42b87a56caa 100644 --- a/htdocs/api/class/api_login.class.php +++ b/htdocs/api/class/api_login.class.php @@ -144,7 +144,7 @@ class Login // Renew the hash if (empty($tmpuser->api_key) || $reset) { $tmpuser->getrights(); - if (empty($tmpuser->rights->user->self->creer)) { + if (!$tmpuser->hasRight('user', 'self', 'creer')) { if (empty($tmpuser->api_key)) { throw new RestException(403, 'No API token set for this user and user need write permission on itself to reset its API token'); } else { diff --git a/htdocs/api/index.php b/htdocs/api/index.php index ebf6c7e8091..008af056681 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -201,7 +201,7 @@ if (!empty($conf->global->API_RESTRICT_ON_IP)) { $allowedip = explode(' ', $conf->global->API_RESTRICT_ON_IP); $ipremote = getUserRemoteIP(); if (!in_array($ipremote, $allowedip)) { - dol_syslog('Remote ip is '.$ipremote.', not into list '.$conf->global->API_RESTRICT_ON_IP); + dol_syslog('Remote ip is '.$ipremote.', not into list ' . getDolGlobalString('API_RESTRICT_ON_IP')); print 'APIs are not allowed from the IP '.$ipremote; header('HTTP/1.1 503 API not allowed from your IP '.$ipremote); //session_destroy(); diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index 7f6c95e8d36..0fe877ae139 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -1525,7 +1525,7 @@ class Asset extends CommonObject if (!empty($conf->global->ASSET_ASSET_ADDON)) { $mybool = false; - $file = $conf->global->ASSET_ASSET_ADDON.".php"; + $file = getDolGlobalString('ASSET_ASSET_ADDON') . ".php"; $classname = $conf->global->ASSET_ASSET_ADDON; // Include file with class diff --git a/htdocs/asset/tpl/linkedobjectblock.tpl.php b/htdocs/asset/tpl/linkedobjectblock.tpl.php index 11d94714db8..2e5c85d4d5d 100644 --- a/htdocs/asset/tpl/linkedobjectblock.tpl.php +++ b/htdocs/asset/tpl/linkedobjectblock.tpl.php @@ -55,7 +55,7 @@ foreach ($linkedObjectBlock as $key => $objectlink) { echo ''.$objectlink->label.''; echo ''.dol_print_date($objectlink->date_start, 'day').''; echo ''; - if ($user->rights->asset->read) { + if ($user->hasRight('asset', 'read')) { $total = $total + $objectlink->acquisition_value_ht; echo price($objectlink->acquisition_value_ht); } diff --git a/htdocs/barcode/printsheet.php b/htdocs/barcode/printsheet.php index 486e65544aa..f257c26196c 100644 --- a/htdocs/barcode/printsheet.php +++ b/htdocs/barcode/printsheet.php @@ -393,7 +393,7 @@ jQuery(document).ready(function() { print ''; print '
'; -if (!empty($user->rights->produit->lire) || $user->hasRight('service', 'lire')) { +if ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire')) { print ''; print '
'; print '
'; diff --git a/htdocs/blockedlog/admin/blockedlog.php b/htdocs/blockedlog/admin/blockedlog.php index 3ffb4d450e8..54737ff96af 100644 --- a/htdocs/blockedlog/admin/blockedlog.php +++ b/htdocs/blockedlog/admin/blockedlog.php @@ -127,7 +127,7 @@ if (!empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) { print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; diff --git a/htdocs/blockedlog/ajax/check_signature.php b/htdocs/blockedlog/ajax/check_signature.php index ab2f6b0427f..5f7121db68c 100644 --- a/htdocs/blockedlog/ajax/check_signature.php +++ b/htdocs/blockedlog/ajax/check_signature.php @@ -73,7 +73,7 @@ if (is_array($bocks)) { $hash = $auth->getBlockchainHash(); // Call external authority -$url = $conf->global->BLOCKEDLOG_AUTHORITY_URL.'/blockedlog/ajax/authority.php?s='.urlencode($auth->signature).'&h='.urlencode($hash); +$url = getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL') . '/blockedlog/ajax/authority.php?s='.urlencode($auth->signature).'&h='.urlencode($hash); $resarray = getURLContent($url, 'GET', '', 1, array(), array(), 2); $res = $resarray['content']; diff --git a/htdocs/blockedlog/class/authority.class.php b/htdocs/blockedlog/class/authority.class.php index 9da736d30ec..496339ddf45 100644 --- a/htdocs/blockedlog/class/authority.class.php +++ b/htdocs/blockedlog/class/authority.class.php @@ -316,7 +316,7 @@ class BlockedLogAuthority if (is_array($blocks)) { foreach ($blocks as &$block) { - $url = $conf->global->BLOCKEDLOG_AUTHORITY_URL.'/blockedlog/ajax/authority.php?s='.$signature.'&b='.$block->signature; + $url = getDolGlobalString('BLOCKEDLOG_AUTHORITY_URL') . '/blockedlog/ajax/authority.php?s='.$signature.'&b='.$block->signature; $res = getURLContent($url); echo $block->signature.' '.$url.' '.$res['content'].'
'; diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index c82548c743e..b8d7eca4b19 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -149,7 +149,7 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; // Add line - if ($action == 'addline' && $user->rights->bom->write) { + if ($action == 'addline' && $user->hasRight('bom', 'write')) { $langs->load('errors'); $error = 0; $predef = ''; @@ -235,7 +235,7 @@ if (empty($reshook)) { } // Update line - if ($action == 'updateline' && $user->rights->bom->write) { + if ($action == 'updateline' && $user->hasRight('bom', 'write')) { $langs->load('errors'); $error = 0; @@ -732,7 +732,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Create MO if (isModEnabled('mrp')) { - if ($object->status == $object::STATUS_VALIDATED && !empty($user->rights->mrp->write)) { + if ($object->status == $object::STATUS_VALIDATED && $user->hasRight('mrp', 'write')) { print ''.$langs->trans("CreateMO").''."\n"; } } diff --git a/htdocs/bom/bom_list.php b/htdocs/bom/bom_list.php index 40983f8a22e..2826ed9b703 100644 --- a/htdocs/bom/bom_list.php +++ b/htdocs/bom/bom_list.php @@ -501,7 +501,7 @@ print ''; $newcardbutton = ''; $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition')); $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition')); -$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bom/bom_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $user->rights->bom->write); +$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bom/bom_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $user->hasRight('bom', 'write')); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1); diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 3cc3b6c6770..798da88add6 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -875,7 +875,7 @@ class BOM extends CommonObject if (!empty($conf->global->BOM_ADDON)) { $mybool = false; - $file = $conf->global->BOM_ADDON.".php"; + $file = getDolGlobalString('BOM_ADDON') . ".php"; $classname = $conf->global->BOM_ADDON; // Include file with class diff --git a/htdocs/bookcal/class/availabilities.class.php b/htdocs/bookcal/class/availabilities.class.php index 90dd80db888..11b2c2e99e3 100644 --- a/htdocs/bookcal/class/availabilities.class.php +++ b/htdocs/bookcal/class/availabilities.class.php @@ -951,7 +951,7 @@ class Availabilities extends CommonObject if (!empty($conf->global->BOOKCAL_AVAILABILITIES_ADDON)) { $mybool = false; - $file = $conf->global->BOOKCAL_AVAILABILITIES_ADDON.".php"; + $file = getDolGlobalString('BOOKCAL_AVAILABILITIES_ADDON') . ".php"; $classname = $conf->global->BOOKCAL_AVAILABILITIES_ADDON; // Include file with class diff --git a/htdocs/bookmarks/admin/bookmark.php b/htdocs/bookmarks/admin/bookmark.php index 74b44bd8f9b..2233544fd24 100644 --- a/htdocs/bookmarks/admin/bookmark.php +++ b/htdocs/bookmarks/admin/bookmark.php @@ -77,7 +77,7 @@ print "\n"; print ''; print $langs->trans("NbOfBoomarkToShow").''; -print ''; +print ''; print ''; print '
'; diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index 5d05c42622f..6b0d7fad6a2 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -88,7 +88,7 @@ function printDropdownBookmarksList() // Url to go on create new bookmark page $newbtn = ''; - if (!empty($user->rights->bookmark->creer)) { + if ($user->hasRight('bookmark', 'creer')) { if (!preg_match('/bookmarks\/card.php/', $_SERVER['PHP_SELF'])) { //$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url); $urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&url='.urlencode($url); @@ -127,10 +127,10 @@ function printDropdownBookmarksList() //$searchForm .= ''; $searchForm .= ''; $searchForm .= ''; + $searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.($user->hasRight('bookmark', 'creer') ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...').'">'; + $searchForm .= dol_escape_htmltag($user->hasRight('bookmark', 'creer') ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...'; // Url to go on create new bookmark page - if (!empty($user->rights->bookmark->creer)) { + if ($user->hasRight('bookmark', 'creer')) { if (!preg_match('/bookmarks\/card.php/', $_SERVER['PHP_SELF'])) { $urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&url='.urlencode($url); $searchForm .= '