From c308c1437fa1c46d609a7474d01560ade8704461 Mon Sep 17 00:00:00 2001
From: MightyMCoder <130976036+MightyMCoder@users.noreply.github.com>
Date: Sun, 23 Mar 2025 11:49:02 +0100
Subject: [PATCH 1/3] fix messed up ids for history log and remove hardcoded
language translation for field names to allow custom values
---
classes/configtable.php | 9 +++++++--
classes/items.php | 9 ++++++---
common_function.php | 2 +-
inventory_manager_profile_addin.php | 4 ++--
items/items_edit_new.php | 2 +-
5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/classes/configtable.php b/classes/configtable.php
index 5f7c07f..192fe74 100644
--- a/classes/configtable.php
+++ b/classes/configtable.php
@@ -242,10 +242,10 @@ private function initializeDefaultFieldsByOrgId(): void
$existingFields = array();
while ($row = $statement->fetch()) {
- $existingFields[$row['imf_name']] = $row;
+ $existingFields[$row['imf_name_intern']] = $row;
}
- $defaultFieldNames = array_column($defaultData, 'imf_name');
+ $defaultFieldNames = array_column($defaultData, 'imf_name_intern');
$pimFields = array();
$customFields = array();
@@ -363,12 +363,17 @@ private function initializeDefaultFieldsByOrgId(): void
if ($newFieldIds[$oldFieldName] != $oldField['imf_id']) {
$sql = 'UPDATE ' . TBL_INVENTORY_MANAGER_DATA . ' SET imd_imf_id = ? WHERE imd_imf_id = ?';
$gDb->queryPrepared($sql, array($newFieldIds[$oldFieldName], $oldField['imf_id']));
+ $sql = 'UPDATE ' . TBL_INVENTORY_MANAGER_LOG . ' SET iml_imf_id = ? WHERE iml_imf_id = ?';
+ $gDb->queryPrepared($sql, array($newFieldIds[$oldFieldName], $oldField['imf_id']));
}
} else {
// Field no longer exists, set the field to empty and show an error message
$sql = 'UPDATE ' . TBL_INVENTORY_MANAGER_DATA . ' SET imd_imf_id = NULL WHERE imd_imf_id = ?';
$gDb->queryPrepared($sql, array($oldField['imf_id']));
$_SESSION['error_messages'][] = 'Error: Field "' . $oldFieldName . '" no longer exists. Please manually check and adjust the database table"' . TBL_INVENTORY_MANAGER_DATA . '" where "imd_imf_id" equals "NULL" to avoid data loss.';
+ $sql = 'UPDATE ' . TBL_INVENTORY_MANAGER_LOG . ' SET iml_imf_id = NULL WHERE iml_imf_id = ?';
+ $gDb->queryPrepared($sql, array($oldField['imf_id']));
+ $_SESSION['error_messages'][] = 'Error: Field "' . $oldFieldName . '" no longer exists. Please manually check and adjust the database table"' . TBL_INVENTORY_MANAGER_LOG . '" where "iml_imf_id" equals "NULL" to avoid data loss.';
}
}
diff --git a/classes/items.php b/classes/items.php
index 30a4afe..d463e10 100644
--- a/classes/items.php
+++ b/classes/items.php
@@ -841,7 +841,7 @@ public function setImportedItem(): void
*/
public function sendNotification($importData = null): bool
{
- global $gCurrentUser, $gSettingsManager, $gL10n;
+ global $gCurrentUser, $gSettingsManager, $gL10n, $gDb, $gCurrentOrgId;
// check if notifications are enabled
if ($gSettingsManager->getBool('system_notifications_new_entries')) {
@@ -970,11 +970,14 @@ public function sendNotification($importData = null): bool
}
}
} else {
+ $itemData = new CItems($gDb, $gCurrentOrgId);
+ $itemData->readItemFields($gCurrentOrgId);
+
$messageUserText = 'SYS_CHANGED_BY';
$messageDateText = 'SYS_CHANGED_AT';
-
+
$message = $gL10n->get($messageHead) . '
'
- . '' . $gL10n->get('PIM_ITEMNAME') . ': ' . $this->getValue('ITEMNAME', 'html') . '
'
+ . '' . convlanguagePIM($itemData->getProperty('ITEMNAME', 'imf_name')) . ': ' . $this->getValue('ITEMNAME', 'html') . '
'
. '' . $gL10n->get($messageUserText) . ': ' . $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME') . '
'
. '' . $gL10n->get($messageDateText) . ': ' . date($gSettingsManager->getString('system_date') . ' ' . $gSettingsManager->getString('system_time')) . '
';
}
diff --git a/common_function.php b/common_function.php
index 06be140..f980a73 100644
--- a/common_function.php
+++ b/common_function.php
@@ -160,7 +160,7 @@ function isUserAuthorizedForAddinPIM() : bool
* @param int|null $keeper The user ID of the keeper
* @return bool true if the keeper is authorized
*/
-function isKeeperAuthorizedToEdit(int $keeper = null) : bool
+function isKeeperAuthorizedToEdit(?int $keeper = null) : bool
{
global $pPreferences, $gCurrentUser;
$gCurrentUser = $GLOBALS['gCurrentUser'];
diff --git a/inventory_manager_profile_addin.php b/inventory_manager_profile_addin.php
index d6a3b1b..b3c1d10 100644
--- a/inventory_manager_profile_addin.php
+++ b/inventory_manager_profile_addin.php
@@ -88,7 +88,7 @@ function insertKeeperView($page, $user, $itemsKeeper) : void
$page->addHtml('