From 25e64b6fd5d25ac727ef329e4898db464a638395 Mon Sep 17 00:00:00 2001 From: Mathias Huth Date: Wed, 24 Sep 2025 21:18:58 +0200 Subject: [PATCH 1/3] feat: make a data export available under Admidio V5 --- classes/configtable.php | 6 +- classes/items.php | 66 ++++++++++++-- common_function.php | 11 ++- inventory_manager.php | 126 +++++++++++++++++++++++++-- languages/de-DE.xml | 6 ++ languages/de.xml | 6 ++ languages/en.xml | 6 ++ languages/fr.xml | 6 ++ languages/it.xml | 6 ++ preferences/preferences_function.php | 29 ++++-- 10 files changed, 241 insertions(+), 27 deletions(-) diff --git a/classes/configtable.php b/classes/configtable.php index 21350c9..e29e118 100644 --- a/classes/configtable.php +++ b/classes/configtable.php @@ -548,7 +548,11 @@ public function write(): void */ public function read(): bool { - return $this->readConfigData(self::SHORTCUT, $this->config); + try { + return $this->readConfigData(self::SHORTCUT, $this->config); + } catch (Exception $e) { + return false; + } } /** diff --git a/classes/items.php b/classes/items.php index 475c303..84a9f15 100644 --- a/classes/items.php +++ b/classes/items.php @@ -37,6 +37,21 @@ * sendNotification($importData = null) : Sends a notification to all users that have the right to see the item *********************************************************************************************** */ + +// for Admidio 5.0 +use Admidio\Infrastructure\Database; +use Admidio\Infrastructure\Image; +use Admidio\Infrastructure\Language; +use Admidio\Infrastructure\Utils\StringUtils; +use Admidio\Infrastructure\Entity\Entity; +use Admidio\Infrastructure\Email; + +try { + require_once(__DIR__ . '/../../../system/bootstrap/constants.php'); +} catch (Exception $e) { + require_once(__DIR__ . '/../../../adm_program/system/bootstrap/constants.php'); +} + require_once(__DIR__ . '/configtable.php'); class CItems @@ -573,7 +588,11 @@ public function readItemData(int $itemId, int $organizationId): void while ($row = $itemDataStatement->fetch()) { if (!array_key_exists($row['imd_imf_id'], $this->mItemData)) { - $this->mItemData[$row['imd_imf_id']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); + if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $this->mItemData[$row['imd_imf_id']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); + } else { + $this->mItemData[$row['imd_imf_id']] = new Entity($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); + } } $this->mItemData[$row['imd_imf_id']]->setArray($row); } @@ -609,7 +628,11 @@ public function saveItemData(): void // for updateFingerPrint a change in db must be executed // why !$this->itemCreated -> updateFingerPrint will be done in getNewItemId if (!$this->itemCreated && $this->columnsValueChanged) { - $updateItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $this->mItemId); + if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $updateItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $this->mItemId); + } else { + $updateItem = new Entity($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $this->mItemId); + } $updateItem->setValue('imi_usr_id_change', null, false); $updateItem->save(); } @@ -642,7 +665,11 @@ public function readItemFields(int $organizationId, string $orderBy = 'imf_id'): while ($row = $statement->fetch()) { if (!array_key_exists($row['imf_name_intern'], $this->mItemFields)) { - $this->mItemFields[$row['imf_name_intern']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_FIELDS, 'imf'); + if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $this->mItemFields[$row['imf_name_intern']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_FIELDS, 'imf'); + } else { + $this->mItemFields[$row['imf_name_intern']] = new Entity($this->mDb, TBL_INVENTORY_MANAGER_FIELDS, 'imf'); + } } $this->mItemFields[$row['imf_name_intern']]->setArray($row); $this->itemFieldsSort[$row['imf_name_intern']] = $row['imf_sequence']; @@ -790,15 +817,30 @@ public function setValue(string $fieldNameIntern, $newValue): bool } if (!array_key_exists($imfId, $this->mItemData)) { - $this->mItemData[$imfId] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); + if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $this->mItemData[$imfId] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); + } else { + $this->mItemData[$imfId] = new Entity($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); + } $this->mItemData[$imfId]->setValue('imd_imf_id', $imfId); $this->mItemData[$imfId]->setValue('imd_imi_id', $this->mItemId); } $returnCode = $this->mItemData[$imfId]->setValue('imd_value', $newValue); - if ($returnCode && $gSettingsManager->getBool('profile_log_edit_fields')) { - $logEntry = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_LOG, 'iml'); + if ($gSettingsManager->has('profile_log_edit_fields')) { + // check if logging of profile field changes is enabled + $loggingEnabled = $gSettingsManager->getBool('profile_log_edit_fields'); + } else { + $loggingEnabled = $gSettingsManager->getBool('changelog_module_enabled'); + } + + if ($returnCode && $loggingEnabled) { + if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $logEntry = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_LOG, 'iml'); + } else { + $logEntry = new Entity($this->mDb, TBL_INVENTORY_MANAGER_LOG, 'iml'); + } $logEntry->setValue('iml_imi_id', $this->mItemId); $logEntry->setValue('iml_imf_id', $imfId); $logEntry->setValue('iml_value_old', $oldFieldValue); @@ -828,13 +870,21 @@ public function getNewItemId(int $organizationId): int $statement = $this->mDb->queryPrepared($sql); while ($row = $statement->fetch()) { - $delItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $row['imi_id']); + if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $delItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $row['imi_id']); + } else { + $delItem = new Entity($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $row['imi_id']); + } $delItem->delete(); } // generate a new ItemId if ($this->itemCreated) { - $newItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi'); + if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $newItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi'); + } else { + $newItem = new Entity($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi'); + } $newItem->setValue('imi_org_id', $organizationId); $newItem->setValue('imi_former', 0); $newItem->save(); diff --git a/common_function.php b/common_function.php index a724122..5735082 100644 --- a/common_function.php +++ b/common_function.php @@ -33,7 +33,16 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Fill; -require_once(__DIR__ . '/../../adm_program/system/common.php'); +// for Admidio 5.0 +use Admidio\Components\Entity\Component; +use Admidio\Roles\Entity\RolesRights; +use Admidio\Menu\ValueObject\MenuNode; + +try { + require_once(__DIR__ . '/../../system/common.php'); +} catch (Exception $e) { + require_once(__DIR__ . '/../../adm_program/system/common.php'); +} // Define necessary constants if not already defined defineConstantsPIM(); diff --git a/inventory_manager.php b/inventory_manager.php index 1908fce..4fc49fa 100644 --- a/inventory_manager.php +++ b/inventory_manager.php @@ -50,13 +50,30 @@ use PhpOffice\PhpSpreadsheet\Writer\Ods; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -require_once(__DIR__ . '/../../adm_program/system/common.php'); -require_once(__DIR__ . '/common_function.php'); -require_once(__DIR__ . '/classes/items.php'); -require_once(__DIR__ . '/classes/configtable.php'); - -// Access only with valid login -require_once(__DIR__ . '/../../adm_program/system/login_valid.php'); +// for Admidio 5.0 +use Admidio\Infrastructure\Utils\SecurityUtils; +use Admidio\Users\Entity\User; +use Admidio\Infrastructure\Utils\FileSystemUtils; + +try { + require_once(__DIR__ . '/../../system/common.php'); + require_once(__DIR__ . '/../../system/bootstrap/constants.php'); + require_once(__DIR__ . '/common_function.php'); + require_once(__DIR__ . '/classes/items.php'); + require_once(__DIR__ . '/classes/configtable.php'); + + // Access only with valid login + require_once(__DIR__ . '/../../system/login_valid.php'); +} catch (Exception $e) { + require_once(__DIR__ . '/../../adm_program/system/common.php'); + require_once(__DIR__ . '/../../adm_program/system/bootstrap/constants.php'); + require_once(__DIR__ . '/common_function.php'); + require_once(__DIR__ . '/classes/items.php'); + require_once(__DIR__ . '/classes/configtable.php'); + + // Access only with valid login + require_once(__DIR__ . '/../../adm_program/system/login_valid.php'); +} //$scriptName is the name as it must be entered in the menu, without any preceding folders such as /playground/adm_plugins/InventoryManager... $scriptName = substr($_SERVER['SCRIPT_NAME'], strpos($_SERVER['SCRIPT_NAME'], FOLDER_PLUGINS)); @@ -75,7 +92,92 @@ // check if plugin need to be updated $pPreferences = new CConfigTablePIM(); -$pPreferences->checkForUpdate() ? $pPreferences->init() : $pPreferences->read(); +// check if installed admidio version is compatible with this plugin version +if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { + $pPreferences->checkForUpdate() ? $pPreferences->init() : $pPreferences->read(); +} else { + // We are in Version 5.0.0 or higher so the plugin is not compatible anymore + // But we need the preferences to get the export filename + if (!$pPreferences->read()) { + $gMessage->show($gL10n->get('PLG_INVENTORY_MANAGER_V5_NO_DATA', array('' . $gL10n->get('SYS_INVENTORY') . ''))); + } + + $exportMode = (admFuncVariableIsValid($_GET, 'mode', 'string', array('defaultValue' => 'html', 'validValues' => array('csv-ms', 'csv-oo', 'html', 'print', 'pdf', 'pdfl', 'xlsx', 'ods'))) === 'html') ? false : true; + + if (!$exportMode) { + $gNavigation->addStartUrl(CURRENT_URL, $gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER'), 'bi-box-seam'); + $page = new HtmlPage('plg-inventory-manager-deprecated'); + $page->setTitle($gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER')); + $page->setHeadline($gL10n->get('PLG_INVENTORY_MANAGER_INVENTORY_MANAGER')); + + $content = ' + '; + $page->addHtml($content); + $page->show(); + } +} + $disableBorrowing = $pPreferences->config['Optionen']['disable_borrowing']; // check if user is authorized for preferences panel @@ -631,8 +733,14 @@ if ($getMode == 'html') { $tempValue = ''; + if ($gSettingsManager->has('profile_log_edit_fields')) { + // check if logging of profile field changes is enabled + $loggingEnabled = $gSettingsManager->getBool('profile_log_edit_fields'); + } else { + $loggingEnabled = $gSettingsManager->getBool('changelog_module_enabled'); + } // show link to view profile field change history - if ($gSettingsManager->getBool('profile_log_edit_fields')) { + if ($loggingEnabled) { $tempValue .= ' diff --git a/languages/de-DE.xml b/languages/de-DE.xml index b47fb46..a9f4f93 100644 --- a/languages/de-DE.xml +++ b/languages/de-DE.xml @@ -100,6 +100,11 @@ Stand Plugininformationen Name des Plugins + Die Inventarverwaltung ist nicht kompatibel mit dieser Version von Admidio + Vielen Dank, dass Sie das Plugin Inventarverwaltung nutzen!\n\nObwohl es erst kürzlich veröffentlicht wurde, hat sich das Plugin bereits für viele Nutzer als sehr hilfreich erwiesen. Da es schon lange eine Nachfrage nach einem integrierten Inventarverwaltungssystem in Admidio gab, wurde das Plugin nun in ein neues Inventar-Modul innerhalb von Admidio integriert.\n\nBitte beachten Sie, dass das neue Modul möglicherweise noch nicht alle Funktionen des Plugins umfasst, aber im Laufe der Zeit weiter verbessert und erweitert wird. + Unten können Sie Ihre vorhandenen Daten aus der Inventarverwaltung exportieren und anschließend in das neue Inventar-Modul von Admidio importieren. + Nachdem Sie Ihre Daten erfolgreich migriert haben, deinstallieren Sie bitte das Plugin Inventarverwaltung unten, um Konflikte mit dem neuen Inventar-Modul zu vermeiden. + Wenn Sie Fragen oder Probleme haben, kontaktieren Sie uns gerne im #VAR1# oder eröffnen Sie ein #VAR2# auf GitHub. Version Einstellungen für die Profilansicht In der Profilansicht eines Mitglieds können ausgegebene Gegenstände angezeigt werden. Standardmäßig wird nur der Gegenstandsname angezeigt. Hier können Sie, zusätzlich zum Gegenstandsnamen, weitere Eigenschaftsfelder auswählen und anzeigen lassen. @@ -110,6 +115,7 @@ aktueller Benutzer als Standardauswahl Soll der aktuelle Benutzer beim Hinzufügen neuer Gegenstände standardmäßig als Verwalter voreingestellt werden, so ist der Haken zu setzen. Sie benutzten eine aktuelle #VAR1#Version von InventoryManager! + Dieses Plugin ist nicht kompatibel mit Version 5 von Admidio. Es sind keine Daten aus einer vorherigen Version der Inventarverwaltung zum Export verfügbar.\n\nBitte entfernen Sie die Plugin-Dateien aus Ihrer Admidio-Installation und verwenden Sie das neue Inventar-Modul, das in Admidio Version 5 implementiert wurde. (#VAR1#) Kategorie Die Kategorie des Gegenstandes diff --git a/languages/de.xml b/languages/de.xml index c0fa6ae..f414354 100644 --- a/languages/de.xml +++ b/languages/de.xml @@ -100,6 +100,11 @@ Stand Plugininformationen Name des Plugins + Die Inventarverwaltung ist nicht kompatibel mit dieser Version von Admidio + Vielen Dank, dass du das Plugin Inventarverwaltung nutzt!\n\nObwohl es erst kürzlich veröffentlicht wurde, hat sich das Plugin bereits für viele Nutzer als sehr hilfreich erwiesen. Da es schon lange eine Nachfrage nach einem integrierten Inventarverwaltungssystem in Admidio gab, wurde das Plugin nun in ein neues Inventar-Modul innerhalb von Admidio integriert.\n\nBitte beachte, dass das neue Modul möglicherweise noch nicht alle Funktionen des Plugins umfasst, aber im Laufe der Zeit weiter verbessert und erweitert wird. + Unten kannst du deine vorhandenen Daten aus der Inventarverwaltung exportieren und anschließend in das neue Inventar-Modul von Admidio importieren. + Nachdem du deine Daten erfolgreich migriert hast, deinstalliere bitte das Plugin Inventarverwaltung unten, um Konflikte mit dem neuen Inventar-Modul zu vermeiden. + Wenn du Fragen oder Probleme hast, kontaktiere uns gerne im #VAR1# oder eröffne ein #VAR2# auf GitHub. Version Einstellungen für die Profilansicht In der Profilansicht eines Mitglieds können ausgegebene Gegenstände angezeigt werden. Standardmäßig wird nur der Gegenstandsname angezeigt. Hier kannst du, zusätzlich zum Gegenstandsnamen, weitere Eigenschaftsfelder auswählen und anzeigen lassen. @@ -110,6 +115,7 @@ aktueller Benutzer als Standardauswahl Soll der aktuelle Benutzer beim Hinzufügen neuer Gegenstände standardmäßig als Verwalter voreingestellt werden, so ist der Haken zu setzen. Du benutzt eine aktuelle #VAR1#Version von InventoryManager! + Dieses Plugin ist nicht kompatibel mit Version 5 von Admidio. Es sind keine Daten aus einer vorherigen Version der Inventarverwaltung zum Export verfügbar.\n\nBitte entferne die Plugin-Dateien aus deiner Admidio-Installation und verwenden das neue Inventar-Modul, das in Admidio Version 5 implementiert wurde. (#VAR1#) Kategorie Die Kategorie des Gegenstandes diff --git a/languages/en.xml b/languages/en.xml index 6ca8f1b..0eb8ea8 100644 --- a/languages/en.xml +++ b/languages/en.xml @@ -100,6 +100,11 @@ Situation Plug-in informations Plug-in name + InventoryManager is not compatible with this version of Admidio + Thank you for using the InventoryManager plugin!\n\nAlthough it was released only recently the plugin has already proven very helpful for many users. Since there has long been a demand for an integrated inventory management system in Admidio the plugin has now been migrated into a new inventory module within Admidio itself.\n\nPlease note that the new module may not yet include all the features of the plugin but it will continue to be improved and expanded over time. + You can export your existing data from the InventoryManager plugin below and then import it into Admidios new inventory module. + After you have successfully migrated your data please uninstall the InventoryManager plugin below to avoid any conflicts with the new inventory module. + If you have any questions or problems feel free to contact us in the #VAR1# or open an #VAR2# on GitHub. Version Profile view settings Issued items can be viewed in a member's profile view. By default, only the item name is displayed. In addition to the item name, other item fields can be selected and displayed here. @@ -110,6 +115,7 @@ Current user as default selection If the current user is to be preset as the keeper when adding new items, the checkbox must be checked. You are using the current #VAR1# version of InventoryManager! + This Plugin is not compatible to Version 5 of Admidio. There is no data available from a previous version of InventoryManager to export.\n\nPlease remove the plugin files from your Admidio installation and use the new Inventory moule implemented in Admidio Version 5. (#VAR1#) Category Category of the item diff --git a/languages/fr.xml b/languages/fr.xml index e6e1686..91c0065 100644 --- a/languages/fr.xml +++ b/languages/fr.xml @@ -100,6 +100,11 @@ État Informations sur le plug-in Nom du plug-in + InventoryManager n'est pas compatible avec cette version d'Admidio + Merci d'utiliser le plugin InventoryManager !\n\nBien qu'il ait été publié récemment, le plugin a déjà prouvé son utilité pour de nombreux utilisateurs. Comme la demande d'un système intégré de gestion d'inventaire dans Admidio existe depuis longtemps, le plugin a maintenant été intégré dans un nouveau module d'inventaire au sein d'Admidio.\n\nVeuillez noter que le nouveau module n'inclut peut-être pas encore toutes les fonctionnalités du plugin, mais il continuera d'être amélioré et étendu au fil du temps. + Vous pouvez exporter vos données existantes du plugin InventoryManager ci-dessous, puis les importer dans le nouveau module d'inventaire d'Admidio. + Après avoir migré avec succès vos données, veuillez désinstaller le plugin InventoryManager ci-dessous afin d'éviter tout conflit avec le nouveau module d'inventaire. + Si vous avez des questions ou des problèmes, n'hésitez pas à nous contacter sur le #VAR1# ou à ouvrir un #VAR2# sur GitHub. Version Paramètres d'affichage du profil Les objets émises peuvent être consultées dans la vue du profil d'un membre. Par défaut, seul le nom de l'objet est affiché. Outre le nom de l'objet, autre champ objets peut être sélectionné et affiché ici. @@ -110,6 +115,7 @@ Utilisateur actuel comme sélection par défaut Si l'utilisateur actuel doit être défini par défaut comme gestionnaire lors de l'ajout de nouveaux objets, cochez cette case. Vous utilisez une #VAR1#version actuelle d'InventoryManager! + Ce plugin n'est pas compatible avec la version 5 d'Admidio. Aucune donnée d'une version antérieure d'InventoryManager n'est disponible pour exportation.\n\nVeuillez supprimer les fichiers du plugin de votre installation Admidio et utiliser le nouveau module d'inventaire implémenté dans Admidio Version 5. (#VAR1#) Catégorie La catégorie de l'objet diff --git a/languages/it.xml b/languages/it.xml index f9582c5..426f752 100644 --- a/languages/it.xml +++ b/languages/it.xml @@ -100,6 +100,11 @@ Situazione Informazioni sul plugin Nome del plugin + InventoryManager non è compatibile con questa versione di Admidio + Grazie per aver utilizzato il plugin InventoryManager! Sebbene sia stato rilasciato solo di recente, il plugin si è già dimostrato molto utile per molti utenti. Dato che da tempo esisteva la richiesta di un sistema integrato di gestione dell'inventario in Admidio, il plugin è stato ora migrato in un nuovo modulo di inventario all'interno dello stesso Admidio. Si prega di notare che il nuovo modulo potrebbe non includere ancora tutte le funzionalità del plugin, ma verrà continuamente migliorato e ampliato nel tempo. + Puoi esportare i dati esistenti dal plugin InventoryManager qui sotto e poi importarli nel nuovo modulo di inventario di Admidio. + Dopo aver migrato con successo i tuoi dati, disinstalla il plugin InventoryManager qui sotto per evitare conflitti con il nuovo modulo di inventario. + Se hai domande o problemi, non esitare a contattarci nel #VAR1# o ad aprire un #VAR2# su GitHub. Versione Impostazioni vista profilo Gli articoli emessi possono essere visualizzati nella vista profilo di un membro. Per impostazione predefinita viene visualizzato solo il nome dell'articolo. Oltre al nome, qui puoi selezionare e visualizzare altri campi dell'articolo. @@ -110,6 +115,7 @@ Utente corrente come selezione predefinita Se l'utente corrente deve essere preimpostato come custode quando si aggiungono nuovi articoli, seleziona questa opzione. Stai utilizzando la versione corrente #VAR1# di InventoryManager! + Questo plugin non è compatibile con la versione 5 di Admidio. Non ci sono dati disponibili da una versione precedente di InventoryManager da esportare.\n\nSi prega di rimuovere i file del plugin dalla propria installazione di Admidio e di utilizzare il nuovo modulo di inventario implementato nella versione 5 di Admidio. (#VAR1#) Categoria Categoria dell'articolo diff --git a/preferences/preferences_function.php b/preferences/preferences_function.php index f3b5a01..895c2d4 100644 --- a/preferences/preferences_function.php +++ b/preferences/preferences_function.php @@ -24,12 +24,25 @@ *********************************************************************************************** */ -require_once(__DIR__ . '/../../../adm_program/system/common.php'); -require_once(__DIR__ . '/../common_function.php'); -require_once(__DIR__ . '/../classes/configtable.php'); +// for Admidio 5.0 +use Admidio\Infrastructure\Utils\SecurityUtils; + +try { + require_once(__DIR__ . '/../../../system/common.php'); + require_once(__DIR__ . '/../common_function.php'); + require_once(__DIR__ . '/../classes/configtable.php'); + +// Access only with valid login + require_once(__DIR__ . '/../../../system/login_valid.php'); + +} catch (Exception $e) { + require_once(__DIR__ . '/../../../adm_program/system/common.php'); + require_once(__DIR__ . '/../common_function.php'); + require_once(__DIR__ . '/../classes/configtable.php'); // Access only with valid login -require_once(__DIR__ . '/../../../adm_program/system/login_valid.php'); + require_once(__DIR__ . '/../../../adm_program/system/login_valid.php'); +} $pPreferences = new CConfigTablePIM(); $pPreferences->read(); @@ -130,19 +143,19 @@ function showDeinstallationDialog(): void $headline = $gL10n->get('PLG_INVENTORY_MANAGER_DEINSTALLATION'); - // create html page object - $page = new HtmlPage('plg-inventory-manager-deinstallation', $headline); - // add current url to navigation stack $gNavigation->addUrl(CURRENT_URL, $headline); + // create html page object + $page = new HtmlPage('plg-inventory-manager-deinstallation', $headline); + $page->addHtml('

