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('
-
' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . $gL10n->get('PIM_KEEPER') . ') +
' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . convlanguagePIM($itemsKeeper->getProperty('KEEPER', 'imf_name')) . ') -
' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . $gL10n->get('PIM_LAST_RECEIVER') . ') +
' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . convlanguagePIM($itemsReceiver->getProperty('LAST_RECEIVER', 'imf_name')) . ') Date: Sun, 23 Mar 2025 11:49:44 +0100 Subject: [PATCH 2/3] Update plugin version to 1.1.6 --- inventory_manager.php | 2 +- version.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inventory_manager.php b/inventory_manager.php index b9902ad..567dcc8 100644 --- a/inventory_manager.php +++ b/inventory_manager.php @@ -3,7 +3,7 @@ *********************************************************************************************** * InventoryManager * - * Version 1.1.5 + * Version 1.1.6 * * InventoryManager is an Admidio plugin for managing the inventory of an organisation. * diff --git a/version.php b/version.php index 86d3d07..07b3774 100644 --- a/version.php +++ b/version.php @@ -11,9 +11,9 @@ */ class CPluginInfoPIM { - protected const PLUGIN_VERSION = '1.1.5'; + protected const PLUGIN_VERSION = '1.1.6'; protected const PLUGIN_VERSION_BETA = 'n/a'; - protected const PLUGIN_STAND = '08.03.2025'; + protected const PLUGIN_STAND = '23.03.2025'; /** * Current version of plugin InventoryManager From fc749c31f7b93ccf255bb95a0e6f433b452a439b Mon Sep 17 00:00:00 2001 From: MightyMCoder <130976036+MightyMCoder@users.noreply.github.com> Date: Sun, 23 Mar 2025 12:46:09 +0100 Subject: [PATCH 3/3] fix sequence when updating to newer plugin version --- classes/configtable.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/classes/configtable.php b/classes/configtable.php index 192fe74..cfcc72a 100644 --- a/classes/configtable.php +++ b/classes/configtable.php @@ -257,24 +257,29 @@ private function initializeDefaultFieldsByOrgId(): void }); foreach ($existingFields as $fieldName => $fieldData) { - if (strpos($fieldName, 'PIM_') === 0) { + if ($fieldData['imf_system'] === 1) { $pimFields[$fieldName] = $fieldData; } else { $customFields[$fieldName] = $fieldData; - $customFields[$fieldName]['previous_imf_name'] = $existingFieldsOrdered[$fieldData['imf_sequence'] - 1]['imf_name']; - $customFields[$fieldName]['previous_sequence'] = $existingFieldsOrdered[$fieldData['imf_sequence'] - 1]['imf_sequence']; + if ($fieldData['imf_sequence'] > 0) { + $customFields[$fieldName]['previous_imf_name_intern'] = $existingFieldsOrdered[$fieldData['imf_sequence'] - 1]['imf_name_intern']; + $customFields[$fieldName]['previous_sequence'] = $existingFieldsOrdered[$fieldData['imf_sequence'] - 1]['imf_sequence']; + } else { + $customFields[$fieldName]['previous_imf_name_intern'] = null; + $customFields[$fieldName]['previous_sequence'] = null; + } } } // Adjust pimFields to match the defaultData foreach ($defaultData as $defaultField) { - $defaultFieldName = $defaultField['imf_name']; + $defaultFieldName = $defaultField['imf_name_intern']; if (!isset($pimFields[$defaultFieldName])) { // Field does not exist, add it to pimFields $pimFields[$defaultFieldName] = $defaultField; } else { foreach ($defaultField as $key => $value) { - if ($key === 'imf_value_list') { + if ($key === 'imf_value_list' || $key === 'imf_name') { continue; } $pimFields[$defaultFieldName][$key] = $value; @@ -287,7 +292,7 @@ private function initializeDefaultFieldsByOrgId(): void return $a['imf_id'] <=> $b['imf_id']; }); - $pimFields = array_combine(array_column($pimFields, 'imf_name'), $pimFields); + $pimFields = array_combine(array_column($pimFields, 'imf_name_intern'), $pimFields); // Remove PIM fields that are not in the defaultData foreach ($pimFields as $fieldName => $fieldData) { @@ -301,8 +306,8 @@ private function initializeDefaultFieldsByOrgId(): void // Adjust the sequence of pimFields based on customFields foreach ($customFields as $customField) { - if (isset($customField['previous_imf_name']) && isset($allFields[$customField['previous_imf_name']])) { - $customSequence = $allFields[$customField['previous_imf_name']]['imf_sequence'] + 1; + if (isset($customField['previous_imf_name_intern']) && isset($allFields[$customField['previous_imf_name_intern']])) { + $customSequence = $allFields[$customField['previous_imf_name_intern']]['imf_sequence'] + 1; $customField['imf_sequence'] = $customSequence; } else { //old previous item doesnt exist anymore @@ -317,8 +322,8 @@ private function initializeDefaultFieldsByOrgId(): void unset($pimField); // Break reference to the last element - if (isset($customField['imf_name'])) { - $allFields[$customField['imf_name']] = $customField; + if (isset($customField['imf_name_intern'])) { + $allFields[$customField['imf_name_intern']] = $customField; } } // Now $allFields contains the combined and updated fields