From b244aca80e945d63982934bfe9b440bbec14839a Mon Sep 17 00:00:00 2001
From: Alex Rock
Date: Mon, 4 Nov 2024 10:56:53 +0100
Subject: [PATCH] Generic controllers forms
---
front/agent.form.php | 110 ----------
front/apiclient.form.php | 87 --------
front/appliance.form.php | 122 -----------
front/authmail.form.php | 73 -------
front/cluster.form.php | 130 ------------
front/computer.form.php | 130 ------------
front/contact.form.php | 132 ------------
front/contract.form.php | 128 ------------
front/enclosure.form.php | 130 ------------
front/infocom.form.php | 97 ---------
front/line.form.php | 122 -----------
front/link.form.php | 85 --------
front/monitor.form.php | 139 -------------
front/ola.form.php | 95 ---------
front/passivedcequipment.form.php | 131 ------------
front/pdu.form.php | 123 -----------
front/peripheral.form.php | 138 ------------
front/phone.form.php | 138 ------------
front/printer.form.php | 136 ------------
front/sla.form.php | 91 --------
front/slm.form.php | 98 ---------
front/software.form.php | 123 -----------
front/supplier.form.php | 118 -----------
front/transfer.form.php | 92 --------
front/unmanaged.form.php | 123 -----------
front/webhook.form.php | 116 -----------
.../Http/LegacyItemtypeRouteListenerTest.php | 13 +-
src/APIClient.php | 10 +
src/Agent.php | 5 +
src/Appliance.php | 5 +
src/AuthMail.php | 12 ++
src/Cluster.php | 19 ++
src/CommonDBTM.php | 67 ++++++
src/CommonGLPI.php | 27 +--
src/Computer.php | 5 +
src/Contact.php | 5 +
src/Contract.php | 5 +
src/Enclosure.php | 18 ++
src/Glpi/Asset/Asset_PeripheralAsset.php | 9 +
.../LegacyConfigurators/SessionConfig.php | 12 +-
.../Controller/DropdownFormController.php | 2 +-
src/Glpi/Controller/GenericFormController.php | 196 ++++++++++++++++++
src/Glpi/Controller/GenericListController.php | 2 +-
.../ItemType/Form/AuthMailFormController.php | 78 +++++++
.../ItemType/Form/ContactFormController.php | 77 +++++++
.../Form/SavedSearchFormController.php | 65 +++---
src/Glpi/Event.php | 15 +-
src/Glpi/Http/LegacyItemtypeRouteListener.php | 16 +-
src/Glpi/Kernel/Kernel.php | 2 +-
src/Glpi/RichText/RichText.php | 2 +-
.../Attribute/ItemtypeFormLegacyRoute.php | 52 +++++
.../Routing/Attribute/ItemtypeFormRoute.php | 52 +++++
src/Infocom.php | 41 ++++
src/Line.php | 5 +
src/Link.php | 5 +
src/Monitor.php | 5 +
src/OLA.php | 5 +
src/PDU.php | 5 +
src/PassiveDCEquipment.php | 19 ++
src/Peripheral.php | 5 +
src/Phone.php | 5 +
src/Printer.php | 5 +
src/SLA.php | 5 +
src/SLM.php | 5 +
src/SavedSearch.php | 5 +
src/Software.php | 5 +
src/Supplier.php | 5 +
src/Transfer.php | 13 ++
src/Unmanaged.php | 5 +
src/Webhook.php | 6 +-
templates/pages/generic_form.html.twig | 37 ++++
.../alert_list_notification.html.twig | 2 +-
tests/cypress/e2e/error_page.cy.js | 8 +-
73 files changed, 901 insertions(+), 3073 deletions(-)
delete mode 100644 front/agent.form.php
delete mode 100644 front/apiclient.form.php
delete mode 100644 front/appliance.form.php
delete mode 100644 front/authmail.form.php
delete mode 100644 front/cluster.form.php
delete mode 100644 front/computer.form.php
delete mode 100644 front/contact.form.php
delete mode 100644 front/contract.form.php
delete mode 100644 front/enclosure.form.php
delete mode 100644 front/infocom.form.php
delete mode 100644 front/line.form.php
delete mode 100644 front/link.form.php
delete mode 100644 front/monitor.form.php
delete mode 100644 front/ola.form.php
delete mode 100644 front/passivedcequipment.form.php
delete mode 100644 front/pdu.form.php
delete mode 100644 front/peripheral.form.php
delete mode 100644 front/phone.form.php
delete mode 100644 front/printer.form.php
delete mode 100644 front/sla.form.php
delete mode 100644 front/slm.form.php
delete mode 100644 front/software.form.php
delete mode 100644 front/supplier.form.php
delete mode 100644 front/transfer.form.php
delete mode 100644 front/unmanaged.form.php
delete mode 100644 front/webhook.form.php
create mode 100644 src/Glpi/Controller/GenericFormController.php
create mode 100644 src/Glpi/Controller/ItemType/Form/AuthMailFormController.php
create mode 100644 src/Glpi/Controller/ItemType/Form/ContactFormController.php
rename front/savedsearch.form.php => src/Glpi/Controller/ItemType/Form/SavedSearchFormController.php (50%)
create mode 100644 src/Glpi/Routing/Attribute/ItemtypeFormLegacyRoute.php
create mode 100644 src/Glpi/Routing/Attribute/ItemtypeFormRoute.php
create mode 100644 templates/pages/generic_form.html.twig
diff --git a/front/agent.form.php b/front/agent.form.php
deleted file mode 100644
index 4b806cb3063..00000000000
--- a/front/agent.form.php
+++ /dev/null
@@ -1,110 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("agent", READ);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$agent = new Agent();
-// delete an agent
-if (isset($_POST["delete"])) {
- $agent->check($_POST['id'], DELETE);
- $ok = $agent->delete($_POST);
- if ($ok) {
- Event::log(
- $_POST["id"],
- "agents",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- }
- $agent->redirectToList();
-} else if (isset($_POST["restore"])) {
- $agent->check($_POST['id'], DELETE);
- if ($agent->restore($_POST)) {
- Event::log(
- $_POST["id"],
- "agents",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- }
- $agent->redirectToList();
-} else if (isset($_POST["purge"])) {
- $agent->check($_POST['id'], PURGE);
- if ($agent->delete($_POST, 1)) {
- Event::log(
- $_POST["id"],
- "agents",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- }
- $agent->redirectToList();
-
- //update an agent
-} else if (isset($_POST["update"])) {
- $agent->check($_POST['id'], UPDATE);
- $agent->update($_POST);
- Event::log(
- $_POST["id"],
- "agents",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {//print agent information
- $menus = ["admin", "glpi\inventory\inventory", "Agent"];
- Agent::displayFullPageForItem((int) $_GET['id'], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true",
- ]);
-}
diff --git a/front/apiclient.form.php b/front/apiclient.form.php
deleted file mode 100644
index 29259934120..00000000000
--- a/front/apiclient.form.php
+++ /dev/null
@@ -1,87 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-/** @var array $CFG_GLPI */
-global $CFG_GLPI;
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
-$client = new APIClient();
-
-if (isset($_POST["add"])) {
- $client->check(-1, CREATE, $_POST);
-
- if ($newID = $client->add($_POST)) {
- Event::log(
- $newID,
- APIClient::class,
- 4,
- "setup",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($client->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["update"])) {
- $client->check($_POST["id"], UPDATE);
- $client->update($_POST);
- Event::log(
- $_POST["id"],
- APIClient::class,
- 4,
- "setup",
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else if (isset($_POST["purge"])) {
- $client->check($_POST["id"], PURGE);
- $client->delete($_POST);
- Event::log(
- $_POST["id"],
- APIClient::class,
- 4,
- "setup",
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- Html::redirect($CFG_GLPI["root_doc"] . "/front/config.form.php");
-} else {
- $menus = ["config", "config", "APIClient"];
- APIClient::displayFullPageForItem($_GET["id"], $menus);
-}
diff --git a/front/appliance.form.php b/front/appliance.form.php
deleted file mode 100644
index 06466b19130..00000000000
--- a/front/appliance.form.php
+++ /dev/null
@@ -1,122 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight('appliance', READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$app = new Appliance();
-
-if (isset($_POST["add"])) {
- $app->check(-1, CREATE, $_POST);
-
- if ($newID = $app->add($_POST)) {
- Event::log(
- $newID,
- "appliance",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($app->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $app->check($_POST["id"], DELETE);
- $app->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "appliance",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $app->redirectToList();
-} else if (isset($_POST["restore"])) {
- $app->check($_POST["id"], DELETE);
-
- $app->restore($_POST);
- Event::log(
- $_POST["id"],
- "appliance",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $app->redirectToList();
-} else if (isset($_POST["purge"])) {
- $app->check($_POST["id"], PURGE);
-
- $app->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "appliance",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $app->redirectToList();
-} else if (isset($_POST["update"])) {
- $app->check($_POST["id"], UPDATE);
-
- $app->update($_POST);
- Event::log(
- $_POST["id"],
- "appliance",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["management", "appliance"];
- Appliance::displayFullPageForItem($_GET['id'], $menus, [
- 'withtemplate' => $_GET['withtemplate']
- ]);
-}
diff --git a/front/authmail.form.php b/front/authmail.form.php
deleted file mode 100644
index 04da1a64a4f..00000000000
--- a/front/authmail.form.php
+++ /dev/null
@@ -1,73 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-Session::checkRight("config", UPDATE);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-$config_mail = new AuthMail();
-
-//IMAP/POP Server add/update/delete
-if (isset($_POST["update"])) {
- $config_mail->update($_POST);
- Html::back();
-} else if (isset($_POST["add"])) {
- //If no name has been given to this configuration, then go back to the page without adding
- if ($_POST["name"] != "") {
- if (
- ($config_mail->add($_POST))
- && $_SESSION['glpibackcreated']
- ) {
- Html::redirect($config_mail->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["purge"])) {
- $config_mail->delete($_POST, 1);
- $_SESSION['glpi_authconfig'] = 2;
- $config_mail->redirectToList();
-} else if (isset($_POST["test"])) {
- if (AuthMail::testAuth($_POST["imap_string"], $_POST["imap_login"], $_POST["imap_password"])) {
- Session::addMessageAfterRedirect(__s('Test successful'));
- } else {
- Session::addMessageAfterRedirect(__s('Test failed'), false, ERROR);
- }
- Html::back();
-}
-
-$menus = ["config", "auth", "AuthMail"];
-AuthMail::displayFullPageForItem($_GET['id'], $menus);
diff --git a/front/cluster.form.php b/front/cluster.form.php
deleted file mode 100644
index aaf73dc8240..00000000000
--- a/front/cluster.form.php
+++ /dev/null
@@ -1,130 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("cluster", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$cluster = new Cluster();
-
-if (isset($_POST["add"])) {
- $cluster->check(-1, CREATE, $_POST);
-
- if ($newID = $cluster->add($_POST)) {
- Event::log(
- $newID,
- "cluster",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($cluster->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $cluster->check($_POST["id"], DELETE);
- $cluster->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "cluster",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $cluster->redirectToList();
-} else if (isset($_POST["restore"])) {
- $cluster->check($_POST["id"], DELETE);
-
- $cluster->restore($_POST);
- Event::log(
- $_POST["id"],
- "cluster",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $cluster->redirectToList();
-} else if (isset($_POST["purge"])) {
- $cluster->check($_POST["id"], PURGE);
-
- $cluster->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "cluster",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $cluster->redirectToList();
-} else if (isset($_POST["update"])) {
- $cluster->check($_POST["id"], UPDATE);
-
- $cluster->update($_POST);
- Event::log(
- $_POST["id"],
- "cluster",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $options = [
- 'withtemplate' => $_GET['withtemplate'],
- 'formoptions' => "data-track-changes=true",
- ];
- if (isset($_GET['position'])) {
- $options['position'] = $_GET['position'];
- }
- if (isset($_GET['room'])) {
- $options['room'] = $_GET['room'];
- }
- $menus = ["management", "cluster"];
- Cluster::displayFullPageForItem($_GET['id'], $menus, $options);
-}
diff --git a/front/computer.form.php b/front/computer.form.php
deleted file mode 100644
index 4f01d45f137..00000000000
--- a/front/computer.form.php
+++ /dev/null
@@ -1,130 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRightsOr(Computer::$rightname, [READ, READ_ASSIGNED, READ_OWNED]);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$computer = new Computer();
-//Add a new computer
-if (isset($_POST["add"])) {
- $computer->check(-1, CREATE, $_POST);
- if ($newID = $computer->add($_POST)) {
- Event::log(
- $newID,
- "computers",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
-
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($computer->getLinkURL());
- }
- }
- Html::back();
-
- // delete a computer
-} else if (isset($_POST["delete"])) {
- $computer->check($_POST['id'], DELETE);
- $ok = $computer->delete($_POST);
- if ($ok) {
- Event::log(
- $_POST["id"],
- "computers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- }
- $computer->redirectToList();
-} else if (isset($_POST["restore"])) {
- $computer->check($_POST['id'], DELETE);
- if ($computer->restore($_POST)) {
- Event::log(
- $_POST["id"],
- "computers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- }
- $computer->redirectToList();
-} else if (isset($_POST["purge"])) {
- $computer->check($_POST['id'], PURGE);
- if ($computer->delete($_POST, 1)) {
- Event::log(
- $_POST["id"],
- "computers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- }
- $computer->redirectToList();
-
- //update a computer
-} else if (isset($_POST["update"])) {
- $computer->check($_POST['id'], UPDATE);
- $computer->update($_POST);
- Event::log(
- $_POST["id"],
- "computers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-
- // Disconnect a computer from a printer/monitor/phone/peripheral
-} else {//print computer information
- $menus = ["assets", "computer"];
- Computer::displayFullPageForItem($_GET['id'], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true",
- ]);
-}
diff --git a/front/contact.form.php b/front/contact.form.php
deleted file mode 100644
index 2eb904a12c2..00000000000
--- a/front/contact.form.php
+++ /dev/null
@@ -1,132 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-/** @var array $CFG_GLPI */
-global $CFG_GLPI;
-
-Session::checkRight("contact_enterprise", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = -1;
-}
-
-$contact = new Contact();
-
-if (isset($_GET['getvcard'])) {
- if ($_GET["id"] < 0) {
- Html::redirect($CFG_GLPI["root_doc"] . "/front/contact.php");
- }
- $contact->check($_GET["id"], READ);
- $contact->generateVcard();
-} else if (isset($_POST["add"])) {
- $contact->check(-1, CREATE, $_POST);
-
- if ($newID = $contact->add($_POST)) {
- Event::log(
- $newID,
- "contacts",
- 4,
- "financial",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($contact->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $contact->check($_POST["id"], DELETE);
-
- if ($contact->delete($_POST)) {
- Event::log(
- $_POST["id"],
- "contacts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- }
- $contact->redirectToList();
-} else if (isset($_POST["restore"])) {
- $contact->check($_POST["id"], DELETE);
-
- if ($contact->restore($_POST)) {
- Event::log(
- $_POST["id"],
- "contacts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- }
- $contact->redirectToList();
-} else if (isset($_POST["purge"])) {
- $contact->check($_POST["id"], PURGE);
-
- if ($contact->delete($_POST, 1)) {
- Event::log(
- $_POST["id"],
- "contacts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- }
- $contact->redirectToList();
-} else if (isset($_POST["update"])) {
- $contact->check($_POST["id"], UPDATE);
-
- if ($contact->update($_POST)) {
- Event::log(
- $_POST["id"],
- "contacts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- }
- Html::back();
-} else {
- $menus = ["management", "contact"];
- Contact::displayFullPageForItem($_GET["id"], $menus, [
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/contract.form.php b/front/contract.form.php
deleted file mode 100644
index 61452a9ad4a..00000000000
--- a/front/contract.form.php
+++ /dev/null
@@ -1,128 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("contract", READ);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = -1;
-}
-
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$contract = new Contract();
-
-if (isset($_POST["add"])) {
- $contract->check(-1, CREATE, $_POST);
-
- if ($newID = $contract->add($_POST)) {
- Event::log(
- $newID,
- "contracts",
- 4,
- "financial",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($contract->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $contract->check($_POST['id'], DELETE);
-
- if ($contract->delete($_POST)) {
- Event::log(
- $_POST["id"],
- "contracts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- }
- $contract->redirectToList();
-} else if (isset($_POST["restore"])) {
- $contract->check($_POST['id'], DELETE);
-
- if ($contract->restore($_POST)) {
- Event::log(
- $_POST["id"],
- "contracts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- }
- $contract->redirectToList();
-} else if (isset($_POST["purge"])) {
- $contract->check($_POST['id'], PURGE);
-
- if ($contract->delete($_POST, 1)) {
- Event::log(
- $_POST["id"],
- "contracts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- }
- $contract->redirectToList();
-} else if (isset($_POST["update"])) {
- $contract->check($_POST['id'], UPDATE);
-
- if ($contract->update($_POST)) {
- Event::log(
- $_POST["id"],
- "contracts",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- }
- Html::back();
-} else {
- $menus = ["management", "contract"];
- Contract::displayFullPageForItem($_GET["id"], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/enclosure.form.php b/front/enclosure.form.php
deleted file mode 100644
index 258b2e65819..00000000000
--- a/front/enclosure.form.php
+++ /dev/null
@@ -1,130 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("datacenter", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$enclosure = new Enclosure();
-
-if (isset($_POST["add"])) {
- $enclosure->check(-1, CREATE, $_POST);
-
- if ($newID = $enclosure->add($_POST)) {
- Event::log(
- $newID,
- "enclosure",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($enclosure->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $enclosure->check($_POST["id"], DELETE);
- $enclosure->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "enclosure",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $enclosure->redirectToList();
-} else if (isset($_POST["restore"])) {
- $enclosure->check($_POST["id"], DELETE);
-
- $enclosure->restore($_POST);
- Event::log(
- $_POST["id"],
- "enclosure",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $enclosure->redirectToList();
-} else if (isset($_POST["purge"])) {
- $enclosure->check($_POST["id"], PURGE);
-
- $enclosure->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "enclosure",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $enclosure->redirectToList();
-} else if (isset($_POST["update"])) {
- $enclosure->check($_POST["id"], UPDATE);
-
- $enclosure->update($_POST);
- Event::log(
- $_POST["id"],
- "enclosure",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $options = [
- 'withtemplate' => $_GET['withtemplate'],
- 'formoptions' => "data-track-changes=true"
- ];
- if (isset($_GET['position'])) {
- $options['position'] = $_GET['position'];
- }
- if (isset($_GET['room'])) {
- $options['room'] = $_GET['room'];
- }
- $menus = ["assets", "enclosure"];
- Enclosure::displayFullPageForItem($_GET['id'], $menus, $options);
-}
diff --git a/front/infocom.form.php b/front/infocom.form.php
deleted file mode 100644
index f09ba040377..00000000000
--- a/front/infocom.form.php
+++ /dev/null
@@ -1,97 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-$ic = new Infocom();
-
-if (isset($_POST['add'])) {
- $ic->check(-1, CREATE, $_POST);
-
- $newID = $ic->add($_POST, false);
- Event::log(
- $newID,
- "infocom",
- 4,
- "financial",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $newID)
- );
- Html::back();
-} else if (isset($_POST["purge"])) {
- $ic->check($_POST["id"], PURGE);
- $ic->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "infocom",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else if (isset($_POST["update"])) {
- $ic->check($_POST["id"], UPDATE);
-
- $ic->update($_POST);
- Event::log(
- $_POST["id"],
- "infocom",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- Session::checkRight("infocom", READ);
-
- Html::popHeader(Infocom::getTypeName(), $_SERVER['PHP_SELF']);
-
- if (isset($_GET["id"])) {
- $ic->getFromDB($_GET["id"]);
- $_GET["itemtype"] = $ic->fields["itemtype"];
- $_GET["items_id"] = $ic->fields["items_id"];
- }
- $item = false;
- if (isset($_GET["itemtype"]) && ($item = getItemForItemtype($_GET["itemtype"]))) {
- if (!isset($_GET["items_id"]) || !$item->getFromDB($_GET["items_id"])) {
- $item = false;
- }
- }
-
- Infocom::showForItem($item, 0);
-
- Html::popFooter();
-}
diff --git a/front/line.form.php b/front/line.form.php
deleted file mode 100644
index da172336552..00000000000
--- a/front/line.form.php
+++ /dev/null
@@ -1,122 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("line", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$line = new Line();
-
-if (isset($_POST["add"])) {
- $line->check(-1, CREATE, $_POST);
-
- if ($newID = $line->add($_POST)) {
- Event::log(
- $newID,
- "lines",
- 4,
- "financial",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($line->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $line->check($_POST["id"], DELETE);
- $line->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "lines",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $line->redirectToList();
-} else if (isset($_POST["restore"])) {
- $line->check($_POST["id"], DELETE);
-
- $line->restore($_POST);
- Event::log(
- $_POST["id"],
- "lines",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $line->redirectToList();
-} else if (isset($_POST["purge"])) {
- $line->check($_POST["id"], PURGE);
-
- $line->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "lines",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $line->redirectToList();
-} else if (isset($_POST["update"])) {
- $line->check($_POST["id"], UPDATE);
-
- $line->update($_POST);
- Event::log(
- $_POST["id"],
- "lines",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["management", "line"];
- Line::displayFullPageForItem($_GET["id"], $menus, [
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/link.form.php b/front/link.form.php
deleted file mode 100644
index 20adc838d94..00000000000
--- a/front/link.form.php
+++ /dev/null
@@ -1,85 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("link", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-$link = new Link();
-
-if (isset($_POST["add"])) {
- $link->check(-1, CREATE);
-
- $newID = $link->add($_POST);
- Event::log(
- $newID,
- "links",
- 4,
- "setup",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- Html::redirect(Toolbox::getItemTypeFormURL('Link') . "?id=" . $newID);
-} else if (isset($_POST["purge"])) {
- $link->check($_POST["id"], PURGE);
- $link->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "links",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $link->redirectToList();
-} else if (isset($_POST["update"])) {
- $link->check($_POST["id"], UPDATE);
- $link->update($_POST);
- Event::log(
- $_POST["id"],
- "links",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["config", "link"];
- Link::displayFullPageForItem($_GET["id"], $menus);
-}
diff --git a/front/monitor.form.php b/front/monitor.form.php
deleted file mode 100644
index fe08d21a4e0..00000000000
--- a/front/monitor.form.php
+++ /dev/null
@@ -1,139 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Asset\Asset_PeripheralAsset;
-use Glpi\Event;
-
-Session::checkRightsOr(Monitor::$rightname, [READ, READ_ASSIGNED, READ_OWNED]);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$monitor = new Monitor();
-
-if (isset($_POST["add"])) {
- $monitor->check(-1, CREATE, $_POST);
-
- if ($newID = $monitor->add($_POST)) {
- Event::log(
- $newID,
- "monitors",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($monitor->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $monitor->check($_POST["id"], DELETE);
- $monitor->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "monitors",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $monitor->redirectToList();
-} else if (isset($_POST["restore"])) {
- $monitor->check($_POST["id"], DELETE);
-
- $monitor->restore($_POST);
- Event::log(
- $_POST["id"],
- "monitors",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $monitor->redirectToList();
-} else if (isset($_POST["purge"])) {
- $monitor->check($_POST["id"], PURGE);
-
- $monitor->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "monitors",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $monitor->redirectToList();
-} else if (isset($_POST["update"])) {
- $monitor->check($_POST["id"], UPDATE);
-
- $monitor->update($_POST);
- Event::log(
- $_POST["id"],
- "monitors",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else if (isset($_POST["unglobalize"])) {
- $monitor->check($_POST["id"], UPDATE);
-
- Asset_PeripheralAsset::unglobalizeItem($monitor);
- Event::log(
- $_POST["id"],
- "monitors",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s sets unitary management'), $_SESSION["glpiname"])
- );
-
- Html::redirect($monitor->getFormURLWithID($_POST["id"]));
-} else {
- $menus = ["assets", "monitor"];
- Monitor::displayFullPageForItem($_GET['id'], $menus, [
- 'loaded' => true,
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true",
- ]);
-}
diff --git a/front/ola.form.php b/front/ola.form.php
deleted file mode 100644
index 49788b0b2b3..00000000000
--- a/front/ola.form.php
+++ /dev/null
@@ -1,95 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-/**
- * @since 9.1
- */
-
-use Glpi\Event;
-
-Session::checkRight("slm", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-$ola = new OLA();
-
-if (isset($_POST["add"])) {
- $ola->check(-1, CREATE, $_POST);
-
- if ($newID = $ola->add($_POST)) {
- Event::log(
- $newID,
- "olas",
- 4,
- "setup",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($ola->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["purge"])) {
- $ola->check($_POST["id"], PURGE);
- $ola->delete($_POST, 1);
-
- Event::log(
- $_POST["id"],
- "olas",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $ola->redirectToList();
-} else if (isset($_POST["update"])) {
- $ola->check($_POST["id"], UPDATE);
- $ola->update($_POST);
-
- Event::log(
- $_POST["id"],
- "olas",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["config", "slm", "OLA"];
- OLA::displayFullPageForItem($_GET["id"], $menus);
-}
diff --git a/front/passivedcequipment.form.php b/front/passivedcequipment.form.php
deleted file mode 100644
index 82132aa247c..00000000000
--- a/front/passivedcequipment.form.php
+++ /dev/null
@@ -1,131 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("datacenter", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$passive_equip = new PassiveDCEquipment();
-
-if (isset($_POST["add"])) {
- $passive_equip->check(-1, CREATE, $_POST);
-
- if ($newID = $passive_equip->add($_POST)) {
- Event::log(
- $newID,
- "passivedcequipment",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($passive_equip->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $passive_equip->check($_POST["id"], DELETE);
- $passive_equip->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "passivedcequipment",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $passive_equip->redirectToList();
-} else if (isset($_POST["restore"])) {
- $passive_equip->check($_POST["id"], DELETE);
-
- $passive_equip->restore($_POST);
- Event::log(
- $_POST["id"],
- "passivedcequipment",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $passive_equip->redirectToList();
-} else if (isset($_POST["purge"])) {
- $passive_equip->check($_POST["id"], PURGE);
-
- $passive_equip->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "passivedcequipment",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $passive_equip->redirectToList();
-} else if (isset($_POST["update"])) {
- $passive_equip->check($_POST["id"], UPDATE);
-
- $passive_equip->update($_POST);
- Event::log(
- $_POST["id"],
- "passivedcequipment",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $options = [
- 'withtemplate' => $_GET['withtemplate'],
- 'formoptions' => "data-track-changes=true"
- ];
- if (isset($_GET['position'])) {
- $options['position'] = $_GET['position'];
- }
- if (isset($_GET['room'])) {
- $options['room'] = $_GET['room'];
- }
-
- $menus = ["assets", "passivedcequipment"];
- PassiveDCEquipment::displayFullPageForItem($_GET['id'], $menus, $options);
-}
diff --git a/front/pdu.form.php b/front/pdu.form.php
deleted file mode 100644
index afda1d2bb95..00000000000
--- a/front/pdu.form.php
+++ /dev/null
@@ -1,123 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("datacenter", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$pdu = new PDU();
-
-if (isset($_POST["add"])) {
- $pdu->check(-1, CREATE, $_POST);
-
- if ($newID = $pdu->add($_POST)) {
- Event::log(
- $newID,
- "pdus",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($pdu->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $pdu->check($_POST["id"], DELETE);
- $pdu->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "pdus",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $pdu->redirectToList();
-} else if (isset($_POST["restore"])) {
- $pdu->check($_POST["id"], DELETE);
-
- $pdu->restore($_POST);
- Event::log(
- $_POST["id"],
- "pdus",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $pdu->redirectToList();
-} else if (isset($_POST["purge"])) {
- $pdu->check($_POST["id"], PURGE);
-
- $pdu->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "pdus",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $pdu->redirectToList();
-} else if (isset($_POST["update"])) {
- $pdu->check($_POST["id"], UPDATE);
-
- $pdu->update($_POST);
- Event::log(
- $_POST["id"],
- "pdus",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["assets", "pdu"];
- PDU::displayFullPageForItem($_GET["id"], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/peripheral.form.php b/front/peripheral.form.php
deleted file mode 100644
index 407475f994d..00000000000
--- a/front/peripheral.form.php
+++ /dev/null
@@ -1,138 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Asset\Asset_PeripheralAsset;
-use Glpi\Event;
-
-Session::checkRightsOr(Peripheral::$rightname, [READ, READ_ASSIGNED, READ_OWNED]);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$peripheral = new Peripheral();
-
-if (isset($_POST["add"])) {
- $peripheral->check(-1, CREATE, $_POST);
-
- if ($newID = $peripheral->add($_POST)) {
- Event::log(
- $newID,
- "peripherals",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($peripheral->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $peripheral->check($_POST["id"], DELETE);
- $peripheral->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "peripherals",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $peripheral->redirectToList();
-} else if (isset($_POST["restore"])) {
- $peripheral->check($_POST["id"], DELETE);
-
- $peripheral->restore($_POST);
- Event::log(
- $_POST["id"],
- "peripherals",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $peripheral->redirectToList();
-} else if (isset($_POST["purge"])) {
- $peripheral->check($_POST["id"], PURGE);
-
- $peripheral->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "peripherals",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $peripheral->redirectToList();
-} else if (isset($_POST["update"])) {
- $peripheral->check($_POST["id"], UPDATE);
-
- $peripheral->update($_POST);
- Event::log(
- $_POST["id"],
- "peripherals",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else if (isset($_POST["unglobalize"])) {
- $peripheral->check($_POST["id"], UPDATE);
-
- Asset_PeripheralAsset::unglobalizeItem($peripheral);
- Event::log(
- $_POST["id"],
- "peripherals",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s sets unitary management'), $_SESSION["glpiname"])
- );
-
- Html::redirect($peripheral->getFormURLWithID($_POST["id"]));
-} else {
- $menus = ["assets", "peripheral"];
- Peripheral::displayFullPageForItem($_GET["id"], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/phone.form.php b/front/phone.form.php
deleted file mode 100644
index 4f9008cc83d..00000000000
--- a/front/phone.form.php
+++ /dev/null
@@ -1,138 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Asset\Asset_PeripheralAsset;
-use Glpi\Event;
-
-Session::checkRightsOr(Phone::$rightname, [READ, READ_ASSIGNED, READ_OWNED]);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$phone = new Phone();
-
-if (isset($_POST["add"])) {
- $phone->check(-1, CREATE, $_POST);
-
- if ($newID = $phone->add($_POST)) {
- Event::log(
- $newID,
- "phones",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($phone->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $phone->check($_POST["id"], DELETE);
- $phone->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "phones",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $phone->redirectToList();
-} else if (isset($_POST["restore"])) {
- $phone->check($_POST["id"], DELETE);
-
- $phone->restore($_POST);
- Event::log(
- $_POST["id"],
- "phones",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $phone->redirectToList();
-} else if (isset($_POST["purge"])) {
- $phone->check($_POST["id"], PURGE);
-
- $phone->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "phones",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $phone->redirectToList();
-} else if (isset($_POST["update"])) {
- $phone->check($_POST["id"], UPDATE);
-
- $phone->update($_POST);
- Event::log(
- $_POST["id"],
- "phones",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else if (isset($_POST["unglobalize"])) {
- $phone->check($_POST["id"], UPDATE);
-
- Asset_PeripheralAsset::unglobalizeItem($phone);
- Event::log(
- $_POST["id"],
- "phones",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s sets unitary management'), $_SESSION["glpiname"])
- );
-
- Html::redirect($phone->getFormURLWithID($_POST["id"]));
-} else {
- $menus = ['assets', 'phone'];
- Phone::displayFullPageForItem($_GET["id"], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/printer.form.php b/front/printer.form.php
deleted file mode 100644
index bd0ff258b00..00000000000
--- a/front/printer.form.php
+++ /dev/null
@@ -1,136 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Asset\Asset_PeripheralAsset;
-use Glpi\Event;
-
-Session::checkRightsOr(Printer::$rightname, [READ, READ_ASSIGNED, READ_OWNED]);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$print = new Printer();
-if (isset($_POST["add"])) {
- $print->check(-1, CREATE, $_POST);
-
- if ($newID = $print->add($_POST)) {
- Event::log(
- $newID,
- "printers",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($print->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $print->check($_POST["id"], DELETE);
- $print->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "printers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $print->redirectToList();
-} else if (isset($_POST["restore"])) {
- $print->check($_POST["id"], DELETE);
-
- $print->restore($_POST);
- Event::log(
- $_POST["id"],
- "printers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $print->redirectToList();
-} else if (isset($_POST["purge"])) {
- $print->check($_POST["id"], PURGE);
-
- $print->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "printers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $print->redirectToList();
-} else if (isset($_POST["update"])) {
- $print->check($_POST["id"], UPDATE);
-
- $print->update($_POST);
- Event::log(
- $_POST["id"],
- "printers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else if (isset($_POST["unglobalize"])) {
- $print->check($_POST["id"], UPDATE);
-
- Asset_PeripheralAsset::unglobalizeItem($print);
- Event::log(
- $_POST["id"],
- "printers",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s sets unitary management'), $_SESSION["glpiname"])
- );
- Html::redirect($print->getFormURLWithID($_POST["id"]));
-} else {
- $menus = ["assets", "printer"];
- Printer::displayFullPageForItem($_GET["id"], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/sla.form.php b/front/sla.form.php
deleted file mode 100644
index 633c26eec11..00000000000
--- a/front/sla.form.php
+++ /dev/null
@@ -1,91 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("slm", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-$sla = new SLA();
-
-if (isset($_POST["add"])) {
- $sla->check(-1, CREATE, $_POST);
-
- if ($newID = $sla->add($_POST)) {
- Event::log(
- $newID,
- "slas",
- 4,
- "setup",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($sla->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["purge"])) {
- $sla->check($_POST["id"], PURGE);
- $sla->delete($_POST, 1);
-
- Event::log(
- $_POST["id"],
- "slas",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $sla->redirectToList();
-} else if (isset($_POST["update"])) {
- $sla->check($_POST["id"], UPDATE);
- $sla->update($_POST);
-
- Event::log(
- $_POST["id"],
- "slas",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["config", "slm", "SLA"];
- SLA::displayFullPageForItem($_GET["id"], $menus);
-}
diff --git a/front/slm.form.php b/front/slm.form.php
deleted file mode 100644
index 8faaf355fee..00000000000
--- a/front/slm.form.php
+++ /dev/null
@@ -1,98 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-/**
- * @since 9.2
- */
-
-use Glpi\Event;
-
-/** @var array $CFG_GLPI */
-global $CFG_GLPI;
-
-Session::checkRight("slm", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-$slm = new SLM();
-
-if (isset($_POST["add"])) {
- $slm->check(-1, CREATE);
-
- if ($newID = $slm->add($_POST)) {
- Event::log(
- $newID,
- "slms",
- 4,
- "setup",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($slm->getLinkURL());
- }
- }
- Html::redirect($CFG_GLPI["root_doc"] . "/front/slm.php");
-} else if (isset($_POST["purge"])) {
- $slm->check($_POST["id"], PURGE);
- $slm->delete($_POST, 1);
-
- Event::log(
- $_POST["id"],
- "slms",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $slm->redirectToList();
-} else if (isset($_POST["update"])) {
- $slm->check($_POST["id"], UPDATE);
- $slm->update($_POST);
-
- Event::log(
- $_POST["id"],
- "slms",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["config", "slm"];
- SLM::displayFullPageForItem($_GET["id"], $menus);
-}
diff --git a/front/software.form.php b/front/software.form.php
deleted file mode 100644
index ca51528f70e..00000000000
--- a/front/software.form.php
+++ /dev/null
@@ -1,123 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRightsOr(Software::$rightname, [READ, READ_ASSIGNED, READ_OWNED]);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$soft = new Software();
-if (isset($_POST["add"])) {
- $soft->check(-1, CREATE, $_POST);
-
- if ($newID = $soft->add($_POST)) {
- Event::log(
- $newID,
- "software",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($soft->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $soft->check($_POST["id"], DELETE);
- $soft->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "software",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
-
- $soft->redirectToList();
-} else if (isset($_POST["restore"])) {
- $soft->check($_POST["id"], DELETE);
-
- $soft->restore($_POST);
- Event::log(
- $_POST["id"],
- "software",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $soft->redirectToList();
-} else if (isset($_POST["purge"])) {
- $soft->check($_POST["id"], PURGE);
-
- $soft->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "software",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $soft->redirectToList();
-} else if (isset($_POST["update"])) {
- $soft->check($_POST["id"], UPDATE);
-
- $soft->update($_POST);
- Event::log(
- $_POST["id"],
- "software",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["assets", "software"];
- Software::displayFullPageForItem($_GET["id"], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/supplier.form.php b/front/supplier.form.php
deleted file mode 100644
index a2efd24bce0..00000000000
--- a/front/supplier.form.php
+++ /dev/null
@@ -1,118 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("contact_enterprise", READ);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = -1;
-}
-
-
-$ent = new Supplier();
-
-if (isset($_POST["add"])) {
- $ent->check(-1, CREATE, $_POST);
-
- if ($newID = $ent->add($_POST)) {
- Event::log(
- $newID,
- "suppliers",
- 4,
- "financial",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($ent->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $ent->check($_POST["id"], DELETE);
- $ent->delete($_POST);
- Event::log(
- $_POST["id"],
- "suppliers",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- $ent->redirectToList();
-} else if (isset($_POST["restore"])) {
- $ent->check($_POST["id"], DELETE);
- $ent->restore($_POST);
- Event::log(
- $_POST["id"],
- "suppliers",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
-
- $ent->redirectToList();
-} else if (isset($_POST["purge"])) {
- $ent->check($_POST["id"], PURGE);
- $ent->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "suppliers",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
-
- $ent->redirectToList();
-} else if (isset($_POST["update"])) {
- $ent->check($_POST["id"], UPDATE);
- $ent->update($_POST);
- Event::log(
- $_POST["id"],
- "suppliers",
- 4,
- "financial",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["management", "supplier"];
- Supplier::displayFullPageForItem($_GET["id"], $menus, [
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/transfer.form.php b/front/transfer.form.php
deleted file mode 100644
index 797956ce41b..00000000000
--- a/front/transfer.form.php
+++ /dev/null
@@ -1,92 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-/** @var array $CFG_GLPI */
-global $CFG_GLPI;
-
-Session::checkRight("transfer", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-$transfer = new Transfer();
-
-if (isset($_POST["add"])) {
- $transfer->check(-1, CREATE, $_POST);
-
- $newID = $transfer->add($_POST);
- Event::log(
- $newID,
- "transfers",
- 4,
- "setup",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- Html::back();
-} else if (isset($_POST["purge"])) {
- $transfer->check($_POST["id"], PURGE);
-
- $transfer->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "transfers",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- Html::redirect($CFG_GLPI["root_doc"] . "/front/transfer.php");
-} else if (isset($_POST["update"])) {
- $transfer->check($_POST["id"], UPDATE);
-
- $transfer->update($_POST);
- Event::log(
- $_POST["id"],
- "transfers",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-}
-
-$menus = ['admin', 'rule', 'Transfer'];
-Transfer::displayFullPageForItem($_GET["id"], $menus, [
- 'target' => $transfer->getFormURL()
-]);
diff --git a/front/unmanaged.form.php b/front/unmanaged.form.php
deleted file mode 100644
index 5e7f7ccb5e0..00000000000
--- a/front/unmanaged.form.php
+++ /dev/null
@@ -1,123 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("unmanaged", READ);
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
-
-$unmanaged = new Unmanaged();
-if (isset($_POST["add"])) {
- $unmanaged->check(-1, CREATE, $_POST);
-
- if ($newID = $unmanaged->add($_POST)) {
- Event::log(
- $newID,
- "Unmanaged",
- 4,
- "inventory",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($unmanaged->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $unmanaged->check($_POST["id"], DELETE);
- $unmanaged->delete($_POST);
-
- Event::log(
- $_POST["id"],
- "unmanaged",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
-
- $unmanaged->redirectToList();
-} else if (isset($_POST["restore"])) {
- $unmanaged->check($_POST["id"], DELETE);
-
- $unmanaged->restore($_POST);
- Event::log(
- $_POST["id"],
- "unmanaged",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- $unmanaged->redirectToList();
-} else if (isset($_POST["purge"])) {
- $unmanaged->check($_POST["id"], PURGE);
-
- $unmanaged->delete($_POST, 1);
- Event::log(
- $_POST["id"],
- "unmanaged",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- $unmanaged->redirectToList();
-} else if (isset($_POST["update"])) {
- $unmanaged->check($_POST["id"], UPDATE);
-
- $unmanaged->update($_POST);
- Event::log(
- $_POST["id"],
- "unmanaged",
- 4,
- "inventory",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- Html::back();
-} else {
- $menus = ["assets", "unmanaged"];
- Unmanaged::displayFullPageForItem($_GET["id"], $menus, [
- 'withtemplate' => $_GET["withtemplate"],
- 'formoptions' => "data-track-changes=true"
- ]);
-}
diff --git a/front/webhook.form.php b/front/webhook.form.php
deleted file mode 100644
index 8e29383cb0f..00000000000
--- a/front/webhook.form.php
+++ /dev/null
@@ -1,116 +0,0 @@
-.
- *
- * ---------------------------------------------------------------------
- */
-
-use Glpi\Event;
-
-Session::checkRight("config", READ);
-
-if (empty($_GET["id"])) {
- $_GET["id"] = "";
-}
-
-$webhook = new Webhook();
-
-if (isset($_POST["add"])) {
- $webhook->check(-1, CREATE);
- if ($newID = $webhook->add($_POST)) {
- Event::log(
- $newID,
- "webhook",
- 4,
- "setup",
- sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])
- );
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($webhook->getLinkURL());
- }
- }
- Html::back();
-} else if (isset($_POST["delete"])) {
- $webhook->check($_POST["id"], DELETE);
- if ($webhook->delete($_POST)) {
- Event::log(
- $_POST["id"],
- "webhook",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s deletes an item'), $_SESSION["glpiname"])
- );
- }
- $webhook->redirectToList();
-} else if (isset($_POST["restore"])) {
- $webhook->check($_POST["id"], DELETE);
- if ($webhook->restore($_POST)) {
- Event::log(
- $_POST["id"],
- "webhook",
- 4,
- "webhook",
- //TRANS: %s is the user login
- sprintf(__('%s restores an item'), $_SESSION["glpiname"])
- );
- }
- $webhook->redirectToList();
-} else if (isset($_POST["purge"])) {
- $webhook->check($_POST["id"], PURGE);
- if ($webhook->delete($_POST, 1)) {
- Event::log(
- $_POST["id"],
- "webhook",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s purges an item'), $_SESSION["glpiname"])
- );
- }
- $webhook->redirectToList();
-} else if (isset($_POST["update"])) {
- $webhook->check($_POST["id"], UPDATE);
- if ($webhook->update($_POST)) {
- Event::log(
- $_POST["id"],
- "webhook",
- 4,
- "setup",
- //TRANS: %s is the user login
- sprintf(__('%s updates an item'), $_SESSION["glpiname"])
- );
- }
- Html::back();
-} else {
- $menus = ["config", Webhook::class];
- Webhook::displayFullPageForItem($_GET["id"], $menus);
-}
diff --git a/phpunit/functional/Glpi/Http/LegacyItemtypeRouteListenerTest.php b/phpunit/functional/Glpi/Http/LegacyItemtypeRouteListenerTest.php
index 24493d9aadb..99aa51f224a 100644
--- a/phpunit/functional/Glpi/Http/LegacyItemtypeRouteListenerTest.php
+++ b/phpunit/functional/Glpi/Http/LegacyItemtypeRouteListenerTest.php
@@ -44,13 +44,14 @@
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelInterface;
+use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
final class LegacyItemtypeRouteListenerTest extends TestCase
{
#[DataProvider('provideItemtypes')]
public function testFindDbClass(string $path_info, string $expected_class_name): void
{
- $listener = new LegacyItemtypeRouteListener();
+ $listener = new LegacyItemtypeRouteListener($this->getUrlMatcherMock());
$request = $this->createRequest($path_info);
$event = new RequestEvent($this->createMock(KernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);
@@ -399,7 +400,7 @@ public static function provideItemtypes(): iterable
#[DataProvider('provideClassesForPlugin')]
public function testFindClassForPlugin(string $path_info, string $class): void
{
- $listener = new LegacyItemtypeRouteListener();
+ $listener = new LegacyItemtypeRouteListener($this->getUrlMatcherMock());
$request = $this->createRequest($path_info);
$event = new RequestEvent($this->createMock(KernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);
@@ -446,4 +447,12 @@ private function createRequest(string $path_info): Request
return $req;
}
+
+ private function getUrlMatcherMock(): UrlMatcherInterface
+ {
+ $mock = $this->createMock(UrlMatcherInterface::class);
+ $mock->method('match')->willThrowException(new \Exception());
+
+ return $mock;
+ }
}
diff --git a/src/APIClient.php b/src/APIClient.php
index 7ca815c8a90..f793b29732f 100644
--- a/src/APIClient.php
+++ b/src/APIClient.php
@@ -70,6 +70,16 @@ public static function getTypeName($nb = 0)
return _n("API client", "API clients", $nb);
}
+ public static function getSectorizedDetails(): array
+ {
+ return ["config", Config::class, self::class];
+ }
+
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'setup';
+ }
+
public function defineTabs($options = [])
{
diff --git a/src/Agent.php b/src/Agent.php
index 80f425d4765..1c4ad3ea157 100644
--- a/src/Agent.php
+++ b/src/Agent.php
@@ -83,6 +83,11 @@ public static function getSectorizedDetails(): array
return ['admin', Inventory::class, self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function rawSearchOptions()
{
diff --git a/src/Appliance.php b/src/Appliance.php
index 78258f7f328..806320905e9 100644
--- a/src/Appliance.php
+++ b/src/Appliance.php
@@ -72,6 +72,11 @@ public static function getSectorizedDetails(): array
return ['management', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public static function getTypeName($nb = 0)
{
return _n('Appliance', 'Appliances', $nb);
diff --git a/src/AuthMail.php b/src/AuthMail.php
index b3bc8f83c51..b48fd545a0f 100644
--- a/src/AuthMail.php
+++ b/src/AuthMail.php
@@ -55,6 +55,12 @@ public static function getSectorizedDetails(): array
public function prepareInputForUpdate($input)
{
+ if (empty($input['name'])) {
+ Session::addMessageAfterRedirect(sprintf(__s('The %s field is mandatory'), 'name'), false, ERROR);
+
+ return false;
+ }
+
if (!empty($input['mail_server'])) {
$input["connect_string"] = Toolbox::constructMailServerConfig($input);
}
@@ -73,6 +79,12 @@ public static function canPurge(): bool
public function prepareInputForAdd($input)
{
+ if (empty($input['name'])) {
+ Session::addMessageAfterRedirect(sprintf(__s('The %s field is mandatory'), 'name'), false, ERROR);
+
+ return false;
+ }
+
if (!empty($input['mail_server'])) {
$input["connect_string"] = Toolbox::constructMailServerConfig($input);
}
diff --git a/src/Cluster.php b/src/Cluster.php
index 6317b1703d9..d0e2e9aa3b7 100644
--- a/src/Cluster.php
+++ b/src/Cluster.php
@@ -65,6 +65,11 @@ public static function getSectorizedDetails(): array
return ['management', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function defineTabs($options = [])
{
$ong = [];
@@ -176,6 +181,20 @@ public function rawSearchOptions()
return $tab;
}
+ public function getFormOptionsFromUrl(array $query_params): array
+ {
+ $options = [];
+
+ if (isset($query_params['position'])) {
+ $options['position'] = $query_params['position'];
+ }
+ if (isset($query_params['room'])) {
+ $options['room'] = $query_params['room'];
+ }
+
+ return $options;
+ }
+
public function cleanDBonPurge()
{
diff --git a/src/CommonDBTM.php b/src/CommonDBTM.php
index 1a0343a3507..9c5b195ab4f 100644
--- a/src/CommonDBTM.php
+++ b/src/CommonDBTM.php
@@ -283,6 +283,33 @@ public static function getTableField($field, $classname = null)
return sprintf('%s.%s', $tablename, $field);
}
+ /**
+ * Returns the default service name to use when logging events.
+ *
+ * @return string
+ */
+ public static function getLogDefaultServiceName(): string
+ {
+ return '';
+ }
+
+ /**
+ * Returns the default level to use when logging events.
+ *
+ * Cases:
+ * 1: Critical (login error only)
+ * 2: Severe (not used)
+ * 3: Important (successful logins)
+ * 4: Notices (add, delete, tracking)
+ * 5: Complete (all)
+ *
+ * @return int
+ */
+ public static function getLogDefaultLevel(): int
+ {
+ return 4;
+ }
+
/**
* Retrieve an item from the database
*
@@ -1185,6 +1212,17 @@ protected function restoreInput(array $default = [])
return $default;
}
+ /**
+ * Extract the main item form options from the URL query parameters.
+ *
+ * @param array $query_params
+ * @return array
+ */
+ public function getFormOptionsFromUrl(array $query_params): array
+ {
+ return [];
+ }
+
/**
* Restore data saved in the session to $this->input
*
@@ -2388,6 +2426,18 @@ public function reset()
$this->fields = [];
}
+ /**
+ * Unglobalize the item : duplicate item and connections.
+ *
+ * @see Asset_PeripheralAsset::unglobalizeItem()
+ */
+ public function unglobalize()
+ {
+ // Wrapper only to standardize the usage of form actions in generic forms
+ Asset_PeripheralAsset::unglobalizeItem($this);
+
+ return null;
+ }
/**
* Have I the global right to add an item for the Object
@@ -6715,4 +6765,21 @@ public static function clearSearchOptionCache(): void
{
self::$search_options_cache = [];
}
+
+ /**
+ * Return the action to execute after a generic form action has been done.
+ *
+ * @param string $form_action
+ * @return string|null
+ */
+ public static function getPostFormAction(string $form_action): ?string
+ {
+ return match ($form_action) {
+ 'add' => 'backcreated',
+ 'update' => 'back',
+ 'delete', 'restore', 'purge' => 'list',
+ 'unglobalize' => 'form',
+ default => null,
+ };
+ }
}
diff --git a/src/CommonGLPI.php b/src/CommonGLPI.php
index c5eca186a15..abc9212b3e1 100644
--- a/src/CommonGLPI.php
+++ b/src/CommonGLPI.php
@@ -755,25 +755,28 @@ public static function createTabEntry($text, $nb = 0, ?string $form_itemtype = n
*
* @return void
**/
- public function redirectToList()
+ public function redirectToList(): void
+ {
+ Html::redirect($this->getRedirectToListUrl());
+ }
+
+ public function getRedirectToListUrl(): string
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
+ if (!empty($_GET['withtemplate'])) {
+ return $CFG_GLPI["root_doc"] . "/front/setup.templates.php?add=0&itemtype=" . static::getType();
+ }
+
if (
- isset($_GET['withtemplate'])
- && !empty($_GET['withtemplate'])
- ) {
- Html::redirect($CFG_GLPI["root_doc"] . "/front/setup.templates.php?add=0&itemtype=" .
- $this->getType());
- } else if (
- isset($_SESSION['glpilisturl'][$this->getType()])
- && !empty($_SESSION['glpilisturl'][$this->getType()])
+ isset($_SESSION['glpilisturl'][static::getType()])
+ && !empty($_SESSION['glpilisturl'][static::getType()])
) {
- Html::redirect($_SESSION['glpilisturl'][$this->getType()]);
- } else {
- Html::redirect($this->getSearchURL());
+ return $_SESSION['glpilisturl'][static::getType()];
}
+
+ return static::getSearchURL();
}
/**
diff --git a/src/Computer.php b/src/Computer.php
index 4ca2a5e9f09..f9e36e4e332 100644
--- a/src/Computer.php
+++ b/src/Computer.php
@@ -97,6 +97,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function useDeletedToLockIfDynamic()
{
return false;
diff --git a/src/Contact.php b/src/Contact.php
index 594c62a5f9c..de03d02824d 100644
--- a/src/Contact.php
+++ b/src/Contact.php
@@ -63,6 +63,11 @@ public static function getSectorizedDetails(): array
return ['management', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'financial';
+ }
+
public function prepareInputForAdd($input)
{
$input = parent::prepareInputForAdd($input);
diff --git a/src/Contract.php b/src/Contract.php
index cb3b1671eab..b20a69e4c08 100644
--- a/src/Contract.php
+++ b/src/Contract.php
@@ -76,6 +76,11 @@ public static function getSectorizedDetails(): array
return ['management', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'financial';
+ }
+
public function post_getEmpty()
{
if (isset($_SESSION['glpiactive_entity'])) {
diff --git a/src/Enclosure.php b/src/Enclosure.php
index a452c215b6a..b5dd6e68112 100644
--- a/src/Enclosure.php
+++ b/src/Enclosure.php
@@ -71,6 +71,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function defineTabs($options = [])
{
$ong = [];
@@ -300,6 +305,19 @@ public function cleanDBonPurge()
);
}
+ public function getFormOptionsFromUrl(array $query_params): array
+ {
+ $options = [];
+
+ if (isset($query_params['position'])) {
+ $options['position'] = $query_params['position'];
+ }
+ if (isset($query_params['room'])) {
+ $options['room'] = $query_params['room'];
+ }
+
+ return $options;
+ }
public function prepareInputForAdd($input)
{
diff --git a/src/Glpi/Asset/Asset_PeripheralAsset.php b/src/Glpi/Asset/Asset_PeripheralAsset.php
index b70acc7b479..50a907a8431 100644
--- a/src/Glpi/Asset/Asset_PeripheralAsset.php
+++ b/src/Glpi/Asset/Asset_PeripheralAsset.php
@@ -613,6 +613,15 @@ public static function unglobalizeItem(CommonDBTM $item): void
{
/** @var \DBmysql $DB */
global $DB;
+ /** @var array $CFG_GLPI */
+ global $CFG_GLPI;
+
+ if (
+ !\in_array($item::class, $CFG_GLPI['directconnect_types'], true)
+ || !$item->isField('is_global')
+ ) {
+ throw new \LogicException(\sprintf('Item of class "%s" does not support being unglobalized', $item::class));
+ }
// Update item to unit management :
if ($item->getField('is_global')) {
diff --git a/src/Glpi/Config/LegacyConfigurators/SessionConfig.php b/src/Glpi/Config/LegacyConfigurators/SessionConfig.php
index 3156e242616..f0e40fc7cb7 100644
--- a/src/Glpi/Config/LegacyConfigurators/SessionConfig.php
+++ b/src/Glpi/Config/LegacyConfigurators/SessionConfig.php
@@ -34,13 +34,17 @@
namespace Glpi\Config\LegacyConfigurators;
+use Glpi\Config\ConfigProviderHasRequestTrait;
+use Glpi\Config\ConfigProviderWithRequestInterface;
use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Debug\Profile;
use Glpi\Toolbox\URL;
use Session;
-final readonly class SessionConfig implements LegacyConfigProviderInterface
+final class SessionConfig implements LegacyConfigProviderInterface, ConfigProviderWithRequestInterface
{
+ use ConfigProviderHasRequestTrait;
+
public function execute(): void
{
// Load Language file
@@ -58,9 +62,11 @@ public function execute(): void
$_SESSION["MESSAGE_AFTER_REDIRECT"] = [];
}
+ $request = $this->getRequest();
+
// Manage force tab
- if (isset($_REQUEST['forcetab'])) {
- $itemtype = URL::extractItemtypeFromUrlPath($_SERVER['PHP_SELF']);
+ if ($request->query->has('forcetab')) {
+ $itemtype = URL::extractItemtypeFromUrlPath($request->getPathInfo());
if ($itemtype !== null) {
Session::setActiveTab($itemtype, $_REQUEST['forcetab']);
}
diff --git a/src/Glpi/Controller/DropdownFormController.php b/src/Glpi/Controller/DropdownFormController.php
index 3015fbb7b83..a818a7f6f99 100644
--- a/src/Glpi/Controller/DropdownFormController.php
+++ b/src/Glpi/Controller/DropdownFormController.php
@@ -49,7 +49,7 @@
final class DropdownFormController extends AbstractController
{
- #[Route("/Dropdown/Form/{class}", name: "glpi_dropdown_form")]
+ #[Route("/Dropdown/{class}/Form", name: "glpi_dropdown_form")]
public function __invoke(Request $request): Response
{
$class = $request->attributes->getString('class');
diff --git a/src/Glpi/Controller/GenericFormController.php b/src/Glpi/Controller/GenericFormController.php
new file mode 100644
index 00000000000..15625ba7bde
--- /dev/null
+++ b/src/Glpi/Controller/GenericFormController.php
@@ -0,0 +1,196 @@
+.
+ *
+ * ---------------------------------------------------------------------
+ */
+
+namespace Glpi\Controller;
+
+use CommonDBTM;
+use Html;
+use Glpi\Event;
+use Glpi\Exception\Http\AccessDeniedHttpException;
+use Glpi\Exception\Http\BadRequestHttpException;
+use Glpi\Exception\Http\NotFoundHttpException;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Routing\Attribute\Route;
+
+class GenericFormController extends AbstractController
+{
+ private const SUPPORTED_ACTIONS = [
+ 'add',
+ 'delete',
+ 'restore',
+ 'purge',
+ 'update',
+ 'unglobalize',
+ ];
+
+ #[Route("/{class}/Form", name: "glpi_itemtype_form", priority: -1)]
+ public function __invoke(Request $request): Response
+ {
+ $class = $request->attributes->getString('class');
+
+ $this->checkIsValidClass($class);
+
+ /** @var class-string $class */
+
+ if (!$class::canView()) {
+ throw new AccessDeniedHttpException();
+ }
+
+ $form_action = $this->getFormAction($request, $class);
+
+ if (!$form_action) {
+ throw new BadRequestHttpException();
+ }
+
+ return $this->handleFormAction($request, $form_action, $class);
+ }
+
+ private function checkIsValidClass(string $class): void
+ {
+ if (!$class) {
+ throw new BadRequestHttpException('The "class" attribute is mandatory for dropdown routes.');
+ }
+
+ if (!\class_exists($class)) {
+ throw new BadRequestHttpException(\sprintf("Class \"%s\" does not exist.", $class));
+ }
+
+ if (!\is_subclass_of($class, CommonDBTM::class)) {
+ throw new BadRequestHttpException(\sprintf("Class \"%s\" is not a DB object.", $class));
+ }
+ }
+
+ /**
+ * @param class-string $class
+ */
+ private function handleFormAction(Request $request, string $form_action, string $class): Response
+ {
+ $id = $request->query->get('id', -1);
+ $post_data = $request->request->all();
+
+ /* @var CommonDBTM $object */
+ $object = new $class();
+
+ if (!$object::isNewID($id) && !$object->getFromDB($id)) {
+ throw new NotFoundHttpException();
+ }
+
+ // Special case for GET
+ if ($form_action === 'get') {
+ if (!$object->can($id, READ)) {
+ throw new AccessDeniedHttpException();
+ }
+ return $this->displayForm($object, $request);
+ }
+
+ // Permissions
+ $can_do_action = match ($form_action) {
+ 'add' => $object->can($id, CREATE, $post_data),
+ 'delete', 'restore' => $object->can($id, DELETE, $post_data),
+ 'purge' => $object->can($id, PURGE, $post_data),
+ 'update', 'unglobalize' => $object->can($id, UPDATE, $post_data),
+ default => throw new \RuntimeException(\sprintf("Unsupported object action \"%s\".", $form_action)),
+ };
+
+ if (!$can_do_action) {
+ throw new AccessDeniedHttpException();
+ }
+
+ // POST action execution
+ $action_result = match ($form_action) {
+ 'add' => $object->add($post_data),
+ 'delete' => $object->delete($post_data),
+ 'restore' => $object->restore($post_data),
+ 'purge' => $object->delete($post_data, 1),
+ 'update' => $object->update($post_data),
+ 'unglobalize' => $object->unglobalize(),
+ default => throw new \RuntimeException(\sprintf("Unsupported object action \"%s\".", $form_action)),
+ };
+
+ if ($action_result) {
+ Event::log(
+ $action_result,
+ $class,
+ $object::getLogDefaultLevel(),
+ $object::getLogDefaultServiceName(),
+ sprintf(__('%1$s executes the "%2$s" action on the item %3$s'), $_SESSION["glpiname"], $form_action, $post_data["name"])
+ );
+ }
+
+ $post_action = $object::getPostFormAction($form_action);
+
+ return match ($post_action) {
+ 'backcreated' => $_SESSION['glpibackcreated']
+ ? new RedirectResponse($object->getLinkURL())
+ : new RedirectResponse(Html::getBackUrl()),
+ 'back' => new RedirectResponse(Html::getBackUrl()),
+ 'form' => new RedirectResponse($object->getLinkURL()),
+ 'list' => new RedirectResponse($object->getRedirectToListUrl()),
+ default => new RedirectResponse($object->getLinkURL()),
+ };
+ }
+
+ /**
+ * @param class-string $class
+ */
+ private function getFormAction(Request $request, string $class): ?string
+ {
+ if ($request->getMethod() === 'POST') {
+ foreach (self::SUPPORTED_ACTIONS as $action) {
+ if ($request->request->has($action)) {
+ return $action;
+ }
+ }
+ }
+
+ return $request->getMethod() === 'GET' ? 'get' : null;
+ }
+
+ public function displayForm(CommonDBTM $object, Request $request): Response
+ {
+ $form_options = $object->getFormOptionsFromUrl($request->query->all());
+ $form_options['formoptions'] = 'data-track-changes=true';
+ if ($object->maybeTemplate()) {
+ $form_options['withtemplate'] = $request->query->get('withtemplate', '');
+ }
+
+ return $this->render('pages/generic_form.html.twig', [
+ 'id' => $request->query->get('id', -1),
+ 'object_class' => $object::class,
+ 'form_options' => $form_options,
+ ]);
+ }
+}
diff --git a/src/Glpi/Controller/GenericListController.php b/src/Glpi/Controller/GenericListController.php
index cc1716fb6ba..6800b0b8b71 100644
--- a/src/Glpi/Controller/GenericListController.php
+++ b/src/Glpi/Controller/GenericListController.php
@@ -43,7 +43,7 @@
final class GenericListController extends AbstractController
{
- #[Route("/{class}/Search", name: "glpi_generic_list")]
+ #[Route("/{class}/Search", name: "glpi_itemtype_list", priority: -1)]
public function __invoke(Request $request): Response
{
$class = $request->attributes->getString('class');
diff --git a/src/Glpi/Controller/ItemType/Form/AuthMailFormController.php b/src/Glpi/Controller/ItemType/Form/AuthMailFormController.php
new file mode 100644
index 00000000000..6758fb09161
--- /dev/null
+++ b/src/Glpi/Controller/ItemType/Form/AuthMailFormController.php
@@ -0,0 +1,78 @@
+.
+ *
+ * ---------------------------------------------------------------------
+ */
+
+namespace Glpi\Controller\ItemType\Form;
+
+use AuthMail;
+use Glpi\Controller\GenericFormController;
+use Glpi\Routing\Attribute\ItemtypeFormLegacyRoute;
+use Glpi\Routing\Attribute\ItemtypeFormRoute;
+use Html;
+use Session;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+class AuthMailFormController extends GenericFormController
+{
+ #[ItemtypeFormRoute(AuthMail::class)]
+ #[ItemtypeFormLegacyRoute(AuthMail::class)]
+ public function __invoke(Request $request): Response
+ {
+ $request->attributes->set('class', AuthMail::class);
+
+ if ($request->request->has('test')) {
+ return $this->handleTestAction($request);
+ }
+
+ return parent::__invoke($request);
+ }
+
+ public function handleTestAction(Request $request): RedirectResponse
+ {
+ $test_auth = AuthMail::testAuth(
+ $request->request->get("imap_string"),
+ $request->request->get("imap_login"),
+ $request->request->get("imap_password"),
+ );
+
+ if ($test_auth) {
+ Session::addMessageAfterRedirect(__s('Test successful'));
+ } else {
+ Session::addMessageAfterRedirect(__s('Test failed'), false, ERROR);
+ }
+
+ return new RedirectResponse(Html::getBackUrl());
+ }
+}
diff --git a/src/Glpi/Controller/ItemType/Form/ContactFormController.php b/src/Glpi/Controller/ItemType/Form/ContactFormController.php
new file mode 100644
index 00000000000..937f77b5634
--- /dev/null
+++ b/src/Glpi/Controller/ItemType/Form/ContactFormController.php
@@ -0,0 +1,77 @@
+.
+ *
+ * ---------------------------------------------------------------------
+ */
+
+namespace Glpi\Controller\ItemType\Form;
+
+use Contact;
+use Glpi\Controller\GenericFormController;
+use Glpi\Exception\Http\AccessDeniedHttpException;
+use Glpi\Exception\Http\BadRequestHttpException;
+use Glpi\Routing\Attribute\ItemtypeFormLegacyRoute;
+use Glpi\Routing\Attribute\ItemtypeFormRoute;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\StreamedResponse;
+
+class ContactFormController extends GenericFormController
+{
+ #[ItemtypeFormRoute(Contact::class)]
+ #[ItemtypeFormLegacyRoute(Contact::class)]
+ public function __invoke(Request $request): Response
+ {
+ $request->attributes->set('class', Contact::class);
+
+ if ($request->query->has('getvcard')) {
+ return $this->generateVCard($request);
+ }
+
+ return parent::__invoke($request);
+ }
+
+ private function generateVCard(Request $request): Response
+ {
+ $id = $request->query->getInt('id');
+
+ if (Contact::isNewID($id)) {
+ throw new BadRequestHttpException();
+ }
+
+ $contact = new Contact();
+ if (!$contact->can($id, READ)) {
+ throw new AccessDeniedHttpException();
+ }
+
+ return new StreamedResponse(fn () => $contact->generateVcard());
+ }
+}
diff --git a/front/savedsearch.form.php b/src/Glpi/Controller/ItemType/Form/SavedSearchFormController.php
similarity index 50%
rename from front/savedsearch.form.php
rename to src/Glpi/Controller/ItemType/Form/SavedSearchFormController.php
index c244cd3d58a..b97837df3e1 100644
--- a/front/savedsearch.form.php
+++ b/src/Glpi/Controller/ItemType/Form/SavedSearchFormController.php
@@ -8,7 +8,6 @@
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
- * @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
@@ -33,42 +32,38 @@
* ---------------------------------------------------------------------
*/
-if (!isset($_GET["id"])) {
- $_GET["id"] = "";
-}
+namespace Glpi\Controller\ItemType\Form;
-if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
-}
+use Glpi\Controller\GenericFormController;
+use Glpi\Routing\Attribute\ItemtypeFormLegacyRoute;
+use Glpi\Routing\Attribute\ItemtypeFormRoute;
+use Html;
+use SavedSearch;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
-$savedsearch = new SavedSearch();
-if (isset($_POST["add"])) {
- //Add a new saved search
- $savedsearch->check(-1, CREATE, $_POST);
- if ($savedsearch->add($_POST)) {
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($savedsearch->getLinkURL());
+class SavedSearchFormController extends GenericFormController
+{
+ #[ItemtypeFormRoute(SavedSearch::class)]
+ #[ItemtypeFormLegacyRoute(SavedSearch::class)]
+ public function __invoke(Request $request): Response
+ {
+ $request->attributes->set('class', SavedSearch::class);
+
+ if ($request->query->has('create_notif')) {
+ return $this->createNotif();
}
+
+ return parent::__invoke($request);
+ }
+
+ public function createNotif(): RedirectResponse
+ {
+ $savedsearch = new SavedSearch();
+ $savedsearch->check($_GET['id'], UPDATE);
+ $savedsearch->createNotif();
+
+ return new RedirectResponse(Html::getBackUrl());
}
- Html::back();
-} else if (isset($_POST["purge"])) {
- // delete a saved search
- $savedsearch->check($_POST['id'], PURGE);
- $savedsearch->delete($_POST, 1);
- $savedsearch->redirectToList();
-} else if (isset($_POST["update"])) {
- //update a saved search
- $savedsearch->check($_POST['id'], UPDATE);
- $savedsearch->update($_POST);
- Html::back();
-} else if (isset($_GET['create_notif'])) {
- $savedsearch->check($_GET['id'], UPDATE);
- $savedsearch->createNotif();
- Html::back();
-} else {
- $menus = [
- 'central' => ['tools', 'savedsearch'],
- 'helpdesk' => [],
- ];
- SavedSearch::displayFullPageForItem($_GET["id"], $menus);
}
diff --git a/src/Glpi/Event.php b/src/Glpi/Event.php
index 2f6703bbd8e..ea46a5f7d5d 100644
--- a/src/Glpi/Event.php
+++ b/src/Glpi/Event.php
@@ -227,8 +227,10 @@ public static function displayItemLogID($type, $items_id)
break;
default:
- $type = getSingular($type);
$url = '';
+ if (!is_a($type, \CommonDBTM::class, true)) {
+ $type = getSingular($type);
+ }
if ($item = getItemForItemtype($type)) {
$url = $item->getFormURLWithID($items_id);
}
@@ -334,7 +336,9 @@ public static function showForUser(string $user = "", bool $display = true)
if (isset($logItemtype[$type])) {
$itemtype = $logItemtype[$type];
} else {
- $type = getSingular($type);
+ if (!is_a($type, \CommonDBTM::class, true)) {
+ $type = getSingular($type);
+ }
if ($item = getItemForItemtype($type)) {
$itemtype = $item->getTypeName(1);
}
@@ -418,8 +422,11 @@ public static function showList($target, $order = 'DESC', $sort = 'date', $start
if (isset($logItemtype[$data['type']])) {
$itemtype_name = $logItemtype[$data['type']];
} else {
- // Converts lowercase plural string into corresponding classname
- $item = getItemForItemtype(getSingular($data['type']));
+ $type = $data['type'];
+ if (!is_a($type, \CommonDBTM::class, true)) {
+ $type = getSingular($type);
+ }
+ $item = getItemForItemtype($type);
if ($item !== false) {
$itemtype_name = $item->getTypeName();
$itemtype_icon = $item->getIcon();
diff --git a/src/Glpi/Http/LegacyItemtypeRouteListener.php b/src/Glpi/Http/LegacyItemtypeRouteListener.php
index 40d97694355..a54900d1959 100644
--- a/src/Glpi/Http/LegacyItemtypeRouteListener.php
+++ b/src/Glpi/Http/LegacyItemtypeRouteListener.php
@@ -41,6 +41,7 @@
use Glpi\Asset\AssetDefinition;
use Glpi\Asset\AssetModel;
use Glpi\Asset\AssetType;
+use Glpi\Controller\GenericFormController;
use Glpi\Controller\GenericListController;
use Glpi\Controller\DropdownFormController;
use Glpi\Dropdown\Dropdown;
@@ -49,9 +50,14 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
final readonly class LegacyItemtypeRouteListener implements EventSubscriberInterface
{
+ public function __construct(private UrlMatcherInterface $url_matcher)
+ {
+ }
+
public static function getSubscribedEvents(): array
{
return [
@@ -74,6 +80,14 @@ public function onKernelRequest(RequestEvent $event): void
return;
}
+ try {
+ $this->url_matcher->match($request->getPathInfo());
+ // The URL matches an existing route, let the symfony routing forward to the expected controller.
+ return;
+ } catch (\Exception $e) {
+ // The URL does not match any route, try to forward it to a generic controller.
+ }
+
if ($class = $this->findClass($request)) {
$is_form = \str_ends_with($request->getPathInfo(), '.form.php');
@@ -81,7 +95,7 @@ public function onKernelRequest(RequestEvent $event): void
$request->attributes->set('_controller', $is_form ? DropdownFormController::class : GenericListController::class);
$request->attributes->set('class', $class);
} else {
- $request->attributes->set('_controller', $is_form ? null : GenericListController::class);
+ $request->attributes->set('_controller', $is_form ? GenericFormController::class : GenericListController::class);
$request->attributes->set('class', $class);
}
}
diff --git a/src/Glpi/Kernel/Kernel.php b/src/Glpi/Kernel/Kernel.php
index b5eea6628f6..5bb05b3264b 100644
--- a/src/Glpi/Kernel/Kernel.php
+++ b/src/Glpi/Kernel/Kernel.php
@@ -150,7 +150,7 @@ protected function configureContainer(ContainerConfigurator $container): void
protected function configureRoutes(RoutingConfigurator $routes): void
{
- // Global core controllers
+ // Global core controllers
$routes->import($this->getProjectDir() . '/src/Glpi/Controller', 'attribute');
// Env-specific route files.
diff --git a/src/Glpi/RichText/RichText.php b/src/Glpi/RichText/RichText.php
index 143f13cc81f..3dbe3ae1ab1 100644
--- a/src/Glpi/RichText/RichText.php
+++ b/src/Glpi/RichText/RichText.php
@@ -292,7 +292,7 @@ public static function getEnhancedHtml(?string $content, array $params = []): st
HTML;
- $content .= HTML::scriptBlock('$(function() { read_more(); });');
+ $content .= Html::scriptBlock('$(function() { read_more(); });');
}
return $content;
diff --git a/src/Glpi/Routing/Attribute/ItemtypeFormLegacyRoute.php b/src/Glpi/Routing/Attribute/ItemtypeFormLegacyRoute.php
new file mode 100644
index 00000000000..6c74cb512cc
--- /dev/null
+++ b/src/Glpi/Routing/Attribute/ItemtypeFormLegacyRoute.php
@@ -0,0 +1,52 @@
+.
+ *
+ * ---------------------------------------------------------------------
+ */
+
+namespace Glpi\Routing\Attribute;
+
+use Symfony\Component\Routing\Attribute\Route;
+
+#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
+class ItemtypeFormLegacyRoute extends Route
+{
+ /**
+ * @phpstan-param class-string<\CommonDBTM> $itemtype
+ */
+ public function __construct(string $itemtype)
+ {
+ parent::__construct(
+ path: $itemtype::getFormURL(false),
+ name: 'glpi_itemtype_' . \strtolower($itemtype) . '_form_legacy',
+ );
+ }
+}
diff --git a/src/Glpi/Routing/Attribute/ItemtypeFormRoute.php b/src/Glpi/Routing/Attribute/ItemtypeFormRoute.php
new file mode 100644
index 00000000000..1e0bd5ea783
--- /dev/null
+++ b/src/Glpi/Routing/Attribute/ItemtypeFormRoute.php
@@ -0,0 +1,52 @@
+.
+ *
+ * ---------------------------------------------------------------------
+ */
+
+namespace Glpi\Routing\Attribute;
+
+use Symfony\Component\Routing\Attribute\Route;
+
+#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
+class ItemtypeFormRoute extends Route
+{
+ /**
+ * @phpstan-param class-string<\CommonDBTM> $itemtype
+ */
+ public function __construct(string $itemtype)
+ {
+ parent::__construct(
+ path: '/' . $itemtype . '/Form',
+ name: 'glpi_itemtype_' . \strtolower($itemtype) . '_form',
+ );
+ }
+}
diff --git a/src/Infocom.php b/src/Infocom.php
index 0cd257e14b6..6c8c42a51f2 100644
--- a/src/Infocom.php
+++ b/src/Infocom.php
@@ -36,6 +36,7 @@
use Glpi\Application\View\TemplateRenderer;
use Glpi\DBAL\QueryExpression;
use Glpi\DBAL\QueryFunction;
+use Glpi\Exception\Http\NotFoundHttpException;
/**
* Infocom class
@@ -882,6 +883,46 @@ public static function getAmortTypeName($value)
}
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'financial';
+ }
+
+ public static function displayFullPageForItem($id, ?array $menus = null, array $options = []): void
+ {
+ $ic = new self();
+
+ $item = false;
+
+ if (isset($_GET["id"])) {
+ $ic->getFromDB($_GET["id"]);
+ $_GET["itemtype"] = $ic->fields["itemtype"];
+ $_GET["items_id"] = $ic->fields["items_id"];
+ }
+
+ if (
+ isset($_GET["itemtype"])
+ && ($item = getItemForItemtype($_GET["itemtype"]))
+ && (
+ !isset($_GET["items_id"])
+ || !$item->getFromDB($_GET["items_id"])
+ )
+ ) {
+ throw new NotFoundHttpException();
+ }
+
+ Html::popHeader(self::getTypeName());
+
+ self::showForItem($item);
+
+ Html::popFooter();
+ }
+
+ public static function getPostFormAction(string $form_action): ?string
+ {
+ // Always return to the previous page
+ return 'back';
+ }
/**
* Calculate TCO and TCO by month for an item
diff --git a/src/Line.php b/src/Line.php
index 54ac3e88b0f..0915e05bbcd 100644
--- a/src/Line.php
+++ b/src/Line.php
@@ -63,6 +63,11 @@ public static function getSectorizedDetails(): array
return ['management', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'financial';
+ }
+
/**
* @see CommonDBTM::useDeletedToLockIfDynamic()
*
diff --git a/src/Link.php b/src/Link.php
index e4388cf8250..bf78d6be16f 100644
--- a/src/Link.php
+++ b/src/Link.php
@@ -63,6 +63,11 @@ public static function getSectorizedDetails(): array
return ['config', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'setup';
+ }
+
/**
* For plugins, add a tag to the links tags
*
diff --git a/src/Monitor.php b/src/Monitor.php
index 3d17e3da95a..6a7aeeb73b7 100644
--- a/src/Monitor.php
+++ b/src/Monitor.php
@@ -86,6 +86,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
/**
* @see CommonDBTM::useDeletedToLockIfDynamic()
*
diff --git a/src/OLA.php b/src/OLA.php
index a0826ee9dea..0d06d19a730 100644
--- a/src/OLA.php
+++ b/src/OLA.php
@@ -56,6 +56,11 @@ public static function getSectorizedDetails(): array
return ['config', SLM::class, self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'setup';
+ }
+
public static function getIcon()
{
return SLM::getIcon();
diff --git a/src/PDU.php b/src/PDU.php
index 37abdbb0d70..872d9940811 100644
--- a/src/PDU.php
+++ b/src/PDU.php
@@ -68,6 +68,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function defineTabs($options = [])
{
$ong = [];
diff --git a/src/PassiveDCEquipment.php b/src/PassiveDCEquipment.php
index ae3540f5c48..3fc864cbedb 100644
--- a/src/PassiveDCEquipment.php
+++ b/src/PassiveDCEquipment.php
@@ -59,6 +59,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function defineTabs($options = [])
{
$ong = [];
@@ -262,6 +267,20 @@ public function rawSearchOptions()
return $tab;
}
+ public function getFormOptionsFromUrl(array $query_params): array
+ {
+ $options = [];
+
+ if (isset($query_params['position'])) {
+ $options['position'] = $query_params['position'];
+ }
+ if (isset($query_params['room'])) {
+ $options['room'] = $query_params['room'];
+ }
+
+ return $options;
+ }
+
public static function getIcon()
{
return "ti ti-layout-navbar";
diff --git a/src/Peripheral.php b/src/Peripheral.php
index b640258a5b7..79556612f29 100644
--- a/src/Peripheral.php
+++ b/src/Peripheral.php
@@ -88,6 +88,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
/**
* @see CommonDBTM::useDeletedToLockIfDynamic()
*
diff --git a/src/Phone.php b/src/Phone.php
index e8976d569ed..9d009645331 100644
--- a/src/Phone.php
+++ b/src/Phone.php
@@ -91,6 +91,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
/**
* @see CommonDBTM::useDeletedToLockIfDynamic()
*
diff --git a/src/Printer.php b/src/Printer.php
index a643af9312b..45dc0f7305b 100644
--- a/src/Printer.php
+++ b/src/Printer.php
@@ -91,6 +91,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
/**
* @see CommonDBTM::useDeletedToLockIfDynamic()
*
diff --git a/src/SLA.php b/src/SLA.php
index 1e28dc7b4e0..3bff5a6b8af 100644
--- a/src/SLA.php
+++ b/src/SLA.php
@@ -60,6 +60,11 @@ public static function getSectorizedDetails(): array
return ['config', SLM::class, self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'setup';
+ }
+
public static function getIcon()
{
return SLM::getIcon();
diff --git a/src/SLM.php b/src/SLM.php
index 8d06d83c8e0..ed385f33ca7 100644
--- a/src/SLM.php
+++ b/src/SLM.php
@@ -63,6 +63,11 @@ public static function getSectorizedDetails(): array
return ['config', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'setup';
+ }
+
public function defineTabs($options = [])
{
$ong = [];
diff --git a/src/SavedSearch.php b/src/SavedSearch.php
index 6690c680b83..9c2786443a6 100644
--- a/src/SavedSearch.php
+++ b/src/SavedSearch.php
@@ -68,6 +68,11 @@ public static function getTypeName($nb = 0)
return _n('Saved search', 'Saved searches', $nb);
}
+ public static function getSectorizedDetails(): array
+ {
+ return ['tools', self::class];
+ }
+
public function getForbiddenStandardMassiveAction()
{
diff --git a/src/Software.php b/src/Software.php
index abe93df107e..36628495812 100644
--- a/src/Software.php
+++ b/src/Software.php
@@ -82,6 +82,11 @@ public static function getMenuShorcut()
return 's';
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
if (
diff --git a/src/Supplier.php b/src/Supplier.php
index 59c205c356e..2be2907bac7 100644
--- a/src/Supplier.php
+++ b/src/Supplier.php
@@ -65,6 +65,11 @@ public static function getSectorizedDetails(): array
return ['management', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'financial';
+ }
+
public function post_getEmpty()
{
$this->fields['is_active'] = 1;
diff --git a/src/Transfer.php b/src/Transfer.php
index 9eeabe00c99..2b02990d8c2 100644
--- a/src/Transfer.php
+++ b/src/Transfer.php
@@ -89,6 +89,19 @@ public static function getSectorizedDetails(): array
return ['admin', Rule::class, self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'setup';
+ }
+
+ public function getFormOptionsFromUrl(array $query_params): array
+ {
+ return [
+ // Required for pagination
+ 'target' => self::getFormURL(),
+ ];
+ }
+
public function maxActionsCount()
{
return 0;
diff --git a/src/Unmanaged.php b/src/Unmanaged.php
index 23562836dc7..427111b83ac 100644
--- a/src/Unmanaged.php
+++ b/src/Unmanaged.php
@@ -60,6 +60,11 @@ public static function getSectorizedDetails(): array
return ['assets', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'inventory';
+ }
+
public function defineTabs($options = [])
{
diff --git a/src/Webhook.php b/src/Webhook.php
index 083dec8c03f..0ed50509bb0 100644
--- a/src/Webhook.php
+++ b/src/Webhook.php
@@ -44,7 +44,6 @@
use Glpi\Application\View\TemplateRenderer;
use Glpi\Search\FilterableInterface;
use Glpi\Search\FilterableTrait;
-use GuzzleHttp\Client as Guzzle_Client;
class Webhook extends CommonDBTM implements FilterableInterface
{
@@ -84,6 +83,11 @@ public static function getSectorizedDetails(): array
return ['config', self::class];
}
+ public static function getLogDefaultServiceName(): string
+ {
+ return 'setup';
+ }
+
public static function canCreate(): bool
{
return static::canUpdate();
diff --git a/templates/pages/generic_form.html.twig b/templates/pages/generic_form.html.twig
new file mode 100644
index 00000000000..ce1b51c2483
--- /dev/null
+++ b/templates/pages/generic_form.html.twig
@@ -0,0 +1,37 @@
+{#
+ # ---------------------------------------------------------------------
+ #
+ # GLPI - Gestionnaire Libre de Parc Informatique
+ #
+ # http://glpi-project.org
+ #
+ # @copyright 2015-2024 Teclib' and contributors.
+ # @licence https://www.gnu.org/licenses/gpl-3.0.html
+ #
+ # ---------------------------------------------------------------------
+ #
+ # LICENSE
+ #
+ # This file is part of GLPI.
+ #
+ # This program 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 3 of the License, or
+ # (at your option) any later version.
+ #
+ # This program 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 this program. If not, see .
+ #
+ # ---------------------------------------------------------------------
+ #}
+
+{{ call([object_class, 'displayFullPageForItem'], [
+ id,
+ call([object_class, 'getSectorizedDetails']),
+ form_options,
+]) }}
diff --git a/templates/pages/tools/savedsearch/alert_list_notification.html.twig b/templates/pages/tools/savedsearch/alert_list_notification.html.twig
index 8d6a23df3e3..420c04721f3 100644
--- a/templates/pages/tools/savedsearch/alert_list_notification.html.twig
+++ b/templates/pages/tools/savedsearch/alert_list_notification.html.twig
@@ -48,7 +48,7 @@
{{ __('Notification does not exist') }}
{% if params.canedit %}
- {{ __('Create it now') }}
+ {{ __('Create it now') }}
{% set params = params|merge({
'canedit': false
}) %}
diff --git a/tests/cypress/e2e/error_page.cy.js b/tests/cypress/e2e/error_page.cy.js
index 6e3435794d7..6177aa72c90 100644
--- a/tests/cypress/e2e/error_page.cy.js
+++ b/tests/cypress/e2e/error_page.cy.js
@@ -79,7 +79,8 @@ describe('Error page', () => {
cy.changeProfile('Self-Service');
const urls = [
- '/front/computer.php', // streamed response
+ '/front/central.php', // streamed response
+ '/front/computer.php', // generic controller
'/Form/Import', // modern controller
];
@@ -105,8 +106,9 @@ describe('Error page', () => {
cy.changeProfile('Super-Admin');
const urls = [
- '/front/computer.form.php?id=999999', // streamed response
- '/Form/Render/999999', // modern controller
+ '/front/logviewer.php?filepath=invalid', // streamed response
+ '/front/computer.form.php?id=999999', // generic response
+ '/Form/Render/999999', // modern controller
];
const expected_code = 404;