diff --git a/ajax/groups.php b/ajax/groups.php
deleted file mode 100644
index 19eba54..0000000
--- a/ajax/groups.php
+++ /dev/null
@@ -1,52 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2015-2022 by Teclib'.
- * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
- * @link https://github.com/pluginsGLPI/uninstall
- * -------------------------------------------------------------------------
- */
-
-include ('../../../inc/includes.php');
-header("Content-Type: text/html; charset=UTF-8");
-Html::header_nocache();
-
-Session::checkSeveralRightsOr(['uninstall:profile' => READ,
- 'uninstall:profile' => PluginUninstallProfile::RIGHT_REPLACE]);
-
-if (Session::haveRight(PluginUninstallProfile::$rightname, READ)) {
- switch ($_POST["id"]) {
- case 'old' :
- echo "";
- echo Dropdown::EMPTY_VALUE;
- break;
-
- case 'set' :
- Group::dropdown(['value' => $_POST["groups_id"],
- 'entity' => $_POST["entities_id"],
- 'entity_sons' => $_POST["entity_sons"],
- 'emptylabel' => __('None')]);
- break;
- }
-}
diff --git a/hook.php b/hook.php
index dad3688..3298998 100644
--- a/hook.php
+++ b/hook.php
@@ -77,6 +77,9 @@ function plugin_uninstall_install() {
PluginUninstallModel::install($migration);
PluginUninstallPreference::install($migration);
PluginUninstallConfig::install($migration);
+
+ $migration->executeMigration();
+
return true;
}
diff --git a/inc/model.class.php b/inc/model.class.php
index 136e1b1..d944f85 100644
--- a/inc/model.class.php
+++ b/inc/model.class.php
@@ -82,15 +82,6 @@ static function getMenuContent() {
return $menu;
}
- function prepareInputForAdd($input) {
-
- if (isset($input['_groups_id_action'])
- && ($input['_groups_id_action'] == 'old')) {
- $input['groups_id'] = -1;
- }
- return $input;
- }
-
function prepareInputForUpdate($input) {
return $this->prepareInputForAdd($input);
@@ -244,15 +235,19 @@ function showForm($ID, $options = []) {
echo "";
echo "
";
- if ($ID == -1) {
- $this->fields['groups_id'] = -1;
- }
-
if ($this->fields["types_id"] != self::TYPE_MODEL_REPLACEMENT) {
echo "" . __('Action on group', 'uninstall') . " | ";
- $uninst = new PluginUninstallUninstall();
- $action = $uninst->dropdownFieldAction("groups_id", $this->fields['entities_id'],
- $entity_sons, $this->fields["groups_id"]);
+ Dropdown::showFromArray(
+ "groups_action",
+ [
+ 'old' => __('Keep in the current group', 'uninstall'),
+ 'set' => __('Affect to a new group', 'uninstall')
+ ],
+ [
+ 'on_change' => '$("#show_groups").toggle($(this).val() === "set");',
+ 'value' => $this->fields["groups_action"],
+ ]
+ );
echo " | ";
} else {
echo " | ";
@@ -262,15 +257,11 @@ function showForm($ID, $options = []) {
echo "
";
if ($this->fields["types_id"] != self::TYPE_MODEL_REPLACEMENT) {
echo "" . __('New group', 'uninstall') . " | ";
- echo "";
- if ($this->fields['groups_id'] != -1) {
- Group::dropdown(['value' => $this->fields["groups_id"],
- 'entity' => $this->fields["entities_id"],
- 'entity_sons' => $entities,
- 'emptylabel' => __('None')]);
- } else {
- echo Dropdown::EMPTY_VALUE;
- }
+ echo "fields["groups_action"] === 'old' ? 'style="display:none;"' : '') . ">";
+ Group::dropdown(['value' => $this->fields["groups_id"],
+ 'entity' => $this->fields["entities_id"],
+ 'entity_sons' => $entities,
+ 'emptylabel' => __('None')]);
echo " | ";
} else {
echo " | ";
@@ -841,6 +832,7 @@ function rawSearchOptions() {
'name' => __('Action on group', 'uninstall'),
'linkfield' => '',
'datatype' => 'specific',
+ 'additionalfields' => ['groups_action'],
'searchtype' => 'equals',
];
@@ -991,9 +983,9 @@ static function getSpecificValueToDisplay($field, $values, array $options = [])
break;
case 'groups_id' :
- if ($values['groups_id'] < 0) {
+ if ($values['groups_action'] === 'old') {
return __('Keep in the current group', 'uninstall');
- } else if (!$values['groups_id']) {
+ } else if ($values['groups_id'] === 0) {
return __('None');
}
return Dropdown::getDropdownName('glpi_groups', $values['groups_id']);
@@ -1175,6 +1167,25 @@ static function install($migration) {
$migration->addField($table, 'raz_antivirus', "bool");
}
+ // 2.7.2
+ if (!$DB->fieldExists($table, 'groups_action')) {
+ $migration->addField($table, 'groups_action', "varchar(10) NOT NULL DEFAULT 'set'");
+ $migration->addPostQuery(
+ $DB->buildUpdate(
+ $table,
+ ['groups_action' => 'set'],
+ ['NOT' => ['groups_id' => '-1']]
+ )
+ );
+ $migration->addPostQuery(
+ $DB->buildUpdate(
+ $table,
+ ['groups_action' => 'old', 'groups_id' => '0'],
+ ['groups_id' => '-1']
+ )
+ );
+ }
+
$migration->migrationOneTable($table);
} else {
@@ -1200,6 +1211,7 @@ static function install($migration) {
`raz_user` int(1) NOT NULL DEFAULT '1',
`raz_ocs_registrykeys` int(1) NOT NULL DEFAULT '1',
`comment` text COLLATE utf8_unicode_ci NOT NULL,
+ `groups_action` varchar(10) NOT NULL DEFAULT 'set',
`groups_id` int(11) NOT NULL DEFAULT '0',
`remove_from_ocs` int(1) NOT NULL DEFAULT '0',
`delete_ocs_link` int(1) NOT NULL DEFAULT '0',
@@ -1281,6 +1293,7 @@ static function createTransferModel($name = 'Uninstall') {
$tmp['raz_fusioninventory'] = 1;
$tmp['raz_plugin_fields'] = 1;
$tmp['comment'] = '';
+ $tmp['groups_action'] = 'set';
$tmp['groups_id'] = 0;
$tmp['remove_from_ocs'] = 0;
$tmp['delete_ocs_link'] = 0;
diff --git a/inc/uninstall.class.php b/inc/uninstall.class.php
index 9672016..b35f544 100644
--- a/inc/uninstall.class.php
+++ b/inc/uninstall.class.php
@@ -188,7 +188,7 @@ static function uninstall($type, $model_id, $tab_ids, $location) {
if ($item->isField('groups_id')) {
$nbgroup = countElementsInTableForEntity("glpi_groups", $entity,
['id' => $item->fields['groups_id']]);
- if (($model->fields["groups_id"] > -1)
+ if (($model->fields["groups_action"] === 'set')
&& ($nbgroup == 1)) {
// If a new group is defined and if the group is accessible in the object's entity
$fields["groups_id"] = $model->fields["groups_id"];
@@ -745,42 +745,6 @@ static function dropdownUninstallModels($name, $user, $entity) {
}
- /**
- * @param $name
- * @param $entity (default 0)
- * @param $entity_sons array
- * @param $value (default -1)
- */
- static function dropdownFieldAction($name, $entity = 0, $entity_sons = [], $value = -1) {
- global $CFG_GLPI;
-
- if ($value == -1) {
- $action = 'old';
- } else {
- $action = 'set';
- }
-
- $tabactions = ['old' => __('Keep in the current group', 'uninstall'), // Keep the current value
- 'set' => __('Affect to a new group', 'uninstall')
- ]; // Affect a new value
-
- preg_match('/(.*)_id/', $name, $results);
- $ajax_page = $results[1];
- $rand = Dropdown::showFromArray("_" . $name . "_action", $tabactions,
- ['value' => $action]);
-
- $params = ['id' => '__VALUE__',
- $name => $value,
- 'entities_id' => $entity,
- 'entity_sons' => $entity_sons];
-
- Ajax::updateItemOnSelectEvent("dropdown__" . $name . "_action".$rand, "show_".$ajax_page,
- Plugin::getWebDir('uninstall')."/ajax/$ajax_page.php",
- $params);
- return $action;
- }
-
-
/**
* @param $entity
* @param $add_entity (false by default)