diff --git a/classes/configdata.php b/classes/configdata.php index bfbda70..e745e08 100644 --- a/classes/configdata.php +++ b/classes/configdata.php @@ -26,36 +26,36 @@ class CConfigDataPIM /** * Default configuration data for plugin InventoryManager */ - const CONFIG_DEFAULT = [ - 'Optionen' => [ + const CONFIG_DEFAULT = array( + 'Optionen' => array( 'interface_pff' => 0, - 'profile_addin' => [ + 'profile_addin' => array( 'ITEMNAME', 'LAST_RECEIVER' - ], + ), 'file_name' => 'InventoryManager', 'add_date' => 0, 'allow_keeper_edit' => 0, - 'allowed_keeper_edit_fields' => [ + 'allowed_keeper_edit_fields' => array( 'IN_INVENTORY', 'LAST_RECEIVER', 'RECEIVED_ON', 'RECEIVED_BACK_ON' - ], + ), 'current_user_default_keeper' => 0, 'allow_negative_numbers' => 1, 'decimal_step' => 0.1, 'field_date_time_format' => 'date', - ], - 'Plugininformationen' => [ + ), + 'Plugininformationen' => array( 'version' => '', 'beta-version' => '', 'stand' => '', - ], - 'access' => [ - 'preferences' => [] - ] - ]; + ), + 'access' => array( + 'preferences' => array(0) + ) + ); /** * Database token for plugin InventoryManager diff --git a/classes/configtable.php b/classes/configtable.php index e4d80e4..27db19a 100644 --- a/classes/configtable.php +++ b/classes/configtable.php @@ -8,17 +8,33 @@ * @copyright 2024 - today MightyMCoder * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 only * - * methods: * + * Methods: + * __construct() : constructor + * checkPffInst() : used to check if the plugin FormFiller is installed * isPffInst() : used to check if plugin FormFiller is installed; if yes returns true otherwise false + * findPff() : used to check if a FormFiller directory exists * pffDir() : used to get the installation directory of the Plugin FormFiller; returns false if it doesn't exists or if it exists multiple times * init() : used to check if the configuration table exists, if not creates it and sets default values + * createTablesIfNotExist() : used to create the necessary tables if they do not exist + * createTableIfNotExist($tableName, + * $tableDefinition) : used to create a table if it does not exist + * initializeDefaultFieldsByOrgId() : used to initialize default fields in the inventory manager database + * createField($name, $internalName, $type, $description, + * $sequence, $system, $mandatory, + * $valueList = '') : used to create a field in the inventory manager database + * initializePreferencesByOrgId() : used to initialize preferences for the inventory manager * write() : used to write the configuration data to database * read() : used to read the configuration data from database + * readPff() : used to read the configuration data of plugin FormFiller from database + * readConfigData($pluginShortcut, + * &$configArray) : used to read the configuration data of a plugin from the database * checkForUpdate() : used to compare version and stand of file "/../version.php" with data from database + * compareVersion() : used to compare plugin version with the current version from the database + * compareStand() : used to compare plugin stand with the current stand from the database + * checkDefaultFieldsForCurrentOrg() : used to check if there are default fields for the current organization * deleteConfigData($deinstOrgSelect) : used to delete configuration data in database * deleteItemData($deinstOrgSelect) : used to delete item data in database - * *********************************************************************************************** */ @@ -49,9 +65,10 @@ public function __construct() /** * Checks if the plugin FormFiller is installed + * * @return void */ - private function checkPffInst() + private function checkPffInst() : void { global $gDb, $gCurrentOrgId; @@ -75,18 +92,20 @@ private function checkPffInst() /** * If the plugin FormFiller is installed * then this method will return true otherwise false - * @return bool Returns @b true if plugin FormFiller is installed + * + * @return bool Returns @b true if plugin FormFiller is installed */ - public function isPffInst() + public function isPffInst() : bool { return $this->isPffInst; } /** * Checks if a FormFiller directory exists + * * @return void */ - private function findPff() + private function findPff() : void { $location = ADMIDIO_PATH . FOLDER_PLUGINS; $searchedFile = 'formfiller.php'; @@ -120,7 +139,8 @@ private function findPff() /** * Returns the Plugin FormFiller directory - * @return bool/string Returns the FormFiller directory otherwise false + * + * @return bool/string Returns the FormFiller directory otherwise false */ public function pffDir() { @@ -129,9 +149,10 @@ public function pffDir() /** * checks if the configuration table exists, if necessarry creats it and fills it with default configuration data + * * @return void */ - public function init() + public function init() : void { $this->createTablesIfNotExist(); $this->initializeDefaultFieldsByOrgId(); @@ -140,9 +161,10 @@ public function init() /** * Creates the necessary tables if they do not exist + * * @return void */ - private function createTablesIfNotExist() + private function createTablesIfNotExist() : void { $this->createTableIfNotExist(TBL_INVENTORY_MANAGER_FIELDS, ' imf_id int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -204,11 +226,12 @@ private function createTablesIfNotExist() /** * Creates a table if it does not exist - * @param string $tableName The name of the table - * @param string $tableDefinition The SQL definition of the table + * + * @param string $tableName The name of the table + * @param string $tableDefinition The SQL definition of the table * @return void */ - private function createTableIfNotExist($tableName, $tableDefinition) + private function createTableIfNotExist($tableName, $tableDefinition) : void { global $gDb; @@ -223,9 +246,10 @@ private function createTableIfNotExist($tableName, $tableDefinition) /** * Initializes default fields in the inventory manager database + * * @return void */ - private function initializeDefaultFieldsByOrgId() + private function initializeDefaultFieldsByOrgId() : void { global $gDb, $gCurrentOrgId; @@ -393,17 +417,18 @@ private function initializeDefaultFieldsByOrgId() /** * Creates a field in the inventory manager database - * @param string $name The name of the field - * @param string $internalName The internal name of the field - * @param string $type The type of the field - * @param string $description The description of the field - * @param int $sequence The sequence order of the field - * @param bool $system Whether the field is a system field - * @param bool $mandatory Whether the field is mandatory - * @param string $valueList The value list for dropdown fields + * + * @param string $name The name of the field + * @param string $internalName The internal name of the field + * @param string $type The type of the field + * @param string $description The description of the field + * @param int $sequence The sequence order of the field + * @param bool $system Whether the field is a system field + * @param bool $mandatory Whether the field is mandatory + * @param string $valueList The value list for dropdown fields * @return void */ - private function createField($name, $internalName, $type, $description, $sequence, $system, $mandatory, $valueList = '') + private function createField($name, $internalName, $type, $description, $sequence, $system, $mandatory, $valueList = '') : void { global $gDb, $gCurrentOrgId; @@ -422,9 +447,10 @@ private function createField($name, $internalName, $type, $description, $sequenc /** * Initializes preferences for the inventory manager + * * @return void */ - private function initializePreferencesByOrgId() + private function initializePreferencesByOrgId() : void { global $gDb, $gCurrentOrgId; @@ -466,9 +492,10 @@ private function initializePreferencesByOrgId() /** * Writes the configuration data of plugin InventoryManager to the database + * * @return void */ - public function write() + public function write() : void { global $gDb, $gCurrentOrgId; @@ -489,7 +516,8 @@ public function write() // Record exists, update it $sql = 'UPDATE ' . $this->table_preferences_name . ' SET plp_value = ? WHERE plp_id = ?;'; $gDb->queryPrepared($sql, array($value, $row->plp_id)); - } else { + } + else { // Record does not exist, insert it $sql = 'INSERT INTO ' . $this->table_preferences_name . ' (plp_org_id, plp_name, plp_value) VALUES (?, ?, ?);'; $gDb->queryPrepared($sql, array($gCurrentOrgId, $plpName, $value)); @@ -500,32 +528,43 @@ public function write() /** * Reads the configuration data of plugin InventoryManager from the database - * @return void + * + * @return bool */ - public function read() + public function read() : bool { - $this->readConfigData(self::SHORTCUT, $this->config); + return $this->readConfigData(self::SHORTCUT, $this->config); } /** * Reads the configuration data of plugin FormFiller (PFF) from the database - * @return void + * + * @return bool */ - public function readPff() + public function readPff() : bool { - $this->readConfigData('PFF', $this->configPff); + return $this->readConfigData('PFF', $this->configPff); } /** * Reads the configuration data of a plugin from the database - * @param string $pluginShortcut The shortcut of the plugin - * @param array &$configArray The array to store the configuration data - * @return void + * + * @param string $pluginShortcut The shortcut of the plugin + * @param array &$configArray The array to store the configuration data + * @return bool */ - private function readConfigData($pluginShortcut, &$configArray) + private function readConfigData($pluginShortcut, &$configArray) : bool { global $gDb, $gCurrentOrgId; + // Check if table *_plugin_preferences exists + $sql = 'SHOW TABLES LIKE \'' . $this->table_preferences_name . '\' '; + $tablePreferencesExistStatement = $gDb->queryPrepared($sql); + + if ($tablePreferencesExistStatement->rowCount() === 0) { + return false; + } + $sql = 'SELECT plp_id, plp_name, plp_value FROM '.$this->table_preferences_name.' WHERE plp_name LIKE ? AND (plp_org_id = ? OR plp_org_id IS NULL);'; $statement = $gDb->queryPrepared($sql, array($pluginShortcut.'__%', $gCurrentOrgId)); @@ -564,13 +603,15 @@ private function readConfigData($pluginShortcut, &$configArray) } } } + return true; } /** * Compare plugin version and stand with current version and stand from database + * * @return bool */ - public function checkForUpdate() + public function checkForUpdate() : bool { global $gDb; @@ -595,9 +636,10 @@ public function checkForUpdate() /** * Compare plugin version with the current version from the database + * * @return bool */ - private function compareVersion() + private function compareVersion() : bool { global $gDb, $gCurrentOrgId; @@ -613,9 +655,10 @@ private function compareVersion() /** * Compare plugin stand with the current stand from the database + * * @return bool */ - private function compareStand() + private function compareStand() : bool { global $gDb, $gCurrentOrgId; @@ -631,9 +674,10 @@ private function compareStand() /** * Checks if there are default fields for the current organization. - * @return bool Returns true if there are no default fields for the current organization, false otherwise. + * + * @return bool Returns true if there are no default fields for the current organization, false otherwise. */ - private function checkDefaultFieldsForCurrentOrg() + private function checkDefaultFieldsForCurrentOrg() : bool { global $gDb, $gCurrentOrgId; @@ -649,10 +693,12 @@ private function checkDefaultFieldsForCurrentOrg() /** * Delete configuration data from the database - * @param int $deinstOrgSelect 0 = only delete data from current org, 1 = delete data from every org - * @return string $result Result message + * + * @param int $deinstOrgSelect 0 = only delete data from current org, + * 1 = delete data from every org + * @return string Result message */ - public function deleteConfigData($deinstOrgSelect) + public function deleteConfigData($deinstOrgSelect) : string { global $gDb, $gCurrentOrgId, $gL10n; @@ -669,7 +715,7 @@ public function deleteConfigData($deinstOrgSelect) $params[] = $gCurrentOrgId; } $result_data = $gDb->queryPrepared($sql, $params); - $result .= ($result_data ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', [$this->table_preferences_name]) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', [$this->table_preferences_name])); + $result .= ($result_data ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', array($this->table_preferences_name)) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', array($this->table_preferences_name))); // Check if the table is empty and can be deleted $sql = 'SELECT * FROM ' . $this->table_preferences_name; @@ -678,9 +724,9 @@ public function deleteConfigData($deinstOrgSelect) if ($statement->rowCount() == 0) { $sql = 'DROP TABLE ' . $this->table_preferences_name; $result_db = $gDb->queryPrepared($sql); - $result .= ($result_db ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETED', [$this->table_preferences_name]) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETE_ERROR', [$this->table_preferences_name])); + $result .= ($result_db ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETED', array($this->table_preferences_name)) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETE_ERROR', array($this->table_preferences_name))); } else { - $result .= $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_CONFIGTABLE_DELETE_NOTPOSSIBLE', [$this->table_preferences_name]); + $result .= $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_CONFIGTABLE_DELETE_NOTPOSSIBLE', array($this->table_preferences_name)); } return $result; @@ -688,39 +734,40 @@ public function deleteConfigData($deinstOrgSelect) /** * Delete the item data from the database + * * @param int $deinstOrgSelect 0 = only delete data from current org, 1 = delete data from every org * @return string $result Result message */ - public function deleteItemData($deinstOrgSelect) + public function deleteItemData($deinstOrgSelect) : string { global $gDb, $gCurrentOrgId, $gL10n; $result = ''; if ($deinstOrgSelect == 0) { $sql = 'DELETE FROM ' . TBL_INVENTORY_MANAGER_DATA . ' WHERE imd_imi_id IN (SELECT imi_id FROM ' . TBL_INVENTORY_MANAGER_ITEMS . ' WHERE imi_org_id = ?)'; - $result_data = $gDb->queryPrepared($sql, [$gCurrentOrgId]); - $result .= ($result_data ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', [TABLE_PREFIX . '_inventory_manager_data']) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', [TABLE_PREFIX . '_inventory_manager_data'])); + $result_data = $gDb->queryPrepared($sql, array($gCurrentOrgId)); + $result .= ($result_data ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', array(TABLE_PREFIX . '_inventory_manager_data')) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', array(TABLE_PREFIX . '_inventory_manager_data'))); $sql = 'DELETE FROM ' . TBL_INVENTORY_MANAGER_LOG . ' WHERE iml_imi_id IN (SELECT imi_id FROM ' . TBL_INVENTORY_MANAGER_ITEMS . ' WHERE imi_org_id = ?)'; - $result_log = $gDb->queryPrepared($sql, [$gCurrentOrgId]); - $result .= ($result_log ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', [TABLE_PREFIX . '_inventory_manager_log']) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', [TABLE_PREFIX . '_inventory_manager_log'])); + $result_log = $gDb->queryPrepared($sql, array($gCurrentOrgId)); + $result .= ($result_log ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', array(TABLE_PREFIX . '_inventory_manager_log')) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', array(TABLE_PREFIX . '_inventory_manager_log'))); $sql = 'DELETE FROM ' . TBL_INVENTORY_MANAGER_ITEMS . ' WHERE imi_org_id = ?'; - $result_items = $gDb->queryPrepared($sql, [$gCurrentOrgId]); - $result .= ($result_items ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', [TABLE_PREFIX . '_inventory_manager_items']) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', [TABLE_PREFIX . '_inventory_manager_items'])); + $result_items = $gDb->queryPrepared($sql, array($gCurrentOrgId)); + $result .= ($result_items ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', array(TABLE_PREFIX . '_inventory_manager_items')) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', array(TABLE_PREFIX . '_inventory_manager_items'))); $sql = 'DELETE FROM ' . TBL_INVENTORY_MANAGER_FIELDS . ' WHERE imf_org_id = ?'; - $result_fields = $gDb->queryPrepared($sql, [$gCurrentOrgId]); - $result .= ($result_fields ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', [TABLE_PREFIX . '_inventory_manager_fields']) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', [TABLE_PREFIX . '_inventory_manager_fields'])); + $result_fields = $gDb->queryPrepared($sql, array($gCurrentOrgId)); + $result .= ($result_fields ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN', array(TABLE_PREFIX . '_inventory_manager_fields')) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_DATA_DELETED_IN_ERROR', array(TABLE_PREFIX . '_inventory_manager_fields'))); } // Drop tables if they are empty or if data should be deleted from every org - $table_array = [ + $table_array = array( TBL_INVENTORY_MANAGER_FIELDS, TBL_INVENTORY_MANAGER_DATA, TBL_INVENTORY_MANAGER_ITEMS, TBL_INVENTORY_MANAGER_LOG - ]; + ); foreach ($table_array as $table_name) { $sql = 'SELECT * FROM ' . $table_name; @@ -729,9 +776,9 @@ public function deleteItemData($deinstOrgSelect) if ($statement->rowCount() == 0 || $deinstOrgSelect == 1) { $sql = 'DROP TABLE ' . $table_name; $result_db = $gDb->queryPrepared($sql); - $result .= ($result_db ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETED', [$table_name]) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETE_ERROR', [$table_name])); + $result .= ($result_db ? $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETED', array($table_name)) : $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETE_ERROR', array($table_name))); } else { - $result .= $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETE_NOTPOSSIBLE', [$table_name]); + $result .= $gL10n->get('PLG_INVENTORY_MANAGER_DEINST_TABLE_DELETE_NOTPOSSIBLE', array($table_name)); } } diff --git a/classes/items.php b/classes/items.php index ff05218..eaf280c 100644 --- a/classes/items.php +++ b/classes/items.php @@ -8,31 +8,33 @@ * @copyright 2024 - today MightyMCoder * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 only * - * methods: * + * Methods: * __construct($database, $organizationId) : Constructor that will initialize variables and read the item field structure * setDatabase($database) : Set the database object for communication with the database of this class * __sleep() : Called on serialization of this object. The database object could not be serialized and should be ignored * clearItemData() : Item data of all item fields will be initialized + * getItemId() : Retrieves the ID of the item * getProperty($fieldNameIntern, $column, $format = '') : Returns the value of a column from the table adm_inventory_manager_fields for a given internal field name * getPropertyById($fieldId, $column, $format = '') : Returns the value of a column from the table adm_inventory_manager_fields for a given field ID * getListValue($fieldNameIntern, $value, $format) : Returns the list values for a given field name intern (imf_name_intern) - * getHtmlValue($fieldNameIntern, $value,) : Returns the value of the field in html format with consideration of all layout parameters + * getHtmlValue($fieldNameIntern, $value) : Returns the value of the field in html format with consideration of all layout parameters * getValue($fieldNameIntern, $format = '') : Returns the item value for this column * showFormerItems($newValue = null) : This method reads or stores the variable for showing former items * isNewItem() : If the recordset is new and wasn't read from database or was not stored in database then this method will return true otherwise false * isDeletedItem() : If the recordset was deleted from database then this method will return true otherwise false * readItemData($itemId, $organizationId) : Reads the item data of all item fields out of database table adm_inventory_manager_data * saveItemData() : Save data of every item field - * readItemFields($organizationId) : Reads the item fields structure out of database table adm_inventory_manager_fields + * readItemFields($organizationId, $orderBy = 'imf_id') : Reads the item fields structure out of database table adm_inventory_manager_fields * readItems($organizationId) : Reads the items out of database table adm_inventory_manager_items - * readItemsByUser($organizationId, $userId) : Reads the items for a user out of database table adm_inventory_manager_items + * readItemsByUser($organizationId, $userId, $fieldNames) : Reads the items for a user out of database table adm_inventory_manager_items * setValue($fieldNameIntern, $newValue) : Set a new value for the item field of the table adm_inventory_manager_data * getNewItemId($organizationId) : Generates a new ItemId. The new value will be stored in mItemId * deleteItem($itemId, $organizationId) : Deletes an item from the database * makeItemFormer($itemId, $organizationId) : Marks an item as former in the database - * sendNotification($organizationId) : Sends a notification to all users that have the right to see the item - * + * undoItemFormer($itemId, $organizationId) : Marks an item as no longer former in the database + * setImportedItem() : Marks an item as imported + * sendNotification($importData = null) : Sends a notification to all users that have the right to see the item *********************************************************************************************** */ require_once(__DIR__ . '/configtable.php'); @@ -82,10 +84,12 @@ public function __construct($database, $organizationId, $fieldsOrderBy = 'imf_id } /** - * Set the database object for communication with the database of this class. - * @param \Database $database An object of the class Database. This should be the global $gDb object. + * Set the database object for communication with the database of this class + * + * @param \Database $database An object of the class Database. This should be the global $gDb object + * @return void */ - public function setDatabase($database) + public function setDatabase($database) : void { $this->mDb = $database; } @@ -93,6 +97,7 @@ public function setDatabase($database) /** * Called on serialization of this object. The database object could not * be serialized and should be ignored. + * * @return string[] Returns all class variables that should be serialized. */ public function __sleep() @@ -103,8 +108,10 @@ public function __sleep() /** * Item data of all item fields will be initialized * the fields array will not be renewed + * + * @return void */ - public function clearItemData() + public function clearItemData() : void { $this->mChangedItemData = array(); $this->mItemData = array(); @@ -113,21 +120,22 @@ public function clearItemData() } /** - * Retrieves the ID of the item. + * Retrieves the ID of the item * - * @return int The ID of the item. + * @return int The ID of the item */ - public function getItemId() + public function getItemId() : int { return $this->mItemId; } /** - * Returns the value of a column from the table adm_inventory_manager_fields for a given internal field name. + * Returns the value of a column from the table adm_inventory_manager_fields for a given internal field name + * * @param string $fieldNameIntern Expects the @b imf_name_intern of table @b adm_inventory_manager_fields * @param string $column The column name of @b adm_inventory_manager_fields for which you want the value * @param string $format Optional the format (is necessary for timestamps) - * @return array|string Returns the value for the column. + * @return array|string Returns the value for the column */ public function getProperty($fieldNameIntern, $column, $format = '') { @@ -147,12 +155,13 @@ public function getProperty($fieldNameIntern, $column, $format = '') /** * Returns the value of a column from the table adm_inventory_manager_fields for a given field ID + * * @param int $fieldId Expects the @b imf_id of table @b adm_inventory_manager_fields * @param string $column The column name of @b adm_inventory_manager_fields for which you want the value * @param string $format Optional the format (is necessary for timestamps) * @return string Returns the value for the column. */ - public function getPropertyById($fieldId, $column, $format = '') + public function getPropertyById($fieldId, $column, $format = '') : string { foreach ($this->mItemFields as $field) { if ((int) $field->getValue('imf_id') === (int) $fieldId) { @@ -164,13 +173,14 @@ public function getPropertyById($fieldId, $column, $format = '') } /** - * Returns the list values for a given field name intern (imf_name_intern). + * Returns the list values for a given field name intern (imf_name_intern) + * * @param string $fieldNameIntern Expects the @b imf_name_intern of table @b adm_inventory_manager_fields * @param string $value The value to be formatted * @param string $format Optional the format (is necessary for timestamps) - * @return array Returns an array with the list values for the given field name intern. + * @return array Returns an array with the list values for the given field name intern */ - protected function getListValue($fieldNameIntern, $value, $format) + protected function getListValue($fieldNameIntern, $value, $format) : array { $arrListValuesWithItems = array(); // array with list values and items that represents the internal value @@ -225,12 +235,13 @@ protected function getListValue($fieldNameIntern, $value, $format) /** * Returns the value of the field in html format with consideration of all layout parameters + * * @param string $fieldNameIntern Internal item field name of the field that should be html formatted * @param string|int $value The value that should be formatted must be committed so that layout * is also possible for values that aren't stored in database * @return string Returns an html formatted string that considered the profile field settings */ - public function getHtmlValue($fieldNameIntern, $value) + public function getHtmlValue($fieldNameIntern, $value) : string { global $gSettingsManager; @@ -255,6 +266,7 @@ public function getHtmlValue($fieldNameIntern, $value) '; break; + case 'DATE': if ($value !== '') { // date must be formatted @@ -280,6 +292,7 @@ public function getHtmlValue($fieldNameIntern, $value) } } break; + case 'DROPDOWN': case 'RADIO_BUTTON': $arrListValuesWithItems = array(); // array with list values and items that represents the internal value @@ -317,13 +330,15 @@ public function getHtmlValue($fieldNameIntern, $value) if (array_key_exists($value, $arrListValuesWithItems)) { $htmlValue = $arrListValuesWithItems[$value]; - } else { + } + else { // if value is not in list then delete the value $htmlValue = ''; //'list value '.$value .' not found'; //$htmlValue = $gL10n->get('PLG_INVENTORY_MANAGER_ITEMFIELD', array($value)); } break; + case 'TEXT_BIG': $htmlValue = nl2br($value); break; @@ -343,12 +358,13 @@ public function getHtmlValue($fieldNameIntern, $value) /** * Returns the item value for this column + * * format = 'html' : returns the value in html-format if this is necessary for that field type * format = 'database' : returns the value that is stored in database with no format applied * @param string $fieldNameIntern Expects the @b imf_name_intern of table @b adm_inventory_manager_fields * @param string $format Returns the field value in a special format @b text, @b html, @b database * or datetime (detailed description in method description) - * @return string|int|bool Returns the value for the column. + * @return string|int|bool Returns the value for the column */ public function getValue($fieldNameIntern, $format = '') { @@ -396,11 +412,13 @@ public function getValue($fieldNameIntern, $format = '') else { $value = $date->format($gSettingsManager->getString('system_date')); } - } else { + } + else { $value = $date->format($format); } } break; + case 'DROPDOWN': case 'RADIO_BUTTON': // the value in db is only the position, now search for the text @@ -424,10 +442,11 @@ public function getValue($fieldNameIntern, $format = '') /** * This method reads or stores the variable for showing former items. * The values will be stored in database without any inspections! + * * @param bool|null $newValue If set, then the new value will be stored in @b showFormerItems. * @return bool Returns the current value of @b showFormerItems */ - public function showFormerItems($newValue = null) + public function showFormerItems($newValue = null) : bool { if ($newValue !== null) { $this->showFormerItems = $newValue; @@ -438,18 +457,20 @@ public function showFormerItems($newValue = null) /** * If the recordset is new and wasn't read from database or was not stored in database * then this method will return true otherwise false + * * @return bool Returns @b true if record is not stored in database */ - public function isNewItem() + public function isNewItem() : bool { return $this->itemCreated; } /** * If the recordset was deleted from database then this method will return true otherwise false + * * @return bool Returns @b true if record is removed from databaseIf the recordset was deleted from database then this method will return true otherwise false */ - public function isDeletedItem() + public function isDeletedItem() : bool { return $this->itemDeleted; } @@ -458,11 +479,13 @@ public function isDeletedItem() * Reads the item data of all item fields out of database table @b adm_inventory_manager_data * and adds an object for each field data to the @b mItemData array. * If profile fields structure wasn't read, this will be done before. + * * @param int $itemId The id of the item for which the item data should be read. * @param int $organizationId The id of the organization for which the item fields * structure should be read if necessary. + * @return void */ - public function readItemData($itemId, $organizationId) + public function readItemData($itemId, $organizationId) : void { if (count($this->mItemFields) === 0) { $this->readItemFields($organizationId); @@ -495,8 +518,10 @@ public function readItemData($itemId, $organizationId) /** * Save data of every item field + * + * @return void */ - public function saveItemData() + public function saveItemData() : void { $this->mDb->startTransaction(); @@ -531,10 +556,13 @@ public function saveItemData() /** * Reads the item fields structure out of database table @b adm_inventory_manager_fields * and adds an object for each field structure to the @b mItemFields array. + * * @param int $organizationId The id of the organization for which the item fields * structure should be read. + * @param string $orderBy The field by which the item fields should be sorted + * @return void */ - public function readItemFields($organizationId, $orderBy = 'imf_id') + public function readItemFields($organizationId, $orderBy = 'imf_id') : void { // first initialize existing data $this->mItemFields = array(); @@ -559,9 +587,11 @@ public function readItemFields($organizationId, $orderBy = 'imf_id') /** * Reads the items out of database table @b adm_inventory_manager_items * and stores the values to the @b items array. + * * @param int $organizationId The id of the organization for which the items should be read. + * @return void */ - public function readItems($organizationId) + public function readItems($organizationId) : void { // first initialize existing data $this->items = array(); @@ -587,11 +617,13 @@ public function readItems($organizationId) /** * Reads the items for a user out of database table @b adm_inventory_manager_items * and stores the values to the @b items array. + * * @param int $organizationId The id of the organization for which the items should be read. * @param int $userId The id of the user for which the items should be read. - * @param string[] $fieldNames field names that should be read + * @param array $fieldNames The internal unique profile field names for which the items should be read + * @return void */ - public function readItemsByUser($organizationId, $userId, $fieldNames = array('KEEPER')) + public function readItemsByUser($organizationId, $userId, $fieldNames = array('KEEPER')) : void { // first initialize existing data $this->items = array(); @@ -630,11 +662,12 @@ public function readItemsByUser($organizationId, $userId, $fieldNames = array('K * Set a new value for the item field of the table adm_inventory_manager_data. * If the user log is activated then the change of the value will be logged in @b adm_inventory_manager_log. * The value is only saved in the object. You must call the method @b save to store the new value to the database + * * @param string $fieldNameIntern The internal unique profile field name * @param mixed $newValue The new value that should be stored in the database field * @return bool Returns @b true if the value is stored in the current object and @b false if a check failed */ - public function setValue($fieldNameIntern, $newValue) + public function setValue($fieldNameIntern, $newValue) : bool { global $gSettingsManager; @@ -713,11 +746,12 @@ public function setValue($fieldNameIntern, $newValue) } /** - * Generates a new ItemId. The new value will be stored in @b mItemId. + * Generates a new ItemId. The new value will be stored in mItemId. + * * @param int $organizationId The id of the organization for which the items should be read. - * @return int @b mItemId + * @return int mItemId */ - public function getNewItemId($organizationId) + public function getNewItemId($organizationId) : int { // If an error occurred while generating an item, there is an ItemId but no data for that item. // the following routine deletes these unused ItemIds @@ -750,10 +784,12 @@ public function getNewItemId($organizationId) /** * delete an item + * * @param int $itemId The id of the item that should be deleted * @param int $organizationId The id of the organization from which the items should be deleted + * @return void */ - public function deleteItem($itemId, $organizationId) + public function deleteItem($itemId, $organizationId) : void { $sql = 'DELETE FROM '.TBL_INVENTORY_MANAGER_LOG.' WHERE iml_imi_id = ?;'; $this->mDb->queryPrepared($sql, array($itemId)); @@ -768,12 +804,14 @@ public function deleteItem($itemId, $organizationId) } /** - * Marks an item as former. + * Marks an item as former + * * @param int $itemId The ID of the item to be marked as former. * @param int $organizationId The id of the organization from which the items should be marked as former + * @return void */ - public function makeItemFormer($itemId, $organizationId) { - + public function makeItemFormer($itemId, $organizationId) : void + { $sql = 'UPDATE '.TBL_INVENTORY_MANAGER_ITEMS.' SET imi_former = 1 WHERE imi_id = ? AND (imi_org_id = ? OR imi_org_id IS NULL);'; $this->mDb->queryPrepared($sql, array($itemId, $organizationId)); @@ -781,11 +819,14 @@ public function makeItemFormer($itemId, $organizationId) { } /** - * Marks an item as no longer former. + * Marks an item as no longer former + * * @param int $itemId The ID of the item to be marked as no longer former. * @param int $organizationId The id of the organization from which the items should be marked as no longer former. + * @return void */ - public function undoItemFormer($itemId, $organizationId) { + public function undoItemFormer($itemId, $organizationId) : void + { $sql = 'UPDATE '.TBL_INVENTORY_MANAGER_ITEMS.' SET imi_former = 0 WHERE imi_id = ? AND (imi_org_id = ? OR imi_org_id IS NULL);'; $this->mDb->queryPrepared($sql, array($itemId, $organizationId)); @@ -794,8 +835,11 @@ public function undoItemFormer($itemId, $organizationId) { /** * Marks an item as imported. + * + * @return void */ - public function setImportedItem() { + public function setImportedItem() : void + { $this->itemImported = true; } @@ -804,14 +848,15 @@ public function setImportedItem() { * to all members of the notification role. This role is configured within the global preference * **system_notifications_role**. The email contains the item name, the name of the current user, * the timestamp, and the details of the changes. - * @param int $organizationId The id of the organization from which the notifications should be sent + * + * @param array $importData The data of the imported items * @return bool Returns **true** if the notification was sent * @throws AdmException 'SYS_EMAIL_NOT_SEND' * @throws Exception */ - public function sendNotification($organizationId, $importData = null): bool + public function sendNotification($importData = null) : bool { - global $gProfileFields, $gCurrentUser, $gSettingsManager, $gL10n; + global $gCurrentUser, $gSettingsManager, $gL10n; // check if notifications are enabled if ($gSettingsManager->getBool('system_notifications_new_entries')) { diff --git a/common_function.php b/common_function.php index bce5ff0..1d0ca42 100644 --- a/common_function.php +++ b/common_function.php @@ -9,33 +9,37 @@ * @copyright 2024 - today MightyMCoder * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 only * - * methods: * - * defineConstantsPIM() : Define necessary constants if not already defined - * isUserAuthorizedForPIM($scriptName) : Check if the user is authorized to access the plugin - * getMenuIdByScriptNamePIM($scriptName) : Get menu ID by script name - * isUserAuthorizedForPreferencesPIM() : Check if the user is authorized to access the Preferences module - * function isUserAuthorizedForAddinPIM() : Check if the user is authorized to see the Inventory Manager Addin on the profile page - * convlanguagePIM($field_name) : Translate field name according to naming conventions - * getNewNameInternPIM($name, $index) : Generate a new internal name - * genNewSequencePIM() : Generate a new sequence number - * umlautePIM($tmptext) : Replace umlauts in the text + * Methods: + * defineConstantsPIM() : Define necessary constants if not already defined + * isUserAuthorizedForPIM($scriptName) : Check if the user is authorized to access the plugin + * isUserAuthorizedForPreferencesPIM() : Check if the user is authorized to access the Preferences module + * isUserAuthorizedForAddinPIM() : Check if the user is authorized to see the + * Inventory Manager Addin on the profile page + * isKeeperAuthorizedToEdit($keeper) : Check if the keeper is authorized to edit spezific item data + * getMenuIdByScriptNamePIM($scriptName) : Get menu ID by script name + * convlanguagePIM($field_name) : Translate field name according to naming conventions + * getNewNameInternPIM($name, $index) : Generate a new internal name + * genNewSequencePIM() : Generate a new sequence number + * umlautePIM($tmptext) : Replace umlauts in the text * getPreferencePanelPIM($group, $id, $title, $icon, $body) : Generate HTML for a preference panel - * + * getSqlOrganizationsUsersCompletePIM() : Get all users with their id, name, and address + * getSqlOrganizationsUsersShortPIM() : Get all users with their id and name *********************************************************************************************** */ require_once(__DIR__ . '/../../adm_program/system/common.php'); +// Define necessary constants if not already defined defineConstantsPIM(); /** * Define necessary constants if not already defined + * + * @return void */ -function defineConstantsPIM() +function defineConstantsPIM() : void { - global $g_tbl_praefix; - if (!defined('PLUGIN_FOLDER_IM')) { define('PLUGIN_FOLDER_IM', '/' . basename(__DIR__)); } @@ -55,10 +59,11 @@ function defineConstantsPIM() /** * Check if the user is authorized to access the plugin + * * @param string $scriptName The script name of the plugin * @return bool true if the user is authorized */ -function isUserAuthorizedForPIM($scriptName) +function isUserAuthorizedForPIM($scriptName) : bool { global $gMessage, $gL10n, $gDb, $gCurrentUser; $gCurrentUser = $GLOBALS['gCurrentUser']; @@ -88,29 +93,12 @@ function isUserAuthorizedForPIM($scriptName) return $userIsAuthorized; } -/** - * Get menu ID by script name - * @param string $scriptName The script name of the plugin - * @return int|null The menu ID or null if not found - */ -function getMenuIdByScriptNamePIM($scriptName) -{ - global $gDb; - - $sql = 'SELECT men_id FROM ' . TBL_MENU . ' WHERE men_url = ?;'; - $menuStatement = $gDb->queryPrepared($sql, array($scriptName)); - - if ($menuStatement->rowCount() === 1) { - return (int)$menuStatement->fetch()['men_id']; - } - return null; -} - /** * Check if the user is authorized to access the Preferences module + * * @return bool true if the user is authorized */ -function isUserAuthorizedForPreferencesPIM() +function isUserAuthorizedForPreferencesPIM() : bool { global $pPreferences, $gCurrentUser; $gCurrentUser = $GLOBALS['gCurrentUser']; @@ -127,32 +115,12 @@ function isUserAuthorizedForPreferencesPIM() return false; } - -/** - * Check if the keeper is authorized to edit spezific item data - * - * @param int|null $keeper The user ID of the keeper. - * @return bool Returns true if the current user is authorized, otherwise false. - */ -function isKeeperAuthorizedToEdit(int $keeper = null) -{ - global $pPreferences, $gCurrentUser; - $gCurrentUser = $GLOBALS['gCurrentUser']; - - if ($pPreferences->config['Optionen']['allow_keeper_edit'] === 1) { - if (isset($keeper) && $keeper === $gCurrentUser->getValue('usr_id')) { - return true; - } - } - - return false; -} - /** * Check if the user is authorized to see the Inventory Manager Addin on the profile page + * * @return bool true if the user is authorized */ -function isUserAuthorizedForAddinPIM() +function isUserAuthorizedForAddinPIM() : bool { global $gDb; @@ -186,12 +154,52 @@ function isUserAuthorizedForAddinPIM() return false; } +/** + * Check if the keeper is authorized to edit spezific item data + * + * @param int|null $keeper The user ID of the keeper + * @return bool true if the keeper is authorized + */ +function isKeeperAuthorizedToEdit(int $keeper = null) : bool +{ + global $pPreferences, $gCurrentUser; + $gCurrentUser = $GLOBALS['gCurrentUser']; + + if ($pPreferences->config['Optionen']['allow_keeper_edit'] === 1) { + if (isset($keeper) && $keeper === $gCurrentUser->getValue('usr_id')) { + return true; + } + } + + return false; +} + +/** + * Get menu ID by script name + * + * @param string $scriptName The script name of the plugin + * @return int|null The menu ID or null if not found + */ +function getMenuIdByScriptNamePIM($scriptName) : ?int +{ + global $gDb; + + $sql = 'SELECT men_id FROM ' . TBL_MENU . ' WHERE men_url = ?;'; + $menuStatement = $gDb->queryPrepared($sql, array($scriptName)); + + if ($menuStatement->rowCount() === 1) { + return (int)$menuStatement->fetch()['men_id']; + } + return null; +} + /** * Translate field name according to naming conventions + * * @param string $field_name field name to translate * @return string translated field name */ -function convlanguagePIM($field_name) +function convlanguagePIM($field_name) : string { global $gL10n; @@ -200,11 +208,12 @@ function convlanguagePIM($field_name) /** * Generate a new internal name + * * @param string $name name to generate internal name from * @param int $index index to append to the internal name * @return string new internal name */ -function getNewNameInternPIM($name, $index) +function getNewNameInternPIM($name, $index) : string { global $gDb; @@ -227,9 +236,10 @@ function getNewNameInternPIM($name, $index) /** * Generate a new sequence number + * * @return int new sequence number */ -function genNewSequencePIM() +function genNewSequencePIM() : int { global $gDb, $gCurrentOrgId; @@ -242,10 +252,11 @@ function genNewSequencePIM() /** * Replace umlauts in the text + * * @param string $tmptext text to replace umlauts in * @return string text with replaced umlauts */ -function umlautePIM($tmptext) +function umlautePIM($tmptext) : string { $replacements = [ 'ü' => 'ue', @@ -265,6 +276,7 @@ function umlautePIM($tmptext) /** * Generate HTML for a preference panel + * * @param string $group group the preference panel belongs to * @param string $id unique ID of the preference panel * @param string $title title of the preference panel @@ -272,7 +284,7 @@ function umlautePIM($tmptext) * @param string $body body of the preference panel * @return string HTML for the preference panel */ -function getPreferencePanelPIM($group, $id, $title, $icon, $body) +function getPreferencePanelPIM($group, $id, $title, $icon, $body) : string { return '
' . $gL10n->get('PLG_INVENTORY_MANAGER_ITEMFIELD_DELETE_DESC') . '
'); - - // show form - $form = new HtmlForm('itemfield_delete_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/fields/fields_delete.php', array('imf_id' => $getimfId, 'mode' => 2)), $page); - - $form->addInput('imf_name', $gL10n->get('SYS_NAME'), $itemField->getValue('imf_name', 'database'), array('maxLength' => 100, 'property' => HtmlForm::FIELD_DISABLED)); - - // show internal field name for information - $form->addInput('imf_name_intern', $gL10n->get('SYS_INTERNAL_NAME'), $itemField->getValue('imf_name_intern'), array('maxLength' => 100, 'property' => HtmlForm::FIELD_DISABLED)); - - $itemFieldText = array( - 'CHECKBOX' => $gL10n->get('SYS_CHECKBOX'), - 'DATE' => $gL10n->get('SYS_DATE'), - 'DECIMAL' => $gL10n->get('SYS_DECIMAL_NUMBER'), - 'DROPDOWN' => $gL10n->get('SYS_DROPDOWN_LISTBOX'), - 'NUMBER' => $gL10n->get('SYS_NUMBER'), - 'RADIO_BUTTON' => $gL10n->get('SYS_RADIO_BUTTON'), - 'TEXT' => $gL10n->get('SYS_TEXT') . ' (100 ' . $gL10n->get('SYS_CHARACTERS') . ')', - 'TEXT_BIG' => $gL10n->get('SYS_TEXT') . ' (4000 ' . $gL10n->get('SYS_CHARACTERS') . ')', - ); - asort($itemFieldText); - - $form->addInput('imf_type', $gL10n->get('ORG_DATATYPE'), $itemFieldText[$itemField->getValue('imf_type')], array('maxLength' => 30, 'property' => HtmlForm::FIELD_DISABLED)); - - $form->addMultilineTextInput('imf_value_list', $gL10n->get('ORG_VALUE_LIST'), (string) $itemField->getValue('imf_value_list', 'database'), 6, array('property' => HtmlForm::FIELD_DISABLED)); - - $form->addMultilineTextInput('imf_description', $gL10n->get('SYS_DESCRIPTION'), $itemField->getValue('imf_description'), 3, array('property' => HtmlForm::FIELD_DISABLED)); - - $form->addSubmitButton('btn_delete', $gL10n->get('SYS_DELETE'), array('icon' => 'fa-trash-alt', 'class' => ' offset-sm-3')); - - $page->addHtml($form->show(false)); - $page->show(); - break; - - case 2: - $sql = 'DELETE FROM ' . TBL_INVENTORY_MANAGER_LOG . ' WHERE iml_imf_id = ?;'; - $gDb->queryPrepared($sql, array($getimfId)); - - $sql = 'DELETE FROM '.TBL_INVENTORY_MANAGER_DATA.' WHERE imd_imf_id = ?;'; - $gDb->queryPrepared($sql, array($getimfId)); - - $sql = 'DELETE FROM '.TBL_INVENTORY_MANAGER_FIELDS.' WHERE imf_id = ? AND (imf_org_id = ? OR imf_org_id IS NULL);'; - $gDb->queryPrepared($sql, array($getimfId, $gCurrentOrgId)); - - // go back to item view - $gMessage->setForwardUrl($gNavigation->getPreviousUrl(), 1000); - $gMessage->show($gL10n->get('PLG_INVENTORY_MANAGER_ITEMFIELD_DELETED')); - - break; - // => EXIT -} \ No newline at end of file + } + + setValueList(); + $("#imf_type").click(function() { setValueList(); });', + true +); + +// add current url to navigation stack +$gNavigation->addUrl(CURRENT_URL, $headline); +$page->addHtml('' . $gL10n->get('PLG_INVENTORY_MANAGER_ITEMFIELD_DELETE_DESC') . '
'); + +// show form +$itemFieldText = array( + 'CHECKBOX' => $gL10n->get('SYS_CHECKBOX'), + 'DATE' => $gL10n->get('SYS_DATE'), + 'DECIMAL' => $gL10n->get('SYS_DECIMAL_NUMBER'), + 'DROPDOWN' => $gL10n->get('SYS_DROPDOWN_LISTBOX'), + 'NUMBER' => $gL10n->get('SYS_NUMBER'), + 'RADIO_BUTTON' => $gL10n->get('SYS_RADIO_BUTTON'), + 'TEXT' => $gL10n->get('SYS_TEXT') . ' (100 ' . $gL10n->get('SYS_CHARACTERS') . ')', + 'TEXT_BIG' => $gL10n->get('SYS_TEXT') . ' (4000 ' . $gL10n->get('SYS_CHARACTERS') . ')', +); +asort($itemFieldText); + +$form = new HtmlForm('itemfield_delete_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/fields/fields_function.php', array('imf_id' => $getimfId, 'mode' => 2)), $page); +$form->addInput('imf_name', $gL10n->get('SYS_NAME'), $itemField->getValue('imf_name', 'database'), array('maxLength' => 100, 'property' => HtmlForm::FIELD_DISABLED)); +$form->addInput('imf_name_intern', $gL10n->get('SYS_INTERNAL_NAME'), $itemField->getValue('imf_name_intern'), array('maxLength' => 100, 'property' => HtmlForm::FIELD_DISABLED)); +$form->addInput('imf_type', $gL10n->get('ORG_DATATYPE'), $itemFieldText[$itemField->getValue('imf_type')], array('maxLength' => 30, 'property' => HtmlForm::FIELD_DISABLED)); +$form->addMultilineTextInput('imf_value_list', $gL10n->get('ORG_VALUE_LIST'), (string) $itemField->getValue('imf_value_list', 'database'), 6, array('property' => HtmlForm::FIELD_DISABLED)); +$form->addMultilineTextInput('imf_description', $gL10n->get('SYS_DESCRIPTION'), $itemField->getValue('imf_description'), 3, array('property' => HtmlForm::FIELD_DISABLED)); +$form->addSubmitButton('btn_delete', $gL10n->get('SYS_DELETE'), array('icon' => 'fa-trash-alt', 'class' => ' offset-sm-3')); +$page->addHtml($form->show(false)); +$page->show(); diff --git a/fields/fields_edit_new.php b/fields/fields_edit_new.php index eb40fc9..b75e7ad 100644 --- a/fields/fields_edit_new.php +++ b/fields/fields_edit_new.php @@ -8,12 +8,11 @@ * @copyright 2024 - today MightyMCoder * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 only * - * Parameters: * + * Parameters: * imf_id : ID of the item field that should be edited * field_name : Name of the field that should be set * redirect_to_import : If true, the user will be redirected to the import page after saving the field - * *********************************************************************************************** */ @@ -78,23 +77,24 @@ function setValueList() { } setValueList(); - $("#imf_type").click(function() { setValueList(); }); -', true); + $("#imf_type").click(function() { setValueList(); });', + true +); // show form -$form = new HtmlForm('item_fields_edit_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/fields/fields_function.php', ['imf_id' => $getimfId, 'mode' => 1, 'redirect_to_import' => $getRedirectToImport]), $page); +$form = new HtmlForm('item_fields_edit_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/fields/fields_function.php', array('imf_id' => $getimfId, 'mode' => 1, 'redirect_to_import' => $getRedirectToImport)), $page); $form->addInput('imf_name', $gL10n->get('SYS_NAME'), $itemField->getValue('imf_name', 'database'), array( - 'maxLength' => 100, - 'property' => $itemField->getValue('imf_system') == 1 ? HtmlForm::FIELD_DEFAULT : HtmlForm::FIELD_REQUIRED + 'maxLength' => 100, + 'property' => $itemField->getValue('imf_system') == 1 ? HtmlForm::FIELD_DEFAULT : HtmlForm::FIELD_REQUIRED ) ); if ($getimfId > 0) { $form->addInput('imf_name_intern', $gL10n->get('SYS_INTERNAL_NAME'), $itemField->getValue('imf_name_intern'), array( - 'maxLength' => 100, - 'property' => HtmlForm::FIELD_DISABLED, - 'helpTextIdLabel' => 'SYS_INTERNAL_NAME_DESC' + 'maxLength' => 100, + 'property' => HtmlForm::FIELD_DISABLED, + 'helpTextIdLabel' => 'SYS_INTERNAL_NAME_DESC' ) ); } @@ -113,28 +113,28 @@ function setValueList() { //bei Systemfeldern darf der Datentyp nicht mehr veraendert werden $form->addSelectBox('imf_type', $gL10n->get('ORG_DATATYPE'), $itemFieldText, array( - 'property' => $itemField->getValue('imf_system') == 1 ? HtmlForm::FIELD_DISABLED : HtmlForm::FIELD_REQUIRED, - 'defaultValue' => $itemField->getValue('imf_type') + 'property' => $itemField->getValue('imf_system') == 1 ? HtmlForm::FIELD_DISABLED : HtmlForm::FIELD_REQUIRED, + 'defaultValue' => $itemField->getValue('imf_type') ) ); $form->addMultilineTextInput('imf_value_list', $gL10n->get('ORG_VALUE_LIST'), (string)$itemField->getValue('imf_value_list', 'database'), 6, array( - 'property' => HtmlForm::FIELD_REQUIRED, - 'helpTextIdLabel' => 'ORG_VALUE_LIST_DESC' + 'property' => HtmlForm::FIELD_REQUIRED, + 'helpTextIdLabel' => 'ORG_VALUE_LIST_DESC' ) ); $form->addCheckbox('imf_mandatory', $gL10n->get('SYS_REQUIRED_INPUT'), (bool)$itemField->getValue('imf_mandatory'), array( - 'property' => HtmlForm::FIELD_DEFAULT, - 'icon' => 'fa-asterisk' + 'property' => HtmlForm::FIELD_DEFAULT, + 'icon' => 'fa-asterisk' ) ); $form->addMultilineTextInput('imf_description', $gL10n->get('SYS_DESCRIPTION'), $itemField->getValue('imf_description'), 3); $form->addSubmitButton('btn_save', $gL10n->get('SYS_SAVE'), array( - 'icon' => 'fa-check', - 'class' => 'offset-sm-3' + 'icon' => 'fa-check', + 'class' => 'offset-sm-3' ) ); diff --git a/fields/fields_function.php b/fields/fields_function.php index 827d78a..97bc2d4 100644 --- a/fields/fields_function.php +++ b/fields/fields_function.php @@ -8,17 +8,17 @@ * @copyright 2024 - today MightyMCoder * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 only * - * Parameters: * + * Parameters: * imf_id : ID of the item field to be managed * mode : 1 - create or edit item field * 2 - delete item field - * 4 - change sequence of item field + * 3 - change sequence of item field * sequence : direction to move the item field, values are TableUserField::MOVE_UP, TableUserField::MOVE_DOWN * redirect_to_import : If true, the user will be redirected to the import page after saving the field * - * Methods: * + * Methods: * handleCreateOrUpdate($itemField, $getRedirectToImport) : Handles the creation or update of an item field * handleDelete($itemField) : Handles the deletion of an item field * handleChangeSequence($itemField, $getSequence) : Handles changing the sequence of an item field @@ -65,20 +65,26 @@ case 1: handleCreateOrUpdate($itemField, $getRedirectToImport); break; + case 2: handleDelete($itemField); break; - case 4: + + case 3: handleChangeSequence($itemField, $getSequence); break; } /** - * Handles the creation or update of an item field. - * @param TableAccess $itemField The item field object to be created or updated. + * Handles the creation or update of an item field + * + * @param TableAccess $itemField The item field object to be created or updated + * @param bool $redirectToImport If true, the user will be redirected to the import page after saving the field + * @return void */ -function handleCreateOrUpdate($itemField, $redirectToImport = false) { - global $gMessage, $gL10n, $gDb, $gCurrentOrgId; +function handleCreateOrUpdate($itemField, $redirectToImport = false) : void +{ + global $gMessage, $gL10n, $gCurrentOrgId; $_SESSION['fields_request'] = $_POST; @@ -104,7 +110,8 @@ function handleCreateOrUpdate($itemField, $redirectToImport = false) { $itemField->setValue($item, $value); } } - } catch (AdmException $e) { + } + catch (AdmException $e) { $e->showHtml(); } @@ -127,7 +134,8 @@ function handleCreateOrUpdate($itemField, $redirectToImport = false) { if ($redirectToImport) { $gMessage->setForwardUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/import/import_column_config.php', 1000); - } else { + } + else { $gMessage->setForwardUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/fields/fields.php', 1000); } $gMessage->show($gL10n->get('SYS_SAVE_DATA')); @@ -135,23 +143,32 @@ function handleCreateOrUpdate($itemField, $redirectToImport = false) { } /** - * Handles the deletion of an item field. - * @param TableAccess $itemField The item field object to be deleted. + * Handles the deletion of an item field + * + * @param TableAccess $itemField The item field object to be deleted + * @return void */ -function handleDelete($itemField) { +function handleDelete($itemField) : void +{ + global $gMessage, $gL10n, $gNavigation; if ($itemField->delete()) { - // Deletion successful -> Return for XMLHttpRequest - echo 'done'; + // Deletion successful + // go back to field view + $gMessage->setForwardUrl($gNavigation->getPreviousUrl(), 1000); + $gMessage->show($gL10n->get('PLG_INVENTORY_MANAGER_ITEMFIELD_DELETED')); } exit(); } /** - * Handles changing the sequence of an item field. - * @param TableAccess $itemField The item field object whose sequence is to be changed. - * @param string $getSequence The direction to move the item field, values are TableUserField::MOVE_UP, TableUserField::MOVE_DOWN. + * Handles changing the sequence of an item field + * + * @param TableAccess $itemField The item field object whose sequence is to be changed + * @param string $getSequence The direction to move the item field, values are TableUserField::MOVE_UP, TableUserField::MOVE_DOWN + * @return void */ -function handleChangeSequence($itemField, $getSequence) { +function handleChangeSequence($itemField, $getSequence) : void +{ global $gDb, $gCurrentOrgId; $imfSequence = (int) $itemField->getValue('imf_sequence'); @@ -181,10 +198,13 @@ function handleChangeSequence($itemField, $getSequence) { } /** - * Validates the required fields for an item field. - * @param TableAccess $itemField The item field object to be validated. + * Validates the required fields for an item field + * + * @param TableAccess $itemField The item field object to be validated + * @return void */ -function validateRequiredFields($itemField) { +function validateRequiredFields($itemField) : void +{ global $gMessage, $gL10n; if ($itemField->getValue('imf_system') == 0) { @@ -206,10 +226,13 @@ function validateRequiredFields($itemField) { } /** - * Checks if an item field already exists. - * @param string $itemField The item field string to be checked. + * Checks if an item field already exists + * + * @param string $itemField The item field string to be checked + * @return void */ -function checkFieldExists($itemField) { +function checkFieldExists($itemField) : void +{ global $gMessage, $gL10n, $gDb, $gCurrentOrgId, $getimfId; $sql = 'SELECT COUNT(*) AS count FROM ' . TBL_INVENTORY_MANAGER_FIELDS . ' diff --git a/import/import_column_config.php b/import/import_column_config.php index 1305caf..f6344de 100644 --- a/import/import_column_config.php +++ b/import/import_column_config.php @@ -7,6 +7,10 @@ * @author MightyMCoder * @copyright 2024 - today MightyMCoder * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 only + * + * + * Methods: + * getColumnAssignmentHtml() : Creates the html for each assignment of a profile field to a column of the import file *********************************************************************************************** */ @@ -44,53 +48,6 @@ $formValues['first_row'] = true; } -/** - * Function creates the html for each assignment of a profile field to a column of the import file. - * @param array $arrayColumnList The array contains the following elements cat_name, cat_tooltip, id, name, name_intern, tooltip - * @param array $arrayCsvColumns An array with the names of the columns from the import file. - * @return string Returns the HTML of a table with all profile fields and possible assigned columns of the import file. - * @throws Exception - */ -function getColumnAssignmentHtml(array $arrayColumnList, array $arrayCsvColumns): string -{ - $html = ''; - - foreach ($arrayColumnList as $field) { - foreach ($field as $key => $value) { - $html .= ''.$gL10n->get('PLG_INVENTORY_MANAGER_IMPORT_ASSIGN_FIELDS').'
'); @@ -100,8 +57,7 @@ function getColumnAssignmentHtml(array $arrayColumnList, array $arrayCsvColumns) $form->addCheckbox('first_row', $gL10n->get('SYS_FIRST_LINE_COLUMN_NAME'), $formValues['first_row']); $form->addHtml('' . $gL10n->get('PLG_INVENTORY_MANAGER_ADDIN_KEEPER_DESC') . '
-' . $gL10n->get('PLG_INVENTORY_MANAGER_ADDIN_KEEPER_DESC') . '
+' . $gL10n->get('PLG_INVENTORY_MANAGER_ADDIN_LAST_RECEIVER_DESC') . '
-' . $gL10n->get('PLG_INVENTORY_MANAGER_ADDIN_LAST_RECEIVER_DESC') . '
+' . $gL10n->get('PLG_INVENTORY_MANAGER_DEINSTALLATION_FORM_DESC') . '
'); // show form - $form = new HtmlForm('deinstallation_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_PLUGINS . PLUGIN_FOLDER_IM . '/preferences/preferences_function.php', array('mode' => 3)), $page); $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->addSubmitButton('btn_deinstall', $gL10n->get('PLG_INVENTORY_MANAGER_DEINSTALLATION'), array('icon' => 'fa-trash-alt', 'class' => 'offset-sm-3')); @@ -138,7 +148,8 @@ function showDeinstallationDialog() { * @param object $preferences The preferences object to be cleaned up. * @return void */ -function performDeinstallation($preferences) { +function performDeinstallation($preferences) : void +{ global $gNavigation, $gMessage, $gHomepage, $gL10n; $gNavigation->clear();