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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions ajax/fieldValueInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Uninstall is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2026 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);
switch ($_POST['action']) {
case PluginUninstallModelcontainerfield::ACTION_NONE:
case PluginUninstallModelcontainerfield::ACTION_RAZ:
echo "";
break;

case PluginUninstallModelcontainerfield::ACTION_NEW_VALUE:
if (isset($_POST['id']) && $_POST['id']) {
$rand = mt_rand();
if (isset($_POST['rand']) && $_POST['rand']) {
$rand = $_POST['rand'];
}

$pluginUninstallField = new PluginUninstallModelcontainerfield();
$pluginUninstallField->getFromDB($_POST['id']);

$pluginFieldsField = new PluginFieldsField();
$pluginFieldsField->getFromDB($pluginUninstallField->fields['plugin_fields_fields_id']);

$type = $pluginFieldsField->fields['type'];

if ($type === 'glpi_item') {
// TODO handling this case
// Display "allowed values" field
echo __('Allowed values', 'fields') . ' :';

$allowed_itemtypes = !empty($pluginFieldsField->fields['allowed_values'])
? json_decode($pluginFieldsField->fields['allowed_values'])
: [];
echo implode(
', ',
array_map(
function ($itemtype) {
return is_a($itemtype, CommonDBTM::class, true)
? $itemtype::getTypeName(Session::getPluralNumber())
: $itemtype;
},
$allowed_itemtypes
)
);
} else {
$dropdown_matches = [];
$is_dropdown = $type == 'dropdown' || preg_match(
'/^dropdown-(?<class>.+)$/',
$type,
$dropdown_matches
) === 1;

if (in_array($type, ['date', 'datetime'])) {
echo '<i class="pointer fa fa-info" title="' . __s(
"You can use 'now' for date and datetime field"
) . '"></i>';
}

if ($is_dropdown) {
$multiple = (bool)$pluginFieldsField->fields['multiple'];

echo '<div style="line-height:var(--tblr-body-line-height);">';

$itemtype = $type == 'dropdown'
? PluginFieldsDropdown::getClassname($pluginFieldsField->fields['name'])
: $dropdown_matches['class'];
$default_value = $multiple ? json_decode(
$pluginUninstallField->fields['new_value'] ?? $pluginFieldsField->fields['default_value']
) : $pluginUninstallField->fields['new_value'] ?? $pluginFieldsField->fields['default_value'];
Dropdown::show(
$itemtype,
[
'name' => 'new_value' . ($multiple ? '[]' : ''),
'value' => $default_value,
'entity_restrict' => -1,
'multiple' => $multiple,
'rand' => $rand
]
);

echo '</div>';
} else if ($type === 'yesno') {
$value = 0;
if ($pluginUninstallField->fields['new_value'] === 1 || $pluginUninstallField->fields['new_value'] === '1') {
$value = 1;
} else if ($pluginFieldsField->fields['default_value']) {
$value = $pluginFieldsField->fields['default_value'];
}
Dropdown::showYesNo(
'new_value',
$value,
-1,
['rand' => $rand]
);
} else {
$id = 'new_value' . $rand;
echo Html::input(
'new_value',
[
'value' => $pluginUninstallField->fields['new_value'] ?? $pluginFieldsField->fields['default_value'],
'id' => $id
]
);
}
}
}
break;
}
45 changes: 45 additions & 0 deletions ajax/saveField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Uninstall is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2026 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);

if (isset($_POST['id']) && $_POST['id']) {
$field = new PluginUninstallModelcontainerfield();
$field->check($_POST['id'], UPDATE);
if ($field->update($_POST)) {
Session::addMessageAfterRedirect(__('Field updated', 'uninstall'));
} else {
Session::addMessageAfterRedirect(__('An error has occured'), ERROR);
}
echo "";
}
35 changes: 33 additions & 2 deletions front/model.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,47 @@

if (isset($_POST["add"])) {
$model->check(-1, UPDATE, $_POST);
$model->add($_POST);
if ($id = $model->add($_POST)) {
$relationsCreated = false;
if (isset($_POST['action_plugin_fields_uninstall'])) {
if ($_POST['action_plugin_fields_uninstall'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
$relationsCreated = true;
}
}
// possible that the relations were created in previous if for replace then uninstall model types
if (isset($_POST['action_plugin_fields_replace']) && !$relationsCreated) {
if ($_POST['action_plugin_fields_replace'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
}
}
}
Html::back();
} elseif (isset($_POST["update"])) {
$model->check($_POST['id'], UPDATE);
$model->update($_POST);
if ($model->update($_POST)) {
$relationsCreated = false;
if (isset($_POST['action_plugin_fields_uninstall'])) {
if ($_POST['action_plugin_fields_uninstall'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
$relationsCreated = true;
}
}
if (isset($_POST['action_plugin_fields_replace']) && !$relationsCreated) {
if ($_POST['action_plugin_fields_replace'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
}
}
}
Html::back();
} elseif (isset($_POST['purge'])) {
$model->check($_POST['id'], DELETE);
$model->delete($_POST);
$model->redirectToList();
} else if (isset($_GET["load_fields"])) {
$model->check($id, UPDATE);
$model->createPluginFieldsRelations($id);
Html::back();
} else {
Html::header(
PluginUninstallModel::getTypeName(),
Expand Down
49 changes: 49 additions & 0 deletions front/modelcontainer.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Uninstall is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2026 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);

$container = new PluginUninstallModelcontainer();
if (isset($_POST["update"])) {
$container->check($_POST['id'], UPDATE);
$container->update($_POST);
Html::back();
} else {
Html::header(
PluginUninstallModelContainer::getTypeName(),
$_SERVER['PHP_SELF'],
"admin",
"PluginUninstallModel",
"model"
);
$container->display(['id' => $_GET['id']]);

Html::footer();
}
56 changes: 56 additions & 0 deletions front/modelcontainerfield.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Uninstall is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2026 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);

$field = new PluginUninstallModelcontainerfield();

if (isset($_POST["update"])) {
// TODO handling of mandatory when action = SET_VALUE
$field->check($_POST['id'], UPDATE);
$field->update($_POST);
Html::back();
} else {
Html::header(
PluginUninstallModelcontainerfield::getTypeName(),
$_SERVER['PHP_SELF'],
"admin",
"PluginUninstallModel",
"model"
);

if (isset($_GET["id"])) {
PluginUninstallModelcontainerfield::displayFullPageForItem($_GET['id']);
} else {
}


Html::footer();
}
Loading