From b5c987631f5b7438f059a2655c0e758527e6c534 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Fri, 27 Jun 2025 17:50:00 +0200 Subject: [PATCH 01/26] GLPI 11 compatibility --- .github/workflows/continuous-integration.yml | 2 +- composer.json | 6 +- composer.lock | 570 ++++++++----------- front/export.massive.php | 16 +- front/export.php | 12 +- hook.php | 2 +- inc/appliance.class.php | 8 +- inc/cartridge.class.php | 87 ++- inc/change_item.class.php | 75 +-- inc/change_problem.class.php | 44 +- inc/change_ticket.class.php | 52 +- inc/changetask.class.php | 10 +- inc/changevalidation.class.php | 10 +- inc/common.class.php | 21 +- inc/commonitilcost.class.php | 7 +- inc/computer_item.class.php | 48 +- inc/computer_softwarelicense.class.php | 118 ++-- inc/computer_softwareversion.class.php | 311 +++++++--- inc/computerantivirus.class.php | 6 +- inc/computervirtualmachine.class.php | 8 +- inc/config.class.php | 14 +- inc/consumableitem.class.php | 4 +- inc/document.class.php | 4 +- inc/group.class.php | 20 +- inc/item_device.class.php | 29 +- inc/item_disk.class.php | 4 +- inc/item_knowbaseitem.class.php | 4 +- inc/item_problem.class.php | 158 +++-- inc/item_softwarelicense.class.php | 120 ++-- inc/item_softwareversion.class.php | 247 +++++--- inc/item_ticket.class.php | 174 ++++-- inc/itilfollowup.class.php | 2 +- inc/itilsolution.class.php | 6 +- inc/knowbaseitem.class.php | 8 +- inc/networkport.class.php | 4 +- inc/preference.class.php | 121 ++-- inc/problem.class.php | 19 +- inc/profile.class.php | 20 +- inc/ticket.class.php | 4 +- inc/tickettask.class.php | 2 +- inc/ticketvalidation.class.php | 4 +- inc/user.class.php | 2 +- phpstan.neon | 3 +- setup.php | 8 +- templates/preference_form.html.twig | 185 ++++++ 45 files changed, 1550 insertions(+), 1029 deletions(-) create mode 100644 templates/preference_form.html.twig diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 2d1180d..62d4e17 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -53,7 +53,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/composer.json b/composer.json index abb3b8e..eff66ba 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "require": { - "php": ">=7.4", - "symfony/yaml": "^5.4", + "php": ">=8.2", + "symfony/yaml": "^7.3", "tecnickcom/tcpdf": "^6.4" }, "require-dev": { @@ -16,7 +16,7 @@ "config": { "optimize-autoloader": true, "platform": { - "php": "7.4.0" + "php": "8.2.99" }, "sort-packages": true, "allow-plugins": { diff --git a/composer.lock b/composer.lock index 2df0c14..821c3ea 100644 --- a/composer.lock +++ b/composer.lock @@ -4,24 +4,24 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8fd215cf6d5e2da742e395d9b0ebd8be", + "content-hash": "7aeed77d2efdc73fe57e884525e33e9c", "packages": [ { "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": { @@ -30,7 +30,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -55,7 +55,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": [ { @@ -71,11 +71,11 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -134,7 +134,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.32.0" }, "funding": [ { @@ -154,31 +154,28 @@ }, { "name": "symfony/yaml", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "a454d47278cc16a5db371fe73ae66a78a633371e" + "reference": "cea40a48279d58dc3efee8112634cb90141156c2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/a454d47278cc16a5db371fe73ae66a78a633371e", - "reference": "a454d47278cc16a5db371fe73ae66a78a633371e", + "url": "https://api.github.com/repos/symfony/yaml/zipball/cea40a48279d58dc3efee8112634cb90141156c2", + "reference": "cea40a48279d58dc3efee8112634cb90141156c2", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", + "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "symfony/console": "<5.3" + "symfony/console": "<6.4" }, "require-dev": { - "symfony/console": "^5.3|^6.0" - }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" + "symfony/console": "^6.4|^7.0" }, "bin": [ "Resources/bin/yaml-lint" @@ -209,7 +206,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v5.4.45" + "source": "https://github.com/symfony/yaml/tree/v7.3.0" }, "funding": [ { @@ -225,20 +222,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-04-04T10:10:33+00:00" }, { "name": "tecnickcom/tcpdf", - "version": "6.9.1", + "version": "6.10.0", "source": { "type": "git", "url": "https://github.com/tecnickcom/TCPDF.git", - "reference": "ed27e28a4c478f7f4015b5e7e7b1912af9e85f2b" + "reference": "ca5b6de294512145db96bcbc94e61696599c391d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/ed27e28a4c478f7f4015b5e7e7b1912af9e85f2b", - "reference": "ed27e28a4c478f7f4015b5e7e7b1912af9e85f2b", + "url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/ca5b6de294512145db96bcbc94e61696599c391d", + "reference": "ca5b6de294512145db96bcbc94e61696599c391d", "shasum": "" }, "require": { @@ -288,15 +285,15 @@ ], "support": { "issues": "https://github.com/tecnickcom/TCPDF/issues", - "source": "https://github.com/tecnickcom/TCPDF/tree/6.9.1" + "source": "https://github.com/tecnickcom/TCPDF/tree/6.10.0" }, "funding": [ { - "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_donations¤cy_code=GBP&business=paypal@tecnick.com&item_name=donation%20for%20tcpdf%20project", + "url": "https://www.paypal.com/donate/?hosted_button_id=NZUEC5XS8MFBJ", "type": "custom" } ], - "time": "2025-04-03T06:38:07+00:00" + "time": "2025-05-27T18:02:28+00:00" } ], "packages-dev": [ @@ -804,16 +801,16 @@ }, { "name": "friendsoftwig/twigcs", - "version": "v6.1.0", + "version": "6.5.0", "source": { "type": "git", "url": "https://github.com/friendsoftwig/twigcs.git", - "reference": "3c36d606c4f19db0dd2a01b735ec7a8151b7f182" + "reference": "aaa3ba112bf4fcee7b51a00d9b45b13bc2cc23bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/friendsoftwig/twigcs/zipball/3c36d606c4f19db0dd2a01b735ec7a8151b7f182", - "reference": "3c36d606c4f19db0dd2a01b735ec7a8151b7f182", + "url": "https://api.github.com/repos/friendsoftwig/twigcs/zipball/aaa3ba112bf4fcee7b51a00d9b45b13bc2cc23bc", + "reference": "aaa3ba112bf4fcee7b51a00d9b45b13bc2cc23bc", "shasum": "" }, "require": { @@ -822,14 +819,14 @@ "ext-json": "*", "ext-mbstring": "*", "ext-simplexml": "*", - "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0", - "symfony/console": "^4.4 || ^5.3 || ^6.0", - "symfony/filesystem": "^4.4 || ^5.3 || ^6.0", - "symfony/finder": "^4.4 || ^5.3 || ^6.0" + "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", + "symfony/console": "^4.4 || ^5.3 || ^6.0 || ^7.0", + "symfony/filesystem": "^4.4 || ^5.3 || ^6.0 || ^7.0", + "symfony/finder": "^4.4 || ^5.3 || ^6.0 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^9.5.20", - "symfony/phpunit-bridge": "^6.2.3" + "phpunit/phpunit": "^9.6.19", + "symfony/phpunit-bridge": "^7.1.4" }, "bin": [ "bin/twigcs" @@ -853,22 +850,22 @@ "description": "Checkstyle automation for Twig", "support": { "issues": "https://github.com/friendsoftwig/twigcs/issues", - "source": "https://github.com/friendsoftwig/twigcs/tree/v6.1.0" + "source": "https://github.com/friendsoftwig/twigcs/tree/6.5.0" }, - "time": "2023-01-04T16:01:24+00:00" + "time": "2024-11-27T21:59:24+00:00" }, { "name": "glpi-project/tools", - "version": "0.7.4", + "version": "0.7.5", "source": { "type": "git", "url": "https://github.com/glpi-project/tools.git", - "reference": "65a09a93350da6fa67d423dd94e4cb4023a17e20" + "reference": "c6ff4a7640384232ead150b46d4a647a14d12ab3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/glpi-project/tools/zipball/65a09a93350da6fa67d423dd94e4cb4023a17e20", - "reference": "65a09a93350da6fa67d423dd94e4cb4023a17e20", + "url": "https://api.github.com/repos/glpi-project/tools/zipball/c6ff4a7640384232ead150b46d4a647a14d12ab3", + "reference": "c6ff4a7640384232ead150b46d4a647a14d12ab3", "shasum": "" }, "require": { @@ -911,7 +908,7 @@ "issues": "https://github.com/glpi-project/tools/issues", "source": "https://github.com/glpi-project/tools" }, - "time": "2024-09-18T06:58:02+00:00" + "time": "2025-05-22T07:31:28+00:00" }, { "name": "php-parallel-lint/php-parallel-lint", @@ -1024,16 +1021,16 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.11", + "version": "2.1.17", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30" + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8ca5f79a8f63c49b2359065832a654e1ec70ac30", - "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/89b5ef665716fa2a52ecd2633f21007a6a349053", + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053", "shasum": "" }, "require": { @@ -1078,25 +1075,25 @@ "type": "github" } ], - "time": "2025-03-24T13:45:00+00:00" + "time": "2025-05-21T20:55:28+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4" + "reference": "468e02c9176891cc901143da118f09dc9505fc2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", - "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/468e02c9176891cc901143da118f09dc9505fc2f", + "reference": "468e02c9176891cc901143da118f09dc9505fc2f", "shasum": "" }, "require": { "php": "^7.4 || ^8.0", - "phpstan/phpstan": "^2.0" + "phpstan/phpstan": "^2.1.15" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", @@ -1123,28 +1120,33 @@ "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", "support": { "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.1" + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.3" }, - "time": "2024-11-28T21:56:36+00:00" + "time": "2025-05-14T10:56:57+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/" @@ -1171,9 +1173,9 @@ ], "support": { "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.2" + "source": "https://github.com/php-fig/container/tree/2.0.2" }, - "time": "2021-11-05T16:50:12+00:00" + "time": "2021-11-05T16:47:00+00:00" }, { "name": "psr/event-dispatcher", @@ -1227,30 +1229,30 @@ }, { "name": "psr/log", - "version": "1.1.4", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=8.0.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "3.x-dev" } }, "autoload": { "psr-4": { - "Psr\\Log\\": "Psr/Log/" + "Psr\\Log\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1271,9 +1273,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.4" + "source": "https://github.com/php-fig/log/tree/3.0.2" }, - "time": "2021-05-03T11:20:27+00:00" + "time": "2024-09-11T13:17:53+00:00" }, { "name": "react/cache", @@ -1803,29 +1805,29 @@ }, { "name": "sebastian/diff", - "version": "4.0.6", + "version": "6.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", - "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^9.3", + "phpunit/phpunit": "^11.0", "symfony/process": "^4.2 || ^5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-main": "6.0-dev" } }, "autoload": { @@ -1857,7 +1859,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/6.0.2" }, "funding": [ { @@ -1865,56 +1868,51 @@ "type": "github" } ], - "time": "2024-03-02T06:30:58+00:00" + "time": "2024-07-03T04:53:05+00:00" }, { "name": "symfony/console", - "version": "v5.4.47", + "version": "v6.4.22", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed" + "reference": "7d29659bc3c9d8e9a34e2c3414ef9e9e003e6cf3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", + "url": "https://api.github.com/repos/symfony/console/zipball/7d29659bc3c9d8e9a34e2c3414ef9e9e003e6cf3", + "reference": "7d29659bc3c9d8e9a34e2c3414ef9e9e003e6cf3", "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": { @@ -1948,7 +1946,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.47" + "source": "https://github.com/symfony/console/tree/v6.4.22" }, "funding": [ { @@ -1964,48 +1962,43 @@ "type": "tidelift" } ], - "time": "2024-11-06T11:30:55+00:00" + "time": "2025-05-07T07:05:04+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "72982eb416f61003e9bb6e91f8b3213600dcf9e9" + "reference": "497f73ac996a598c92409b44ac43b6690c4f666d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/72982eb416f61003e9bb6e91f8b3213600dcf9e9", - "reference": "72982eb416f61003e9bb6e91f8b3213600dcf9e9", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/497f73ac996a598c92409b44ac43b6690c4f666d", + "reference": "497f73ac996a598c92409b44ac43b6690c4f666d", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/event-dispatcher-contracts": "^2|^3", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2", + "symfony/event-dispatcher-contracts": "^2.5|^3" }, "conflict": { - "symfony/dependency-injection": "<4.4" + "symfony/dependency-injection": "<6.4", + "symfony/service-contracts": "<2.5" }, "provide": { "psr/event-dispatcher-implementation": "1.0", - "symfony/event-dispatcher-implementation": "2.0" + "symfony/event-dispatcher-implementation": "2.0|3.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/error-handler": "^4.4|^5.0|^6.0", - "symfony/expression-language": "^4.4|^5.0|^6.0", - "symfony/http-foundation": "^4.4|^5.0|^6.0", - "symfony/service-contracts": "^1.1|^2|^3", - "symfony/stopwatch": "^4.4|^5.0|^6.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/error-handler": "^6.4|^7.0", + "symfony/expression-language": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/stopwatch": "^6.4|^7.0" }, "type": "library", "autoload": { @@ -2033,7 +2026,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v5.4.45" + "source": "https://github.com/symfony/event-dispatcher/tree/v7.3.0" }, "funding": [ { @@ -2049,29 +2042,26 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-04-22T09:11:45+00:00" }, { "name": "symfony/event-dispatcher-contracts", - "version": "v2.5.4", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "e0fe3d79b516eb75126ac6fa4cbf19b79b08c99f" + "reference": "59eb412e93815df44f05f342958efa9f46b1e586" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/e0fe3d79b516eb75126ac6fa4cbf19b79b08c99f", - "reference": "e0fe3d79b516eb75126ac6fa4cbf19b79b08c99f", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586", + "reference": "59eb412e93815df44f05f342958efa9f46b1e586", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=8.1", "psr/event-dispatcher": "^1" }, - "suggest": { - "symfony/event-dispatcher-implementation": "" - }, "type": "library", "extra": { "thanks": { @@ -2079,7 +2069,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -2112,7 +2102,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v2.5.4" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.6.0" }, "funding": [ { @@ -2128,30 +2118,29 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/filesystem", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54" + "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/57c8294ed37d4a055b77057827c67f9558c95c54", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b8dce482de9d7c9fe2891155035a7248ab5c7fdb", + "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=8.2", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8", - "symfony/polyfill-php80": "^1.16" + "symfony/polyfill-mbstring": "~1.8" }, "require-dev": { - "symfony/process": "^5.4|^6.4" + "symfony/process": "^6.4|^7.0" }, "type": "library", "autoload": { @@ -2179,7 +2168,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.45" + "source": "https://github.com/symfony/filesystem/tree/v7.3.0" }, "funding": [ { @@ -2195,26 +2184,27 @@ "type": "tidelift" } ], - "time": "2024-10-22T13:05:35+00:00" + "time": "2024-10-25T15:15:23+00:00" }, { "name": "symfony/finder", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "63741784cd7b9967975eec610b256eed3ede022b" + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/63741784cd7b9967975eec610b256eed3ede022b", - "reference": "63741784cd7b9967975eec610b256eed3ede022b", + "url": "https://api.github.com/repos/symfony/finder/zipball/ec2344cf77a48253bbca6939aa3d2477773ea63d", + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2" + }, + "require-dev": { + "symfony/filesystem": "^6.4|^7.0" }, "type": "library", "autoload": { @@ -2242,7 +2232,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.4.45" + "source": "https://github.com/symfony/finder/tree/v7.3.0" }, "funding": [ { @@ -2258,27 +2248,25 @@ "type": "tidelift" } ], - "time": "2024-09-28T13:32:08+00:00" + "time": "2024-12-30T19:00:26+00:00" }, { "name": "symfony/options-resolver", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "74e5b6f0db3e8589e6cfd5efb317a1fc2bb52fb6" + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/74e5b6f0db3e8589e6cfd5efb317a1fc2bb52fb6", - "reference": "74e5b6f0db3e8589e6cfd5efb317a1fc2bb52fb6", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/afb9a8038025e5dbc657378bfab9198d75f10fca", + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-php73": "~1.0", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3" }, "type": "library", "autoload": { @@ -2311,7 +2299,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v5.4.45" + "source": "https://github.com/symfony/options-resolver/tree/v7.3.0" }, "funding": [ { @@ -2327,11 +2315,11 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-04-04T13:12:05+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", @@ -2389,7 +2377,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.32.0" }, "funding": [ { @@ -2409,7 +2397,7 @@ }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -2470,7 +2458,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.32.0" }, "funding": [ { @@ -2490,19 +2478,20 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" + "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493", + "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493", "shasum": "" }, "require": { + "ext-iconv": "*", "php": ">=7.2" }, "provide": { @@ -2550,7 +2539,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.32.0" }, "funding": [ { @@ -2566,96 +2555,20 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" - }, - { - "name": "symfony/polyfill-php73", - "version": "v1.31.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.31.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-12-23T08:48:59+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608", + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608", "shasum": "" }, "require": { @@ -2706,7 +2619,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.32.0" }, "funding": [ { @@ -2722,11 +2635,11 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-01-02T08:10:11+00:00" }, { "name": "symfony/polyfill-php81", - "version": "v1.31.0", + "version": "v1.32.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php81.git", @@ -2782,7 +2695,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.32.0" }, "funding": [ { @@ -2802,21 +2715,20 @@ }, { "name": "symfony/process", - "version": "v5.4.47", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "5d1662fb32ebc94f17ddb8d635454a776066733d" + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/5d1662fb32ebc94f17ddb8d635454a776066733d", - "reference": "5d1662fb32ebc94f17ddb8d635454a776066733d", + "url": "https://api.github.com/repos/symfony/process/zipball/40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2" }, "type": "library", "autoload": { @@ -2844,7 +2756,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v5.4.47" + "source": "https://github.com/symfony/process/tree/v7.3.0" }, "funding": [ { @@ -2860,33 +2772,30 @@ "type": "tidelift" } ], - "time": "2024-11-06T11:36:42+00:00" + "time": "2025-04-17T09:11:12+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": { @@ -2894,13 +2803,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": [ @@ -2927,7 +2839,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": [ { @@ -2943,25 +2855,25 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-04-25T09:37:31+00:00" }, { "name": "symfony/stopwatch", - "version": "v5.4.45", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "fb2c199cf302eb207f8c23e7ee174c1c31a5c004" + "reference": "5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/fb2c199cf302eb207f8c23e7ee174c1c31a5c004", - "reference": "fb2c199cf302eb207f8c23e7ee174c1c31a5c004", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd", + "reference": "5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/service-contracts": "^1|^2|^3" + "php": ">=8.2", + "symfony/service-contracts": "^2.5|^3" }, "type": "library", "autoload": { @@ -2989,7 +2901,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v5.4.45" + "source": "https://github.com/symfony/stopwatch/tree/v7.3.0" }, "funding": [ { @@ -3005,38 +2917,39 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-02-24T10:49:57+00:00" }, { "name": "symfony/string", - "version": "v5.4.47", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "136ca7d72f72b599f2631aca474a4f8e26719799" + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/136ca7d72f72b599f2631aca474a4f8e26719799", - "reference": "136ca7d72f72b599f2631aca474a4f8e26719799", + "url": "https://api.github.com/repos/symfony/string/zipball/f3570b8c61ca887a9e2938e85cb6458515d2b125", + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125", "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": { @@ -3075,7 +2988,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.47" + "source": "https://github.com/symfony/string/tree/v7.3.0" }, "funding": [ { @@ -3091,31 +3004,30 @@ "type": "tidelift" } ], - "time": "2024-11-10T20:33:58+00:00" + "time": "2025-04-20T20:19:01+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" }, @@ -3159,7 +3071,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": [ { @@ -3171,7 +3083,7 @@ "type": "tidelift" } ], - "time": "2024-11-07T12:34:41+00:00" + "time": "2025-05-03T07:21:55+00:00" } ], "aliases": [], @@ -3180,11 +3092,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/front/export.massive.php b/front/export.massive.php index 0fab385..fac0208 100644 --- a/front/export.massive.php +++ b/front/export.massive.php @@ -45,12 +45,14 @@ /** @var \DBmysql $DB */ global $DB; -$result = $DB->request( - 'glpi_plugin_pdf_preferences', - ['SELECT' => 'tabref', - 'WHERE' => ['users_ID' => $_SESSION['glpiID'], - 'itemtype' => $type]], -); +$result = $DB->request([ + 'FROM' => 'glpi_plugin_pdf_preferences', + 'SELECT' => 'tabref', + 'WHERE' => [ + 'users_ID' => $_SESSION['glpiID'], + 'itemtype' => $type + ] +]); $tab = []; @@ -69,5 +71,5 @@ $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); $itempdf->generatePDF($tab_id, $tab, (isset($pag) ? $pag : 0)); } else { - die('Missing hook'); + throw new \RuntimeException('Missing PDF plugin hook for type: ' . $type); } diff --git a/front/export.php b/front/export.php index d3df80e..37d8143 100644 --- a/front/export.php +++ b/front/export.php @@ -30,6 +30,9 @@ * -------------------------------------------------------------------------- */ +/** @var array $PLUGIN_HOOKS */ +global $PLUGIN_HOOKS; + define('GLPI_KEEP_CSRF_TOKEN', true); // 0.90 $token = (isset($_POST['_glpi_csrf_token']) ? $_POST['_glpi_csrf_token'] : false); @@ -37,11 +40,6 @@ Session::checkRight('plugin_pdf', READ); -/* 0.85 Hack to allow multiple exports, yes this is an hack, yes an awful one */ -if (!isset($_SESSION['glpicsrftokens'][$token])) { - $_SESSION['glpicsrftokens'][$token] = time() + GLPI_CSRF_EXPIRES; -} - Plugin::load('pdf', true); $dbu = new DbUtils(); @@ -74,8 +72,8 @@ $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); $itempdf->generatePDF([$_POST['itemID']], $tab, (isset($_POST['page']) ? $_POST['page'] : 0)); } else { - die('Missing hook'); + throw new \RuntimeException('Missing PDF plugin hook for type: ' . $type); } } else { - die('Missing context'); + throw new \InvalidArgumentException('Missing required context or parameters for PDF generation'); } diff --git a/hook.php b/hook.php index d6150bf..bd2507d 100644 --- a/hook.php +++ b/hook.php @@ -99,7 +99,7 @@ function plugin_pdf_uninstall() $query = "DELETE FROM `glpi_profilerights` WHERE `name` = 'plugin_pdf'"; - $DB->doQueryOrDie($query, $DB->error()); + $DB->doQuery($query); $migration->executeMigration(); diff --git a/inc/appliance.class.php b/inc/appliance.class.php index cf23ca8..61fa5be 100644 --- a/inc/appliance.class.php +++ b/inc/appliance.class.php @@ -220,9 +220,11 @@ public static function pdfForAppliance(PluginPdfSimplePDF $pdf, Appliance $appli $pdf->setColumnsSize(100); $pdf->displayTitle('' . _n('Associated item', 'Associated items', 2) . ''); - $result = $DB->request('SELECT DISTINCT `itemtype` - FROM `glpi_appliances_items` - WHERE `appliances_id` = ' . $instID); + $result = $DB->request([ + 'SELECT' => 'DISTINCT itemtype', + 'FROM' => 'glpi_appliances_items', + 'WHERE' => ['appliances_id' => $instID] + ]); $number = count($result); if (Session::isMultiEntitiesMode()) { diff --git a/inc/cartridge.class.php b/inc/cartridge.class.php index 266368d..229e534 100644 --- a/inc/cartridge.class.php +++ b/inc/cartridge.class.php @@ -62,26 +62,46 @@ public static function pdfForPrinter(PluginPdfSimplePDF $pdf, Printer $p, $old = if ($old) { $dateout = ' IS NOT NULL '; } - $query = 'SELECT `glpi_cartridgeitems`.`id` AS tID, - `glpi_cartridgeitems`.`is_deleted`, - `glpi_cartridgeitems`.`ref`, - `glpi_cartridgeitems`.`name` AS type, - `glpi_cartridges`.`id`, - `glpi_cartridges`.`pages`, - `glpi_cartridges`.`date_use`, - `glpi_cartridges`.`date_out`, - `glpi_cartridges`.`date_in`, - `glpi_cartridgeitemtypes`.`name` AS typename - FROM `glpi_cartridges`, - `glpi_cartridgeitems` - LEFT JOIN `glpi_cartridgeitemtypes` - ON (`glpi_cartridgeitems`.`cartridgeitemtypes_id` = `glpi_cartridgeitemtypes`.`id`) - WHERE `glpi_cartridges`.`date_out` ' . $dateout . " - AND `glpi_cartridges`.`printers_id` = '" . $instID . "' - AND `glpi_cartridges`.`cartridgeitems_id` = `glpi_cartridgeitems`.`id` - ORDER BY `glpi_cartridges`.`date_out` ASC, - `glpi_cartridges`.`date_use` DESC, - `glpi_cartridges`.`date_in`"; + $query = [ + 'SELECT' => [ + 'glpi_cartridgeitems.id AS tID', + 'glpi_cartridgeitems.is_deleted', + 'glpi_cartridgeitems.ref', + 'glpi_cartridgeitems.name AS type', + 'glpi_cartridges.id', + 'glpi_cartridges.pages', + 'glpi_cartridges.date_use', + 'glpi_cartridges.date_out', + 'glpi_cartridges.date_in', + 'glpi_cartridgeitemtypes.name AS typename' + ], + 'FROM' => 'glpi_cartridges', + 'INNER JOIN' => [ + 'glpi_cartridgeitems' => [ + 'FKEY' => [ + 'glpi_cartridges' => 'cartridgeitems_id', + 'glpi_cartridgeitems' => 'id' + ] + ] + ], + 'LEFT JOIN' => [ + 'glpi_cartridgeitemtypes' => [ + 'FKEY' => [ + 'glpi_cartridgeitems' => 'cartridgeitemtypes_id', + 'glpi_cartridgeitemtypes' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_cartridges.printers_id' => $instID, + 'glpi_cartridges.date_out' => ($old ? ['NOT' => null] : null) + ], + 'ORDER' => [ + 'glpi_cartridges.date_out ASC', + 'glpi_cartridges.date_use DESC', + 'glpi_cartridges.date_in' + ] + ]; $result = $DB->request($query); $number = count($result); @@ -245,18 +265,25 @@ public static function pdfForCartridgeItem(PluginPdfSimplePDF $pdf, CartridgeIte $pages_printed = 0; $nb_pages_printed = 0; - $iterator = $DB->request( - Cartridge::gettable(), - ['SELECT' => ['glpi_cartridges.*', + $iterator = $DB->request([ + 'FROM' => Cartridge::getTable(), + 'SELECT' => [ + 'glpi_cartridges.*', 'glpi_printers.id AS printID', 'glpi_printers.name AS printname', - 'glpi_printers.init_pages_counter'], - 'LEFT JOIN' => ['glpi_printers' - => ['FKEY' => [Cartridge::getTable() => 'printers_id', - 'glpi_printers' => 'id']]], - 'WHERE' => $where, - 'ORDER' => $order], - ); + 'glpi_printers.init_pages_counter' + ], + 'LEFT JOIN' => [ + 'glpi_printers' => [ + 'FKEY' => [ + Cartridge::getTable() => 'printers_id', + 'glpi_printers' => 'id' + ] + ] + ], + 'WHERE' => $where, + 'ORDER' => $order + ]); $number = count($iterator); diff --git a/inc/change_item.class.php b/inc/change_item.class.php index daebdde..d2a4c35 100644 --- a/inc/change_item.class.php +++ b/inc/change_item.class.php @@ -52,13 +52,13 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) return false; } - $result = $DB->request( - 'glpi_changes_items', - ['SELECT' => 'itemtype', - 'DISTINCT' => true, - 'WHERE' => ['changes_id' => $instID], - 'ORDER' => 'itemtype'], - ); + $result = $DB->request([ + 'FROM' => 'glpi_changes_items', + 'SELECT' => 'itemtype', + 'DISTINCT' => true, + 'WHERE' => ['changes_id' => $instID], + 'ORDER' => 'itemtype' + ]); $number = count($result); $pdf->setColumnsSize(100); @@ -115,7 +115,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $query['ORDER'] = ['glpi_entities.completename', $itemtable . '.name']; - $result_linked = $DB->request($query, '', true); + $result_linked = $DB->request($query); $nb = count($result_linked); $prem = true; @@ -193,33 +193,42 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr break; } - $SELECT = ''; - $FROM = ''; + $SELECT = ['glpi_changes.*', 'glpi_itilcategories.completename AS catname']; + $LEFT_JOIN = [ + 'glpi_changes_items' => [ + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_items' => 'changes_id'] + ], + 'glpi_changes_groups' => [ + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_groups' => 'changes_id'] + ], + 'glpi_changes_users' => [ + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_users' => 'changes_id'] + ], + 'glpi_changes_suppliers' => [ + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_suppliers' => 'changes_id'] + ], + 'glpi_itilcategories' => [ + 'FKEY' => ['glpi_changes' => 'itilcategories_id', 'glpi_itilcategories' => 'id'] + ] + ]; + if (count($_SESSION['glpiactiveentities']) > 1) { - $SELECT = ', `glpi_entities`.`completename` AS entityname, - `glpi_changes`.`entities_id` AS entityID '; - $FROM = ' LEFT JOIN `glpi_entities` - ON (`glpi_entities`.`id` = `glpi_changes`.`entities_id`) '; + $SELECT[] = 'glpi_entities.completename AS entityname'; + $SELECT[] = 'glpi_changes.entities_id AS entityID'; + $LEFT_JOIN['glpi_entities'] = [ + 'FKEY' => ['glpi_entities' => 'id', 'glpi_changes' => 'entities_id'] + ]; } - $query = "SELECT DISTINCT `glpi_changes`.*, - `glpi_itilcategories`.`completename` AS catname - $SELECT - FROM `glpi_changes` - LEFT JOIN `glpi_changes_items` - ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) - LEFT JOIN `glpi_changes_groups` - ON (`glpi_changes`.`id` = `glpi_changes_groups`.`changes_id`) - LEFT JOIN `glpi_changes_users` - ON (`glpi_changes`.`id` = `glpi_changes_users`.`changes_id`) - LEFT JOIN `glpi_changes_suppliers` - ON (`glpi_changes`.`id` = `glpi_changes_suppliers`.`changes_id`) - LEFT JOIN `glpi_itilcategories` - ON (`glpi_changes`.`itilcategories_id` = `glpi_itilcategories`.`id`) - $FROM - WHERE $restrict " . - $dbu->getEntitiesRestrictRequest('AND', 'glpi_changes') . " - ORDER BY $order - LIMIT " . intval($_SESSION['glpilist_limit']); + + $query = [ + 'SELECT' => $SELECT, + 'DISTINCT' => true, + 'FROM' => 'glpi_changes', + 'LEFT JOIN' => $LEFT_JOIN, + 'WHERE' => [$restrict] + $dbu->getEntitiesRestrictCriteria('glpi_changes'), + 'ORDER' => $order, + 'LIMIT' => (int)$_SESSION['glpilist_limit'] + ]; $result = $DB->request($query); $number = count($result); diff --git a/inc/change_problem.class.php b/inc/change_problem.class.php index 5bb0d1a..79579c9 100644 --- a/inc/change_problem.class.php +++ b/inc/change_problem.class.php @@ -52,17 +52,17 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) return false; } - $result = $DB->request( - 'glpi_changes_problems', - ['SELECT' => 'glpi_changes_problems.id', - 'DISTINCT' => true, - 'FIELDS' => ['glpi_problems.*', 'name'], - 'LEFT JOIN' => ['glpi_problems' - => ['FKEY' => ['glpi_changes_problems' => 'problems_id', - 'glpi_problems' => 'id']]], - 'WHERE' => ['changes_id' => $ID], - 'ORDER' => 'name'], - ); + $result = $DB->request([ + 'SELECT' => ['glpi_changes_problems.id'], + 'DISTINCT' => true, + 'FROM' => 'glpi_changes_problems', + 'FIELDS' => ['glpi_problems.*', 'name'], + 'LEFT JOIN' => ['glpi_problems' + => ['FKEY' => ['glpi_changes_problems' => 'problems_id', + 'glpi_problems' => 'id']]], + 'WHERE' => ['changes_id' => $ID], + 'ORDER' => 'name' + ]); $number = count($result); $problems = []; @@ -294,17 +294,17 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) return false; } - $result = $DB->request( - 'glpi_changes_problems', - ['SELECT' => 'glpi_changes_problems.id', - 'DISTINCT' => true, - 'FIELDS' => ['glpi_changes.*', 'name'], - 'LEFT JOIN' => ['glpi_changes' - => ['FKEY' => ['glpi_changes_problems' => 'changes_id', - 'glpi_changes' => 'id']]], - 'WHERE' => ['problems_id' => $ID], - 'ORDER' => 'name'], - ); + $result = $DB->request([ + 'SELECT' => ['glpi_changes_problems.id'], + 'DISTINCT' => true, + 'FROM' => 'glpi_changes_problems', + 'FIELDS' => ['glpi_changes.*', 'name'], + 'LEFT JOIN' => ['glpi_changes' + => ['FKEY' => ['glpi_changes_problems' => 'changes_id', + 'glpi_changes' => 'id']]], + 'WHERE' => ['problems_id' => $ID], + 'ORDER' => 'name' + ]); $number = count($result); $problems = []; diff --git a/inc/change_ticket.class.php b/inc/change_ticket.class.php index bdf9537..476eb9b 100644 --- a/inc/change_ticket.class.php +++ b/inc/change_ticket.class.php @@ -52,17 +52,17 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) return false; } - $result = $DB->request( - 'glpi_changes_tickets', - ['SELECT' => 'glpi_changes_tickets.id', - 'DISTINCT' => true, - 'FIELDS' => ['glpi_tickets.*', 'name'], - 'LEFT JOIN' => ['glpi_tickets' - => ['FKEY' => ['glpi_changes_tickets' => 'tickets_id', - 'glpi_tickets' => 'id']]], - 'WHERE' => ['changes_id' => $ID], - 'ORDER' => 'name'], - ); + $result = $DB->request([ + 'SELECT' => ['glpi_changes_tickets.id'], + 'DISTINCT' => true, + 'FROM' => 'glpi_changes_tickets', + 'FIELDS' => ['glpi_tickets.*', 'name'], + 'LEFT JOIN' => ['glpi_tickets' + => ['FKEY' => ['glpi_changes_tickets' => 'tickets_id', + 'glpi_tickets' => 'id']]], + 'WHERE' => ['changes_id' => $ID], + 'ORDER' => 'name' + ]); $number = count($result); $pdf->setColumnsSize(100); @@ -274,10 +274,10 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $first = true; $listitems = $texteitem = ''; - foreach ($DB->request( - 'glpi_items_tickets', - ['WHERE' => ['tickets_id' => $job->fields['id']]], - ) as $data) { + foreach ($DB->request([ + 'FROM' => 'glpi_items_tickets', + 'WHERE' => ['tickets_id' => $job->fields['id']] + ]) as $data) { if (!($item = $dbu->getItemForItemtype($data['itemtype']))) { continue; } @@ -322,17 +322,17 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) return false; } - $result = $DB->request( - 'glpi_changes_tickets', - ['SELECT' => 'glpi_changes_tickets.id', - 'DISTINCT' => true, - 'FIELDS' => ['glpi_changes.*', 'name'], - 'LEFT JOIN' => ['glpi_changes' - => ['FKEY' => ['glpi_changes_tickets' => 'changes_id', - 'glpi_changes' => 'id']]], - 'WHERE' => ['tickets_id' => $ID], - 'ORDER' => 'name'], - ); + $result = $DB->request([ + 'SELECT' => ['glpi_changes_tickets.id'], + 'DISTINCT' => true, + 'FROM' => 'glpi_changes_tickets', + 'FIELDS' => ['glpi_changes.*', 'name'], + 'LEFT JOIN' => ['glpi_changes' + => ['FKEY' => ['glpi_changes_tickets' => 'changes_id', + 'glpi_changes' => 'id']]], + 'WHERE' => ['tickets_id' => $ID], + 'ORDER' => 'name' + ]); $number = count($result); $pdf->setColumnsSize(100); diff --git a/inc/changetask.class.php b/inc/changetask.class.php index a54058c..4ddf1d8 100644 --- a/inc/changetask.class.php +++ b/inc/changetask.class.php @@ -48,11 +48,11 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $job) $ID = $job->getField('id'); - $result = $DB->request( - 'glpi_changetasks', - ['WHERE' => ['changes_id' => $ID], - 'ORDER' => 'date DESC'], - ); + $result = $DB->request([ + 'FROM' => 'glpi_changetasks', + 'WHERE' => ['changes_id' => $ID], + 'ORDER' => 'date DESC' + ]); $number = count($result); diff --git a/inc/changevalidation.class.php b/inc/changevalidation.class.php index bc8d797..abb30f5 100644 --- a/inc/changevalidation.class.php +++ b/inc/changevalidation.class.php @@ -61,11 +61,11 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) } $ID = $change->getField('id'); - $result = $DB->request( - 'glpi_changevalidations', - ['WHERE' => ['changes_id' => $change->getField('id')], - 'ORDER' => 'submission_date DESC'], - ); + $result = $DB->request([ + 'FROM' => 'glpi_changevalidations', + 'WHERE' => ['changes_id' => $change->getField('id')], + 'ORDER' => 'submission_date DESC' + ]); $number = count($result); $pdf->setColumnsSize(100); diff --git a/inc/common.class.php b/inc/common.class.php index 7d6a289..91e49c9 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -123,7 +123,13 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (Session::haveRight('plugin_pdf', READ)) { if (empty($withtemplate)) { - return __('Print to pdf', 'pdf'); + $icon_html = sprintf('', 'file-type-pdf'); + + return sprintf( + '%s%s', + $icon_html, + __('Print to pdf', 'pdf'), + ); } } return ''; @@ -280,8 +286,11 @@ final public static function displayCommonTabForPDF(PluginPdfSimplePDF $pdf, Com **/ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + $pref = new PluginPdfPreference(); - $pref->menu($item, Plugin::getWebDir('pdf') . '/front/export.php'); + $pref->menu($item, $CFG_GLPI['root_doc'] . '/plugins/pdf/front/export.php'); return true; } @@ -308,7 +317,7 @@ private function addHeader($ID) if (Session::isMultiEntitiesMode() && $this->obj->isEntityAssign()) { $entity = ' (' . Dropdown::getDropdownName('glpi_entities', $this->obj->getEntityID()) . ')'; } - $header = Glpi\Toolbox\Sanitizer::unsanitize(sprintf( + $header = sprintf( __('%1$s - %2$s'), $this->obj->getTypeName(), sprintf( @@ -316,7 +325,7 @@ private function addHeader($ID) $name, $entity, ), - )); + ); $this->pdf->setHeader($header); return true; @@ -621,9 +630,9 @@ public static function processMassiveActionsForOneItemtype( } $_SESSION['plugin_pdf']['type'] = $item->getType(); $_SESSION['plugin_pdf']['tab_id'] = serialize($tab_id); - $webDir = Plugin::getWebDir('pdf'); + $webDir = Plugin::getPhpDir('pdf', false); echo ""; + location.href='/plugins/pdf/front/export.massive.php'"; break; } } diff --git a/inc/commonitilcost.class.php b/inc/commonitilcost.class.php index 2d01a00..378354a 100644 --- a/inc/commonitilcost.class.php +++ b/inc/commonitilcost.class.php @@ -49,8 +49,11 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $job) $table = 'glpi_' . (strtolower($type)) . 'costs'; $classname = $type . 'Cost'; - $result = $DB->request($table, ['WHERE' => [$job->getForeignKeyField() => $ID], - 'ORDER' => 'begin_date']); + $result = $DB->request([ + 'FROM' => $table, + 'WHERE' => [$job->getForeignKeyField() => $ID], + 'ORDER' => 'begin_date' + ]); $number = count($result); diff --git a/inc/computer_item.class.php b/inc/computer_item.class.php index d1b4d14..9332a4b 100644 --- a/inc/computer_item.class.php +++ b/inc/computer_item.class.php @@ -1,5 +1,7 @@ obj = ($obj ? $obj : new Computer_Item()); + $this->obj = ($obj ? $obj : new Asset_PeripheralAsset()); } public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) @@ -65,21 +67,33 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) if (!$item->canView()) { continue; } - $query = 'SELECT `glpi_computers_items`.`id` AS assoc_id, - `glpi_computers_items`.`computers_id` AS assoc_computers_id, - `glpi_computers_items`.`itemtype`, - `glpi_computers_items`.`items_id`, - `glpi_computers_items`.`is_dynamic` AS assoc_is_dynamic, - ' . $dbu->getTableForItemType($type) . '.* - FROM `glpi_computers_items` - LEFT JOIN `' . $dbu->getTableForItemType($type) . '` - ON (`' . $dbu->getTableForItemType($type) . "`.`id` - = `glpi_computers_items`.`items_id`) - WHERE `computers_id` = '$ID' - AND `itemtype` = '" . $type . "' - AND `glpi_computers_items`.`is_deleted` = '0'"; + $itemTable = $dbu->getTableForItemType($type); + $query = [ + 'SELECT' => [ + 'glpi_assets_assets_peripheralassets.id AS assoc_id', + 'glpi_assets_assets_peripheralassets.computers_id AS assoc_computers_id', + 'glpi_assets_assets_peripheralassets.itemtype', + 'glpi_assets_assets_peripheralassets.items_id', + 'glpi_assets_assets_peripheralassets.is_dynamic AS assoc_is_dynamic' + ], + 'FROM' => 'glpi_assets_assets_peripheralassets', + 'LEFT JOIN' => [ + $itemTable => [ + 'FKEY' => [ + $itemTable => 'id', + 'glpi_assets_assets_peripheralassets' => 'items_id' + ] + ] + ], + 'WHERE' => [ + 'computers_id' => $ID, + 'itemtype' => $type, + 'glpi_assets_assets_peripheralassets.is_deleted' => 0 + ] + ]; + if ($item->maybetemplate()) { - $query .= ' AND NOT `' . $dbu->getTableForItemType($type) . '`.`is_template` '; + $query['WHERE'][$itemTable . '.is_template'] = 0; } $result = $DB->request($query); @@ -183,9 +197,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); $title = '' . __('Direct connections') . ''; - $result = $DB->request( - 'glpi_computers_items', - ['items_id' => $ID, + $result = $DB->request(['FROM' => 'glpi_assets_assets_peripheralassets'] + ['items_id' => $ID, 'itemtype' => $type], ); $resultnum = count($result); diff --git a/inc/computer_softwarelicense.class.php b/inc/computer_softwarelicense.class.php index b401c57..696ec2e 100644 --- a/inc/computer_softwarelicense.class.php +++ b/inc/computer_softwarelicense.class.php @@ -118,42 +118,88 @@ public static function pdfForLicenseByComputer(PluginPdfSimplePDF $pdf, Software $title = sprintf(__('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); - $query = "SELECT `glpi_computers_softwarelicenses`.*, - `glpi_computers`.`name` AS compname, - `glpi_computers`.`id` AS cID, - `glpi_computers`.`serial`, - `glpi_computers`.`otherserial`, - `glpi_users`.`name` AS username, - `glpi_softwarelicenses`.`name` AS license, - `glpi_softwarelicenses`.`id` AS vID, - `glpi_softwarelicenses`.`name` AS vername, - `glpi_entities`.`name` AS entity, - `glpi_locations`.`completename` AS location, - `glpi_states`.`name` AS state, - `glpi_groups`.`name` AS groupe, - `glpi_softwarelicenses`.`name` AS lname, - `glpi_softwarelicenses`.`id` AS lID - FROM `glpi_computers_softwarelicenses` - INNER JOIN `glpi_softwarelicenses` - ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id` - = `glpi_softwarelicenses`.`id`) - INNER JOIN `glpi_computers` - ON (`glpi_computers_softwarelicenses`.`computers_id` = `glpi_computers`.`id`) - LEFT JOIN `glpi_entities` - ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`) - LEFT JOIN `glpi_locations` - ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`) - LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`) - LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`) - LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`) - WHERE (`glpi_softwarelicenses`.`id` = '" . $ID . "') " . - $dbu->getEntitiesRestrictRequest(' AND', 'glpi_computers') . " - AND `glpi_computers`.`is_deleted` = '0' - AND `glpi_computers`.`is_template` = '0' - ORDER BY `entity`, `compname` - LIMIT 0," . intval($_SESSION['glpilist_limit']); - - $result = $DB->request($query); + $query_params = [ + 'SELECT' => [ + 'glpi_computers_softwarelicenses.*', + 'glpi_computers.name AS compname', + 'glpi_computers.id AS cID', + 'glpi_computers.serial', + 'glpi_computers.otherserial', + 'glpi_users.name AS username', + 'glpi_softwarelicenses.name AS license', + 'glpi_softwarelicenses.id AS vID', + 'glpi_softwarelicenses.name AS vername', + 'glpi_entities.name AS entity', + 'glpi_locations.completename AS location', + 'glpi_states.name AS state', + 'glpi_groups.name AS groupe', + 'glpi_softwarelicenses.name AS lname', + 'glpi_softwarelicenses.id AS lID' + ], + 'FROM' => 'glpi_computers_softwarelicenses', + 'INNER JOIN' => [ + 'glpi_softwarelicenses' => [ + 'ON' => [ + 'glpi_computers_softwarelicenses' => 'softwarelicenses_id', + 'glpi_softwarelicenses' => 'id' + ] + ], + 'glpi_computers' => [ + 'ON' => [ + 'glpi_computers_softwarelicenses' => 'computers_id', + 'glpi_computers' => 'id' + ] + ] + ], + 'LEFT JOIN' => [ + 'glpi_entities' => [ + 'ON' => [ + 'glpi_computers' => 'entities_id', + 'glpi_entities' => 'id' + ] + ], + 'glpi_locations' => [ + 'ON' => [ + 'glpi_computers' => 'locations_id', + 'glpi_locations' => 'id' + ] + ], + 'glpi_states' => [ + 'ON' => [ + 'glpi_computers' => 'states_id', + 'glpi_states' => 'id' + ] + ], + 'glpi_groups' => [ + 'ON' => [ + 'glpi_computers' => 'groups_id', + 'glpi_groups' => 'id' + ] + ], + 'glpi_users' => [ + 'ON' => [ + 'glpi_computers' => 'users_id', + 'glpi_users' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_softwarelicenses.id' => $ID, + 'glpi_computers.is_deleted' => 0, + 'glpi_computers.is_template' => 0 + ], + 'ORDER' => ['entity', 'compname'], + 'START' => 0, + 'LIMIT' => intval($_SESSION['glpilist_limit']) + ]; + + // Ajout de la restriction d'entités + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_computers'); + if (!empty($entity_restrict)) { + $query_params['WHERE'][] = new \Glpi\DBAL\QueryExpression($entity_restrict); + } + + $result = $DB->request($query_params); $showEntity = ($license->isRecursive()); if ($showEntity) { diff --git a/inc/computer_softwareversion.class.php b/inc/computer_softwareversion.class.php index 23935d7..fdddff5 100644 --- a/inc/computer_softwareversion.class.php +++ b/inc/computer_softwareversion.class.php @@ -79,45 +79,93 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $total = $row['cpt']; } - $query = "SELECT DISTINCT `glpi_computers_softwareversions`.*, - `glpi_computers`.`name` AS compname, - `glpi_computers`.`id` AS cID, - `glpi_computers`.`serial`, - `glpi_computers`.`otherserial`, - `glpi_users`.`name` AS username, - `glpi_users`.`id` AS userid, - `glpi_users`.`realname` AS userrealname, - `glpi_users`.`firstname` AS userfirstname, - `glpi_softwareversions`.`name` AS version, - `glpi_softwareversions`.`id` AS vID, - `glpi_softwareversions`.`softwares_id` AS sID, - `glpi_softwareversions`.`name` AS vername, - `glpi_entities`.`completename` AS entity, - `glpi_locations`.`completename` AS location, - `glpi_states`.`name` AS state, - `glpi_groups`.`name` AS groupe - FROM `glpi_computers_softwareversions` - INNER JOIN `glpi_softwareversions` - ON (`glpi_computers_softwareversions`.`softwareversions_id` - = `glpi_softwareversions`.`id`) - INNER JOIN `glpi_computers` - ON (`glpi_computers_softwareversions`.`computers_id` = `glpi_computers`.`id`) - LEFT JOIN `glpi_entities` ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`) - LEFT JOIN `glpi_locations` - ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`) - LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`) - LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`) - LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`) - WHERE (`glpi_softwareversions`.`$crit` = '$ID') " . - $dbu->getEntitiesRestrictRequest(' AND', 'glpi_computers') . " - AND `glpi_computers`.`is_deleted` = '0' - AND `glpi_computers`.`is_template` = '0' - ORDER BY version, compname - LIMIT 0," . intval($_SESSION['glpilist_limit']); + $query_params = [ + 'SELECT' => [ + 'glpi_computers_softwareversions.*', + 'glpi_computers.name AS compname', + 'glpi_computers.id AS cID', + 'glpi_computers.serial', + 'glpi_computers.otherserial', + 'glpi_users.name AS username', + 'glpi_users.id AS userid', + 'glpi_users.realname AS userrealname', + 'glpi_users.firstname AS userfirstname', + 'glpi_softwareversions.name AS version', + 'glpi_softwareversions.id AS vID', + 'glpi_softwareversions.softwares_id AS sID', + 'glpi_softwareversions.name AS vername', + 'glpi_entities.completename AS entity', + 'glpi_locations.completename AS location', + 'glpi_states.name AS state', + 'glpi_groups.name AS groupe' + ], + 'DISTINCT' => true, + 'FROM' => 'glpi_computers_softwareversions', + 'INNER JOIN' => [ + 'glpi_softwareversions' => [ + 'ON' => [ + 'glpi_computers_softwareversions' => 'softwareversions_id', + 'glpi_softwareversions' => 'id' + ] + ], + 'glpi_computers' => [ + 'ON' => [ + 'glpi_computers_softwareversions' => 'computers_id', + 'glpi_computers' => 'id' + ] + ] + ], + 'LEFT JOIN' => [ + 'glpi_entities' => [ + 'ON' => [ + 'glpi_computers' => 'entities_id', + 'glpi_entities' => 'id' + ] + ], + 'glpi_locations' => [ + 'ON' => [ + 'glpi_computers' => 'locations_id', + 'glpi_locations' => 'id' + ] + ], + 'glpi_states' => [ + 'ON' => [ + 'glpi_computers' => 'states_id', + 'glpi_states' => 'id' + ] + ], + 'glpi_groups' => [ + 'ON' => [ + 'glpi_computers' => 'groups_id', + 'glpi_groups' => 'id' + ] + ], + 'glpi_users' => [ + 'ON' => [ + 'glpi_computers' => 'users_id', + 'glpi_users' => 'id' + ] + ] + ], + 'WHERE' => [ + "glpi_softwareversions.$crit" => $ID, + 'glpi_computers.is_deleted' => 0, + 'glpi_computers.is_template' => 0 + ], + 'ORDER' => ['version', 'compname'], + 'START' => 0, + 'LIMIT' => intval($_SESSION['glpilist_limit']) + ]; + + // Ajout de la restriction d'entités + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_computers'); + if (!empty($entity_restrict)) { + $query_params['WHERE'][] = new \Glpi\DBAL\QueryExpression($entity_restrict); + } $pdf->setColumnsSize(100); - $result = $DB->request($query); + $result = $DB->request($query_params); if (($number = count($result)) > 0) { if ($number == $total) { $pdf->displayTitle('' . sprintf( @@ -181,7 +229,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $data['username'], $data['userrealname'], $data['userfirstname'], - $linkUser, + $linkUser ? 1 : 0, ), implode(', ', $tmp), Html::convDate($data['date_install']), @@ -260,33 +308,52 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) $ID = $comp->getField('id'); // From Computer_SoftwareVersion::showForComputer(); - $query = "SELECT `glpi_softwares`.`softwarecategories_id`, - `glpi_softwares`.`name` AS softname, - `glpi_computers_softwareversions`.`id`, - `glpi_states`.`name` AS state, - `glpi_softwareversions`.`id` AS verid, - `glpi_softwareversions`.`softwares_id`, - `glpi_softwareversions`.`name` AS version, - `glpi_softwares`.`is_valid` AS softvalid, - `glpi_computers_softwareversions`.`date_install` AS dateinstall - FROM `glpi_computers_softwareversions` - LEFT JOIN `glpi_softwareversions` - ON (`glpi_computers_softwareversions`.`softwareversions_id` - = `glpi_softwareversions`.`id`) - LEFT JOIN `glpi_states` - ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`) - LEFT JOIN `glpi_softwares` - ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`) - WHERE `glpi_computers_softwareversions`.`computers_id` = '$ID' - AND `glpi_computers_softwareversions`.`is_deleted` = '0' - ORDER BY `softwarecategories_id`, `softname`, `version`"; + $query_params = [ + 'SELECT' => [ + 'glpi_softwares.softwarecategories_id', + 'glpi_softwares.name AS softname', + 'glpi_computers_softwareversions.id', + 'glpi_states.name AS state', + 'glpi_softwareversions.id AS verid', + 'glpi_softwareversions.softwares_id', + 'glpi_softwareversions.name AS version', + 'glpi_softwares.is_valid AS softvalid', + 'glpi_computers_softwareversions.date_install AS dateinstall' + ], + 'FROM' => 'glpi_computers_softwareversions', + 'LEFT JOIN' => [ + 'glpi_softwareversions' => [ + 'ON' => [ + 'glpi_computers_softwareversions' => 'softwareversions_id', + 'glpi_softwareversions' => 'id' + ] + ], + 'glpi_states' => [ + 'ON' => [ + 'glpi_states' => 'id', + 'glpi_softwareversions' => 'states_id' + ] + ], + 'glpi_softwares' => [ + 'ON' => [ + 'glpi_softwareversions' => 'softwares_id', + 'glpi_softwares' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_computers_softwareversions.computers_id' => $ID, + 'glpi_computers_softwareversions.is_deleted' => 0 + ], + 'ORDER' => ['softwarecategories_id', 'softname', 'version'] + ]; $output = []; $software_category = new SoftwareCategory(); $software_version = new SoftwareVersion(); - foreach ($DB->request($query) as $softwareversion) { + foreach ($DB->request($query_params) as $softwareversion) { $output[] = $softwareversion; } @@ -326,22 +393,44 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) // From Computer_SoftwareVersion::displaySoftsByCategory() $verid = $soft['verid']; - $query = "SELECT `glpi_softwarelicenses`.*, - `glpi_softwarelicensetypes`.`name` AS type - FROM `glpi_computers_softwarelicenses` - INNER JOIN `glpi_softwarelicenses` - ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id` - = `glpi_softwarelicenses`.`id`) - LEFT JOIN `glpi_softwarelicensetypes` - ON (`glpi_softwarelicenses`.`softwarelicensetypes_id` - =`glpi_softwarelicensetypes`.`id`) - WHERE `glpi_computers_softwarelicenses`.`computers_id` = '$ID' - AND (`glpi_softwarelicenses`.`softwareversions_id_use` = '$verid' - OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0' - AND `glpi_softwarelicenses`.`softwareversions_id_buy` = '$verid'))"; + $query_license_params = [ + 'SELECT' => [ + 'glpi_softwarelicenses.*', + 'glpi_softwarelicensetypes.name AS type' + ], + 'FROM' => 'glpi_computers_softwarelicenses', + 'INNER JOIN' => [ + 'glpi_softwarelicenses' => [ + 'ON' => [ + 'glpi_computers_softwarelicenses' => 'softwarelicenses_id', + 'glpi_softwarelicenses' => 'id' + ] + ] + ], + 'LEFT JOIN' => [ + 'glpi_softwarelicensetypes' => [ + 'ON' => [ + 'glpi_softwarelicenses' => 'softwarelicensetypes_id', + 'glpi_softwarelicensetypes' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_computers_softwarelicenses.computers_id' => $ID, + 'OR' => [ + 'glpi_softwarelicenses.softwareversions_id_use' => $verid, + [ + 'AND' => [ + 'glpi_softwarelicenses.softwareversions_id_use' => 0, + 'glpi_softwarelicenses.softwareversions_id_buy' => $verid + ] + ] + ] + ] + ]; $lic = ''; - foreach ($DB->request($query) as $licdata) { + foreach ($DB->request($query_license_params) as $licdata) { $installed[] = $licdata['id']; $lic .= (empty($lic) ? '' : ', ') . '' . $licdata['name'] . ' ' . $licdata['serial']; if (!empty($licdata['type'])) { @@ -361,31 +450,67 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) } // Affected licenses NOT installed - $query = "SELECT `glpi_softwarelicenses`.*, - `glpi_softwares`.`name` AS softname, - `glpi_softwareversions`.`name` AS version, - `glpi_states`.`name` AS state - FROM `glpi_softwarelicenses` - LEFT JOIN `glpi_computers_softwarelicenses` - ON (`glpi_computers_softwarelicenses`.softwarelicenses_id - = `glpi_softwarelicenses`.`id`) - INNER JOIN `glpi_softwares` - ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`) - LEFT JOIN `glpi_softwareversions` - ON (`glpi_softwarelicenses`.`softwareversions_id_use` - = `glpi_softwareversions`.`id` - OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0' - AND `glpi_softwarelicenses`.`softwareversions_id_buy` - = `glpi_softwareversions`.`id`)) - LEFT JOIN `glpi_states` - ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`) - WHERE `glpi_computers_softwarelicenses`.`computers_id` = '$ID' "; + $query_affected_params = [ + 'SELECT' => [ + 'glpi_softwarelicenses.*', + 'glpi_softwares.name AS softname', + 'glpi_softwareversions.name AS version', + 'glpi_states.name AS state' + ], + 'FROM' => 'glpi_softwarelicenses', + 'LEFT JOIN' => [ + 'glpi_computers_softwarelicenses' => [ + 'ON' => [ + 'glpi_computers_softwarelicenses' => 'softwarelicenses_id', + 'glpi_softwarelicenses' => 'id' + ] + ], + 'glpi_softwareversions' => [ + 'ON' => [ + 'OR' => [ + [ + 'glpi_softwarelicenses' => 'softwareversions_id_use', + 'glpi_softwareversions' => 'id' + ], + [ + 'AND' => [ + 'glpi_softwarelicenses.softwareversions_id_use' => 0, + [ + 'glpi_softwarelicenses' => 'softwareversions_id_buy', + 'glpi_softwareversions' => 'id' + ] + ] + ] + ] + ] + ], + 'glpi_states' => [ + 'ON' => [ + 'glpi_states' => 'id', + 'glpi_softwareversions' => 'states_id' + ] + ] + ], + 'INNER JOIN' => [ + 'glpi_softwares' => [ + 'ON' => [ + 'glpi_softwarelicenses' => 'softwares_id', + 'glpi_softwares' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_computers_softwarelicenses.computers_id' => $ID + ] + ]; if (count($installed)) { - $query .= ' AND `glpi_softwarelicenses`.`id` NOT IN (' . implode(',', $installed) . ')'; + $query_affected_params['WHERE'][] = new \Glpi\DBAL\QueryExpression( + 'glpi_softwarelicenses.id NOT IN (' . implode(',', $installed) . ')' + ); } - $req = $DB->request($query); + $req = $DB->request($query_affected_params); if ($req->numrows()) { $pdf->setColumnsSize(100); $pdf->displayTitle('' . __('Affected licenses of not installed software', 'pdf') . ''); diff --git a/inc/computerantivirus.class.php b/inc/computerantivirus.class.php index d1f6e13..ae22dc4 100644 --- a/inc/computerantivirus.class.php +++ b/inc/computerantivirus.class.php @@ -36,7 +36,7 @@ class PluginPdfComputerAntivirus extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new ComputerAntivirus()); + $this->obj = ($obj ? $obj : new ItemAntivirus()); } public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) @@ -46,7 +46,7 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) $ID = $item->getField('id'); - $result = $DB->request('glpi_computerantiviruses', ['computers_id' => $ID, + $result = $DB->request(['FROM' => 'glpi_itemantiviruses'] + ['computers_id' => $ID, 'is_deleted' => 0]); $number = count($result); @@ -74,7 +74,7 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) __('Expiration date'), ); - $antivirus = new ComputerAntivirus(); + $antivirus = new ItemAntivirus(); foreach ($result as $data) { $pdf->displayLine( $data['name'], diff --git a/inc/computervirtualmachine.class.php b/inc/computervirtualmachine.class.php index ab9afb8..85e0702 100644 --- a/inc/computervirtualmachine.class.php +++ b/inc/computervirtualmachine.class.php @@ -36,7 +36,7 @@ class PluginPdfComputerVirtualMachine extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new ComputerVirtualMachine()); + $this->obj = ($obj ? $obj : new ItemVirtualMachine()); } public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) @@ -47,7 +47,7 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) // From ComputerVirtualMachine::showForComputer() $virtualmachines = $dbu->getAllDataFromTable( - 'glpi_computervirtualmachines', + 'glpi_itemvirtualmachines', ['computers_id' => $ID], ); $pdf->setColumnsSize(100); @@ -80,7 +80,7 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) foreach ($virtualmachines as $virtualmachine) { $name = ''; - if ($link_computer = ComputerVirtualMachine::findVirtualMachine($virtualmachine)) { + if ($link_computer = ItemVirtualMachine::findVirtualMachine($virtualmachine)) { $computer = new Computer(); if ($computer->getFromDB($link_computer)) { $name = $computer->getName(); @@ -114,7 +114,7 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) $item::getTable(), ['RAW' => ['LOWER(uuid)' - => ComputerVirtualMachine::getUUIDRestrictCriteria($item->fields['uuid']), + => ItemVirtualMachine::getUUIDRestrictCriteria($item->fields['uuid']), ], ], ); diff --git a/inc/config.class.php b/inc/config.class.php index 302973a..e8dfddf 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -121,14 +121,12 @@ public static function install(Migration $mig) PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET= {$default_charset} COLLATE = {$default_collation} ROW_FORMAT=DYNAMIC"; - $DB->doQueryOrDie($query, 'Error in creating glpi_plugin_pdf_configs' . - '
' . $DB->error()); + $DB->doQuery($query); $query = "INSERT INTO `$table` (id, currency) VALUES (1, 'EUR')"; - $DB->doQueryOrDie($query, 'Error during update glpi_plugin_pdf_configs' . - '
' . $DB->error()); + $DB->doQuery($query); } else { // 2.1.0 if ($DB->fieldExists($table, 'date_mod')) { @@ -187,7 +185,13 @@ public static function showConfigForm($item) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Config') { - return $this->getName(); + $icon_html = sprintf('', 'file-type-pdf'); + + return sprintf( + '%s%s', + $icon_html, + self::getName(), + ); } return ''; diff --git a/inc/consumableitem.class.php b/inc/consumableitem.class.php index 74df805..84b96ae 100644 --- a/inc/consumableitem.class.php +++ b/inc/consumableitem.class.php @@ -160,9 +160,7 @@ public static function pdfForConsumableItem(PluginPdfSimplePDF $pdf, ConsumableI $number = $dbu->countElementsInTable('glpi_consumables', $where); - $iterator = $DB->request( - 'glpi_consumables', - ['WHERE' => $where, + $iterator = $DB->request(['FROM' => 'glpi_consumables'] + ['WHERE' => $where, 'ORDER' => $order], ); diff --git a/inc/document.class.php b/inc/document.class.php index 1b45280..d282e79 100644 --- a/inc/document.class.php +++ b/inc/document.class.php @@ -47,9 +47,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ID = $item->getField('id'); $type = get_class($item); - $result = $DB->request( - 'glpi_documents_items', - ['SELECT' => ['glpi_documents_items.id', + $result = $DB->request(['FROM' => 'glpi_documents_items'] + ['SELECT' => ['glpi_documents_items.id', 'glpi_documents_items.date_mod', 'glpi_documents.*', 'glpi_entities.id', 'completename'], diff --git a/inc/group.class.php b/inc/group.class.php index cd824bc..1e9240c 100644 --- a/inc/group.class.php +++ b/inc/group.class.php @@ -160,17 +160,15 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, Group $group, $tech, $t $dbu = new DbUtils(); if ($tech) { - $types = $CFG_GLPI['linkgroup_tech_types']; $field = 'groups_id_tech'; $title = __('Managed items'); } else { - $types = $CFG_GLPI['linkgroup_types']; $field = 'groups_id'; $title = __('Used items'); } $datas = []; - $max = $group->getDataItems($types, $field, $tree, $user, 0, $datas); + $max = $group->getDataItems($tech, $tree, $user, 0, $datas); $nb = count($datas); if ($nb < $max) { @@ -247,8 +245,13 @@ public static function pdfChildren(PluginPdfSimplePDF $pdf, CommonTreeDropdown $ $entity_assign = $item->isEntityAssign(); $fk = $item->getForeignKeyField(); - $crit = [$fk => $item->getID(), - 'ORDER' => 'name']; + $crit = [ + 'FROM' => $item->getTable(), + 'WHERE' => [ + $fk => $item->getID() + ], + 'ORDER' => 'name' + ]; if ($item->haveChildren()) { $pdf->setColumnsSize(100); @@ -256,10 +259,9 @@ public static function pdfChildren(PluginPdfSimplePDF $pdf, CommonTreeDropdown $ if ($entity_assign) { if ($fk == 'entities_id') { - $crit['id'] = $_SESSION['glpiactiveentities']; - $crit['id'] += $_SESSION['glpiparententities']; + $crit['WHERE']['id'] = $_SESSION['glpiactiveentities'] + $_SESSION['glpiparententities']; } else { - $crit['entities_id'] = $_SESSION['glpiactiveentities']; + $crit['WHERE']['entities_id'] = $_SESSION['glpiactiveentities']; } $pdf->setColumnsSize(30, 30, 40); @@ -269,7 +271,7 @@ public static function pdfChildren(PluginPdfSimplePDF $pdf, CommonTreeDropdown $ $pdf->displayTitle(__('Name'), __('Comments')); } - foreach ($DB->request($item->getTable(), $crit) as $data) { + foreach ($DB->request($crit) as $data) { if ($entity_assign) { $pdf->displayLine( $data['name'], diff --git a/inc/item_device.class.php b/inc/item_device.class.php index 64d7af8..9ebe448 100644 --- a/inc/item_device.class.php +++ b/inc/item_device.class.php @@ -63,26 +63,35 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) $devicetypes = new $itemtype(); $specificities = $devicetypes->getSpecificities(); $specif_fields = array_keys($specificities); - $specif_text = implode(',', $specif_fields); - if (!empty($specif_text)) { - $specif_text = ' ,' . $specif_text . ' '; - } $associated_type = str_replace('Item_', '', $itemtype); $linktable = $dbu->getTableForItemType($itemtype); $fk = $dbu->getForeignKeyFieldForTable($dbu->getTableForItemType($associated_type)); - $query = 'SELECT count(*) AS NB, `id`, `' . $fk . '`' . $specif_text . ' - FROM `' . $linktable . "` - WHERE `items_id` = '" . $ID . "' - AND `itemtype` = '" . $item->getType() . "' - GROUP BY `" . $fk . '`' . $specif_text; + $select_fields = ['COUNT(*) AS NB', 'id', $fk]; + if (!empty($specif_fields)) { + $select_fields = array_merge($select_fields, $specif_fields); + } + // Construction de la clause GROUP BY + $group_by = [$fk]; + if (!empty($specif_fields)) { + $group_by = array_merge($group_by, $specif_fields); + } + $query_params = [ + 'SELECT' => $select_fields, + 'FROM' => $linktable, + 'WHERE' => [ + 'items_id' => $ID, + 'itemtype' => $item->getType() + ], + 'GROUPBY' => $group_by + ]; $device = new $associated_type(); $itemdevice = new $itemtype(); - foreach ($DB->request($query) as $data) { + foreach ($DB->request($query_params) as $data) { $itemdevice->getFromDB($data['id']); if ($device->getFromDB($data[$fk])) { $spec = $device->getAdditionalFields(); diff --git a/inc/item_disk.class.php b/inc/item_disk.class.php index f4befda..1f78896 100644 --- a/inc/item_disk.class.php +++ b/inc/item_disk.class.php @@ -46,9 +46,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ID = $item->getField('id'); - $result = $DB->request( - 'glpi_items_disks', - ['SELECT' => ['glpi_filesystems.name', 'glpi_items_disks.*'], + $result = $DB->request(['FROM' => 'glpi_items_disks'] + ['SELECT' => ['glpi_filesystems.name', 'glpi_items_disks.*'], 'LEFT JOIN' => ['glpi_filesystems' => ['FKEY' => ['glpi_items_disks' => 'filesystems_id', 'glpi_filesystems' => 'id']]], diff --git a/inc/item_knowbaseitem.class.php b/inc/item_knowbaseitem.class.php index 6bb6768..a316331 100644 --- a/inc/item_knowbaseitem.class.php +++ b/inc/item_knowbaseitem.class.php @@ -46,9 +46,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ID = $item->getField('id'); - $result = $DB->request( - 'glpi_knowbaseitems', - ['SELECT' => ['glpi_knowbaseitems.*', + $result = $DB->request(['FROM' => 'glpi_knowbaseitems'] + ['SELECT' => ['glpi_knowbaseitems.*', 'glpi_knowbaseitems_items.itemtype', 'glpi_knowbaseitems_items.items_id'], 'LEFT JOIN' => ['glpi_knowbaseitems_items' diff --git a/inc/item_problem.class.php b/inc/item_problem.class.php index 9cae4e1..9c4de44 100644 --- a/inc/item_problem.class.php +++ b/inc/item_problem.class.php @@ -52,9 +52,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) return false; } - $result = $DB->request( - 'glpi_items_problems', - ['SELECT' => 'itemtype', + $result = $DB->request(['FROM' => 'glpi_items_problems'] + ['SELECT' => 'itemtype', 'DISTINCT' => true, 'WHERE' => ['problems_id' => $instID], 'ORDER' => 'itemtype'], @@ -89,35 +87,55 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) if ($item->canView()) { $itemtable = $dbu->getTableForItemType($itemtype); - $query = "SELECT `$itemtable`.*, - `glpi_items_problems`.`id` AS IDD, - `glpi_entities`.`id` AS entity - FROM `glpi_items_problems`, - `$itemtable`"; + $query_params = [ + 'SELECT' => [ + "$itemtable.*", + 'glpi_items_problems.id AS IDD', + 'glpi_entities.id AS entity' + ], + 'FROM' => 'glpi_items_problems', + 'INNER JOIN' => [ + $itemtable => [ + 'ON' => [ + $itemtable => 'id', + 'glpi_items_problems' => 'items_id' + ] + ] + ], + 'WHERE' => [ + 'glpi_items_problems.itemtype' => $itemtype, + 'glpi_items_problems.problems_id' => $instID + ], + 'ORDER' => ['glpi_entities.completename', "$itemtable.name"] + ]; if ($itemtype != 'Entity') { - $query .= " LEFT JOIN `glpi_entities` - ON (`$itemtable`.`entities_id`=`glpi_entities`.`id`) "; + $query_params['LEFT JOIN']['glpi_entities'] = [ + 'ON' => [ + $itemtable => 'entities_id', + 'glpi_entities' => 'id' + ] + ]; } - $query .= " WHERE `$itemtable`.`id` = `glpi_items_problems`.`items_id` - AND `glpi_items_problems`.`itemtype` = '$itemtype' - AND `glpi_items_problems`.`problems_id` = '$instID'"; - if ($item->maybeTemplate()) { - $query .= " AND `$itemtable`.`is_template` = '0'"; + $query_params['WHERE']["$itemtable.is_template"] = 0; } - $query .= $dbu->getEntitiesRestrictRequest( - ' AND', + // Ajout de la restriction d'entités + $entity_restrict = $dbu->getEntitiesRestrictRequest( + '', $itemtable, '', '', $item->maybeRecursive(), - ) . " - ORDER BY `glpi_entities`.`completename`, `$itemtable`.`name`"; + ); + + if (!empty($entity_restrict)) { + $query_params['WHERE'][] = new \Glpi\DBAL\QueryExpression($entity_restrict); + } - $result_linked = $DB->request($query); + $result_linked = $DB->request($query_params); $nb = count($result_linked); $prem = true; @@ -192,36 +210,82 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr break; } - $SELECT = ''; - $FROM = ''; + $select_fields = [ + 'glpi_problems.*', + 'glpi_itilcategories.completename AS catname' + ]; + + if (count($_SESSION['glpiactiveentities']) > 1) { + $select_fields[] = 'glpi_entities.completename AS entityname'; + $select_fields[] = 'glpi_problems.entities_id AS entityID'; + } + + $left_joins = [ + 'glpi_items_problems' => [ + 'ON' => [ + 'glpi_problems' => 'id', + 'glpi_items_problems' => 'problems_id' + ] + ], + 'glpi_groups_problems' => [ + 'ON' => [ + 'glpi_problems' => 'id', + 'glpi_groups_problems' => 'problems_id' + ] + ], + 'glpi_problems_users' => [ + 'ON' => [ + 'glpi_problems' => 'id', + 'glpi_problems_users' => 'problems_id' + ] + ], + 'glpi_problems_suppliers' => [ + 'ON' => [ + 'glpi_problems' => 'id', + 'glpi_problems_suppliers' => 'problems_id' + ] + ], + 'glpi_itilcategories' => [ + 'ON' => [ + 'glpi_problems' => 'itilcategories_id', + 'glpi_itilcategories' => 'id' + ] + ] + ]; + if (count($_SESSION['glpiactiveentities']) > 1) { - $SELECT = ', `glpi_entities`.`completename` AS entityname, - `glpi_problems`.`entities_id` AS entityID '; - $FROM = ' LEFT JOIN `glpi_entities` - ON (`glpi_entities`.`id` = `glpi_problems`.`entities_id`) '; + $left_joins['glpi_entities'] = [ + 'ON' => [ + 'glpi_entities' => 'id', + 'glpi_problems' => 'entities_id' + ] + ]; + } + + $where_conditions = []; + + if (strpos($restrict, 'IN (') !== false || strpos($restrict, 'AND') !== false || strpos($restrict, 'OR') !== false) { + $where_conditions[] = new \Glpi\DBAL\QueryExpression($restrict); + } else { + $where_conditions[] = new \Glpi\DBAL\QueryExpression($restrict); + } + + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_problems'); + if (!empty($entity_restrict)) { + $where_conditions[] = new \Glpi\DBAL\QueryExpression($entity_restrict); } - $query = "SELECT DISTINCT `glpi_problems`.*, - `glpi_itilcategories`.`completename` AS catname - $SELECT - FROM `glpi_problems` - LEFT JOIN `glpi_items_problems` - ON (`glpi_problems`.`id` = `glpi_items_problems`.`problems_id`) - LEFT JOIN `glpi_groups_problems` - ON (`glpi_problems`.`id` = `glpi_groups_problems`.`problems_id`) - LEFT JOIN `glpi_problems_users` - ON (`glpi_problems`.`id` = `glpi_problems_users`.`problems_id`) - LEFT JOIN `glpi_problems_suppliers` - ON (`glpi_problems`.`id` = `glpi_problems_suppliers`.`problems_id`) - LEFT JOIN `glpi_itilcategories` - ON (`glpi_problems`.`itilcategories_id` = `glpi_itilcategories`.`id`) - $FROM - WHERE $restrict " . - $dbu->getEntitiesRestrictRequest('AND', 'glpi_problems') . " - ORDER BY $order - LIMIT " . intval($_SESSION['glpilist_limit']); - - $result = $DB->request($query); + $query_params = [ + 'SELECT' => $select_fields, + 'DISTINCT' => true, + 'FROM' => 'glpi_problems', + 'LEFT JOIN' => $left_joins, + 'WHERE' => $where_conditions, + 'ORDER' => $order, + 'LIMIT' => intval($_SESSION['glpilist_limit']) + ]; + + $result = $DB->request($query_params); $number = count($result); $pdf->setColumnsSize(100); diff --git a/inc/item_softwarelicense.class.php b/inc/item_softwarelicense.class.php index b543e87..67e6e64 100644 --- a/inc/item_softwarelicense.class.php +++ b/inc/item_softwarelicense.class.php @@ -119,43 +119,89 @@ public static function pdfForLicenseByComputer(PluginPdfSimplePDF $pdf, Software $title = sprintf(__('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); - $query = "SELECT `glpi_items_softwarelicenses`.*, - `glpi_computers`.`name` AS compname, - `glpi_computers`.`id` AS cID, - `glpi_computers`.`serial`, - `glpi_computers`.`otherserial`, - `glpi_users`.`name` AS username, - `glpi_softwarelicenses`.`name` AS license, - `glpi_softwarelicenses`.`id` AS vID, - `glpi_softwarelicenses`.`name` AS vername, - `glpi_entities`.`name` AS entity, - `glpi_locations`.`completename` AS location, - `glpi_states`.`name` AS state, - `glpi_groups`.`name` AS groupe, - `glpi_softwarelicenses`.`name` AS lname, - `glpi_softwarelicenses`.`id` AS lID - FROM `glpi_items_softwarelicenses` - INNER JOIN `glpi_softwarelicenses` - ON (`glpi_items_softwarelicenses`.`softwarelicenses_id` - = `glpi_softwarelicenses`.`id`) - INNER JOIN `glpi_computers` - ON (`glpi_items_softwarelicenses`.`items_id` = `glpi_computers`.`id` - AND `glpi_items_softwarelicenses`.`itemtype` = 'Computer') - LEFT JOIN `glpi_entities` - ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`) - LEFT JOIN `glpi_locations` - ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`) - LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`) - LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`) - LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`) - WHERE (`glpi_softwarelicenses`.`id` = '" . $ID . "') " . - $dbu->getEntitiesRestrictRequest(' AND', 'glpi_computers') . " - AND `glpi_computers`.`is_deleted` = '0' - AND `glpi_computers`.`is_template` = '0' - ORDER BY `entity`, `compname` - LIMIT 0," . intval($_SESSION['glpilist_limit']); - - $result = $DB->request($query); + $query_params = [ + 'SELECT' => [ + 'glpi_items_softwarelicenses.*', + 'glpi_computers.name AS compname', + 'glpi_computers.id AS cID', + 'glpi_computers.serial', + 'glpi_computers.otherserial', + 'glpi_users.name AS username', + 'glpi_softwarelicenses.name AS license', + 'glpi_softwarelicenses.id AS vID', + 'glpi_softwarelicenses.name AS vername', + 'glpi_entities.name AS entity', + 'glpi_locations.completename AS location', + 'glpi_states.name AS state', + 'glpi_groups.name AS groupe', + 'glpi_softwarelicenses.name AS lname', + 'glpi_softwarelicenses.id AS lID' + ], + 'FROM' => 'glpi_items_softwarelicenses', + 'INNER JOIN' => [ + 'glpi_softwarelicenses' => [ + 'ON' => [ + 'glpi_items_softwarelicenses' => 'softwarelicenses_id', + 'glpi_softwarelicenses' => 'id' + ] + ], + 'glpi_computers' => [ + 'ON' => [ + 'glpi_items_softwarelicenses' => 'items_id', + 'glpi_computers' => 'id', + ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']] + ] + ] + ], + 'LEFT JOIN' => [ + 'glpi_entities' => [ + 'ON' => [ + 'glpi_computers' => 'entities_id', + 'glpi_entities' => 'id' + ] + ], + 'glpi_locations' => [ + 'ON' => [ + 'glpi_computers' => 'locations_id', + 'glpi_locations' => 'id' + ] + ], + 'glpi_states' => [ + 'ON' => [ + 'glpi_computers' => 'states_id', + 'glpi_states' => 'id' + ] + ], + 'glpi_groups' => [ + 'ON' => [ + 'glpi_computers' => 'groups_id', + 'glpi_groups' => 'id' + ] + ], + 'glpi_users' => [ + 'ON' => [ + 'glpi_computers' => 'users_id', + 'glpi_users' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_softwarelicenses.id' => $ID, + 'glpi_computers.is_deleted' => 0, + 'glpi_computers.is_template' => 0 + ], + 'ORDER' => ['entity', 'compname'], + 'START' => 0, + 'LIMIT' => intval($_SESSION['glpilist_limit']) + ]; + + // Ajout de la restriction d'entités + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_computers'); + if (!empty($entity_restrict)) { + $query_params['WHERE'][] = new \Glpi\DBAL\QueryExpression($entity_restrict); + } + + $result = $DB->request($query_params); $showEntity = ($license->isRecursive()); if ($showEntity) { diff --git a/inc/item_softwareversion.class.php b/inc/item_softwareversion.class.php index c21f93a..489ce22 100644 --- a/inc/item_softwareversion.class.php +++ b/inc/item_softwareversion.class.php @@ -70,7 +70,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) 'glpi_softwareversions.id AS vID', "{$itemtable}.name AS itemname", "{$itemtable}.id AS iID", - new QueryExpression($DB->quoteValue($itemtype) . ' AS ' . $DB::quoteName('item_type')), + new \Glpi\DBAL\QueryExpression($DB->quoteValue($itemtype) . ' AS ' . $DB::quoteName('item_type')), ], 'FROM' => $item_version_table, 'INNER JOIN' => ['glpi_softwareversions' @@ -91,17 +91,13 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) if ($DB->fieldExists($itemtable, 'serial')) { $query['SELECT'][] = $itemtable . '.serial'; } else { - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.serial'), - ); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.serial')); } if ($DB->fieldExists($itemtable, 'otherserial')) { $query['SELECT'][] = $itemtable . '.otherserial'; } else { - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.otherserial'), - ); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.otherserial')); } if ($DB->fieldExists($itemtable, 'users_id')) { @@ -113,18 +109,10 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) 'glpi_users' => 'id'], ]; } else { - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.username'), - ); - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('-1') . ' AS ' . $DB->quoteName($itemtable . '.userid'), - ); - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.userrealname'), - ); - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.userfirstname'), - ); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.username')); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('-1') . ' AS ' . $DB->quoteName($itemtable . '.userid')); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.userrealname')); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.userfirstname')); } if ($DB->fieldExists($itemtable, 'entities_id')) { @@ -134,9 +122,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) ]; $query['WHERE'] += getEntitiesRestrictCriteria($itemtable, '', '', true); } else { - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName('entity'), - ); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('entity')); } if ($DB->fieldExists($itemtable, 'locations_id')) { @@ -145,9 +131,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) 'glpi_locations' => 'id'], ]; } else { - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName('location'), - ); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('location')); } if ($DB->fieldExists($itemtable, 'states_id')) { $query['SELECT'][] = 'glpi_states.name AS state'; @@ -155,9 +139,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) 'glpi_states' => 'id'], ]; } else { - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName('state'), - ); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('state')); } if ($DB->fieldExists($itemtable, 'groups_id')) { @@ -166,9 +148,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) 'glpi_groups' => 'id'], ]; } else { - $query['SELECT'][] = new QueryExpression( - $DB->quoteValue('') . ' AS ' . $DB->quoteName('groupe'), - ); + $query['SELECT'][] = new \Glpi\DBAL\QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('groupe')); } if ($DB->fieldExists($itemtable, 'is_deleted')) { @@ -181,13 +161,15 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) $queries[] = $query; } - $union = new QueryUnion($queries, true); - $criteria = ['SELECT' => [], + + $union = new \Glpi\DBAL\QueryUnion($queries, true); + $criteria = [ 'FROM' => $union, 'ORDER' => "$sort ASC", 'LIMIT' => $_SESSION['glpilist_limit'], ]; + $iterator = $DB->request($criteria); $pdf->setColumnsSize(100); @@ -252,7 +234,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) $data['username'], $data['userrealname'], $data['userfirstname'], - $linkUser, + $linkUser ? 1 : 0, ), implode(', ', $tmp), ); @@ -327,35 +309,54 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) $ID = $item->getField('id'); // From Item_SoftwareVersion::showForComputer(); - $query = "SELECT `glpi_softwares`.`softwarecategories_id`, - `glpi_softwares`.`name` AS softname, - `glpi_items_softwareversions`.`id`, - `glpi_states`.`name` AS state, - `glpi_softwareversions`.`id` AS verid, - `glpi_softwareversions`.`softwares_id`, - `glpi_softwareversions`.`name` AS version, - `glpi_softwares`.`is_valid` AS softvalid, - `glpi_items_softwareversions`.`date_install` AS dateinstall - FROM `glpi_items_softwareversions` - LEFT JOIN `glpi_softwareversions` - ON (`glpi_items_softwareversions`.`softwareversions_id` - = `glpi_softwareversions`.`id` - AND `glpi_items_softwareversions`.`itemtype` = '" . $item->getType() . "') - LEFT JOIN `glpi_states` - ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`) - LEFT JOIN `glpi_softwares` - ON (`glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`) - WHERE `glpi_items_softwareversions`.`items_id` = '$ID' - AND `glpi_items_softwareversions`.`itemtype` = '" . $item->getType() . "' - AND `glpi_items_softwareversions`.`is_deleted` = '0' - ORDER BY `softwarecategories_id`, `softname`, `version`"; + $query_params = [ + 'SELECT' => [ + 'glpi_softwares.softwarecategories_id', + 'glpi_softwares.name AS softname', + 'glpi_items_softwareversions.id', + 'glpi_states.name AS state', + 'glpi_softwareversions.id AS verid', + 'glpi_softwareversions.softwares_id', + 'glpi_softwareversions.name AS version', + 'glpi_softwares.is_valid AS softvalid', + 'glpi_items_softwareversions.date_install AS dateinstall' + ], + 'FROM' => 'glpi_items_softwareversions', + 'LEFT JOIN' => [ + 'glpi_softwareversions' => [ + 'ON' => [ + 'glpi_items_softwareversions' => 'softwareversions_id', + 'glpi_softwareversions' => 'id', + ['AND' => ['glpi_items_softwareversions.itemtype' => $item->getType()]] + ] + ], + 'glpi_states' => [ + 'ON' => [ + 'glpi_states' => 'id', + 'glpi_softwareversions' => 'states_id' + ] + ], + 'glpi_softwares' => [ + 'ON' => [ + 'glpi_softwareversions' => 'softwares_id', + 'glpi_softwares' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_items_softwareversions.items_id' => $ID, + 'glpi_items_softwareversions.itemtype' => $item->getType(), + 'glpi_items_softwareversions.is_deleted' => 0 + ], + 'ORDER' => ['softwarecategories_id', 'softname', 'version'] + ]; $output = []; $software_category = new SoftwareCategory(); $software_version = new SoftwareVersion(); - foreach ($DB->request($query) as $softwareversion) { + foreach ($DB->request($query_params) as $softwareversion) { $output[] = $softwareversion; } @@ -395,23 +396,45 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) // From Item_SoftwareVersion::displaySoftsByCategory() $verid = $soft['verid']; - $query = "SELECT `glpi_softwarelicenses`.*, - `glpi_softwarelicensetypes`.`name` AS type - FROM `glpi_items_softwarelicenses` - INNER JOIN `glpi_softwarelicenses` - ON (`glpi_items_softwarelicenses`.`softwarelicenses_id` - = `glpi_softwarelicenses`.`id`) - LEFT JOIN `glpi_softwarelicensetypes` - ON (`glpi_softwarelicenses`.`softwarelicensetypes_id` - =`glpi_softwarelicensetypes`.`id` - AND `glpi_items_softwarelicenses`.`itemtype` = 'Computer') - WHERE `glpi_items_softwarelicenses`.`items_id` = '$ID' - AND (`glpi_softwarelicenses`.`softwareversions_id_use` = '$verid' - OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0' - AND `glpi_softwarelicenses`.`softwareversions_id_buy` = '$verid'))"; + $query_license_params = [ + 'SELECT' => [ + 'glpi_softwarelicenses.*', + 'glpi_softwarelicensetypes.name AS type' + ], + 'FROM' => 'glpi_items_softwarelicenses', + 'INNER JOIN' => [ + 'glpi_softwarelicenses' => [ + 'ON' => [ + 'glpi_items_softwarelicenses' => 'softwarelicenses_id', + 'glpi_softwarelicenses' => 'id' + ] + ] + ], + 'LEFT JOIN' => [ + 'glpi_softwarelicensetypes' => [ + 'ON' => [ + 'glpi_softwarelicenses' => 'softwarelicensetypes_id', + 'glpi_softwarelicensetypes' => 'id', + ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']] + ] + ] + ], + 'WHERE' => [ + 'glpi_items_softwarelicenses.items_id' => $ID, + 'OR' => [ + 'glpi_softwarelicenses.softwareversions_id_use' => $verid, + [ + 'AND' => [ + 'glpi_softwarelicenses.softwareversions_id_use' => 0, + 'glpi_softwarelicenses.softwareversions_id_buy' => $verid + ] + ] + ] + ] + ]; $lic = ''; - foreach ($DB->request($query) as $licdata) { + foreach ($DB->request($query_license_params) as $licdata) { $installed[] = $licdata['id']; $lic .= (empty($lic) ? '' : ', ') . '' . $licdata['name'] . ' ' . $licdata['serial']; if (!empty($licdata['type'])) { @@ -431,32 +454,68 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) } // Affected licenses NOT installed - $query = "SELECT `glpi_softwarelicenses`.*, - `glpi_softwares`.`name` AS softname, - `glpi_softwareversions`.`name` AS version, - `glpi_states`.`name` AS state - FROM `glpi_softwarelicenses` - LEFT JOIN `glpi_items_softwarelicenses` - ON (`glpi_items_softwarelicenses`.softwarelicenses_id - = `glpi_softwarelicenses`.`id` - AND `glpi_items_softwarelicenses`.`itemtype` = 'Computer') - INNER JOIN `glpi_softwares` - ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`) - LEFT JOIN `glpi_softwareversions` - ON (`glpi_softwarelicenses`.`softwareversions_id_use` - = `glpi_softwareversions`.`id` - OR (`glpi_softwarelicenses`.`softwareversions_id_use` = '0' - AND `glpi_softwarelicenses`.`softwareversions_id_buy` - = `glpi_softwareversions`.`id`)) - LEFT JOIN `glpi_states` - ON (`glpi_states`.`id` = `glpi_softwareversions`.`states_id`) - WHERE `glpi_items_softwarelicenses`.`items_id` = '$ID'"; + $query_affected_params = [ + 'SELECT' => [ + 'glpi_softwarelicenses.*', + 'glpi_softwares.name AS softname', + 'glpi_softwareversions.name AS version', + 'glpi_states.name AS state' + ], + 'FROM' => 'glpi_softwarelicenses', + 'LEFT JOIN' => [ + 'glpi_items_softwarelicenses' => [ + 'ON' => [ + 'glpi_items_softwarelicenses' => 'softwarelicenses_id', + 'glpi_softwarelicenses' => 'id', + ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']] + ] + ], + 'glpi_softwareversions' => [ + 'ON' => [ + 'OR' => [ + [ + 'glpi_softwarelicenses' => 'softwareversions_id_use', + 'glpi_softwareversions' => 'id' + ], + [ + 'AND' => [ + 'glpi_softwarelicenses.softwareversions_id_use' => 0, + [ + 'glpi_softwarelicenses' => 'softwareversions_id_buy', + 'glpi_softwareversions' => 'id' + ] + ] + ] + ] + ] + ], + 'glpi_states' => [ + 'ON' => [ + 'glpi_states' => 'id', + 'glpi_softwareversions' => 'states_id' + ] + ] + ], + 'INNER JOIN' => [ + 'glpi_softwares' => [ + 'ON' => [ + 'glpi_softwarelicenses' => 'softwares_id', + 'glpi_softwares' => 'id' + ] + ] + ], + 'WHERE' => [ + 'glpi_items_softwarelicenses.items_id' => $ID + ] + ]; if (count($installed)) { - $query .= ' AND `glpi_softwarelicenses`.`id` NOT IN (' . implode(',', $installed) . ')'; + $query_affected_params['WHERE'][] = new \Glpi\DBAL\QueryExpression( + 'glpi_softwarelicenses.id NOT IN (' . implode(',', $installed) . ')' + ); } - $req = $DB->request($query); + $req = $DB->request($query_affected_params); if ($req->numrows()) { $pdf->setColumnsSize(100); $pdf->displayTitle('' . __('Affected licenses of not installed software', 'pdf') . ''); diff --git a/inc/item_ticket.class.php b/inc/item_ticket.class.php index 039d7c0..1775d39 100644 --- a/inc/item_ticket.class.php +++ b/inc/item_ticket.class.php @@ -52,9 +52,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su return false; } - $result = $DB->request( - 'glpi_items_tickets', - ['SELECT' => 'itemtype', + $result = $DB->request(['FROM' => 'glpi_items_tickets'] + ['SELECT' => 'itemtype', 'DISTINCT' => true, 'WHERE' => ['tickets_id' => $instID], 'ORDER' => 'itemtype'], @@ -88,35 +86,61 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su if ($item->canView()) { $itemtable = $dbu->getTableForItemType($itemtype); - $query = "SELECT `$itemtable`.*, - `glpi_items_tickets`.`id` AS IDD, - `glpi_entities`.`id` AS entity - FROM `glpi_items_tickets`, - `$itemtable`"; + $select_fields = [ + "$itemtable.*", + 'glpi_items_tickets.id AS IDD', + 'glpi_entities.id AS entity' + ]; + + $joins = [ + 'glpi_items_tickets' => [ + 'ON' => [ + $itemtable => 'id', + 'glpi_items_tickets' => 'items_id' + ] + ] + ]; if ($itemtype != 'Entity') { - $query .= " LEFT JOIN `glpi_entities` - ON (`$itemtable`.`entities_id`=`glpi_entities`.`id`) "; + $joins['glpi_entities'] = [ + 'ON' => [ + $itemtable => 'entities_id', + 'glpi_entities' => 'id' + ] + ]; } - $query .= " WHERE `$itemtable`.`id` = `glpi_items_tickets`.`items_id` - AND `glpi_items_tickets`.`itemtype` = '$itemtype' - AND `glpi_items_tickets`.`tickets_id` = '$instID'"; + $where_conditions = [ + 'glpi_items_tickets.itemtype' => $itemtype, + 'glpi_items_tickets.tickets_id' => $instID + ]; if ($item->maybeTemplate()) { - $query .= " AND `$itemtable`.`is_template` = '0'"; + $where_conditions["$itemtable.is_template"] = 0; } - $query .= $dbu->getEntitiesRestrictRequest( - ' AND', + $entity_restrict = $dbu->getEntitiesRestrictRequest( + '', $itemtable, '', '', $item->maybeRecursive(), - ) . " - ORDER BY `glpi_entities`.`completename`, `$itemtable`.`name`"; + ); + + if (!empty($entity_restrict)) { + $where_conditions[] = new \Glpi\DBAL\QueryExpression($entity_restrict); + } - $result_linked = $DB->request($query); + // Construction de la requête finale + $query_params = [ + 'SELECT' => $select_fields, + 'FROM' => $itemtable, + 'LEFT JOIN' => $joins, + 'WHERE' => $where_conditions, + 'ORDER' => ['glpi_entities.completename', "$itemtable.name"] + ]; + + $result_linked = $DB->request($query_params); $nb = count($result_linked); $prem = true; @@ -216,38 +240,88 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $order = '`glpi_tickets`.`date_mod` DESC'; } - $SELECT = ''; - $FROM = ''; + $select_fields = [ + 'glpi_tickets.*', + 'glpi_itilcategories.completename AS catname' + ]; + + if (count($_SESSION['glpiactiveentities']) > 1) { + $select_fields[] = 'glpi_entities.completename AS entityname'; + $select_fields[] = 'glpi_tickets.entities_id AS entityID'; + } + + $left_joins = [ + 'glpi_groups_tickets' => [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_groups_tickets' => 'tickets_id' + ] + ], + 'glpi_tickets_users' => [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_tickets_users' => 'tickets_id' + ] + ], + 'glpi_suppliers_tickets' => [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_suppliers_tickets' => 'tickets_id' + ] + ], + 'glpi_itilcategories' => [ + 'ON' => [ + 'glpi_tickets' => 'itilcategories_id', + 'glpi_itilcategories' => 'id' + ] + ], + 'glpi_tickettasks' => [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_tickettasks' => 'tickets_id' + ] + ], + 'glpi_items_tickets' => [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_items_tickets' => 'tickets_id' + ] + ] + ]; + if (count($_SESSION['glpiactiveentities']) > 1) { - $SELECT = ', `glpi_entities`.`completename` AS entityname, - `glpi_tickets`.`entities_id` AS entityID '; - $FROM = ' LEFT JOIN `glpi_entities` - ON (`glpi_entities`.`id` = `glpi_tickets`.`entities_id`) '; + $left_joins['glpi_entities'] = [ + 'ON' => [ + 'glpi_entities' => 'id', + 'glpi_tickets' => 'entities_id' + ] + ]; + } + + $where_conditions = []; + + if (strpos($restrict, 'OR') !== false || strpos($restrict, 'AND') !== false) { + $where_conditions[] = new \Glpi\DBAL\QueryExpression($restrict); + } else { + $where_conditions[] = $restrict; + } + + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_tickets'); + if (!empty($entity_restrict)) { + $where_conditions[] = new \Glpi\DBAL\QueryExpression($entity_restrict); } - $query = "SELECT DISTINCT `glpi_tickets`.*, - `glpi_itilcategories`.`completename` AS catname - $SELECT - FROM `glpi_tickets` - LEFT JOIN `glpi_groups_tickets` - ON (`glpi_tickets`.`id` = `glpi_groups_tickets`.`tickets_id`) - LEFT JOIN `glpi_tickets_users` - ON (`glpi_tickets`.`id` = `glpi_tickets_users`.`tickets_id`) - LEFT JOIN `glpi_suppliers_tickets` - ON (`glpi_tickets`.`id` = `glpi_suppliers_tickets`.`tickets_id`) - LEFT JOIN `glpi_itilcategories` - ON (`glpi_tickets`.`itilcategories_id` = `glpi_itilcategories`.`id`) - LEFT JOIN `glpi_tickettasks` - ON (`glpi_tickets`.`id` = `glpi_tickettasks`.`tickets_id`) - LEFT JOIN `glpi_items_tickets` - ON (`glpi_tickets`.`id` = `glpi_items_tickets`.`tickets_id`) - $FROM - WHERE $restrict " . - $dbu->getEntitiesRestrictRequest('AND', 'glpi_tickets') . " - ORDER BY $order - LIMIT " . intval($_SESSION['glpilist_limit']); - - $result = $DB->request($query); + $query_params = [ + 'SELECT' => $select_fields, + 'DISTINCT' => true, + 'FROM' => 'glpi_tickets', + 'LEFT JOIN' => $left_joins, + 'WHERE' => $where_conditions, + 'ORDER' => $order, + 'LIMIT' => intval($_SESSION['glpilist_limit']) + ]; + + $result = $DB->request($query_params); $number = count($result); $pdf->setColumnsSize(100); @@ -456,9 +530,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $first = true; $listitems = $texteitem = ''; - foreach ($DB->request( - 'glpi_items_tickets', - ['WHERE' => ['tickets_id' => $job->fields['id']]], + foreach ($DB->request(['FROM' => 'glpi_items_tickets'] + ['WHERE' => ['tickets_id' => $job->fields['id']]], ) as $data) { if (!($item = $dbu->getItemForItemtype($data['itemtype']))) { continue; diff --git a/inc/itilfollowup.class.php b/inc/itilfollowup.class.php index 8f5b08d..d50f67d 100644 --- a/inc/itilfollowup.class.php +++ b/inc/itilfollowup.class.php @@ -103,7 +103,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $pr ); - $content = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($data['content'])); + $content = $data['content']; $content = preg_replace('#data:image/[^;]+;base64,#', '@', $content); preg_match_all('/]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $content, $res, PREG_SET_ORDER); diff --git a/inc/itilsolution.class.php b/inc/itilsolution.class.php index 6a59bf7..b3cde31 100644 --- a/inc/itilsolution.class.php +++ b/inc/itilsolution.class.php @@ -48,9 +48,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); - $soluce = $DB->request( - 'glpi_itilsolutions', - ['itemtype' => $item->getType(), + $soluce = $DB->request(['FROM' => 'glpi_itilsolutions'] + ['itemtype' => $item->getType(), 'items_id' => $item->fields['id']], ); @@ -71,7 +69,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) } else { $title = __('Solution'); } - $sol = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($row['content'])); + $sol = $row['content']; $sol = preg_replace('#data:image/[^;]+;base64,#', '@', $sol); preg_match_all('/]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $sol, $res, PREG_SET_ORDER); diff --git a/inc/knowbaseitem.class.php b/inc/knowbaseitem.class.php index b8b5787..a6272ca 100644 --- a/inc/knowbaseitem.class.php +++ b/inc/knowbaseitem.class.php @@ -71,13 +71,9 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) )); $question - = Toolbox::stripTags(Glpi\Toolbox\Sanitizer::unsanitize(html_entity_decode( - $item->getField('name'), - ENT_QUOTES, - 'UTF-8', - ))); + = Toolbox::stripTags(html_entity_decode($item->getField('name'))); - $answer = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($item->getField('answer'))); + $answer = $item->getField('answer'); $answer = preg_replace('#data:image/[^;]+;base64,#', '@', $answer); preg_match_all('/]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $answer, $res, PREG_SET_ORDER); diff --git a/inc/networkport.class.php b/inc/networkport.class.php index a5005ec..800b4f8 100644 --- a/inc/networkport.class.php +++ b/inc/networkport.class.php @@ -51,9 +51,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $type = get_class($item); $pdf->setColumnsSize(100); - $result = $DB->request( - 'glpi_networkports', - ['SELECT' => ['id', 'name', 'logical_number'], + $result = $DB->request(['FROM' => 'glpi_networkports'] + ['SELECT' => ['id', 'name', 'logical_number'], 'WHERE' => ['items_id' => $ID, 'itemtype' => $type], 'ORDER' => ['name', 'logical_number']], diff --git a/inc/preference.class.php b/inc/preference.class.php index a024925..26838e0 100644 --- a/inc/preference.class.php +++ b/inc/preference.class.php @@ -30,6 +30,8 @@ * -------------------------------------------------------------------------- */ +use Glpi\Application\View\TemplateRenderer; + class PluginPdfPreference extends CommonDBTM { public static $rightname = 'plugin_pdf'; @@ -55,17 +57,6 @@ public static function showPreferences() echo ''; } - /** - * @param $num - * @param $label - * @param $checked (false by default) - **/ - public function checkbox($num, $label, $checked = false) - { - echo " " . $label . ''; - } - /** * @param $item * @param $action @@ -78,7 +69,6 @@ public function menu($item, $action) $type = $item->getType(); - // $ID set if current object, not set from preference if (isset($item->fields['id'])) { $ID = $item->fields['id']; } else { @@ -93,98 +83,57 @@ public function menu($item, $action) $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); $options = $itempdf->defineAllTabsPDF(); - $formid = "plugin_pdf_{$type}_" . mt_rand(); - echo "
"; - $landscape = false; $values = []; - foreach ($DB->request( - $this->getTable(), - ['SELECT' => 'tabref', - 'WHERE' => ['users_id' => $_SESSION['glpiID'], - 'itemtype' => $type]], - ) as $data) { + $criterias = [ + 'SELECT' => 'tabref', + 'FROM' => $this->getTable(), + 'WHERE' => [ + 'users_id' => $_SESSION['glpiID'], + 'itemtype' => $type, + ], + ]; + + foreach ($DB->request($criterias) as $data) { if ($data['tabref'] == 'landscape') { $landscape = true; } else { $values[$data['tabref']] = $data['tabref']; } } - // Always export, at least, main part. + if (!count($values) && isset($options[$type . '$main'])) { $values[$type . '$main'] = 1; } - echo "'; - - $i = 0; - foreach ($options as $num => $title) { - if (!$i) { - echo ""; - } - if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { - $title = "$title ($num)"; - } - $this->checkbox($num, $title, (isset($values[$num]) ? true : false)); - if ($i == 4) { - echo ''; - $i = 0; - } else { - $i++; - } - } - if ($i) { - while ($i <= 4) { - echo ""; - $i++; - } - echo ''; - } - - echo "'; - - echo "
" . sprintf( - __('%1$s: %2$s'), - __('Choose the tables to print in pdf', 'pdf'), - $item->getTypeName(), - ); - echo '
 
"; - echo "" . __('Check all') . ' / '; - echo "" . __('Uncheck all') . '"; - echo Html::hidden('plugin_pdf_inventory_type', ['value' => $type]); - echo Html::hidden('indice', ['value' => count($options)]); - - if ($ID) { - echo __('Display (number of items)') . ' '; - Dropdown::showListLimit(); - } - echo "    \n"; + $formid = "plugin_pdf_{$type}_" . mt_rand(); - if ($ID) { - echo Html::hidden('itemID', ['value' => $ID]); - echo Html::submit(_sx('button', 'Print', 'pdf'), ['name' => 'generate', - 'class' => 'btn btn-primary']); - } else { - echo Html::submit(_sx('button', 'Save'), ['name' => 'plugin_pdf_user_preferences_save', - 'class' => 'btn btn-primary', - 'icon' => 'ti ti-device-floppy']); - } - echo '
'; - Html::closeForm(); + $template_data = [ + 'form_id' => $formid, + 'action' => $action, + 'item_id' => $ID, + 'item_type_name' => $item->getTypeName(), + 'inventory_type' => $type, + 'options' => $options, + 'values' => $values, + 'landscape' => $landscape, + 'debug_mode' => $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE, + ]; + + TemplateRenderer::getInstance()->display('@pdf/preference_form.html.twig', $template_data); } public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (($item->getType() == 'Preference')) { - return __('Print to pdf', 'pdf'); + $icon_html = sprintf('', 'file-type-pdf'); + + return sprintf( + '%s%s', + $icon_html, + __('Print to pdf', 'pdf'), + ); } return ''; @@ -219,7 +168,7 @@ public static function install(Migration $mig) PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET= {$default_charset} COLLATE = {$default_collation} ROW_FORMAT=DYNAMIC"; - $DB->doQueryOrDie($query, $DB->error()); + $DB->doQuery($query); } else { if ($DB->tableExists('glpi_plugin_pdf_preference')) { $mig->renameTable('glpi_plugin_pdf_preference', 'glpi_plugin_pdf_preferences'); diff --git a/inc/problem.class.php b/inc/problem.class.php index f2bf915..8f84706 100644 --- a/inc/problem.class.php +++ b/inc/problem.class.php @@ -263,10 +263,10 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) ); foreach ($job->getGroups(CommonITILActor::ASSIGN) as $d) { $groups[] - = Toolbox::stripTags(Glpi\Toolbox\Sanitizer::unsanitize(Dropdown::getDropdownName( + = Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_groups', $d['groups_id'], - ))); + )); } if (count($groups)) { $listgroups = implode(', ', $groups); @@ -315,35 +315,26 @@ public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Problem $job) $text = ''; if ($job->fields['impactcontent']) { - $text = Toolbox::stripTags(Glpi\Toolbox\Sanitizer::unsanitize( + $text = Toolbox::stripTags( html_entity_decode( $job->getField('impactcontent'), - ENT_QUOTES, - 'UTF-8', - ), )); } $pdf->displayText('' . sprintf(__('%1$s: %2$s'), __('Impacts') . '', $text)); if ($job->fields['causecontent']) { - $text = Toolbox::stripTags(Glpi\Toolbox\Sanitizer::unsanitize( + $text = Toolbox::stripTags( html_entity_decode( $job->getField('causecontent'), - ENT_QUOTES, - 'UTF-8', - ), )); } $pdf->displayText('' . sprintf(__('%1$s: %2$s'), __('Causes') . '', $text)); if ($job->fields['symptomcontent']) { - $text = Toolbox::stripTags(Glpi\Toolbox\Sanitizer::unsanitize( + $text = Toolbox::stripTags( html_entity_decode( $job->getField('symptomcontent'), - ENT_QUOTES, - 'UTF-8', - ), )); } diff --git a/inc/profile.class.php b/inc/profile.class.php index 8f40a86..5526cd0 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -91,7 +91,13 @@ public function showForm($ID, $options = []) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Profile') { - return __('Print to pdf', 'pdf'); + $icon_html = sprintf('', 'file-type-pdf'); + + return sprintf( + '%s%s', + $icon_html, + __('Print to pdf', 'pdf'), + ); } return ''; @@ -171,9 +177,7 @@ public static function initProfile() } } - foreach ($DB->request( - 'glpi_profilerights', - ['profiles_id' => $_SESSION['glpiactiveprofile']['id'], + foreach ($DB->request(['FROM' => 'glpi_profilerights'] + ['profiles_id' => $_SESSION['glpiactiveprofile']['id'], 'name' => ['LIKE', '%plugin_pdf%']], ) as $prof) { $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; @@ -209,7 +213,13 @@ public static function install(Migration $mig) $profileRight = new ProfileRight(); if ($DB->tableExists($table)) { - foreach ($DB->request($table, ['use' => 1]) as $data) { + $criterias = [ + 'FROM' => $table, + 'WHERE' => [ + 'use' => 1 + ] + ]; + foreach ($DB->request($criterias) as $data) { $right['profiles_id'] = $data['id']; $right['name'] = 'plugin_pdf'; $right['rights'] = $data['use']; diff --git a/inc/ticket.class.php b/inc/ticket.class.php index b74611c..7268768 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -457,7 +457,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) '' . sprintf(__('%1$s: %2$s'), __('Title') . '', $job->fields['name']), ); - $content = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($job->fields['content'])); + $content = $job->fields['content']; $content = preg_replace('#data:image/[^;]+;base64,#', '@', $content); @@ -478,7 +478,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) ); // Linked tickets - $tickets = Ticket_Ticket::getLinkedTicketsTo($ID); + $tickets = Ticket_Ticket::getLinkedTo(Ticket::class, $ID); if (count($tickets)) { $ticket = new Ticket(); $pdf->displayLine('' . sprintf( diff --git a/inc/tickettask.class.php b/inc/tickettask.class.php index ce14193..aa8dc77 100644 --- a/inc/tickettask.class.php +++ b/inc/tickettask.class.php @@ -146,7 +146,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job, $priva Toolbox::stripTags($dbu->getUserName($data['users_id'])), $planification, ); - $content = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($data['content'])); + $content = $data['content']; $content = preg_replace('#data:image/[^;]+;base64,#', '@', $content); preg_match_all('/]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $content, $res, PREG_SET_ORDER); diff --git a/inc/ticketvalidation.class.php b/inc/ticketvalidation.class.php index bf1d617..6d27c0e 100644 --- a/inc/ticketvalidation.class.php +++ b/inc/ticketvalidation.class.php @@ -54,9 +54,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) } $ID = $ticket->getField('id'); - $result = $DB->request( - 'glpi_ticketvalidations', - ['WHERE' => ['tickets_id' => $ticket->getField('id')], + $result = $DB->request(['FROM' => 'glpi_ticketvalidations'] + ['WHERE' => ['tickets_id' => $ticket->getField('id')], 'ORDER' => 'submission_date DESC'], ); diff --git a/inc/user.class.php b/inc/user.class.php index 98456cc..e6ffa62 100644 --- a/inc/user.class.php +++ b/inc/user.class.php @@ -91,7 +91,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, User $item) ); $emails = []; - foreach ($DB->request('glpi_useremails', ['users_id' => $item->getField('id')]) as $key => $email) { + foreach ($DB->request(['FROM' => 'glpi_useremails', 'WHERE' => ['users_id' => $item->getField('id')]]) as $key => $email) { if ($email['is_default'] == 1) { $emails[] = $email['email'] . ' (' . __('Default email') . ')'; } else { diff --git a/phpstan.neon b/phpstan.neon index 1a1e4a6..8c5e662 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,8 @@ parameters: maximumNumberOfProcesses: 2 level: 5 bootstrapFiles: - - ../../inc/based_config.php + - ../../stubs/glpi_constants.php + - ../../vendor/autoload.php paths: - front - inc diff --git a/setup.php b/setup.php index c978a12..7e7053a 100644 --- a/setup.php +++ b/setup.php @@ -33,9 +33,11 @@ * -------------------------------------------------------------------------- */ -define('PLUGIN_PDF_VERSION', '4.0.2'); -define('PLUGIN_PDF_MIN_GLPI', '10.0.11'); -define('PLUGIN_PDF_MAX_GLPI', '10.0.99'); +use Glpi\Http\Firewall; + +define('PLUGIN_PDF_VERSION', '4.0.1'); +define('PLUGIN_PDF_MIN_GLPI', '11.0.0'); +define('PLUGIN_PDF_MAX_GLPI', '11.0.99'); function plugin_init_pdf() { diff --git a/templates/preference_form.html.twig b/templates/preference_form.html.twig new file mode 100644 index 0000000..082f8c3 --- /dev/null +++ b/templates/preference_form.html.twig @@ -0,0 +1,185 @@ +{# + # PDF Plugin preference form template + # ------------------------------------------------------------------------- + #} + + + +
+
+

+ + {{ __('%1$s: %2$s')|format(__('Choose the tables to print in pdf', 'pdf'), item_type_name) }} +

+
+ +
+ {% if debug_mode %} +
+ + {{ __('Debug mode enabled - showing internal references') }} +
+ {% endif %} + +
+
+
+ + + {{ __('Available tables', 'pdf') }} + + +
+ + + + + {{ __('Select tables to include in PDF export', 'pdf') }} + +
+ +
+ {% for option_key, option_title in options %} +
+
+
+
+ + +
+
+
+
+ {% endfor %} +
+
+
+
+ +
+
+
+ + +
+
+ + {% if item_id %} +
+
+ + +
+
+ {% endif %} +
+
+ + +
+ + + From 7ee0a827767b9d0fead06545b73ad36782f2e701 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Fri, 27 Jun 2025 17:55:21 +0200 Subject: [PATCH 02/26] GLPI 11 compatibility --- front/config.form.php | 2 -- front/export.massive.php | 2 -- front/export.php | 2 -- tools/move_to_po.php | 4 ++-- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/front/config.form.php b/front/config.form.php index 3ea7941..0ef89c5 100644 --- a/front/config.form.php +++ b/front/config.form.php @@ -30,8 +30,6 @@ * -------------------------------------------------------------------------- */ -include('../../../inc/includes.php'); - Session::checkLoginUser(); // No autoload when plugin is not activated diff --git a/front/export.massive.php b/front/export.massive.php index fac0208..d9fcdf6 100644 --- a/front/export.massive.php +++ b/front/export.massive.php @@ -30,8 +30,6 @@ * -------------------------------------------------------------------------- */ -include('../../../inc/includes.php'); - Session::checkRight('plugin_pdf', READ); Plugin::load('pdf', true); diff --git a/front/export.php b/front/export.php index 37d8143..348e7aa 100644 --- a/front/export.php +++ b/front/export.php @@ -36,8 +36,6 @@ define('GLPI_KEEP_CSRF_TOKEN', true); // 0.90 $token = (isset($_POST['_glpi_csrf_token']) ? $_POST['_glpi_csrf_token'] : false); -include('../../../inc/includes.php'); - Session::checkRight('plugin_pdf', READ); Plugin::load('pdf', true); diff --git a/tools/move_to_po.php b/tools/move_to_po.php index 2c28b44..656ef2e 100755 --- a/tools/move_to_po.php +++ b/tools/move_to_po.php @@ -58,7 +58,7 @@ if (!is_readable(GLPI_ROOT . '/locales/' . $_GET['lang'] . '.php')) { print "Unable to read dictionnary file\n"; - exit(); + return; } include(GLPI_ROOT . '/locales/en_GB.php'); /** @var array $LANG */ @@ -84,7 +84,7 @@ if (!is_readable(GLPI_ROOT . '/locales/glpi.pot')) { print "Unable to read glpi.pot file\n"; - exit(); + return; } $current_string = ''; $current_string_plural = ''; From a08fb638f872d07424c92279207f452741a0d182 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Fri, 27 Jun 2025 18:00:19 +0200 Subject: [PATCH 03/26] Fix file headers --- inc/computer_item.class.php | 3 +-- templates/preference_form.html.twig | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/inc/computer_item.class.php b/inc/computer_item.class.php index 9332a4b..253bc80 100644 --- a/inc/computer_item.class.php +++ b/inc/computer_item.class.php @@ -1,7 +1,5 @@ . + # + # @author Nelly Mahu-Lasson, Remi Collet, Teclib + # @copyright Copyright (c) 2009-2022 PDF plugin team + # @license AGPL License 3.0 or (at your option) any later version + # @link https://github.com/pluginsGLPI/pdf/ + # @link http://www.glpi-project.org/ + # @package pdf + # @since 2009 + # http://www.gnu.org/licenses/agpl-3.0-standalone.html + # -------------------------------------------------------------------------- #}
From 31b7460c05c10395ca18f72f4dd2117109fb0440 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Fri, 27 Jun 2025 18:04:18 +0200 Subject: [PATCH 04/26] Fix php-cs-fixer --- front/export.massive.php | 4 +- inc/appliance.class.php | 2 +- inc/cartridge.class.php | 30 +++---- inc/change_item.class.php | 18 ++-- inc/change_problem.class.php | 4 +- inc/change_ticket.class.php | 6 +- inc/changetask.class.php | 2 +- inc/changevalidation.class.php | 2 +- inc/commonitilcost.class.php | 2 +- inc/computer_item.class.php | 16 ++-- inc/computer_softwarelicense.class.php | 38 ++++---- inc/computer_softwareversion.class.php | 120 ++++++++++++------------- inc/consumableitem.class.php | 3 +- inc/document.class.php | 3 +- inc/group.class.php | 4 +- inc/item_device.class.php | 4 +- inc/item_disk.class.php | 3 +- inc/item_knowbaseitem.class.php | 3 +- inc/item_problem.class.php | 49 +++++----- inc/item_softwarelicense.class.php | 38 ++++---- inc/item_softwareversion.class.php | 82 ++++++++--------- inc/item_ticket.class.php | 56 ++++++------ inc/itilsolution.class.php | 3 +- inc/networkport.class.php | 3 +- inc/problem.class.php | 9 +- inc/profile.class.php | 7 +- inc/ticketvalidation.class.php | 3 +- 27 files changed, 265 insertions(+), 249 deletions(-) diff --git a/front/export.massive.php b/front/export.massive.php index d9fcdf6..659eeda 100644 --- a/front/export.massive.php +++ b/front/export.massive.php @@ -48,8 +48,8 @@ 'SELECT' => 'tabref', 'WHERE' => [ 'users_ID' => $_SESSION['glpiID'], - 'itemtype' => $type - ] + 'itemtype' => $type, + ], ]); $tab = []; diff --git a/inc/appliance.class.php b/inc/appliance.class.php index 61fa5be..7f66908 100644 --- a/inc/appliance.class.php +++ b/inc/appliance.class.php @@ -223,7 +223,7 @@ public static function pdfForAppliance(PluginPdfSimplePDF $pdf, Appliance $appli $result = $DB->request([ 'SELECT' => 'DISTINCT itemtype', 'FROM' => 'glpi_appliances_items', - 'WHERE' => ['appliances_id' => $instID] + 'WHERE' => ['appliances_id' => $instID], ]); $number = count($result); diff --git a/inc/cartridge.class.php b/inc/cartridge.class.php index 229e534..4ad10ab 100644 --- a/inc/cartridge.class.php +++ b/inc/cartridge.class.php @@ -73,34 +73,34 @@ public static function pdfForPrinter(PluginPdfSimplePDF $pdf, Printer $p, $old = 'glpi_cartridges.date_use', 'glpi_cartridges.date_out', 'glpi_cartridges.date_in', - 'glpi_cartridgeitemtypes.name AS typename' + 'glpi_cartridgeitemtypes.name AS typename', ], 'FROM' => 'glpi_cartridges', 'INNER JOIN' => [ 'glpi_cartridgeitems' => [ 'FKEY' => [ 'glpi_cartridges' => 'cartridgeitems_id', - 'glpi_cartridgeitems' => 'id' - ] - ] + 'glpi_cartridgeitems' => 'id', + ], + ], ], 'LEFT JOIN' => [ 'glpi_cartridgeitemtypes' => [ 'FKEY' => [ 'glpi_cartridgeitems' => 'cartridgeitemtypes_id', - 'glpi_cartridgeitemtypes' => 'id' - ] - ] + 'glpi_cartridgeitemtypes' => 'id', + ], + ], ], 'WHERE' => [ 'glpi_cartridges.printers_id' => $instID, - 'glpi_cartridges.date_out' => ($old ? ['NOT' => null] : null) + 'glpi_cartridges.date_out' => ($old ? ['NOT' => null] : null), ], 'ORDER' => [ 'glpi_cartridges.date_out ASC', 'glpi_cartridges.date_use DESC', - 'glpi_cartridges.date_in' - ] + 'glpi_cartridges.date_in', + ], ]; $result = $DB->request($query); @@ -271,18 +271,18 @@ public static function pdfForCartridgeItem(PluginPdfSimplePDF $pdf, CartridgeIte 'glpi_cartridges.*', 'glpi_printers.id AS printID', 'glpi_printers.name AS printname', - 'glpi_printers.init_pages_counter' + 'glpi_printers.init_pages_counter', ], 'LEFT JOIN' => [ 'glpi_printers' => [ 'FKEY' => [ Cartridge::getTable() => 'printers_id', - 'glpi_printers' => 'id' - ] - ] + 'glpi_printers' => 'id', + ], + ], ], 'WHERE' => $where, - 'ORDER' => $order + 'ORDER' => $order, ]); $number = count($iterator); diff --git a/inc/change_item.class.php b/inc/change_item.class.php index d2a4c35..e3b3739 100644 --- a/inc/change_item.class.php +++ b/inc/change_item.class.php @@ -57,7 +57,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) 'SELECT' => 'itemtype', 'DISTINCT' => true, 'WHERE' => ['changes_id' => $instID], - 'ORDER' => 'itemtype' + 'ORDER' => 'itemtype', ]); $number = count($result); @@ -196,27 +196,27 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $SELECT = ['glpi_changes.*', 'glpi_itilcategories.completename AS catname']; $LEFT_JOIN = [ 'glpi_changes_items' => [ - 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_items' => 'changes_id'] + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_items' => 'changes_id'], ], 'glpi_changes_groups' => [ - 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_groups' => 'changes_id'] + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_groups' => 'changes_id'], ], 'glpi_changes_users' => [ - 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_users' => 'changes_id'] + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_users' => 'changes_id'], ], 'glpi_changes_suppliers' => [ - 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_suppliers' => 'changes_id'] + 'FKEY' => ['glpi_changes' => 'id', 'glpi_changes_suppliers' => 'changes_id'], ], 'glpi_itilcategories' => [ - 'FKEY' => ['glpi_changes' => 'itilcategories_id', 'glpi_itilcategories' => 'id'] - ] + 'FKEY' => ['glpi_changes' => 'itilcategories_id', 'glpi_itilcategories' => 'id'], + ], ]; if (count($_SESSION['glpiactiveentities']) > 1) { $SELECT[] = 'glpi_entities.completename AS entityname'; $SELECT[] = 'glpi_changes.entities_id AS entityID'; $LEFT_JOIN['glpi_entities'] = [ - 'FKEY' => ['glpi_entities' => 'id', 'glpi_changes' => 'entities_id'] + 'FKEY' => ['glpi_entities' => 'id', 'glpi_changes' => 'entities_id'], ]; } @@ -227,7 +227,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr 'LEFT JOIN' => $LEFT_JOIN, 'WHERE' => [$restrict] + $dbu->getEntitiesRestrictCriteria('glpi_changes'), 'ORDER' => $order, - 'LIMIT' => (int)$_SESSION['glpilist_limit'] + 'LIMIT' => (int) $_SESSION['glpilist_limit'], ]; $result = $DB->request($query); diff --git a/inc/change_problem.class.php b/inc/change_problem.class.php index 79579c9..50f427b 100644 --- a/inc/change_problem.class.php +++ b/inc/change_problem.class.php @@ -61,7 +61,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) => ['FKEY' => ['glpi_changes_problems' => 'problems_id', 'glpi_problems' => 'id']]], 'WHERE' => ['changes_id' => $ID], - 'ORDER' => 'name' + 'ORDER' => 'name', ]); $number = count($result); @@ -303,7 +303,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) => ['FKEY' => ['glpi_changes_problems' => 'changes_id', 'glpi_changes' => 'id']]], 'WHERE' => ['problems_id' => $ID], - 'ORDER' => 'name' + 'ORDER' => 'name', ]); $number = count($result); diff --git a/inc/change_ticket.class.php b/inc/change_ticket.class.php index 476eb9b..29efd41 100644 --- a/inc/change_ticket.class.php +++ b/inc/change_ticket.class.php @@ -61,7 +61,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) => ['FKEY' => ['glpi_changes_tickets' => 'tickets_id', 'glpi_tickets' => 'id']]], 'WHERE' => ['changes_id' => $ID], - 'ORDER' => 'name' + 'ORDER' => 'name', ]); $number = count($result); @@ -276,7 +276,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $listitems = $texteitem = ''; foreach ($DB->request([ 'FROM' => 'glpi_items_tickets', - 'WHERE' => ['tickets_id' => $job->fields['id']] + 'WHERE' => ['tickets_id' => $job->fields['id']], ]) as $data) { if (!($item = $dbu->getItemForItemtype($data['itemtype']))) { continue; @@ -331,7 +331,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) => ['FKEY' => ['glpi_changes_tickets' => 'changes_id', 'glpi_changes' => 'id']]], 'WHERE' => ['tickets_id' => $ID], - 'ORDER' => 'name' + 'ORDER' => 'name', ]); $number = count($result); diff --git a/inc/changetask.class.php b/inc/changetask.class.php index 4ddf1d8..1cd7f65 100644 --- a/inc/changetask.class.php +++ b/inc/changetask.class.php @@ -51,7 +51,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $job) $result = $DB->request([ 'FROM' => 'glpi_changetasks', 'WHERE' => ['changes_id' => $ID], - 'ORDER' => 'date DESC' + 'ORDER' => 'date DESC', ]); $number = count($result); diff --git a/inc/changevalidation.class.php b/inc/changevalidation.class.php index abb30f5..8df2427 100644 --- a/inc/changevalidation.class.php +++ b/inc/changevalidation.class.php @@ -64,7 +64,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $result = $DB->request([ 'FROM' => 'glpi_changevalidations', 'WHERE' => ['changes_id' => $change->getField('id')], - 'ORDER' => 'submission_date DESC' + 'ORDER' => 'submission_date DESC', ]); $number = count($result); diff --git a/inc/commonitilcost.class.php b/inc/commonitilcost.class.php index 378354a..1bce183 100644 --- a/inc/commonitilcost.class.php +++ b/inc/commonitilcost.class.php @@ -52,7 +52,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $job) $result = $DB->request([ 'FROM' => $table, 'WHERE' => [$job->getForeignKeyField() => $ID], - 'ORDER' => 'begin_date' + 'ORDER' => 'begin_date', ]); $number = count($result); diff --git a/inc/computer_item.class.php b/inc/computer_item.class.php index 253bc80..a1173f8 100644 --- a/inc/computer_item.class.php +++ b/inc/computer_item.class.php @@ -31,6 +31,7 @@ */ use Glpi\Asset\Asset_PeripheralAsset; + class PluginPdfComputer_Item extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; @@ -73,22 +74,22 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) 'glpi_assets_assets_peripheralassets.computers_id AS assoc_computers_id', 'glpi_assets_assets_peripheralassets.itemtype', 'glpi_assets_assets_peripheralassets.items_id', - 'glpi_assets_assets_peripheralassets.is_dynamic AS assoc_is_dynamic' + 'glpi_assets_assets_peripheralassets.is_dynamic AS assoc_is_dynamic', ], 'FROM' => 'glpi_assets_assets_peripheralassets', 'LEFT JOIN' => [ $itemTable => [ 'FKEY' => [ $itemTable => 'id', - 'glpi_assets_assets_peripheralassets' => 'items_id' - ] - ] + 'glpi_assets_assets_peripheralassets' => 'items_id', + ], + ], ], 'WHERE' => [ 'computers_id' => $ID, 'itemtype' => $type, - 'glpi_assets_assets_peripheralassets.is_deleted' => 0 - ] + 'glpi_assets_assets_peripheralassets.is_deleted' => 0, + ], ]; if ($item->maybetemplate()) { @@ -196,7 +197,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); $title = '' . __('Direct connections') . ''; - $result = $DB->request(['FROM' => 'glpi_assets_assets_peripheralassets'] + ['items_id' => $ID, + $result = $DB->request( + ['FROM' => 'glpi_assets_assets_peripheralassets'] + ['items_id' => $ID, 'itemtype' => $type], ); $resultnum = count($result); diff --git a/inc/computer_softwarelicense.class.php b/inc/computer_softwarelicense.class.php index 696ec2e..9fb333f 100644 --- a/inc/computer_softwarelicense.class.php +++ b/inc/computer_softwarelicense.class.php @@ -134,63 +134,63 @@ public static function pdfForLicenseByComputer(PluginPdfSimplePDF $pdf, Software 'glpi_states.name AS state', 'glpi_groups.name AS groupe', 'glpi_softwarelicenses.name AS lname', - 'glpi_softwarelicenses.id AS lID' + 'glpi_softwarelicenses.id AS lID', ], 'FROM' => 'glpi_computers_softwarelicenses', 'INNER JOIN' => [ 'glpi_softwarelicenses' => [ 'ON' => [ 'glpi_computers_softwarelicenses' => 'softwarelicenses_id', - 'glpi_softwarelicenses' => 'id' - ] + 'glpi_softwarelicenses' => 'id', + ], ], 'glpi_computers' => [ 'ON' => [ 'glpi_computers_softwarelicenses' => 'computers_id', - 'glpi_computers' => 'id' - ] - ] + 'glpi_computers' => 'id', + ], + ], ], 'LEFT JOIN' => [ 'glpi_entities' => [ 'ON' => [ 'glpi_computers' => 'entities_id', - 'glpi_entities' => 'id' - ] + 'glpi_entities' => 'id', + ], ], 'glpi_locations' => [ 'ON' => [ 'glpi_computers' => 'locations_id', - 'glpi_locations' => 'id' - ] + 'glpi_locations' => 'id', + ], ], 'glpi_states' => [ 'ON' => [ 'glpi_computers' => 'states_id', - 'glpi_states' => 'id' - ] + 'glpi_states' => 'id', + ], ], 'glpi_groups' => [ 'ON' => [ 'glpi_computers' => 'groups_id', - 'glpi_groups' => 'id' - ] + 'glpi_groups' => 'id', + ], ], 'glpi_users' => [ 'ON' => [ 'glpi_computers' => 'users_id', - 'glpi_users' => 'id' - ] - ] + 'glpi_users' => 'id', + ], + ], ], 'WHERE' => [ 'glpi_softwarelicenses.id' => $ID, 'glpi_computers.is_deleted' => 0, - 'glpi_computers.is_template' => 0 + 'glpi_computers.is_template' => 0, ], 'ORDER' => ['entity', 'compname'], 'START' => 0, - 'LIMIT' => intval($_SESSION['glpilist_limit']) + 'LIMIT' => intval($_SESSION['glpilist_limit']), ]; // Ajout de la restriction d'entités diff --git a/inc/computer_softwareversion.class.php b/inc/computer_softwareversion.class.php index fdddff5..536b8a7 100644 --- a/inc/computer_softwareversion.class.php +++ b/inc/computer_softwareversion.class.php @@ -97,7 +97,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) 'glpi_entities.completename AS entity', 'glpi_locations.completename AS location', 'glpi_states.name AS state', - 'glpi_groups.name AS groupe' + 'glpi_groups.name AS groupe', ], 'DISTINCT' => true, 'FROM' => 'glpi_computers_softwareversions', @@ -105,56 +105,56 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) 'glpi_softwareversions' => [ 'ON' => [ 'glpi_computers_softwareversions' => 'softwareversions_id', - 'glpi_softwareversions' => 'id' - ] + 'glpi_softwareversions' => 'id', + ], ], 'glpi_computers' => [ 'ON' => [ 'glpi_computers_softwareversions' => 'computers_id', - 'glpi_computers' => 'id' - ] - ] + 'glpi_computers' => 'id', + ], + ], ], 'LEFT JOIN' => [ 'glpi_entities' => [ 'ON' => [ 'glpi_computers' => 'entities_id', - 'glpi_entities' => 'id' - ] + 'glpi_entities' => 'id', + ], ], 'glpi_locations' => [ 'ON' => [ 'glpi_computers' => 'locations_id', - 'glpi_locations' => 'id' - ] + 'glpi_locations' => 'id', + ], ], 'glpi_states' => [ 'ON' => [ 'glpi_computers' => 'states_id', - 'glpi_states' => 'id' - ] + 'glpi_states' => 'id', + ], ], 'glpi_groups' => [ 'ON' => [ 'glpi_computers' => 'groups_id', - 'glpi_groups' => 'id' - ] + 'glpi_groups' => 'id', + ], ], 'glpi_users' => [ 'ON' => [ 'glpi_computers' => 'users_id', - 'glpi_users' => 'id' - ] - ] + 'glpi_users' => 'id', + ], + ], ], 'WHERE' => [ "glpi_softwareversions.$crit" => $ID, 'glpi_computers.is_deleted' => 0, - 'glpi_computers.is_template' => 0 + 'glpi_computers.is_template' => 0, ], 'ORDER' => ['version', 'compname'], 'START' => 0, - 'LIMIT' => intval($_SESSION['glpilist_limit']) + 'LIMIT' => intval($_SESSION['glpilist_limit']), ]; // Ajout de la restriction d'entités @@ -318,34 +318,34 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) 'glpi_softwareversions.softwares_id', 'glpi_softwareversions.name AS version', 'glpi_softwares.is_valid AS softvalid', - 'glpi_computers_softwareversions.date_install AS dateinstall' + 'glpi_computers_softwareversions.date_install AS dateinstall', ], 'FROM' => 'glpi_computers_softwareversions', 'LEFT JOIN' => [ 'glpi_softwareversions' => [ 'ON' => [ 'glpi_computers_softwareversions' => 'softwareversions_id', - 'glpi_softwareversions' => 'id' - ] + 'glpi_softwareversions' => 'id', + ], ], 'glpi_states' => [ 'ON' => [ 'glpi_states' => 'id', - 'glpi_softwareversions' => 'states_id' - ] + 'glpi_softwareversions' => 'states_id', + ], ], 'glpi_softwares' => [ 'ON' => [ 'glpi_softwareversions' => 'softwares_id', - 'glpi_softwares' => 'id' - ] - ] + 'glpi_softwares' => 'id', + ], + ], ], 'WHERE' => [ 'glpi_computers_softwareversions.computers_id' => $ID, - 'glpi_computers_softwareversions.is_deleted' => 0 + 'glpi_computers_softwareversions.is_deleted' => 0, ], - 'ORDER' => ['softwarecategories_id', 'softname', 'version'] + 'ORDER' => ['softwarecategories_id', 'softname', 'version'], ]; $output = []; @@ -396,24 +396,24 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) $query_license_params = [ 'SELECT' => [ 'glpi_softwarelicenses.*', - 'glpi_softwarelicensetypes.name AS type' + 'glpi_softwarelicensetypes.name AS type', ], 'FROM' => 'glpi_computers_softwarelicenses', 'INNER JOIN' => [ 'glpi_softwarelicenses' => [ 'ON' => [ 'glpi_computers_softwarelicenses' => 'softwarelicenses_id', - 'glpi_softwarelicenses' => 'id' - ] - ] + 'glpi_softwarelicenses' => 'id', + ], + ], ], 'LEFT JOIN' => [ 'glpi_softwarelicensetypes' => [ 'ON' => [ 'glpi_softwarelicenses' => 'softwarelicensetypes_id', - 'glpi_softwarelicensetypes' => 'id' - ] - ] + 'glpi_softwarelicensetypes' => 'id', + ], + ], ], 'WHERE' => [ 'glpi_computers_softwarelicenses.computers_id' => $ID, @@ -422,11 +422,11 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) [ 'AND' => [ 'glpi_softwarelicenses.softwareversions_id_use' => 0, - 'glpi_softwarelicenses.softwareversions_id_buy' => $verid - ] - ] - ] - ] + 'glpi_softwarelicenses.softwareversions_id_buy' => $verid, + ], + ], + ], + ], ]; $lic = ''; @@ -455,58 +455,58 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) 'glpi_softwarelicenses.*', 'glpi_softwares.name AS softname', 'glpi_softwareversions.name AS version', - 'glpi_states.name AS state' + 'glpi_states.name AS state', ], 'FROM' => 'glpi_softwarelicenses', 'LEFT JOIN' => [ 'glpi_computers_softwarelicenses' => [ 'ON' => [ 'glpi_computers_softwarelicenses' => 'softwarelicenses_id', - 'glpi_softwarelicenses' => 'id' - ] + 'glpi_softwarelicenses' => 'id', + ], ], 'glpi_softwareversions' => [ 'ON' => [ 'OR' => [ [ 'glpi_softwarelicenses' => 'softwareversions_id_use', - 'glpi_softwareversions' => 'id' + 'glpi_softwareversions' => 'id', ], [ 'AND' => [ 'glpi_softwarelicenses.softwareversions_id_use' => 0, [ 'glpi_softwarelicenses' => 'softwareversions_id_buy', - 'glpi_softwareversions' => 'id' - ] - ] - ] - ] - ] + 'glpi_softwareversions' => 'id', + ], + ], + ], + ], + ], ], 'glpi_states' => [ 'ON' => [ 'glpi_states' => 'id', - 'glpi_softwareversions' => 'states_id' - ] - ] + 'glpi_softwareversions' => 'states_id', + ], + ], ], 'INNER JOIN' => [ 'glpi_softwares' => [ 'ON' => [ 'glpi_softwarelicenses' => 'softwares_id', - 'glpi_softwares' => 'id' - ] - ] + 'glpi_softwares' => 'id', + ], + ], ], 'WHERE' => [ - 'glpi_computers_softwarelicenses.computers_id' => $ID - ] + 'glpi_computers_softwarelicenses.computers_id' => $ID, + ], ]; if (count($installed)) { $query_affected_params['WHERE'][] = new \Glpi\DBAL\QueryExpression( - 'glpi_softwarelicenses.id NOT IN (' . implode(',', $installed) . ')' + 'glpi_softwarelicenses.id NOT IN (' . implode(',', $installed) . ')', ); } diff --git a/inc/consumableitem.class.php b/inc/consumableitem.class.php index 84b96ae..897d21b 100644 --- a/inc/consumableitem.class.php +++ b/inc/consumableitem.class.php @@ -160,7 +160,8 @@ public static function pdfForConsumableItem(PluginPdfSimplePDF $pdf, ConsumableI $number = $dbu->countElementsInTable('glpi_consumables', $where); - $iterator = $DB->request(['FROM' => 'glpi_consumables'] + ['WHERE' => $where, + $iterator = $DB->request( + ['FROM' => 'glpi_consumables'] + ['WHERE' => $where, 'ORDER' => $order], ); diff --git a/inc/document.class.php b/inc/document.class.php index d282e79..2e524a3 100644 --- a/inc/document.class.php +++ b/inc/document.class.php @@ -47,7 +47,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ID = $item->getField('id'); $type = get_class($item); - $result = $DB->request(['FROM' => 'glpi_documents_items'] + ['SELECT' => ['glpi_documents_items.id', + $result = $DB->request( + ['FROM' => 'glpi_documents_items'] + ['SELECT' => ['glpi_documents_items.id', 'glpi_documents_items.date_mod', 'glpi_documents.*', 'glpi_entities.id', 'completename'], diff --git a/inc/group.class.php b/inc/group.class.php index 1e9240c..43ef59c 100644 --- a/inc/group.class.php +++ b/inc/group.class.php @@ -248,9 +248,9 @@ public static function pdfChildren(PluginPdfSimplePDF $pdf, CommonTreeDropdown $ $crit = [ 'FROM' => $item->getTable(), 'WHERE' => [ - $fk => $item->getID() + $fk => $item->getID(), ], - 'ORDER' => 'name' + 'ORDER' => 'name', ]; if ($item->haveChildren()) { diff --git a/inc/item_device.class.php b/inc/item_device.class.php index 9ebe448..a660810 100644 --- a/inc/item_device.class.php +++ b/inc/item_device.class.php @@ -84,9 +84,9 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) 'FROM' => $linktable, 'WHERE' => [ 'items_id' => $ID, - 'itemtype' => $item->getType() + 'itemtype' => $item->getType(), ], - 'GROUPBY' => $group_by + 'GROUPBY' => $group_by, ]; $device = new $associated_type(); diff --git a/inc/item_disk.class.php b/inc/item_disk.class.php index 1f78896..d2f1d9a 100644 --- a/inc/item_disk.class.php +++ b/inc/item_disk.class.php @@ -46,7 +46,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ID = $item->getField('id'); - $result = $DB->request(['FROM' => 'glpi_items_disks'] + ['SELECT' => ['glpi_filesystems.name', 'glpi_items_disks.*'], + $result = $DB->request( + ['FROM' => 'glpi_items_disks'] + ['SELECT' => ['glpi_filesystems.name', 'glpi_items_disks.*'], 'LEFT JOIN' => ['glpi_filesystems' => ['FKEY' => ['glpi_items_disks' => 'filesystems_id', 'glpi_filesystems' => 'id']]], diff --git a/inc/item_knowbaseitem.class.php b/inc/item_knowbaseitem.class.php index a316331..c39ed0c 100644 --- a/inc/item_knowbaseitem.class.php +++ b/inc/item_knowbaseitem.class.php @@ -46,7 +46,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ID = $item->getField('id'); - $result = $DB->request(['FROM' => 'glpi_knowbaseitems'] + ['SELECT' => ['glpi_knowbaseitems.*', + $result = $DB->request( + ['FROM' => 'glpi_knowbaseitems'] + ['SELECT' => ['glpi_knowbaseitems.*', 'glpi_knowbaseitems_items.itemtype', 'glpi_knowbaseitems_items.items_id'], 'LEFT JOIN' => ['glpi_knowbaseitems_items' diff --git a/inc/item_problem.class.php b/inc/item_problem.class.php index 9c4de44..c753c7f 100644 --- a/inc/item_problem.class.php +++ b/inc/item_problem.class.php @@ -52,7 +52,8 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) return false; } - $result = $DB->request(['FROM' => 'glpi_items_problems'] + ['SELECT' => 'itemtype', + $result = $DB->request( + ['FROM' => 'glpi_items_problems'] + ['SELECT' => 'itemtype', 'DISTINCT' => true, 'WHERE' => ['problems_id' => $instID], 'ORDER' => 'itemtype'], @@ -91,30 +92,30 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) 'SELECT' => [ "$itemtable.*", 'glpi_items_problems.id AS IDD', - 'glpi_entities.id AS entity' + 'glpi_entities.id AS entity', ], 'FROM' => 'glpi_items_problems', 'INNER JOIN' => [ $itemtable => [ 'ON' => [ $itemtable => 'id', - 'glpi_items_problems' => 'items_id' - ] - ] + 'glpi_items_problems' => 'items_id', + ], + ], ], 'WHERE' => [ 'glpi_items_problems.itemtype' => $itemtype, - 'glpi_items_problems.problems_id' => $instID + 'glpi_items_problems.problems_id' => $instID, ], - 'ORDER' => ['glpi_entities.completename', "$itemtable.name"] + 'ORDER' => ['glpi_entities.completename', "$itemtable.name"], ]; if ($itemtype != 'Entity') { $query_params['LEFT JOIN']['glpi_entities'] = [ 'ON' => [ $itemtable => 'entities_id', - 'glpi_entities' => 'id' - ] + 'glpi_entities' => 'id', + ], ]; } @@ -212,7 +213,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $select_fields = [ 'glpi_problems.*', - 'glpi_itilcategories.completename AS catname' + 'glpi_itilcategories.completename AS catname', ]; if (count($_SESSION['glpiactiveentities']) > 1) { @@ -224,41 +225,41 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr 'glpi_items_problems' => [ 'ON' => [ 'glpi_problems' => 'id', - 'glpi_items_problems' => 'problems_id' - ] + 'glpi_items_problems' => 'problems_id', + ], ], 'glpi_groups_problems' => [ 'ON' => [ 'glpi_problems' => 'id', - 'glpi_groups_problems' => 'problems_id' - ] + 'glpi_groups_problems' => 'problems_id', + ], ], 'glpi_problems_users' => [ 'ON' => [ 'glpi_problems' => 'id', - 'glpi_problems_users' => 'problems_id' - ] + 'glpi_problems_users' => 'problems_id', + ], ], 'glpi_problems_suppliers' => [ 'ON' => [ 'glpi_problems' => 'id', - 'glpi_problems_suppliers' => 'problems_id' - ] + 'glpi_problems_suppliers' => 'problems_id', + ], ], 'glpi_itilcategories' => [ 'ON' => [ 'glpi_problems' => 'itilcategories_id', - 'glpi_itilcategories' => 'id' - ] - ] + 'glpi_itilcategories' => 'id', + ], + ], ]; if (count($_SESSION['glpiactiveentities']) > 1) { $left_joins['glpi_entities'] = [ 'ON' => [ 'glpi_entities' => 'id', - 'glpi_problems' => 'entities_id' - ] + 'glpi_problems' => 'entities_id', + ], ]; } @@ -282,7 +283,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr 'LEFT JOIN' => $left_joins, 'WHERE' => $where_conditions, 'ORDER' => $order, - 'LIMIT' => intval($_SESSION['glpilist_limit']) + 'LIMIT' => intval($_SESSION['glpilist_limit']), ]; $result = $DB->request($query_params); diff --git a/inc/item_softwarelicense.class.php b/inc/item_softwarelicense.class.php index 67e6e64..f5bf317 100644 --- a/inc/item_softwarelicense.class.php +++ b/inc/item_softwarelicense.class.php @@ -135,64 +135,64 @@ public static function pdfForLicenseByComputer(PluginPdfSimplePDF $pdf, Software 'glpi_states.name AS state', 'glpi_groups.name AS groupe', 'glpi_softwarelicenses.name AS lname', - 'glpi_softwarelicenses.id AS lID' + 'glpi_softwarelicenses.id AS lID', ], 'FROM' => 'glpi_items_softwarelicenses', 'INNER JOIN' => [ 'glpi_softwarelicenses' => [ 'ON' => [ 'glpi_items_softwarelicenses' => 'softwarelicenses_id', - 'glpi_softwarelicenses' => 'id' - ] + 'glpi_softwarelicenses' => 'id', + ], ], 'glpi_computers' => [ 'ON' => [ 'glpi_items_softwarelicenses' => 'items_id', 'glpi_computers' => 'id', - ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']] - ] - ] + ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']], + ], + ], ], 'LEFT JOIN' => [ 'glpi_entities' => [ 'ON' => [ 'glpi_computers' => 'entities_id', - 'glpi_entities' => 'id' - ] + 'glpi_entities' => 'id', + ], ], 'glpi_locations' => [ 'ON' => [ 'glpi_computers' => 'locations_id', - 'glpi_locations' => 'id' - ] + 'glpi_locations' => 'id', + ], ], 'glpi_states' => [ 'ON' => [ 'glpi_computers' => 'states_id', - 'glpi_states' => 'id' - ] + 'glpi_states' => 'id', + ], ], 'glpi_groups' => [ 'ON' => [ 'glpi_computers' => 'groups_id', - 'glpi_groups' => 'id' - ] + 'glpi_groups' => 'id', + ], ], 'glpi_users' => [ 'ON' => [ 'glpi_computers' => 'users_id', - 'glpi_users' => 'id' - ] - ] + 'glpi_users' => 'id', + ], + ], ], 'WHERE' => [ 'glpi_softwarelicenses.id' => $ID, 'glpi_computers.is_deleted' => 0, - 'glpi_computers.is_template' => 0 + 'glpi_computers.is_template' => 0, ], 'ORDER' => ['entity', 'compname'], 'START' => 0, - 'LIMIT' => intval($_SESSION['glpilist_limit']) + 'LIMIT' => intval($_SESSION['glpilist_limit']), ]; // Ajout de la restriction d'entités diff --git a/inc/item_softwareversion.class.php b/inc/item_softwareversion.class.php index 489ce22..b9959fc 100644 --- a/inc/item_softwareversion.class.php +++ b/inc/item_softwareversion.class.php @@ -319,7 +319,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) 'glpi_softwareversions.softwares_id', 'glpi_softwareversions.name AS version', 'glpi_softwares.is_valid AS softvalid', - 'glpi_items_softwareversions.date_install AS dateinstall' + 'glpi_items_softwareversions.date_install AS dateinstall', ], 'FROM' => 'glpi_items_softwareversions', 'LEFT JOIN' => [ @@ -327,28 +327,28 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) 'ON' => [ 'glpi_items_softwareversions' => 'softwareversions_id', 'glpi_softwareversions' => 'id', - ['AND' => ['glpi_items_softwareversions.itemtype' => $item->getType()]] - ] + ['AND' => ['glpi_items_softwareversions.itemtype' => $item->getType()]], + ], ], 'glpi_states' => [ 'ON' => [ 'glpi_states' => 'id', - 'glpi_softwareversions' => 'states_id' - ] + 'glpi_softwareversions' => 'states_id', + ], ], 'glpi_softwares' => [ 'ON' => [ 'glpi_softwareversions' => 'softwares_id', - 'glpi_softwares' => 'id' - ] - ] + 'glpi_softwares' => 'id', + ], + ], ], 'WHERE' => [ 'glpi_items_softwareversions.items_id' => $ID, 'glpi_items_softwareversions.itemtype' => $item->getType(), - 'glpi_items_softwareversions.is_deleted' => 0 + 'glpi_items_softwareversions.is_deleted' => 0, ], - 'ORDER' => ['softwarecategories_id', 'softname', 'version'] + 'ORDER' => ['softwarecategories_id', 'softname', 'version'], ]; $output = []; @@ -399,25 +399,25 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) $query_license_params = [ 'SELECT' => [ 'glpi_softwarelicenses.*', - 'glpi_softwarelicensetypes.name AS type' + 'glpi_softwarelicensetypes.name AS type', ], 'FROM' => 'glpi_items_softwarelicenses', 'INNER JOIN' => [ 'glpi_softwarelicenses' => [ 'ON' => [ 'glpi_items_softwarelicenses' => 'softwarelicenses_id', - 'glpi_softwarelicenses' => 'id' - ] - ] + 'glpi_softwarelicenses' => 'id', + ], + ], ], 'LEFT JOIN' => [ 'glpi_softwarelicensetypes' => [ 'ON' => [ 'glpi_softwarelicenses' => 'softwarelicensetypes_id', 'glpi_softwarelicensetypes' => 'id', - ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']] - ] - ] + ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']], + ], + ], ], 'WHERE' => [ 'glpi_items_softwarelicenses.items_id' => $ID, @@ -426,11 +426,11 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) [ 'AND' => [ 'glpi_softwarelicenses.softwareversions_id_use' => 0, - 'glpi_softwarelicenses.softwareversions_id_buy' => $verid - ] - ] - ] - ] + 'glpi_softwarelicenses.softwareversions_id_buy' => $verid, + ], + ], + ], + ], ]; $lic = ''; @@ -459,7 +459,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) 'glpi_softwarelicenses.*', 'glpi_softwares.name AS softname', 'glpi_softwareversions.name AS version', - 'glpi_states.name AS state' + 'glpi_states.name AS state', ], 'FROM' => 'glpi_softwarelicenses', 'LEFT JOIN' => [ @@ -467,51 +467,51 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) 'ON' => [ 'glpi_items_softwarelicenses' => 'softwarelicenses_id', 'glpi_softwarelicenses' => 'id', - ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']] - ] + ['AND' => ['glpi_items_softwarelicenses.itemtype' => 'Computer']], + ], ], 'glpi_softwareversions' => [ 'ON' => [ 'OR' => [ [ 'glpi_softwarelicenses' => 'softwareversions_id_use', - 'glpi_softwareversions' => 'id' + 'glpi_softwareversions' => 'id', ], [ 'AND' => [ 'glpi_softwarelicenses.softwareversions_id_use' => 0, [ 'glpi_softwarelicenses' => 'softwareversions_id_buy', - 'glpi_softwareversions' => 'id' - ] - ] - ] - ] - ] + 'glpi_softwareversions' => 'id', + ], + ], + ], + ], + ], ], 'glpi_states' => [ 'ON' => [ 'glpi_states' => 'id', - 'glpi_softwareversions' => 'states_id' - ] - ] + 'glpi_softwareversions' => 'states_id', + ], + ], ], 'INNER JOIN' => [ 'glpi_softwares' => [ 'ON' => [ 'glpi_softwarelicenses' => 'softwares_id', - 'glpi_softwares' => 'id' - ] - ] + 'glpi_softwares' => 'id', + ], + ], ], 'WHERE' => [ - 'glpi_items_softwarelicenses.items_id' => $ID - ] + 'glpi_items_softwarelicenses.items_id' => $ID, + ], ]; if (count($installed)) { $query_affected_params['WHERE'][] = new \Glpi\DBAL\QueryExpression( - 'glpi_softwarelicenses.id NOT IN (' . implode(',', $installed) . ')' + 'glpi_softwarelicenses.id NOT IN (' . implode(',', $installed) . ')', ); } diff --git a/inc/item_ticket.class.php b/inc/item_ticket.class.php index 1775d39..b98d7b6 100644 --- a/inc/item_ticket.class.php +++ b/inc/item_ticket.class.php @@ -52,7 +52,8 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su return false; } - $result = $DB->request(['FROM' => 'glpi_items_tickets'] + ['SELECT' => 'itemtype', + $result = $DB->request( + ['FROM' => 'glpi_items_tickets'] + ['SELECT' => 'itemtype', 'DISTINCT' => true, 'WHERE' => ['tickets_id' => $instID], 'ORDER' => 'itemtype'], @@ -89,30 +90,30 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su $select_fields = [ "$itemtable.*", 'glpi_items_tickets.id AS IDD', - 'glpi_entities.id AS entity' + 'glpi_entities.id AS entity', ]; $joins = [ 'glpi_items_tickets' => [ 'ON' => [ $itemtable => 'id', - 'glpi_items_tickets' => 'items_id' - ] - ] + 'glpi_items_tickets' => 'items_id', + ], + ], ]; if ($itemtype != 'Entity') { $joins['glpi_entities'] = [ 'ON' => [ $itemtable => 'entities_id', - 'glpi_entities' => 'id' - ] + 'glpi_entities' => 'id', + ], ]; } $where_conditions = [ 'glpi_items_tickets.itemtype' => $itemtype, - 'glpi_items_tickets.tickets_id' => $instID + 'glpi_items_tickets.tickets_id' => $instID, ]; if ($item->maybeTemplate()) { @@ -137,7 +138,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su 'FROM' => $itemtable, 'LEFT JOIN' => $joins, 'WHERE' => $where_conditions, - 'ORDER' => ['glpi_entities.completename', "$itemtable.name"] + 'ORDER' => ['glpi_entities.completename', "$itemtable.name"], ]; $result_linked = $DB->request($query_params); @@ -242,7 +243,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $select_fields = [ 'glpi_tickets.*', - 'glpi_itilcategories.completename AS catname' + 'glpi_itilcategories.completename AS catname', ]; if (count($_SESSION['glpiactiveentities']) > 1) { @@ -254,47 +255,47 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr 'glpi_groups_tickets' => [ 'ON' => [ 'glpi_tickets' => 'id', - 'glpi_groups_tickets' => 'tickets_id' - ] + 'glpi_groups_tickets' => 'tickets_id', + ], ], 'glpi_tickets_users' => [ 'ON' => [ 'glpi_tickets' => 'id', - 'glpi_tickets_users' => 'tickets_id' - ] + 'glpi_tickets_users' => 'tickets_id', + ], ], 'glpi_suppliers_tickets' => [ 'ON' => [ 'glpi_tickets' => 'id', - 'glpi_suppliers_tickets' => 'tickets_id' - ] + 'glpi_suppliers_tickets' => 'tickets_id', + ], ], 'glpi_itilcategories' => [ 'ON' => [ 'glpi_tickets' => 'itilcategories_id', - 'glpi_itilcategories' => 'id' - ] + 'glpi_itilcategories' => 'id', + ], ], 'glpi_tickettasks' => [ 'ON' => [ 'glpi_tickets' => 'id', - 'glpi_tickettasks' => 'tickets_id' - ] + 'glpi_tickettasks' => 'tickets_id', + ], ], 'glpi_items_tickets' => [ 'ON' => [ 'glpi_tickets' => 'id', - 'glpi_items_tickets' => 'tickets_id' - ] - ] + 'glpi_items_tickets' => 'tickets_id', + ], + ], ]; if (count($_SESSION['glpiactiveentities']) > 1) { $left_joins['glpi_entities'] = [ 'ON' => [ 'glpi_entities' => 'id', - 'glpi_tickets' => 'entities_id' - ] + 'glpi_tickets' => 'entities_id', + ], ]; } @@ -318,7 +319,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr 'LEFT JOIN' => $left_joins, 'WHERE' => $where_conditions, 'ORDER' => $order, - 'LIMIT' => intval($_SESSION['glpilist_limit']) + 'LIMIT' => intval($_SESSION['glpilist_limit']), ]; $result = $DB->request($query_params); @@ -530,7 +531,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $first = true; $listitems = $texteitem = ''; - foreach ($DB->request(['FROM' => 'glpi_items_tickets'] + ['WHERE' => ['tickets_id' => $job->fields['id']]], + foreach ($DB->request( + ['FROM' => 'glpi_items_tickets'] + ['WHERE' => ['tickets_id' => $job->fields['id']]], ) as $data) { if (!($item = $dbu->getItemForItemtype($data['itemtype']))) { continue; diff --git a/inc/itilsolution.class.php b/inc/itilsolution.class.php index b3cde31..5786ac2 100644 --- a/inc/itilsolution.class.php +++ b/inc/itilsolution.class.php @@ -48,7 +48,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); - $soluce = $DB->request(['FROM' => 'glpi_itilsolutions'] + ['itemtype' => $item->getType(), + $soluce = $DB->request( + ['FROM' => 'glpi_itilsolutions'] + ['itemtype' => $item->getType(), 'items_id' => $item->fields['id']], ); diff --git a/inc/networkport.class.php b/inc/networkport.class.php index 800b4f8..1e8f50d 100644 --- a/inc/networkport.class.php +++ b/inc/networkport.class.php @@ -51,7 +51,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $type = get_class($item); $pdf->setColumnsSize(100); - $result = $DB->request(['FROM' => 'glpi_networkports'] + ['SELECT' => ['id', 'name', 'logical_number'], + $result = $DB->request( + ['FROM' => 'glpi_networkports'] + ['SELECT' => ['id', 'name', 'logical_number'], 'WHERE' => ['items_id' => $ID, 'itemtype' => $type], 'ORDER' => ['name', 'logical_number']], diff --git a/inc/problem.class.php b/inc/problem.class.php index 8f84706..2517058 100644 --- a/inc/problem.class.php +++ b/inc/problem.class.php @@ -318,7 +318,8 @@ public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Problem $job) $text = Toolbox::stripTags( html_entity_decode( $job->getField('impactcontent'), - )); + ), + ); } $pdf->displayText('' . sprintf(__('%1$s: %2$s'), __('Impacts') . '', $text)); @@ -326,7 +327,8 @@ public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Problem $job) $text = Toolbox::stripTags( html_entity_decode( $job->getField('causecontent'), - )); + ), + ); } $pdf->displayText('' . sprintf(__('%1$s: %2$s'), __('Causes') . '', $text)); @@ -335,7 +337,8 @@ public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Problem $job) $text = Toolbox::stripTags( html_entity_decode( $job->getField('symptomcontent'), - )); + ), + ); } $pdf->displayText('' . sprintf(__('%1$s: %2$s'), __('Symptoms') . '', $text)); diff --git a/inc/profile.class.php b/inc/profile.class.php index 5526cd0..46de799 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -177,7 +177,8 @@ public static function initProfile() } } - foreach ($DB->request(['FROM' => 'glpi_profilerights'] + ['profiles_id' => $_SESSION['glpiactiveprofile']['id'], + foreach ($DB->request( + ['FROM' => 'glpi_profilerights'] + ['profiles_id' => $_SESSION['glpiactiveprofile']['id'], 'name' => ['LIKE', '%plugin_pdf%']], ) as $prof) { $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; @@ -216,8 +217,8 @@ public static function install(Migration $mig) $criterias = [ 'FROM' => $table, 'WHERE' => [ - 'use' => 1 - ] + 'use' => 1, + ], ]; foreach ($DB->request($criterias) as $data) { $right['profiles_id'] = $data['id']; diff --git a/inc/ticketvalidation.class.php b/inc/ticketvalidation.class.php index 6d27c0e..3b922bb 100644 --- a/inc/ticketvalidation.class.php +++ b/inc/ticketvalidation.class.php @@ -54,7 +54,8 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) } $ID = $ticket->getField('id'); - $result = $DB->request(['FROM' => 'glpi_ticketvalidations'] + ['WHERE' => ['tickets_id' => $ticket->getField('id')], + $result = $DB->request( + ['FROM' => 'glpi_ticketvalidations'] + ['WHERE' => ['tickets_id' => $ticket->getField('id')], 'ORDER' => 'submission_date DESC'], ); From 79124610b10ea1a86812cca9e876a085190899f5 Mon Sep 17 00:00:00 2001 From: RomainLvr Date: Mon, 30 Jun 2025 14:39:37 +0200 Subject: [PATCH 05/26] GLPI 11 compatibility --- composer.json | 1 + composer.lock | 50 +++++++++++++++++- front/export.massive.php | 18 +++++-- front/export.php | 13 +++-- hook.php | 2 +- inc/appliance.class.php | 5 +- inc/common.class.php | 14 ++--- inc/config.class.php | 15 +++--- inc/contract_item.class.php | 6 ++- inc/item_device.class.php | 16 ++++-- inc/preference.class.php | 22 ++++---- inc/profile.class.php | 13 +++-- inc/remote.class.php | 25 +++++++-- inc/simplepdf.class.php | 2 +- phpstan.neon | 2 - {fonts => public/fonts}/Times-Bold.afm | 0 {fonts => public/fonts}/Times-BoldItalic.afm | 0 {fonts => public/fonts}/Times-Italic.afm | 0 {fonts => public/fonts}/Times-Roman.afm | 0 {fonts => public/fonts}/php_Times-Bold.afm | 0 .../fonts}/php_Times-BoldItalic.afm | 0 {fonts => public/fonts}/php_Times-Italic.afm | 0 {fonts => public/fonts}/php_Times-Roman.afm | 0 {pics => public/pics}/fd_logo.jpg | Bin {pics => public/pics}/fd_logo.png | Bin templates/preference_form.html.twig | 6 +-- tools/move_to_po.php | 4 +- tools/pdftest.php | 2 +- 28 files changed, 158 insertions(+), 58 deletions(-) rename {fonts => public/fonts}/Times-Bold.afm (100%) rename {fonts => public/fonts}/Times-BoldItalic.afm (100%) rename {fonts => public/fonts}/Times-Italic.afm (100%) rename {fonts => public/fonts}/Times-Roman.afm (100%) rename {fonts => public/fonts}/php_Times-Bold.afm (100%) rename {fonts => public/fonts}/php_Times-BoldItalic.afm (100%) rename {fonts => public/fonts}/php_Times-Italic.afm (100%) rename {fonts => public/fonts}/php_Times-Roman.afm (100%) rename {pics => public/pics}/fd_logo.jpg (100%) rename {pics => public/pics}/fd_logo.png (100%) diff --git a/composer.json b/composer.json index eff66ba..b4bc5cf 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.73", "friendsoftwig/twigcs": "^6.1", + "glpi-project/phpstan-glpi": "^1.0", "glpi-project/tools": "^0.7.4", "php-parallel-lint/php-parallel-lint": "^1.4", "phpstan/extension-installer": "^1.4", diff --git a/composer.lock b/composer.lock index 821c3ea..65f8d48 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7aeed77d2efdc73fe57e884525e33e9c", + "content-hash": "322ca0605fe8ff3d0a33158bbbdf409f", "packages": [ { "name": "symfony/deprecation-contracts", @@ -854,6 +854,54 @@ }, "time": "2024-11-27T21:59:24+00:00" }, + { + "name": "glpi-project/phpstan-glpi", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/glpi-project/phpstan-glpi.git", + "reference": "432f7a10d221f60abdbd4ab4676dbd846a485df1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/glpi-project/phpstan-glpi/zipball/432f7a10d221f60abdbd4ab4676dbd846a485df1", + "reference": "432f7a10d221f60abdbd4ab4676dbd846a485df1", + "shasum": "" + }, + "require": { + "php": ">=7.4", + "phpstan/phpstan": "^2.1" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.75", + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.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.0.0" + }, + "time": "2025-06-24T11:45:31+00:00" + }, { "name": "glpi-project/tools", "version": "0.7.5", diff --git a/front/export.massive.php b/front/export.massive.php index 659eeda..cc2a155 100644 --- a/front/export.massive.php +++ b/front/export.massive.php @@ -30,12 +30,19 @@ * -------------------------------------------------------------------------- */ +/** @var array $PLUGIN_HOOKS */ +global $PLUGIN_HOOKS; + Session::checkRight('plugin_pdf', READ); Plugin::load('pdf', true); $type = $_SESSION['plugin_pdf']['type']; -$item = new $type(); +$dbu = new DbUtils(); +$item = $dbu->getItemForItemtype($type); +if (!$item) { + throw new \InvalidArgumentException('Invalid item type: ' . $type); +} $tab_id = unserialize($_SESSION['plugin_pdf']['tab_id']); unset($_SESSION['plugin_pdf']['tab_id']); @@ -65,8 +72,13 @@ $tab[] = $type . '$main'; } -if (isset($PLUGIN_HOOKS['plugin_pdf'][$type])) { - $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); +if (isset($PLUGIN_HOOKS['plugin_pdf'][$type]) && class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) { + $pdf_class = $PLUGIN_HOOKS['plugin_pdf'][$type]; + if (!is_a($pdf_class, PluginPdfCommon::class, true)) { + throw new \RuntimeException('Invalid PDF plugin class for type: ' . $type); + } + + $itempdf = new $pdf_class($item); $itempdf->generatePDF($tab_id, $tab, (isset($pag) ? $pag : 0)); } else { throw new \RuntimeException('Missing PDF plugin hook for type: ' . $type); diff --git a/front/export.php b/front/export.php index 348e7aa..75505ab 100644 --- a/front/export.php +++ b/front/export.php @@ -65,9 +65,16 @@ $tab[] = $type . '$main'; } - if (isset($PLUGIN_HOOKS['plugin_pdf'][$type]) - && class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) { - $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); + if ( + isset($PLUGIN_HOOKS['plugin_pdf'][$type]) + && class_exists($PLUGIN_HOOKS['plugin_pdf'][$type]) + ) { + $pdf_class = $PLUGIN_HOOKS['plugin_pdf'][$type]; + if (!is_a($pdf_class, PluginPdfCommon::class, true)) { + throw new \RuntimeException('Invalid PDF plugin class for type: ' . $type); + } + + $itempdf = new $pdf_class($item); $itempdf->generatePDF([$_POST['itemID']], $tab, (isset($_POST['page']) ? $_POST['page'] : 0)); } else { throw new \RuntimeException('Missing PDF plugin hook for type: ' . $type); diff --git a/hook.php b/hook.php index bd2507d..792f22d 100644 --- a/hook.php +++ b/hook.php @@ -51,7 +51,7 @@ function plugin_pdf_MassiveActions($type) default: if (isset($PLUGIN_HOOKS['plugin_pdf'][$type])) { return ['PluginPdfCommon' . MassiveAction::CLASS_ACTION_SEPARATOR . 'DoIt' - => __('Print to pdf', 'pdf')]; + => '' . __('Print to pdf', 'pdf')]; } } diff --git a/inc/appliance.class.php b/inc/appliance.class.php index 7f66908..d17535e 100644 --- a/inc/appliance.class.php +++ b/inc/appliance.class.php @@ -350,7 +350,10 @@ public static function showList_relation($pdf, $relID) $item = $relation->fields['itemtype']; - $objtype = new $item(); + $objtype = $dbu->getItemForItemtype($item); + if (!$objtype) { + return; + } // selects all the attached relations $tablename = $dbu->getTableForItemType($item); diff --git a/inc/common.class.php b/inc/common.class.php index 91e49c9..bb51751 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -123,13 +123,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (Session::haveRight('plugin_pdf', READ)) { if (empty($withtemplate)) { - $icon_html = sprintf('', 'file-type-pdf'); - - return sprintf( - '%s%s', - $icon_html, - __('Print to pdf', 'pdf'), - ); + return self::createTabEntry(__('Print to pdf', 'pdf'), 0, $item::getType(), PluginPdfConfig::getIcon()); } } return ''; @@ -620,6 +614,9 @@ public static function processMassiveActionsForOneItemtype( CommonDBTM $item, array $ids ) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + switch ($ma->getAction()) { case 'DoIt': $tab_id = []; @@ -630,9 +627,8 @@ public static function processMassiveActionsForOneItemtype( } $_SESSION['plugin_pdf']['type'] = $item->getType(); $_SESSION['plugin_pdf']['tab_id'] = serialize($tab_id); - $webDir = Plugin::getPhpDir('pdf', false); echo ""; + location.href='" . $CFG_GLPI['root_doc'] . "/plugins/pdf/front/export.massive.php'"; break; } } diff --git a/inc/config.class.php b/inc/config.class.php index e8dfddf..14ff9ed 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -79,7 +79,7 @@ public static function canView(): bool public static function getTypeName($nb = 0) { - return __('Setup'); + return __('PDF settings', 'pdf'); } public function getName($params = []) @@ -87,6 +87,11 @@ public function getName($params = []) return __('Print to pdf', 'pdf'); } + public static function getIcon() + { + return "ti ti-file-type-pdf"; + } + /** * Singleton for the unique config record */ @@ -185,13 +190,7 @@ public static function showConfigForm($item) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Config') { - $icon_html = sprintf('', 'file-type-pdf'); - - return sprintf( - '%s%s', - $icon_html, - self::getName(), - ); + return self::createTabEntry(self::getTypeName(), 0, $item::getType(), self::getIcon()); } return ''; diff --git a/inc/contract_item.class.php b/inc/contract_item.class.php index daa8366..39cae1e 100644 --- a/inc/contract_item.class.php +++ b/inc/contract_item.class.php @@ -228,7 +228,11 @@ public static function pdfForContract(PluginPdfSimplePDF $pdf, Contract $contrac $prem = true; $nb = count($datas); foreach ($datas as $objdata) { - $item = new $itemtype(); + $dbu = new DbUtils(); + $item = $dbu->getItemForItemtype($itemtype); + if (!$item) { + continue; + } if ($item instanceof Item_Devices) { $name = $objdata['name_device']; } else { diff --git a/inc/item_device.class.php b/inc/item_device.class.php index a660810..e836f5a 100644 --- a/inc/item_device.class.php +++ b/inc/item_device.class.php @@ -60,7 +60,11 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) $vide = true; foreach ($devtypes as $itemtype) { - $devicetypes = new $itemtype(); + $dbu_local = new DbUtils(); + $devicetypes = $dbu_local->getItemForItemtype($itemtype); + if (!$devicetypes) { + continue; + } $specificities = $devicetypes->getSpecificities(); $specif_fields = array_keys($specificities); @@ -89,9 +93,15 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) 'GROUPBY' => $group_by, ]; - $device = new $associated_type(); - $itemdevice = new $itemtype(); + $dbu = new DbUtils(); + // Validate that the types are valid before using them + if (!$dbu->getItemForItemtype($associated_type) || !$dbu->getItemForItemtype($itemtype)) { + continue; + } + foreach ($DB->request($query_params) as $data) { + $device = $dbu->getItemForItemtype($associated_type); + $itemdevice = $dbu->getItemForItemtype($itemtype); $itemdevice->getFromDB($data['id']); if ($device->getFromDB($data[$fk])) { $spec = $device->getAdditionalFields(); diff --git a/inc/preference.class.php b/inc/preference.class.php index 26838e0..f836d52 100644 --- a/inc/preference.class.php +++ b/inc/preference.class.php @@ -36,6 +36,11 @@ class PluginPdfPreference extends CommonDBTM { public static $rightname = 'plugin_pdf'; + public static function getTypeName($nb = 0) + { + return __('PDF preferences', 'pdf'); + } + public static function showPreferences() { /** @var array $PLUGIN_HOOKS */ @@ -80,7 +85,13 @@ public function menu($item, $action) || !class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) { return; } - $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); + + $pdf_class = $PLUGIN_HOOKS['plugin_pdf'][$type]; + if (!is_a($pdf_class, PluginPdfCommon::class, true)) { + return; + } + + $itempdf = new $pdf_class($item); $options = $itempdf->defineAllTabsPDF(); $landscape = false; @@ -127,15 +138,8 @@ public function menu($item, $action) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (($item->getType() == 'Preference')) { - $icon_html = sprintf('', 'file-type-pdf'); - - return sprintf( - '%s%s', - $icon_html, - __('Print to pdf', 'pdf'), - ); + return self::createTabEntry(self::getTypeName(), 0, $item::getType(), PluginPdfConfig::getIcon()); } - return ''; } diff --git a/inc/profile.class.php b/inc/profile.class.php index 46de799..a137683 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -34,6 +34,11 @@ class PluginPdfProfile extends Profile { public static $rightname = 'profile'; + public static function getTypeName($nb = 0) + { + return _n('PDF profile', 'PDF profiles', $nb, 'pdf'); + } + public function rawSearchOptions() { $tab = []; @@ -91,13 +96,7 @@ public function showForm($ID, $options = []) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Profile') { - $icon_html = sprintf('', 'file-type-pdf'); - - return sprintf( - '%s%s', - $icon_html, - __('Print to pdf', 'pdf'), - ); + return self::createTabEntry(self::getTypeName(), 0, $item::getType(), PluginPdfConfig::getIcon()); } return ''; diff --git a/inc/remote.class.php b/inc/remote.class.php index fe18e67..5e9a8e3 100644 --- a/inc/remote.class.php +++ b/inc/remote.class.php @@ -60,8 +60,22 @@ public static function methodGetTabs($params, $protocol) if (isset($PLUGIN_HOOKS['plugin_pdf'][$type]) && class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) { - $item = new $type(); - $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); + $dbu = new DbUtils(); + if (!$item = $dbu->getItemForItemtype($type)) { + return PluginWebservicesMethodCommon::Error( + $protocol, + WEBSERVICES_ERROR_BADPARAMETER, + '', + 'type', + ); + } + + $pdf_class = $PLUGIN_HOOKS['plugin_pdf'][$type]; + if (!is_a($pdf_class, PluginPdfCommon::class, true)) { + return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_FAILED); + } + + $itempdf = new $pdf_class($item); return $itempdf->defineAllTabs(); } @@ -142,7 +156,12 @@ public static function methodGetPdf($params, $protocol) $tabs = [$type . '$main']; } if (isset($PLUGIN_HOOKS['plugin_pdf'][$type]) && class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) { - $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); + $pdf_class = $PLUGIN_HOOKS['plugin_pdf'][$type]; + if (!is_a($pdf_class, PluginPdfCommon::class, true)) { + return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_FAILED); + } + + $itempdf = new $pdf_class($item); if (isset($params['alltabs'])) { $tabs = $itempdf->defineAllTabs(); $tabs = array_keys($tabs); diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 5c06d71..8f8b1d4 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -129,7 +129,7 @@ public function setHeader($msg) ) { $this->pdf->SetHeaderData($hook['logo_path'], 15, $msg, ''); } else { - $path = Plugin::getPhpDir('pdf') . '/pics/'; + $path = Plugin::getPhpDir('pdf') . '/public/pics/'; $this->pdf->SetHeaderData($path . 'fd_logo.png', 15, $msg, ''); } } diff --git a/phpstan.neon b/phpstan.neon index 8c5e662..3611e20 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -20,5 +20,3 @@ parameters: ignoreErrors: - '#Call to static method Error\(\) on an unknown class PluginWebservicesMethodCommon#' - '#Constant WEBSERVICES_ERROR_[A-Z]+ not found#' -rules: - - GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule diff --git a/fonts/Times-Bold.afm b/public/fonts/Times-Bold.afm similarity index 100% rename from fonts/Times-Bold.afm rename to public/fonts/Times-Bold.afm diff --git a/fonts/Times-BoldItalic.afm b/public/fonts/Times-BoldItalic.afm similarity index 100% rename from fonts/Times-BoldItalic.afm rename to public/fonts/Times-BoldItalic.afm diff --git a/fonts/Times-Italic.afm b/public/fonts/Times-Italic.afm similarity index 100% rename from fonts/Times-Italic.afm rename to public/fonts/Times-Italic.afm diff --git a/fonts/Times-Roman.afm b/public/fonts/Times-Roman.afm similarity index 100% rename from fonts/Times-Roman.afm rename to public/fonts/Times-Roman.afm diff --git a/fonts/php_Times-Bold.afm b/public/fonts/php_Times-Bold.afm similarity index 100% rename from fonts/php_Times-Bold.afm rename to public/fonts/php_Times-Bold.afm diff --git a/fonts/php_Times-BoldItalic.afm b/public/fonts/php_Times-BoldItalic.afm similarity index 100% rename from fonts/php_Times-BoldItalic.afm rename to public/fonts/php_Times-BoldItalic.afm diff --git a/fonts/php_Times-Italic.afm b/public/fonts/php_Times-Italic.afm similarity index 100% rename from fonts/php_Times-Italic.afm rename to public/fonts/php_Times-Italic.afm diff --git a/fonts/php_Times-Roman.afm b/public/fonts/php_Times-Roman.afm similarity index 100% rename from fonts/php_Times-Roman.afm rename to public/fonts/php_Times-Roman.afm diff --git a/pics/fd_logo.jpg b/public/pics/fd_logo.jpg similarity index 100% rename from pics/fd_logo.jpg rename to public/pics/fd_logo.jpg diff --git a/pics/fd_logo.png b/public/pics/fd_logo.png similarity index 100% rename from pics/fd_logo.png rename to public/pics/fd_logo.png diff --git a/templates/preference_form.html.twig b/templates/preference_form.html.twig index 58fafbe..5dc01bb 100644 --- a/templates/preference_form.html.twig +++ b/templates/preference_form.html.twig @@ -28,7 +28,7 @@ # -------------------------------------------------------------------------- #} - +
@@ -78,8 +78,8 @@