/** * Set lockables fields * *@param $p_id Lockable id. If 0 creates a new lockable record, else update. *@param $p_itemtype Table name. *@param $p_fields Array of fields to set to lockable (ex : "0=>name 1=>comments 2=>contact"). *@param $p_entities_id Entity id. *@param $p_recursive Recursive lock (0/1). *TODO: check rights * *@return nothing **/ static function setLockableForm($p_post) { global $DB, $LINK_ID_TABLE; $tableId = array_search($p_post["tableSelect"], $LINK_ID_TABLE); $_SESSION["glpi_plugin_fusioninventory_lockable_table"] = $tableId; if (isset($p_post['plugin_fusioninventory_lockable_add']) and isset($p_post['columnSelect']) or isset($_POST['plugin_fusioninventory_lockable_delete']) and isset($p_post['columnLockable'])) { // delete AND columns to delete $db_lockable = $DB->fetch_assoc(PluginFusioninventoryLockable::getLockable('', $tableId)); $lockable_id = $db_lockable["id"]; $lockable_fields = $db_lockable["fields"]; $lockable = importArrayFromDB($lockable_fields); if (isset($p_post['plugin_fusioninventory_lockable_add']) and isset($p_post['columnSelect'])) { // add foreach ($p_post['columnSelect'] as $key => $id_value) { array_push($lockable, $id_value); } } if (isset($_POST['plugin_fusioninventory_lockable_delete']) and isset($p_post['columnLockable'])) { // delete foreach ($p_post['columnLockable'] as $key => $id_value) { $fieldToDel = array_search($id_value, $lockable); if (isset($lockable[$fieldToDel])) { $fieldName = $lockable[$fieldToDel]; // TODO add a confirmation request before lockable deletion if locks are defined on this field unset($lockable[$fieldToDel]); // field is not lockable any more --> delete all locks on this field PluginFusioninventoryLock::deleteInAllLockArray($tableId, $fieldName); } } } PluginFusioninventoryLockable::setLockable($lockable_id, $tableId, exportArrayToDB($lockable), '', ''); } }