From 336a4c57e08acbaca8a12d367617cfacd8ea7c44 Mon Sep 17 00:00:00 2001 From: yannis Date: Tue, 24 Jun 2025 11:40:42 +0200 Subject: [PATCH] refactor: clean code --- htdocs/user/api_token/list.php | 37 +++++++++------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/htdocs/user/api_token/list.php b/htdocs/user/api_token/list.php index 20b744febdd..4389a93ef60 100644 --- a/htdocs/user/api_token/list.php +++ b/htdocs/user/api_token/list.php @@ -41,28 +41,25 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; */ // Load translation files required by page -$langs->loadLangs(array('companies', 'products', 'admin', 'users', 'languages', 'projects', 'members')); - -// Defini si peux lire/modifier permissions -$canreaduser = ($user->admin || $user->hasRight("user", "user", "read")); -$caneditfield = false; +$langs->loadLangs(array('admin', 'users')); +// Security check $id = GETPOSTINT('id'); $action = GETPOST('action', 'aZ09'); -$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userihm'; // To manage different context of search +$massaction = GETPOST('massaction', 'alpha'); if (!isset($id) || empty($id)) { accessforbidden(); } -'@phan-var-force int<1,max> $id'; +// Retrieve needed GETPOSTS for this file $toselect = GETPOST('toselect', 'array'); -// $user est le user qui edite, $id est l'id de l'utilisateur edite +// $user is current user, $id is id of edited user +$canreaduser = ($user->admin || $user->hasRight("user", "user", "read")); $caneditfield = ((($user->id == $id) && $user->hasRight("user", "self", "write")) || (($user->id != $id) && $user->hasRight("user", "user", "write"))); - // Security check $socid = 0; if ($user->socid > 0) { @@ -70,9 +67,6 @@ if ($user->socid > 0) { } $feature2 = (($socid && $user->hasRight("user", "self", "write")) ? '' : 'user'); -// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context -$hookmanager->initHooks(array('usercard', 'userihm', 'globalcard')); - $result = restrictedArea($user, 'user', $id, 'user&user', $feature2); if ($user->id != $id && !$canreaduser) { accessforbidden(); @@ -113,20 +107,12 @@ $help_url = ''; llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-card_param_ihm'); -$massaction = GETPOST('massaction', 'alpha'); $arrayofselected = is_array($toselect) ? $toselect : array(); $head = user_prepare_head($object); $title = $langs->trans("User"); -if ($action == 'edit') { - print '
'; - print ''; - print ''; - print ''; -} - print dol_get_fiche_head($head, 'apitoken', $title, -1, 'user'); $linkback = ''.$langs->trans("BackToList").''; @@ -140,13 +126,8 @@ $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->tra dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref); -$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); -$massactionbutton = $form->selectMassAction('', $arrayofmassactions); - print '
'; - print '
'; - print ''; // Login @@ -169,15 +150,16 @@ if (!empty($object->ldap_sid) && $object->status == 0) { print ''; } print ''."\n"; - print '
'; - print '
'; print dol_get_fiche_end(); print ''."\n"; +$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); +$massactionbutton = $form->selectMassAction('', $arrayofmassactions); + $morehtmlright = ''; //if (!empty($moreoptions['showhideaddbutton']) && $conf->use_javascript_ajax) { $tmpurlforbutton = DOL_URL_ROOT.'/user/api_token/list.php?id='.$id.'&action=create'; @@ -187,7 +169,6 @@ $morehtmlright .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle print ''."\n"; print ''; - print load_fiche_titre($langs->trans("ListOfTokensForUser"), $morehtmlright, '', 0, '', '', $massactionbutton); print '
';