diff --git a/classes/configtable.php b/classes/configtable.php
index 5f7c07f..cfcc72a 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();
@@ -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
@@ -363,12 +368,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.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/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('