diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index d1f521d0..b442e5b4 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -20,7 +20,7 @@ jobs:
name: "Generate CI matrix"
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
with:
- glpi-version: "10.0.x"
+ glpi-version: "11.0.x"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
new file mode 100644
index 00000000..7a81c5ba
--- /dev/null
+++ b/.php-cs-fixer.php
@@ -0,0 +1,21 @@
+in(__DIR__)
+ ->name('*.php')
+ ->ignoreVCSIgnored(true);
+
+$config = new Config();
+
+$rules = [
+ '@PER-CS2.0' => true,
+ 'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
+];
+
+return $config
+ ->setRules($rules)
+ ->setFinder($finder)
+ ->setUsingCache(false);
diff --git a/.phpcs.xml b/.phpcs.xml
deleted file mode 100644
index 6c5742f9..00000000
--- a/.phpcs.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- .
- /.git/
- ^vendor/
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.twig_cs.dist.php b/.twig_cs.dist.php
new file mode 100644
index 00000000..6041bcf7
--- /dev/null
+++ b/.twig_cs.dist.php
@@ -0,0 +1,17 @@
+in(__DIR__ . '/templates')
+ ->name('*.html.twig')
+ ->ignoreVCSIgnored(true);
+
+return Config::create()
+ ->setFinder($finder)
+ ->setRuleSet(GlpiTwigRuleset::class)
+;
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e30aa4c0..d9bd5bc7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,9 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
-## [Unreleased]
+## [3.0.0 (Migration Only)] - 2025-30-09
-- Fix massive actions compatibility with Fields plugin
+- GLPI 11 compatibility
## [2.14.14] - 2025-04-23
diff --git a/ajax/remove.txt b/ajax/remove.txt
deleted file mode 100644
index 97732142..00000000
--- a/ajax/remove.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-Vous pouvez effacer ce fichier sans dommages.
-
-You can safely remove this file.
diff --git a/composer.json b/composer.json
index 05b653c3..ac53a7ea 100644
--- a/composer.json
+++ b/composer.json
@@ -1,19 +1,20 @@
{
"require": {
- "php": ">=7.4"
+ "php": ">=8.2"
},
"require-dev": {
- "glpi-project/phpstan-glpi": "^1.1",
- "glpi-project/tools": "^0.8.0",
- "php-parallel-lint/php-parallel-lint": "^1.4",
- "phpstan/phpstan": "^2.1",
- "squizlabs/php_codesniffer": "^3.13"
+ "glpi-project/tools": "^0.8.0"
},
"config": {
"optimize-autoloader": true,
"platform": {
- "php": "7.4.0"
+ "php": "8.2.99"
},
"sort-packages": true
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "Glpi\\Tools\\": "../../tools/src/"
+ }
}
}
diff --git a/composer.lock b/composer.lock
index 6425d1e6..67aaeadf 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,70 +4,21 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "4f3c8fd45c1590d3efd34bde0a7c463e",
+ "content-hash": "a3a3de4fba7ca124cc1e054dc3210d27",
"packages": [],
"packages-dev": [
- {
- "name": "glpi-project/phpstan-glpi",
- "version": "1.1.1",
- "source": {
- "type": "git",
- "url": "https://github.com/glpi-project/phpstan-glpi.git",
- "reference": "e98ef833abc1389a0cc69743db5b1f3a7dc8ccfe"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/glpi-project/phpstan-glpi/zipball/e98ef833abc1389a0cc69743db5b1f3a7dc8ccfe",
- "reference": "e98ef833abc1389a0cc69743db5b1f3a7dc8ccfe",
- "shasum": ""
- },
- "require": {
- "php": ">=7.4",
- "phpstan/phpstan": "^2.1",
- "symfony/polyfill-php80": "^1.32"
- },
- "require-dev": {
- "friendsofphp/php-cs-fixer": "^3.85",
- "php-parallel-lint/php-parallel-lint": "^1.4",
- "phpstan/phpstan-phpunit": "^2.0",
- "phpunit/phpunit": "^9.6"
- },
- "type": "phpstan-extension",
- "extra": {
- "phpstan": {
- "includes": [
- "extension.neon"
- ]
- }
- },
- "autoload": {
- "psr-4": {
- "PHPStanGlpi\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "PHPStan rules for GLPI.",
- "support": {
- "issues": "https://github.com/glpi-project/phpstan-glpi/issues",
- "source": "https://github.com/glpi-project/phpstan-glpi/tree/1.1.1"
- },
- "time": "2025-08-11T13:48:13+00:00"
- },
{
"name": "glpi-project/tools",
- "version": "0.8.0",
+ "version": "0.8.1",
"source": {
"type": "git",
"url": "https://github.com/glpi-project/tools.git",
- "reference": "7c2dcec105ed3427183bdfd382d785363aade436"
+ "reference": "cf182b1a6bd1a73c5c6469dbbd0edabf7cb5857e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/glpi-project/tools/zipball/7c2dcec105ed3427183bdfd382d785363aade436",
- "reference": "7c2dcec105ed3427183bdfd382d785363aade436",
+ "url": "https://api.github.com/repos/glpi-project/tools/zipball/cf182b1a6bd1a73c5c6469dbbd0edabf7cb5857e",
+ "reference": "cf182b1a6bd1a73c5c6469dbbd0edabf7cb5857e",
"shasum": ""
},
"require": {
@@ -110,145 +61,31 @@
"issues": "https://github.com/glpi-project/tools/issues",
"source": "https://github.com/glpi-project/tools"
},
- "time": "2025-08-26T10:18:38+00:00"
- },
- {
- "name": "php-parallel-lint/php-parallel-lint",
- "version": "v1.4.0",
- "source": {
- "type": "git",
- "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git",
- "reference": "6db563514f27e19595a19f45a4bf757b6401194e"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e",
- "reference": "6db563514f27e19595a19f45a4bf757b6401194e",
- "shasum": ""
- },
- "require": {
- "ext-json": "*",
- "php": ">=5.3.0"
- },
- "replace": {
- "grogy/php-parallel-lint": "*",
- "jakub-onderka/php-parallel-lint": "*"
- },
- "require-dev": {
- "nette/tester": "^1.3 || ^2.0",
- "php-parallel-lint/php-console-highlighter": "0.* || ^1.0",
- "squizlabs/php_codesniffer": "^3.6"
- },
- "suggest": {
- "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet"
- },
- "bin": [
- "parallel-lint"
- ],
- "type": "library",
- "autoload": {
- "classmap": [
- "./src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-2-Clause"
- ],
- "authors": [
- {
- "name": "Jakub Onderka",
- "email": "ahoj@jakubonderka.cz"
- }
- ],
- "description": "This tool checks the syntax of PHP files about 20x faster than serial check.",
- "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint",
- "keywords": [
- "lint",
- "static analysis"
- ],
- "support": {
- "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues",
- "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0"
- },
- "time": "2024-03-27T12:14:49+00:00"
- },
- {
- "name": "phpstan/phpstan",
- "version": "2.1.22",
- "source": {
- "type": "git",
- "url": "https://github.com/phpstan/phpstan.git",
- "reference": "41600c8379eb5aee63e9413fe9e97273e25d57e4"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/41600c8379eb5aee63e9413fe9e97273e25d57e4",
- "reference": "41600c8379eb5aee63e9413fe9e97273e25d57e4",
- "shasum": ""
- },
- "require": {
- "php": "^7.4|^8.0"
- },
- "conflict": {
- "phpstan/phpstan-shim": "*"
- },
- "bin": [
- "phpstan",
- "phpstan.phar"
- ],
- "type": "library",
- "autoload": {
- "files": [
- "bootstrap.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "PHPStan - PHP Static Analysis Tool",
- "keywords": [
- "dev",
- "static analysis"
- ],
- "support": {
- "docs": "https://phpstan.org/user-guide/getting-started",
- "forum": "https://github.com/phpstan/phpstan/discussions",
- "issues": "https://github.com/phpstan/phpstan/issues",
- "security": "https://github.com/phpstan/phpstan/security/policy",
- "source": "https://github.com/phpstan/phpstan-src"
- },
- "funding": [
- {
- "url": "https://github.com/ondrejmirtes",
- "type": "github"
- },
- {
- "url": "https://github.com/phpstan",
- "type": "github"
- }
- ],
- "time": "2025-08-04T19:17:37+00:00"
+ "time": "2025-09-08T09:45:41+00:00"
},
{
"name": "psr/container",
- "version": "1.1.2",
+ "version": "2.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
- "reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
+ "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
- "reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
+ "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963",
+ "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0.x-dev"
+ }
+ },
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
@@ -275,142 +112,53 @@
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
- "source": "https://github.com/php-fig/container/tree/1.1.2"
- },
- "time": "2021-11-05T16:50:12+00:00"
- },
- {
- "name": "squizlabs/php_codesniffer",
- "version": "3.13.2",
- "source": {
- "type": "git",
- "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git",
- "reference": "5b5e3821314f947dd040c70f7992a64eac89025c"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5b5e3821314f947dd040c70f7992a64eac89025c",
- "reference": "5b5e3821314f947dd040c70f7992a64eac89025c",
- "shasum": ""
- },
- "require": {
- "ext-simplexml": "*",
- "ext-tokenizer": "*",
- "ext-xmlwriter": "*",
- "php": ">=5.4.0"
- },
- "require-dev": {
- "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4"
- },
- "bin": [
- "bin/phpcbf",
- "bin/phpcs"
- ],
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "3.x-dev"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Greg Sherwood",
- "role": "Former lead"
- },
- {
- "name": "Juliette Reinders Folmer",
- "role": "Current lead"
- },
- {
- "name": "Contributors",
- "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors"
- }
- ],
- "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
- "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer",
- "keywords": [
- "phpcs",
- "standards",
- "static analysis"
- ],
- "support": {
- "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues",
- "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy",
- "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer",
- "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki"
+ "source": "https://github.com/php-fig/container/tree/2.0.2"
},
- "funding": [
- {
- "url": "https://github.com/PHPCSStandards",
- "type": "github"
- },
- {
- "url": "https://github.com/jrfnl",
- "type": "github"
- },
- {
- "url": "https://opencollective.com/php_codesniffer",
- "type": "open_collective"
- },
- {
- "url": "https://thanks.dev/u/gh/phpcsstandards",
- "type": "thanks_dev"
- }
- ],
- "time": "2025-06-17T22:17:01+00:00"
+ "time": "2021-11-05T16:47:00+00:00"
},
{
"name": "symfony/console",
- "version": "v5.4.47",
+ "version": "v6.4.25",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed"
+ "reference": "273fd29ff30ba0a88ca5fb83f7cf1ab69306adae"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed",
- "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed",
+ "url": "https://api.github.com/repos/symfony/console/zipball/273fd29ff30ba0a88ca5fb83f7cf1ab69306adae",
+ "reference": "273fd29ff30ba0a88ca5fb83f7cf1ab69306adae",
"shasum": ""
},
"require": {
- "php": ">=7.2.5",
- "symfony/deprecation-contracts": "^2.1|^3",
+ "php": ">=8.1",
+ "symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-mbstring": "~1.0",
- "symfony/polyfill-php73": "^1.9",
- "symfony/polyfill-php80": "^1.16",
- "symfony/service-contracts": "^1.1|^2|^3",
- "symfony/string": "^5.1|^6.0"
+ "symfony/service-contracts": "^2.5|^3",
+ "symfony/string": "^5.4|^6.0|^7.0"
},
"conflict": {
- "psr/log": ">=3",
- "symfony/dependency-injection": "<4.4",
- "symfony/dotenv": "<5.1",
- "symfony/event-dispatcher": "<4.4",
- "symfony/lock": "<4.4",
- "symfony/process": "<4.4"
+ "symfony/dependency-injection": "<5.4",
+ "symfony/dotenv": "<5.4",
+ "symfony/event-dispatcher": "<5.4",
+ "symfony/lock": "<5.4",
+ "symfony/process": "<5.4"
},
"provide": {
- "psr/log-implementation": "1.0|2.0"
+ "psr/log-implementation": "1.0|2.0|3.0"
},
"require-dev": {
- "psr/log": "^1|^2",
- "symfony/config": "^4.4|^5.0|^6.0",
- "symfony/dependency-injection": "^4.4|^5.0|^6.0",
- "symfony/event-dispatcher": "^4.4|^5.0|^6.0",
- "symfony/lock": "^4.4|^5.0|^6.0",
- "symfony/process": "^4.4|^5.0|^6.0",
- "symfony/var-dumper": "^4.4|^5.0|^6.0"
- },
- "suggest": {
- "psr/log": "For using the console logger",
- "symfony/event-dispatcher": "",
- "symfony/lock": "",
- "symfony/process": ""
+ "psr/log": "^1|^2|^3",
+ "symfony/config": "^5.4|^6.0|^7.0",
+ "symfony/dependency-injection": "^5.4|^6.0|^7.0",
+ "symfony/event-dispatcher": "^5.4|^6.0|^7.0",
+ "symfony/http-foundation": "^6.4|^7.0",
+ "symfony/http-kernel": "^6.4|^7.0",
+ "symfony/lock": "^5.4|^6.0|^7.0",
+ "symfony/messenger": "^5.4|^6.0|^7.0",
+ "symfony/process": "^5.4|^6.0|^7.0",
+ "symfony/stopwatch": "^5.4|^6.0|^7.0",
+ "symfony/var-dumper": "^5.4|^6.0|^7.0"
},
"type": "library",
"autoload": {
@@ -444,7 +192,7 @@
"terminal"
],
"support": {
- "source": "https://github.com/symfony/console/tree/v5.4.47"
+ "source": "https://github.com/symfony/console/tree/v6.4.25"
},
"funding": [
{
@@ -455,29 +203,33 @@
"url": "https://github.com/fabpot",
"type": "github"
},
+ {
+ "url": "https://github.com/nicolas-grekas",
+ "type": "github"
+ },
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
- "time": "2024-11-06T11:30:55+00:00"
+ "time": "2025-08-22T10:21:53+00:00"
},
{
"name": "symfony/deprecation-contracts",
- "version": "v2.5.4",
+ "version": "v3.6.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
- "reference": "605389f2a7e5625f273b53960dc46aeaf9c62918"
+ "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/605389f2a7e5625f273b53960dc46aeaf9c62918",
- "reference": "605389f2a7e5625f273b53960dc46aeaf9c62918",
+ "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
+ "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
"shasum": ""
},
"require": {
- "php": ">=7.1"
+ "php": ">=8.1"
},
"type": "library",
"extra": {
@@ -486,7 +238,7 @@
"name": "symfony/contracts"
},
"branch-alias": {
- "dev-main": "2.5-dev"
+ "dev-main": "3.6-dev"
}
},
"autoload": {
@@ -511,7 +263,7 @@
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.4"
+ "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
},
"funding": [
{
@@ -527,7 +279,7 @@
"type": "tidelift"
}
],
- "time": "2024-09-25T14:11:13+00:00"
+ "time": "2024-09-25T14:21:43+00:00"
},
{
"name": "symfony/polyfill-ctype",
@@ -864,275 +616,28 @@
],
"time": "2024-12-23T08:48:59+00:00"
},
- {
- "name": "symfony/polyfill-php73",
- "version": "v1.33.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/polyfill-php73.git",
- "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f68c03565dcaaf25a890667542e8bd75fe7e5bb",
- "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb",
- "shasum": ""
- },
- "require": {
- "php": ">=7.2"
- },
- "type": "library",
- "extra": {
- "thanks": {
- "url": "https://github.com/symfony/polyfill",
- "name": "symfony/polyfill"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ],
- "psr-4": {
- "Symfony\\Polyfill\\Php73\\": ""
- },
- "classmap": [
- "Resources/stubs"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Nicolas Grekas",
- "email": "p@tchwork.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions",
- "homepage": "https://symfony.com",
- "keywords": [
- "compatibility",
- "polyfill",
- "portable",
- "shim"
- ],
- "support": {
- "source": "https://github.com/symfony/polyfill-php73/tree/v1.33.0"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "https://github.com/nicolas-grekas",
- "type": "github"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
- "type": "tidelift"
- }
- ],
- "time": "2024-09-09T11:45:10+00:00"
- },
- {
- "name": "symfony/polyfill-php80",
- "version": "v1.33.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/polyfill-php80.git",
- "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608",
- "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608",
- "shasum": ""
- },
- "require": {
- "php": ">=7.2"
- },
- "type": "library",
- "extra": {
- "thanks": {
- "url": "https://github.com/symfony/polyfill",
- "name": "symfony/polyfill"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ],
- "psr-4": {
- "Symfony\\Polyfill\\Php80\\": ""
- },
- "classmap": [
- "Resources/stubs"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Ion Bazan",
- "email": "ion.bazan@gmail.com"
- },
- {
- "name": "Nicolas Grekas",
- "email": "p@tchwork.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
- "homepage": "https://symfony.com",
- "keywords": [
- "compatibility",
- "polyfill",
- "portable",
- "shim"
- ],
- "support": {
- "source": "https://github.com/symfony/polyfill-php80/tree/v1.33.0"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "https://github.com/nicolas-grekas",
- "type": "github"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
- "type": "tidelift"
- }
- ],
- "time": "2025-01-02T08:10:11+00:00"
- },
- {
- "name": "symfony/polyfill-php81",
- "version": "v1.33.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/polyfill-php81.git",
- "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c",
- "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c",
- "shasum": ""
- },
- "require": {
- "php": ">=7.2"
- },
- "type": "library",
- "extra": {
- "thanks": {
- "url": "https://github.com/symfony/polyfill",
- "name": "symfony/polyfill"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ],
- "psr-4": {
- "Symfony\\Polyfill\\Php81\\": ""
- },
- "classmap": [
- "Resources/stubs"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Nicolas Grekas",
- "email": "p@tchwork.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions",
- "homepage": "https://symfony.com",
- "keywords": [
- "compatibility",
- "polyfill",
- "portable",
- "shim"
- ],
- "support": {
- "source": "https://github.com/symfony/polyfill-php81/tree/v1.33.0"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "https://github.com/nicolas-grekas",
- "type": "github"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
- "type": "tidelift"
- }
- ],
- "time": "2024-09-09T11:45:10+00:00"
- },
{
"name": "symfony/service-contracts",
- "version": "v2.5.4",
+ "version": "v3.6.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/service-contracts.git",
- "reference": "f37b419f7aea2e9abf10abd261832cace12e3300"
+ "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f37b419f7aea2e9abf10abd261832cace12e3300",
- "reference": "f37b419f7aea2e9abf10abd261832cace12e3300",
+ "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4",
+ "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4",
"shasum": ""
},
"require": {
- "php": ">=7.2.5",
- "psr/container": "^1.1",
- "symfony/deprecation-contracts": "^2.1|^3"
+ "php": ">=8.1",
+ "psr/container": "^1.1|^2.0",
+ "symfony/deprecation-contracts": "^2.5|^3"
},
"conflict": {
"ext-psr": "<1.1|>=2"
},
- "suggest": {
- "symfony/service-implementation": ""
- },
"type": "library",
"extra": {
"thanks": {
@@ -1140,13 +645,16 @@
"name": "symfony/contracts"
},
"branch-alias": {
- "dev-main": "2.5-dev"
+ "dev-main": "3.6-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Contracts\\Service\\": ""
- }
+ },
+ "exclude-from-classmap": [
+ "/Test/"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -1173,7 +681,7 @@
"standards"
],
"support": {
- "source": "https://github.com/symfony/service-contracts/tree/v2.5.4"
+ "source": "https://github.com/symfony/service-contracts/tree/v3.6.0"
},
"funding": [
{
@@ -1189,38 +697,39 @@
"type": "tidelift"
}
],
- "time": "2024-09-25T14:11:13+00:00"
+ "time": "2025-04-25T09:37:31+00:00"
},
{
"name": "symfony/string",
- "version": "v5.4.47",
+ "version": "v7.3.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
- "reference": "136ca7d72f72b599f2631aca474a4f8e26719799"
+ "reference": "17a426cce5fd1f0901fefa9b2a490d0038fd3c9c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/string/zipball/136ca7d72f72b599f2631aca474a4f8e26719799",
- "reference": "136ca7d72f72b599f2631aca474a4f8e26719799",
+ "url": "https://api.github.com/repos/symfony/string/zipball/17a426cce5fd1f0901fefa9b2a490d0038fd3c9c",
+ "reference": "17a426cce5fd1f0901fefa9b2a490d0038fd3c9c",
"shasum": ""
},
"require": {
- "php": ">=7.2.5",
+ "php": ">=8.2",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-intl-grapheme": "~1.0",
"symfony/polyfill-intl-normalizer": "~1.0",
- "symfony/polyfill-mbstring": "~1.0",
- "symfony/polyfill-php80": "~1.15"
+ "symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
- "symfony/translation-contracts": ">=3.0"
+ "symfony/translation-contracts": "<2.5"
},
"require-dev": {
- "symfony/error-handler": "^4.4|^5.0|^6.0",
- "symfony/http-client": "^4.4|^5.0|^6.0",
- "symfony/translation-contracts": "^1.1|^2",
- "symfony/var-exporter": "^4.4|^5.0|^6.0"
+ "symfony/emoji": "^7.1",
+ "symfony/error-handler": "^6.4|^7.0",
+ "symfony/http-client": "^6.4|^7.0",
+ "symfony/intl": "^6.4|^7.0",
+ "symfony/translation-contracts": "^2.5|^3.0",
+ "symfony/var-exporter": "^6.4|^7.0"
},
"type": "library",
"autoload": {
@@ -1259,7 +768,7 @@
"utf8"
],
"support": {
- "source": "https://github.com/symfony/string/tree/v5.4.47"
+ "source": "https://github.com/symfony/string/tree/v7.3.3"
},
"funding": [
{
@@ -1270,36 +779,39 @@
"url": "https://github.com/fabpot",
"type": "github"
},
+ {
+ "url": "https://github.com/nicolas-grekas",
+ "type": "github"
+ },
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
- "time": "2024-11-10T20:33:58+00:00"
+ "time": "2025-08-25T06:35:40+00:00"
},
{
"name": "twig/twig",
- "version": "v3.11.3",
+ "version": "v3.21.1",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
- "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e"
+ "reference": "285123877d4dd97dd7c11842ac5fb7e86e60d81d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/twigphp/Twig/zipball/3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e",
- "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e",
+ "url": "https://api.github.com/repos/twigphp/Twig/zipball/285123877d4dd97dd7c11842ac5fb7e86e60d81d",
+ "reference": "285123877d4dd97dd7c11842ac5fb7e86e60d81d",
"shasum": ""
},
"require": {
- "php": ">=7.2.5",
+ "php": ">=8.1.0",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-ctype": "^1.8",
- "symfony/polyfill-mbstring": "^1.3",
- "symfony/polyfill-php80": "^1.22",
- "symfony/polyfill-php81": "^1.29"
+ "symfony/polyfill-mbstring": "^1.3"
},
"require-dev": {
+ "phpstan/phpstan": "^2.0",
"psr/container": "^1.0|^2.0",
"symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0"
},
@@ -1343,7 +855,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
- "source": "https://github.com/twigphp/Twig/tree/v3.11.3"
+ "source": "https://github.com/twigphp/Twig/tree/v3.21.1"
},
"funding": [
{
@@ -1355,7 +867,7 @@
"type": "tidelift"
}
],
- "time": "2024-11-07T12:34:41+00:00"
+ "time": "2025-05-03T07:21:55+00:00"
}
],
"aliases": [],
@@ -1364,11 +876,11 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
- "php": ">=7.4"
+ "php": ">=8.2"
},
"platform-dev": {},
"platform-overrides": {
- "php": "7.4.0"
+ "php": "8.2.99"
},
"plugin-api-version": "2.6.0"
}
diff --git a/css/styles.css b/css/styles.css
deleted file mode 100644
index 13117607..00000000
--- a/css/styles.css
+++ /dev/null
@@ -1,91 +0,0 @@
-/*!
- * -------------------------------------------------------------------------
- * GenericObject plugin for GLPI
- * -------------------------------------------------------------------------
- *
- * LICENSE
- *
- * This file is part of GenericObject.
- *
- * GenericObject 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.
- *
- * GenericObject 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 GenericObject. If not, see .
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-/*
- * Menu entry wrapper
- */
-.genericobject_menu_wrapper {
- display: block;
- position: relative;
- margin: 0;
- padding: 0;
-}
-
-/*
- * Icon positionning
- */
-.genericobject_menu_icon {
- height: 16px;
- width: 16px;
- vertical-align: middle;
- display: inline-block;
-}
-.icon_preview {
- height: 32px;
- width: 32px;
-}
-
-.icon_preview > .genericobject_menu_icon {
- display: block;
- margin: 0 auto;
- height: initial;
- width: initial;
- max-height: 32px;
- max-width: 32px;
-}
-
-.genericobject_menu_text {
- padding-left: 5px;
- margin: 0;
- display: inline-block;
-}
-
-
-/*
- * Fields Form
- */
-
-.genericobject_fields.add_new {
- width: 80%;
-}
-
-.genericobject_fields.add_new td.label {
- width: 20%;
-}
-
-.genericobject_fields.add_new td.dropdown {
- width: 100%;
-}
-
-/*
- * Type's Profile tab : specific alignment
- */
-
-.genericobject_type_profiles tr > td {
- width : 10%;
-}
diff --git a/fields/field.constant.php b/fields/field.constant.php
index ce9f489e..1560d07c 100644
--- a/fields/field.constant.php
+++ b/fields/field.constant.php
@@ -30,123 +30,123 @@
global $GO_FIELDS;
-$GO_FIELDS['id']['name'] = __("ID");
+$GO_FIELDS['id']['name'] = __s("ID");
$GO_FIELDS['id']['input_type'] = 'text';
$GO_FIELDS['id']['massiveaction'] = false;
-$GO_FIELDS['name']['name'] = __("Name");
+$GO_FIELDS['name']['name'] = __s("Name");
$GO_FIELDS['name']['field'] = 'name';
$GO_FIELDS['name']['input_type'] = 'text';
$GO_FIELDS['name']['autoname'] = true;
-$GO_FIELDS['serial']['name'] = __("Serial number");
+$GO_FIELDS['serial']['name'] = __s("Serial number");
$GO_FIELDS['serial']['field'] = 'serial';
$GO_FIELDS['serial']['input_type'] = 'text';
-$GO_FIELDS['otherserial']['name'] = __("Inventory number");
+$GO_FIELDS['otherserial']['name'] = __s("Inventory number");
$GO_FIELDS['otherserial']['field'] = 'otherserial';
$GO_FIELDS['otherserial']['input_type'] = 'text';
$GO_FIELDS['otherserial']['autoname'] = true;
-$GO_FIELDS['comment']['name'] = __("Comments");
+$GO_FIELDS['comment']['name'] = __s("Comments");
$GO_FIELDS['comment']['field'] = 'comment';
$GO_FIELDS['comment']['input_type'] = 'multitext';
-$GO_FIELDS['other']['name'] = __("Others");
+$GO_FIELDS['other']['name'] = __s("Others");
$GO_FIELDS['other']['input_type'] = 'text';
-$GO_FIELDS['creationdate']['name'] = __("Creation date");
+$GO_FIELDS['creationdate']['name'] = __s("Creation date");
$GO_FIELDS['creationdate']['input_type'] = 'date';
-$GO_FIELDS['expirationdate']['name'] = __("Expiration date");
+$GO_FIELDS['expirationdate']['name'] = __s("Expiration date");
$GO_FIELDS['expirationdate']['input_type'] = 'date';
-$GO_FIELDS['date_mod']['name'] = __("Last update");
+$GO_FIELDS['date_mod']['name'] = __s("Last update");
$GO_FIELDS['date_mod']['input_type'] = 'datetime';
-$GO_FIELDS['date_creation']['name'] = __('Creation date');
+$GO_FIELDS['date_creation']['name'] = __s('Creation date');
$GO_FIELDS['date_creation']['input_type'] = 'datetime';
-$GO_FIELDS['url']['name'] = __("URL");
+$GO_FIELDS['url']['name'] = __s("URL");
$GO_FIELDS['url']['field'] = 'url';
$GO_FIELDS['url']['input_type'] = 'text';
$GO_FIELDS['url']['datatype'] = 'weblink';
-$GO_FIELDS['types_id']['name'] = __("Type");
+$GO_FIELDS['types_id']['name'] = __s("Type");
$GO_FIELDS['types_id']['linkfield'] = 'type';
$GO_FIELDS['types_id']['input_type'] = 'dropdown';
// The 'isolated' dropdown type will create a isolated table for each type that will be assigned
// with this field.
$GO_FIELDS['types_id']['dropdown_type'] = 'isolated';
-$GO_FIELDS['models_id']['name'] = __("Model");
+$GO_FIELDS['models_id']['name'] = __s("Model");
$GO_FIELDS['models_id']['input_type'] = 'dropdown';
$GO_FIELDS['models_id']['dropdown_type'] = 'isolated';
-$GO_FIELDS['categories_id']['name'] = __("Category");
+$GO_FIELDS['categories_id']['name'] = __s("Category");
$GO_FIELDS['categories_id']['input_type'] = 'dropdown';
$GO_FIELDS['categories_id']['dropdown_type'] = 'isolated';
-$GO_FIELDS['entities_id']['name'] = __("Entity");
+$GO_FIELDS['entities_id']['name'] = __s("Entity");
$GO_FIELDS['entities_id']['input_type'] = 'dropdown';
$GO_FIELDS['entities_id']['massiveaction'] = false;
-$GO_FIELDS['template_name']['name'] = __("Template name");
+$GO_FIELDS['template_name']['name'] = __s("Template name");
$GO_FIELDS['template_name']['input_type'] = 'text';
$GO_FIELDS['template_name']['massiveaction'] = false;
-$GO_FIELDS['notepad']['name'] = _n('Note', 'Notes', 2);
+$GO_FIELDS['notepad']['name'] = _sn('Note', 'Notes', 2);
$GO_FIELDS['notepad']['input_type'] = 'multitext';
-$GO_FIELDS['is_recursive']['name'] = __("Child entities");
+$GO_FIELDS['is_recursive']['name'] = __s("Child entities");
$GO_FIELDS['is_recursive']['input_type'] = 'bool';
-$GO_FIELDS['is_deleted']['name'] = __("Item in the dustbin");
+$GO_FIELDS['is_deleted']['name'] = __s("Item in the dustbin");
$GO_FIELDS['is_deleted']['input_type'] = 'bool';
$GO_FIELDS['is_deleted']['massiveaction'] = false;
-$GO_FIELDS['is_template']['name'] = __("Templates");
+$GO_FIELDS['is_template']['name'] = __s("Templates");
$GO_FIELDS['is_template']['input_type'] = 'bool';
$GO_FIELDS['is_template']['massiveaction'] = false;
-$GO_FIELDS['is_global']['name'] = __("Management type");
+$GO_FIELDS['is_global']['name'] = __s("Management type");
$GO_FIELDS['is_global']['input_type'] = 'bool';
$GO_FIELDS['is_global']['massiveaction'] = false;
-$GO_FIELDS['is_helpdesk_visible']['name'] = __("Associable to a ticket");
+$GO_FIELDS['is_helpdesk_visible']['name'] = __s("Associable to a ticket");
$GO_FIELDS['is_helpdesk_visible']['input_type'] = 'bool';
-$GO_FIELDS['ticket_tco']['name'] = __("TCO");
+$GO_FIELDS['ticket_tco']['name'] = __s("TCO");
$GO_FIELDS['ticket_tco']['input_type'] = 'decimal';
-$GO_FIELDS['locations_id']['name'] = __("Item location");
+$GO_FIELDS['locations_id']['name'] = __s("Item location");
$GO_FIELDS['locations_id']['input_type'] = 'dropdown';
-$GO_FIELDS['states_id']['name'] = __("Status");
+$GO_FIELDS['states_id']['name'] = __s("Status");
$GO_FIELDS['states_id']['input_type'] = 'dropdown';
-$GO_FIELDS['users_id']['name'] = __("User");
+$GO_FIELDS['users_id']['name'] = __s("User");
$GO_FIELDS['users_id']['input_type'] = 'dropdown';
-$GO_FIELDS['groups_id']['name'] = __("Group");
+$GO_FIELDS['groups_id']['name'] = __s("Group");
$GO_FIELDS['groups_id']['input_type'] = 'dropdown';
$GO_FIELDS['groups_id']['condition'] = ['is_itemgroup' => 1];
-$GO_FIELDS['manufacturers_id']['name'] = __("Manufacturer");
+$GO_FIELDS['manufacturers_id']['name'] = __s("Manufacturer");
$GO_FIELDS['manufacturers_id']['input_type'] = 'dropdown';
-$GO_FIELDS['users_id_tech']['name'] = __("Technician in charge");
+$GO_FIELDS['users_id_tech']['name'] = __s("Technician in charge");
$GO_FIELDS['users_id_tech']['input_type'] = 'dropdown';
-$GO_FIELDS['domains_id']['name'] = __("Domain");
+$GO_FIELDS['domains_id']['name'] = __s("Domain");
$GO_FIELDS['domains_id']['input_type'] = 'dropdown';
-$GO_FIELDS['contact']['name'] = __("Alternate username");
+$GO_FIELDS['contact']['name'] = __s("Alternate username");
$GO_FIELDS['contact']['input_type'] = 'text';
-$GO_FIELDS['contact_num']['name'] = __("Alternate username number");
+$GO_FIELDS['contact_num']['name'] = __s("Alternate username number");
$GO_FIELDS['contact_num']['input_type'] = 'text';
-$GO_FIELDS['groups_id_tech']['name'] = __("Group in charge");
+$GO_FIELDS['groups_id_tech']['name'] = __s("Group in charge");
$GO_FIELDS['groups_id_tech']['input_type'] = 'dropdown';
$GO_FIELDS['groups_id_tech']['condition'] = ['is_assign' => 1];
diff --git a/front/commondropdown.form.php b/front/commondropdown.form.php
deleted file mode 100644
index 11c7cc1a..00000000
--- a/front/commondropdown.form.php
+++ /dev/null
@@ -1,43 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-if (isset($_REQUEST['itemtype'])) {
- $itemtype = $_REQUEST['itemtype'];
- if (class_exists($itemtype)) {
- $dropdown = new $itemtype();
- include(GLPI_ROOT . "/front/dropdown.common.form.php");
- } else {
- Html::displayErrorAndDie(__('The requested dropdown does not exists', 'genericobject'));
- }
-} else {
- Html::displayErrorAndDie(__('Not Found!'));
-}
diff --git a/front/commondropdown.php b/front/commondropdown.php
deleted file mode 100644
index 3597003e..00000000
--- a/front/commondropdown.php
+++ /dev/null
@@ -1,43 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-if (isset($_REQUEST['itemtype'])) {
- $itemtype = $_REQUEST['itemtype'];
- if (class_exists($itemtype)) {
- $dropdown = new $itemtype();
- include(GLPI_ROOT . "/front/dropdown.common.php");
- } else {
- Html::displayErrorAndDie(__('The requested dropdown does not exists', 'genericobject'));
- }
-} else {
- Html::displayErrorAndDie(__('Not Found!'));
-}
diff --git a/front/commontreedropdown.form.php b/front/commontreedropdown.form.php
deleted file mode 100644
index 11c7cc1a..00000000
--- a/front/commontreedropdown.form.php
+++ /dev/null
@@ -1,43 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-if (isset($_REQUEST['itemtype'])) {
- $itemtype = $_REQUEST['itemtype'];
- if (class_exists($itemtype)) {
- $dropdown = new $itemtype();
- include(GLPI_ROOT . "/front/dropdown.common.form.php");
- } else {
- Html::displayErrorAndDie(__('The requested dropdown does not exists', 'genericobject'));
- }
-} else {
- Html::displayErrorAndDie(__('Not Found!'));
-}
diff --git a/front/commontreedropdown.php b/front/commontreedropdown.php
deleted file mode 100644
index da2d6ff5..00000000
--- a/front/commontreedropdown.php
+++ /dev/null
@@ -1,32 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-include("./commondropdown.php");
diff --git a/front/typefamily.form.php b/front/eol_info.php
similarity index 77%
rename from front/typefamily.form.php
rename to front/eol_info.php
index 3a94c818..291a4f74 100644
--- a/front/typefamily.form.php
+++ b/front/eol_info.php
@@ -28,7 +28,20 @@
* -------------------------------------------------------------------------
*/
-include("../../../inc/includes.php");
+// Check if user has admin rights
+Session::checkRight('config', READ);
-$dropdown = new PluginGenericobjectTypeFamily();
-include(GLPI_ROOT . "/front/dropdown.common.form.php");
+/** @var array $CFG_GLPI */
+global $CFG_GLPI;
+
+Html::header(
+ __s('Genericobject End of Life Information', 'genericobject'),
+ $_SERVER['PHP_SELF'],
+ 'tools',
+ 'PluginGenericobjectEOLInfo',
+);
+
+$eolInfo = new PluginGenericobjectEOLInfo();
+$eolInfo->showForm();
+
+Html::footer();
diff --git a/front/familylist.php b/front/familylist.php
deleted file mode 100644
index 3880052a..00000000
--- a/front/familylist.php
+++ /dev/null
@@ -1,70 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include('../../../inc/includes.php');
-
-$family = new PluginGenericobjectTypeFamily();
-
-if (!isset($_GET['id']) || !$family->getFromDB($_GET['id'])) {
- Html::header(
- __("Objects management", "genericobject"),
- $_SERVER['PHP_SELF'],
- "assets",
- "genericobject"
- );
-
- echo "
";
- echo "| " . __("Empty family", "genericobject") . " |
";
- echo "
";
-} else {
- $family->getFromDB($_GET['id']);
- Html::header(
- __("Objects management", "genericobject"),
- $_SERVER['PHP_SELF'],
- "assets",
- $family->getName()
- );
-
- echo "";
- $types = PluginGenericobjectTypeFamily::getItemtypesByFamily($_GET['id']);
- echo "| " . Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $_GET['id']) . " |
";
- foreach ($types as $type) {
- $itemtype = $type['itemtype'];
- if (Session::haveRight(PluginGenericobjectProfile::getProfileNameForItemtype($itemtype), READ)) {
- echo "| ";
- echo "";
- echo $itemtype::getTypeName();
- echo " |
";
- }
- }
- echo "
";
-}
-
-Html::footer();
diff --git a/front/field.form.php b/front/field.form.php
deleted file mode 100644
index 0c2f26d2..00000000
--- a/front/field.form.php
+++ /dev/null
@@ -1,63 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-if (isset($_POST["delete"])) {
- if (isset($_POST["fields"]) && count($_POST["fields"]) > 0) {
- $type = new PluginGenericobjectType();
- $type->getFromDB($_POST["id"]);
- $itemtype = $type->fields['itemtype'];
- PluginGenericobjectType::registerOneType($itemtype);
-
- foreach ($_POST["fields"] as $field => $value) {
- if (
- $type->can($_POST["id"], PURGE)
- && $value == 1
- && PluginGenericobjectField::checkNecessaryFieldsDelete($itemtype, $field)
- ) {
- PluginGenericobjectField::deleteField(getTableForItemType($itemtype), $field);
- Session::addMessageAfterRedirect(__("Field(s) deleted successfully", "genericobject"), true, INFO);
- }
- }
- }
-} else if (isset($_POST["add_field"])) {
- $type = new PluginGenericobjectType();
- if ($_POST["new_field"] && $type->can($_POST["id"], UPDATE)) {
- $itemtype = $type->fields['itemtype'];
- PluginGenericobjectType::registerOneType($itemtype);
- PluginGenericobjectField::addNewField(getTableForItemType($itemtype), $_POST["new_field"]);
- Session::addMessageAfterRedirect(__("Field added successfully", "genericobject"));
- }
-} else if (isset($_POST['action'])) {
- //Move field
- PluginGenericobjectField::changeFieldOrder($_POST);
-}
-
-Html::back();
diff --git a/front/getimpacticon.php b/front/getimpacticon.php
deleted file mode 100644
index 6efe10e1..00000000
--- a/front/getimpacticon.php
+++ /dev/null
@@ -1,65 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-// Read itemtype
-$itemtype = $_GET['itemtype'] ?? null;
-
-// Missing required parameter
-if (empty($itemtype)) {
- http_response_code(400);
- die;
-}
-
-// Find by itemtype
-$type = new PluginGenericobjectType();
-if (!$type->getFromDBByCrit(['itemtype' => $itemtype])) {
- http_response_code(400);
- die;
-}
-
-// Get filepath
-$filepath = $type->getImpactIconFilePath();
-if ($filepath === null) {
- http_response_code(404);
- die;
-}
-
-// Validate image
-if (!Document::isImage($filepath)) {
- http_response_code(400);
- die;
-}
-
-// Send image
-header("Content-Type: " . mime_content_type($filepath));
-readfile($filepath);
-die;
diff --git a/front/migration_status.php b/front/migration_status.php
new file mode 100644
index 00000000..0b472ab1
--- /dev/null
+++ b/front/migration_status.php
@@ -0,0 +1,78 @@
+.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/genericobject
+ * -------------------------------------------------------------------------
+ */
+
+use Glpi\Application\View\TemplateRenderer;
+use Glpi\Asset\AssetDefinition;
+
+// Check if user has admin rights
+Session::checkRight('config', UPDATE);
+
+/** @var DBmysql $DB */
+global $DB;
+
+// Get all GenericObject types
+$genericobject_types = [];
+if ($DB->tableExists(PluginGenericobjectType::getTable())) {
+ $query = [
+ 'SELECT' => ['itemtype', 'name'],
+ 'FROM' => PluginGenericobjectType::getTable(),
+ ];
+ $request = $DB->request($query);
+ foreach ($request as $data) {
+ $genericobject_types[$data['name']] = $data;
+ }
+}
+
+// Get all custom asset definitions
+$customassets = [];
+if ($DB->tableExists(AssetDefinition::getTable())) {
+ $query = [
+ 'SELECT' => ['id', 'system_name', 'label', 'icon'],
+ 'FROM' => AssetDefinition::getTable(),
+ ];
+ $request = $DB->request($query);
+ foreach ($request as $data) {
+ // If genericobject asset is migrated to native custom asset, count linked items
+ $customassets[$data['system_name']] = $data;
+ $customassets[$data['system_name']]['items'] = countElementsInTable('glpi_assets_assets', ['assets_assetdefinitions_id' => $data['id']]);
+ }
+}
+
+// Display GLPI header
+Html::header(__s('GenericObject Migration Status', 'genericobject'), '', "tools", "migration");
+
+// Render the template content
+TemplateRenderer::getInstance()->display('@genericobject/migration_status.html.twig', [
+ 'genericobject_types' => $genericobject_types,
+ 'customassets' => $customassets,
+]);
+
+// Display GLPI footer
+Html::footer();
diff --git a/front/object.form.php b/front/object.form.php
deleted file mode 100644
index f3cad980..00000000
--- a/front/object.form.php
+++ /dev/null
@@ -1,113 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-$itemtype = null;
-
-if (isset($_REQUEST['itemtype'])) {
- $types = array_keys(PluginGenericobjectType::getTypes());
-
- $requested_type = $_REQUEST['itemtype'];
- $error = [];
-
- if (!in_array($requested_type, $types)) {
- $error[] = __('The requested type has not been defined yet!');
- if (!PluginGenericobjectType::canCreate()) {
- $error[] = __('Please ask your administrator to create this type of object');
- };
- } else if (!class_exists($requested_type)) {
- $error[] = __('The generated files for the requested type of object are missing!');
- $error[] = __('You might need to regenerate the files under ' . GENERICOBJECT_DOC_DIR . '.');
- }
-
- if (count($error) > 0) {
- Html::header(__('Type not found!'));
- Html::displayErrorAndDie(implode('
', $error));
- } else {
- $itemtype = $requested_type;
- }
-}
-
-if (!is_null($itemtype)) {
- if (!isset($_REQUEST['id'])) {
- $id = -1;
- } else {
- $id = $_REQUEST['id'];
- }
-
- if (!isset($_GET["withtemplate"])) {
- $_GET["withtemplate"] = "";
- }
-
- $item = new $itemtype();
-
- if (isset($_POST["add"])) {
- $item->check($id, CREATE);
- $newID = $item->add($_POST);
-
- if ($_SESSION['glpibackcreated']) {
- Html::redirect($itemtype::getFormURL() . "&id=" . $newID);
- } else {
- Html::back();
- }
- } else if (isset($_POST["update"])) {
- $item->check($id, UPDATE);
- $item->update($_POST);
- Html::back();
- } else if (isset($_POST["restore"])) {
- $item->check($id, DELETE);
- $item->restore($_POST);
- Html::back();
- } else if (isset($_POST["purge"])) {
- $item->check($id, PURGE);
- $item->delete($_POST, 1);
- $item->redirectToList();
- } else if (isset($_POST["delete"])) {
- $item->check($id, DELETE);
- $item->delete($_POST);
- $item->redirectToList();
- }
- $menu = PluginGenericobjectType::getFamilyNameByItemtype($_GET['itemtype']);
- Html::header(
- $itemtype::getTypeName(),
- $_SERVER['PHP_SELF'],
- "assets",
- ($menu !== false ? $menu : $itemtype),
- strtolower($itemtype)
- );
-
- $item->display($_GET, ['withtemplate' => $_GET["withtemplate"]]);
-
- Html::footer();
-} else {
- Html::header(__('Access Denied!'));
- Html::DisplayErrorAndDie(__("You can't access to this page directly!"));
-}
diff --git a/front/object.php b/front/object.php
deleted file mode 100644
index de023a91..00000000
--- a/front/object.php
+++ /dev/null
@@ -1,46 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-if (isset($_GET['itemtype'])) {
- Session::checkRight(PluginGenericobjectProfile::getProfileNameForItemtype($_GET['itemtype']), READ);
- $menu = PluginGenericobjectType::getFamilyNameByItemtype($_GET['itemtype']);
- Html::header(
- __("Type of objects", "genericobject"),
- $_SERVER['PHP_SELF'],
- "assets",
- ($menu !== false ? $menu : strtolower($_GET['itemtype'])),
- strtolower($_GET['itemtype'])
- );
- Search::Show($_GET['itemtype']);
-}
-
-Html::footer();
diff --git a/front/profile.form.php b/front/profile.form.php
deleted file mode 100644
index 9d6fdc25..00000000
--- a/front/profile.form.php
+++ /dev/null
@@ -1,54 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-Session::checkRight("profile", UPDATE);
-
-_log($_POST);
-$prof = new Profile();
-
-/* save profile */
-if (isset($_POST['update_all_rights']) && isset($_POST['itemtype'])) {
- $profiles = [];
- foreach ($_POST as $key => $val) {
- if (preg_match("/^profile_/", $key)) {
- $id = preg_replace("/^profile_/", "", $key);
- $profiles[$id] = [
- "id" => $id,
- "_" . PluginGenericobjectProfile::getProfileNameForItemtype($_POST['itemtype']) => $val
- ];
- }
- }
- _log($profiles);
- foreach ($profiles as $profile_id => $input) {
- $prof->update($input);
- }
-}
-Html::redirect($_SERVER['HTTP_REFERER']);
diff --git a/front/type.form.php b/front/type.form.php
deleted file mode 100644
index 8df873df..00000000
--- a/front/type.form.php
+++ /dev/null
@@ -1,76 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-if (!isset($_GET["id"])) {
- $_GET["id"] = '';
-}
-$type = new PluginGenericobjectType();
-$extraparams = [];
-if (isset($_POST["select"]) && $_POST["select"] == "all") {
- $extraparams["selected"] = "checked";
-}
-
-if (isset($_POST["add"])) {
- //Add a new itemtype
- $new_id = $type->add($_POST);
- Html::redirect(Toolbox::getItemTypeFormURL('PluginGenericobjectType') . "?id=$new_id");
-} else if (isset($_POST["update"])) {
- //Update an existing itemtype
- if (isset($_POST['itemtypes']) && is_array($_POST['itemtypes'])) {
- $_POST['linked_itemtypes'] = json_encode($_POST['itemtypes']);
- }
- $type->update($_POST);
- Html::back();
-} else if (isset($_POST["purge"])) {
- //Delete an itemtype
- $type->delete($_POST);
- $type->redirectToList();
-} else if (isset($_POST['regenerate'])) {
- //Regenerate files for an itemtype
- $type->getFromDB($_POST["id"]);
- PluginGenericobjectType::checkClassAndFilesForOneItemType(
- $type->fields['itemtype'],
- $type->fields['name'],
- true
- );
- Html::back();
-}
-
-Html::header(
- __("Objects management", "genericobject"),
- $_SERVER['PHP_SELF'],
- "config",
- "PluginGenericobjectType"
-);
-$type->display($_GET);
-
-Html::footer();
diff --git a/front/type.php b/front/type.php
deleted file mode 100644
index 74c4b6a0..00000000
--- a/front/type.php
+++ /dev/null
@@ -1,54 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-if (
- isset($_GET['itemtype'])
- && !isset($_GET['search'])
- && !isset($_GET['sort'])
-) {
- $type = new PluginGenericobjectType();
- $type->getFromDBByType($_GET['itemtype']);
- Html::redirect(Toolbox::getItemTypeFormURL('PluginGenericobjectType') . '?id=' . $type->getID());
-} else if (Session::haveRightsOr('plugin_genericobject_types', [READ, CREATE, UPDATE, PURGE])) {
- Html::header(
- __("Type of objects", "genericobject"),
- $_SERVER['PHP_SELF'],
- "config",
- "PluginGenericobjectType"
- );
- Search::Show('PluginGenericobjectType');
- Html::footer();
-} else {
- /** @var array $CFG_GLPI */
- global $CFG_GLPI;
- Html::redirect($CFG_GLPI['root_doc'] . "/front/central.php");
-}
diff --git a/front/typefamily.php b/front/typefamily.php
deleted file mode 100644
index 51bd93bc..00000000
--- a/front/typefamily.php
+++ /dev/null
@@ -1,34 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-include("../../../inc/includes.php");
-
-$dropdown = new PluginGenericobjectTypeFamily();
-include(GLPI_ROOT . "/front/dropdown.common.php");
diff --git a/hook.php b/hook.php
index 4ead38bf..90a3b519 100644
--- a/hook.php
+++ b/hook.php
@@ -28,54 +28,6 @@
* -------------------------------------------------------------------------
*/
-function plugin_genericobject_AssignToTicket($types)
-{
- foreach (PluginGenericobjectType::getTypes() as $tmp => $value) {
- $itemtype = $value['itemtype'];
- if ($value['use_tickets']) {
- if (class_exists($itemtype)) {
- $types[$itemtype] = $itemtype::getTypeName();
- } else {
- $types[$itemtype] = $itemtype;
- }
- }
- }
- return $types;
-}
-
-// Define Dropdown tables to be manage in GLPI :
-function plugin_genericobject_getDropdown()
-{
-
- $dropdowns = ['PluginGenericobjectTypeFamily' => PluginGenericobjectTypeFamily::getTypeName(2)];
-
- $plugin = new Plugin();
- if ($plugin->isActivated("genericobject")) {
- foreach (PluginGenericobjectType::getTypes() as $type) {
- //_log($idx, var_export($type, true));
- $itemtype = $type['itemtype'];
- PluginGenericobjectType::registerOneType($itemtype);
- foreach (PluginGenericobjectType::getDropdownForItemtype($itemtype) as $table) {
- $dropdown_itemtype = getItemTypeForTable($table);
- if (class_exists($dropdown_itemtype)) {
- $dropdowns[$dropdown_itemtype] = $dropdown_itemtype::getTypeName();
- }
- }
- }
- }
- return $dropdowns;
-}
-
-function plugin_uninstall_addUninstallTypes($uninstal_types = [])
-{
- foreach (PluginGenericobjectType::getTypes() as $tmp => $type) {
- if ($type["use_plugin_uninstall"]) {
- $uninstal_types[] = $type["itemtype"];
- }
- }
- return $uninstal_types;
-}
-
//----------------------- INSTALL / UNINSTALL FUNCTION -------------------------------//
/**
@@ -93,11 +45,9 @@ function plugin_genericobject_install()
foreach (
[
'PluginGenericobjectField',
- 'PluginGenericobjectCommonDropdown',
- 'PluginGenericobjectCommonTreeDropdown',
'PluginGenericobjectProfile',
'PluginGenericobjectType',
- 'PluginGenericobjectTypeFamily'
+ 'PluginGenericobjectTypeFamily',
] as $itemtype
) {
if ($plug = isPluginItemType($itemtype)) {
@@ -113,22 +63,15 @@ function plugin_genericobject_install()
}
}
- if (!is_dir(GENERICOBJECT_CLASS_PATH)) {
- @ mkdir(GENERICOBJECT_CLASS_PATH, 0755, true)
- or die("Can't create folder " . GENERICOBJECT_CLASS_PATH);
- }
-
- // Add icon directory
+ // Add icon directory
$icons_dir = GLPI_PLUGIN_DOC_DIR . '/genericobject/impact_icons/';
if (!is_dir($icons_dir)) {
mkdir($icons_dir);
}
- //Init plugin & types
+ //Init plugin
plugin_init_genericobject();
- //Init profiles
- PluginGenericobjectProfile::changeProfile();
return true;
}
@@ -145,7 +88,7 @@ function plugin_genericobject_uninstall()
include_once(GENERICOBJECT_DIR . "/inc/object.class.php");
include_once(GENERICOBJECT_DIR . "/inc/type.class.php");
- //For each type
+ //For each type
foreach (PluginGenericobjectType::getTypes(true) as $tmp => $value) {
$itemtype = $value['itemtype'];
if (class_exists($itemtype)) {
@@ -158,7 +101,7 @@ function plugin_genericobject_uninstall()
'PluginGenericobjectType',
'PluginGenericobjectProfile',
'PluginGenericobjectField',
- 'PluginGenericobjectTypeFamily'
+ 'PluginGenericobjectTypeFamily',
] as $itemtype
) {
if ($plug = isPluginItemType($itemtype)) {
@@ -172,66 +115,16 @@ function plugin_genericobject_uninstall()
}
}
- // Delete all models of datainjection about genericobject
+ // Delete all models of datainjection about genericobject
$table_datainjection_model = 'glpi_plugin_datainjection_models';
if ($DB->tableExists($table_datainjection_model)) {
- $DB->query("DELETE FROM $table_datainjection_model WHERE itemtype LIKE 'PluginGenericobject%'");
+ $DB->delete($table_datainjection_model, [
+ 'itemtype' => ['LIKE', 'PluginGenericobject%'],
+ ]);
}
- // Invalidate menu data in current session
+ // Invalidate menu data in current session
unset($_SESSION['glpimenu']);
return true;
}
-
-function plugin_datainjection_populate_genericobject()
-{
- /** @var array $INJECTABLE_TYPES */
- global $INJECTABLE_TYPES;
- $type = new PluginGenericobjectType();
- foreach ($type->find(['use_plugin_datainjection' => 1, 'is_active' => 1]) as $data) {
- if (class_exists($data ['itemtype'] . "Injection")) {
- $INJECTABLE_TYPES[$data ['itemtype'] . "Injection"] = 'genericobject';
- }
- }
-}
-
-function plugin_genericobject_MassiveActions($type)
-{
- $types = PluginGenericobjectType::getTypes();
- if (isset($types[$type])) {
- $objecttype = PluginGenericobjectType::getInstance($type);
- if ($objecttype->isTransferable()) {
- return ['PluginGenericobjectObject' .
- MassiveAction::CLASS_ACTION_SEPARATOR . 'plugin_genericobject_transfer' => __("Transfer")
- ];
- } else {
- return [];
- }
- } else {
- return [];
- }
-}
-
-function plugin_genericobject_MassiveActionsFieldsDisplay($options = [])
-{
- if (!Plugin::isPluginActive('fields')) {
- return false;
- }
-
- if (!class_exists('PluginFieldsContainer') || !method_exists('PluginFieldsContainer', 'getEntries')) {
- return false;
- }
-
- if (!class_exists('PluginFieldsField') || !method_exists('PluginFieldsField', 'showSingle')) {
- return false;
- }
-
- $itemtypes = PluginFieldsContainer::getEntries('all');
-
- if (in_array($options['itemtype'], $itemtypes)) {
- return PluginFieldsField::showSingle($options['itemtype'], $options['options'], true);
- }
-
- return false;
-}
diff --git a/inc/autoload.php b/inc/autoload.php
index f3627944..6f7d7662 100644
--- a/inc/autoload.php
+++ b/inc/autoload.php
@@ -41,8 +41,8 @@ public function __construct($options = null)
public function setOptions($options)
{
- if (!is_array($options) && !($options instanceof \Traversable)) {
- throw new \InvalidArgumentException();
+ if (!is_array($options) && !($options instanceof Traversable)) {
+ throw new InvalidArgumentException();
}
foreach ($options as $path) {
@@ -79,11 +79,11 @@ public function autoload($classname)
$filename = implode(".", [
$class_name,
"class",
- "php"
+ "php",
]);
foreach ($this->paths as $path) {
- $test = $path . DIRECTORY_SEPARATOR . $filename;
+ $test = $path . DIRECTORY_SEPARATOR . $filename;
if (file_exists($test)) {
return include_once($test);
}
diff --git a/inc/commondropdown.class.php b/inc/commondropdown.class.php
index 0baeaa1f..ce6a68d6 100644
--- a/inc/commondropdown.class.php
+++ b/inc/commondropdown.class.php
@@ -33,19 +33,19 @@ class PluginGenericobjectCommonDropdown extends CommonDropdown
//Get itemtype name
public static function getTypeName($nb = 0)
{
- $class = get_called_class();
+ $class = static::class;
return dropdown_getTypeName($class, $nb);
}
public static function getFormURL($full = true)
{
- return Toolbox::getItemTypeFormURL(get_parent_class(get_called_class()), $full) .
- "?itemtype=" . get_called_class();
+ return Toolbox::getItemTypeFormURL(get_parent_class(static::class), $full) .
+ "?itemtype=" . static::class;
}
public static function getSearchURL($full = true)
{
- return Toolbox::getItemTypeSearchURL(get_parent_class(get_called_class()), $full) .
- "?itemtype=" . get_called_class();
+ return Toolbox::getItemTypeSearchURL(get_parent_class(static::class), $full) .
+ "?itemtype=" . static::class;
}
}
diff --git a/inc/commontreedropdown.class.php b/inc/commontreedropdown.class.php
index e5432ed4..3b8ed576 100644
--- a/inc/commontreedropdown.class.php
+++ b/inc/commontreedropdown.class.php
@@ -33,21 +33,21 @@ class PluginGenericobjectCommonTreeDropdown extends CommonTreeDropdown
//Get itemtype name
public static function getTypeName($nb = 0)
{
- $class = get_called_class();
+ $class = static::class;
return dropdown_getTypeName($class, $nb);
}
public static function getFormURL($full = true)
{
- _log("PluginGenericobjectCommonTreeDropdown::getFormURL", get_parent_class(get_called_class()));
- return Toolbox::getItemTypeFormURL(get_parent_class(get_called_class()), $full) .
- "?itemtype=" . get_called_class();
+ _log("PluginGenericobjectCommonTreeDropdown::getFormURL", get_parent_class(static::class));
+ return Toolbox::getItemTypeFormURL(get_parent_class(static::class), $full) .
+ "?itemtype=" . static::class;
}
public static function getSearchURL($full = true)
{
- _log("PluginGenericobjectCommonTreeDropdown::getSearchURL", get_parent_class(get_called_class()));
- return Toolbox::getItemTypeSearchURL(get_parent_class(get_called_class()), $full) .
- "?itemtype=" . get_called_class();
+ _log("PluginGenericobjectCommonTreeDropdown::getSearchURL", get_parent_class(static::class));
+ return Toolbox::getItemTypeSearchURL(get_parent_class(static::class), $full) .
+ "?itemtype=" . static::class;
}
}
diff --git a/inc/eolinfo.class.php b/inc/eolinfo.class.php
new file mode 100644
index 00000000..3029d7c2
--- /dev/null
+++ b/inc/eolinfo.class.php
@@ -0,0 +1,127 @@
+.
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
+ * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
+ * @link https://github.com/pluginsGLPI/genericobject
+ * -------------------------------------------------------------------------
+ */
+
+use Glpi\Application\View\TemplateRenderer;
+
+/**
+ * Class to display End of Life information for GenericObject
+ */
+class PluginGenericobjectEOLInfo extends CommonGLPI
+{
+ public static $rightname = 'config';
+
+ /**
+ * Get menu name
+ *
+ * @return string
+ */
+ public static function getMenuName()
+ {
+ return __s('GenericObject EOL Info', 'genericobject');
+ }
+
+ /**
+ * Get menu content
+ *
+ * @return array
+ */
+ public static function getMenuContent()
+ {
+ $menu = [];
+
+ if (static::canView()) {
+ $menu['title'] = static::getMenuName();
+ $menu['page'] = '/plugins/genericobject/front/eol_info.php';
+ $menu['icon'] = 'ti ti-alert-triangle';
+ $menu['links']['search'] = '/plugins/genericobject/front/eol_info.php';
+ }
+
+ return $menu;
+ }
+
+ /**
+ * Check if user can view EOL info
+ *
+ * @return bool
+ */
+ public static function canView(): bool
+ {
+ return Session::haveRight('config', READ);
+ }
+
+ /**
+ * Get type name
+ *
+ * @param int $nb
+ * @return string
+ */
+ public static function getTypeName($nb = 0)
+ {
+ return __s('GenericObject End of Life Information', 'genericobject');
+ }
+
+ /**
+ * Show EOL information form using Twig template
+ *
+ * @return void
+ */
+ public function showForm()
+ {
+ /** @var array $CFG_GLPI */
+ global $CFG_GLPI;
+
+ TemplateRenderer::getInstance()->display('@genericobject/eol_info.html.twig', [
+ 'plugin_version' => PLUGIN_GENERICOBJECT_VERSION,
+ 'plugin_web_dir' => $CFG_GLPI['root_doc'] . '/plugins/genericobject',
+ ]);
+ }
+
+ /**
+ * Display EOL warning on central dashboard using Twig template
+ *
+ * @return void
+ */
+ public static function displayCentralEOLWarning()
+ {
+ /** @var array $CFG_GLPI */
+ global $CFG_GLPI;
+
+ if (!static::canView()) {
+ return;
+ }
+
+ $_SESSION['formcreator_eol_central_shown'] = true;
+
+ TemplateRenderer::getInstance()->display('@genericobject/central_eol_warning.html.twig', [
+ 'plugin_version' => PLUGIN_GENERICOBJECT_VERSION,
+ 'root_doc' => $CFG_GLPI['root_doc'],
+ ]);
+ }
+}
diff --git a/inc/field.class.php b/inc/field.class.php
index 53cfd578..c3d635b9 100644
--- a/inc/field.class.php
+++ b/inc/field.class.php
@@ -30,170 +30,21 @@
class PluginGenericobjectField extends CommonDBTM
{
- /**
- *
- * Displat all fields present in DB for an itemtype
- * @param $id the itemtype's id
- */
- public static function showObjectFieldsForm($id)
- {
- /**
- * @var array $GO_BLACKLIST_FIELDS
- * @var array $GO_READONLY_FIELDS
- * @var array $GO_FIELDS
- */
- global $GO_BLACKLIST_FIELDS, $GO_READONLY_FIELDS, $GO_FIELDS;
-
- $url = Toolbox::getItemTypeFormURL(__CLASS__);
- $object_type = new PluginGenericobjectType();
- $object_type->getFromDB($id);
- $itemtype = $object_type->fields['itemtype'];
- $fields_in_db = PluginGenericobjectSingletonObjectField::getInstance($itemtype);
- $used_fields = [];
-
- //Reset fields definition only to keep the itemtype ones
- $GO_FIELDS = [];
- plugin_genericobject_includeCommonFields(true);
-
- PluginGenericobjectType::includeLocales($object_type->fields['name']);
- PluginGenericobjectType::includeConstants($object_type->fields['name'], true);
-
- self::addReadOnlyFields($object_type);
-
- foreach ($GO_BLACKLIST_FIELDS as $autofield) {
- if (!in_array($autofield, $used_fields)) {
- $used_fields[$autofield] = $autofield;
- }
- }
-
- echo "";
- }
-
- /**
- * Method to set fields as read only, when the depend on some features
- * that are enabled
- * @since 0.85+2.4.0
- */
- public static function addReadOnlyFields(PluginGenericobjectType $type)
- {
- /** @var array $GO_READONLY_FIELDS */
- global $GO_READONLY_FIELDS;
-
- if ($type->canBeReserved()) {
- $GO_READONLY_FIELDS[] = 'users_id';
- $GO_READONLY_FIELDS[] = 'locations_id';
- }
-
- if ($type->canUseGlobalSearch()) {
- $GO_READONLY_FIELDS[] = 'serial';
- $GO_READONLY_FIELDS[] = 'otherserial';
- $GO_READONLY_FIELDS[] = 'locations_id';
- $GO_READONLY_FIELDS[] = 'states_id';
- $GO_READONLY_FIELDS[] = 'users_id';
- $GO_READONLY_FIELDS[] = 'groups_id';
- $GO_READONLY_FIELDS[] = 'manufacturers_id';
- $GO_READONLY_FIELDS[] = 'users_id_tech';
- }
-
- if ($type->canUseItemDevice()) {
- $GO_READONLY_FIELDS[] = 'locations_id';
- }
- }
- /**
- * Get the name of the field, as defined in a constant file
- * The name may be the same, or not depending if it's an isolated dropdown or not
- */
+ /**
+ * Get the name of the field, as defined in a constant file
+ * The name may be the same, or not depending if it's an isolated dropdown or not
+ */
public static function getFieldName($field, $itemtype, $options, $remove_prefix = false)
{
/** @var DBmysql $DB */
global $DB;
- $field_orig = $field;
$field_table = null;
- $input_type = isset($options['input_type'])
- ? $options['input_type']
- : null;
+ $input_type = $options['input_type']
+ ?? null;
switch ($input_type) {
case 'dropdown':
- $dropdown_type = isset($options['dropdown_type'])
- ? $options['dropdown_type']
- : null;
+ $dropdown_type = $options['dropdown_type']
+ ?? null;
$fk = getForeignKeyFieldForTable(getTableForItemType($itemtype));
if ($dropdown_type == 'isolated') {
@@ -208,95 +59,25 @@ public static function getFieldName($field, $itemtype, $options, $remove_prefix
//Prepend plugin's table prefix if this dropdown is not already handled by GLPI natively
if (
- substr($field, 0, strlen('plugin_genericobject')) !== 'plugin_genericobject'
- and (
- substr($field_table, strlen('glpi_'))
- === substr($field, 0, strlen($field) - strlen('_id'))
- )
- and !$DB->tableExists($field_table)
+ (!str_starts_with($field, 'plugin_genericobject') && substr($field_table, strlen('glpi_')) === substr($field, 0, strlen($field) - strlen('_id')) && !$DB->tableExists($field_table)) && !$remove_prefix
) {
- if (!$remove_prefix) {
- $field = 'plugin_genericobject_' . $field;
- }
+ $field = 'plugin_genericobject_' . $field;
}
break;
}
return $field;
}
- /**
- *
- * Display a dropdown with all available fields for an itemtype
- * @since
- * @param string $name the dropdown name
- * @param string $itemtype the itemtype
- * @param array $used an array which contains all fields already added
- *
- * @return int the dropdown random ID
- */
- public static function dropdownFields($name, $itemtype, $used = [])
- {
- /** @var array $GO_FIELDS */
- global $GO_FIELDS;
-
- $dropdown_types = [];
- foreach ($GO_FIELDS as $field => $values) {
- $message = "";
- $field_options = [];
- $field = self::getFieldName($field, $itemtype, $values, false);
- if (!in_array($field, $used)) {
- if (!isset($dropdown_types[$field])) {
- //Global management :
- //meaning that a dropdown can be useful in all types (for example type, model, etc.)
- if (isset($values['input_type']) && $values['input_type'] == 'dropdown') {
- if (isset($values['entities_id'])) {
- $field_options[] = __("Entity") . " : " . Dropdown::getYesNo($values['entities_id']);
- if ($values['entities_id']) {
- if (isset($values['is_recursive'])) {
- $field_options[] = __("Child entities") . " : " . Dropdown::getYesNo($values['is_recursive']);
- }
- }
- } else {
- $field_options[] = __("Entity") . " : " . Dropdown::getYesNo(0);
- }
- if (isset($values['is_tree'])) {
- $field_options[] = __("tree structure") . " : " . Dropdown::getYesNo($values['is_tree']);
- } else {
- $field_options[] = __("tree structure") . " : " . Dropdown::getYesNo(0);
- }
- //if (isset($values['isolated']) and $values['isolated']) {
- // $field_options[] = __("Isolated") . " : ". Dropdown::getYesNo($values['isolated']);
- //} else {
- // $field_options[] = __("Isolated") . " : ". Dropdown::getYesNo(0);
- //}
- }
- if (!empty($field_options)) {
- $message = "(" . trim(implode(", ", $field_options)) . ")";
- }
- }
- $dropdown_types[$field] = $values['name'] . " " . $message;
- }
- }
-
- // Don't show dropdown empty
- if (empty($dropdown_types)) {
- return '';
- }
-
- ksort($dropdown_types);
- return Dropdown::showFromArray($name, $dropdown_types, ['display' => false]);
- }
-
- /**
- *
- * Get field's options defined in constant files.
- * If this field has not been defined, it means that this field has been defined globally and
- * must be dynamically created.
- *
- * @param $field the current field
- * @param $itemtype the itemtype
- * @return array which contains the full field definition
- */
+ /**
+ *
+ * Get field's options defined in constant files.
+ * If this field has not been defined, it means that this field has been defined globally and
+ * must be dynamically created.
+ *
+ * @param $field the current field
+ * @param $itemtype the itemtype
+ * @return array which contains the full field definition
+ */
public static function getFieldOptions($field, $itemtype = "")
{
/** @var array $GO_FIELDS */
@@ -305,275 +86,26 @@ public static function getFieldOptions($field, $itemtype = "")
$options = [];
$cleaned_field = preg_replace("/^plugin_genericobject_/", '', $field);
if (!isset($GO_FIELDS[$cleaned_field]) && !empty($itemtype)) {
- // This field has been dynamically defined because it's an isolated dropdown
+ // This field has been dynamically defined because it's an isolated dropdown
$tmpfield = self::getFieldName(
$field,
$itemtype,
[
'dropdown_type' => 'isolated',
- 'input_type' => 'dropdown'
+ 'input_type' => 'dropdown',
],
- true
+ true,
);
$options = $GO_FIELDS[$tmpfield];
$options['realname'] = $tmpfield;
- } else if (isset($GO_FIELDS[$cleaned_field])) {
+ } elseif (isset($GO_FIELDS[$cleaned_field])) {
$options = $GO_FIELDS[$cleaned_field];
$options['realname'] = $cleaned_field;
}
return $options;
}
- public static function displayFieldDefinition($target, $itemtype, $field, $index, $last = false)
- {
- /**
- * @var array $CFG_GLPI
- * @var array $GO_BLACKLIST_FIELDS
- * @var array $GO_READONLY_FIELDS
- */
- global $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_READONLY_FIELDS;
-
- $readonly = in_array($field, $GO_READONLY_FIELDS);
- $blacklist = in_array($field, $GO_BLACKLIST_FIELDS);
- $options = self::getFieldOptions($field, $itemtype);
-
- echo "";
- echo "| ";
- if (!$blacklist && !$readonly) {
- echo "";
- } else {
- echo "";
- }
- echo " | ";
- echo "" . __($options['name'], 'genericobject') . " | ";
- echo "" . $field . " | ";
-
- echo "";
- if ((!$blacklist || $readonly) && $index > 1) {
- Html::showSimpleForm(
- $target,
- $CFG_GLPI["root_doc"] . "/pics/deplier_up.png",
- 'up',
- ['field' => $field, 'action' => 'up', 'itemtype' => $itemtype],
- $CFG_GLPI["root_doc"] . "/pics/deplier_up.png"
- );
- }
- echo " | ";
-
- echo "";
- if ((!$blacklist || $readonly) && !$last) {
- Html::showSimpleForm(
- $target,
- $CFG_GLPI["root_doc"] . "/pics/deplier_down.png",
- 'down',
- ['field' => $field, 'action' => 'down', 'itemtype' => $itemtype],
- $CFG_GLPI["root_doc"] . "/pics/deplier_down.png"
- );
- }
- echo " | ";
-
- echo "
";
- }
-
- /**
- * Add a new field in DB
- * @param string $table the table
- * @param string $field the field to delete
- * @return void
- */
- public static function addNewField($table, $field, $after = false)
- {
- /** @var DBmysql $DB */
- global $DB;
-
- _log("add", $field, "from", $table);
- $itemtype = getItemTypeForTable($table);
- if (!$DB->fieldExists($table, $field, false)) {
- $options = self::getFieldOptions($field, $itemtype);
- $query = "ALTER TABLE `$table` ADD `$field` ";
- switch ($options['input_type']) {
- case 'dropdown_yesno':
- case 'dropdown_global':
- case 'bool':
- $query .= "TINYINT NOT NULL DEFAULT '0'";
- break;
- case 'emptyspace':
- case 'text':
- $query .= "VARCHAR ( 255 ) NOT NULL DEFAULT ''";
- break;
- case 'multitext':
- $query .= "TEXT NULL";
- break;
- case 'dropdown':
- $query .= "INT unsigned NOT NULL DEFAULT '0'";
- break;
- case 'integer':
- $query .= "INT NOT NULL DEFAULT '0'";
- break;
- case 'date':
- $query .= "DATE DEFAULT NULL";
- break;
- case 'datetime':
- $query .= "TIMESTAMP NULL DEFAULT NULL";
- break;
- case 'float':
- $query .= "FLOAT NOT NULL DEFAULT '0'";
- break;
- case 'decimal':
- $query .= "DECIMAL(20,4) NOT NULL DEFAULT '0.0000'";
- break;
- }
- if ($after) {
- $query .= " AFTER `$after`";
- }
- $DB->query($query);
-
- //Reload list of fields for this itemtype in the singleton
-
- $recursive = $entity_assign = $tree = false;
-
- $table = getTableNameForForeignKeyField($field);
-
- if ($table != '' && !$DB->tableExists($table)) {
- //Cannot use standard methods because class doesn't exists yet !
- $name = str_replace("glpi_plugin_genericobject_", "", $table);
- $name = getSingular($name);
-
- $options['linked_itemtype'] = $itemtype;
-
- PluginGenericobjectType::addNewDropdown(
- $name,
- 'PluginGenericobject' . ucfirst($name),
- $options
- );
- }
- // Invalidate menu data in current session
- unset($_SESSION['glpimenu']);
-
- PluginGenericobjectSingletonObjectField::getInstance($itemtype, true);
- }
- }
-
- /**
- * Delete a field in DB
- * @param string $table the table
- * @param string $field the field to delete
- * @return void
- */
- public static function deleteField($table, $field)
- {
- /** @var DBmysql $DB */
- global $DB;
-
- //Remove field from displaypreferences
- self::deleteDisplayPreferences($table, $field);
-
- //If field exists, drop it !
- if ($DB->fieldExists($table, $field)) {
- $DB->query("ALTER TABLE `$table` DROP `$field`");
- }
+ public static function install(Migration $migration) {}
- $table = getTableNameForForeignKeyField($field);
- //If dropdown is managed by the plugin
- if ($table != '' && preg_match('/plugin_genericobject_(.*)/', $table, $results)) {
- //Delete dropdown table
- $query = "DROP TABLE `$table`";
- $DB->query($query);
- //Delete dropdown files & class
- $name = getSingular($results[1]);
- PluginGenericobjectType::deleteClassFile($name);
- PluginGenericobjectType::deleteFormFile($name);
- PluginGenericobjectType::deletesearchFile($name);
- }
- }
-
- public static function deleteDisplayPreferences($table, $field)
- {
-
- $pref = new DisplayPreference();
- $itemtype = getItemTypeForTable($table);
- $searchopt = Search::getCleanedOptions($itemtype);
- foreach ($searchopt as $num => $option) {
- if (
- (isset($option['field']) && ($option['field'] == $field))
- || (isset($option['field']) && $option['linkfield'] == $field)
- ) {
- $pref->deleteByCriteria([
- 'itemtype' => $itemtype,
- 'num' => $num
- ]);
- break;
- }
- }
- }
-
- /**
- * Change field order in DB
- * @params an array which contains the itemtype, the field to move and the action (up/down)
- * @return void
- */
- public static function changeFieldOrder($params = [])
- {
- /** @var DBmysql $DB */
- global $DB;
- $itemtype = $params['itemtype'];
- $field = $params['field'];
- $table = getTableForItemType($itemtype);
- $fields = PluginGenericobjectSingletonObjectField::getInstance($params['itemtype']);
-
- //If action is down, reverse array first
- if ($params['action'] == 'down') {
- $fields = array_reverse($fields);
- }
-
- //Get array keys
- $keys = array_keys($fields);
- //Index represents current position of $field
- $index = 0;
- foreach ($keys as $id => $key) {
- if ($key == $field) {
- $index = $id;
- }
- }
- //Get 2 positions before and move field
- if ($params['action'] == 'down') {
- $previous = $index - 1;
- } else {
- $previous = $index - 2;
- }
-
- if (isset($keys[$previous])) {
- $parent = $fields[$keys[$previous]];
- $query = "ALTER TABLE `$table` MODIFY `$field` " . $fields[$field]['Type'];
- $query .= " AFTER `" . $fields[$keys[$previous]]['Field'] . "`";
- $DB->query($query) or die($DB->error());
- }
- }
-
- public static function checkNecessaryFieldsDelete($itemtype, $field)
- {
- $type = new PluginGenericobjectType();
- $type->getFromDBByType($itemtype);
-
- if ($type->canUseNetworkPorts() && 'locations_id' == $field) {
- return false;
- }
- /*
- if ($type->fields['use_direct_connections']) {
- foreach(['users_id','groups_id',' states_id','locations_id'] as $tmp_field) {
- if ($tmp_field == $field) {
- return false;
- }
- }
- }*/
- return true;
- }
-
- public static function install(Migration $migration)
- {
- }
-
- public static function uninstall()
- {
- }
+ public static function uninstall() {}
}
diff --git a/inc/functions.php b/inc/functions.php
index eaf6ba0c..7b8122ba 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -36,16 +36,30 @@
*/
function dropdown_getTypeName($class, $nb = 0)
{
+ if (!class_exists($class, true)) {
+ return $class;
+ }
+
$fk = getForeignKeyFieldForTable(getTableForItemType($class));
+ /** @var CommonDBTM $instance */
$instance = new $class();
- $options = PluginGenericobjectField::getFieldOptions($fk, $instance->linked_itemtype);
- $dropdown_type = isset($options['dropdown_type'])
- ? $options['dropdown_type']
- : null;
+
+ $linked_itemtype = null;
+ if (property_exists($instance, 'linked_itemtype')) {
+ $linked_itemtype = $instance->linked_itemtype;
+ }
+
+ $options = PluginGenericobjectField::getFieldOptions($fk, $linked_itemtype);
+ $dropdown_type = $options['dropdown_type']
+ ?? null;
$label = $options['name'] ?? "no-name";
- if (!is_null($dropdown_type) and $dropdown_type === 'isolated') {
- $linked_itemtype_object = new $instance->linked_itemtype();
- $label .= " (" . __($linked_itemtype_object::getTypeName(), 'genericobject') . ")";
+ if (!is_null($dropdown_type) && $dropdown_type === 'isolated' && !is_null($linked_itemtype)) {
+ if (!class_exists($linked_itemtype, true)) {
+ return $label;
+ }
+ /** @var CommonDBTM $linked_itemtype_object */
+ $linked_itemtype_object = new $linked_itemtype();
+ $label .= " (" . __s($linked_itemtype_object::getTypeName(), 'genericobject') . ")";
}
if ($label != '') {
return $label;
@@ -72,18 +86,12 @@ function _log()
$trace_file = str_replace("\\", "/", $trace[0]['file']);
$filename = preg_replace("|^" . $glpi_root . "/" . Plugin::getPhpDir('genericobject', false) . "/|", "", $trace_file);
}
- if (count($trace) > 1) {
- $caller = $trace[1];
- } else {
- $caller = null;
- }
+ $caller = count($trace) > 1 ? $trace[1] : null;
$msg = _format_trace($trace, func_get_args());
$msg .= "\n";
$show_log = false;
if (
- !is_null($caller) and
- isset($caller['class']) and
- in_array($caller['class'], $LOG_FILTER)
+ !is_null($caller) && isset($caller['class']) && in_array($caller['class'], $LOG_FILTER)
) {
$callee = array_shift($trace);
$show_log = true;
@@ -123,9 +131,9 @@ function _format_trace($bt, $args)
foreach ($args as $arg) {
if (is_array($arg) || is_object($arg)) {
$msg .= " " . str_replace("\n", "\n ", print_r($arg, true));
- } else if (is_null($arg)) {
+ } elseif (is_null($arg)) {
$msg .= 'NULL ';
- } else if (is_bool($arg)) {
+ } elseif (is_bool($arg)) {
$msg .= ($arg ? 'true' : 'false') . ' ';
} else {
$msg .= $arg . ' ';
diff --git a/inc/object.class.php b/inc/object.class.php
index 8b3269a2..f35f09ad 100644
--- a/inc/object.class.php
+++ b/inc/object.class.php
@@ -27,1322 +27,21 @@
* @link https://github.com/pluginsGLPI/genericobject
* -------------------------------------------------------------------------
*/
+
+use Glpi\Features\Clonable;
+
class PluginGenericobjectObject extends CommonDBTM
{
- use Glpi\Features\Clonable;
+ use Clonable;
protected $objecttype;
- //Internal field counter
- private $cpt = 0;
-
- //Get itemtype name
- public static function getTypeName($nb = 0)
- {
- /** @var array $LANG */
- global $LANG;
- $class = get_called_class();
- //Datainjection : Don't understand why I need this trick : need to be investigated !
- if (preg_match("/Injection$/i", $class)) {
- $class = str_replace("Injection", "", $class);
- }
- $item = new $class();
- //Itemtype name can be contained in a specific locale field : try to load it
- PluginGenericobjectType::includeLocales($item->objecttype->fields['name']);
- if (isset($LANG['genericobject'][$class][0])) {
- $type_name = $LANG['genericobject'][$class][0];
- } else {
- $type_name = $item->objecttype->fields['name'];
- }
- return ucwords($type_name);
- }
-
-
- public function __construct()
- {
- $class = get_called_class();
- if (class_exists($class)) {
- $this->objecttype = PluginGenericobjectType::getInstance($class);
- }
- $this->dohistory = $this->canUseHistory();
-
- if (preg_match("/PluginGenericobject(.*)/", $class, $results)) {
- if (preg_match("/^(.*)y$/i", $results[1], $end_results)) {
- static::$rightname = 'plugin_genericobject_' . strtolower($end_results[1]) . 'ies';
- } else if (preg_match("/^(.*)(ss|x)$/i", $results[1])) {
- static::$rightname = 'plugin_genericobject_' . strtolower($results[1]) . 'es';
- } else {
- static::$rightname = 'plugin_genericobject_' . strtolower($results[1]) . 's';
- }
- }
-
- if ($this->canUseNotepad()) {
- $this->usenotepad = true;
- }
- }
-
public function getCloneRelations(): array
- {
- return [
- Computer_Item::class,
- Contract_Item::class,
- Document_Item::class,
- Infocom::class,
- Item_Devices::class,
- NetworkPort::class,
- ];
- }
-
-
- /**
- * Display information on treeview plugin
- *
- * @params itemtype, id, pic, url, name
- *
- * @return array
- **/
- public static function showGenericObjectTreeview($params)
- {
- /** @var array $CFG_GLPI */
- global $CFG_GLPI;
-
- if (array_key_exists($params['itemtype'], PluginGenericobjectType::getTypes())) {
- $item = new $params['itemtype']();
- if ($item->getFromDB($params['id'])) {
- $params['name'] = $item->fields["name"];
- $params['url'] = Plugin::getWebDir('genericobject') . "/front/object.form.php" . "?itemtype=" . $params['itemtype'] . "&id=" . $params['id'];
- }
- }
- return $params;
- }
-
- /**
- * Display node search url on treeview plugin
- *
- * @params itemtype, id, pic, url, name
- *
- * @return array
- **/
- public static function getParentNodeSearchUrl($params)
- {
- if (array_key_exists($params['itemtype'], PluginGenericobjectType::getTypes())) {
- $item = new $params['itemtype']();
- $search = $item->rawSearchOptions();
- //get searchoption id for location_id
- $index = '';
- foreach ($search as $key => $val) {
- if (isset($val['table']) && $val['table'] === 'glpi_locations') {
- $index = $key;
- }
- }
-
- $token = Session::getNewCSRFToken();
-
- $params['searchurl'] = $params['itemtype']::getSearchURL() . "&is_deleted=0&criteria[0][field]=" . $index . "&criteria[0]" . "[searchtype]=equals&criteria[0][value]=" . $params['locations_id'] . "&search=Rechercher&start=0&_glpi_csrf_token=$token";
- return $params;
- }
-
- return $params;
- }
-
- public static function install()
- {
- }
-
- public static function uninstall()
- {
- }
-
- public static function registerType()
- {
- /**
- * @var array $PLUGIN_HOOKS
- * @var array $UNINSTALL_TYPES
- * @var array $ORDER_TYPES
- * @var array $CFG_GLPI
- * @var array $GO_LINKED_TYPES
- * @var array $GENINVENTORYNUMBER_TYPES
- */
- global $PLUGIN_HOOKS, $UNINSTALL_TYPES, $ORDER_TYPES, $CFG_GLPI, $GO_LINKED_TYPES, $GENINVENTORYNUMBER_TYPES;
-
- $class = get_called_class();
- $item = new $class();
- $fields = PluginGenericobjectSingletonObjectField::getInstance($class);
- $plugin = new Plugin();
-
- PluginGenericobjectType::includeLocales($item->getObjectTypeName());
- PluginGenericobjectType::includeConstants($item->getObjectTypeName());
-
- $options = [
- "document_types" => $item->canUseDocuments(),
- "helpdesk_visible_types" => $item->canUseTickets(),
- "linkgroup_types" => isset($fields["groups_id"]),
- "linkuser_types" => isset($fields["users_id"]),
- "linkgroup_tech_types" => isset($fields["groups_id_tech"]),
- "linkuser_tech_types" => isset($fields["users_id_tech"]),
- "ticket_types" => $item->canUseTickets(),
- "infocom_types" => $item->canUseInfocoms(),
- "networkport_types" => $item->canUseNetworkPorts(),
- "reservation_types" => $item->canBeReserved(),
- "contract_types" => $item->canUseContracts(),
- "unicity_types" => $item->canUseUnicity(),
- "location_types" => isset($fields['locations_id']),
- "itemdevices_types" => $item->canUseItemDevice(),
- "itemdevicememory_types" => $item->canUseItemDevice(),
- "itemdevicepowersupply_types" => $item->canUseItemDevice(),
- "itemdevicenetworkcard_types" => $item->canUseItemDevice(),
- "itemdeviceharddrive_types" => $item->canUseItemDevice(),
- "itemdevicebattery_types" => $item->canUseItemDevice(),
- "itemdevicefirmware_types" => $item->canUseItemDevice(),
- "itemdevicesimcard_types" => $item->canUseItemDevice(),
- "itemdevicegeneric_types" => $item->canUseItemDevice(),
- "itemdevicepci_types" => $item->canUseItemDevice(),
- "itemdevicesensor_types" => $item->canUseItemDevice(),
- "itemdeviceprocessor_types" => $item->canUseItemDevice(),
- "itemdevicesoundcard_types" => $item->canUseItemDevice(),
- "itemdevicegraphiccard_types" => $item->canUseItemDevice(),
- "itemdevicemotherboard_types" => $item->canUseItemDevice(),
- "itemdevicecamera_types" => $item->canUseItemDevice(),
-
- ];
-
- $glpiVersion = new Plugin();
- $glpiVersion = $glpiVersion->getGlpiVersion();
-
- if (version_compare($glpiVersion, "10.0.19", '>=')) {
- $options["itemdevicedrive_types"] = $item->canUseItemDevice();
- $options["itemdevicecontrol_types"] = $item->canUseItemDevice();
- }
-
- Plugin::registerClass($class, $options);
-
- if (plugin_genericobject_haveRight($class, READ)) {
- //Change url for adding a new object, depending on template management activation
- if ($item->canUseTemplate()) {
- //Template management is active
- $add_url = "/front/setup.templates.php?itemtype=$class&add=1";
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$class]['links']['template'] = "/front/setup.templates.php?itemtype=$class&add=0";
- } else {
- //Template management is not active
- $add_url = Toolbox::getItemTypeFormURL($class, false);
- }
- //Menu management
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$class]['title'] = $class::getTypeName();
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$class]['page'] = Toolbox::getItemTypeSearchURL($class, false);
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$class]['links']['search'] = Toolbox::getItemTypeSearchURL($class, false);
-
- if (plugin_genericobject_haveRight($class, UPDATE)) {
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$class]['links']['add'] = $add_url;
- }
-
- //Add configuration icon, if user has right
- if (Session::haveRight('config', UPDATE)) {
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$class]['links']['config'] = Toolbox::getItemTypeSearchURL('PluginGenericobjectType', false) . "?itemtype=$class";
- }
-
- if ($item->canUsePluginUninstall()) {
- if (!in_array($class, $UNINSTALL_TYPES)) {
- array_push($UNINSTALL_TYPES, $class);
- }
- }
- if ($item->canUsePluginSimcard()) {
- if ($plugin->isActivated('simcard') && $plugin->isActivated('simcard')) {
- //@phpstan-ignore-next-line
- PluginSimcardSimcard_Item::registerItemtype($class);
- }
- }
- if ($item->canUsePluginOrder()) {
- if (!in_array($class, $ORDER_TYPES)) {
- array_push($ORDER_TYPES, $class);
- }
- }
- if ($item->canBeReserved()) {
- //Manage name used for sector
- //See object.form.php L101
- //it can be 'itemtype' name or 'family' name
- if (($name = PluginGenericobjectType::getFamilyNameByItemtype($class)) === false) {
- $name = $class;
- }
- //from define.php $CFG_GLPI['javascript']['assets'] seems to be computed only once (from start)
- //need to add manually js for sector and itemtype/family
- $CFG_GLPI['javascript']['assets'][strtolower($name)] = ['fullcalendar', 'reservations'];
- }
-
- if ($item->canUseGlobalSearch()) {
- if (!in_array($class, $CFG_GLPI['asset_types'])) {
- array_push($CFG_GLPI['asset_types'], $class);
- }
-
- if (!in_array($class, $CFG_GLPI['globalsearch_types'])) {
- array_push($CFG_GLPI['globalsearch_types'], $class);
- }
- }
-
- if ($item->canUseDirectConnections()) {
- if (!in_array($class, $GO_LINKED_TYPES)) {
- array_push($GO_LINKED_TYPES, $class);
- }
- $items_class = $class . "_Item";
- $items_class::registerType();
- }
-
- if ($item->canUseProjects()) {
- if (!in_array($class, $CFG_GLPI['project_asset_types'])) {
- array_push($CFG_GLPI['project_asset_types'], $class);
- }
- }
-
- $plugin_gen_path = Plugin::getPhpDir('geninventorynumber');
- if ($item->canUsePluginGeninventorynumber()) {
- if (!in_array($class, $GENINVENTORYNUMBER_TYPES)) {
- include_once("$plugin_gen_path/inc/profile.class.php");
- //@phpstan-ignore-next-line
- PluginGeninventorynumberConfigField::registerNewItemType($class);
- array_push($GENINVENTORYNUMBER_TYPES, $class);
- }
- } else if ($plugin->isActivated('geninventorynumber')) {
- include_once("$plugin_gen_path/inc/profile.class.php");
- //@phpstan-ignore-next-line
- PluginGeninventorynumberConfigField::unregisterNewItemType($class);
- }
- }
-
- foreach (PluginGenericobjectType::getDropdownForItemtype($class) as $table) {
- $itemtype = getItemTypeForTable($table);
- if (class_exists($itemtype)) {
- $item = new $itemtype();
- //If entity dropdown, check rights to view & create
- if ($itemtype::canView()) {
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$itemtype]['links']['search'] = Toolbox::getItemTypeSearchURL($itemtype, false);
- if ($itemtype::canCreate()) {
- $PLUGIN_HOOKS['submenu_entry']['genericobject']['options'][$class]['links']['add'] = Toolbox::getItemTypeFormURL($class, false);
- }
- }
- }
- }
- }
-
- public static function getMenuIcon($itemtype)
- {
- /** @var array $CFG_GLPI */
- global $CFG_GLPI;
- $itemtype_table = getTableForItemType($itemtype);
- $itemtype_shortname = preg_replace("/^glpi_plugin_genericobject_/", "", $itemtype_table);
- $itemtype_icons = glob(
- GENERICOBJECT_PICS_PATH . '/' . getSingular($itemtype_shortname) . ".*"
- );
- $finfo = new finfo(FILEINFO_MIME);
- $icon_found = null;
- foreach ($itemtype_icons as $icon) {
- if (preg_match("|^image/|", $finfo->file($icon))) {
- $icon_found = preg_replace("|^" . GLPI_ROOT . "|", "", $icon);
- }
- }
- if (!is_null($icon_found)) {
- $icon_path = $CFG_GLPI['root_doc'] . $icon_found;
- } else {
- $icon_path = Plugin::getWebDir('genericobject') . "/pics/default-icon.png";
- }
- return "";
- }
-
- public static function checkItemtypeRight($class, $right)
- {
- if (!is_null($class) and class_exists($class)) {
- $right_name = PluginGenericobjectProfile::getProfileNameForItemtype(
- $class
- );
-
- return Session::haveRight($right_name, $right);
- }
- }
-
- public static function canCreate()
- {
- $class = get_called_class();
- //Datainjection : Don't understand why I need this trick : need to be investigated !
- if (preg_match("/Injection$/i", $class)) {
- $class = str_replace("Injection", "", $class);
- }
- return static::checkItemtypeRight($class, CREATE);
- }
-
- public static function canView()
- {
- $class = get_called_class();
- return static::checkItemtypeRight($class, READ);
- }
-
- public static function canUpdate()
- {
- $class = get_called_class();
- return static::checkItemtypeRight($class, UPDATE);
- }
-
- public static function canDelete()
- {
- $class = get_called_class();
- return static::checkItemtypeRight($class, DELETE);
- }
-
- public static function canPurge()
- {
- $class = get_called_class();
- return static::checkItemtypeRight($class, PURGE);
- }
-
- public function defineTabs($options = [])
- {
- $tabs = [];
-
- $this->addDefaultFormTab($tabs);
-
- if (!$this->isNewItem()) {
- // Register impact tab is enabled
- if ($this->canUseImpact()) {
- $this->addImpactTab($tabs, $options);
- }
-
- if ($this->canUseNetworkPorts()) {
- $this->addStandardTab('NetworkPort', $tabs, $options);
- }
-
- if ($this->canUseItemDevice()) {
- $this->addStandardTab('Item_Devices', $tabs, $options);
- }
-
- if ($this->canUseInfocoms()) {
- $this->addStandardTab('Infocom', $tabs, $options);
- }
-
- if ($this->canUseContracts()) {
- $this->addStandardTab('Contract_Item', $tabs, $options);
- }
-
- if ($this->canUseDocuments()) {
- $this->addStandardTab('Document_Item', $tabs, $options);
- }
-
- if ($this->canUseTickets()) {
- $this->addStandardTab('Ticket', $tabs, $options);
- $this->addStandardTab('Item_Problem', $tabs, $options);
- $this->addStandardTab('Change_Item', $tabs, $options);
- }
-
- if ($this->canUseNotepad()) {
- $this->addStandardTab('Notepad', $tabs, $options);
- }
-
- if ($this->canBeReserved()) {
- $this->addStandardTab('Reservation', $tabs, $options);
- }
-
- if ($this->canUseHistory()) {
- $this->addStandardTab('Log', $tabs, $options);
- }
- }
- return $tabs;
- }
-
-
- //------------------------ CAN methods -------------------------------------//
-
- public function getObjectTypeName()
- {
- return $this->objecttype->getName();
- }
-
- public function canUseInfocoms()
- {
- return ($this->objecttype->canUseInfocoms() && Session::haveRight("infocom", READ));
- }
-
- public function canUseContracts()
- {
- return ($this->objecttype->canUseContracts() && Session::haveRight("contract", READ));
- }
-
-
- public function canUseTemplate()
- {
- return $this->objecttype->canUseTemplate();
- }
-
-
- public function canUseNotepad()
- {
- return $this->objecttype->canUseNotepad();
- }
-
- public function canUseUnicity()
- {
- // Disable unicity feature (for GLPI 0.85 onward) : see issue #16
- // Related code : search for #16
- // FIXME : The bug may be in GLPI itself
- return ($this->objecttype->canUseUnicity() && Session::haveRight("config", READ));
- }
-
-
- public function canUseDocuments()
- {
- return ($this->objecttype->canUseDocuments() && Session::haveRight("document", READ));
- }
-
-
- public function canUseTickets()
- {
- return ($this->objecttype->canUseTickets());
- }
-
-
- public function canUseGlobalSearch()
- {
- return ($this->objecttype->canUseGlobalSearch());
- }
-
-
- public function canBeReserved()
- {
- return (
- $this->objecttype->canBeReserved()
- and Session::haveRight(ReservationItem::$rightname, ReservationItem::RESERVEANITEM)
- );
- }
-
-
- public function canUseHistory()
- {
- return ($this->objecttype->canUseHistory());
- }
-
-
- public function canUsePluginDataInjection()
- {
- return ($this->objecttype->canUsePluginDataInjection());
- }
-
-
- public function canUsePluginPDF()
- {
- return ($this->objecttype->canUsePluginPDF());
- }
-
-
- public function canUsePluginOrder()
- {
- return ($this->objecttype->canUsePluginOrder());
- }
-
- public function canUsePluginGeninventorynumber()
- {
- return ($this->objecttype->canUsePluginGeninventorynumber());
- }
-
- public function canUseNetworkPorts()
- {
- return ($this->objecttype->canUseNetworkPorts());
- }
-
-
- public function canUseDirectConnections()
- {
- return ($this->objecttype->canUseDirectConnections());
- }
-
- public function canUseProjects()
- {
- return ($this->objecttype->canUseProjects());
- }
-
-
- public function canUsePluginUninstall()
- {
- return ($this->objecttype->canUsePluginUninstall());
- }
-
- public function canUsePluginSimcard()
- {
- return ($this->objecttype->canUsePluginSimcard());
- }
-
- public function getLinkedItemTypesAsArray()
- {
- return $this->objecttype->getLinkedItemTypesAsArray();
- }
-
- public function canUseItemDevice()
- {
- return ($this->objecttype->canUseItemDevice());
- }
-
- public function canUseImpact()
- {
- return ($this->objecttype->canUseImpact());
- }
-
- public function title()
- {
- }
-
-
- public function showForm($id, $options = [], $previsualisation = false)
- {
- if ($previsualisation) {
- $canedit = true;
- $this->getEmpty();
- } else {
- if ($id > 0) {
- $this->check($id, READ);
- } else {
- // Create item
- $this->check(-1, CREATE);
- $this->getEmpty();
- }
-
- $canedit = $this->can($id, UPDATE);
- }
-
- if (isset($options['withtemplate']) && $options['withtemplate'] == 2) {
- $template = "newcomp";
- } else if (isset($options['withtemplate']) && $options['withtemplate'] == 1) {
- $template = "newtemplate";
- } else {
- $template = false;
- }
-
- $this->fields['id'] = $id;
- $this->initForm($id, $options);
- $this->showFormHeader($options);
-
- if ($previsualisation) {
- echo "| " . __("Object preview", "genericobject") . ": ";
- $itemtype = $this->objecttype->fields['itemtype'];
- echo $itemtype::getTypeName();
- echo " |
";
- }
-
- //Reset fields definition only to keep the itemtype ones
- $GO_FIELDS = [];
- plugin_genericobject_includeCommonFields(true);
- PluginGenericobjectType::includeConstants($this->getObjectTypeName(), true);
-
- foreach (PluginGenericobjectSingletonObjectField::getInstance($this->objecttype->fields['itemtype']) as $field => $description) {
- if ($field == "is_helpdesk_visible" && $id <= 0) {
- $this->displayField($canedit, $field, 1, $template, $description);
- } else {
- $this->displayField($canedit, $field, $this->fields[$field], $template, $description);
- }
- }
- $this->closeColumn();
-
- if (!$previsualisation) {
- $this->showFormButtons($options);
- } else {
- echo "";
- Html::closeForm();
- }
-
- return true;
- }
-
-
- public static function getFieldsToHide()
- {
- return ['id', 'is_recursive', 'is_template', 'template_name', 'is_deleted',
- 'entities_id', 'notepad', 'date_mod', 'date_creation', 'ticket_tco'
- ];
- }
-
-
- public function displayField($canedit, $name, $value, $template, $description = [])
- {
- $searchoption = PluginGenericobjectField::getFieldOptions($name, get_called_class());
-
- if (
- !empty($searchoption)
- && !in_array($name, self::getFieldsToHide())
- ) {
- if (isset($searchoption['input_type']) && 'emptyspace' === $searchoption['input_type']) {
- $searchoption['name'] = " ";
- $description['Type'] = 'emptyspace';
- }
-
- $this->startColumn();
- echo '';
-
- // Keep only main column type by removing anything that is preceded by a space (e.g. " unsigned")
- // or a parenthesis (e.g. "(255)").
- echo '';
- $column_type = preg_replace('/^([a-z]+)([ (].+)*$/', '$1', $description['Type']);
- switch ($column_type) {
- case "int":
- $fk_table = getTableNameForForeignKeyField($name);
- if ($fk_table != '') {
- $itemtype = getItemTypeForTable($fk_table);
- $dropdown = new $itemtype();
- $parameters = ['name' => $name, 'value' => $value, 'comments' => true];
- if ($dropdown->isEntityAssign()) {
- $parameters["entity"] = $this->fields['entities_id'];
- }
- if ($dropdown->maybeRecursive()) {
- $parameters['entity_sons'] = true;
- }
- if (isset($searchoption['condition'])) {
- $parameters['condition'] = $searchoption['condition'];
- }
- if ($dropdown instanceof User) {
- $parameters['entity'] = $this->fields["entities_id"];
- $parameters['right'] = 'all';
- User::dropdown($parameters);
- } else {
- Dropdown::show($itemtype, $parameters);
- }
- } else {
- $min = $max = $step = 0;
- if (isset($searchoption['min'])) {
- $min = $searchoption['min'];
- } else {
- $min = 0;
- }
- if (isset($searchoption['max'])) {
- $max = $searchoption['max'];
- } else {
- $max = 100;
- }
- if (isset($searchoption['step'])) {
- $step = $searchoption['step'];
- } else {
- $step = 1;
- }
- Dropdown::showNumber(
- $name,
- [
- 'value' => $value,
- 'min' => $min,
- 'max' => $max,
- 'step' => $step
- ]
- );
- }
- break;
-
- case "tinyint":
- Dropdown::showYesNo($name, $value);
- break;
-
- case "varchar":
- if (isset($searchoption['autoname']) && $searchoption['autoname']) {
- $objectName = autoName(
- $this->fields[$name],
- $name,
- ($template === "newcomp"),
- $this->getType(),
- $this->fields["entities_id"]
- );
- } else {
- $objectName = $this->fields[$name];
- }
- echo Html::input(
- $name,
- [
- 'value' => $objectName,
- ]
- );
- break;
-
- case "longtext":
- case "text":
- case "mediumtext":
- echo "";
- break;
-
- case "emptyspace":
- echo ' ';
- break;
-
- case "date":
- Html::showDateField(
- $name,
- [
- 'value' => $value,
- 'maybeempty' => true,
- 'canedit' => true
- ]
- );
- break;
-
- case "datetime":
- case "timestamp":
- Html::showDateTimeField(
- $name,
- [
- 'value' => $value,
- 'timestep' => true,
- 'maybeempty' => true
- ]
- );
- break;
-
- case "float":
- case 'decimal':
- echo "";
- break;
-
- default:
- echo "";
- break;
- }
- echo '
';
- $this->endColumn();
- }
- }
-
-
-
- /**
- * Add a new column
- **/
- public function startColumn()
- {
- if ($this->cpt == 0) {
- echo '';
- echo '
';
- echo '
';
- echo '
';
- echo '
';
- }
- echo '
';
-
- $this->cpt++;
- }
-
-
-
- /**
- * End a column
- **/
- public function endColumn()
- {
- echo "
";
- }
-
-
-
- /**
- * Close a column
- **/
- public function closeColumn()
- {
- if ($this->cpt > 0) {
- echo "
";
- }
- }
-
-
- public function prepareInputForAdd($input)
- {
-
- //Template management
- if (isset($input["id"]) && $input["id"] > 0) {
- $input["_oldID"] = $input["id"];
- }
- unset($input['id']);
- unset($input['withtemplate']);
-
- return $input;
- }
-
-
- public function cleanDBonPurge()
- {
- $parameters = ['items_id' => $this->getID(), 'itemtype' => get_called_class()];
- $types = ['Computer_Item', 'ReservationItem', 'Document_Item', 'Infocom', 'Contract_Item'];
- foreach ($types as $type) {
- $item = new $type();
- $item->deleteByCriteria($parameters);
- }
-
- foreach (['NetworkPort', 'Computer_Item', 'ReservationItem', 'ReservationItem', 'Document_Item', 'Infocom', 'Contract_Item', 'Item_Problem', 'Change_Item', 'Item_Project'] as $itemtype) {
- $ip = new $itemtype();
- $ip->cleanDBonItemDelete(get_called_class(), $this->getID());
- }
- }
-
- /**
- * Display object preview form
- * @param PluginGenericobjectType $type the object type
- */
- public static function showPrevisualisationForm(PluginGenericobjectType $type)
- {
- $itemtype = $type->fields['itemtype'];
- $item = new $itemtype();
-
- $right_name = PluginGenericobjectProfile::getProfileNameForItemtype(
- $itemtype
- );
-
- if (Session::haveRight($right_name, READ) && Session::haveRight($right_name, CREATE)) {
- $item->showForm(-1, [], true);
- } else {
- echo "
" . __(
- "You must configure rights to enable the preview",
- "genericobject"
- ) . "
";
- }
- }
-
- public function rawSearchOptions()
- {
- $datainjection_blacklisted = ['id', 'date_mod', 'entities_id', 'date_creation'];
- $index_exceptions = ['name' => 1, 'id' => 2, 'completename' => 3, 'comment' => 16, 'date_mod' => 19,
- 'entities_id' => 80, 'is_recursive' => 86, 'notepad' => 90,
- 'date_creation' => 121
- ];
-
- // Don't use indexes blacklisted by other item types in plugin DataInjection.
- $plugin = new Plugin();
- if (
- $plugin->isActivated("datainjection")
- && class_exists('PluginDatainjectionCommonInjectionLib')
- ) {
- $blacklisted_indexes = PluginDatainjectionCommonInjectionLib::getBlacklistedOptions(
- get_called_class() //A class that extends PluginGenericobjectObject
- );
- } else {
- $blacklisted_indexes = [];
- }
-
- $index = 3;
-
- $options = \Location::rawSearchOptionsToAdd();
-
- $options[] = [
- 'id' => 'common',
- 'name' => __('Characteristics'),
- ];
-
- $table = getTableForItemType(get_called_class());
-
- // Prevent usage of reserved and blacklisted indexes
- $taken_indexes = array_merge($index_exceptions, $blacklisted_indexes);
-
- plugin_genericobject_includeCommonFields(true);
-
- foreach (PluginGenericobjectSingletonObjectField::getInstance(get_called_class()) as $field => $values) {
- $searchoption = PluginGenericobjectField::getFieldOptions(
- $field,
- $this->objecttype->fields['itemtype']
- );
-
- if ($field == 'is_deleted') {
- continue;
- }
-
- //Some fields have fixed index values...
- $currentindex = $index;
- if (isset($index_exceptions[$field])) {
- $currentindex = $index_exceptions[$field];
- } else {
- //If this index is reserved, jump to next available one.
- while (in_array($currentindex, $taken_indexes)) {
- $currentindex++;
- }
- }
-
- $option = [
- 'id' => $currentindex,
- ];
- $taken_indexes[] = $option['id'];
-
- $item = new $this->objecttype->fields['itemtype']();
-
- //Table definition
- //We test if it ends with s_id, in order to be sure that this pattern
- //was found in a field that doesn't represent a foreign key
- //for exemple a field called : is_identification
- if (preg_match("/(s_id$|s_id_)/", $field)) {
- $tmp = getTableNameForForeignKeyField($field);
- } else {
- $tmp = '';
- }
-
- if (preg_match("/(s_id_)/", $field)) {
- $option['linkfield'] = $field;
- }
-
- if ($tmp != '') {
- $itemtype = getItemTypeForTable($tmp);
- $tmpobj = new $itemtype();
-
- //Set table
- $option['table'] = $tmp;
-
- //Set field
- if ($tmpobj instanceof CommonTreeDropdown) {
- $option['field'] = 'completename';
- } else {
- $option['field'] = 'name';
- }
- } else {
- $option['table'] = $table;
- $option['field'] = $field;
- }
-
- $option['name'] = $searchoption['name'];
-
- //Massive action or not
- if (isset($searchoption['massiveaction'])) {
- $option['massiveaction'] = $searchoption['massiveaction'];
- }
-
- //Datainjection option
- if (!in_array($field, $datainjection_blacklisted)) {
- $option['injectable'] = 1;
- } else {
- $option['injectable'] = 0;
- }
-
- //Field type
- $column_type = preg_replace('/^([a-z]+)([ (].+)*$/', '$1', $values['Type']);
- switch ($column_type) {
- default:
- case "varchar":
- if ($field == 'name') {
- $option['datatype'] = 'itemlink';
- $option['itemlink_type'] = get_called_class();
- $option['massiveaction'] = false;
- // Enable autocomplete only for name, other fields may contains sensitive data
- $option['autocomplete'] = true;
- } else {
- if (isset($searchoption['datatype']) && $searchoption['datatype'] == 'weblink') {
- $option['datatype'] = 'weblink';
- } else {
- $option['datatype'] = 'string';
- }
- }
- if ($item->canUsePluginDataInjection()) {
- //Datainjection specific
- $option['checktype'] = 'text';
- $option['displaytype'] = 'text';
- }
- break;
- case "tinyint":
- $option['datatype'] = 'bool';
- if ($item->canUsePluginDataInjection()) {
- //Datainjection specific
- $option['displaytype'] = 'bool';
- }
- break;
- case "text":
- case "longtext":
- case "mediumtext":
- $option['datatype'] = 'text';
- if ($item->canUsePluginDataInjection()) {
- //Datainjection specific
- $option['displaytype'] = 'multiline_text';
- }
- break;
- case "int":
- if ($tmp != '') {
- $option['datatype'] = 'dropdown';
- } else {
- $option['datatype'] = 'integer';
- }
-
- if ($item->canUsePluginDataInjection()) {
- if ($tmp != '') {
- $option['displaytype'] = 'dropdown';
- $option['checktype'] = 'text';
- } else {
- //Datainjection specific
- $option['displaytype'] = 'dropdown_integer';
- $option['checktype'] = 'integer';
- }
- }
- break;
- case "float":
- case "decimal":
- $option['datatype'] = $values['Type'];
- if ($item->canUsePluginDataInjection()) {
- //Datainjection specific
- $option['display'] = 'text';
- $option['checktype'] = $values['Type'];
- }
- break;
- case "date":
- $option['datatype'] = 'date';
- if ($item->canUsePluginDataInjection()) {
- //Datainjection specific
- $option['displaytype'] = 'date';
- $option['checktype'] = 'date';
- }
- break;
- case "datetime":
- case "timestamp":
- $option['datatype'] = 'datetime';
- if ($item->canUsePluginDataInjection()) {
- //Datainjection specific
- $option['displaytype'] = 'date';
- $option['checktype'] = 'date';
- }
- if ($field == 'date_mod') {
- $option['massiveaction'] = false;
- }
- break;
- }
-
- $options[] = $option;
-
- $index = $currentindex + 1;
- }
-
- usort(
- $options,
- function ($a, $b) {
- return ($a['id'] < $b['id']) ? -1 : 1;
- }
- );
-
- return $options;
- }
-
-
- //Datainjection specific methods
- public function isPrimaryType()
- {
- return true;
- }
-
-
- public function connectedTo()
{
return [];
}
+ public static function install() {}
- /**
- * Standard method to add an object into glpi
- *
- * @param array $values fields to add into glpi
- * @param array $options options used during creation
- * @return array
- *
- **/
- public function addOrUpdateObject($values = [], $options = [])
- {
- //@phpstan-ignore-next-line
- $lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options);
- $lib->processAddOrUpdate();
- return $lib->getInjectionResults();
- }
-
-
- public function getOptions($primary_type = '')
- {
- return Search::getOptions($primary_type);
- }
-
-
- public function transfer($new_entity)
- {
- if ($this->fields['id'] > 0 && $this->fields['entities_id'] != $new_entity) {
- //Update entity for this object
- $tmp['id'] = $this->fields['id'];
- $tmp['entities_id'] = $new_entity;
- $this->update($tmp);
-
- $toupdate = ['id' => $this->fields['id']];
- foreach (PluginGenericobjectSingletonObjectField::getInstance(get_called_class()) as $field => $data) {
- $table = getTableNameForForeignKeyField($field);
-
- //It is a dropdown table !
- if (
- $field != 'entities_id'
- && $table != ''
- && isset($this->fields[$field]) && $this->fields[$field] > 0
- ) {
- //Instanciate a new dropdown object
- $dropdown_itemtype = getItemTypeForTable($table);
- $dropdown = new $dropdown_itemtype();
- $dropdown->getFromDB($this->fields[$field]);
-
- //If dropdown is only accessible in the other entity
- //do not go further
- if (!$dropdown->isEntityAssign() || in_array($new_entity, getAncestorsOf('glpi_entities', $dropdown->getEntityID()))) {
- continue;
- } else {
- $tmp = [];
- $where = [];
- if ($dropdown instanceof CommonTreeDropdown) {
- $tmp['completename'] = $dropdown->fields['completename'];
- $where['completename'] = Toolbox::addslashes_deep($tmp['completename']);
- } else {
- $tmp['name'] = $dropdown->fields['name'];
- $where['name'] = Toolbox::addslashes_deep($tmp['name']);
- }
- $tmp['entities_id'] = $new_entity;
- $where['entities_id'] = $tmp['entities_id'];
- //There's a dropdown value in the target entity
- if ($found = $dropdown->find($where)) {
- $myfound = array_pop($found);
- if ($myfound['id'] != $this->fields[$field]) {
- $toupdate[$field] = $myfound['id'];
- }
- } else {
- $clone = $dropdown->fields;
- if ($dropdown instanceof CommonTreeDropdown) {
- unset($clone['completename']);
- }
- unset($clone['id']);
- $clone['entities_id'] = $new_entity;
- $new_id = $dropdown->import($clone);
- $toupdate[$field] = $new_id;
- }
- }
- }
- }
- $this->update($toupdate);
- }
- return true;
- }
-
- /**
- * @since version 0.85
- *
- * @see CommonDBTM::showMassiveActionsSubForm()
- **/
- public static function showMassiveActionsSubForm(MassiveAction $ma)
- {
- // KK TODO: check if MassiveAction itemtypes are concerned
- //if (in_array ($options['itemtype'], $GENINVENTORYNUMBER_TYPES)) {
- switch ($ma->getAction()) {
- case "plugin_genericobject_transfer":
- Dropdown::show('Entity', ['name' => 'new_entity']);
- echo " ";
- break;
- default:
- break;
- }
- //}
- return true;
- }
-
- // @codingStandardsIgnoreStart
- public function plugin_genericobject_MassiveActionsProcess($data)
- {
- // @codingStandardsIgnoreEnd
- /** @var DBmysql $DB */
- global $DB;
-
- switch ($data['action']) {
- case 'plugin_genericobject_transfer':
- $item = new $data['itemtype']();
- foreach ($data["item"] as $key => $val) {
- if ($val == 1) {
- $item->getFromDB($key);
- $item->transfer($_POST['new_entity']);
- }
- }
- break;
- }
- }
-
- public static function processMassiveActionsForOneItemtype(
- MassiveAction $ma,
- CommonDBTM $item,
- array $ids
- ) {
- $results = [
- 'ok' => 0,
- 'ko' => 0,
- 'noright' => 0,
- 'messages' => []
- ];
-
- switch ($ma->action) {
- case "plugin_genericobject_transfer":
- foreach ($ma->items as $itemtype => $val) {
- foreach ($val as $key => $item_id) {
- $item = new $itemtype();
- $item->getFromDB($item_id);
- $item->transfer($_POST['new_entity']);
- $results['ok']++;
- }
- }
- break;
-
- default:
- break;
- }
- $ma->results = $results;
- }
-
- public static function getMenuContent()
- {
- $types = PluginGenericobjectType::getTypes();
- $menu = [];
- foreach ($types as $type) {
- $itemtype = $type['itemtype'];
- if (!class_exists($itemtype)) {
- continue;
- }
- $item = new $itemtype();
-
- $itemtype_rightname = PluginGenericobjectProfile::getProfileNameForItemtype($itemtype);
- if (
- class_exists($itemtype)
- && Session::haveRight($itemtype_rightname, READ)
- ) {
- $links = [];
- $links['search'] = $itemtype::getSearchUrl(false);
- $links['lists'] = '';
-
- if ($item->canUseTemplate()) {
- $links['template'] = "/front/setup.templates.php?itemtype=$itemtype&add=0";
- if (Session::haveRight($itemtype_rightname, CREATE)) {
- $links['add'] = "/front/setup.templates.php?itemtype=$itemtype&add=1";
- }
- } else {
- if (Session::haveRight($itemtype_rightname, CREATE)) {
- $links['add'] = $itemtype::getFormUrl(false);
- }
- }
-
- if (
- $type['plugin_genericobject_typefamilies_id'] > 0
- && (!isset($_GET['itemtype'])
- || !preg_match("/itemtype=" . $_GET['itemtype'] . "/", $_GET['itemtype']))
- ) {
- $family_id = $type['plugin_genericobject_typefamilies_id'];
- $name = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id, 0, false);
- $str_name = strtolower($name);
- $menu[$str_name]['title'] = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id);
- $menu[$str_name]['page'] = '/' . Plugin::getWebDir('genericobject', false) . '/front/familylist.php?id=' . $family_id;
- $menu[$str_name]['options'][strtolower($itemtype)] = [
- 'title' => $type['itemtype']::getMenuName(),
- 'page' => $itemtype::getSearchUrl(false),
- 'links' => $links,
- 'lists_itemtype' => $itemtype,
- ];
- } else {
- $menu[strtolower($itemtype)] = [
- 'title' => $type['itemtype']::getMenuName(),
- 'page' => $itemtype::getSearchUrl(false),
- 'links' => $links,
- 'lists_itemtype' => $itemtype,
- ];
- }
- }
- }
-
- // Sort by menu entries name
- uasort($menu, fn($a, $b) => $a['title'] <=> $b['title']);
-
- // Mark as multi entries
- $menu['is_multi_entries'] = true;
-
- return $menu;
- }
+ public static function uninstall() {}
}
diff --git a/inc/object_item.class.php b/inc/object_item.class.php
deleted file mode 100644
index ac86590e..00000000
--- a/inc/object_item.class.php
+++ /dev/null
@@ -1,138 +0,0 @@
-.
- * -------------------------------------------------------------------------
- * @copyright Copyright (C) 2009-2023 by GenericObject plugin team.
- * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
- * @link https://github.com/pluginsGLPI/genericobject
- * -------------------------------------------------------------------------
- */
-
-// @codingStandardsIgnoreStart
-class PluginGenericobjectObject_Item extends CommonDBChild
-{
- // @codingStandardsIgnoreEnd
- public $dohistory = true;
-
- // From CommonDBRelation
- public static $itemtype_1 = "PluginGenericobjectObject";
- public static $items_id_1 = 'plugin_genericobject_objects_id';
-
- public static $itemtype_2 = 'itemtype';
- public static $items_id_2 = 'items_id';
-
- //Get itemtype name
- public static function getTypeName($nb = 0)
- {
- /** @var array $LANG */
- global $LANG;
- $class = get_called_class();
- //Datainjection : Don't understand why I need this trick : need to be investigated !
- if (preg_match("/Injection$/i", $class)) {
- $class = str_replace("Injection", "", $class);
- }
- $item = new $class();
- //Itemtype name can be contained in a specific locale field : try to load it
- PluginGenericobjectType::includeLocales($item->objecttype->fields['name']);
- if (isset($LANG['genericobject'][$class][0])) {
- return $LANG['genericobject'][$class][0];
- } else {
- return $item->objecttype->fields['name'];
- }
- }
-
- public static function canView()
- {
- return Session::haveRight(self::$itemtype_1, READ);
- }
-
- public static function canCreate()
- {
- return Session::haveRight(self::$itemtype_1, CREATE);
- }
-
- /**
- *
- * Enter description here ...
- * @since 2.2.0
- * @param CommonDBTM $item
- */
- public static function showItemsForSource(CommonDBTM $item)
- {
- }
-
- /**
- *
- * Enter description here ...
- * @since 2.2.0
- * @param CommonDBTM $item
- */
- public static function showItemsForTarget(CommonDBTM $item)
- {
- }
-
- /**
- *
- * Enter description here ...
- * @since 2.2.0
- */
- public static function registerType()
- {
- Plugin::registerClass(get_called_class(), ['addtabon' => self::getLinkedItemTypes()]);
- }
-
- public static function getLinkedItemTypes()
- {
- $source_itemtype = self::getItemType1();
- $source_item = new $source_itemtype();
- return $source_item->getLinkedItemTypesAsArray();
- }
-
- public static function getItemType1()
- {
- $classname = get_called_class();
- return $classname::$itemtype_1;
- }
-
- public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
- {
- if (!$withtemplate) {
- $itemtypes = self::getLinkedItemTypes();
- if (in_array(get_class($item), $itemtypes) || get_class($item) == self::getItemType1()) {
- return [1 => __("Objects management", "genericobject")];
- }
- }
- return '';
- }
-
- public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
- {
- $itemtypes = self::getLinkedItemTypes();
- if (get_class($item) == self::getItemType1()) {
- self::showItemsForSource($item);
- } else if (in_array(get_class($item), $itemtypes)) {
- self::showItemsForTarget($item);
- }
- return true;
- }
-}
diff --git a/inc/profile.class.php b/inc/profile.class.php
index 988beb86..f8dd7e82 100644
--- a/inc/profile.class.php
+++ b/inc/profile.class.php
@@ -30,371 +30,17 @@
class PluginGenericobjectProfile extends Profile
{
- /* if profile deleted */
+ /* if profile deleted */
public function cleanProfiles($id)
{
$this->deleteByCriteria(['id' => $id]);
}
- public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
- {
- switch ($item->getType()) {
- case 'Profile':
- return self::createTabEntry(__('Objects management', 'genericobject'));
- case 'PluginGenericobjectType':
- return self::createTabEntry(_n('Profile', 'Profiles', 2));
- }
-
- return '';
- }
-
- public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
- {
- switch ($item->getType()) {
- case 'Profile':
- $profile = new self();
- $profile->showForm($item->getID());
- break;
- case 'PluginGenericobjectType':
- _log($item);
- self::showForItemtype($item);
- break;
- }
- return true;
- }
-
- public static function showForItemtype($type)
- {
- if (!Session::haveRight("profile", READ)) {
- return false;
- }
- self::installRights();
- $canedit = Session::haveRight("profile", UPDATE);
-
- echo "