From 727a6b825b0065a1c68075fdb81b8ec8aec7c934 Mon Sep 17 00:00:00 2001
From: MightyMCoder <130976036+MightyMCoder@users.noreply.github.com>
Date: Wed, 15 Jan 2025 18:39:36 +0100
Subject: [PATCH] bugfix: cannot import user
---
inventory_manager.php | 50 +++++++++++++++++++++++++++++++++++++------
1 file changed, 44 insertions(+), 6 deletions(-)
diff --git a/inventory_manager.php b/inventory_manager.php
index 1c96787..d66ac84 100644
--- a/inventory_manager.php
+++ b/inventory_manager.php
@@ -491,9 +491,28 @@
$content = $gL10n->get('SYS_DELETED_USER');
}
else {
- $content = ($getMode == 'html') ?
- '' . $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME') . '' :
- $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME');
+ if ($getMode == 'html') {
+ $content = '' . $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME') . '';
+ }
+ else {
+ $sql = 'SELECT usr_id, CONCAT(last_name.usd_value, \', \', first_name.usd_value, IFNULL(CONCAT(\', \', postcode.usd_value),\'\'), IFNULL(CONCAT(\' \', city.usd_value),\'\'), IFNULL(CONCAT(\', \', street.usd_value),\'\') ) as name
+ FROM ' . TBL_USERS . '
+ JOIN ' . TBL_USER_DATA . ' as last_name ON last_name.usd_usr_id = usr_id AND last_name.usd_usf_id = ' . $gProfileFields->getProperty('LAST_NAME', 'usf_id') . '
+ JOIN ' . TBL_USER_DATA . ' as first_name ON first_name.usd_usr_id = usr_id AND first_name.usd_usf_id = ' . $gProfileFields->getProperty('FIRST_NAME', 'usf_id') . '
+ LEFT JOIN ' . TBL_USER_DATA . ' as postcode ON postcode.usd_usr_id = usr_id AND postcode.usd_usf_id = ' . $gProfileFields->getProperty('POSTCODE', 'usf_id') . '
+ LEFT JOIN ' . TBL_USER_DATA . ' as city ON city.usd_usr_id = usr_id AND city.usd_usf_id = ' . $gProfileFields->getProperty('CITY', 'usf_id') . '
+ LEFT JOIN ' . TBL_USER_DATA . ' as street ON street.usd_usr_id = usr_id AND street.usd_usf_id = ' . $gProfileFields->getProperty('ADDRESS', 'usf_id') . '
+ WHERE usr_valid = 1 AND EXISTS (SELECT 1 FROM ' . TBL_MEMBERS . ', ' . TBL_ROLES . ', ' . TBL_CATEGORIES . ' WHERE mem_usr_id = usr_id AND mem_rol_id = rol_id AND mem_begin <= \'' . DATE_NOW . '\' AND mem_end > \'' . DATE_NOW . '\' AND rol_valid = 1 AND rol_cat_id = cat_id AND (cat_org_id = ' . $gCurrentOrgId . ' OR cat_org_id IS NULL)) ORDER BY last_name.usd_value, first_name.usd_value;';
+ $result = $gDb->queryPrepared($sql);
+
+ while ($row = $result->fetch()) {
+ if ($row['usr_id'] == $user->getValue('usr_id')) {
+ $content = $row['name'];
+ break;
+ }
+ $content = $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME');
+ }
+ }
}
}
@@ -501,9 +520,28 @@
if (is_numeric($content)) {
$user->readDataById($content);
if (!$user->getValue('usr_uuid') == '') {
- $content = ($getMode == 'html') ?
- '' . $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME') . '' :
- $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME');
+ if ($getMode == 'html') {
+ $content = '' . $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME') . '';
+ }
+ else {
+ $sql = 'SELECT usr_id, CONCAT(last_name.usd_value, \', \', first_name.usd_value, IFNULL(CONCAT(\', \', postcode.usd_value),\'\'), IFNULL(CONCAT(\' \', city.usd_value),\'\'), IFNULL(CONCAT(\', \', street.usd_value),\'\') ) as name
+ FROM ' . TBL_USERS . '
+ JOIN ' . TBL_USER_DATA . ' as last_name ON last_name.usd_usr_id = usr_id AND last_name.usd_usf_id = ' . $gProfileFields->getProperty('LAST_NAME', 'usf_id') . '
+ JOIN ' . TBL_USER_DATA . ' as first_name ON first_name.usd_usr_id = usr_id AND first_name.usd_usf_id = ' . $gProfileFields->getProperty('FIRST_NAME', 'usf_id') . '
+ LEFT JOIN ' . TBL_USER_DATA . ' as postcode ON postcode.usd_usr_id = usr_id AND postcode.usd_usf_id = ' . $gProfileFields->getProperty('POSTCODE', 'usf_id') . '
+ LEFT JOIN ' . TBL_USER_DATA . ' as city ON city.usd_usr_id = usr_id AND city.usd_usf_id = ' . $gProfileFields->getProperty('CITY', 'usf_id') . '
+ LEFT JOIN ' . TBL_USER_DATA . ' as street ON street.usd_usr_id = usr_id AND street.usd_usf_id = ' . $gProfileFields->getProperty('ADDRESS', 'usf_id') . '
+ WHERE usr_valid = 1 AND EXISTS (SELECT 1 FROM ' . TBL_MEMBERS . ', ' . TBL_ROLES . ', ' . TBL_CATEGORIES . ' WHERE mem_usr_id = usr_id AND mem_rol_id = rol_id AND mem_begin <= \'' . DATE_NOW . '\' AND mem_end > \'' . DATE_NOW . '\' AND rol_valid = 1 AND rol_cat_id = cat_id AND (cat_org_id = ' . $gCurrentOrgId . ' OR cat_org_id IS NULL)) ORDER BY last_name.usd_value, first_name.usd_value;';
+ $result = $gDb->queryPrepared($sql);
+
+ while ($row = $result->fetch()) {
+ if ($row['usr_id'] == $user->getValue('usr_id')) {
+ $content = $row['name'];
+ break;
+ }
+ $content = $user->getValue('LAST_NAME') . ', ' . $user->getValue('FIRST_NAME');
+ }
+ }
}
}
}