diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b20ec7cd22e..8c845d9cdacb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -219,6 +219,8 @@ The present file will list all changes made to the project; according to the
- `js/Forms/FaIconSelector.js` and therefore `window.GLPI.Forms.FaIconSelector` has been deprecated and replaced by `js/modules/Form/WebIconSelector.js`
- `linkuser_types`, `linkgroup_types`, `linkuser_tech_types`, `linkgroup_tech_types` configuration entries have been merged in a unique `assignable_types` configuration entry.
- Usage of the `front/dropdown.common.php` and the `dropdown.common.form.php` files. There is now a generic controller that will serve the search and form pages of any `Dropdown` class.
+- Usage of the `$link` parameter in `formatUserName()` and `DbUtils::formatUserName()`. Use `formatUserLink()` or `DbUtils::formatUserLink()` instead.
+- Usage of the `$link` parameter in `getUserName()` and `DbUtils::getUserName()`. Use `getUserLink()`, `DbUtils::getUserLink()`, or `User::getInfoCard()` instead.
- `Auth::getErr()`
- `AuthLDAP::dropdownUserDeletedActions()`
- `AuthLDAP::getOptions()`
@@ -311,6 +313,7 @@ The present file will list all changes made to the project; according to the
- `CommonGLPI::showDislayOptions()`
- `CommonITILActor::showUserNotificationForm()`
- `CommonITILActor::showSupplierNotificationForm()`
+- `CommonITILObject::getAssignName()`
- `CommonITILValidation::alreadyExists()`
- `CommonITILValidation::getTicketStatusNumber()`
- `CommonTreeDropdown::sanitizeSeparatorInCompletename()`
@@ -496,6 +499,7 @@ The present file will list all changes made to the project; according to the
- `ajax/planningcheck.php` script. Use `Planning::showPlanningCheck()` instead.
- `test_ldap` and `test_ldap_replicate` actions in `front/authldap.form.php`. Use `ajax/ldap.php` instead.
- `ajax/ticketsatisfaction.php` and `ajax/changesatisfaction.php` scripts. Access `ajax/commonitilsatisfaction.php` directly instead.
+- Usage of the `$cut` parameter in `formatUserName()` and `DbUtils::formatUserName()`.
## [10.0.17] unreleased
diff --git a/ajax/comments.php b/ajax/comments.php
index 4562241f8d28..6fadc953ff24 100644
--- a/ajax/comments.php
+++ b/ajax/comments.php
@@ -60,36 +60,32 @@
switch ($_POST["itemtype"]) {
case User::getType():
+ $link = null;
+ $comments = [];
if ($_POST['value'] == 0) {
- $tmpname = [
- 'link' => $CFG_GLPI['root_doc'] . "/front/user.php",
- 'comment' => "",
- ];
+ $link = $CFG_GLPI['root_doc'] . "/front/user.php";
} else {
$user = new \User();
if (is_array($_POST["value"])) {
- $comments = [];
foreach ($_POST["value"] as $users_id) {
if ($user->getFromDB($users_id) && $user->canView()) {
- $username = getUserName($users_id, 2);
- $comments[] = $username['comment'] ?? "";
+ $comments[] = $user->getInfoCard();
}
}
- $tmpname = [
- 'comment' => implode("
", $comments),
- ];
unset($_POST['withlink']);
} else {
if ($user->getFromDB($_POST['value']) && $user->canView()) {
- $tmpname = getUserName($_POST["value"], 2);
+ $link = $user->getLinkURL();
+ $comments[] = $user->getInfoCard();
}
}
}
- echo($tmpname["comment"] ?? '');
- if (isset($_POST['withlink']) && isset($tmpname['link'])) {
+ echo(implode("
", $comments));
+
+ if (isset($_POST['withlink']) && $link !== null) {
echo "\n";
}
break;
diff --git a/front/stat.graph.php b/front/stat.graph.php
index 133e79033b3b..42dbe6fa9d8c 100644
--- a/front/stat.graph.php
+++ b/front/stat.graph.php
@@ -88,12 +88,10 @@
$val1 = $_GET["id"];
$val2 = "";
$values = Stat::getItems($_GET["itemtype"], $_GET["date1"], $_GET["date2"], $_GET["type"]);
- $link = User::canView() ? 1 : 0;
- $name = $item->getAssignName($_GET["id"], 'User', $link);
$title = sprintf(
__s('%1$s: %2$s'),
__s('Technician'),
- $link ? $name : htmlspecialchars($name)
+ getUserLink($_GET["id"])
);
break;
@@ -101,12 +99,11 @@
$val1 = $_GET["id"];
$val2 = "";
$values = Stat::getItems($_GET["itemtype"], $_GET["date1"], $_GET["date2"], $_GET["type"]);
- $link = Supplier::canView() ? 1 : 0;
- $name = $item->getAssignName($_GET["id"], 'Supplier', $link);
+ $supplier = Supplier::getById($_GET["id"]);
$title = sprintf(
__s('%1$s: %2$s'),
Supplier::getTypeName(1),
- $link ? $name : htmlspecialchars($name)
+ $supplier !== false ? $supplier->getLink(['comments' => true]) : ''
);
break;
@@ -115,12 +112,10 @@
$val1 = $_GET["id"];
$val2 = "";
$values = Stat::getItems($_GET["itemtype"], $_GET["date1"], $_GET["date2"], $_GET["type"]);
- $link = User::canView() ? 1 : 0;
- $name = getUserName($_GET["id"], $link);
$title = sprintf(
__s('%1$s: %2$s'),
User::getTypeName(1),
- $link ? $name : htmlspecialchars($name)
+ getUserLink($_GET["id"])
);
break;
diff --git a/src/Change.php b/src/Change.php
index 685a137fcc3b..900de7cedacf 100644
--- a/src/Change.php
+++ b/src/Change.php
@@ -1224,9 +1224,8 @@ public static function showCentralList($start, $status = "process", $showgroupch
) {
foreach ($change->users[CommonITILActor::REQUESTER] as $d) {
if ($d["users_id"] > 0) {
- $userdata = getUserName($d["users_id"], 2);
$name = '' .
- $userdata['name'];
+ htmlspecialchars(getUserName($d["users_id"]));
$requesters[] = $name;
} else {
$requesters[] = '' .
@@ -1451,16 +1450,17 @@ public static function showVeryShort($ID, $forcetab = '')
&& count($change->users[CommonITILActor::REQUESTER])
) {
foreach ($change->users[CommonITILActor::REQUESTER] as $d) {
- if ($d["users_id"] > 0) {
- $userdata = getUserName($d["users_id"], 2);
- $name = "" . $userdata['name'] . "";
+ $user = new User();
+ if ($d["users_id"] > 0 && $user->getFromDB($d["users_id"])) {
+ $name = "" . htmlspecialchars($user->getName()) . "";
if ($viewusers) {
$name = sprintf(
- __('%1$s %2$s'),
+ __s('%1$s %2$s'),
$name,
Html::showToolTip(
- $userdata["comment"],
- ['link' => $userdata["link"],
+ $user->getInfoCard(),
+ [
+ 'link' => $user->getLinkURL(),
'display' => false
]
)
diff --git a/src/CommonDBTM.php b/src/CommonDBTM.php
index c27ed3ca0815..0c2bef7e2314 100644
--- a/src/CommonDBTM.php
+++ b/src/CommonDBTM.php
@@ -4911,11 +4911,14 @@ public function getValueToDisplay($field_id_or_search_options, $values, $options
return $searchoptions['emptylabel'];
}
+ $user = new User();
if ($searchoptions['table'] == 'glpi_users') {
+ if (!$user->getFromDB($value)) {
+ return '';
+ }
if ($param['comments']) {
- $tmp = getUserName($value, 2);
- return $tmp['name'] . ' ' . Html::showToolTip(
- $tmp['comment'],
+ return $user->getLink() . ' ' . Html::showToolTip(
+ $user->getInfoCard(),
['display' => false]
);
}
diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php
index cfdfb4bb3d1c..475c92d2b577 100644
--- a/src/CommonITILObject.php
+++ b/src/CommonITILObject.php
@@ -5542,35 +5542,6 @@ public static function getActionTime($actiontime)
return Html::timestampToString($actiontime, false);
}
-
- /**
- * @param $ID
- * @param $itemtype
- * @param $link (default 0)
- **/
- public static function getAssignName($ID, $itemtype, $link = 0)
- {
-
- switch ($itemtype) {
- case 'User':
- if ($ID == 0) {
- return "";
- }
- return getUserName($ID, $link);
-
- case 'Supplier':
- case 'Group':
- $item = new $itemtype();
- if ($item->getFromDB($ID)) {
- if ($link) {
- return $item->getLink(['comments' => true]);
- }
- return $item->getNameID();
- }
- return "";
- }
- }
-
/**
* Form to add a solution to an ITIL object
*
@@ -5960,12 +5931,11 @@ public function getUsedAuthorBetween($date1 = '', $date2 = '')
foreach ($iterator as $line) {
$tab[] = [
'id' => $line['users_id'],
- 'link' => formatUserName(
+ 'link' => formatUserLink(
$line['users_id'],
$line['name'],
$line['realname'],
- $line['firstname'],
- 1
+ $line['firstname']
)
];
}
@@ -6028,12 +5998,11 @@ public function getUsedRecipientBetween($date1 = '', $date2 = '')
foreach ($iterator as $line) {
$tab[] = [
'id' => $line['user_id'],
- 'link' => formatUserName(
+ 'link' => formatUserLink(
$line['user_id'],
$line['name'],
$line['realname'],
$line['firstname'],
- 1
)
];
}
@@ -6444,7 +6413,6 @@ public function getUsedTechBetween($date1 = '', $date2 = '')
$linkclass = new $this->userlinkclass();
$linktable = $linkclass->getTable();
- $showlink = User::canView();
$ctable = $this->getTable();
$criteria = [
@@ -6499,7 +6467,7 @@ public function getUsedTechBetween($date1 = '', $date2 = '')
foreach ($iterator as $line) {
$tab[] = [
'id' => $line['users_id'],
- 'link' => formatUserName($line['users_id'], $line['name'], $line['realname'], $line['firstname'], $showlink),
+ 'link' => formatUserLink($line['users_id'], $line['name'], $line['realname'], $line['firstname']),
];
}
return $tab;
@@ -6519,7 +6487,6 @@ public function getUsedTechTaskBetween($date1 = '', $date2 = '')
global $DB;
$linktable = getTableForItemType($this->getType() . 'Task');
- $showlink = User::canView();
$ctable = $this->getTable();
$criteria = [
@@ -6592,7 +6559,7 @@ public function getUsedTechTaskBetween($date1 = '', $date2 = '')
foreach ($iterator as $line) {
$tab[] = [
'id' => $line['users_id'],
- 'link' => formatUserName($line['users_id'], $line['name'], $line['realname'], $line['firstname'], $showlink),
+ 'link' => formatUserLink($line['users_id'], $line['name'], $line['realname'], $line['firstname']),
];
}
return $tab;
@@ -6906,18 +6873,21 @@ public static function showShort($id, $options = [])
// eighth Column
$eighth_col = "";
foreach ($item->getUsers(CommonITILActor::REQUESTER) as $d) {
- $userdata = getUserName($d["users_id"], 2);
- $eighth_col .= sprintf(
- __('%1$s %2$s'),
- "" . $userdata['name'] . "",
- Html::showToolTip(
- $userdata["comment"],
- ['link' => $userdata["link"],
- 'display' => false
- ]
- )
- );
- $eighth_col .= "
";
+ $user = new User();
+ if ($user->getFromDB($d["users_id"])) {
+ $eighth_col .= sprintf(
+ __('%1$s %2$s'),
+ "" . htmlspecialchars($user->getName()) . "",
+ Html::showToolTip(
+ $user->getInfoCard(),
+ [
+ 'link' => $user->getLinkURL(),
+ 'display' => false
+ ]
+ )
+ );
+ $eighth_col .= "
";
+ }
}
foreach ($item->getGroups(CommonITILActor::REQUESTER) as $d) {
@@ -6930,6 +6900,7 @@ public static function showShort($id, $options = [])
// ninth column
$ninth_col = "";
foreach ($item->getUsers(CommonITILActor::ASSIGN) as $d) {
+ $user = new User();
if (
Session::getCurrentInterface() == 'helpdesk'
&& !empty($anon_name = User::getAnonymizedNameForUser(
@@ -6938,14 +6909,14 @@ public static function showShort($id, $options = [])
))
) {
$ninth_col .= $anon_name;
- } else {
- $userdata = getUserName($d["users_id"], 2);
+ } elseif ($user->getFromDB($d["users_id"])) {
$ninth_col .= sprintf(
__('%1$s %2$s'),
- "" . $userdata['name'] . "",
+ "" . htmlspecialchars($user->getName()) . "",
Html::showToolTip(
- $userdata["comment"],
- ['link' => $userdata["link"],
+ $user->getInfoCard(),
+ [
+ 'link' => $user->getLinkURL(),
'display' => false
]
)
@@ -7338,22 +7309,22 @@ public static function getDatatableEntries(array $data, $params = []): array
$entry['requester'] = '';
foreach ($item->getUsers(CommonITILActor::REQUESTER) as $d) {
- if (!isset($user_cache[$d["users_id"]])) {
- $userdata = getUserName($d["users_id"], 2);
+ $user = new User();
+ if (!isset($user_cache[$d["users_id"]]) && $user->getFromDB($d["users_id"])) {
$user_value = sprintf(
- __('%1$s %2$s'),
- htmlspecialchars($userdata['name']),
+ __s('%1$s %2$s'),
+ htmlspecialchars($user->getName()),
Html::showToolTip(
- $userdata["comment"],
+ $user->getInfoCard(),
[
- 'link' => $userdata["link"],
+ 'link' => $user->getLinkURL(),
'display' => false
]
)
);
$user_cache[$d['users_id']] = $user_value;
}
- $entry['requester'] .= $user_cache[$d['users_id']] . '
';
+ $entry['requester'] .= isset($user_cache[$d["users_id"]]) ? $user_cache[$d['users_id']] . '
' : '';
}
foreach ($item->getGroups(CommonITILActor::REQUESTER) as $d) {
if (!isset($group_cache[$d['groups_id']])) {
@@ -7367,11 +7338,22 @@ public static function getDatatableEntries(array $data, $params = []): array
if (Session::getCurrentInterface() === 'helpdesk' && !empty($anon_name = User::getAnonymizedNameForUser($d['users_id'], $item->getEntityID()))) {
$entry['assigned'] .= htmlspecialchars($anon_name) . '
';
} else {
- if (!isset($user_cache[$d['users_id']])) {
- $user_cache[$d['users_id']] = getUserName($d['users_id'], 2);
+ $user = new User();
+ if (!isset($user_cache[$d["users_id"]]) && $user->getFromDB($d["users_id"])) {
+ $user_value = sprintf(
+ __s('%1$s %2$s'),
+ htmlspecialchars($user->getName()),
+ Html::showToolTip(
+ $user->getInfoCard(),
+ [
+ 'link' => $user->getLinkURL(),
+ 'display' => false
+ ]
+ )
+ );
+ $user_cache[$d['users_id']] = $user_value;
}
- $user_name = is_array($user_cache[$d['users_id']]) ? htmlspecialchars($user_cache[$d['users_id']]['name']) : $user_cache[$d['users_id']];
- $entry['assigned'] .= $user_name . '
';
+ $entry['assigned'] .= isset($user_cache[$d["users_id"]]) ? $user_cache[$d['users_id']] . '
' : '';
}
}
foreach ($item->getGroups(CommonITILActor::ASSIGN) as $d) {
@@ -7440,10 +7422,22 @@ public static function getDatatableEntries(array $data, $params = []): array
$planned_infos .= htmlspecialchars(sprintf(__('From %s'), Html::convDateTime($plan['begin'])));
$planned_infos .= htmlspecialchars(sprintf(__('To %s'), Html::convDateTime($plan['end'])));
if ($plan['users_id_tech']) {
- if (!isset($user_cache[$plan['users_id_tech']])) {
- $user_cache[$plan['users_id_tech']] = getUserName($plan['users_id_tech'], 2);
+ $user = new User();
+ if (!isset($user_cache[$plan["users_id_tech"]]) && $user->getFromDB($plan["users_id_tech"])) {
+ $user_value = sprintf(
+ __s('%1$s %2$s'),
+ htmlspecialchars($user->getName()),
+ Html::showToolTip(
+ $user->getInfoCard(),
+ [
+ 'link' => $user->getLinkURL(),
+ 'display' => false
+ ]
+ )
+ );
+ $user_cache[$plan['users_id']] = $user_value;
}
- $planned_infos .= htmlspecialchars(sprintf(__('By %s'), $user_cache[$plan['users_id_tech']]['name']));
+ $planned_infos .= htmlspecialchars(sprintf(__s('By %s'), $user_cache[$plan['users_id_tech']]));
}
$planned_infos .= "
";
}
diff --git a/src/DbUtils.php b/src/DbUtils.php
index f4511922c766..7a2cb5d446e1 100644
--- a/src/DbUtils.php
+++ b/src/DbUtils.php
@@ -1684,20 +1684,32 @@ public function constructListFromTree($tree, $parent = 0)
/**
- * Format a user name
+ * Format a user name.
*
- * @param integer $ID ID of the user.
- * @param string|null $login login of the user
- * @param string|null $realname realname of the user
- * @param string|null $firstname firstname of the user
- * @param integer $link include link (only if $link==1) (default =0)
- * @param integer $cut limit string length (0 = no limit) (default =0)
- * @param boolean $force_config force order and id_visible to use common config (false by default)
+ * @param integer $ID ID of the user.
+ * @param string|null $login login of the user
+ * @param string|null $realname realname of the user
+ * @param string|null $firstname firstname of the user
+ * @param integer $link include link
+ * @param integer $cut IGNORED PARAMETER
+ * @param boolean $force_config force order and id_visible to use common config
*
- * @return string formatted username
+ * @return string
+ *
+ * @since 11.0 `$link` parameter is deprecated
+ * @since 11.0 `$cut` parameter is ignored
*/
public function formatUserName($ID, $login, $realname, $firstname, $link = 1, $cut = 0, $force_config = false)
{
+ if ((bool) $cut) {
+ trigger_error('`$cut` parameter is now ignored.', E_USER_WARNING);
+ }
+
+ if ((bool) $link) {
+ Toolbox::deprecated('`$link` parameter is deprecated. Use `formatUserLink()` instead.');
+ return $this->formatUserLink($ID, $login, $realname, $firstname);
+ }
+
/** @var array $CFG_GLPI */
global $CFG_GLPI;
@@ -1739,21 +1751,33 @@ public function formatUserName($ID, $login, $realname, $firstname, $link = 1, $c
$formatted = sprintf(__('%1$s (%2$s)'), $formatted, $ID);
}
- $username = $formatted;
+ return $formatted;
+ }
- if (
- ($link == 1)
- && ($ID > 0)
- ) {
- $username = sprintf(
- '%s',
- htmlspecialchars($formatted),
- User::getFormURLWithID($ID),
- htmlspecialchars($formatted)
- );
+ /**
+ * Format a user link.
+ *
+ * @param integer $id ID of the user.
+ * @param string|null $login login of the user
+ * @param string|null $realname realname of the user
+ * @param string|null $firstname firstname of the user
+ *
+ * @return string
+ */
+ public function formatUserLink(int $id, ?string $login, ?string $realname, ?string $firstname): string
+ {
+ $username = $this->formatUserName($id, $login, $realname, $firstname);
+
+ if ($id <= 0 || !User::canView()) {
+ return $username;
}
- return $username;
+ return sprintf(
+ '%s',
+ htmlspecialchars($username),
+ User::getFormURLWithID($id),
+ htmlspecialchars($username)
+ );
}
@@ -1766,102 +1790,73 @@ public function formatUserName($ID, $login, $realname, $firstname, $link = 1, $c
* @param $disable_anon bool disable anonymization of username.
*
* @return string[]|string username string (realname if not empty and name if realname is empty).
+ *
+ * @since 11.0 `$link` parameter is deprecated.
*/
public function getUserName($ID, $link = 0, $disable_anon = false)
{
/** @var \DBmysql $DB */
global $DB;
- $user = "";
- if ($link == 2) {
- $user = ["name" => "",
- "link" => "",
- "comment" => ""
- ];
- }
+ $username = "";
+ $user = new User();
+ $valid_user = false;
+ $anon_name = null;
if ($ID === 'myself') {
- $name = __('Myself');
- if (isset($user['name'])) {
- $user['name'] = $name;
- } else {
- $user = $name;
- }
+ $username = __('Myself');
} else if ($ID === 'requester_manager') {
- $name = __("Requester's manager");
- if (isset($user['name'])) {
- $user['name'] = $name;
- } else {
- $user = $name;
- }
+ $username = __("Requester's manager");
} else if ($ID) {
- $iterator = $DB->request([
- 'FROM' => 'glpi_users',
- 'WHERE' => ['id' => $ID]
- ]);
-
- if ($link == 2) {
- $user = ["name" => "",
- "comment" => "",
- "link" => ""
- ];
+ $anon_name = !$disable_anon && $ID != ($_SESSION['glpiID'] ?? 0) && Session::getCurrentInterface() == 'helpdesk' ? User::getAnonymizedNameForUser($ID) : null;
+ if ($anon_name !== null) {
+ $username = $anon_name;
+ } elseif ($valid_user = $user->getFromDB($ID)) {
+ $username = $user->getName();
}
+ }
- if (count($iterator) == 1) {
- $data = $iterator->current();
+ if ($link == 1) {
+ Toolbox::deprecated('Usage of `$link` parameter is deprecated. Use `getUserLink()` instead.');
+ return $valid_user
+ ? sprintf('%s', htmlspecialchars($username), User::getFormURLWithID($ID), htmlspecialchars($username))
+ : htmlspecialchars($username);
+ }
- $anon_name = !$disable_anon && $ID != ($_SESSION['glpiID'] ?? 0) && Session::getCurrentInterface() == 'helpdesk' ? User::getAnonymizedNameForUser($ID) : null;
- if ($anon_name !== null) {
- $username = $anon_name;
- } else {
- $username = $this->formatUserName(
- $data["id"],
- $data["name"],
- $data["realname"],
- $data["firstname"],
- $link
- );
- }
+ if ($link == 2) {
+ Toolbox::deprecated('Usage of `$link` parameter is deprecated. Use `User::getInforCard()` instead.');
- if ($link == 2) {
- $user["name"] = $username;
- $user["link"] = User::getFormURLWithID($ID);
- $user['comment'] = '';
+ return [
+ 'name' => $username,
+ 'link' => $valid_user ? $user->getLinkUrl() : '',
+ 'comment' => $valid_user ? $user->getInfoCard() : '',
+ ];
+ }
- $user_params = [
- 'id' => $ID,
- 'user_name' => $username,
- ];
+ return $username;
+ }
- if ($anon_name === null) {
- $user_params = array_merge($user_params, [
- 'email' => UserEmail::getDefaultForUser($ID),
- 'phone' => $data["phone"],
- 'phone2' => $data["phone2"],
- 'mobile' => $data["mobile"],
- 'locations_id' => $data['locations_id'],
- 'usertitles_id' => $data['usertitles_id'],
- 'usercategories_id' => $data['usercategories_id'],
- 'registration_number' => $data['registration_number'],
- ]);
-
- if (Session::haveRight('user', READ)) {
- $user_params['login'] = $data['name'];
- }
- if (!empty($data["groups_id"])) {
- $user_params['groups_id'] = $data["groups_id"];
- }
- $user['comment'] = TemplateRenderer::getInstance()->render('components/user/info_card.html.twig', [
- 'user' => $user_params,
- 'enable_anonymization' => Session::getCurrentInterface() == 'helpdesk',
- ]);
- }
- } else {
- $user = $username;
- }
- }
+ /**
+ * Get link of the given user.
+ *
+ * @param int $id
+ *
+ * @return string
+ */
+ public function getUserLink(int $id): string
+ {
+ $username = $this->getUserName($id);
+
+ if (!is_int($id) || $id <= 0 || !User::canView()) {
+ return $username;
}
- return $user;
+
+ return sprintf(
+ '%s',
+ htmlspecialchars($username),
+ User::getFormURLWithID($id),
+ htmlspecialchars($username)
+ );
}
/**
diff --git a/src/Document.php b/src/Document.php
index 45179f4ff9e9..66aaf47557f0 100644
--- a/src/Document.php
+++ b/src/Document.php
@@ -364,14 +364,10 @@ public function showForm($ID, array $options = [])
if ($ID > 0) {
$this->check($ID, READ);
}
- $showuserlink = 0;
- if (Session::haveRight('user', READ)) {
- $showuserlink = 1;
- }
TemplateRenderer::getInstance()->display('pages/management/document.html.twig', [
'item' => $this,
- 'uploader' => $this->fields['users_id'] > 0 ? getUserName($this->fields["users_id"], $showuserlink) : '',
+ 'uploader' => $this->fields['users_id'] > 0 ? getUserLink($this->fields["users_id"]) : '',
'uploaded_files' => self::getUploadedFiles(),
'params' => [
'canedit' => $this->canUpdateItem(),
diff --git a/src/Glpi/Features/PlanningEvent.php b/src/Glpi/Features/PlanningEvent.php
index a1c3e3e512b0..9e004fa353d6 100644
--- a/src/Glpi/Features/PlanningEvent.php
+++ b/src/Glpi/Features/PlanningEvent.php
@@ -1101,11 +1101,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
return '';
}
foreach (json_decode($values[$field], true) as $user_id) {
- $users[] = sprintf(
- '%s',
- User::getFormURLWithID($user_id),
- getUserName($user_id, 1)
- );
+ $users[] = getUserLink($user_id);
}
return implode(', ', $users);
}
diff --git a/src/Glpi/Search/Provider/SQLProvider.php b/src/Glpi/Search/Provider/SQLProvider.php
index 6171b186c044..4d0f392be618 100644
--- a/src/Glpi/Search/Provider/SQLProvider.php
+++ b/src/Glpi/Search/Provider/SQLProvider.php
@@ -5107,23 +5107,26 @@ public static function giveItem(
) {
$out .= $anon_name;
} else {
- $userdata = getUserName($data[$ID][$k]['name'], 2);
- $tooltip = "";
- if (Session::haveRight('user', READ)) {
- $tooltip = \Html::showToolTip(
- $userdata["comment"],
- ['link' => $userdata["link"],
- 'display' => false
- ]
- );
+ $user = new \User();
+ if ($user->getFromDB($data[$ID][$k]['name'])) {
+ $tooltip = "";
+ if (Session::haveRight('user', READ)) {
+ $tooltip = \Html::showToolTip(
+ $user->getInfoCard(),
+ [
+ 'link' => $user->getLinkURL(),
+ 'display' => false
+ ]
+ );
+ }
+ $out .= sprintf(__s('%1$s %2$s'), htmlspecialchars($user->getName()), $tooltip);
}
- $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip);
}
$count_display++;
}
} else {
- $out .= getUserName($data[$ID][$k]['name'], $showuserlink);
+ $out .= getUserLink($data[$ID][$k]['name']);
$count_display++;
}
@@ -5154,22 +5157,24 @@ public static function giveItem(
($itemtype == 'Ticket')
&& ($data[$ID][0]['id'] > 0)
) {
- $userdata = getUserName($data[$ID][0]['id'], 2);
- $toadd = \Html::showToolTip(
- $userdata["comment"],
- ['link' => $userdata["link"],
- 'display' => false
- ]
- );
+ $user = new \User();
+ if (Session::haveRight('user', READ) && $user->getFromDB($data[$ID][0]['id'])) {
+ $toadd = \Html::showToolTip(
+ $user->getInfoCard(),
+ [
+ 'link' => $user->getLinkURL(),
+ 'display' => false
+ ]
+ );
+ }
}
- $usernameformat = formatUserName(
+ $userlink = formatUserLink(
$data[$ID][0]['id'],
$data[$ID][0]['name'],
$data[$ID][0]['realname'],
$data[$ID][0]['firstname'],
- 1
);
- return sprintf(__('%1$s %2$s'), $usernameformat, $toadd);
+ return sprintf(__s('%1$s %2$s'), $userlink, $toadd);
}
if ($html_output) {
diff --git a/src/Item_SoftwareLicense.php b/src/Item_SoftwareLicense.php
index bb24494d2c89..dfed22e902c7 100644
--- a/src/Item_SoftwareLicense.php
+++ b/src/Item_SoftwareLicense.php
@@ -787,7 +787,6 @@ function updateItemDropdown(itemtype_el) {
$soft = new Software();
$soft->getFromDB($license->fields['softwares_id']);
$showEntity = ($license->isRecursive());
- $linkUser = User::canView();
$text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]);
$text = sprintf(__('%1$s - %2$s'), $text, $data["license"]);
@@ -863,12 +862,11 @@ function updateItemDropdown(itemtype_el) {
echo "