diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 101f5995e6c..f52dc501bc8 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2020 OScss-Shop - * + * Copyright (C) 2023 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -267,6 +267,35 @@ class Fiscalyear extends CommonObject } } + /** + * getTooltipContentArray + * + * @param array $params ex option, infologin + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $langs; + + $langs->load('compta'); + + $datas = []; + $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("FiscalPeriod").''; + if (isset($this->statut)) { + $datas['picto'] .= ' '.$this->getLibStatut(5); + } + $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; + if (isset($this->date_start)) { + $datas['date_start'] .= '
'.$langs->trans('DateStart').': '.dol_print_date($this->date_start, 'day'); + } + if (isset($this->date_start)) { + $datas['date_end'] .= '
'.$langs->trans('DateEnd').': '.dol_print_date($this->date_end, 'day');; + } + + return $datas; + } + /** * Return clicable link of object (with eventually picto) * @@ -286,14 +315,27 @@ class Fiscalyear extends CommonObject if (!empty($conf->dol_no_mouse_hover)) { $notooltip = 1; // Force disable tooltips } - - $result = ''; - - $url = DOL_URL_ROOT.'/accountancy/admin/fiscalyear_card.php?id='.$this->id; - - if (empty($user->rights->accounting->fiscalyear->write)) { + $option = ''; + if (!$user->hasRight('accounting', 'fiscalyear', 'write')) { $option = 'nolink'; } + $result = ''; + $params = [ + 'id' => $this->id, + 'objecttype' => $this->element, + 'option', $option, + 'nofetch' => 1, + ]; + $classfortooltip = 'classfortooltip'; + $dataparams = ''; + if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { + $classfortooltip = 'classforajaxtooltip'; + $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; + $label = 'ToComplete'; + } else { + $label = implode($this->getTooltipContentArray($params)); + } + $url = DOL_URL_ROOT.'/accountancy/admin/fiscalyear_card.php?id='.$this->id; if ($option !== 'nolink') { // Add param to save lastsearch_values or not @@ -306,28 +348,14 @@ class Fiscalyear extends CommonObject } } - if ($short) { - return $url; - } - - $label = ''; - - if ($user->rights->accounting->fiscalyear->write) { - $label = ''.$langs->trans("FiscalPeriod").''; - $label .= '
'.$langs->trans('Ref').': '.$this->id; - if (isset($this->statut)) { - $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5); - } - } - $linkclose = ''; - if (empty($notooltip) && $user->rights->accounting->fiscalyear->write) { + if (empty($notooltip) && $user->hasRight('accounting', 'fiscalyear', 'write')) { if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("FiscalYear"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip"'; + $linkclose .= $dataparams.' class="'.$classfortooltip.'"'; } $linkstart = 'picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { $result .= $this->ref; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index db6cbaf72f8..b770c71f839 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -11414,6 +11414,10 @@ function getElementProperties($element_type) $classname = 'Websitepage'; $module = 'website'; $subelement = 'websitepage'; + } elseif ($element_type == 'fiscalyear') { + $classpath = 'core/class'; + $module = 'accounting'; + $subelement = 'fiscalyear'; } if (empty($classfile)) { diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 023f8ebafba..0d283ea623d 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -509,6 +509,11 @@ function restrictedArea(User $user, $features, $object = 0, $tableandshare = '', if ($subfeature == 'user' && $user->id == $objectid) { continue; // A user can always read its own card } + if ($subfeature == 'fiscalyear' && $user->hasRight('accounting', 'fiscalyear', 'write')) { + // only one right for fiscalyear + $tmpreadok = 1; + continue; + } if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) { $tmpreadok = 0; } elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) {