' . $gL10n->get('PLG_INVENTORY_MANAGER_DEINSTALLATION_FORM_DESC') . '

'); // show form $radioButtonEntries = array('0' => $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_ACTORGONLY'), '1' => $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_ALLORG')); $form = new HtmlForm('deinstallation_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/preferences/preferences_function.php', array('mode' => 3)), $page); - $form->addRadioButton('deinst_org_select', $gL10n->get('PLG_INVENTORY_MANAGER_ORG_CHOICE'), $radioButtonEntries, array('defaultValue' => '0')); + $form->addRadioButton('deinst_org_select', $gL10n->get('PLG_INVENTORY_MANAGER_ORG_CHOICE'), $radioButtonEntries, array('defaultValue' => '0', 'toggleable' => false)); $form->addSubmitButton('btn_deinstall', $gL10n->get('PLG_INVENTORY_MANAGER_DEINSTALLATION'), array('icon' => 'fa-trash-alt', 'class' => 'offset-sm-3')); // add form to html page and show page From 3e68c5f35df911cf86bf62addc39b27d0f5c523e Mon Sep 17 00:00:00 2001 From: Mathias Huth Date: Wed, 24 Sep 2025 21:47:28 +0200 Subject: [PATCH 2/3] fix: enhance compatibility with Admidio 5.0 by updating class aliases and file inclusion logic --- classes/items.php | 66 +++++++++------------------- common_function.php | 23 +++++++--- inventory_manager.php | 41 +++++++++-------- preferences/preferences_function.php | 31 ++++++++----- 4 files changed, 78 insertions(+), 83 deletions(-) diff --git a/classes/items.php b/classes/items.php index 84a9f15..788692e 100644 --- a/classes/items.php +++ b/classes/items.php @@ -38,22 +38,24 @@ *********************************************************************************************** */ -// for Admidio 5.0 -use Admidio\Infrastructure\Database; -use Admidio\Infrastructure\Image; -use Admidio\Infrastructure\Language; -use Admidio\Infrastructure\Utils\StringUtils; -use Admidio\Infrastructure\Entity\Entity; -use Admidio\Infrastructure\Email; - -try { +// compatibility for Admidio 5.0 -> +if(file_exists(__DIR__ . '/../../../system/bootstrap/constants.php')) { require_once(__DIR__ . '/../../../system/bootstrap/constants.php'); -} catch (Exception $e) { +} else { require_once(__DIR__ . '/../../../adm_program/system/bootstrap/constants.php'); } - require_once(__DIR__ . '/configtable.php'); +// classes for Admidio 5.0 +if (!version_compare(ADMIDIO_VERSION, '5.0', '<')) { + class_alias(Admidio\Infrastructure\Database::class, Database::class); + class_alias(Admidio\Infrastructure\Image::class, Image::class); + class_alias(Admidio\Infrastructure\Language::class, Language::class); + class_alias(Admidio\Infrastructure\Utils\StringUtils::class, StringUtils::class); + class_alias(Admidio\Infrastructure\Entity\Entity::class, TableAccess::class); + class_alias(Admidio\Infrastructure\Email::class, Email::class); +} +// <- compatibility for Admidio 5.0 class CItems { public array $mItemFields = array(); ///< Array with all item fields objects @@ -588,11 +590,7 @@ public function readItemData(int $itemId, int $organizationId): void while ($row = $itemDataStatement->fetch()) { if (!array_key_exists($row['imd_imf_id'], $this->mItemData)) { - if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { - $this->mItemData[$row['imd_imf_id']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); - } else { - $this->mItemData[$row['imd_imf_id']] = new Entity($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); - } + $this->mItemData[$row['imd_imf_id']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); } $this->mItemData[$row['imd_imf_id']]->setArray($row); } @@ -628,11 +626,7 @@ public function saveItemData(): void // for updateFingerPrint a change in db must be executed // why !$this->itemCreated -> updateFingerPrint will be done in getNewItemId if (!$this->itemCreated && $this->columnsValueChanged) { - if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { - $updateItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $this->mItemId); - } else { - $updateItem = new Entity($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $this->mItemId); - } + $updateItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $this->mItemId); $updateItem->setValue('imi_usr_id_change', null, false); $updateItem->save(); } @@ -665,11 +659,7 @@ public function readItemFields(int $organizationId, string $orderBy = 'imf_id'): while ($row = $statement->fetch()) { if (!array_key_exists($row['imf_name_intern'], $this->mItemFields)) { - if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { - $this->mItemFields[$row['imf_name_intern']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_FIELDS, 'imf'); - } else { - $this->mItemFields[$row['imf_name_intern']] = new Entity($this->mDb, TBL_INVENTORY_MANAGER_FIELDS, 'imf'); - } + $this->mItemFields[$row['imf_name_intern']] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_FIELDS, 'imf'); } $this->mItemFields[$row['imf_name_intern']]->setArray($row); $this->itemFieldsSort[$row['imf_name_intern']] = $row['imf_sequence']; @@ -817,11 +807,7 @@ public function setValue(string $fieldNameIntern, $newValue): bool } if (!array_key_exists($imfId, $this->mItemData)) { - if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { - $this->mItemData[$imfId] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); - } else { - $this->mItemData[$imfId] = new Entity($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); - } + $this->mItemData[$imfId] = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_DATA, 'imd'); $this->mItemData[$imfId]->setValue('imd_imf_id', $imfId); $this->mItemData[$imfId]->setValue('imd_imi_id', $this->mItemId); } @@ -836,11 +822,7 @@ public function setValue(string $fieldNameIntern, $newValue): bool } if ($returnCode && $loggingEnabled) { - if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { - $logEntry = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_LOG, 'iml'); - } else { - $logEntry = new Entity($this->mDb, TBL_INVENTORY_MANAGER_LOG, 'iml'); - } + $logEntry = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_LOG, 'iml'); $logEntry->setValue('iml_imi_id', $this->mItemId); $logEntry->setValue('iml_imf_id', $imfId); $logEntry->setValue('iml_value_old', $oldFieldValue); @@ -870,21 +852,13 @@ public function getNewItemId(int $organizationId): int $statement = $this->mDb->queryPrepared($sql); while ($row = $statement->fetch()) { - if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { - $delItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $row['imi_id']); - } else { - $delItem = new Entity($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $row['imi_id']); - } + $delItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi', $row['imi_id']); $delItem->delete(); } // generate a new ItemId if ($this->itemCreated) { - if (version_compare(ADMIDIO_VERSION, '5.0.0', '<')) { - $newItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi'); - } else { - $newItem = new Entity($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi'); - } + $newItem = new TableAccess($this->mDb, TBL_INVENTORY_MANAGER_ITEMS, 'imi'); $newItem->setValue('imi_org_id', $organizationId); $newItem->setValue('imi_former', 0); $newItem->save(); diff --git a/common_function.php b/common_function.php index 5735082..db44bd6 100644 --- a/common_function.php +++ b/common_function.php @@ -33,16 +33,25 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Fill; -// for Admidio 5.0 -use Admidio\Components\Entity\Component; -use Admidio\Roles\Entity\RolesRights; -use Admidio\Menu\ValueObject\MenuNode; - -try { +// compatibility for Admidio 5.0 -> +if (file_exists(__DIR__ . '/../../system/common.php')) { require_once(__DIR__ . '/../../system/common.php'); -} catch (Exception $e) { +}else { require_once(__DIR__ . '/../../adm_program/system/common.php'); } +if(file_exists(__DIR__ . '/../../system/bootstrap/constants.php')) { + require_once(__DIR__ . '/../../system/bootstrap/constants.php'); +} else { + require_once(__DIR__ . '/../../adm_program/system/bootstrap/constants.php'); +} + +// classes for Admidio 5.0 +if (!version_compare(ADMIDIO_VERSION, '5.0', '<')) { + class_alias(Admidio\Components\Entity\Component::class, Component::class); + class_alias(Admidio\Roles\Entity\RolesRights::class, RolesRights::class); + class_alias(Admidio\Menu\ValueObject\MenuNode::class, MenuNode::class); +} +// <- compatibility for Admidio 5.0 // Define necessary constants if not already defined defineConstantsPIM(); diff --git a/inventory_manager.php b/inventory_manager.php index 4fc49fa..996d8a0 100644 --- a/inventory_manager.php +++ b/inventory_manager.php @@ -50,31 +50,34 @@ use PhpOffice\PhpSpreadsheet\Writer\Ods; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; -// for Admidio 5.0 -use Admidio\Infrastructure\Utils\SecurityUtils; -use Admidio\Users\Entity\User; -use Admidio\Infrastructure\Utils\FileSystemUtils; - -try { +// compatibility for Admidio 5.0 -> +if (file_exists(__DIR__ . '/../../system/common.php')) { require_once(__DIR__ . '/../../system/common.php'); - require_once(__DIR__ . '/../../system/bootstrap/constants.php'); - require_once(__DIR__ . '/common_function.php'); - require_once(__DIR__ . '/classes/items.php'); - require_once(__DIR__ . '/classes/configtable.php'); - - // Access only with valid login - require_once(__DIR__ . '/../../system/login_valid.php'); -} catch (Exception $e) { +}else { require_once(__DIR__ . '/../../adm_program/system/common.php'); +} +if(file_exists(__DIR__ . '/../../system/bootstrap/constants.php')) { + require_once(__DIR__ . '/../../system/bootstrap/constants.php'); +} else { require_once(__DIR__ . '/../../adm_program/system/bootstrap/constants.php'); - require_once(__DIR__ . '/common_function.php'); - require_once(__DIR__ . '/classes/items.php'); - require_once(__DIR__ . '/classes/configtable.php'); - - // Access only with valid login +} +require_once(__DIR__ . '/common_function.php'); +require_once(__DIR__ . '/classes/items.php'); +require_once(__DIR__ . '/classes/configtable.php'); +// Access only with valid login +if (file_exists(__DIR__ . '/../../system/login_valid.php')) { + require_once(__DIR__ . '/../../system/login_valid.php'); +} else { require_once(__DIR__ . '/../../adm_program/system/login_valid.php'); } +// classes for Admidio 5.0 +if (!version_compare(ADMIDIO_VERSION, '5.0', '<')) { + class_alias(Admidio\Infrastructure\Utils\SecurityUtils::class, SecurityUtils::class); + class_alias(Admidio\Users\Entity\User::class, User::class); + class_alias(Admidio\Infrastructure\Utils\FileSystemUtils::class, FileSystemUtils::class); +} +// <- compatibility for Admidio 5.0 //$scriptName is the name as it must be entered in the menu, without any preceding folders such as /playground/adm_plugins/InventoryManager... $scriptName = substr($_SERVER['SCRIPT_NAME'], strpos($_SERVER['SCRIPT_NAME'], FOLDER_PLUGINS)); diff --git a/preferences/preferences_function.php b/preferences/preferences_function.php index 895c2d4..93aa83f 100644 --- a/preferences/preferences_function.php +++ b/preferences/preferences_function.php @@ -27,23 +27,32 @@ // for Admidio 5.0 use Admidio\Infrastructure\Utils\SecurityUtils; -try { +// compatibility for Admidio 5.0 -> +if (file_exists(__DIR__ . '/../../../system/common.php')) { require_once(__DIR__ . '/../../../system/common.php'); - require_once(__DIR__ . '/../common_function.php'); - require_once(__DIR__ . '/../classes/configtable.php'); - -// Access only with valid login - require_once(__DIR__ . '/../../../system/login_valid.php'); - -} catch (Exception $e) { +}else { require_once(__DIR__ . '/../../../adm_program/system/common.php'); - require_once(__DIR__ . '/../common_function.php'); - require_once(__DIR__ . '/../classes/configtable.php'); - +} +if(file_exists(__DIR__ . '/../../system/bootstrap/constants.php')) { + require_once(__DIR__ . '/../../system/bootstrap/constants.php'); +} else { + require_once(__DIR__ . '/../../adm_program/system/bootstrap/constants.php'); +} +require_once(__DIR__ . '/../common_function.php'); +require_once(__DIR__ . '/../classes/configtable.php'); // Access only with valid login +if (file_exists(__DIR__ . '/../../../system/login_valid.php')) { + require_once(__DIR__ . '/../../../system/login_valid.php'); +} else { require_once(__DIR__ . '/../../../adm_program/system/login_valid.php'); } +// classes for Admidio 5.0 +if (!version_compare(ADMIDIO_VERSION, '5.0', '<')) { + class_alias(Admidio\Infrastructure\Utils\SecurityUtils::class, SecurityUtils::class); +} +// <- compatibility for Admidio 5.0 + $pPreferences = new CConfigTablePIM(); $pPreferences->read(); From 6ae0057f2367a7689aff569d622e82ffd36727bf Mon Sep 17 00:00:00 2001 From: Mathias Huth Date: Wed, 24 Sep 2025 21:50:59 +0200 Subject: [PATCH 3/3] fix: add exit() to prevent further script execution after showing deprecated page --- inventory_manager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inventory_manager.php b/inventory_manager.php index 996d8a0..6aea203 100644 --- a/inventory_manager.php +++ b/inventory_manager.php @@ -178,6 +178,7 @@ class_alias(Admidio\Infrastructure\Utils\FileSystemUtils::class, FileSystemUtils $content .= ''; $page->addHtml($content); $page->show(); + exit(); } }