Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions classes/configtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.';
}
}

Expand Down
9 changes: 6 additions & 3 deletions classes/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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) . '<br/><br/>'
. '<b>' . $gL10n->get('PIM_ITEMNAME') . ':</b> ' . $this->getValue('ITEMNAME', 'html') . '<br/>'
. '<b>' . convlanguagePIM($itemData->getProperty('ITEMNAME', 'imf_name')) . ':</b> ' . $this->getValue('ITEMNAME', 'html') . '<br/>'
. '<b>' . $gL10n->get($messageUserText) . ':</b> ' . $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME') . '<br/>'
. '<b>' . $gL10n->get($messageDateText) . ':</b> ' . date($gSettingsManager->getString('system_date') . ' ' . $gSettingsManager->getString('system_time')) . '<br/>';
}
Expand Down
2 changes: 1 addition & 1 deletion common_function.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion inventory_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions inventory_manager_profile_addin.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function insertKeeperView($page, $user, $itemsKeeper) : void

$page->addHtml('
<div class="card admidio-field-group" id="inventory_manager_box_keeper">
<div class="card-header">' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . $gL10n->get('PIM_KEEPER') . ')
<div class="card-header">' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . convlanguagePIM($itemsKeeper->getProperty('KEEPER', 'imf_name')) . ')
<a class="admidio-icon-link float-right" href="' . SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/inventory_manager.php', array(
'export_and_filter' => true,
'show_all' => true,
Expand Down Expand Up @@ -231,7 +231,7 @@ function insertReceiverView($page, $user, $itemsReceiver) : void

$page->addHtml('
<div class="card admidio-field-group" id="inventory_manager_box_receiver">
<div class="card-header">' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . $gL10n->get('PIM_LAST_RECEIVER') . ')
<div class="card-header">' . $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER') . ' (' . $gL10n->get('SYS_VIEW') . ': ' . convlanguagePIM($itemsReceiver->getProperty('LAST_RECEIVER', 'imf_name')) . ')
<a class="admidio-icon-link float-right" href="' . SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/inventory_manager.php', array(
'export_and_filter' => true,
'show_all' => true,
Expand Down
2 changes: 1 addition & 1 deletion items/items_edit_new.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
if (isset($pimInInventoryId, $pimLastReceiverId, $pimReceivedOnId, $pimReceivedBackOnId) && $imfNameIntern === 'IN_INVENTORY') {
$pPreferences->config['Optionen']['field_date_time_format'] === 'datetime' ? $datetime = 'true' : $datetime = 'false';

// Add JavaScript to check the PIM_LAST_RECEIVER field and set the required attribute for pimReceivedOnId and pimReceivedBackOnId
// Add JavaScript to check the LAST_RECEIVER field and set the required attribute for pimReceivedOnId and pimReceivedBackOnId
$page->addJavascript('
document.addEventListener("DOMContentLoaded", function() {
if (document.querySelector("[id=\'imf-' . $pimReceivedOnId . '_time\']")) {
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down