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/.twig_cs.dist.php b/.twig_cs.dist.php index 352fe0a..6041bcf 100644 --- a/.twig_cs.dist.php +++ b/.twig_cs.dist.php @@ -2,14 +2,16 @@ declare(strict_types=1); -use FriendsOfTwig\Twigcs; +use FriendsOfTwig\Twigcs\Finder\TemplateFinder; +use FriendsOfTwig\Twigcs\Config\Config; +use Glpi\Tools\GlpiTwigRuleset; -$finder = Twigcs\Finder\TemplateFinder::create() +$finder = TemplateFinder::create() ->in(__DIR__ . '/templates') ->name('*.html.twig') ->ignoreVCSIgnored(true); -return Twigcs\Config\Config::create() +return Config::create() ->setFinder($finder) - ->setRuleSet(\Glpi\Tools\GlpiTwigRuleset::class) + ->setRuleSet(GlpiTwigRuleset::class) ; diff --git a/CHANGELOG.md b/CHANGELOG.md index 9004616..166286d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [UNRELEASE] +## [4.1.0] - 2025-10-01 + +### Added + +- GLPI 11 compatibility ## [4.0.2] - 2025-09-30 diff --git a/composer.json b/composer.json index abb3b8e..b4bc5cf 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,13 @@ { "require": { - "php": ">=7.4", - "symfony/yaml": "^5.4", + "php": ">=8.2", + "symfony/yaml": "^7.3", "tecnickcom/tcpdf": "^6.4" }, "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", @@ -16,7 +17,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..2d1df72 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": "322ca0605fe8ff3d0a33158bbbdf409f", "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.33.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.33.0" }, "funding": [ { @@ -145,6 +145,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -154,31 +158,28 @@ }, { "name": "symfony/yaml", - "version": "v5.4.45", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "a454d47278cc16a5db371fe73ae66a78a633371e" + "reference": "d4f4a66866fe2451f61296924767280ab5732d9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/a454d47278cc16a5db371fe73ae66a78a633371e", - "reference": "a454d47278cc16a5db371fe73ae66a78a633371e", + "url": "https://api.github.com/repos/symfony/yaml/zipball/d4f4a66866fe2451f61296924767280ab5732d9d", + "reference": "d4f4a66866fe2451f61296924767280ab5732d9d", "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 +210,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.3" }, "funding": [ { @@ -220,25 +221,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-08-27T11:34: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 +293,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": [ @@ -445,16 +450,16 @@ }, { "name": "composer/semver", - "version": "3.4.3", + "version": "3.4.4", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12" + "reference": "198166618906cb2de69b95d7d47e5fa8aa1b2b95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", - "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", + "url": "https://api.github.com/repos/composer/semver/zipball/198166618906cb2de69b95d7d47e5fa8aa1b2b95", + "reference": "198166618906cb2de69b95d7d47e5fa8aa1b2b95", "shasum": "" }, "require": { @@ -506,7 +511,7 @@ "support": { "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.4.3" + "source": "https://github.com/composer/semver/tree/3.4.4" }, "funding": [ { @@ -516,13 +521,9 @@ { "url": "https://github.com/composer", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" } ], - "time": "2024-09-19T14:15:21+00:00" + "time": "2025-08-20T19:15:30+00:00" }, { "name": "composer/xdebug-handler", @@ -639,16 +640,16 @@ }, { "name": "fidry/cpu-core-counter", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/theofidry/cpu-core-counter.git", - "reference": "8520451a140d3f46ac33042715115e290cf5785f" + "reference": "db9508f7b1474469d9d3c53b86f817e344732678" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/8520451a140d3f46ac33042715115e290cf5785f", - "reference": "8520451a140d3f46ac33042715115e290cf5785f", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/db9508f7b1474469d9d3c53b86f817e344732678", + "reference": "db9508f7b1474469d9d3c53b86f817e344732678", "shasum": "" }, "require": { @@ -658,10 +659,10 @@ "fidry/makefile": "^0.2.0", "fidry/php-cs-fixer-config": "^1.1.2", "phpstan/extension-installer": "^1.2.0", - "phpstan/phpstan": "^1.9.2", - "phpstan/phpstan-deprecation-rules": "^1.0.0", - "phpstan/phpstan-phpunit": "^1.2.2", - "phpstan/phpstan-strict-rules": "^1.4.4", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^8.5.31 || ^9.5.26", "webmozarts/strict-phpunit": "^7.5" }, @@ -688,7 +689,7 @@ ], "support": { "issues": "https://github.com/theofidry/cpu-core-counter/issues", - "source": "https://github.com/theofidry/cpu-core-counter/tree/1.2.0" + "source": "https://github.com/theofidry/cpu-core-counter/tree/1.3.0" }, "funding": [ { @@ -696,62 +697,62 @@ "type": "github" } ], - "time": "2024-08-06T10:04:20+00:00" + "time": "2025-08-14T07:29:31+00:00" }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.75.0", + "version": "v3.88.2", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c" + "reference": "a8d15584bafb0f0d9d938827840060fd4a3ebc99" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/399a128ff2fdaf4281e4e79b755693286cdf325c", - "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/a8d15584bafb0f0d9d938827840060fd4a3ebc99", + "reference": "a8d15584bafb0f0d9d938827840060fd4a3ebc99", "shasum": "" }, "require": { - "clue/ndjson-react": "^1.0", + "clue/ndjson-react": "^1.3", "composer/semver": "^3.4", - "composer/xdebug-handler": "^3.0.3", + "composer/xdebug-handler": "^3.0.5", "ext-filter": "*", "ext-hash": "*", "ext-json": "*", "ext-tokenizer": "*", - "fidry/cpu-core-counter": "^1.2", + "fidry/cpu-core-counter": "^1.3", "php": "^7.4 || ^8.0", - "react/child-process": "^0.6.5", - "react/event-loop": "^1.0", - "react/promise": "^2.0 || ^3.0", - "react/socket": "^1.0", - "react/stream": "^1.0", - "sebastian/diff": "^4.0 || ^5.1 || ^6.0 || ^7.0", - "symfony/console": "^5.4 || ^6.4 || ^7.0", - "symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0", - "symfony/filesystem": "^5.4 || ^6.4 || ^7.0", - "symfony/finder": "^5.4 || ^6.4 || ^7.0", - "symfony/options-resolver": "^5.4 || ^6.4 || ^7.0", - "symfony/polyfill-mbstring": "^1.31", - "symfony/polyfill-php80": "^1.31", - "symfony/polyfill-php81": "^1.31", - "symfony/process": "^5.4 || ^6.4 || ^7.2", - "symfony/stopwatch": "^5.4 || ^6.4 || ^7.0" + "react/child-process": "^0.6.6", + "react/event-loop": "^1.5", + "react/promise": "^3.3", + "react/socket": "^1.16", + "react/stream": "^1.4", + "sebastian/diff": "^4.0.6 || ^5.1.1 || ^6.0.2 || ^7.0", + "symfony/console": "^5.4.47 || ^6.4.24 || ^7.0", + "symfony/event-dispatcher": "^5.4.45 || ^6.4.24 || ^7.0", + "symfony/filesystem": "^5.4.45 || ^6.4.24 || ^7.0", + "symfony/finder": "^5.4.45 || ^6.4.24 || ^7.0", + "symfony/options-resolver": "^5.4.45 || ^6.4.24 || ^7.0", + "symfony/polyfill-mbstring": "^1.33", + "symfony/polyfill-php80": "^1.33", + "symfony/polyfill-php81": "^1.33", + "symfony/polyfill-php84": "^1.33", + "symfony/process": "^5.4.47 || ^6.4.24 || ^7.2", + "symfony/stopwatch": "^5.4.45 || ^6.4.24 || ^7.0" }, "require-dev": { - "facile-it/paraunit": "^1.3.1 || ^2.6", - "infection/infection": "^0.29.14", - "justinrainbow/json-schema": "^5.3 || ^6.2", - "keradus/cli-executor": "^2.1", + "facile-it/paraunit": "^1.3.1 || ^2.7", + "infection/infection": "^0.31.0", + "justinrainbow/json-schema": "^6.5", + "keradus/cli-executor": "^2.2", "mikey179/vfsstream": "^1.6.12", - "php-coveralls/php-coveralls": "^2.7", - "php-cs-fixer/accessible-object": "^1.1", + "php-coveralls/php-coveralls": "^2.8", "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.6", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.6", - "phpunit/phpunit": "^9.6.22 || ^10.5.45 || ^11.5.12", - "symfony/var-dumper": "^5.4.48 || ^6.4.18 || ^7.2.3", - "symfony/yaml": "^5.4.45 || ^6.4.18 || ^7.2.3" + "phpunit/phpunit": "^9.6.25 || ^10.5.53 || ^11.5.34", + "symfony/var-dumper": "^5.4.48 || ^6.4.24 || ^7.3.2", + "symfony/yaml": "^5.4.45 || ^6.4.24 || ^7.3.2" }, "suggest": { "ext-dom": "For handling output formats in XML", @@ -792,7 +793,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.75.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.88.2" }, "funding": [ { @@ -800,20 +801,20 @@ "type": "github" } ], - "time": "2025-03-31T18:40:42+00:00" + "time": "2025-09-27T00:24:15+00:00" }, { "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 +823,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 +854,71 @@ "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/phpstan-glpi", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/glpi-project/phpstan-glpi.git", + "reference": "e98ef833abc1389a0cc69743db5b1f3a7dc8ccfe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/glpi-project/phpstan-glpi/zipball/e98ef833abc1389a0cc69743db5b1f3a7dc8ccfe", + "reference": "e98ef833abc1389a0cc69743db5b1f3a7dc8ccfe", + "shasum": "" + }, + "require": { + "php": ">=7.4", + "phpstan/phpstan": "^2.1", + "symfony/polyfill-php80": "^1.32" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.85", + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStanGlpi\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for GLPI.", + "support": { + "issues": "https://github.com/glpi-project/phpstan-glpi/issues", + "source": "https://github.com/glpi-project/phpstan-glpi/tree/1.1.1" + }, + "time": "2025-08-11T13:48:13+00:00" }, { "name": "glpi-project/tools", - "version": "0.7.4", + "version": "0.7.8", "source": { "type": "git", "url": "https://github.com/glpi-project/tools.git", - "reference": "65a09a93350da6fa67d423dd94e4cb4023a17e20" + "reference": "bd78ad2ab0d30510729530c077f84d52b8f02866" }, "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/bd78ad2ab0d30510729530c077f84d52b8f02866", + "reference": "bd78ad2ab0d30510729530c077f84d52b8f02866", "shasum": "" }, "require": { @@ -911,7 +961,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-08-20T09:58:56+00:00" }, { "name": "php-parallel-lint/php-parallel-lint", @@ -1024,16 +1074,16 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.11", + "version": "2.1.29", "source": { "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30" + "url": "https://github.com/phpstan/phpstan-phar-composer-source.git", + "reference": "git" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8ca5f79a8f63c49b2359065832a654e1ec70ac30", - "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d618573eed4a1b6b75e37b2e0b65ac65c885d88e", + "reference": "d618573eed4a1b6b75e37b2e0b65ac65c885d88e", "shasum": "" }, "require": { @@ -1078,25 +1128,25 @@ "type": "github" } ], - "time": "2025-03-24T13:45:00+00:00" + "time": "2025-09-25T06:58:18+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 +1173,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 +1226,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 +1282,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 +1326,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", @@ -1572,23 +1627,23 @@ }, { "name": "react/promise", - "version": "v3.2.0", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/reactphp/promise.git", - "reference": "8a164643313c71354582dc850b42b33fa12a4b63" + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/8a164643313c71354582dc850b42b33fa12a4b63", - "reference": "8a164643313c71354582dc850b42b33fa12a4b63", + "url": "https://api.github.com/repos/reactphp/promise/zipball/23444f53a813a3296c1368bb104793ce8d88f04a", + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a", "shasum": "" }, "require": { "php": ">=7.1.0" }, "require-dev": { - "phpstan/phpstan": "1.10.39 || 1.4.10", + "phpstan/phpstan": "1.12.28 || 1.4.10", "phpunit/phpunit": "^9.6 || ^7.5" }, "type": "library", @@ -1633,7 +1688,7 @@ ], "support": { "issues": "https://github.com/reactphp/promise/issues", - "source": "https://github.com/reactphp/promise/tree/v3.2.0" + "source": "https://github.com/reactphp/promise/tree/v3.3.0" }, "funding": [ { @@ -1641,7 +1696,7 @@ "type": "open_collective" } ], - "time": "2024-05-24T10:39:05+00:00" + "time": "2025-08-19T18:57:03+00:00" }, { "name": "react/socket", @@ -1803,29 +1858,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 +1912,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 +1921,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.26", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed" + "reference": "492de6dfd93910d7d7a729c5a04ddcd2b9e99c4f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", - "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", + "url": "https://api.github.com/repos/symfony/console/zipball/492de6dfd93910d7d7a729c5a04ddcd2b9e99c4f", + "reference": "492de6dfd93910d7d7a729c5a04ddcd2b9e99c4f", "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 +1999,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.47" + "source": "https://github.com/symfony/console/tree/v6.4.26" }, "funding": [ { @@ -1959,53 +2010,52 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-11-06T11:30:55+00:00" + "time": "2025-09-26T12:13:46+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v5.4.45", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "72982eb416f61003e9bb6e91f8b3213600dcf9e9" + "reference": "b7dc69e71de420ac04bc9ab830cf3ffebba48191" }, "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/b7dc69e71de420ac04bc9ab830cf3ffebba48191", + "reference": "b7dc69e71de420ac04bc9ab830cf3ffebba48191", "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 +2083,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.3" }, "funding": [ { @@ -2044,34 +2094,35 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-08-13T11:49:31+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 +2130,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -2112,7 +2163,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 +2179,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.2", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54" + "reference": "edcbb768a186b5c3f25d0643159a787d3e63b7fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/57c8294ed37d4a055b77057827c67f9558c95c54", - "reference": "57c8294ed37d4a055b77057827c67f9558c95c54", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/edcbb768a186b5c3f25d0643159a787d3e63b7fd", + "reference": "edcbb768a186b5c3f25d0643159a787d3e63b7fd", "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 +2229,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.2" }, "funding": [ { @@ -2190,31 +2240,36 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-10-22T13:05:35+00:00" + "time": "2025-07-07T08:17:47+00:00" }, { "name": "symfony/finder", - "version": "v5.4.45", + "version": "v7.3.2", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "63741784cd7b9967975eec610b256eed3ede022b" + "reference": "2a6614966ba1074fa93dae0bc804227422df4dfe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/63741784cd7b9967975eec610b256eed3ede022b", - "reference": "63741784cd7b9967975eec610b256eed3ede022b", + "url": "https://api.github.com/repos/symfony/finder/zipball/2a6614966ba1074fa93dae0bc804227422df4dfe", + "reference": "2a6614966ba1074fa93dae0bc804227422df4dfe", "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 +2297,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.2" }, "funding": [ { @@ -2253,32 +2308,34 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-28T13:32:08+00:00" + "time": "2025-07-15T13:41:35+00:00" }, { "name": "symfony/options-resolver", - "version": "v5.4.45", + "version": "v7.3.3", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "74e5b6f0db3e8589e6cfd5efb317a1fc2bb52fb6" + "reference": "0ff2f5c3df08a395232bbc3c2eb7e84912df911d" }, "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/0ff2f5c3df08a395232bbc3c2eb7e84912df911d", + "reference": "0ff2f5c3df08a395232bbc3c2eb7e84912df911d", "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 +2368,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v5.4.45" + "source": "https://github.com/symfony/options-resolver/tree/v7.3.3" }, "funding": [ { @@ -2322,25 +2379,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-25T14:11:13+00:00" + "time": "2025-08-05T10:16:07+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe" + "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/380872130d3a5dd3ace2f4010d95125fde5d5c70", + "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70", "shasum": "" }, "require": { @@ -2389,7 +2450,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.33.0" }, "funding": [ { @@ -2400,16 +2461,20 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-06-27T09:58:17+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -2470,7 +2535,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.33.0" }, "funding": [ { @@ -2481,6 +2546,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -2490,19 +2559,20 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.31.0", + "version": "v1.33.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 +2620,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.33.0" }, "funding": [ { @@ -2561,25 +2631,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-12-23T08:48:59+00:00" }, { - "name": "symfony/polyfill-php73", - "version": "v1.31.0", + "name": "symfony/polyfill-php80", + "version": "v1.33.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb" + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f68c03565dcaaf25a890667542e8bd75fe7e5bb", - "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608", + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608", "shasum": "" }, "require": { @@ -2597,7 +2671,7 @@ "bootstrap.php" ], "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" + "Symfony\\Polyfill\\Php80\\": "" }, "classmap": [ "Resources/stubs" @@ -2608,6 +2682,10 @@ "MIT" ], "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, { "name": "Nicolas Grekas", "email": "p@tchwork.com" @@ -2617,7 +2695,7 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", "homepage": "https://symfony.com", "keywords": [ "compatibility", @@ -2626,7 +2704,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.33.0" }, "funding": [ { @@ -2637,25 +2715,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-01-02T08:10:11+00:00" }, { - "name": "symfony/polyfill-php80", - "version": "v1.31.0", + "name": "symfony/polyfill-php81", + "version": "v1.33.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" + "url": "https://github.com/symfony/polyfill-php81.git", + "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", + "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", "shasum": "" }, "require": { @@ -2673,7 +2755,7 @@ "bootstrap.php" ], "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" + "Symfony\\Polyfill\\Php81\\": "" }, "classmap": [ "Resources/stubs" @@ -2684,10 +2766,6 @@ "MIT" ], "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, { "name": "Nicolas Grekas", "email": "p@tchwork.com" @@ -2697,7 +2775,7 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", "homepage": "https://symfony.com", "keywords": [ "compatibility", @@ -2706,7 +2784,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.33.0" }, "funding": [ { @@ -2717,6 +2795,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -2725,17 +2807,17 @@ "time": "2024-09-09T11:45:10+00:00" }, { - "name": "symfony/polyfill-php81", - "version": "v1.31.0", + "name": "symfony/polyfill-php84", + "version": "v1.33.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-php81.git", - "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c" + "url": "https://github.com/symfony/polyfill-php84.git", + "reference": "d8ced4d875142b6a7426000426b8abc631d6b191" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", - "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", + "url": "https://api.github.com/repos/symfony/polyfill-php84/zipball/d8ced4d875142b6a7426000426b8abc631d6b191", + "reference": "d8ced4d875142b6a7426000426b8abc631d6b191", "shasum": "" }, "require": { @@ -2753,7 +2835,7 @@ "bootstrap.php" ], "psr-4": { - "Symfony\\Polyfill\\Php81\\": "" + "Symfony\\Polyfill\\Php84\\": "" }, "classmap": [ "Resources/stubs" @@ -2773,7 +2855,7 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", + "description": "Symfony polyfill backporting some PHP 8.4+ features to lower PHP versions", "homepage": "https://symfony.com", "keywords": [ "compatibility", @@ -2782,7 +2864,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php84/tree/v1.33.0" }, "funding": [ { @@ -2793,30 +2875,33 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-06-24T13:30:11+00:00" }, { "name": "symfony/process", - "version": "v5.4.47", + "version": "v7.3.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "5d1662fb32ebc94f17ddb8d635454a776066733d" + "reference": "f24f8f316367b30810810d4eb30c543d7003ff3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/5d1662fb32ebc94f17ddb8d635454a776066733d", - "reference": "5d1662fb32ebc94f17ddb8d635454a776066733d", + "url": "https://api.github.com/repos/symfony/process/zipball/f24f8f316367b30810810d4eb30c543d7003ff3b", + "reference": "f24f8f316367b30810810d4eb30c543d7003ff3b", "shasum": "" }, "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" + "php": ">=8.2" }, "type": "library", "autoload": { @@ -2844,7 +2929,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.4" }, "funding": [ { @@ -2855,38 +2940,39 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-11-06T11:36:42+00:00" + "time": "2025-09-11T10:12:26+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 +2980,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 +3016,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 +3032,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 +3078,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 +3094,38 @@ "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.4", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "136ca7d72f72b599f2631aca474a4f8e26719799" + "reference": "f96476035142921000338bad71e5247fbc138872" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/136ca7d72f72b599f2631aca474a4f8e26719799", - "reference": "136ca7d72f72b599f2631aca474a4f8e26719799", + "url": "https://api.github.com/repos/symfony/string/zipball/f96476035142921000338bad71e5247fbc138872", + "reference": "f96476035142921000338bad71e5247fbc138872", "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/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 +3164,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.47" + "source": "https://github.com/symfony/string/tree/v7.3.4" }, "funding": [ { @@ -3086,36 +3175,39 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-11-10T20:33:58+00:00" + "time": "2025-09-11T14:36:48+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 +3251,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,20 +3263,20 @@ "type": "tidelift" } ], - "time": "2024-11-07T12:34:41+00:00" + "time": "2025-05-03T07:21:55+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.4" + "php": ">=8.2" }, - "platform-dev": [], + "platform-dev": {}, "platform-overrides": { - "php": "7.4.0" + "php": "8.2.99" }, "plugin-api-version": "2.6.0" } diff --git a/front/config.form.php b/front/config.form.php index 3ea7941..ed9a7bf 100644 --- a/front/config.form.php +++ b/front/config.form.php @@ -30,12 +30,10 @@ * -------------------------------------------------------------------------- */ -include('../../../inc/includes.php'); - Session::checkLoginUser(); // No autoload when plugin is not activated -require_once('../inc/config.class.php'); +require_once(__DIR__ . '/../inc/config.class.php'); $config = new PluginPdfConfig(); if (isset($_POST['update'])) { diff --git a/front/export.massive.php b/front/export.massive.php index 0fab385..2302400 100644 --- a/front/export.massive.php +++ b/front/export.massive.php @@ -30,27 +30,34 @@ * -------------------------------------------------------------------------- */ -include('../../../inc/includes.php'); +/** @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']); -/** @var \DBmysql $DB */ +/** @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 = []; @@ -61,13 +68,18 @@ $tab[] = $data['tabref']; } } -if (empty($tab)) { +if ($tab === []) { $tab[] = $type . '$main'; } -if (isset($PLUGIN_HOOKS['plugin_pdf'][$type])) { - $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); - $itempdf->generatePDF($tab_id, $tab, (isset($pag) ? $pag : 0)); +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, ($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..dea3448 100644 --- a/front/export.php +++ b/front/export.php @@ -30,18 +30,14 @@ * -------------------------------------------------------------------------- */ -define('GLPI_KEEP_CSRF_TOKEN', true); // 0.90 -$token = (isset($_POST['_glpi_csrf_token']) ? $_POST['_glpi_csrf_token'] : false); +/** @var array $PLUGIN_HOOKS */ +global $PLUGIN_HOOKS; -include('../../../inc/includes.php'); +define('GLPI_KEEP_CSRF_TOKEN', true); // 0.90 +$token = ($_POST['_glpi_csrf_token'] ?? false); 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(); @@ -65,17 +61,24 @@ } } } - if (empty($tab)) { + if ($tab === []) { $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); - $itempdf->generatePDF([$_POST['itemID']], $tab, (isset($_POST['page']) ? $_POST['page'] : 0)); + 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, ($_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/front/preference.form.php b/front/preference.form.php index 657af87..c84ae48 100644 --- a/front/preference.form.php +++ b/front/preference.form.php @@ -30,11 +30,11 @@ * -------------------------------------------------------------------------- */ -include_once('../../../inc/includes.php'); +include_once(__DIR__ . '/../../../inc/includes.php'); Session::checkLoginUser(); -/** @var \DBmysql $DB */ +/** @var DBmysql $DB */ global $DB; //Save user preferences diff --git a/hook.php b/hook.php index d6150bf..c6d1a75 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')]; + => '' . __s('PDF export', 'pdf')]; } } @@ -99,22 +99,9 @@ function plugin_pdf_uninstall() $query = "DELETE FROM `glpi_profilerights` WHERE `name` = 'plugin_pdf'"; - $DB->doQueryOrDie($query, $DB->error()); + $DB->doQuery($query); $migration->executeMigration(); return true; } - - -/** - * @since version 1.0.2 -**/ -function plugin_pdf_registerMethods() -{ - /** @var array $WEBSERVICES_METHOD */ - global $WEBSERVICES_METHOD; - - $WEBSERVICES_METHOD['pdf.getTabs'] = ['PluginPdfRemote', 'methodGetTabs']; - $WEBSERVICES_METHOD['pdf.getPdf'] = ['PluginPdfRemote', 'methodGetPdf']; -} diff --git a/inc/appliance.class.php b/inc/appliance.class.php index cf23ca8..bbee4b1 100644 --- a/inc/appliance.class.php +++ b/inc/appliance.class.php @@ -39,7 +39,7 @@ class PluginPdfAppliance extends PluginPdfCommon **/ public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Appliance()); + $this->obj = ($obj ?: new Appliance()); } /** @@ -96,15 +96,13 @@ public static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGL public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) { - $dbu = new DbUtils(); - PluginPdfCommon::mainTitle($pdf, $item); $pdf->displayLine( - sprintf(__('%1$s: %2$s'), '' . __('Name') . '', $item->fields['name']), + sprintf(__s('%1$s: %2$s'), '' . __s('Name') . '', $item->fields['name']), sprintf( - __('%1$s: %2$s'), - '' . _n('Status', 'Statuses', 1) . '', + __s('%1$s: %2$s'), + '' . _sn('Status', 'Statuses', 1) . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_states', $item->fields['states_id'], @@ -114,13 +112,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) $pdf->displayLine( sprintf( - __('%1$s: %2$s'), - '' . __('Associable to a ticket') . '', + __s('%1$s: %2$s'), + '' . __s('Associable to a ticket') . '', Dropdown::getYesNo($item->fields['is_helpdesk_visible']), ), sprintf( - __('%1$s: %2$s'), - '' . __('Location') . '', + __s('%1$s: %2$s'), + '' . __s('Location') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_locations', $item->fields['locations_id'], @@ -130,32 +128,32 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) $pdf->displayLine( sprintf( - __('%1$s: %2$s'), - '' . __('Type') . '', + __s('%1$s: %2$s'), + '' . __s('Type') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_appliancetypes', $item->fields['appliancetypes_id'], )), ), sprintf( - __('%1$s: %2$s'), - '' . __('Technician in charge of the hardware') . '', + __s('%1$s: %2$s'), + '' . __s('Technician in charge of the hardware') . '', getUserName($item->fields['users_id_tech']), ), ); $pdf->displayLine( sprintf( - __('%1$s: %2$s'), - '' . __('Manufacturer') . '', + __s('%1$s: %2$s'), + '' . __s('Manufacturer') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_suppliers', $item->fields['manufacturers_id'], )), ), sprintf( - __('%1$s: %2$s'), - '' . __('Group in charge of the hardware') . '', + __s('%1$s: %2$s'), + '' . __s('Group in charge of the hardware') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_groups', $item->fields['groups_id_tech'], @@ -165,26 +163,26 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) $pdf->displayLine( sprintf( - __('%1$s: %2$s'), - '' . __('Serial number') . '', + __s('%1$s: %2$s'), + '' . __s('Serial number') . '', $item->fields['serial'], ), sprintf( - __('%1$s: %2$s'), - '' . __('Inventory number') . '', + __s('%1$s: %2$s'), + '' . __s('Inventory number') . '', $item->fields['otherserial'], ), ); $pdf->displayLine( sprintf( - __('%1$s: %2$s'), - '' . __('User') . '', + __s('%1$s: %2$s'), + '' . __s('User') . '', getUserName($item->fields['users_id']), ), sprintf( - __('%1$s: %2$s'), - '' . __('Group') . '', + __s('%1$s: %2$s'), + '' . __s('Group') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_groups', $item->fields['groups_id'], @@ -194,8 +192,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) $pdf->displayLine( sprintf( - __('%1$s: %2$s'), - '' . __('Environment', 'appliances') . '', + __s('%1$s: %2$s'), + '' . __s('Environment', 'appliances') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_applianceenvironments', $item->fields['applianceenvironments_id'], @@ -204,7 +202,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) ); $pdf->displayText( - sprintf(__('%1$s: %2$s'), '' . __('Comments') . '', $item->fields['comment']), + sprintf(__s('%1$s: %2$s'), '' . __s('Comments') . '', $item->fields['comment']), ); $pdf->displaySpace(); @@ -218,34 +216,36 @@ public static function pdfForAppliance(PluginPdfSimplePDF $pdf, Appliance $appli $instID = $appli->fields['id']; $pdf->setColumnsSize(100); - $pdf->displayTitle('' . _n('Associated item', 'Associated items', 2) . ''); + $pdf->displayTitle('' . _sn('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()) { $pdf->setColumnsSize(12, 27, 25, 18, 18); $pdf->displayTitle( - '' . __('Type'), - __('Name'), - __('Entity'), - __('Serial number'), - __('Inventory number') . '', + '' . __s('Type'), + __s('Name'), + __s('Entity'), + __s('Serial number'), + __s('Inventory number') . '', ); } else { $pdf->setColumnsSize(25, 31, 22, 22); $pdf->displayTitle( - '' . __('Type'), - __('Name'), - __('Serial number'), - __('Inventory number') . '', + '' . __s('Type'), + __s('Name'), + __s('Serial number'), + __s('Inventory number') . '', ); } - if (!$number) { - $pdf->displayLine(__('No item found')); + if ($number === 0) { + $pdf->displayLine(__s('No item found')); } else { $dbu = new DbUtils(); foreach ($result as $id => $row) { @@ -286,21 +286,21 @@ public static function pdfForAppliance(PluginPdfSimplePDF $pdf, Appliance $appli $query['ORDER'] = ['glpi_entities.completename', $item->getTable() . '.' . $column]; $result_linked = $DB->request($query); - if (count($result_linked)) { + if (count($result_linked) > 0) { foreach ($result_linked as $id => $data) { if (!$item->getFromDB($data['id'])) { continue; } if ($type == 'Ticket') { - $data['name'] = sprintf(__('%1$s %2$s'), __('Ticket'), $data['id']); + $data['name'] = sprintf(__s('%1$s %2$s'), __s('Ticket'), $data['id']); } if ($type == 'KnowbaseItem') { $data['name'] = $data['question']; } $name = $data['name']; if (empty($data['name'])) { - $name = sprintf(__('%1$s (%2$s)'), $name, $data['id']); + $name = sprintf(__s('%1$s (%2$s)'), $name, $data['id']); } if (Session::isMultiEntitiesMode()) { @@ -312,16 +312,16 @@ public static function pdfForAppliance(PluginPdfSimplePDF $pdf, Appliance $appli 'glpi_entities', $data['entities_id'], ), - (isset($data['serial']) ? $data['serial'] : '-'), - (isset($data['otherserial']) ? $data['otherserial'] : '-'), + ($data['serial'] ?? '-'), + ($data['otherserial'] ?? '-'), ); } else { $pdf->setColumnsSize(25, 31, 22, 22); $pdf->displayTitle( $item->getTypeName(1), $name, - (isset($data['serial']) ? $data['serial'] : '-'), - (isset($data['otherserial']) ? $data['otherserial'] : '-'), + ($data['serial'] ?? '-'), + ($data['otherserial'] ?? '-'), ); } @@ -348,7 +348,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); @@ -374,8 +377,8 @@ public static function showList_relation($pdf, $relID) } $pdf->setColumnsSize(100); $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - '' . __('Relations') . " $title ", + __s('%1$s: %2$s'), + '' . __s('Relations') . " $title ", implode(', ', $opts), )); } @@ -398,7 +401,7 @@ public static function showList_PDF($pdf, $ID, $appliancesID) 'ORDER' => 'vvalues']); $number_champs = count($result_app_opt); - if (!$number_champs) { + if ($number_champs === 0) { return; } @@ -420,8 +423,8 @@ public static function showList_PDF($pdf, $ID, $appliancesID) $pdf->setColumnsSize(100); $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - '' . __('User fields', 'appliances') . '', + __s('%1$s: %2$s'), + '' . __s('User fields', 'appliances') . '', implode(', ', $opts), )); } @@ -431,13 +434,11 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) /** @var DBmysql $DB */ global $DB; - $dbu = new DbUtils(); - $ID = $item->getField('id'); $itemtype = get_class($item); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Associated appliances', 'appliances') . ''); + $pdf->displayTitle('' . __s('Associated appliances', 'appliances') . ''); $query = ['FIELDS' => ['glpi_plugin_appliances_appliances_items.id AS entID', 'glpi_plugin_appliances_appliances.*'], @@ -462,15 +463,15 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $result = $DB->request($query); $number = count($result); - if (!$number) { - $pdf->displayLine(__('No item found')); + if ($number === 0) { + $pdf->displayLine(__s('No item found')); } else { if (Session::isMultiEntitiesMode()) { $pdf->setColumnsSize(30, 30, 20, 20); - $pdf->displayTitle('' . __('Name'), __('Entity'), __('Group'), __('Type') . ''); + $pdf->displayTitle('' . __s('Name'), __s('Entity'), __s('Group'), __s('Type') . ''); } else { $pdf->setColumnsSize(50, 25, 25); - $pdf->displayTitle('' . __('Name'), __('Group'), __('Type') . ''); + $pdf->displayTitle('' . __s('Name'), __s('Group'), __s('Type') . ''); } while ($data = $result->current()) { diff --git a/inc/cartridge.class.php b/inc/cartridge.class.php index 266368d..efda6d0 100644 --- a/inc/cartridge.class.php +++ b/inc/cartridge.class.php @@ -39,7 +39,7 @@ class PluginPdfCartridge extends PluginPdfCommon **/ public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Cartridge()); + $this->obj = ($obj ?: new Cartridge()); } /** @@ -62,78 +62,98 @@ 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); - $i = 0; $pages = $p->fields['init_pages_counter']; $pdf->setColumnsSize(100); - $title = '' . ($old ? __('Worn cartridges') : __('Used cartridges')) . ''; + $title = '' . ($old ? __s('Worn cartridges') : __s('Used cartridges')) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $stock_time = 0; + $use_time = 0; + $pages_printed = 0; + $nb_pages_printed = 0; + + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); if (!$old) { $pdf->setColumnsSize(5, 35, 30, 15, 15); $pdf->displayTitle( - '' . __('ID'), - __('Cartridge model'), - __('Cartridge type'), - __('Add date'), - __('Use date') . + '' . __s('ID'), + __s('Cartridge model'), + __s('Cartridge type'), + __s('Add date'), + __s('Use date') . '', ); } else { $pdf->setColumnsSize(4, 20, 20, 10, 10, 10, 13, 13); $pdf->displayTitle( - '' . __('ID'), - __('Cartridge model'), - __('Cartridge type'), - __('Add date'), - __('Use date'), - __('End date'), - __('Printer counter'), - __('Printed pages') . + '' . __s('ID'), + __s('Cartridge model'), + __s('Cartridge type'), + __s('Add date'), + __s('Use date'), + __s('End date'), + __s('Printer counter'), + __s('Printed pages') . '', ); } - $stock_time = 0; - $use_time = 0; - $pages_printed = 0; - $nb_pages_printed = 0; foreach ($result as $data) { $date_in = Html::convDate($data['date_in']); $date_use = Html::convDate($data['date_use']); $date_out = Html::convDate($data['date_out']); $col1 = $data['id']; - $col2 = sprintf(__('%1$s - %2$s'), $data['type'], $data['ref']); + $col2 = sprintf(__s('%1$s - %2$s'), $data['type'], $data['ref']); $col6 = $data['pages']; $col7 = ''; @@ -156,9 +176,9 @@ public static function pdfForPrinter(PluginPdfSimplePDF $pdf, Printer $p, $old = $pages_printed += $data['pages'] - $pages; $nb_pages_printed++; $col7 = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col6, - __('%d printed pages'), + __s('%d printed pages'), ($data['pages'] - $pages), ); $pages = $data['pages']; @@ -192,18 +212,18 @@ public static function pdfForPrinter(PluginPdfSimplePDF $pdf, Printer $p, $old = $pdf->setColumnsSize(33, 33, 34); $pdf->displayTitle( '' . sprintf( - __('%1$s: %2$s'), - __('Average time in stock') . '', - sprintf(_n('%d month', '%d months', (int) $time_stock), $time_stock), + __s('%1$s: %2$s'), + __s('Average time in stock') . '', + sprintf(_sn('%d month', '%d months', (int) $time_stock), $time_stock), ), '' . sprintf( - __('%1$s: %2$s'), - __('Average time in use') . '', - sprintf(_n('%d month', '%d months', (int) $time_use), $time_use), + __s('%1$s: %2$s'), + __s('Average time in use') . '', + sprintf(_sn('%d month', '%d months', (int) $time_use), $time_use), ), '' . sprintf( - __('%1$s: %2$s'), - __('Average number of printed pages') . '', + __s('%1$s: %2$s'), + __s('Average number of printed pages') . '', round($pages_printed / $nb_pages_printed), ), ); @@ -245,76 +265,83 @@ 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); $pages = []; - if ($number) { + if ($number !== 0) { if ($state == 'new') { $pdf->setColumnsSize(25, 25, 25, 25); $pdf->displayTitle( - '' . __('Total') . '', + '' . __s('Total') . '', '' . Cartridge::getTotalNumber($tID) . '', '' . sprintf( - __('%1$s %2$s'), - _n('Cartridge', 'Cartridges', $number), + __s('%1$s %2$s'), + _sn('Cartridge', 'Cartridges', $number), _nx('cartridge', 'New', 'New', $number), ) . '', '' . Cartridge::getUnusedNumber($tID) . '', ); $pdf->displayTitle( - '' . __('Used cartridges') . '', + '' . __s('Used cartridges') . '', '' . Cartridge::getUsedNumber($tID), - '' . __('Worn cartridges') . '', + '' . __s('Worn cartridges') . '', '' . Cartridge::getOldNumber($tID), ); $pdf->setColumnsSize(100); $pdf->displayTitle('' . sprintf( - __('%1$s %2$s'), - _n('Cartridge', 'Cartridges', $number), + __s('%1$s %2$s'), + _sn('Cartridge', 'Cartridges', $number), _nx('cartridge', 'New', 'New', $number), ) . ''); } elseif ($state == 'used') { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Used cartridges') . ''); + $pdf->displayTitle('' . __s('Used cartridges') . ''); } else { // Old $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Worn cartridges') . ''); + $pdf->displayTitle('' . __s('Worn cartridges') . ''); } if ($state != 'old') { $pdf->setColumnsSize(5, 20, 20, 20, 35); $pdf->displayLine( - '' . __('ID') . '', + '' . __s('ID') . '', '' . _x('item', 'State') . '', - '' . __('Add date') . '', - '' . __('Use date') . '', - '' . __('Used on') . '', + '' . __s('Add date') . '', + '' . __s('Use date') . '', + '' . __s('Used on') . '', ); } else { $pdf->setColumnsSize(5, 20, 15, 15, 15, 15, 15); $pdf->displayLine( - '' . __('ID') . '', + '' . __s('ID') . '', '' . _x('item', 'State') . '', - '' . __('Add date') . '', - '' . __('Use date') . '', - '' . __('Used on') . '', - '' . __('End date') . '', - '' . __('Printer counter') . '', + '' . __s('Add date') . '', + '' . __s('Use date') . '', + '' . __s('Used on') . '', + '' . __s('End date') . '', + '' . __s('Printer counter') . '', ); } @@ -347,10 +374,10 @@ public static function pdfForCartridgeItem(PluginPdfSimplePDF $pdf, CartridgeIte $pages_printed += $data['pages'] - $pages[$printer]; $nb_pages_printed++; $pp = $data['pages'] - $pages[$printer]; - $pdfpages = sprintf(_n('%d printed page', '%d printed pages', $pp), $pp); + $pdfpages = sprintf(_sn('%d printed page', '%d printed pages', $pp), $pp); $pages[$printer] = $data['pages']; } elseif ($data['pages'] != 0) { - $pdfpages = __('Counter error'); + $pdfpages = __s('Counter error'); } } $pdf->displayLine( @@ -370,14 +397,14 @@ public static function pdfForCartridgeItem(PluginPdfSimplePDF $pdf, CartridgeIte } $pdf->setColumnsSize(33, 33, 34); $pdf->displayLine( - '' . __('Average time in stock') . '', - '' . __('Average time in use') . '', - '' . __('Average number of printed pages') . '', + '' . __s('Average time in stock') . '', + '' . __s('Average time in use') . '', + '' . __s('Average number of printed pages') . '', ); $pdf->displayLine( - round($stock_time / $number / 60 / 60 / 24 / 30.5, 1) . ' ' . __('month'), - round($use_time / $number / 60 / 60 / 24 / 30.5, 1) . ' ' . __('month'), + round($stock_time / $number / 60 / 60 / 24 / 30.5, 1) . ' ' . __s('month'), + round($use_time / $number / 60 / 60 / 24 / 30.5, 1) . ' ' . __s('month'), round($pages_printed / $nb_pages_printed), ); } diff --git a/inc/cartridgeitem.class.php b/inc/cartridgeitem.class.php index 17a9644..63a09db 100644 --- a/inc/cartridgeitem.class.php +++ b/inc/cartridgeitem.class.php @@ -36,7 +36,7 @@ class PluginPdfCartridgeItem extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new CartridgeItem()); + $this->obj = ($obj ?: new CartridgeItem()); } public function defineAllTabsPDF($options = []) @@ -53,10 +53,10 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem) PluginPdfCommon::mainTitle($pdf, $cartitem); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Name') . '', $cartitem->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Name') . '', $cartitem->fields['name']), '' . sprintf( - __('%1$s: %2$s'), - __('Location') . '', + __s('%1$s: %2$s'), + __s('Location') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_locations', $cartitem->fields['locations_id'], @@ -65,26 +65,26 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem) ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Type') . '', + __s('%1$s: %2$s'), + __s('Type') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_cartridgeitemtypes', $cartitem->fields['cartridgeitemtypes_id'], )), ), - '' . sprintf(__('%1$s: %2$s'), __('Reference') . '', $cartitem->fields['ref']), + '' . sprintf(__s('%1$s: %2$s'), __s('Reference') . '', $cartitem->fields['ref']), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Technician in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Technician in charge of the hardware') . '', $dbu->getUserName($cartitem->fields['users_id_tech']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Manufacturer') . '', + __s('%1$s: %2$s'), + __s('Manufacturer') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_manufacturers', $cartitem->fields['manufacturers_id'], @@ -93,8 +93,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem) ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Group in charge of the hardware') . '', Dropdown::getDropdownName( 'glpi_groups', $cartitem->fields['groups_id_tech'], @@ -104,16 +104,16 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Stock location') . '', + __s('%1$s: %2$s'), + __s('Stock location') . '', Dropdown::getDropdownName( 'glpi_locations', $cartitem->fields['locations_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Alert threshold') . '', + __s('%1$s: %2$s'), + __s('Alert threshold') . '', $cartitem->getField('alarm_threshold'), ), ); @@ -161,14 +161,14 @@ public static function pdfForPrinterModel(PluginPdfSimplePDF $pdf, CartridgeItem } $pdf->setColumnsSize(100); - $title = '' . _n('Printer model', 'Printer models', $number) . ''; - if (!$number) { - $pdf->displayTitle(__('No printel model associated', 'pdf')); + $title = '' . _sn('Printer model', 'Printer models', $number) . ''; + if ($number === 0) { + $pdf->displayTitle(__s('No printel model associated', 'pdf')); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); diff --git a/inc/change.class.php b/inc/change.class.php index 2d6a8a3..0aa10a6 100644 --- a/inc/change.class.php +++ b/inc/change.class.php @@ -36,7 +36,7 @@ class PluginPdfChange extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Change()); + $this->obj = ($obj ?: new Change()); } public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) @@ -51,7 +51,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $pdf->setColumnsSize(100); $pdf->displayTitle('' . - (empty($job->fields['name']) ? __('Without title') : $name = $job->fields['name']) . ''); + (empty($job->fields['name']) ? __s('Without title') : $name = $job->fields['name']) . ''); if (count($_SESSION['glpiactiveentities']) > 1) { $entity = ' (' . Dropdown::getDropdownName('glpi_entities', $job->fields['entities_id']) . ')'; @@ -61,24 +61,23 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $pdf->setColumnsSize(50, 50); $recipient_name = ''; + $due = ""; if ($job->fields['users_id_recipient']) { $recipient = new User(); $recipient->getFromDB($job->fields['users_id_recipient']); $recipient_name = $recipient->getName(); } - - $sla = $due = $commentsla = ''; if ($job->fields['time_to_resolve']) { $due = '' . sprintf( - __('%1$s: %2$s'), - __('Time to resolve') . '', + __s('%1$s: %2$s'), + __s('Time to resolve') . '', Html::convDateTime($job->fields['time_to_resolve']), ); } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Opening date') . '', + __s('%1$s: %2$s'), + __s('Opening date') . '', Html::convDateTime($job->fields['date']), ), $due, @@ -88,29 +87,29 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('By') . '', $recipient_name), - '' . sprintf(__('%1$s: %2$s'), __('Last update') . '', $lastupdate), + '' . sprintf(__s('%1$s: %2$s'), __s('By') . '', $recipient_name), + '' . sprintf(__s('%1$s: %2$s'), __s('Last update') . '', $lastupdate), ); $status = ''; if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { - $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['solvedate'])); + $status = sprintf(__s('%1$s %2$s'), '-', Html::convDateTime($job->fields['solvedate'])); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['closedate'])); + $status = sprintf(__s('%1$s %2$s'), '-', Html::convDateTime($job->fields['closedate'])); } if ($job->fields['status'] == Change::WAITING) { $status = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), '-', Html::convDateTime($job->fields['begin_waiting_date']), ); @@ -118,13 +117,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Status') . '', + __s('%1$s: %2$s'), + __s('Status') . '', Toolbox::stripTags($job->getStatus($job->fields['status'])) . $status, ), '' . sprintf( - __('%1$s: %2$s'), - __('Urgency') . '', + __s('%1$s: %2$s'), + __s('Urgency') . '', Toolbox::stripTags($job->getUrgencyName($job->fields['urgency'])), ), ); @@ -132,29 +131,29 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Impact') . '', + __s('%1$s: %2$s'), + __s('Impact') . '', Toolbox::stripTags($job->getImpactName($job->fields['impact'])), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Total duration') . '', + __s('%1$s: %2$s'), + __s('Total duration') . '', Toolbox::stripTags(CommonITILObject::getActionTime($job->fields['actiontime'])), ), '' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Toolbox::stripTags($job->getPriorityName($job->fields['priority'])), ), ); @@ -164,7 +163,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) // Requester $users = []; $listusers = ''; - $requester = '' . sprintf(__('%1$s: %2$s') . '', __('Requester'), $listusers); + $requester = '' . sprintf(__s('%1$s: %2$s') . '', __s('Requester'), $listusers); foreach ($job->getUsers(CommonITILActor::REQUESTER) as $d) { if ($d['users_id']) { $tmp = Toolbox::stripTags($dbu->getUserName($d['users_id'])); @@ -184,8 +183,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $groups = []; $listgroups = ''; $requestergroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Requester group'), + __s('%1$s: %2$s') . '', + __s('Requester group'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::REQUESTER) as $d) { @@ -200,7 +199,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) // Observer $users = []; $listusers = ''; - $watcher = '' . sprintf(__('%1$s: %2$s') . '', __('Watcher'), $listusers); + $watcher = '' . sprintf(__s('%1$s: %2$s') . '', __s('Watcher'), $listusers); foreach ($job->getUsers(CommonITILActor::OBSERVER) as $d) { if ($d['users_id']) { $tmp = Toolbox::stripTags($dbu->getUserName($d['users_id'])); @@ -220,8 +219,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $groups = []; $listgroups = ''; $watchergroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Watcher group'), + __s('%1$s: %2$s') . '', + __s('Watcher group'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::OBSERVER) as $d) { @@ -237,8 +236,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $users = []; $listusers = ''; $assign = '' . sprintf( - __('%1$s: %2$s') . '', - __('Assigned to technicians'), + __s('%1$s: %2$s') . '', + __s('Assigned to technicians'), $listusers, ); foreach ($job->getUsers(CommonITILActor::ASSIGN) as $d) { @@ -260,8 +259,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $groups = []; $listgroups = ''; $assigngroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Assigned to groups'), + __s('%1$s: %2$s') . '', + __s('Assigned to groups'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::ASSIGN) as $d) { @@ -277,8 +276,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $suppliers = []; $listsuppliers = ''; $assignsupplier = '' . sprintf( - __('%1$s: %2$s') . '', - __('Assigned to a supplier'), + __s('%1$s: %2$s') . '', + __s('Assigned to a supplier'), $listsuppliers, ); foreach ($job->getSuppliers(CommonITILActor::ASSIGN) as $d) { @@ -294,11 +293,11 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) $pdf->setColumnsSize(100); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Title') . '', $job->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Title') . '', $job->fields['name']), ); $pdf->displayText( - '' . sprintf(__('%1$s: %2$s') . '', __('Description'), ''), + '' . sprintf(__s('%1$s: %2$s') . '', __s('Description'), ''), Toolbox::stripTags($job->fields['content']), 1, ); @@ -309,19 +308,19 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Change $job) public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Change $job) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Analysis') . ''); + $pdf->displayTitle('' . __s('Analysis') . ''); $pdf->setColumnsSize(10, 90); $pdf->displayText(sprintf( - __('%1$s: %2$s'), - '' . __('Impacts') . '', + __s('%1$s: %2$s'), + '' . __s('Impacts') . '', $job->fields['impactcontent'], )); $pdf->displayText(sprintf( - __('%1$s: %2$s'), - '' . __('Control list') . '', + __s('%1$s: %2$s'), + '' . __s('Control list') . '', $job->fields['controlistcontent'], )); } @@ -329,25 +328,25 @@ public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Change $job) public static function pdfPlan(PluginPdfSimplePDF $pdf, Change $job) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Plans') . ''); + $pdf->displayTitle('' . __s('Plans') . ''); $pdf->setColumnsSize(10, 90); $pdf->displayText(sprintf( - __('%1$s: %2$s'), - '' . __('Deployment plan') . '', + __s('%1$s: %2$s'), + '' . __s('Deployment plan') . '', $job->fields['rolloutplancontent'], )); $pdf->displayText(sprintf( - __('%1$s: %2$s'), - '' . __('Backup plan') . '', + __s('%1$s: %2$s'), + '' . __s('Backup plan') . '', $job->fields['backoutplancontent'], )); $pdf->displayText(sprintf( - __('%1$s: %2$s'), - '' . __('Checklist') . '', + __s('%1$s: %2$s'), + '' . __s('Checklist') . '', $job->fields['checklistcontent'], )); } @@ -355,24 +354,24 @@ public static function pdfPlan(PluginPdfSimplePDF $pdf, Change $job) public static function pdfStat(PluginPdfSimplePDF $pdf, Change $job) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Statistics') . ''); + $pdf->displayTitle('' . __s('Statistics') . ''); - $pdf->displayTitle('' . _n('Date', 'Dates', 2) . ''); + $pdf->displayTitle('' . _sn('Date', 'Dates', 2) . ''); $pdf->setColumnsSize(50, 50); - $pdf->displayLine(__('Opening date'), Html::convDateTime($job->fields['date'])); - $pdf->displayLine(__('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve'])); + $pdf->displayLine(__s('Opening date'), Html::convDateTime($job->fields['date'])); + $pdf->displayLine(__s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve'])); if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { - $pdf->displayLine(__('Resolution date'), Html::convDateTime($job->fields['solvedate'])); + $pdf->displayLine(__s('Resolution date'), Html::convDateTime($job->fields['solvedate'])); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - $pdf->displayLine(__('Closing date'), Html::convDateTime($job->fields['closedate'])); + $pdf->displayLine(__s('Closing date'), Html::convDateTime($job->fields['closedate'])); } $pdf->setColumnsSize(100); - $pdf->displayTitle('' . _n('Time', 'Times', 2) . ''); + $pdf->displayTitle('' . _sn('Time', 'Times', 2) . ''); $pdf->setColumnsSize(50, 50); if (isset($job->fields['takeintoaccount_delay_stat']) > 0) { @@ -380,31 +379,26 @@ public static function pdfStat(PluginPdfSimplePDF $pdf, Change $job) $accountdelay = Toolbox::stripTags(Html::timestampToString($job->fields['takeintoaccount_delay_stat'], false)); } $pdf->displayLine( - __('Take into account'), - isset($accountdelay) ? $accountdelay : '', + __s('Take into account'), + $accountdelay ?? '', ); } - if (in_array($job->fields['status'], $job->getSolvedStatusArray()) - || in_array($job->fields['status'], $job->getClosedStatusArray())) { - if ($job->fields['solve_delay_stat'] > 0) { - $pdf->displayLine( - __('Resolution'), - Toolbox::stripTags(Html::timestampToString($job->fields['solve_delay_stat'], false)), - ); - } + if ((in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) && $job->fields['solve_delay_stat'] > 0) { + $pdf->displayLine( + __s('Resolution'), + Toolbox::stripTags(Html::timestampToString($job->fields['solve_delay_stat'], false)), + ); } - if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - if ($job->fields['close_delay_stat'] > 0) { - $pdf->displayLine( - __('Closing'), - Toolbox::stripTags(Html::timestampToString($job->fields['close_delay_stat'], false)), - ); - } + if (in_array($job->fields['status'], $job->getClosedStatusArray()) && $job->fields['close_delay_stat'] > 0) { + $pdf->displayLine( + __s('Closing'), + Toolbox::stripTags(Html::timestampToString($job->fields['close_delay_stat'], false)), + ); } if ($job->fields['waiting_duration'] > 0) { $pdf->displayLine( - __('Pending'), + __s('Pending'), Toolbox::stripTags(Html::timestampToString($job->fields['waiting_duration'], false)), ); } @@ -421,7 +415,7 @@ public function defineAllTabsPDF($options = []) if (Session::haveRight('change', Change::READALL) // for technician || Session::haveRight('followup', ITILFollowup::SEEPRIVATE) || Session::haveRight('task', TicketTask::SEEPRIVATE)) { - $onglets['_private_'] = __('Private'); + $onglets['_private_'] = __s('Private'); } return $onglets; diff --git a/inc/change_item.class.php b/inc/change_item.class.php index daebdde..e6790b7 100644 --- a/inc/change_item.class.php +++ b/inc/change_item.class.php @@ -36,7 +36,7 @@ class PluginPdfChange_Item extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Change_Item()); + $this->obj = ($obj ?: new Change_Item()); } public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) @@ -52,31 +52,31 @@ 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); - $title = '' . _n('Item', 'Items', $number) . ''; + $title = '' . _sn('Item', 'Items', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); $pdf->setColumnsSize(20, 20, 26, 17, 17); $pdf->displayTitle( - '' . __('Type'), - __('Name'), - __('Entity'), - __('Serial number'), - __('Inventory number') . '', + '' . __s('Type'), + __s('Name'), + __s('Entity'), + __s('Serial number'), + __s('Inventory number') . '', ); $totalnb = 0; @@ -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; @@ -127,7 +127,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) if ($prem) { $typename = $item->getTypeName($nb); $pdf->displayLine( - Toolbox::stripTags(sprintf(__('%1$s: %2$s'), $typename, $nb)), + Toolbox::stripTags(sprintf(__s('%1$s: %2$s'), $typename, $nb)), Toolbox::stripTags($name), Dropdown::getDropdownName('glpi_entities', $data['entity']), Toolbox::stripTags((string) $data["serial"]), @@ -150,7 +150,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) } } // } - $pdf->displayLine('' . sprintf(__('%1$s = %2$s') . '', __('Total'), $totalnb)); + $pdf->displayLine('' . sprintf(__s('%1$s = %2$s') . '', __s('Total'), $totalnb)); } } @@ -193,44 +193,53 @@ 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); $pdf->setColumnsSize(100); $title = '' . Change::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d change', 'Last %d changes', $number) . '', + _sn('Last %d change', 'Last %d changes', $number) . '', $number, )); @@ -241,14 +250,14 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . - sprintf(__('%1$s: %2$s'), __('Status'), Change::getStatus($job->fields['status'])); + sprintf(__s('%1$s: %2$s'), __s('Status'), Change::getStatus($job->fields['status'])); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName('glpi_entities', $job->fields['entities_id']), ); @@ -259,15 +268,15 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if ($job->fields['begin_waiting_date']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Put on hold on %s') . '', + __s('Put on hold on %s') . '', Html::convDateTime($job->fields['begin_waiting_date']), ), ); @@ -275,31 +284,31 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -307,35 +316,35 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->displayLine($col); $col = '' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Change::getPriorityName($job->fields['priority']), ); if ($job->fields['itilcategories_id']) { $cat = '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], ), ); - $col = sprintf(__('%1$s - %2$s'), $col, $cat); + $col = sprintf(__s('%1$s - %2$s'), $col, $cat); } $pdf->displayLine($col); $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); @@ -346,28 +355,28 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -376,7 +385,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -387,28 +396,28 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -417,13 +426,13 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Associated items'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Associated items'), ''); - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } } diff --git a/inc/change_problem.class.php b/inc/change_problem.class.php index 5bb0d1a..16eca1b 100644 --- a/inc/change_problem.class.php +++ b/inc/change_problem.class.php @@ -36,7 +36,7 @@ class PluginPdfChange_Problem extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Change_Problem()); + $this->obj = ($obj ?: new Change_Problem()); } public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) @@ -52,30 +52,27 @@ 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 = []; - $used = []; - $pdf->setColumnsSize(100); $title = '' . Problem::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d problem', 'Last %d problems', $number) . '', + _sn('Last %d problem', 'Last %d problems', $number) . '', $number, )); @@ -87,17 +84,17 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . sprintf( - __('%1$s: %2$s'), - __('Status'), + __s('%1$s: %2$s'), + __s('Status'), Problem::getStatus($job->fields['status']), ); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName( 'glpi_entities', @@ -111,15 +108,15 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if ($job->fields['begin_waiting_date']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Put on hold on %s') . '', + __s('Put on hold on %s') . '', Html::convDateTime($job->fields['begin_waiting_date']), ), ); @@ -127,31 +124,31 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -161,29 +158,29 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Ticket::getPriorityName($job->fields['priority']), )); if ($job->fields['itilcategories_id']) { $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], @@ -199,28 +196,28 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -229,7 +226,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -240,28 +237,28 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -270,11 +267,11 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } } @@ -294,29 +291,26 @@ 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 = []; - $used = []; - $pdf->setColumnsSize(100); $title = '' . Change::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d change', 'Last %d changes', $number) . '', + _sn('Last %d change', 'Last %d changes', $number) . '', $number, )); @@ -328,17 +322,17 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . sprintf( - __('%1$s: %2$s'), - __('Status'), + __s('%1$s: %2$s'), + __s('Status'), Problem::getStatus($job->fields['status']), ); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName( 'glpi_entities', @@ -352,37 +346,37 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -392,28 +386,28 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Ticket::getPriorityName($job->fields['priority']), )); if ($job->fields['itilcategories_id']) { $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], @@ -429,28 +423,28 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -459,7 +453,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -470,28 +464,28 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -500,11 +494,11 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } } diff --git a/inc/change_ticket.class.php b/inc/change_ticket.class.php index bdf9537..9712793 100644 --- a/inc/change_ticket.class.php +++ b/inc/change_ticket.class.php @@ -36,7 +36,7 @@ class PluginPdfChange_Ticket extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Change_Ticket()); + $this->obj = ($obj ?: new Change_Ticket()); } public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) @@ -52,27 +52,27 @@ 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); $title = '' . Ticket::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d ticket', 'Last %d tickets', $number) . '', + _sn('Last %d ticket', 'Last %d tickets', $number) . '', $number, )); $pdf->displayTitle($title); @@ -85,17 +85,17 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . sprintf( - __('%1$s: %2$s'), - __('Status'), + __s('%1$s: %2$s'), + __s('Status'), Ticket::getStatus($job->fields['status']), ); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName( 'glpi_entities', @@ -109,15 +109,15 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if ($job->fields['begin_waiting_date']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Put on hold on %s') . '', + __s('Put on hold on %s') . '', Html::convDateTime($job->fields['begin_waiting_date']), ), ); @@ -125,31 +125,31 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -159,29 +159,29 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Ticket::getPriorityName($job->fields['priority']), )); if ($job->fields['itilcategories_id']) { $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], @@ -197,28 +197,28 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -227,7 +227,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -238,28 +238,28 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -268,28 +268,28 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } $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; } if ($first) { $texteitem = '' . sprintf( - __('%1$s: %2$s') . '', - _n('Associated items', 'Associated items', 2), + __s('%1$s: %2$s') . '', + _sn('Associated items', 'Associated items', 2), '' . '
', ); } $listitems .= sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $item->getTypeName(1), Dropdown::getDropdownName( getTableForItemType($data['itemtype']), @@ -302,7 +302,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $pdf->displayText($texteitem, $listitems); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } } @@ -322,26 +322,26 @@ 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); $title = '' . Change::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d change', 'Last %d changes', $number) . '', + _sn('Last %d change', 'Last %d changes', $number) . '', $number, )); @@ -353,17 +353,17 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . sprintf( - __('%1$s: %2$s'), - __('Status'), + __s('%1$s: %2$s'), + __s('Status'), Problem::getStatus($job->fields['status']), ); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName( 'glpi_entities', @@ -377,37 +377,37 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -417,28 +417,28 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Ticket::getPriorityName($job->fields['priority']), )); if ($job->fields['itilcategories_id']) { $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], @@ -454,28 +454,28 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -484,7 +484,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -495,28 +495,28 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -525,11 +525,11 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } } diff --git a/inc/changetask.class.php b/inc/changetask.class.php index a54058c..c438de7 100644 --- a/inc/changetask.class.php +++ b/inc/changetask.class.php @@ -36,7 +36,7 @@ class PluginPdfChangeTask extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new ChangeTask()); + $this->obj = ($obj ?: new ChangeTask()); } public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $job) @@ -48,30 +48,30 @@ 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); $pdf->setColumnsSize(100); $title = '' . ChangeTask::getTypeName(2) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); foreach ($result as $data) { $pdf->setColumnsSize(20, 20, 20, 20, 20); $pdf->displayTitle( - '' . __('Type'), - __('Date'), - __('Duration'), - __('Writer'), - __('Planning') . '', + '' . __s('Type'), + __s('Date'), + __s('Duration'), + __s('Writer'), + __s('Planning') . '', ); $actiontime = Html::timestampToString($data['actiontime'], false); @@ -83,33 +83,29 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $job) } else { if (isset($data['state']) && $data['state']) { $planification = sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('item', 'State'), Planning::getState($data['state']), ); } $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('Begin'), + __s('%1$s: %2$s'), + __s('Begin'), Html::convDateTime($data['begin']), ); $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('End'), + __s('%1$s: %2$s'), + __s('End'), Html::convDateTime($data['end']), ); $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('By'), + __s('%1$s: %2$s'), + __s('By'), $dbu->getUserName($data['users_id_tech']), ); } - if ($data['taskcategories_id']) { - $lib = Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']); - } else { - $lib = ''; - } + $lib = $data['taskcategories_id'] ? Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']) : ''; $pdf->displayLine( '' . Toolbox::stripTags($lib), @@ -120,7 +116,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $job) 1, ); $pdf->displayText( - '' . sprintf(__('%1$s: %2$s') . '', __('Description'), ''), + '' . sprintf(__s('%1$s: %2$s') . '', __s('Description'), ''), $data['content'], 1, ); diff --git a/inc/changevalidation.class.php b/inc/changevalidation.class.php index bc8d797..6b20670 100644 --- a/inc/changevalidation.class.php +++ b/inc/changevalidation.class.php @@ -36,7 +36,7 @@ class PluginPdfChangeValidation extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new ChangeValidation()); + $this->obj = ($obj ?: new ChangeValidation()); } public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) @@ -47,7 +47,7 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) $dbu = new DbUtils(); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Approvals for the change', 'pdf') . ''); + $pdf->displayTitle('' . __s('Approvals for the change', 'pdf') . ''); if (!Session::haveRightsOr( 'changevalidation', @@ -59,32 +59,32 @@ public static function pdfForChange(PluginPdfSimplePDF $pdf, Change $change) )) { return false; } - $ID = $change->getField('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); $title = '' . ChangeValidation::getTypeName(2) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); $pdf->setColumnsSize(10, 10, 15, 20, 10, 15, 20); $pdf->displayTitle( _x('item', 'State'), - __('Request date'), - __('Approval requester'), - __('Request comments'), - __('Approval status'), - __('Approver'), - __('Approval comments'), + __s('Request date'), + __s('Approval requester'), + __s('Request comments'), + __s('Approval status'), + __s('Approver'), + __s('Approval comments'), ); foreach ($result as $row) { diff --git a/inc/common.class.php b/inc/common.class.php index 7d6a289..04fad82 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -42,22 +42,16 @@ abstract class PluginPdfCommon extends CommonGLPI **/ public function __construct(?CommonGLPI $obj = null) { - if ($obj) { + if ($obj instanceof CommonGLPI) { $this->obj = $obj; } } - /** - * Add standard define tab - * - * @param $itemtype itemtype link to the tab - * @param $ong array defined tab array - * @param $options array of options (for withtemplate) - * - * @return CommonGLPI (set the tab array) - **/ - final public function addStandardTab($itemtype, &$ong, $options) + // cannot override because created in CommonGLPI as final + /** @phpstan-ignore-next-line */ + public function addStandardTab($itemtype, array &$ong, array $options) { + parent::addStandardTab($itemtype, $ong, $options); $dbu = new DbUtils(); $withtemplate = 0; @@ -65,19 +59,14 @@ final public function addStandardTab($itemtype, &$ong, $options) $withtemplate = $options['withtemplate']; } - if (!is_numeric($itemtype) - && ($obj = $dbu->getItemForItemtype($itemtype))) { - if (method_exists($itemtype, 'displayTabContentForPDF') - && !($obj instanceof PluginPdfCommon)) { - $titles = $obj->getTabNameForItem($this->obj, $withtemplate); - if (!is_array($titles)) { - $titles = [1 => $titles]; - } - - foreach ($titles as $key => $val) { - if (!empty($val)) { - $ong[$itemtype . '$' . $key] = $val; - } + if (!is_numeric($itemtype) && ($obj = $dbu->getItemForItemtype($itemtype)) && (method_exists($itemtype, 'displayTabContentForPDF'))) { + $titles = $obj->getTabNameForItem($this->obj, $withtemplate); + if (!is_array($titles)) { + $titles = [1 => $titles]; + } + foreach ($titles as $key => $val) { + if (!empty($val)) { + $ong[$itemtype . '$' . $key] = $val; } } } @@ -121,10 +110,8 @@ public function defineAllTabsPDF($options = []) **/ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if (Session::haveRight('plugin_pdf', READ)) { - if (empty($withtemplate)) { - return __('Print to pdf', 'pdf'); - } + if (Session::haveRight('plugin_pdf', READ) && empty($withtemplate)) { + return self::createTabEntry(__s('PDF export', 'pdf'), 0, $item::getType(), PluginPdfConfig::getIcon()); } return ''; } @@ -280,8 +267,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; } @@ -302,21 +292,21 @@ private function addHeader($ID) && $this->obj->getField('name')) { $name = $this->obj->getField('name'); } else { - $name = sprintf(__('%1$s %2$s'), __('ID'), $ID); + $name = sprintf(__s('%1$s %2$s'), __s('ID'), $ID); } if (Session::isMultiEntitiesMode() && $this->obj->isEntityAssign()) { $entity = ' (' . Dropdown::getDropdownName('glpi_entities', $this->obj->getEntityID()) . ')'; } - $header = Glpi\Toolbox\Sanitizer::unsanitize(sprintf( - __('%1$s - %2$s'), + $header = sprintf( + __s('%1$s - %2$s'), $this->obj->getTypeName(), sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $name, $entity, ), - )); + ); $this->pdf->setHeader($header); return true; @@ -334,15 +324,15 @@ public static function pdfNote(PluginPdfSimplePDF $pdf, CommonDBTM $item) $number = count($notes); $pdf->setColumnsSize(100); - $title = '' . _n('Note', 'Notes', $number) . ''; + $title = '' . _sn('Note', 'Notes', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); @@ -384,12 +374,12 @@ final public function generatePDF($tab_id, $tabs, $page = 0, $render = true) } foreach ($tabs as $tab) { - if (!$this->displayTabContentForPDF($this->pdf, $this->obj, $tab) - && !$this->displayCommonTabForPDF($this->pdf, $this->obj, $tab)) { + if (!static::displayTabContentForPDF($this->pdf, $this->obj, $tab) + && !static::displayCommonTabForPDF($this->pdf, $this->obj, $tab)) { $data = explode('$', $tab); $itemtype = $data[0]; // Default set - $tabnum = (isset($data[1]) ? $data[1] : 1); + $tabnum = ($data[1] ?? 1); if (!is_numeric($itemtype) && ($itemtype != 'empty')) { @@ -404,6 +394,7 @@ final public function generatePDF($tab_id, $tabs, $page = 0, $render = true) } } elseif (method_exists($itemtype, 'displayTabContentForPdf') && ($obj = $dbu->getItemForItemtype($itemtype))) { + /** @phpstan-ignore-next-line */ if ($obj->displayTabContentForPdf($this->pdf, $this->obj, $tabnum)) { continue; } @@ -411,7 +402,7 @@ final public function generatePDF($tab_id, $tabs, $page = 0, $render = true) } Toolbox::logInFile( 'php-errors', - sprintf(__("PDF: don't know how to display %s tab") . '\n', $tab), + sprintf(__s("PDF: don't know how to display %s tab") . '\n', $tab), ); } } @@ -433,19 +424,19 @@ public static function mainTitle(PluginPdfSimplePDF $pdf, $item) { $pdf->setColumnsSize(50, 50); - $col1 = '' . sprintf(__('%1$s %2$s'), __('ID'), $item->fields['id']) . ''; + $col1 = '' . sprintf(__s('%1$s %2$s'), __s('ID'), $item->fields['id']) . ''; $col2 = sprintf( - __('%1$s: %2$s'), - __('Last update'), + __s('%1$s: %2$s'), + __s('Last update'), Html::convDateTime($item->fields['date_mod']), ); if (!empty($item->fields['template_name'])) { $col2 = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col2, sprintf( - __('%1$s: %2$s'), - __('Template name'), + __s('%1$s: %2$s'), + __s('Template name'), $item->fields['template_name'], ), ); @@ -463,13 +454,13 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) case 'name-status': return $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Name') . '', + __s('%1$s: %2$s'), + __s('Name') . '', $item->fields['name'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Status') . '', + __s('%1$s: %2$s'), + __s('Status') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_states', $item->fields['states_id'], @@ -480,16 +471,16 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) case 'location-type': return $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Location') . '', + __s('%1$s: %2$s'), + __s('Location') . '', Dropdown::getDropdownName( 'glpi_locations', $item->fields['locations_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Type') . '', + __s('%1$s: %2$s'), + __s('Type') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_' . $type . 'types', $item->fields[$type . 'types_id'], @@ -500,13 +491,13 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) case 'tech-manufacturer': return $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Technician in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Technician in charge of the hardware') . '', $dbu->getUserName($item->fields['users_id_tech']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Manufacturer') . '', + __s('%1$s: %2$s'), + __s('Manufacturer') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_manufacturers', $item->fields['manufacturers_id'], @@ -516,16 +507,16 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) case 'group-model': return $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Group in charge of the hardware') . '', Dropdown::getDropdownName( 'glpi_groups', $item->fields['groups_id_tech'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Model') . '', + __s('%1$s: %2$s'), + __s('Model') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_' . $type . 'models', $item->fields[$type . 'models_id'], @@ -536,13 +527,13 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) case 'contactnum-serial': return $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Alternate username number') . '', + __s('%1$s: %2$s'), + __s('Alternate username number') . '', $item->fields['contact_num'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Serial number') . '', + __s('%1$s: %2$s'), + __s('Serial number') . '', $item->fields['serial'], ), ); @@ -550,13 +541,13 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) case 'contact-otherserial': return $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Alternate username') . '', + __s('%1$s: %2$s'), + __s('Alternate username') . '', $item->fields['contact'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Inventory number') . '', + __s('%1$s: %2$s'), + __s('Inventory number') . '', $item->fields['otherserial'], ), ); @@ -564,22 +555,22 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) case 'user-management': return $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('User') . '', + __s('%1$s: %2$s'), + __s('User') . '', $dbu->getUserName($item->fields['users_id']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Management type') . '', - ($item->fields['is_global'] ? __('Global management') - : __('Unit management')), + __s('%1$s: %2$s'), + __s('Management type') . '', + ($item->fields['is_global'] ? __s('Global management') + : __s('Unit management')), ), ); case 'comment': return $pdf->displayText('' . sprintf( - __('%1$s: %2$s'), - __('Comments') . '', + __s('%1$s: %2$s'), + __s('Comments') . '', '', ), $item->fields['comment']); @@ -611,6 +602,9 @@ public static function processMassiveActionsForOneItemtype( CommonDBTM $item, array $ids ) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + switch ($ma->getAction()) { case 'DoIt': $tab_id = []; @@ -621,9 +615,8 @@ public static function processMassiveActionsForOneItemtype( } $_SESSION['plugin_pdf']['type'] = $item->getType(); $_SESSION['plugin_pdf']['tab_id'] = serialize($tab_id); - $webDir = Plugin::getWebDir('pdf'); echo ""; + location.href='" . $CFG_GLPI['root_doc'] . "/plugins/pdf/front/export.massive.php'"; break; } } diff --git a/inc/commonitilcost.class.php b/inc/commonitilcost.class.php index 2d01a00..8532c2b 100644 --- a/inc/commonitilcost.class.php +++ b/inc/commonitilcost.class.php @@ -36,7 +36,7 @@ class PluginPdfCommonItilCost extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new TicketCost()); + $this->obj = ($obj ?: new TicketCost()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $job) @@ -49,31 +49,34 @@ 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); - if (!$number) { + if ($number === 0) { $pdf->setColumnsSize(100); $pdf->displayTitle(sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), '' . $classname::getTypeName(2) . '', - __('No item to display'), + __s('No item to display'), )); } else { $pdf->setColumnsSize(60, 20, 20); $title = $classname::getTypeName($number); if (!empty(PluginPdfConfig::currencyName())) { $title = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $classname::getTypeName($number), PluginPdfConfig::currencyName(), ); } $pdf->displayTitle( '' . $title . '', - '' . __('Duration') . '', + '' . __s('Duration') . '', '' . CommonITILObject::getActionTime($job->fields['actiontime']) . '', ); @@ -90,15 +93,15 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $job) 'right', ); $pdf->displayTitle( - '' . __('Name') . '', - '' . __('Begin date') . '', - '' . __('End date') . '', - '' . __('Budget') . '', - '' . __('Duration') . '', - '' . __('Time cost') . '', - '' . __('Fixed cost') . '', - '' . __('Material cost') . '', - '' . __('Total cost') . '', + '' . __s('Name') . '', + '' . __s('Begin date') . '', + '' . __s('End date') . '', + '' . __s('Budget') . '', + '' . __s('Duration') . '', + '' . __s('Time cost') . '', + '' . __s('Fixed cost') . '', + '' . __s('Material cost') . '', + '' . __s('Total cost') . '', ); $total = 0; @@ -138,7 +141,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $job) $pdf->setColumnsSize(52, 8, 10, 10, 10, 10); $pdf->setColumnsAlign('right', 'right', 'right', 'right', 'right', 'right'); $pdf->displayLine( - '' . __('Total') . '', + '' . __s('Total') . '', '' . CommonITILObject::getActionTime($total_time) . '', '' . PluginPdfConfig::formatNumber($total_costtime) . '', '' . PluginPdfConfig::formatNumber($total_fixed) . '', diff --git a/inc/computer.class.php b/inc/computer.class.php index b88b448..c8851cf 100644 --- a/inc/computer.class.php +++ b/inc/computer.class.php @@ -36,7 +36,7 @@ class PluginPdfComputer extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Computer()); + $this->obj = ($obj ?: new Computer()); } public function defineAllTabsPDF($options = []) diff --git a/inc/computer_item.class.php b/inc/computer_item.class.php index d1b4d14..7b1f443 100644 --- a/inc/computer_item.class.php +++ b/inc/computer_item.class.php @@ -30,13 +30,15 @@ * -------------------------------------------------------------------------- */ +use Glpi\Asset\Asset_PeripheralAsset; + class PluginPdfComputer_Item extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Computer_Item()); + $this->obj = ($obj ?: new Asset_PeripheralAsset()); } public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) @@ -48,38 +50,48 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) $ID = $comp->getField('id'); - $items = ['Printer' => _n('Printer', 'Printers', 2), - 'Monitor' => _n('Monitor', 'Monitors', 2), - 'Peripheral' => _n('Device', 'Devices', 2), - 'Phone' => _n('Phone', 'Phones', 2)]; + $items = ['Printer' => _sn('Printer', 'Printers', 2), + 'Monitor' => _sn('Monitor', 'Monitors', 2), + 'Peripheral' => _sn('Device', 'Devices', 2), + 'Phone' => _sn('Phone', 'Phones', 2)]; $info = new Infocom(); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Direct connections') . ''); + $pdf->displayTitle('' . __s('Direct connections') . ''); - foreach ($items as $type => $title) { - if (!($item = $dbu->getItemForItemtype($type))) { - continue; - } + foreach (array_keys($items) as $type) { + $item = $dbu->getItemForItemtype($type); 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); @@ -89,23 +101,25 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) $tID = $row['items_id']; $connID = $row['id']; $item->getFromDB($tID); - $info->getFromDBforDevice($type, $tID) || $info->getEmpty(); + if (!$info->getFromDBforDevice($type, $tID)) { + $info->getEmpty(); + } $line1 = $item->getName(); if ($item->getField('serial') != null) { $line1 = sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $line1, sprintf( - __('%1$s: %2$s'), - __('Serial number'), + __s('%1$s: %2$s'), + __s('Serial number'), $item->getField('serial'), ), ); } $line1 = sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $line1, Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_states', @@ -116,31 +130,31 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) $line2 = ''; if ($item->getField('otherserial') != null) { $line2 = sprintf( - __('%1$s: %2$s'), - __('Inventory number'), + __s('%1$s: %2$s'), + __s('Inventory number'), $item->getField('otherserial'), ); } if ($info->fields['immo_number']) { $line2 = sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $line2, sprintf( - __('%1$s: %2$s'), - __('Immobilization number'), + __s('%1$s: %2$s'), + __s('Immobilization number'), $info->fields['immo_number'], ), ); } - if ($line2) { + if ($line2 !== '' && $line2 !== '0') { $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), $item->getTypeName() . '', ''), + '' . sprintf(__s('%1$s: %2$s'), $item->getTypeName() . '', ''), $line1 . "\n" . $line2, 2, ); } else { $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), $item->getTypeName() . '', ''), + '' . sprintf(__s('%1$s: %2$s'), $item->getTypeName() . '', ''), $line1, 1, ); @@ -149,19 +163,19 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $comp) } else { // No row switch ($type) { case 'Printer': - $pdf->displayLine(sprintf(__('No printer', 'pdf'))); + $pdf->displayLine(__s('No printer', 'pdf')); break; case 'Monitor': - $pdf->displayLine(sprintf(__('No monitor', 'pdf'))); + $pdf->displayLine(__s('No monitor', 'pdf')); break; case 'Peripheral': - $pdf->displayLine(sprintf(__('No peripheral', 'pdf'))); + $pdf->displayLine(__s('No peripheral', 'pdf')); break; case 'Phone': - $pdf->displayLine(sprintf(__('No phone', 'pdf'))); + $pdf->displayLine(__s('No phone', 'pdf')); break; } } // No row @@ -181,17 +195,16 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $comp = new Computer(); $pdf->setColumnsSize(100); - $title = '' . __('Direct connections') . ''; + $title = '' . __s('Direct connections') . ''; $result = $DB->request( - 'glpi_computers_items', - ['items_id' => $ID, + ['FROM' => 'glpi_assets_assets_peripheralassets'] + ['items_id' => $ID, 'itemtype' => $type], ); $resultnum = count($result); - if (!$resultnum) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($resultnum === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle($title); @@ -199,16 +212,18 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $tID = $row['computers_id']; $connID = $row['id']; $comp->getFromDB($tID); - $info->getFromDBforDevice('Computer', $tID) || $info->getEmpty(); + if (!$info->getFromDBforDevice('Computer', $tID)) { + $info->getEmpty(); + } - $line1 = (isset($comp->fields['name']) ? $comp->fields['name'] : '(' . $comp->fields['id'] . ')'); + $line1 = ($comp->fields['name'] ?? '(' . $comp->fields['id'] . ')'); if (isset($comp->fields['states_id'])) { $line1 = sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $line1, sprintf( - __('%1$s: %2$s'), - '' . __('Status') . '', + __s('%1$s: %2$s'), + '' . __s('Status') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_states', $comp->fields['states_id'], @@ -218,11 +233,11 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) } if (isset($comp->fields['serial'])) { $line1 = sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $line1, sprintf( - __('%1$s: %2$s'), - '' . __('Serial number') . '', + __s('%1$s: %2$s'), + '' . __s('Serial number') . '', $comp->fields['serial'], ), ); @@ -231,11 +246,11 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) if (isset($comp->fields['otherserial'])) { $line1 = sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $line1, sprintf( - __('%1$s: %2$s'), - '' . __('Inventory number') . '', + __s('%1$s: %2$s'), + '' . __s('Inventory number') . '', $item->getField('otherserial'), ), ); @@ -243,24 +258,24 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $line2 = ''; if ($info->fields['immo_number']) { $line2 = sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $line2, sprintf( - __('%1$s: %2$s'), - '' . __('Immobilization number') . '', + __s('%1$s: %2$s'), + '' . __s('Immobilization number') . '', $info->fields['immo_number'], ), ); } - if ($line2) { + if ($line2 !== '' && $line2 !== '0') { $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), __('Computer') . '', ''), + '' . sprintf(__s('%1$s: %2$s'), __s('Computer') . '', ''), $line1 . "\n" . $line2, 2, ); } else { $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), __('Computer') . '', ''), + '' . sprintf(__s('%1$s: %2$s'), __s('Computer') . '', ''), $line1, 1, ); diff --git a/inc/computer_softwarelicense.class.php b/inc/computer_softwarelicense.class.php index b401c57..67ac3f2 100644 --- a/inc/computer_softwarelicense.class.php +++ b/inc/computer_softwarelicense.class.php @@ -30,13 +30,44 @@ * -------------------------------------------------------------------------- */ +use Glpi\DBAL\QueryExpression; + +/** + * ------------------------------------------------------------------------- + * LICENSE + * + * This file is part of PDF plugin for GLPI. + * + * PDF is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PDF is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Reports. If not, see . + * + * @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 + * -------------------------------------------------------------------------- + */ class PluginPdfComputer_SoftwareLicense extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_SoftwareLicense()); + $this->obj = ($obj ?: new Item_SoftwareLicense()); } public static function pdfForLicenseByEntity(PluginPdfSimplePDF $pdf, SoftwareLicense $license) @@ -51,15 +82,15 @@ public static function pdfForLicenseByEntity(PluginPdfSimplePDF $pdf, SoftwareLi $pdf->setColumnsSize(65, 35); $pdf->setColumnsAlign('left', 'right'); $pdf->displayTitle( - '' . __('Entity') . '', - '' . __('Number of affected computers') . '', + '' . __s('Entity') . '', + '' . __s('Number of affected computers') . '', ); $tot = 0; if (in_array(0, $_SESSION['glpiactiveentities'])) { $nb = Item_SoftwareLicense::countForLicense($ID, 0, 'Computer'); if ($nb > 0) { - $pdf->displayLine(__('Root entity'), $nb); + $pdf->displayLine(__s('Root entity'), $nb); $tot += $nb; } } @@ -77,11 +108,11 @@ public static function pdfForLicenseByEntity(PluginPdfSimplePDF $pdf, SoftwareLi } if ($tot > 0) { - $pdf->displayLine(__('Total'), $tot); + $pdf->displayLine(__s('Total'), $tot); } else { $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $pdf->displayLine(__('No item to display')); + $pdf->displayLine(__s('No item to display')); } $pdf->displaySpace(); } @@ -110,84 +141,130 @@ public static function pdfForLicenseByComputer(PluginPdfSimplePDF $pdf, Software $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $title = '' . __('Affected computers') . ''; + $title = '' . __s('Affected computers') . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%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 QueryExpression($entity_restrict); + } + + $result = $DB->request($query_params); $showEntity = ($license->isRecursive()); if ($showEntity) { $pdf->setColumnsSize(12, 12, 12, 12, 18, 10, 12, 12); $pdf->displayTitle( - '' . __('Entity'), - __('Name'), - __('Serial number'), - __('Inventory number'), - __('Location'), - __('Status'), - __('Group'), - __('User') . + '' . __s('Entity'), + __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Location'), + __s('Status'), + __s('Group'), + __s('User') . '', ); } else { $pdf->setColumnsSize(14, 14, 14, 18, 14, 13, 13); $pdf->displayTitle( - '' . __('Name'), - __('Serial number'), - __('Inventory number'), - __('Location'), - __('Status'), - __('Group'), - __('User') . + '' . __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Location'), + __s('Status'), + __s('Group'), + __s('User') . '', ); } foreach ($result as $data) { $compname = $data['compname']; if (empty($compname)) { - $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']); + $compname = sprintf(__s('%1$s (%2$s)'), $compname, $data['cID']); } - $entname = (empty($data['entity']) ? __('Root entity') : $data['entity']); + $entname = (empty($data['entity']) ? __s('Root entity') : $data['entity']); if ($showEntity) { $pdf->displayLine( diff --git a/inc/computer_softwareversion.class.php b/inc/computer_softwareversion.class.php index 23935d7..546452f 100644 --- a/inc/computer_softwareversion.class.php +++ b/inc/computer_softwareversion.class.php @@ -30,13 +30,44 @@ * -------------------------------------------------------------------------- */ +use Glpi\DBAL\QueryExpression; + +/** + * ------------------------------------------------------------------------- + * LICENSE + * + * This file is part of PDF plugin for GLPI. + * + * PDF is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PDF is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Reports. If not, see . + * + * @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 + * -------------------------------------------------------------------------- + */ class PluginPdfComputer_SoftwareVersion extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_SoftwareVersion()); + $this->obj = ($obj ?: new Item_SoftwareVersion()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -79,77 +110,125 @@ 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 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( - __('%1$s: %2$s'), - _n('Installation', 'Installations', 2), + __s('%1$s: %2$s'), + _sn('Installation', 'Installations', 2), $number, ) . ''); } else { $pdf->displayTitle('' . sprintf( - __('%1$s: %2$s'), - _n('Installation', 'Installations', 2), + __s('%1$s: %2$s'), + _sn('Installation', 'Installations', 2), $number . ' / ' . $total, ) . ''); } $pdf->setColumnsSize(8, 12, 10, 10, 12, 8, 10, 5, 17, 8); $pdf->displayTitle( - '' . _n('Version', 'Versions', 2), - __('Name'), - __('Serial number'), - __('Inventory number'), - __('Location'), - __('Status'), - __('Group'), - __('User'), - _n('License', 'Licenses', 2), - __('Installation date') . '', + '' . _sn('Version', 'Versions', 2), + __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Location'), + __s('Status'), + __s('Group'), + __s('User'), + _sn('License', 'Licenses', 2), + __s('Installation date') . '', ); foreach ($result as $data) { $compname = $data['compname']; if (empty($compname)) { - $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']); + $compname = sprintf(__s('%1$s (%2$s)'), $compname, $data['cID']); } $lics = Item_SoftwareLicense::GetLicenseForInstallation( 'Computer', @@ -162,7 +241,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) foreach ($lics as $lic) { $licname = $lic['name']; if (!empty($lic['type'])) { - $licname = sprintf(__('%1$s (%2$s)'), $licname, $lic['type']); + $licname = sprintf(__s('%1$s (%2$s)'), $licname, $lic['type']); } $tmp[] = $licname; } @@ -181,15 +260,15 @@ 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']), ); } } else { - $pdf->displayTitle('' . _n('Installation', 'Installations', 2) . ''); - $pdf->displayLine(__('No item found')); + $pdf->displayTitle('' . _sn('Installation', 'Installations', 2) . ''); + $pdf->displayLine(__s('No item found')); } $pdf->displaySpace(); } @@ -205,7 +284,7 @@ public static function pdfForVersionByEntity(PluginPdfSimplePDF $pdf, SoftwareVe $pdf->setColumnsSize(100); $pdf->displayTitle('' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), Dropdown::getDropdownName( 'glpi_softwares', $version->getField('softwares_id'), @@ -215,13 +294,13 @@ public static function pdfForVersionByEntity(PluginPdfSimplePDF $pdf, SoftwareVe $pdf->setColumnsSize(75, 25); $pdf->setColumnsAlign('left', 'right'); - $pdf->displayTitle('' . __('Entity'), _n('Installation', 'Installations', 2) . ''); + $pdf->displayTitle('' . __s('Entity'), _sn('Installation', 'Installations', 2) . ''); $lig = $tot = 0; if (in_array(0, $_SESSION['glpiactiveentities'])) { $nb = Item_SoftwareVersion::countForVersion($softwareversions_id, '0'); if ($nb > 0) { - $pdf->displayLine(__('Root entity'), $nb); + $pdf->displayLine(__s('Root entity'), $nb); $tot += $nb; $lig++; } @@ -242,12 +321,12 @@ public static function pdfForVersionByEntity(PluginPdfSimplePDF $pdf, SoftwareVe if ($tot > 0) { if ($lig > 1) { - $pdf->displayLine(__('Total'), $tot); + $pdf->displayLine(__s('Total'), $tot); } } else { $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $pdf->displayLine(__('No item to display')); + $pdf->displayLine(__s('No item to display')); } $pdf->displaySpace(); } @@ -260,92 +339,129 @@ 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(); + new SoftwareVersion(); - foreach ($DB->request($query) as $softwareversion) { + foreach ($DB->request($query_params) as $softwareversion) { $output[] = $softwareversion; } $installed = []; $pdf->setColumnsSize(100); - $title = '' . __('Installed software') . ''; + $title = '' . __s('Installed software') . ''; if (!count($output)) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, count($output)); + $title = sprintf(__s('%1$s: %2$s'), $title, count($output)); $pdf->displayTitle($title); $cat = -1; foreach ($output as $soft) { if ($soft['softwarecategories_id'] != $cat) { $cat = $soft['softwarecategories_id']; - if ($cat && $software_category->getFromDB($cat)) { - $catname = $software_category->getName(); - } else { - $catname = __('Uncategorized software'); - } + $catname = $cat && $software_category->getFromDB($cat) ? $software_category->getName() : __s('Uncategorized software'); $pdf->setColumnsSize(100); $pdf->displayTitle('' . $catname . ''); $pdf->setColumnsSize(39, 9, 11, 19, 14, 8); $pdf->displayTitle( - '' . __('Name'), - __('Status'), - __('Version'), - __('License'), - __('Installation date'), - __('Valid license') . '', + '' . __s('Name'), + __s('Status'), + __s('Version'), + __s('License'), + __s('Installation date'), + __s('Valid license') . '', ); } // 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'])) { - $lic = sprintf(__('%1$s (%2$s)'), $lic, $licdata['type']); + $lic = sprintf(__s('%1$s (%2$s)'), $lic, $licdata['type']); } } @@ -361,44 +477,80 @@ 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 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') . ''); + $pdf->displayTitle('' . __s('Affected licenses of not installed software', 'pdf') . ''); $pdf->setColumnsSize(50, 13, 13, 24); - $pdf->displayTitle('' . __('Name'), __('Status'), __('Version'), __('License') . ''); + $pdf->displayTitle('' . __s('Name'), __s('Status'), __s('Version'), __s('License') . ''); $lic = ''; foreach ($req as $data) { $lic .= '' . $data['name'] . ' ' . $data['serial']; if (!empty($data['softwarelicensetypes_id'])) { $lic = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $lic, Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwarelicensetypes', diff --git a/inc/computerantivirus.class.php b/inc/computerantivirus.class.php index d1f6e13..2ad61d7 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 ?: new ItemAntivirus()); } public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) @@ -46,35 +46,35 @@ 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); $pdf->setColumnsSize(100); - $title = '' . __('Antivirus') . ''; + $title = '' . __s('Antivirus') . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(25, 20, 15, 15, 5, 5, 15); $pdf->displayTitle( - __('Name'), - __('Manufacturer'), - __('Antivirus version'), - __('Signature database version'), - __('Active'), - __('Up to date'), - __('Expiration date'), + __s('Name'), + __s('Manufacturer'), + __s('Antivirus version'), + __s('Signature database version'), + __s('Active'), + __s('Up to date'), + __s('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..5affc15 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 ?: new ItemVirtualMachine()); } public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) @@ -47,40 +47,40 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) // From ComputerVirtualMachine::showForComputer() $virtualmachines = $dbu->getAllDataFromTable( - 'glpi_computervirtualmachines', + 'glpi_itemvirtualmachines', ['computers_id' => $ID], ); $pdf->setColumnsSize(100); - $title = '' . __('List of virtualized environments') . ''; + $title = '' . __s('List of virtualized environments') . ''; $number = count($virtualmachines); - if (!$number) { - $pdf->displayTitle('' . __('No virtualized environment associated with the computer') . ''); + if ($number === 0) { + $pdf->displayTitle('' . __s('No virtualized environment associated with the computer') . ''); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(19, 11, 11, 8, 20, 8, 8, 15); $pdf->displayTitle( - __('Name'), - __('Virtualization system'), - __('Virtualization model'), - __('State'), - __('UUID'), + __s('Name'), + __s('Virtualization system'), + __s('Virtualization model'), + __s('State'), + __s('UUID'), _x('quantity', 'Processors number'), - sprintf(__('%1$s (%2$s)'), __('Memory'), __('Mio')), - __('Machine'), + sprintf(__s('%1$s (%2$s)'), __s('Memory'), __s('Mio')), + __s('Machine'), ); $pdf->setColumnsAlign('left', 'center', 'center', 'center', 'left', 'right', 'right', 'left'); 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,17 +114,17 @@ public static function pdfForComputer(PluginPdfSimplePDF $pdf, Computer $item) $item::getTable(), ['RAW' => ['LOWER(uuid)' - => ComputerVirtualMachine::getUUIDRestrictCriteria($item->fields['uuid']), + => ItemVirtualMachine::getUUIDRestrictCriteria($item->fields['uuid']), ], ], ); if (count($hosts)) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('List of virtualized environments') . ''); + $pdf->displayTitle('' . __s('List of virtualized environments') . ''); $pdf->setColumnsSize(26, 37, 37); - $pdf->displayTitle(__('Name'), __('Operating system'), __('Entity')); + $pdf->displayTitle(__s('Name'), __s('Operating system'), __s('Entity')); $computer = new Computer(); foreach ($hosts as $host) { diff --git a/inc/config.class.php b/inc/config.class.php index 302973a..7dc583b 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -79,12 +79,17 @@ public static function canView(): bool public static function getTypeName($nb = 0) { - return __('Setup'); + return __s('PDF export', 'pdf'); } public function getName($params = []) { - return __('Print to pdf', 'pdf'); + return __s('PDF exportf', 'pdf'); + } + + public static function getIcon() + { + return "ti ti-file-type-pdf"; } /** @@ -121,14 +126,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 +190,7 @@ public static function showConfigForm($item) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Config') { - return $this->getName(); + return self::createTabEntry(self::getTypeName(), 0, $item::getType(), self::getIcon()); } return ''; @@ -205,156 +208,156 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ public static function currency() { // name, symbole, currency, uniqUE - return ['AED' => [__('UAE Dirham', 'pdf'), 'د.إ', false], - 'AFN' => [__('Afghani', 'pdf'), 'Af'], - 'ALL' => [__('Lek', 'pdf'), 'L', false], - 'AMD' => [__('Armenian Dram', 'pdf'), 'Դ'], - 'AOA' => [__('Kwanza', 'pdf'), 'Kz'], - 'ARS' => [__('Argentine Peso', 'pdf'), '$', false], - 'AUD' => [__('Australian Dollar', 'pdf'), '$', false], - 'AWG' => [__('Aruban Guilder/Florin', 'pdf'), 'ƒ'], - 'AZN' => [__('Azerbaijanian Manat', 'pdf'), 'ман'], - 'BAM' => [__('Konvertibilna Marka', 'pdf'), 'КМ'], - 'BBD' => [__('Barbados Dollar', 'pdf'), '$', false], - 'BDT' => [__('Taka', 'pdf'), '৳'], - 'BGN' => [__('Bulgarian Lev', 'pdf'), 'лв'], - 'BHD' => [__('Bahraini Dinar', 'pdf'), 'ب.د'], - 'BIF' => [__('Burundi Franc', 'pdf'), '₣', false], - 'BMD' => [__('Bermudian Dollar', 'pdf'), '$', false], - 'BND' => [__('Brunei Dollar', 'pdf'), '$', false], - 'BOB' => [__('Boliviano', 'pdf'), 'Bs.'], - 'BRL' => [__('Brazilian Real', 'pdf'), 'R$'], - 'BSD' => [__('Bahamian Dollar', 'pdf'), '$', false], - 'BTN' => [__('Ngultrum', 'pdf'), ''], - 'BWP' => [__('Pula', 'pdf'), 'P', false], - 'BYR' => [__('Belarussian Ruble', 'pdf'), 'Br.'], - 'BZD' => [__('Belize Dollar', 'pdf'), '$', false], - 'CAD' => [__('Canadian Dollar', 'pdf'), '$', false], - 'CDF' => [__('Congolese Franc', 'pdf'), 'F', false], - 'CHF' => [__('Swiss Franc', 'pdf'), 'F', false], - 'CLP' => [__('Chilean Peso', 'pdf'), '$', false], - 'CNY' => [__('Yuan', 'pdf'), '¥'], - 'COP' => [__('Colombian Peso', 'pdf'), '$', false], - 'CRC' => [__('Costa Rican Colon', 'pdf'), '₡'], - 'CUP' => [__('Cuban Peso', 'pdf'), '$', false], - 'CVE' => [__('Cape Verde Escudo', 'pdf'), '$', false], - 'CZK' => [__('Czech Koruna', 'pdf'), 'Kč'], - 'DJF' => [__('Djibouti Franc', 'pdf'), '₣', false], - 'DKK' => [__('Danish Krone', 'pdf'), 'kr', false], - 'DOP' => [__('Dominican Peso', 'pdf'), '$', false], - 'DZD' => [__('Algerian Dinar', 'pdf'), 'د.ج'], - 'EGP' => [__('Egyptian Pound', 'pdf'), '£', false], - 'ERN' => [__('Nakfa', 'pdf'), 'Nfk'], - 'ETB' => [__('Ethiopian Birr', 'pdf'), ''], - 'EUR' => [__('Euro', 'pdf'), '€'], - 'FJD' => [__('Fiji Dollar', 'pdf'), '$', false], - 'FKP' => [__('Falkland Islands Pound', 'pdf'), '£', false], - 'GBP' => [__('Pound Sterling', 'pdf'), '£', false], - 'GEL' => [__('Lari', 'pdf'), 'ლ'], - 'GHS' => [__('Cedi', 'pdf'), '₵'], - 'GIP' => [__('Gibraltar Pound', 'pdf'), '£', false], - 'GMD' => [__('Dalasi', 'pdf'), 'D'], - 'GNF' => [__('Guinea Franc', 'pdf'), '₣', false], - 'GTQ' => [__('Quetzal', 'pdf'), 'Q'], - 'HKD' => [__('Hong Kong Dollar', 'pdf'), '$', false], - 'HNL' => [__('Lempira', 'pdf'), 'L', false], - 'HRK' => [__('Croatian Kuna', 'pdf'), 'Kn'], - 'HTG' => [__('Gourde', 'pdf'), 'G'], - 'HUF' => [__('Forint', 'pdf'), 'Ft'], - 'IDR' => [__('Rupiah', 'pdf'), 'Rp'], - 'ILS' => [__('New Israeli Shekel', 'pdf'), '₪'], - 'INR' => [__('Indian Rupee', 'pdf'), '₨', false], - 'IQD' => [__('Iraqi Dinar', 'pdf'), 'ع.د'], - 'IRR' => [__('Iranian Rial', 'pdf'), '﷼'], - 'ISK' => [__('Iceland Krona', 'pdf'), 'Kr', false], - 'JMD' => [__('Jamaican Dollar', 'pdf'), '$', false], - 'JOD' => [__('Jordanian Dinar', 'pdf'), 'د.ا', false], - 'JPY' => [__('Yen', 'pdf'), '¥'], - 'KES' => [__('Kenyan Shilling', 'pdf'), 'Sh', false], - 'KGS' => [__('Som', 'pdf'), ''], - 'KHR' => [__('Riel', 'pdf'), '៛'], - 'KPW' => [__('North Korean Won', 'pdf'), '₩', false], - 'KRW' => [__('South Korean Won', 'pdf'), '₩', false], - 'KWD' => [__('Kuwaiti Dinar', 'pdf'), 'د.ك'], - 'KYD' => [__('Cayman Islands Dollar', 'pdf'), '$', false], - 'KZT' => [__('Tenge', 'pdf'), '〒'], - 'LAK' => [__('Kip', 'pdf'), '₭'], - 'LBP' => [__('Lebanese Pound', 'pdf'), '£L'], - 'LKR' => [__('Sri Lanka Rupee', 'pdf'), 'Rs'], - 'LRD' => [__('Liberian Dollar', 'pdf'), '$', false], - 'LSL' => [__('Loti', 'pdf'), 'L', false], - 'LYD' => [__('Libyan Dinar', 'pdf'), 'ل.د'], - 'MAD' => [__('Moroccan Dirham', 'pdf'), 'د.م.'], - 'MDL' => [__('Moldavian Leu', 'pdf'), 'L', false], - 'MGA' => [__('Malagasy Ariary', 'pdf'), ''], - 'MKD' => [__('Denar', 'pdf'), 'ден'], - 'MMK' => [__('Kyat', 'pdf'), 'K', false], - 'MNT' => [__('Tugrik', 'pdf'), '₮'], - 'MOP' => [__('Pataca', 'pdf'), 'P', false], - 'MRO' => [__('Ouguiya', 'pdf'), 'UM'], - 'MUR' => [__('Mauritius Rupee', 'pdf'), '₨', false], - 'MVR' => [__('Rufiyaa', 'pdf'), 'ރ.'], - 'MWK' => [__('Kwacha', 'pdf'), 'MK'], - 'MXN' => [__('Mexican Peso', 'pdf'), '$', false], - 'MYR' => [__('Malaysian Ringgit', 'pdf'), 'RM'], - 'MZN' => [__('Metical', 'pdf'), 'MTn'], - 'NAD' => [__('Namibia Dollar', 'pdf'), '$', false], - 'NGN' => [__('Naira', 'pdf'), '₦'], - 'NIO' => [__('Cordoba Oro', 'pdf'), 'C$'], - 'NOK' => [__('Norwegian Krone', 'pdf'), 'kr', false], - 'NPR' => [__('Nepalese Rupee', 'pdf'), '₨', false], - 'NZD' => [__('New Zealand Dollar', 'pdf'), '$', false], - 'OMR' => [__('Rial Omani', 'pdf'), 'ر.ع.'], - 'PAB' => [__('Balboa', 'pdf'), 'B/.'], - 'PEN' => [__('Nuevo Sol', 'pdf'), 'S/.'], - 'PGK' => [__('Kina', 'pdf'), 'K', false], - 'PHP' => [__('Philippine Peso', 'pdf'), '₱'], - 'PKR' => [__('Pakistan Rupee', 'pdf'), '₨', false], - 'PLN' => [__('PZloty', 'pdf'), 'zł'], - 'PYG' => [__('Guarani', 'pdf'), '₲'], - 'QAR' => [__('Qatari Rial', 'pdf'), 'ر.ق'], - 'RON' => [__('Leu', 'pdf'), 'L', false], - 'RSD' => [__('Serbian Dinar', 'pdf'), 'din'], - 'RUB' => [__('Russian Ruble', 'pdf'), 'р.'], - 'RWF' => [__('Rwanda Franc', 'pdf'), 'F', false], - 'SAR' => [__('Saudi Riyal', 'pdf'), 'ر.س '], - 'SBD' => [__('Solomon Islands Dollar', 'pdf'), '$', false], - 'SCR' => [__('Seychelles Rupee', 'pdf'), '₨', false], - 'SDG' => [__('Sudanese', 'pdf'), '£', false], - 'SEK' => [__('Swedish Krona', 'pdf'), 'kr', false], - 'SGD' => [__('Singapore Dollar', 'pdf'), '$', false], - 'SHP' => [__('Saint Helena Pound', 'pdf'), '£', false], - 'SLL' => [__('leone', 'pdf'), 'Le'], - 'SOS' => [__('Somali Shilling', 'pdf'), 'Sh', false], - 'SRD' => [__('Suriname Dollar', 'pdf'), '$', false], - 'STD' => [__('Dobra', 'pdf'), 'Db'], - 'SYP' => [__('Syrian Pound', 'pdf'), 'ل.س'], - 'SZL' => [__('Lilangeni', 'pdf'), 'L', false], - 'THB' => [__('Baht', 'pdf'), '฿'], - 'TJS' => [__('Somoni', 'pdf'), 'ЅМ'], - 'TMT' => [__('Manat', 'pdf'), 'm'], - 'TND' => [__('Tunisian Dinar', 'pdf'), 'د.ت'], - 'TOP' => [__('Pa’anga', 'pdf'), 'T$'], - 'TRY' => [__('Turkish Lira', 'pdf'), '₤', false], - 'TTD' => [__('Trinidad and Tobago Dollar', 'pdf'), '$', false], - 'TWD' => [__('Taiwan Dollar', 'pdf'), '$', false], - 'TZS' => [__('Tanzanian Shilling', 'pdf'), 'Sh', false], - 'UAH' => [__('Hryvnia', 'pdf'), '₴'], - 'UGX' => [__('Uganda Shilling', 'pdf'), 'Sh', false], - 'USD' => [__('US Dollar', 'pdf'), '$', false], - 'UYU' => [__('Peso Uruguayo', 'pdf'), '$', false], - 'UZS' => [__('Uzbekistan Sum', 'pdf'), ''], - 'VEF' => [__('Bolivar Fuerte', 'pdf'), 'Bs F'], - 'VND' => [__('Dong', 'pdf'), '₫'], - 'VUV' => [__('Vatu', 'pdf'), 'Vt'], - 'WST' => [__('Tala', 'pdf'), 'T'], - 'XAF' => [__('CFA Franc BCEAO', 'pdf'), '₣', false], - 'XCD' => [__('East Caribbean Dollar', 'pdf'), '$', false], - 'XPF' => [__('CFP Franc', 'pdf'), '₣', false], - 'YER' => [__('Yemeni Rial', 'pdf'), '﷼'], - 'ZAR' => [__('Rand', 'pdf'), 'R'], - 'ZMW' => [__('Zambian Kwacha', 'pdf'), 'ZK'], - 'ZWL' => [__('Zimbabwe Dollar', 'pdf'), '$', false]]; + return ['AED' => [__s('UAE Dirham', 'pdf'), 'د.إ', false], + 'AFN' => [__s('Afghani', 'pdf'), 'Af'], + 'ALL' => [__s('Lek', 'pdf'), 'L', false], + 'AMD' => [__s('Armenian Dram', 'pdf'), 'Դ'], + 'AOA' => [__s('Kwanza', 'pdf'), 'Kz'], + 'ARS' => [__s('Argentine Peso', 'pdf'), '$', false], + 'AUD' => [__s('Australian Dollar', 'pdf'), '$', false], + 'AWG' => [__s('Aruban Guilder/Florin', 'pdf'), 'ƒ'], + 'AZN' => [__s('Azerbaijanian Manat', 'pdf'), 'ман'], + 'BAM' => [__s('Konvertibilna Marka', 'pdf'), 'КМ'], + 'BBD' => [__s('Barbados Dollar', 'pdf'), '$', false], + 'BDT' => [__s('Taka', 'pdf'), '৳'], + 'BGN' => [__s('Bulgarian Lev', 'pdf'), 'лв'], + 'BHD' => [__s('Bahraini Dinar', 'pdf'), 'ب.د'], + 'BIF' => [__s('Burundi Franc', 'pdf'), '₣', false], + 'BMD' => [__s('Bermudian Dollar', 'pdf'), '$', false], + 'BND' => [__s('Brunei Dollar', 'pdf'), '$', false], + 'BOB' => [__s('Boliviano', 'pdf'), 'Bs.'], + 'BRL' => [__s('Brazilian Real', 'pdf'), 'R$'], + 'BSD' => [__s('Bahamian Dollar', 'pdf'), '$', false], + 'BTN' => [__s('Ngultrum', 'pdf'), ''], + 'BWP' => [__s('Pula', 'pdf'), 'P', false], + 'BYR' => [__s('Belarussian Ruble', 'pdf'), 'Br.'], + 'BZD' => [__s('Belize Dollar', 'pdf'), '$', false], + 'CAD' => [__s('Canadian Dollar', 'pdf'), '$', false], + 'CDF' => [__s('Congolese Franc', 'pdf'), 'F', false], + 'CHF' => [__s('Swiss Franc', 'pdf'), 'F', false], + 'CLP' => [__s('Chilean Peso', 'pdf'), '$', false], + 'CNY' => [__s('Yuan', 'pdf'), '¥'], + 'COP' => [__s('Colombian Peso', 'pdf'), '$', false], + 'CRC' => [__s('Costa Rican Colon', 'pdf'), '₡'], + 'CUP' => [__s('Cuban Peso', 'pdf'), '$', false], + 'CVE' => [__s('Cape Verde Escudo', 'pdf'), '$', false], + 'CZK' => [__s('Czech Koruna', 'pdf'), 'Kč'], + 'DJF' => [__s('Djibouti Franc', 'pdf'), '₣', false], + 'DKK' => [__s('Danish Krone', 'pdf'), 'kr', false], + 'DOP' => [__s('Dominican Peso', 'pdf'), '$', false], + 'DZD' => [__s('Algerian Dinar', 'pdf'), 'د.ج'], + 'EGP' => [__s('Egyptian Pound', 'pdf'), '£', false], + 'ERN' => [__s('Nakfa', 'pdf'), 'Nfk'], + 'ETB' => [__s('Ethiopian Birr', 'pdf'), ''], + 'EUR' => [__s('Euro', 'pdf'), '€'], + 'FJD' => [__s('Fiji Dollar', 'pdf'), '$', false], + 'FKP' => [__s('Falkland Islands Pound', 'pdf'), '£', false], + 'GBP' => [__s('Pound Sterling', 'pdf'), '£', false], + 'GEL' => [__s('Lari', 'pdf'), 'ლ'], + 'GHS' => [__s('Cedi', 'pdf'), '₵'], + 'GIP' => [__s('Gibraltar Pound', 'pdf'), '£', false], + 'GMD' => [__s('Dalasi', 'pdf'), 'D'], + 'GNF' => [__s('Guinea Franc', 'pdf'), '₣', false], + 'GTQ' => [__s('Quetzal', 'pdf'), 'Q'], + 'HKD' => [__s('Hong Kong Dollar', 'pdf'), '$', false], + 'HNL' => [__s('Lempira', 'pdf'), 'L', false], + 'HRK' => [__s('Croatian Kuna', 'pdf'), 'Kn'], + 'HTG' => [__s('Gourde', 'pdf'), 'G'], + 'HUF' => [__s('Forint', 'pdf'), 'Ft'], + 'IDR' => [__s('Rupiah', 'pdf'), 'Rp'], + 'ILS' => [__s('New Israeli Shekel', 'pdf'), '₪'], + 'INR' => [__s('Indian Rupee', 'pdf'), '₨', false], + 'IQD' => [__s('Iraqi Dinar', 'pdf'), 'ع.د'], + 'IRR' => [__s('Iranian Rial', 'pdf'), '﷼'], + 'ISK' => [__s('Iceland Krona', 'pdf'), 'Kr', false], + 'JMD' => [__s('Jamaican Dollar', 'pdf'), '$', false], + 'JOD' => [__s('Jordanian Dinar', 'pdf'), 'د.ا', false], + 'JPY' => [__s('Yen', 'pdf'), '¥'], + 'KES' => [__s('Kenyan Shilling', 'pdf'), 'Sh', false], + 'KGS' => [__s('Som', 'pdf'), ''], + 'KHR' => [__s('Riel', 'pdf'), '៛'], + 'KPW' => [__s('North Korean Won', 'pdf'), '₩', false], + 'KRW' => [__s('South Korean Won', 'pdf'), '₩', false], + 'KWD' => [__s('Kuwaiti Dinar', 'pdf'), 'د.ك'], + 'KYD' => [__s('Cayman Islands Dollar', 'pdf'), '$', false], + 'KZT' => [__s('Tenge', 'pdf'), '〒'], + 'LAK' => [__s('Kip', 'pdf'), '₭'], + 'LBP' => [__s('Lebanese Pound', 'pdf'), '£L'], + 'LKR' => [__s('Sri Lanka Rupee', 'pdf'), 'Rs'], + 'LRD' => [__s('Liberian Dollar', 'pdf'), '$', false], + 'LSL' => [__s('Loti', 'pdf'), 'L', false], + 'LYD' => [__s('Libyan Dinar', 'pdf'), 'ل.د'], + 'MAD' => [__s('Moroccan Dirham', 'pdf'), 'د.م.'], + 'MDL' => [__s('Moldavian Leu', 'pdf'), 'L', false], + 'MGA' => [__s('Malagasy Ariary', 'pdf'), ''], + 'MKD' => [__s('Denar', 'pdf'), 'ден'], + 'MMK' => [__s('Kyat', 'pdf'), 'K', false], + 'MNT' => [__s('Tugrik', 'pdf'), '₮'], + 'MOP' => [__s('Pataca', 'pdf'), 'P', false], + 'MRO' => [__s('Ouguiya', 'pdf'), 'UM'], + 'MUR' => [__s('Mauritius Rupee', 'pdf'), '₨', false], + 'MVR' => [__s('Rufiyaa', 'pdf'), 'ރ.'], + 'MWK' => [__s('Kwacha', 'pdf'), 'MK'], + 'MXN' => [__s('Mexican Peso', 'pdf'), '$', false], + 'MYR' => [__s('Malaysian Ringgit', 'pdf'), 'RM'], + 'MZN' => [__s('Metical', 'pdf'), 'MTn'], + 'NAD' => [__s('Namibia Dollar', 'pdf'), '$', false], + 'NGN' => [__s('Naira', 'pdf'), '₦'], + 'NIO' => [__s('Cordoba Oro', 'pdf'), 'C$'], + 'NOK' => [__s('Norwegian Krone', 'pdf'), 'kr', false], + 'NPR' => [__s('Nepalese Rupee', 'pdf'), '₨', false], + 'NZD' => [__s('New Zealand Dollar', 'pdf'), '$', false], + 'OMR' => [__s('Rial Omani', 'pdf'), 'ر.ع.'], + 'PAB' => [__s('Balboa', 'pdf'), 'B/.'], + 'PEN' => [__s('Nuevo Sol', 'pdf'), 'S/.'], + 'PGK' => [__s('Kina', 'pdf'), 'K', false], + 'PHP' => [__s('Philippine Peso', 'pdf'), '₱'], + 'PKR' => [__s('Pakistan Rupee', 'pdf'), '₨', false], + 'PLN' => [__s('PZloty', 'pdf'), 'zł'], + 'PYG' => [__s('Guarani', 'pdf'), '₲'], + 'QAR' => [__s('Qatari Rial', 'pdf'), 'ر.ق'], + 'RON' => [__s('Leu', 'pdf'), 'L', false], + 'RSD' => [__s('Serbian Dinar', 'pdf'), 'din'], + 'RUB' => [__s('Russian Ruble', 'pdf'), 'р.'], + 'RWF' => [__s('Rwanda Franc', 'pdf'), 'F', false], + 'SAR' => [__s('Saudi Riyal', 'pdf'), 'ر.س '], + 'SBD' => [__s('Solomon Islands Dollar', 'pdf'), '$', false], + 'SCR' => [__s('Seychelles Rupee', 'pdf'), '₨', false], + 'SDG' => [__s('Sudanese', 'pdf'), '£', false], + 'SEK' => [__s('Swedish Krona', 'pdf'), 'kr', false], + 'SGD' => [__s('Singapore Dollar', 'pdf'), '$', false], + 'SHP' => [__s('Saint Helena Pound', 'pdf'), '£', false], + 'SLL' => [__s('leone', 'pdf'), 'Le'], + 'SOS' => [__s('Somali Shilling', 'pdf'), 'Sh', false], + 'SRD' => [__s('Suriname Dollar', 'pdf'), '$', false], + 'STD' => [__s('Dobra', 'pdf'), 'Db'], + 'SYP' => [__s('Syrian Pound', 'pdf'), 'ل.س'], + 'SZL' => [__s('Lilangeni', 'pdf'), 'L', false], + 'THB' => [__s('Baht', 'pdf'), '฿'], + 'TJS' => [__s('Somoni', 'pdf'), 'ЅМ'], + 'TMT' => [__s('Manat', 'pdf'), 'm'], + 'TND' => [__s('Tunisian Dinar', 'pdf'), 'د.ت'], + 'TOP' => [__s('Pa’anga', 'pdf'), 'T$'], + 'TRY' => [__s('Turkish Lira', 'pdf'), '₤', false], + 'TTD' => [__s('Trinidad and Tobago Dollar', 'pdf'), '$', false], + 'TWD' => [__s('Taiwan Dollar', 'pdf'), '$', false], + 'TZS' => [__s('Tanzanian Shilling', 'pdf'), 'Sh', false], + 'UAH' => [__s('Hryvnia', 'pdf'), '₴'], + 'UGX' => [__s('Uganda Shilling', 'pdf'), 'Sh', false], + 'USD' => [__s('US Dollar', 'pdf'), '$', false], + 'UYU' => [__s('Peso Uruguayo', 'pdf'), '$', false], + 'UZS' => [__s('Uzbekistan Sum', 'pdf'), ''], + 'VEF' => [__s('Bolivar Fuerte', 'pdf'), 'Bs F'], + 'VND' => [__s('Dong', 'pdf'), '₫'], + 'VUV' => [__s('Vatu', 'pdf'), 'Vt'], + 'WST' => [__s('Tala', 'pdf'), 'T'], + 'XAF' => [__s('CFA Franc BCEAO', 'pdf'), '₣', false], + 'XCD' => [__s('East Caribbean Dollar', 'pdf'), '$', false], + 'XPF' => [__s('CFP Franc', 'pdf'), '₣', false], + 'YER' => [__s('Yemeni Rial', 'pdf'), '﷼'], + 'ZAR' => [__s('Rand', 'pdf'), 'R'], + 'ZMW' => [__s('Zambian Kwacha', 'pdf'), 'ZK'], + 'ZWL' => [__s('Zimbabwe Dollar', 'pdf'), '$', false]]; } public static function formatNumber($value) @@ -393,12 +396,9 @@ public static function currencyName() global $PDF_DEVICES; $config = self::getInstance(); - $name = ''; foreach ($PDF_DEVICES as $option => $value) { - if ($config->getField('currency') == $option) { - if (isset($value[2])) { - return $value[0]; - } + if ($config->getField('currency') == $option && isset($value[2])) { + return $value[0]; } } } diff --git a/inc/consumableitem.class.php b/inc/consumableitem.class.php index 74df805..991a641 100644 --- a/inc/consumableitem.class.php +++ b/inc/consumableitem.class.php @@ -36,7 +36,7 @@ class PluginPdfConsumableItem extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new CartridgeItem()); + $this->obj = ($obj ?: new CartridgeItem()); } public function defineAllTabsPDF($options = []) @@ -53,10 +53,10 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem PluginPdfCommon::mainTitle($pdf, $consitem); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Name') . '', $consitem->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Name') . '', $consitem->fields['name']), '' . sprintf( - __('%1$s: %2$s'), - __('Type') . '', + __s('%1$s: %2$s'), + __s('Type') . '
', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_consumableitemtypes', $consitem->fields['consumableitemtypes_id'], @@ -64,10 +64,10 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem ), ); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Reference') . '', $consitem->fields['ref']), + '' . sprintf(__s('%1$s: %2$s'), __s('Reference') . '', $consitem->fields['ref']), '' . sprintf( - __('%1$s: %2$s'), - __('Manufacturer') . '', + __s('%1$s: %2$s'), + __s('Manufacturer') . '
', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_manufacturers', $consitem->fields['manufacturers_id'], @@ -77,13 +77,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Technician in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Technician in charge of the hardware') . '', $dbu->getUserName($consitem->fields['users_id_tech']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Group in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Group in charge of the hardware') . '', Dropdown::getDropdownName( 'glpi_groups', $consitem->fields['groups_id_tech'], @@ -93,24 +93,24 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Stock location') . '', + __s('%1$s: %2$s'), + __s('Stock location') . '', Dropdown::getDropdownName( 'glpi_locations', $consitem->fields['locations_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Alert threshold') . '', + __s('%1$s: %2$s'), + __s('Alert threshold') . '', $consitem->getField('alarm_threshold'), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Inventory number') . '', + __s('%1$s: %2$s'), + __s('Inventory number') . '', $consitem->fields['otherserial'], ), ); @@ -161,54 +161,53 @@ public static function pdfForConsumableItem(PluginPdfSimplePDF $pdf, ConsumableI $number = $dbu->countElementsInTable('glpi_consumables', $where); $iterator = $DB->request( - 'glpi_consumables', - ['WHERE' => $where, + ['FROM' => 'glpi_consumables'] + ['WHERE' => $where, 'ORDER' => $order], ); if (!$number) { $pdf->setColumnsSize(100); - $pdf->displayTitle(__('No consumable')); + $pdf->displayTitle(__s('No consumable')); } else { if (!$show_old) { $pdf->setColumnsSize(50, 50); $pdf->displayTitle( '' . sprintf( - __('%1$s: %2$s'), - __('Total'), + __s('%1$s: %2$s'), + __s('Total'), Consumable::getTotalNumber($instID), ) . '', '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _nx('consumable', 'New', 'New', $instID), Consumable::getUnusedNumber($instID), ) . '', ); $pdf->displayTitle('', '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _nx('consumable', 'Used', 'Used', $instID), Consumable::getOldNumber($instID), )); } else { // Old $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Used consumables') . ''); + $pdf->displayTitle('' . __s('Used consumables') . ''); } if (!$show_old) { $pdf->setColumnsSize(10, 45, 45); $pdf->displayLine( - '' . __('ID') . '', + '' . __s('ID') . '', '' . _x('item', 'State') . '', - '' . __('Add date') . '', + '' . __s('Add date') . '', ); } else { $pdf->setColumnsSize(8, 23, 23, 23, 23); $pdf->displayLine( - '' . __('ID') . '', + '' . __s('ID') . '', '' . _x('item', 'State') . '', - '' . __('Add date') . '', - '' . __('Use date') . '', - '' . __('Given to') . '', + '' . __s('Add date') . '', + '' . __s('Use date') . '', + '' . __s('Given to') . '', ); } @@ -221,10 +220,8 @@ public static function pdfForConsumableItem(PluginPdfSimplePDF $pdf, ConsumableI $pdf->displayLine($data['id'], Consumable::getStatus($data['id']), $date_in); } else { $name = ''; - if ($item = getItemForItemtype($data['itemtype'])) { - if ($item->getFromDB($data['items_id'])) { - $name = $item->getNameID(); - } + if (($item = getItemForItemtype($data['itemtype'])) && $item->getFromDB($data['items_id'])) { + $name = $item->getNameID(); } $pdf->setColumnsSize(8, 23, 23, 23, 23); $pdf->displayLine( diff --git a/inc/contract.class.php b/inc/contract.class.php index 3461060..c44664a 100644 --- a/inc/contract.class.php +++ b/inc/contract.class.php @@ -36,7 +36,7 @@ class PluginPdfContract extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Contract()); + $this->obj = ($obj ?: new Contract()); } public function defineAllTabsPDF($options = []) @@ -49,15 +49,13 @@ public function defineAllTabsPDF($options = []) public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) { - $dbu = new DbUtils(); - PluginPdfCommon::mainTitle($pdf, $contract); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Name') . '', $contract->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Name') . '', $contract->fields['name']), '' . sprintf( - __('%1$s: %2$s'), - __('Status') . '', + __s('%1$s: %2$s'), + __s('Status') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_states', $contract->fields['states_id'], @@ -67,15 +65,15 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Contract type') . '', + __s('%1$s: %2$s'), + __s('Contract type') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_contracttypes', $contract->fields['contracttypes_id'], )), ), '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('phone', 'Number') . '', $contract->fields['num'], ), @@ -84,7 +82,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) $textduration = ''; if (!empty($contract->fields['begin_date'])) { $textduration = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), ' -> ', Infocom::getWarrantyExpir( $contract->fields['begin_date'], @@ -94,15 +92,15 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Start date') . '', + __s('%1$s: %2$s'), + __s('Start date') . '', Html::convDate($contract->fields['begin_date']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Initial contract period') . '', + __s('%1$s: %2$s'), + __s('Initial contract period') . '', sprintf( - _n('%d month', '%d months', $contract->fields['duration']), + _sn('%d month', '%d months', $contract->fields['duration']), $contract->fields['duration'], ) . $textduration, ), @@ -110,7 +108,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) if (!empty($contract->fields['begin_date']) && ($contract->fields['notice'] > 0)) { $textduration = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), ' -> ', Infocom::getWarrantyExpir( $contract->fields['begin_date'], @@ -121,34 +119,34 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Notice') . '', + __s('%1$s: %2$s'), + __s('Notice') . '', sprintf( - _n('%d month', '%d months', $contract->fields['notice']), + _sn('%d month', '%d months', $contract->fields['notice']), $contract->fields['notice'], ) . $textduration, ), '' . sprintf( - __('%1$s: %2$s'), - __('Account number') . '', + __s('%1$s: %2$s'), + __s('Account number') . '', $contract->fields['accounting_number'], ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Contract renewal period') . '', + __s('%1$s: %2$s'), + __s('Contract renewal period') . '', sprintf( - _n('%d month', '%d months', $contract->fields['periodicity']), + _sn('%d month', '%d months', $contract->fields['periodicity']), $contract->fields['periodicity'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Invoice period') . '', + __s('%1$s: %2$s'), + __s('Invoice period') . '', sprintf( - _n('%d month', '%d months', $contract->fields['billing']), + _sn('%d month', '%d months', $contract->fields['billing']), $contract->fields['billing'], ), ), @@ -156,13 +154,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Renewal') . '', + __s('%1$s: %2$s'), + __s('Renewal') . '', Contract::getContractRenewalName($contract->fields['renewal']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Max number of items') . '', + __s('%1$s: %2$s'), + __s('Max number of items') . '', $contract->fields['max_links_allowed'], ), ); @@ -170,8 +168,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Contract $contract) if (Entity::getUsedConfig('use_contracts_alert', $contract->fields['entities_id'])) { $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Email alarms') . '', + __s('%1$s: %2$s'), + __s('Email alarms') . '', ($contract->fields['alert'] > 0) ? $contract->fields['alert'] : '', ), ); @@ -215,12 +213,12 @@ public static function pdfCost(PluginPdfSimplePDF $pdf, Contract $contract) $number = count($result); - if (!$number) { + if ($number === 0) { $pdf->setColumnsSize(100); $pdf->displayTitle(sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), '' . ContractCost::getTypeName(2) . '', - __('No item to display'), + __s('No item to display'), )); } else { $pdf->setColumnsSize(100); @@ -230,11 +228,11 @@ public static function pdfCost(PluginPdfSimplePDF $pdf, Contract $contract) $pdf->setColumnsAlign('left', 'center', 'center', 'left', 'right'); $pdf->displayTitle( - '' . __('Name') . '', - '' . __('Begin date') . '', - '' . __('End date') . '', + '' . __s('Name') . '', + '' . __s('Begin date') . '', + '' . __s('End date') . '', '' . Budget::getTypeName(1) . '', - '' . _n('Cost', 'Costs', 1) . '', + '' . _sn('Cost', 'Costs', 1) . '', ); $total = 0; @@ -255,7 +253,7 @@ public static function pdfCost(PluginPdfSimplePDF $pdf, Contract $contract) $pdf->setColumnsSize(81, 19); $pdf->setColumnsAlign('right', 'right'); $pdf->displayLine( - '' . __('Total cost') . '', + '' . __s('Total cost') . '', '' . PluginPdfConfig::formatNumber($total) . '', ); } diff --git a/inc/contract_item.class.php b/inc/contract_item.class.php index daa8366..ed33e58 100644 --- a/inc/contract_item.class.php +++ b/inc/contract_item.class.php @@ -36,7 +36,7 @@ class PluginPdfContract_Item extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Contract_Item()); + $this->obj = ($obj ?: new Contract_Item()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -46,7 +46,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $type = $item->getType(); $ID = $item->getField('id'); - $itemtable = getTableForItemType($type); + getTableForItemType($type); $con = new Contract(); $dbu = new DbUtils(); @@ -64,21 +64,21 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $number = count($result); $pdf->setColumnsSize(100); - $title = '' . _n('Associated contract', 'Associated contracts', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('Associated contract', 'Associated contracts', $number) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, $number)); + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, $number)); $pdf->setColumnsSize(19, 19, 15, 10, 16, 11, 10); $pdf->displayTitle( - __('Name'), - __('Entity'), + __s('Name'), + __s('Entity'), _x('phone', 'Number'), - __('Contract type'), - __('Supplier'), - __('Start date'), - __('Initial contract period'), + __s('Contract type'), + __s('Supplier'), + __s('Start date'), + __s('Initial contract period'), ); foreach ($result as $row) { @@ -89,7 +89,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $textduration = ''; if ($con->fields['duration'] > 0) { $textduration = sprintf( - __('Valid to %s'), + __s('Valid to %s'), Infocom::getWarrantyExpir( $con->fields['begin_date'], $con->fields['duration'], @@ -107,9 +107,9 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) str_replace('
', ' ', $con->getSuppliersNames()), Html::convDate($con->fields['begin_date']), sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), sprintf( - _n('%d month', '%d months', $con->fields['duration']), + _sn('%d month', '%d months', $con->fields['duration']), $con->fields['duration'], ), $textduration, @@ -202,22 +202,22 @@ public static function pdfForContract(PluginPdfSimplePDF $pdf, Contract $contrac } $pdf->setColumnsSize(100); - $title = '' . _n('Item', 'Items', $number) . ''; + $title = '' . _sn('Item', 'Items', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); $pdf->setColumnsSize(15, 18, 29, 15, 15, 8); $pdf->displayTitle( - '' . __('Type') . '', - '' . __('Name') . '', - '' . __('Entity') . '', - '' . __('Serial number') . '', - '' . __('Inventory number') . '', - '' . __('Status') . '', + '' . __s('Type') . '', + '' . __s('Name') . '', + '' . __s('Entity') . '', + '' . __s('Serial number') . '', + '' . __s('Inventory number') . '', + '' . __s('Status') . '', ); $totalnb = 0; @@ -228,20 +228,20 @@ public static function pdfForContract(PluginPdfSimplePDF $pdf, Contract $contrac $prem = true; $nb = count($datas); foreach ($datas as $objdata) { - $item = new $itemtype(); - if ($item instanceof Item_Devices) { - $name = $objdata['name_device']; - } else { - $name = $objdata['name']; + $dbu = new DbUtils(); + $item = $dbu->getItemForItemtype($itemtype); + if (!$item) { + continue; } + $name = $item instanceof Item_Devices ? $objdata['name_device'] : $objdata['name']; if (empty($data['name'])) { - $name = sprintf(__('%1$s (%2$s)'), $name, $objdata['id']); + $name = sprintf(__s('%1$s (%2$s)'), $name, $objdata['id']); } if ($prem) { $typename = $item->getTypeName($nb); $pdf->displayLine( - Toolbox::stripTags(sprintf(__('%1$s: %2$s'), $typename, $nb)), + Toolbox::stripTags(sprintf(__s('%1$s: %2$s'), $typename, $nb)), Toolbox::stripTags($name), Dropdown::getDropdownName('glpi_entities', $objdata['entity']), Toolbox::stripTags((isset($objdata['serial']) diff --git a/inc/document.class.php b/inc/document.class.php index 1b45280..418cd12 100644 --- a/inc/document.class.php +++ b/inc/document.class.php @@ -36,7 +36,7 @@ class PluginPdfDocument extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Document()); + $this->obj = ($obj ?: new Document()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -48,8 +48,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $type = get_class($item); $result = $DB->request( - 'glpi_documents_items', - ['SELECT' => ['glpi_documents_items.id', + ['FROM' => 'glpi_documents_items'] + ['SELECT' => ['glpi_documents_items.id', 'glpi_documents_items.date_mod', 'glpi_documents.*', 'glpi_entities.id', 'completename'], @@ -67,27 +66,27 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $number = count($result); $pdf->setColumnsSize(100); - $title = '' . _n('Document', 'Documents', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('Document', 'Documents', $number) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(20, 15, 10, 10, 10, 8, 20, 7); $pdf->displayTitle( - __('Name'), - __('Entity'), - __('File'), - __('Web link'), - __('Heading'), - __('MIME type'), - __('Tag'), - __('Date'), + __s('Name'), + __s('Entity'), + __s('File'), + __s('Web link'), + __s('Heading'), + __s('MIME type'), + __s('Tag'), + __s('Date'), ); foreach ($result as $data) { if (empty($data['link'])) { diff --git a/inc/domain_item.class.php b/inc/domain_item.class.php index 4cfd664..22e5456 100644 --- a/inc/domain_item.class.php +++ b/inc/domain_item.class.php @@ -36,7 +36,7 @@ class PluginPdfDomain_Item extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Domain_Item()); + $this->obj = ($obj ?: new Domain_Item()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -62,26 +62,26 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); $title = '' . Domain::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(17, 15, 10, 10, 8, 8, 16, 16); $pdf->displayTitle( - __('Name'), - __('Entity'), - __('Group in charge'), - __('Technician in charge'), - __('Type'), - __('Domain relation'), - __('Creation date'), - __('Expiration date'), + __s('Name'), + __s('Entity'), + __s('Group in charge'), + __s('Technician in charge'), + __s('Type'), + __s('Domain relation'), + __s('Creation date'), + __s('Expiration date'), ); foreach ($result as $data) { diff --git a/inc/group.class.php b/inc/group.class.php index cd824bc..5b7e82c 100644 --- a/inc/group.class.php +++ b/inc/group.class.php @@ -36,84 +36,84 @@ class PluginPdfGroup extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Group()); + $this->obj = ($obj ?: new Group()); } public static function pdfMain(PluginPdfSimplePDF $pdf, Group $item) { - $ID = $item->getField('id'); + $item->getField('id'); $pdf->setColumnsSize(50, 50); $pdf->displayTitle( - '' . sprintf(__('%1$s %2$s'), __('ID'), $item->fields['id']) . '', + '' . sprintf(__s('%1$s %2$s'), __s('ID'), $item->fields['id']) . '', sprintf( - __('%1$s: %2$s'), - __('Last update'), + __s('%1$s: %2$s'), + __s('Last update'), Html::convDateTime($item->fields['date_mod']), ), ); $pdf->setColumnsSize(100); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Complete name') . '', + __s('%1$s: %2$s'), + __s('Complete name') . '', $item->fields['completename'], )); $pdf->setColumnsAlign('center'); - $pdf->displayLine('' . sprintf(__('%1$s: %2$s'), __('Visible in a ticket'), '' . '')); + $pdf->displayLine('' . sprintf(__s('%1$s: %2$s'), __s('Visible in a ticket'), '' . '')); $pdf->setColumnsSize(20, 20, 20, 20, 20); $pdf->displayLine( '' . sprintf( - __('%1$s - %2$s'), - __('Requester') . '', + __s('%1$s - %2$s'), + __s('Requester') . '', Dropdown::getYesNo($item->fields['is_requester']), ), '' . sprintf( - __('%1$s - %2$s'), - __('Watcher') . '', + __s('%1$s - %2$s'), + __s('Watcher') . '', Dropdown::getYesNo($item->fields['is_watcher']), ), '' . sprintf( - __('%1$s - %2$s'), - __('Assigned to') . '', + __s('%1$s - %2$s'), + __s('Assigned to') . '', Dropdown::getYesNo($item->fields['is_assign']), ), '' . sprintf( - __('%1$s - %2$s'), - __('Task') . '', + __s('%1$s - %2$s'), + __s('Task') . '', Dropdown::getYesNo($item->fields['is_task']), ), '' . sprintf( - __('%1$s - %2$s'), - __('Can be notified') . '', + __s('%1$s - %2$s'), + __s('Can be notified') . '', Dropdown::getYesNo($item->fields['is_notify']), ), ); $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $pdf->displayLine('' . sprintf(__('%1$s: %2$s'), __('Visible in a project'), '')); + $pdf->displayLine('' . sprintf(__s('%1$s: %2$s'), __s('Visible in a project'), '')); $pdf->setColumnsAlign('left'); $pdf->displayLine('' . sprintf( - __('%1$s - %2$s'), - __('Can be manager') . '', + __s('%1$s - %2$s'), + __s('Can be manager') . '', Dropdown::getYesNo($item->fields['is_manager']), )); $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $pdf->displayLine('' . sprintf(__('%1$s: %2$s'), __('Can contain'), '')); + $pdf->displayLine('' . sprintf(__s('%1$s: %2$s'), __s('Can contain'), '')); $pdf->setColumnsSize(50, 50); $pdf->displayLine( '' . sprintf( - __('%1$s - %2$s'), - _n('Item', 'Items', 2) . '', + __s('%1$s - %2$s'), + _sn('Item', 'Items', 2) . '', Dropdown::getYesNo($item->fields['is_itemgroup']), ), '' . sprintf( - __('%1$s - %2$s'), - _n('User', 'Users', 2) . '', + __s('%1$s - %2$s'), + _sn('User', 'Users', 2) . '', Dropdown::getYesNo($item->fields['is_usergroup']), ), ); @@ -128,22 +128,22 @@ public static function pdfLdapForm(PluginPdfSimplePDF $pdf, Group $item) { if (Session::haveRight('config', READ) && AuthLDAP::useAuthLdap()) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('LDAP directory link') . ''); + $pdf->displayTitle('' . __s('LDAP directory link') . ''); $pdf->displayText( '' . sprintf( - __('%1$s: %2$s'), - __('User attribute containing its groups') . '', + __s('%1$s: %2$s'), + __s('User attribute containing its groups') . '', '', ), $item->getField('ldap_field'), ); $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), __('Attribute value') . '', ''), + '' . sprintf(__s('%1$s: %2$s'), __s('Attribute value') . '', ''), $item->getField('ldap_value'), ); $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), __('Group DN') . '', ''), + '' . sprintf(__s('%1$s: %2$s'), __s('Group DN') . '', ''), $item->getField('ldap_group_dn'), ); @@ -160,46 +160,40 @@ 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'); + $title = __s('Managed items'); } else { - $types = $CFG_GLPI['linkgroup_types']; $field = 'groups_id'; - $title = __('Used items'); + $title = __s('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) { - $title = sprintf(__('%1$s (%2$s)'), $title, $nb . '/' . $max); - } else { - $title = sprintf(__('%1$s (%2$s)'), $title, $nb); - } + $title = $nb < $max ? sprintf(__s('%1$s (%2$s)'), $title, $nb . '/' . $max) : sprintf(__s('%1$s (%2$s)'), $title, $nb); $pdf->setColumnsSize(100); $pdf->displayTitle('' . $title . ''); - if ($nb) { + if ($nb !== 0) { if ($tree || $user) { $pdf->setColumnsSize(16, 20, 34, 30); $pdf->displayTitle( - __('Type'), - __('Name'), - __('Entity'), + __s('Type'), + __s('Name'), + __s('Entity'), Group::getTypeName(1) . ' / ' . User::getTypeName(1), ); } else { $pdf->setColumnsSize(20, 25, 55); - $pdf->displayTitle(__('Type'), __('Name'), __('Entity')); + $pdf->displayTitle(__s('Type'), __s('Name'), __s('Entity')); } } else { - $pdf->displayLine(__('No item found')); + $pdf->displayLine(__s('No item found')); } $tmpgrp = new Group(); - $tmpusr = new User(); + new User(); foreach ($datas as $data) { if (!($item = $dbu->getItemForItemtype($data['itemtype']))) { @@ -241,35 +235,38 @@ public static function pdfChildren(PluginPdfSimplePDF $pdf, CommonTreeDropdown $ /** @var DBmysql $DB */ global $DB; - $ID = $item->getID(); - $fields = $item->getAdditionalFields(); - $nb = count($fields); + $item->getID(); + $item->getAdditionalFields(); $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); - $pdf->displayTitle(sprintf(__('Sons of %s'), '' . $item->getNameID() . '')); + $pdf->displayTitle(sprintf(__s('Sons of %s'), '' . $item->getNameID() . '')); 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); - $pdf->displayTitle(__('Name'), __('Entity'), __('Comments')); + $pdf->displayTitle(__s('Name'), __s('Entity'), __s('Comments')); } else { $pdf->setColumnsSize(45, 55); - $pdf->displayTitle(__('Name'), __('Comments')); + $pdf->displayTitle(__s('Name'), __s('Comments')); } - foreach ($DB->request($item->getTable(), $crit) as $data) { + foreach ($DB->request($crit) as $data) { if ($entity_assign) { $pdf->displayLine( $data['name'], @@ -282,7 +279,7 @@ public static function pdfChildren(PluginPdfSimplePDF $pdf, CommonTreeDropdown $ } } else { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . sprintf(__('No sons of %s', 'behaviors'), $item->getNameID() . '')); + $pdf->displayTitle('' . sprintf(__s('No sons of %s', 'behaviors'), $item->getNameID() . '')); } $pdf->displaySpace(); diff --git a/inc/group_user.class.php b/inc/group_user.class.php index 730e0a8..a1d02b1 100644 --- a/inc/group_user.class.php +++ b/inc/group_user.class.php @@ -36,7 +36,7 @@ class PluginPdfGroup_User extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Group_User()); + $this->obj = ($obj ?: new Group_User()); } public static function pdfForGroup(PluginPdfSimplePDF $pdf, Group $group, $tree) @@ -46,20 +46,20 @@ public static function pdfForGroup(PluginPdfSimplePDF $pdf, Group $group, $tree) $ids = []; // Retrieve member list - $entityrestrict = Group_User::getDataForGroup($group, $used, $ids, '', $tree); + Group_User::getDataForGroup($group, $used, $ids, '', $tree); $number = count($used); $pdf->setColumnsSize(100); - $title = '' . _n('User', 'Users', 2) . ''; + $title = '' . _sn('User', 'Users', 2) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); + $title = sprintf(__s('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); @@ -71,19 +71,19 @@ public static function pdfForGroup(PluginPdfSimplePDF $pdf, Group $group, $tree) $pdf->displayTitle( User::getTypeName(1), Group::getTypeName(1), - __('Dynamic'), - __('Manager'), - __('Delegatee'), - __('Active'), + __s('Dynamic'), + __s('Manager'), + __s('Delegatee'), + __s('Active'), ); } else { $pdf->setColumnsSize(40, 15, 15, 15, 15); $pdf->displayTitle( User::getTypeName(1), - __('Dynamic'), - __('Manager'), - __('Delegatee'), - __('Active'), + __s('Dynamic'), + __s('Manager'), + __s('Delegatee'), + __s('Active'), ); } diff --git a/inc/infocom.class.php b/inc/infocom.class.php index c618694..37b45a4 100644 --- a/inc/infocom.class.php +++ b/inc/infocom.class.php @@ -36,7 +36,7 @@ class PluginPdfInfocom extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Infocom()); + $this->obj = ($obj ?: new Infocom()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -54,71 +54,71 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ic = new Infocom(); $pdf->setColumnsSize(100); - $title = '' . __('Financial and administratives information') . ''; + $title = '' . __s('Financial and administratives information') . ''; if (!$ic->getFromDBforDevice(get_class($item), $ID)) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $pdf->displayTitle('' . __('Asset lifecycle') . ''); + $pdf->displayTitle('' . __s('Asset lifecycle') . ''); $pdf->setColumnsSize(50, 50); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Order date') . '', + __s('%1$s: %2$s'), + __s('Order date') . '', Html::convDate($ic->fields['order_date']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Date of purchase') . '', + __s('%1$s: %2$s'), + __s('Date of purchase') . '', Html::convDate($ic->fields['buy_date']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Delivery date') . '', + __s('%1$s: %2$s'), + __s('Delivery date') . '', Html::convDate($ic->fields['delivery_date']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Startup date') . '', + __s('%1$s: %2$s'), + __s('Startup date') . '', Html::convDate($ic->fields['use_date']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Date of last physical inventory') . '', + __s('%1$s: %2$s'), + __s('Date of last physical inventory') . '', Html::convDate($ic->fields['inventory_date']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Decommission date') . '', + __s('%1$s: %2$s'), + __s('Decommission date') . '', Html::convDate($ic->fields['decommission_date']), ), ); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Financial and administrative information') . ''); + $pdf->displayTitle('' . __s('Financial and administrative information') . ''); $pdf->setColumnsSize(50, 50); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Supplier') . '', + __s('%1$s: %2$s'), + __s('Supplier') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_suppliers', $ic->fields['suppliers_id'], )), ), '' . sprintf( - __('%1$s: %2$s'), - __('Budget') . '', + __s('%1$s: %2$s'), + __s('Budget') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_budgets', $ic->fields['budgets_id'], @@ -128,47 +128,47 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Order number') . '', + __s('%1$s: %2$s'), + __s('Order number') . '', $ic->fields['order_number'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Immobilization number') . '', + __s('%1$s: %2$s'), + __s('Immobilization number') . '', $ic->fields['immo_number'], ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Invoice number') . '', + __s('%1$s: %2$s'), + __s('Invoice number') . '', $ic->fields['bill'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Delivery form') . '', + __s('%1$s: %2$s'), + __s('Delivery form') . '', $ic->fields['delivery_number'], ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('price', 'Value') . '', PluginPdfConfig::formatNumber($ic->fields['value']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Warranty extension value') . '', + __s('%1$s: %2$s'), + __s('Warranty extension value') . '', PluginPdfConfig::formatNumber($ic->fields['warranty_value']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Account net value') . '', + __s('%1$s: %2$s'), + __s('Account net value') . '', PluginPdfConfig::formatNumber(Infocom::Amort( $ic->fields['sink_type'], $ic->fields['value'], @@ -181,12 +181,12 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) )), ), '' . sprintf( - __('%1$s: %2$s'), - __('Amortization duration') . '', + __s('%1$s: %2$s'), + __s('Amortization duration') . '', sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), sprintf( - _n('%d year', '%d years', $ic->fields['sink_time']), + _sn('%d year', '%d years', $ic->fields['sink_time']), $ic->fields['sink_time'], ), Infocom::getAmortTypeName($ic->fields['sink_type']), @@ -196,13 +196,13 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Amortization type') . '', + __s('%1$s: %2$s'), + __s('Amortization type') . '', Infocom::getAmortTypeName($ic->fields['sink_type']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Amortization coefficient') . '', + __s('%1$s: %2$s'), + __s('Amortization coefficient') . '', $ic->fields['sink_coeff'], ), ); @@ -217,10 +217,10 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('TCO (value + tracking cost)') . '', + __s('%1$s: %2$s'), + __s('TCO (value + tracking cost)') . '', sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), Toolbox::stripTags((string) Infocom::showTco( $item->getField('ticket_tco'), $ic->fields['value'], @@ -229,10 +229,10 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Monthly TCO') . '', + __s('%1$s: %2$s'), + __s('Monthly TCO') . '', sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), Toolbox::stripTags((string) Infocom::showTco( $item->getField('ticket_tco'), $ic->fields['value'], @@ -245,8 +245,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Business criticity') . '', + __s('%1$s: %2$s'), + __s('Business criticity') . '', Dropdown::getDropdownName( 'glpi_businesscriticities', $ic->fields['businesscriticities_id'], @@ -257,23 +257,23 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) PluginPdfCommon::mainLine($pdf, $ic, 'comment'); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Warranty information') . ''); + $pdf->displayTitle('' . __s('Warranty information') . ''); $pdf->setColumnsSize(50, 50); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Start date of warranty') . '', + __s('%1$s: %2$s'), + __s('Start date of warranty') . '', Html::convDate($ic->fields['warranty_date']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Warranty duration') . '', + __s('%1$s: %2$s'), + __s('Warranty duration') . '', sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), sprintf( - _n( + _sn( '%d month', '%d months', $ic->fields['warranty_duration'], @@ -281,7 +281,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ic->fields['warranty_duration'], ), sprintf( - __('Valid to %s'), + __s('Valid to %s'), Infocom::getWarrantyExpir( $ic->fields['buy_date'], $ic->fields['warranty_duration'], @@ -291,16 +291,16 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) ), ); - $col1 = '' . __('Alarms on financial and administrative information') . ''; + $col1 = '' . __s('Alarms on financial and administrative information') . ''; if ($ic->fields['alert'] == 0) { - $col1 = sprintf(__('%1$s: %2$s'), $col1, __('No')); + $col1 = sprintf(__s('%1$s: %2$s'), $col1, __s('No')); } elseif ($ic->fields['alert'] == 4) { - $col1 = sprintf(__('%1$s: %2$s'), $col1, __('Warranty expiration date')); + $col1 = sprintf(__s('%1$s: %2$s'), $col1, __s('Warranty expiration date')); } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Warranty information') . '', + __s('%1$s: %2$s'), + __s('Warranty information') . '', $ic->fields['warranty_info'], ), $col1, diff --git a/inc/item_device.class.php b/inc/item_device.class.php index 64d7af8..bceeb3d 100644 --- a/inc/item_device.class.php +++ b/inc/item_device.class.php @@ -36,7 +36,7 @@ class PluginPdfItem_Device extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_Devices()); + $this->obj = ($obj ?: new Item_Devices()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) @@ -54,40 +54,55 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) } $pdf->setColumnsSize(100); - $pdf->displayTitle('' . Toolbox::ucfirst(_n('Component', 'Components', 2)) . ''); + $pdf->displayTitle('' . Toolbox::ucfirst(_sn('Component', 'Components', 2)) . ''); $pdf->setColumnsSize(3, 14, 42, 41); $vide = true; foreach ($devtypes as $itemtype) { - $devicetypes = new $itemtype(); + $dbu_local = new DbUtils(); + $devicetypes = $dbu_local->getItemForItemtype($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 ($specif_fields !== []) { + $select_fields = array_merge($select_fields, $specif_fields); + } + // Construction of the GROUP BY clause + $group_by = [$fk]; + if ($specif_fields !== []) { + $group_by = array_merge($group_by, $specif_fields); + } - $device = new $associated_type(); - $itemdevice = new $itemtype(); - foreach ($DB->request($query) as $data) { + $query_params = [ + 'SELECT' => $select_fields, + 'FROM' => $linktable, + 'WHERE' => [ + 'items_id' => $ID, + 'itemtype' => $item->getType(), + ], + 'GROUPBY' => $group_by, + ]; + + $dbu = new DbUtils(); + 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(); + $spec = []; + if (method_exists($device, 'getAdditionalFields')) { + $spec = $device->getAdditionalFields(); + } + $col4 = ''; - if (count($spec)) { + if (count($spec) > 0) { $colspan = (60 / count($spec)); foreach ($spec as $i => $label) { $toto = substr($label['name'], 0, strpos($label['name'], '_')); @@ -107,7 +122,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) ); } $col4 .= '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), $label['label'] . '', Toolbox::stripTags($value) . ' ', ); @@ -116,27 +131,23 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) $value = $device->fields[$label['name']]; } if ($label['type'] == 'bool') { - if ($value == 1) { - $value = __('Yes'); - } else { - $value = __('No'); - } + $value = $value == 1 ? __s('Yes') : __s('No'); } if (isset($label['unit'])) { $labelname = '' . sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $label['label'], $label['unit'], ) . ''; } else { $labelname = $label['label']; } - $col4 .= '' . sprintf(__('%1$s: %2$s'), $labelname . '', $value . ' '); + $col4 .= '' . sprintf(__s('%1$s: %2$s'), $labelname . '', $value . ' '); } } elseif (isset($device->fields[$label['name'] . '_default']) && !empty($device->fields[$label['name'] . '_default'])) { $col4 .= '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), $label['label'] . '', $device->fields[$label['name'] . '_default'] . ' ', ); @@ -151,7 +162,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) if ($vide) { $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $pdf->displayLine(__('No item to display')); + $pdf->displayLine(__s('No item to display')); } $pdf->displaySpace(); diff --git a/inc/item_disk.class.php b/inc/item_disk.class.php index f4befda..7c0f165 100644 --- a/inc/item_disk.class.php +++ b/inc/item_disk.class.php @@ -36,7 +36,7 @@ class PluginPdfItem_Disk extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_Disk()); + $this->obj = ($obj ?: new Item_Disk()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -47,8 +47,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.*'], + ['FROM' => 'glpi_items_disks'] + ['SELECT' => ['glpi_filesystems.name', 'glpi_items_disks.*'], 'LEFT JOIN' => ['glpi_filesystems' => ['FKEY' => ['glpi_items_disks' => 'filesystems_id', 'glpi_filesystems' => 'id']]], @@ -60,27 +59,27 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $number = count($result); $pdf->setColumnsSize(100); - $title = '' . _n('Volume', 'Volumes', $number) . ''; + $title = '' . _sn('Volume', 'Volumes', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(21, 21, 20, 9, 9, 9, 11); $pdf->displayTitle( - '' . __('Name'), - __('Partition'), - __('Mount point'), - __('File system'), - __('Global size'), - __('Free size'), - __('Free percentage') . '', + '' . __s('Name'), + __s('Partition'), + __s('Mount point'), + __s('File system'), + __s('Global size'), + __s('Free size'), + __s('Free percentage') . '', ); $pdf->setColumnsAlign('left', 'left', 'left', 'left', 'center', 'right', 'right'); @@ -96,7 +95,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $data['mountpoint'], $data['name'], sprintf( - __('%s Mio'), + __s('%s Mio'), Toolbox::stripTags(Html::formatNumber( $data['totalsize'], false, @@ -104,7 +103,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) )), ), sprintf( - __('%s Mio'), + __s('%s Mio'), Toolbox::stripTags(Html::formatNumber( $data['freesize'], false, @@ -112,7 +111,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) )), ), sprintf( - __('%s %s'), + __s('%s %s'), Toolbox::stripTags(Html::formatNumber($percent, false, 0)), '%', ), diff --git a/inc/item_knowbaseitem.class.php b/inc/item_knowbaseitem.class.php index 6bb6768..2096bc9 100644 --- a/inc/item_knowbaseitem.class.php +++ b/inc/item_knowbaseitem.class.php @@ -36,7 +36,7 @@ class PluginPdfItem_Knowbaseitem extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_Disk()); + $this->obj = ($obj ?: new Item_Disk()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -47,8 +47,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ID = $item->getField('id'); $result = $DB->request( - 'glpi_knowbaseitems', - ['SELECT' => ['glpi_knowbaseitems.*', + ['FROM' => 'glpi_knowbaseitems'] + ['SELECT' => ['glpi_knowbaseitems.*', 'glpi_knowbaseitems_items.itemtype', 'glpi_knowbaseitems_items.items_id'], 'LEFT JOIN' => ['glpi_knowbaseitems_items' @@ -61,23 +60,23 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); - if (!$number) { - $pdf->displayTitle('' . __('No knowledge base entries linked') . ''); + if ($number === 0) { + $pdf->displayTitle('' . __s('No knowledge base entries linked') . ''); } else { - $title = '' . __('Link a knowledge base entry') . ''; + $title = '' . __s('Link a knowledge base entry') . ''; if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(40, 40, 10, 10); - $pdf->displayTitle(__('Type'), __('Item'), __('Creation date'), __('Update date')); + $pdf->displayTitle(__s('Type'), __s('Item'), __s('Creation date'), __s('Update date')); foreach ($result as $data) { $pdf->displayLine( - __('Knowledge base'), + __s('Knowledge base'), $data['name'], Html::convDateTime($data['date_creation']), Html::convDateTime($data['date_mod']), diff --git a/inc/item_operatingsystem.class.php b/inc/item_operatingsystem.class.php index f1c055f..50686fe 100644 --- a/inc/item_operatingsystem.class.php +++ b/inc/item_operatingsystem.class.php @@ -36,7 +36,7 @@ class PluginPdfItem_OperatingSystem extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_OperatingSystem()); + $this->obj = ($obj ?: new Item_OperatingSystem()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) @@ -85,27 +85,27 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, $item) $number = count($result); $pdf->setColumnsSize(100); - $title = '' . __('Operating system') . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . __s('Operating system') . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(17, 10, 14, 15, 10, 10, 12, 12); $pdf->displayTitle( - __('Name'), - __('Version'), - __('Architecture'), - __('Service pack'), - __('Kernel'), - __('Edition'), - __('Product ID'), - __('Serial number'), + __s('Name'), + __s('Version'), + __s('Architecture'), + __s('Service pack'), + __s('Kernel'), + __s('Edition'), + __s('Product ID'), + __s('Serial number'), ); } diff --git a/inc/item_problem.class.php b/inc/item_problem.class.php index 9cae4e1..0a1bdc8 100644 --- a/inc/item_problem.class.php +++ b/inc/item_problem.class.php @@ -30,13 +30,44 @@ * -------------------------------------------------------------------------- */ +use Glpi\DBAL\QueryExpression; + +/** + * ------------------------------------------------------------------------- + * LICENSE + * + * This file is part of PDF plugin for GLPI. + * + * PDF is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PDF is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Reports. If not, see . + * + * @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 + * -------------------------------------------------------------------------- + */ class PluginPdfItem_Problem extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_Problem()); + $this->obj = ($obj ?: new Item_Problem()); } public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) @@ -53,8 +84,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) } $result = $DB->request( - 'glpi_items_problems', - ['SELECT' => 'itemtype', + ['FROM' => 'glpi_items_problems'] + ['SELECT' => 'itemtype', 'DISTINCT' => true, 'WHERE' => ['problems_id' => $instID], 'ORDER' => 'itemtype'], @@ -64,20 +94,20 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $totalnb = 0; $pdf->setColumnsSize(100); - $title = '' . _n('Item', 'Items', 2) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('Item', 'Items', 2) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); $pdf->setColumnsSize(20, 20, 26, 17, 17); $pdf->displayTitle( - '' . __('Type'), - __('Name'), - __('Entity'), - __('Serial number'), - __('Inventory number') . '', + '' . __s('Type'), + __s('Name'), + __s('Entity'), + __s('Serial number'), + __s('Inventory number') . '', ); foreach ($result as $row) { @@ -89,35 +119,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 QueryExpression($entity_restrict); + } - $result_linked = $DB->request($query); + $result_linked = $DB->request($query_params); $nb = count($result_linked); $prem = true; @@ -129,7 +179,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) if ($prem) { $typename = $item->getTypeName($nb); $pdf->displayLine( - Toolbox::stripTags(sprintf(__('%1$s: %2$s'), $typename, $nb)), + Toolbox::stripTags(sprintf(__s('%1$s: %2$s'), $typename, $nb)), Toolbox::stripTags($name), Dropdown::getDropdownName('glpi_entities', $data['entity']), Toolbox::stripTags($data['serial']), @@ -152,7 +202,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) } } } - $pdf->displayLine('' . sprintf(__('%1$s = %2$s') . '', __('Total'), $totalnb)); + $pdf->displayLine('' . sprintf(__s('%1$s = %2$s') . '', __s('Total'), $totalnb)); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tree = false) @@ -192,45 +242,91 @@ 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 (str_contains($restrict, 'IN (') || str_contains($restrict, 'AND') || str_contains($restrict, 'OR')) { + $where_conditions[] = new QueryExpression($restrict); + } else { + $where_conditions[] = new QueryExpression($restrict); + } + + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_problems'); + if (!empty($entity_restrict)) { + $where_conditions[] = new 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); $title = '' . Problem::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d problem', 'Last %d problems', $number) . '', + _sn('Last %d problem', 'Last %d problems', $number) . '', $number, )); } @@ -242,14 +338,14 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . - sprintf(__('%1$s: %2$s'), __('Status'), Problem::getStatus($job->fields['status'])); + sprintf(__s('%1$s: %2$s'), __s('Status'), Problem::getStatus($job->fields['status'])); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName('glpi_entities', $job->fields['entities_id']), ); @@ -260,15 +356,15 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if ($job->fields['begin_waiting_date']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Put on hold on %s') . '', + __s('Put on hold on %s') . '', Html::convDateTime($job->fields['begin_waiting_date']), ), ); @@ -276,31 +372,31 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -308,35 +404,35 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->displayLine($col); $col = '' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Problem::getPriorityName($job->fields['priority']), ); if ($job->fields['itilcategories_id']) { $cat = '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], ), ); - $col = sprintf(__('%1$s - %2$s'), $col, $cat); + $col = sprintf(__s('%1$s - %2$s'), $col, $cat); } $pdf->displayLine($col); $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); @@ -347,28 +443,28 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -377,7 +473,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -388,28 +484,28 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -418,13 +514,13 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Associated items'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Associated items'), ''); - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } $pdf->displaySpace(); diff --git a/inc/item_softwarelicense.class.php b/inc/item_softwarelicense.class.php index b543e87..35aa2cf 100644 --- a/inc/item_softwarelicense.class.php +++ b/inc/item_softwarelicense.class.php @@ -30,13 +30,44 @@ * -------------------------------------------------------------------------- */ +use Glpi\DBAL\QueryExpression; + +/** + * ------------------------------------------------------------------------- + * LICENSE + * + * This file is part of PDF plugin for GLPI. + * + * PDF is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PDF is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Reports. If not, see . + * + * @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 + * -------------------------------------------------------------------------- + */ class PluginPdfItem_SoftwareLicense extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_SoftwareLicense()); + $this->obj = ($obj ?: new Item_SoftwareLicense()); } public static function pdfForLicenseByEntity(PluginPdfSimplePDF $pdf, SoftwareLicense $license) @@ -51,15 +82,15 @@ public static function pdfForLicenseByEntity(PluginPdfSimplePDF $pdf, SoftwareLi $pdf->setColumnsSize(65, 35); $pdf->setColumnsAlign('left', 'right'); $pdf->displayTitle( - '' . __('Entity') . '', - '' . __('Number of affected computers') . '', + '' . __s('Entity') . '', + '' . __s('Number of affected computers') . '', ); $tot = 0; if (in_array(0, $_SESSION['glpiactiveentities'])) { $nb = Item_SoftwareLicense::countForLicense($ID, 0); if ($nb > 0) { - $pdf->displayLine(__('Root entity'), $nb); + $pdf->displayLine(__s('Root entity'), $nb); $tot += $nb; } } @@ -77,11 +108,11 @@ public static function pdfForLicenseByEntity(PluginPdfSimplePDF $pdf, SoftwareLi } if ($tot > 0) { - $pdf->displayLine(__('Total'), $tot); + $pdf->displayLine(__s('Total'), $tot); } else { $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $pdf->displayLine(__('No item to display')); + $pdf->displayLine(__s('No item to display')); } $pdf->displaySpace(); } @@ -111,85 +142,131 @@ public static function pdfForLicenseByComputer(PluginPdfSimplePDF $pdf, Software $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $title = '' . __('Affected computers') . ''; + $title = '' . __s('Affected computers') . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%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']), + ]; + + // Addition of entity restriction + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_computers'); + if (!empty($entity_restrict)) { + $query_params['WHERE'][] = new QueryExpression($entity_restrict); + } + + $result = $DB->request($query_params); $showEntity = ($license->isRecursive()); if ($showEntity) { $pdf->setColumnsSize(12, 12, 12, 12, 18, 10, 12, 12); $pdf->displayTitle( - '' . __('Entity'), - __('Name'), - __('Serial number'), - __('Inventory number'), - __('Location'), - __('Status'), - __('Group'), - __('User') . + '' . __s('Entity'), + __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Location'), + __s('Status'), + __s('Group'), + __s('User') . '', ); } else { $pdf->setColumnsSize(14, 14, 14, 18, 14, 13, 13); $pdf->displayTitle( - '' . __('Name'), - __('Serial number'), - __('Inventory number'), - __('Location'), - __('Status'), - __('Group'), - __('User') . + '' . __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Location'), + __s('Status'), + __s('Group'), + __s('User') . '', ); } foreach ($result as $data) { $compname = $data['compname']; if (empty($compname)) { - $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']); + $compname = sprintf(__s('%1$s (%2$s)'), $compname, $data['cID']); } - $entname = (empty($data['entity']) ? __('Root entity') : $data['entity']); + $entname = (empty($data['entity']) ? __s('Root entity') : $data['entity']); if ($showEntity) { $pdf->displayLine( diff --git a/inc/item_softwareversion.class.php b/inc/item_softwareversion.class.php index c21f93a..a2fa7dd 100644 --- a/inc/item_softwareversion.class.php +++ b/inc/item_softwareversion.class.php @@ -30,13 +30,45 @@ * -------------------------------------------------------------------------- */ +use Glpi\DBAL\QueryExpression; +use Glpi\DBAL\QueryUnion; + +/** + * ------------------------------------------------------------------------- + * LICENSE + * + * This file is part of PDF plugin for GLPI. + * + * PDF is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PDF is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Reports. If not, see . + * + * @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 + * -------------------------------------------------------------------------- + */ class PluginPdfItem_SoftwareVersion extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_SoftwareVersion()); + $this->obj = ($obj ?: new Item_SoftwareVersion()); } public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -45,8 +77,6 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) /** @var DBmysql $DB */ global $DB, $CFG_GLPI; - $dbu = new DbUtils(); - $ID = $item->getField('id'); $type = $item->getType(); $crit = ($type == 'Software' ? 'softwares_id' : 'id'); @@ -91,17 +121,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 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 QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName($itemtable . '.otherserial')); } if ($DB->fieldExists($itemtable, 'users_id')) { @@ -113,18 +139,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 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')); } if ($DB->fieldExists($itemtable, 'entities_id')) { @@ -134,9 +152,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 QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('entity')); } if ($DB->fieldExists($itemtable, 'locations_id')) { @@ -145,9 +161,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 QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('location')); } if ($DB->fieldExists($itemtable, 'states_id')) { $query['SELECT'][] = 'glpi_states.name AS state'; @@ -155,9 +169,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 QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('state')); } if ($DB->fieldExists($itemtable, 'groups_id')) { @@ -166,9 +178,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 QueryExpression($DB->quoteValue('') . ' AS ' . $DB->quoteName('groupe')); } if ($DB->fieldExists($itemtable, 'is_deleted')) { @@ -181,45 +191,47 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) $queries[] = $query; } + $union = new QueryUnion($queries, true); - $criteria = ['SELECT' => [], + $criteria = [ 'FROM' => $union, 'ORDER' => "$sort ASC", 'LIMIT' => $_SESSION['glpilist_limit'], ]; + $iterator = $DB->request($criteria); $pdf->setColumnsSize(100); - $title = '' . _n('Installation', 'Installations', $number) . ''; + $title = '' . _sn('Installation', 'Installations', $number) . ''; if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(8, 8, 12, 10, 10, 12, 8, 10, 12, 12); $pdf->displayTitle( - '' . _n('Version', 'Versions', 2), - __('Name'), - __('Serial number'), - __('Inventory number'), - __('Location'), - __('Status'), - __('Group'), - __('User'), - _n('License', 'Licenses', 2), - __('Type') . '', + '' . _sn('Version', 'Versions', 2), + __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Location'), + __s('Status'), + __s('Group'), + __s('User'), + _sn('License', 'Licenses', 2), + __s('Type') . '', ); foreach ($iterator as $data) { $itemname = $data['itemname']; if (empty($itemname) || $_SESSION['glpiis_ids_visible']) { - $itemname = sprintf(__('%1$s (%2$s)'), $itemname, $data['iID']); + $itemname = sprintf(__s('%1$s (%2$s)'), $itemname, $data['iID']); } $lics = Item_SoftwareLicense::GetLicenseForInstallation( $data['item_type'], @@ -232,7 +244,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) foreach ($lics as $lic) { $licname = $lic['name']; if (!empty($lic['type'])) { - $licname = sprintf(__('%1$s (%2$s)'), $licname, $lic['type']); + $licname = sprintf(__s('%1$s (%2$s)'), $licname, $lic['type']); } $tmp[] = $licname; } @@ -252,7 +264,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, CommonDBTM $item) $data['username'], $data['userrealname'], $data['userfirstname'], - $linkUser, + $linkUser ? 1 : 0, ), implode(', ', $tmp), ); @@ -272,7 +284,7 @@ public static function pdfForVersionByEntity(PluginPdfSimplePDF $pdf, SoftwareVe $pdf->setColumnsSize(100); $pdf->displayTitle('' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), Dropdown::getDropdownName( 'glpi_softwares', $version->getField('softwares_id'), @@ -282,13 +294,13 @@ public static function pdfForVersionByEntity(PluginPdfSimplePDF $pdf, SoftwareVe $pdf->setColumnsSize(75, 25); $pdf->setColumnsAlign('left', 'right'); - $pdf->displayTitle('' . __('Entity'), _n('Installation', 'Installations', 2) . ''); + $pdf->displayTitle('' . __s('Entity'), _sn('Installation', 'Installations', 2) . ''); $lig = $tot = 0; if (in_array(0, $_SESSION['glpiactiveentities'])) { $nb = Item_SoftwareVersion::countForVersion($softwareversions_id, '0'); if ($nb > 0) { - $pdf->displayLine(__('Root entity'), $nb); + $pdf->displayLine(__s('Root entity'), $nb); $tot += $nb; $lig++; } @@ -309,12 +321,12 @@ public static function pdfForVersionByEntity(PluginPdfSimplePDF $pdf, SoftwareVe if ($tot > 0) { if ($lig > 1) { - $pdf->displayLine(__('Total'), $tot); + $pdf->displayLine(__s('Total'), $tot); } } else { $pdf->setColumnsSize(100); $pdf->setColumnsAlign('center'); - $pdf->displayLine(__('No item to display')); + $pdf->displayLine(__s('No item to display')); } $pdf->displaySpace(); } @@ -327,95 +339,132 @@ 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(); + new SoftwareVersion(); - foreach ($DB->request($query) as $softwareversion) { + foreach ($DB->request($query_params) as $softwareversion) { $output[] = $softwareversion; } $installed = []; $pdf->setColumnsSize(100); - $title = '' . __('Installed software') . ''; + $title = '' . __s('Installed software') . ''; if (!count($output)) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, count($output)); + $title = sprintf(__s('%1$s: %2$s'), $title, count($output)); $pdf->displayTitle($title); $cat = -1; foreach ($output as $soft) { if ($soft['softwarecategories_id'] != $cat) { $cat = $soft['softwarecategories_id']; - if ($cat && $software_category->getFromDB($cat)) { - $catname = $software_category->getName(); - } else { - $catname = __('Uncategorized software'); - } + $catname = $cat && $software_category->getFromDB($cat) ? $software_category->getName() : __s('Uncategorized software'); $pdf->setColumnsSize(100); $pdf->displayTitle('' . $catname . ''); $pdf->setColumnsSize(39, 9, 11, 19, 14, 8); $pdf->displayTitle( - '' . __('Name'), - __('Status'), - __('Version'), - __('License'), - __('Installation date'), - __('Valid license') . '', + '' . __s('Name'), + __s('Status'), + __s('Version'), + __s('License'), + __s('Installation date'), + __s('Valid license') . '', ); } // 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'])) { - $lic = sprintf(__('%1$s (%2$s)'), $lic, $licdata['type']); + $lic = sprintf(__s('%1$s (%2$s)'), $lic, $licdata['type']); } } @@ -431,45 +480,81 @@ 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 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') . ''); + $pdf->displayTitle('' . __s('Affected licenses of not installed software', 'pdf') . ''); $pdf->setColumnsSize(50, 13, 13, 24); - $pdf->displayTitle('' . __('Name'), __('Status'), __('Version'), __('License') . ''); + $pdf->displayTitle('' . __s('Name'), __s('Status'), __s('Version'), __s('License') . ''); $lic = ''; foreach ($req as $data) { $lic .= '' . $data['name'] . ' ' . $data['serial']; if (!empty($data['softwarelicensetypes_id'])) { $lic = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $lic, Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwarelicensetypes', diff --git a/inc/item_ticket.class.php b/inc/item_ticket.class.php index 039d7c0..0c0a2ca 100644 --- a/inc/item_ticket.class.php +++ b/inc/item_ticket.class.php @@ -30,13 +30,44 @@ * -------------------------------------------------------------------------- */ +use Glpi\DBAL\QueryExpression; + +/** + * ------------------------------------------------------------------------- + * LICENSE + * + * This file is part of PDF plugin for GLPI. + * + * PDF is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PDF is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Reports. If not, see . + * + * @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 + * -------------------------------------------------------------------------- + */ class PluginPdfItem_Ticket extends PluginPdfCommon { public static $rightname = 'plugin_pdf'; public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Item_Ticket()); + $this->obj = ($obj ?: new Item_Ticket()); } public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $sub = false) @@ -53,8 +84,9 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su } $result = $DB->request( - 'glpi_items_tickets', - ['SELECT' => 'itemtype', + [ + 'SELECT' => 'itemtype', + 'FROM' => 'glpi_items_tickets', 'DISTINCT' => true, 'WHERE' => ['tickets_id' => $instID], 'ORDER' => 'itemtype'], @@ -62,20 +94,20 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su $number = count($result); $pdf->setColumnsSize(100); - $title = '' . _n('Item', 'Items', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('Item', 'Items', $number) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, ''); + $title = sprintf(__s('%1$s: %2$s'), $title, ''); $pdf->displayTitle($title); $pdf->setColumnsSize(20, 20, 26, 17, 17); $pdf->displayTitle( - '' . __('Type'), - __('Name'), - __('Entity'), - __('Serial number'), - __('Inventory number') . '', + '' . __s('Type'), + __s('Name'), + __s('Entity'), + __s('Serial number'), + __s('Inventory number') . '', ); $totalnb = 0; @@ -88,35 +120,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 QueryExpression($entity_restrict); + } + + // Building the final query + $query_params = [ + 'SELECT' => $select_fields, + 'FROM' => $itemtable, + 'LEFT JOIN' => $joins, + 'WHERE' => $where_conditions, + 'ORDER' => ['glpi_entities.completename', "$itemtable.name"], + ]; - $result_linked = $DB->request($query); + $result_linked = $DB->request($query_params); $nb = count($result_linked); $prem = true; @@ -128,7 +186,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su if ($prem) { $typename = $item->getTypeName($nb); $pdf->displayLine( - Toolbox::stripTags(sprintf(__('%1$s: %2$s'), $typename, $nb)), + Toolbox::stripTags(sprintf(__s('%1$s: %2$s'), $typename, $nb)), Toolbox::stripTags($name), Dropdown::getDropdownName('glpi_entities', $data['entity']), isset($data['serial']) ? Toolbox::stripTags($data['serial']) : '', @@ -150,7 +208,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket, $su $totalnb += $nb; } } - $pdf->displayLine('' . sprintf(__('%1$s = %2$s') . '', __('Total'), $totalnb)); + $pdf->displayLine('' . sprintf(__s('%1$s = %2$s') . '', __s('Total'), $totalnb)); } $pdf->displaySpace(); } @@ -162,8 +220,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $dbu = new DbUtils(); - $ID = $item->getField('id'); - $type = $item->getType(); + $item->getField('id'); + $item->getType(); if (!Session::haveRightsOr( 'ticket', @@ -216,47 +274,97 @@ 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 (str_contains($restrict, 'OR') || str_contains($restrict, 'AND')) { + $where_conditions[] = new QueryExpression($restrict); + } else { + $where_conditions[] = $restrict; + } + + $entity_restrict = $dbu->getEntitiesRestrictRequest('', 'glpi_tickets'); + if (!empty($entity_restrict)) { + $where_conditions[] = new 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); $title = '' . Ticket::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d ticket', 'Last %d tickets', $number) . '', + _sn('Last %d ticket', 'Last %d tickets', $number) . '', $number, )); @@ -268,17 +376,17 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . sprintf( - __('%1$s: %2$s'), - __('Status'), + __s('%1$s: %2$s'), + __s('Status'), Ticket::getStatus($job->fields['status']), ); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName( 'glpi_entities', @@ -292,15 +400,15 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if ($job->fields['begin_waiting_date']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Put on hold on %s') . '', + __s('Put on hold on %s') . '', Html::convDateTime($job->fields['begin_waiting_date']), ), ); @@ -308,31 +416,31 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -340,35 +448,35 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->displayLine($col); $col = '' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Ticket::getPriorityName($job->fields['priority']), ); if ($job->fields['itilcategories_id']) { $cat = '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], ), ); - $col = sprintf(__('%1$s - %2$s'), $col, $cat); + $col = sprintf(__s('%1$s - %2$s'), $col, $cat); } $pdf->displayLine($col); $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); @@ -379,28 +487,28 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -409,7 +517,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -420,28 +528,28 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -450,28 +558,30 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } $first = true; $listitems = $texteitem = ''; foreach ($DB->request( - 'glpi_items_tickets', - ['WHERE' => ['tickets_id' => $job->fields['id']]], + [ + 'FROM' => 'glpi_items_tickets', + 'WHERE' => ['tickets_id' => $job->fields['id']], + ], ) as $data) { if (!($item = $dbu->getItemForItemtype($data['itemtype']))) { continue; } if ($first) { $texteitem = '' . sprintf( - __('%1$s: %2$s') . '', - _n('Associated items', 'Associated items', 2), + __s('%1$s: %2$s') . '', + _sn('Associated items', 'Associated items', 2), '' . '
', ); } $listitems .= sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), $item->getTypeName(1), Dropdown::getDropdownName( getTableForItemType($data['itemtype']), @@ -484,7 +594,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $tr $pdf->displayText($texteitem, $listitems); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } } diff --git a/inc/itilfollowup.class.php b/inc/itilfollowup.class.php index 8f5b08d..46c8c7a 100644 --- a/inc/itilfollowup.class.php +++ b/inc/itilfollowup.class.php @@ -36,7 +36,7 @@ class PluginPdfItilFollowup extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new ITILFollowup()); + $this->obj = ($obj ?: new ITILFollowup()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $private) @@ -72,29 +72,25 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $pr $pdf->setColumnsSize(100); $title = '' . ITILFollowup::getTypeName(2) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); + $title = sprintf(__s('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(44, 14, 42); - $pdf->displayTitle('' . __('Source of followup', 'pdf') . '', // Source - '' . __('Date') . '', // Date - '' . __('Requester') . ''); // Author + $pdf->displayTitle('' . __s('Source of followup', 'pdf') . '', // Source + '' . __s('Date') . '', // Date + '' . __s('Requester') . ''); // Author foreach ($result as $data) { - if ($data['requesttypes_id']) { - $lib = Dropdown::getDropdownName('glpi_requesttypes', $data['requesttypes_id']); - } else { - $lib = ''; - } + $lib = $data['requesttypes_id'] ? Dropdown::getDropdownName('glpi_requesttypes', $data['requesttypes_id']) : ''; if ($data['is_private']) { - $lib = sprintf(__('%1$s (%2$s)'), $lib, __('Private')); + $lib = sprintf(__s('%1$s (%2$s)'), $lib, __s('Private')); } $pdf->displayLine( Toolbox::stripTags($lib), @@ -103,7 +99,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); @@ -117,7 +113,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item, $pr } $pdf->displayText( - '' . sprintf(__('%1$s: %2$s') . '', __('Description'), ''), + '' . sprintf(__s('%1$s: %2$s') . '', __s('Description'), ''), $content, 1, ); diff --git a/inc/itilsolution.class.php b/inc/itilsolution.class.php index 6a59bf7..f612963 100644 --- a/inc/itilsolution.class.php +++ b/inc/itilsolution.class.php @@ -36,7 +36,7 @@ class PluginPdfITILSolution extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new ITILSolution()); + $this->obj = ($obj ?: new ITILSolution()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -49,18 +49,17 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); $soluce = $DB->request( - 'glpi_itilsolutions', - ['itemtype' => $item->getType(), + ['FROM' => 'glpi_itilsolutions'] + ['itemtype' => $item->getType(), 'items_id' => $item->fields['id']], ); $number = count($soluce); - $title = '' . __('Solution') . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . __s('Solution') . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); $pdf->displayTitle($title); foreach ($soluce as $row) { if ($row['solutiontypes_id']) { @@ -69,9 +68,9 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $row['solutiontypes_id'], )); } else { - $title = __('Solution'); + $title = __s('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); @@ -86,25 +85,25 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $text = $textapprove = ''; if ($row['status'] == 3) { - $text = __('Soluce approved on ', 'pdf'); + $text = __s('Soluce approved on ', 'pdf'); } elseif ($row['status'] == 4) { - $text = __('Soluce refused on ', 'pdf'); + $text = __s('Soluce refused on ', 'pdf'); } if (isset($row['date_approval']) || !empty($row['users_id_approval'])) { $textapprove = '


' . sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $text, Html::convDateTime($row['date_approval']), ) . ' ' . sprintf( - __('%1$s %2$s'), - __('By'), + __s('%1$s %2$s'), + __s('By'), Toolbox::stripTags($dbu->getUserName($row['users_id_approval'])), ) . ''; } - $pdf->displayText('' . sprintf(__('%1$s: %2$s'), $title . '', ''), $sol . $textapprove); + $pdf->displayText('' . sprintf(__s('%1$s: %2$s'), $title . '', ''), $sol . $textapprove); } } diff --git a/inc/knowbaseitem.class.php b/inc/knowbaseitem.class.php index b8b5787..74c95aa 100644 --- a/inc/knowbaseitem.class.php +++ b/inc/knowbaseitem.class.php @@ -36,7 +36,7 @@ class PluginPdfKnowbaseItem extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new KnowbaseItem()); + $this->obj = ($obj ?: new KnowbaseItem()); } public function defineAllTabsPDF($options = []) @@ -54,7 +54,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) { $dbu = new DbUtils(); - $ID = $item->getField('id'); + $item->getField('id'); if (!Session::haveRightsOr( 'knowbase', @@ -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); @@ -98,31 +94,31 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item) $pdf->setColumnsSize(100); if (Toolbox::strlen($fullcategoryname) > 0) { - $pdf->displayTitle('' . __('Category name') . ''); + $pdf->displayTitle('' . __s('Category name') . ''); $pdf->displayLine($fullcategoryname); } if (Toolbox::strlen($question) > 0) { - $pdf->displayTitle('' . __('Subject') . ''); + $pdf->displayTitle('' . __s('Subject') . ''); $pdf->displayText('', $question, 5); } else { - $pdf->displayTitle('' . __('No question found', 'pdf') . ''); + $pdf->displayTitle('' . __s('No question found', 'pdf') . ''); } if (Toolbox::strlen($answer) > 0) { - $pdf->displayTitle('' . __('Content') . ''); + $pdf->displayTitle('' . __s('Content') . ''); $pdf->displayText('', $answer, 5); } else { - $pdf->displayTitle('' . __('No answer found', 'pdf') . ''); + $pdf->displayTitle('' . __s('No answer found', 'pdf') . ''); } $pdf->setColumnsSize(50, 15, 15, 10, 10); $pdf->displayTitle( - __('Writer'), - __('Creation date'), - __('Last update'), - __('FAQ'), - _n('View', 'Views', 2), + __s('Writer'), + __s('Creation date'), + __s('Last update'), + __s('FAQ'), + _sn('View', 'Views', 2), ); $pdf->displayLine( $dbu->getUserName($item->fields['users_id']), @@ -179,22 +175,22 @@ public static function pdfCible(PluginPdfSimplePDF $pdf, KnowbaseItem $item) $nb = $item->countVisibilities(); if ($nb) { $pdf->setColumnsSize(100); - $pdf->displayTitle(_n('Target', 'Targets', $nb)); + $pdf->displayTitle(_sn('Target', 'Targets', $nb)); $pdf->setColumnsSize(30, 70); - $pdf->displayTitle(__('Type'), _n('Recipient', 'Recipients', 2)); + $pdf->displayTitle(__s('Type'), _sn('Recipient', 'Recipients', 2)); $recursive = ''; if (count($entities)) { foreach ($entities as $key => $val) { foreach ($val as $data) { if ($data['is_recursive']) { - $recursive = '(' . __('R') . ')'; + $recursive = '(' . __s('R') . ')'; } $pdf->displayLine( - __('Entity'), + __s('Entity'), sprintf( - __('%1s %2s'), + __s('%1s %2s'), Dropdown::getDropdownName( 'glpi_entities', $data['entities_id'], @@ -210,13 +206,13 @@ public static function pdfCible(PluginPdfSimplePDF $pdf, KnowbaseItem $item) foreach ($profiles as $key => $val) { foreach ($val as $data) { if ($data['is_recursive']) { - $recursive = '(' . __('R') . ')'; + $recursive = '(' . __s('R') . ')'; } $names = Dropdown::getDropdownName('glpi_profiles', $data['profiles_id']); $profilename = ''; if ($data['entities_id'] >= 0) { $profilename = sprintf( - __('%1$s / %2$s'), + __s('%1$s / %2$s'), $names, Dropdown::getDropdownName( 'glpi_entities', @@ -224,10 +220,10 @@ public static function pdfCible(PluginPdfSimplePDF $pdf, KnowbaseItem $item) ), ); if ($data['is_recursive']) { - $profilename = sprintf(__('%1$s %2$s'), $profilename, $recursive); + $profilename = sprintf(__s('%1$s %2$s'), $profilename, $recursive); } } - $pdf->displayLine(__('Profile'), $profilename); + $pdf->displayLine(__s('Profile'), $profilename); } } } @@ -236,13 +232,13 @@ public static function pdfCible(PluginPdfSimplePDF $pdf, KnowbaseItem $item) foreach ($groups as $key => $val) { foreach ($val as $data) { if ($data['is_recursive']) { - $recursive = '(' . __('R') . ')'; + $recursive = '(' . __s('R') . ')'; } $names = Dropdown::getDropdownName('glpi_groups', $data['groups_id']); $groupname = ''; if ($data['entities_id'] >= 0) { $groupname = sprintf( - __('%1$s / %2$s'), + __s('%1$s / %2$s'), $names, Dropdown::getDropdownName( 'glpi_entities', @@ -250,10 +246,10 @@ public static function pdfCible(PluginPdfSimplePDF $pdf, KnowbaseItem $item) ), ); if ($data['is_recursive']) { - $groupname = sprintf(__('%1$s %2$s'), $groupname, $recursive); + $groupname = sprintf(__s('%1$s %2$s'), $groupname, $recursive); } } - $pdf->displayLine(__('Group'), $groupname); + $pdf->displayLine(__s('Group'), $groupname); } } } @@ -261,7 +257,7 @@ public static function pdfCible(PluginPdfSimplePDF $pdf, KnowbaseItem $item) if (count($users)) { foreach ($users as $key => $val) { foreach ($val as $data) { - $pdf->displayLine(__('User'), $dbu->getUserName($data['users_id'])); + $pdf->displayLine(__s('User'), $dbu->getUserName($data['users_id'])); } } } diff --git a/inc/link.class.php b/inc/link.class.php index e8794ef..b4e040d 100644 --- a/inc/link.class.php +++ b/inc/link.class.php @@ -36,7 +36,7 @@ class PluginPdfLink extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Link()); + $this->obj = ($obj ?: new Link()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -44,7 +44,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) /** @var DBmysql $DB */ global $DB; - $ID = $item->getField('id'); + $item->getField('id'); $type = get_class($item); $query = ['SELECT' => ['glpi_links.id', 'link', 'name', 'data'], @@ -59,14 +59,14 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $number = count($result); $pdf->setColumnsSize(100); - $title = '' . _n('External link', 'External links', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('External link', 'External links', $number) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); @@ -83,7 +83,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $i = 1; foreach ($links as $key => $link) { $url = $link; - $pdf->displayLine(sprintf(__('%1$s: %2$s'), "$name #$i", $link)); + $pdf->displayLine(sprintf(__s('%1$s: %2$s'), "$name #$i", $link)); $i++; $i++; } @@ -100,7 +100,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $file = reset($files); } $pdf->displayText( - sprintf(__('%1$s: %2$s'), "$name #$i - $file", ''), + sprintf(__s('%1$s: %2$s'), "$name #$i - $file", ''), trim($data), 1, 10, diff --git a/inc/log.class.php b/inc/log.class.php index 58f6924..feb190c 100644 --- a/inc/log.class.php +++ b/inc/log.class.php @@ -36,7 +36,7 @@ class PluginPdfLog extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Log()); + $this->obj = ($obj ?: new Log()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -46,24 +46,24 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $number = count($changes); $pdf->setColumnsSize(100); - $title = '' . __('Historical') . ''; + $title = '' . __s('Historical') . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(10, 15, 24, 11, 40); $pdf->displayTitle( - '' . __('ID'), - __('Date'), - __('User'), - __('Field'), + '' . __s('ID'), + __s('Date'), + __s('User'), + __s('Field'), _x('name', 'Update') . '', ); diff --git a/inc/monitor.class.php b/inc/monitor.class.php index bfff18e..5d7ccc7 100644 --- a/inc/monitor.class.php +++ b/inc/monitor.class.php @@ -36,7 +36,7 @@ class PluginPdfMonitor extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Monitor()); + $this->obj = ($obj ?: new Monitor()); } public function defineAllTabsPDF($options = []) @@ -62,26 +62,26 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Monitor $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group') . '', + __s('%1$s: %2$s'), + __s('Group') . '', Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Size') . '', - sprintf(__('%1$s %2$s'), $item->fields['size'], '"'), + __s('%1$s: %2$s'), + __s('Size') . '', + sprintf(__s('%1$s %2$s'), $item->fields['size'], '"'), ), ); - $opts = ['have_micro' => __('Microphone'), - 'have_speaker' => __('Speakers'), - 'have_subd' => __('Sub-D'), - 'have_bnc' => __('BNC'), - 'have_dvi' => __('DVI'), - 'have_pivot' => __('Pivot'), - 'have_hdmi' => __('HDMI'), - 'have_displayport' => __('DisplayPort')]; - foreach ($opts as $key => $val) { + $opts = ['have_micro' => __s('Microphone'), + 'have_speaker' => __s('Speakers'), + 'have_subd' => __s('Sub-D'), + 'have_bnc' => __s('BNC'), + 'have_dvi' => __s('DVI'), + 'have_pivot' => __s('Pivot'), + 'have_hdmi' => __s('HDMI'), + 'have_displayport' => __s('DisplayPort')]; + foreach (array_keys($opts) as $key) { if (!$item->fields[$key]) { unset($opts[$key]); } @@ -89,9 +89,9 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Monitor $item) $pdf->setColumnsSize(100); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Flags') . '', - (count($opts) ? implode(', ', $opts) : __('None')), + __s('%1$s: %2$s'), + __s('Flags') . '', + (count($opts) ? implode(', ', $opts) : __s('None')), ), ); diff --git a/inc/networkequipment.class.php b/inc/networkequipment.class.php index 161622c..cbd1155 100644 --- a/inc/networkequipment.class.php +++ b/inc/networkequipment.class.php @@ -36,7 +36,7 @@ class PluginPdfNetworkEquipment extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new NetworkEquipment()); + $this->obj = ($obj ?: new NetworkEquipment()); } public function defineAllTabsPDF($options = []) @@ -68,13 +68,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, NetworkEquipment $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('User') . '', + __s('%1$s: %2$s'), + __s('User') . '', $dbu->getUserName($item->fields['users_id']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Network') . '', + __s('%1$s: %2$s'), + __s('Network') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_networks', $item->fields['networks_id'], @@ -84,14 +84,14 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, NetworkEquipment $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group') . '', + __s('%1$s: %2$s'), + __s('Group') . '', Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']), ), - '' . __('The MAC address and the IP of the equipment are included in an aggregated network port'), + '' . __s('The MAC address and the IP of the equipment are included in an aggregated network port'), '' . sprintf( - __('%1$s: %2$s'), - sprintf(__('%1$s (%2$s)'), __('Memory'), __('Mio')) . '', + __s('%1$s: %2$s'), + sprintf(__s('%1$s (%2$s)'), __s('Memory'), __s('Mio')) . '', $item->fields['ram'], ), ); diff --git a/inc/networkport.class.php b/inc/networkport.class.php index a5005ec..1d5a0ee 100644 --- a/inc/networkport.class.php +++ b/inc/networkport.class.php @@ -38,7 +38,7 @@ class PluginPdfNetworkPort extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new NetworkPort()); + $this->obj = ($obj ?: new NetworkPort()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -52,22 +52,21 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); $result = $DB->request( - 'glpi_networkports', - ['SELECT' => ['id', 'name', 'logical_number'], + ['FROM' => 'glpi_networkports'] + ['SELECT' => ['id', 'name', 'logical_number'], 'WHERE' => ['items_id' => $ID, 'itemtype' => $type], 'ORDER' => ['name', 'logical_number']], ); $nb_connect = count($result); - $title = '' . _n('Network port', 'Network ports', $nb_connect) . ''; - if (!$nb_connect) { - $pdf->displayTitle('' . __('No network port found') . ''); + $title = '' . _sn('Network port', 'Network ports', $nb_connect) . ''; + if ($nb_connect === 0) { + $pdf->displayTitle('' . __s('No network port found') . ''); } else { if ($nb_connect > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $nb_connect); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $nb_connect); } else { - $title = sprintf(__('%1$s: %2$d'), $title, $nb_connect); + $title = sprintf(__s('%1$s: %2$d'), $title, $nb_connect); } $pdf->displayTitle($title); @@ -79,35 +78,30 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->displayTitle('' . $instname . ''); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), '#', $netport->fields['logical_number'], )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Name') . '', + __s('%1$s: %2$s'), + __s('Name') . '', $netport->fields['name'], )); $contact = new NetworkPort(); $netport2 = new NetworkPort(); - $add = __('Not connected.'); - if ($cid = $contact->getContact($netport->fields['id'])) { - if ($netport2->getFromDB($cid) - && ($device2 = $dbu->getItemForItemtype($netport2->fields['itemtype']))) { - if ($device2->getFromDB($netport2->fields['items_id'])) { - $add = $netport2->getName() . ' ' . __('on') . ' ' . - $device2->getName() . ' (' . $device2->getTypeName() . ')'; - } - } + $add = __s('Not connected.'); + $cid = $contact->getContact($netport->fields['id']); + if ($cid && $netport2->getFromDB($cid) && ($device2 = $dbu->getItemForItemtype($netport2->fields['itemtype'])) && $device2->getFromDB($netport2->fields['items_id'])) { + $add = $netport2->getName() . ' ' . __s('on') . ' ' . $device2->getName() . ' (' . $device2->getTypeName() . ')'; } if ($instantiation_type == 'NetworkPortEthernet') { $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Connected to') . '', + __s('%1$s: %2$s'), + __s('Connected to') . '', $add, )); $netportethernet = new NetworkPortEthernet(); @@ -118,10 +112,10 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $type = NetworkPortEthernet::getPortTypeName($netportethernet->fields['type']); } $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Ethernet port speed') . '', $speed), + '' . sprintf(__s('%1$s: %2$s'), __s('Ethernet port speed') . '', $speed), ); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Ethernet port type') . '', $type), + '' . sprintf(__s('%1$s: %2$s'), __s('Ethernet port type') . '', $type), ); $netpoint = new Socket(); @@ -132,15 +126,15 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Network outlet') . '', + __s('%1$s: %2$s'), + __s('Network outlet') . '', $outlet, ), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('MAC') . '', + __s('%1$s: %2$s'), + __s('MAC') . '', $netport->fields['mac'], )); @@ -156,7 +150,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) if ($ip->getFromDBByRequest($sqlip)) { $ipname = $ip->fields['name']; - $pdf->displayLine('' . sprintf(__('%1$s: %2$s'), __('ip') . '', $ipname)); + $pdf->displayLine('' . sprintf(__s('%1$s: %2$s'), __s('ip') . '', $ipname)); $sql = ['SELECT' => 'glpi_ipaddresses_ipnetworks.ipnetworks_id', 'FROM' => 'glpi_ipaddresses_ipnetworks', @@ -171,8 +165,8 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $ipnetwork = new IPNetwork(); if ($ipnetwork->getFromDB($row['ipnetworks_id'])) { $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('IP network') . '', + __s('%1$s: %2$s'), + __s('IP network') . '', $ipnetwork->fields['completename'], )); } diff --git a/inc/peripheral.class.php b/inc/peripheral.class.php index ed868cf..9f38312 100644 --- a/inc/peripheral.class.php +++ b/inc/peripheral.class.php @@ -36,7 +36,7 @@ class PluginPdfPeripheral extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Peripheral()); + $this->obj = ($obj ?: new Peripheral()); } public function defineAllTabsPDF($options = []) @@ -64,11 +64,11 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Peripheral $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group') . '', + __s('%1$s: %2$s'), + __s('Group') . '', Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']), ), - '' . sprintf(__('%1$s: %2$s'), __('Brand') . '', $item->fields['brand']), + '' . sprintf(__s('%1$s: %2$s'), __s('Brand') . '', $item->fields['brand']), ); $pdf->setColumnsSize(100); diff --git a/inc/phone.class.php b/inc/phone.class.php index b3a8840..e35cf92 100644 --- a/inc/phone.class.php +++ b/inc/phone.class.php @@ -36,7 +36,7 @@ class PluginPdfPhone extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Phone()); + $this->obj = ($obj ?: new Phone()); } public function defineAllTabsPDF($options = []) @@ -65,29 +65,29 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Phone $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group') . '', + __s('%1$s: %2$s'), + __s('Group') . '', Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']), ), '' . sprintf( - __('%1$s: %2$s'), - __('UUID') . '', + __s('%1$s: %2$s'), + __s('UUID') . '', $item->fields['uuid'], ), ); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Brand') . '', $item->fields['brand']), + '' . sprintf(__s('%1$s: %2$s'), __s('Brand') . '', $item->fields['brand']), '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('quantity', 'Number of lines') . '', $item->fields['number_line'], ), ); - $opts = ['have_headset' => __('Headset'), - 'have_hp' => __('Speaker')]; - foreach ($opts as $key => $val) { + $opts = ['have_headset' => __s('Headset'), + 'have_hp' => __s('Speaker')]; + foreach (array_keys($opts) as $key) { if (!$item->fields[$key]) { unset($opts[$key]); } @@ -95,14 +95,14 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Phone $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Power supply') . '', + __s('%1$s: %2$s'), + __s('Power supply') . '', Dropdown::getYesNo($item->fields['phonepowersupplies_id']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Flags') . '', - (count($opts) ? implode(', ', $opts) : __('None')), + __s('%1$s: %2$s'), + __s('Flags') . '', + (count($opts) ? implode(', ', $opts) : __s('None')), ), ); diff --git a/inc/preference.class.php b/inc/preference.class.php index a024925..15a8dc7 100644 --- a/inc/preference.class.php +++ b/inc/preference.class.php @@ -30,16 +30,23 @@ * -------------------------------------------------------------------------- */ +use Glpi\Application\View\TemplateRenderer; + class PluginPdfPreference extends CommonDBTM { public static $rightname = 'plugin_pdf'; + public static function getTypeName($nb = 0) + { + return __s('PDF export', 'pdf'); + } + public static function showPreferences() { /** @var array $PLUGIN_HOOKS */ global $PLUGIN_HOOKS; - $target = Toolbox::getItemTypeFormURL(__CLASS__); + $target = Toolbox::getItemTypeFormURL(self::class); $pref = new self(); $dbu = new DbUtils(); @@ -55,17 +62,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 +74,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 { @@ -90,103 +85,61 @@ public function menu($item, $action) || !class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) { return; } - $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item); - $options = $itempdf->defineAllTabsPDF(); - $formid = "plugin_pdf_{$type}_" . mt_rand(); - echo "
"; + $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; $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'); + return self::createTabEntry(self::getTypeName(), 0, $item::getType(), PluginPdfConfig::getIcon()); } - return ''; } @@ -219,7 +172,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/printer.class.php b/inc/printer.class.php index 08272da..d493fc0 100644 --- a/inc/printer.class.php +++ b/inc/printer.class.php @@ -36,7 +36,7 @@ class PluginPdfPrinter extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Printer()); + $this->obj = ($obj ?: new Printer()); } public function defineAllTabsPDF($options = []) @@ -67,27 +67,27 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Printer $printer) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Sysdescr') . '', + __s('%1$s: %2$s'), + __s('Sysdescr') . '', $printer->fields['sysdescr'], ), '' . sprintf( - __('%1$s: %2$s'), - __('User') . '', + __s('%1$s: %2$s'), + __s('User') . '', $dbu->getUserName($printer->fields['users_id']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Management type') . '', - ($printer->fields['is_global'] ? __('Global management') - : __('Unit management')), + __s('%1$s: %2$s'), + __s('Management type') . '', + ($printer->fields['is_global'] ? __s('Global management') + : __s('Unit management')), ), '' . sprintf( - __('%1$s: %2$s'), - __('Network') . '', + __s('%1$s: %2$s'), + __s('Network') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_networks', $printer->fields['networks_id'], @@ -97,13 +97,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Printer $printer) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group') . '', + __s('%1$s: %2$s'), + __s('Group') . '', Dropdown::getDropdownName('glpi_groups', $printer->fields['groups_id']), ), '' . sprintf( - __('%1$s: %2$s'), - __('UUID') . '', + __s('%1$s: %2$s'), + __s('UUID') . '', $printer->fields['uuid'], ), ); @@ -111,32 +111,32 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Printer $printer) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Memory') . '', + __s('%1$s: %2$s'), + __s('Memory') . '', $printer->fields['memory_size'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Initial page counter') . '', + __s('%1$s: %2$s'), + __s('Initial page counter') . '', $printer->fields['init_pages_counter'], ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Current counter of pages') . '', + __s('%1$s: %2$s'), + __s('Current counter of pages') . '', $printer->fields['last_pages_counter'], ), ); - $opts = ['have_serial' => __('Serial'), - 'have_parallel' => __('Parallel'), - 'have_usb' => __('USB'), - 'have_ethernet' => __('Ethernet'), - 'have_wifi' => __('Wifi')]; + $opts = ['have_serial' => __s('Serial'), + 'have_parallel' => __s('Parallel'), + 'have_usb' => __s('USB'), + 'have_ethernet' => __s('Ethernet'), + 'have_wifi' => __s('Wifi')]; - foreach ($opts as $key => $val) { + foreach (array_keys($opts) as $key) { if (!$printer->fields[$key]) { unset($opts[$key]); } @@ -144,9 +144,9 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Printer $printer) $pdf->setColumnsSize(100); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - _n('Port', 'Ports', count($opts)) . '', - (count($opts) ? implode(', ', $opts) : __('None')), + __s('%1$s: %2$s'), + _sn('Port', 'Ports', count($opts)) . '', + (count($opts) ? implode(', ', $opts) : __s('None')), )); PluginPdfCommon::mainLine($pdf, $printer, 'comment'); diff --git a/inc/problem.class.php b/inc/problem.class.php index f2bf915..0bcd65a 100644 --- a/inc/problem.class.php +++ b/inc/problem.class.php @@ -36,7 +36,7 @@ class PluginPdfProblem extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Problem()); + $this->obj = ($obj ?: new Problem()); } public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) @@ -51,7 +51,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $pdf->setColumnsSize(100); $pdf->displayTitle('' . - (empty($job->fields['name']) ? __('Without title') : $name = $job->fields['name']) . ''); + (empty($job->fields['name']) ? __s('Without title') : $name = $job->fields['name']) . ''); if (count($_SESSION['glpiactiveentities']) > 1) { $entity = ' (' . Dropdown::getDropdownName('glpi_entities', $job->fields['entities_id']) . ')'; @@ -61,24 +61,23 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $pdf->setColumnsSize(50, 50); $recipient_name = ''; + $due = ''; if ($job->fields['users_id_recipient']) { $recipient = new User(); $recipient->getFromDB($job->fields['users_id_recipient']); $recipient_name = $recipient->getName(); } - - $sla = $due = $commentsla = ''; if ($job->fields['time_to_resolve']) { $due = '' . sprintf( - __('%1$s: %2$s'), - __('Time to resolve') . '', + __s('%1$s: %2$s'), + __s('Time to resolve') . '', Html::convDateTime($job->fields['time_to_resolve']), ); } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Opening date') . '', + __s('%1$s: %2$s'), + __s('Opening date') . '', Html::convDateTime($job->fields['date']), ), $due, @@ -87,29 +86,29 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('By') . '', $recipient_name), - '' . sprintf(__('%1$s: %2$s'), __('Last update') . '', $lastupdate), + '' . sprintf(__s('%1$s: %2$s'), __s('By') . '', $recipient_name), + '' . sprintf(__s('%1$s: %2$s'), __s('Last update') . '', $lastupdate), ); $status = ''; if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { - $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['solvedate'])); + $status = sprintf(__s('%1$s %2$s'), '-', Html::convDateTime($job->fields['solvedate'])); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['closedate'])); + $status = sprintf(__s('%1$s %2$s'), '-', Html::convDateTime($job->fields['closedate'])); } if ($job->fields['status'] == Ticket::WAITING) { $status = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), '-', Html::convDateTime($job->fields['begin_waiting_date']), ); @@ -117,42 +116,42 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Status') . '', + __s('%1$s: %2$s'), + __s('Status') . '', Toolbox::stripTags($job->getStatus($job->fields['status'])) . $status, ), '' . sprintf( - __('%1$s: %2$s'), - __('Urgency') . '', + __s('%1$s: %2$s'), + __s('Urgency') . '', Toolbox::stripTags($job->getUrgencyName($job->fields['urgency'])), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Impact') . '', + __s('%1$s: %2$s'), + __s('Impact') . '', Toolbox::stripTags($job->getImpactName($job->fields['impact'])), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Total duration') . '', + __s('%1$s: %2$s'), + __s('Total duration') . '', Toolbox::stripTags(CommonITILObject::getActionTime($job->fields['actiontime'])), ), '' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Toolbox::stripTags($job->getPriorityName($job->fields['priority'])), ), ); @@ -161,7 +160,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) // Requester $users = []; $listusers = ''; - $requester = '' . sprintf(__('%1$s: %2$s') . '', __('Requester'), $listusers); + $requester = '' . sprintf(__s('%1$s: %2$s') . '', __s('Requester'), $listusers); foreach ($job->getUsers(CommonITILActor::REQUESTER) as $d) { if ($d['users_id']) { $tmp = Toolbox::stripTags($dbu->getUserName($d['users_id'])); @@ -181,8 +180,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $groups = []; $listgroups = ''; $requestergroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Requester group'), + __s('%1$s: %2$s') . '', + __s('Requester group'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::REQUESTER) as $d) { @@ -197,7 +196,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) // Observer $users = []; $listusers = ''; - $watcher = '' . sprintf(__('%1$s: %2$s') . '', __('Watcher'), $listusers); + $watcher = '' . sprintf(__s('%1$s: %2$s') . '', __s('Watcher'), $listusers); foreach ($job->getUsers(CommonITILActor::OBSERVER) as $d) { if ($d['users_id']) { $tmp = Toolbox::stripTags($dbu->getUserName($d['users_id'])); @@ -217,8 +216,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $groups = []; $listgroups = ''; $watchergroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Watcher group'), + __s('%1$s: %2$s') . '', + __s('Watcher group'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::OBSERVER) as $d) { @@ -234,8 +233,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $users = []; $listusers = ''; $assign = '' . sprintf( - __('%1$s: %2$s') . '', - __('Technician as assigned'), + __s('%1$s: %2$s') . '', + __s('Technician as assigned'), $listusers, ); foreach ($job->getUsers(CommonITILActor::ASSIGN) as $d) { @@ -257,16 +256,16 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $groups = []; $listgroups = ''; $assigngroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Technician group'), + __s('%1$s: %2$s') . '', + __s('Technician group'), $listgroups, ); 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); @@ -277,8 +276,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $suppliers = []; $listsuppliers = ''; $assignsupplier = '' . sprintf( - __('%1$s: %2$s') . '', - __('Supplier'), + __s('%1$s: %2$s') . '', + __s('Supplier'), $listsuppliers, ); foreach ($job->getSuppliers(CommonITILActor::ASSIGN) as $d) { @@ -294,11 +293,11 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) $pdf->setColumnsSize(100); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Title') . '', $job->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Title') . '', $job->fields['name']), ); $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), __('Description') . '', ''), + '' . sprintf(__s('%1$s: %2$s'), __s('Description') . '', ''), Toolbox::stripTags($job->fields['content']), 1, ); @@ -309,45 +308,39 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Problem $job) public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Problem $job) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Analysis') . ''); + $pdf->displayTitle('' . __s('Analysis') . ''); $pdf->setColumnsSize(10, 90); $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)); + $pdf->displayText('' . sprintf(__s('%1$s: %2$s'), __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)); + $pdf->displayText('' . sprintf(__s('%1$s: %2$s'), __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', ), - )); + ); } - $pdf->displayText('' . sprintf(__('%1$s: %2$s'), __('Symptoms') . '', $text)); + $pdf->displayText('' . sprintf(__s('%1$s: %2$s'), __s('Symptoms') . '', $text)); $pdf->displaySpace(); } @@ -355,62 +348,57 @@ public static function pdfAnalysis(PluginPdfSimplePDF $pdf, Problem $job) public static function pdfStat(PluginPdfSimplePDF $pdf, Problem $job) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . _n('Date', 'Dates', 2) . ''); + $pdf->displayTitle('' . _sn('Date', 'Dates', 2) . ''); $pdf->setColumnsSize(50, 50); $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Opening date'), + __s('%1$s: %2$s'), + __s('Opening date'), Html::convDateTime($job->fields['date']), )); $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Time to resolve'), + __s('%1$s: %2$s'), + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), )); if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Resolution date'), + __s('%1$s: %2$s'), + __s('Resolution date'), Html::convDateTime($job->fields['solvedate']), )); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Closing date'), + __s('%1$s: %2$s'), + __s('Closing date'), Html::convDateTime($job->fields['closedate']), )); } $pdf->setColumnsSize(100); - $pdf->displayTitle('' . _n('Time', 'Times', 2) . ''); + $pdf->displayTitle('' . _sn('Time', 'Times', 2) . ''); - if (in_array($job->fields['status'], $job->getSolvedStatusArray()) - || in_array($job->fields['status'], $job->getClosedStatusArray())) { - if ($job->fields['solve_delay_stat'] > 0) { - $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Solution'), - Toolbox::stripTags(Html::timestampToString($job->fields['solve_delay_stat'], false)), - )); - } + if ((in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) && $job->fields['solve_delay_stat'] > 0) { + $pdf->displayLine(sprintf( + __s('%1$s: %2$s'), + __s('Solution'), + Toolbox::stripTags(Html::timestampToString($job->fields['solve_delay_stat'], false)), + )); } - if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - if ($job->fields['close_delay_stat'] > 0) { - $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Closing'), - Toolbox::stripTags(Html::timestampToString($job->fields['close_delay_stat'], false)), - )); - } + if (in_array($job->fields['status'], $job->getClosedStatusArray()) && $job->fields['close_delay_stat'] > 0) { + $pdf->displayLine(sprintf( + __s('%1$s: %2$s'), + __s('Closing'), + Toolbox::stripTags(Html::timestampToString($job->fields['close_delay_stat'], false)), + )); } if ($job->fields['waiting_duration'] > 0) { $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Pending'), + __s('%1$s: %2$s'), + __s('Pending'), Toolbox::stripTags(Html::timestampToString($job->fields['waiting_duration'], false)), )); } @@ -426,7 +414,7 @@ public function defineAllTabsPDF($options = []) if (Session::haveRight('problem', Problem::READALL) // for technician || Session::haveRight('followup', ITILFollowup::SEEPRIVATE)) { - $onglets['_private_'] = __('Private'); + $onglets['_private_'] = __s('Private'); } return $onglets; diff --git a/inc/problem_ticket.class.php b/inc/problem_ticket.class.php index 61a7ded..e1629ec 100644 --- a/inc/problem_ticket.class.php +++ b/inc/problem_ticket.class.php @@ -36,7 +36,7 @@ class PluginPdfProblem_Ticket extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Problem_Ticket()); + $this->obj = ($obj ?: new Problem_Ticket()); } public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) @@ -64,16 +64,13 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $result = $DB->request($query); $number = count($result); - $problems = []; - $used = []; - $pdf->setColumnsSize(100); - $title = '' . _n('Problem', 'Problems', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('Problem', 'Problems', $number) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d problem', 'Last %d problems', $number) . '', + _sn('Last %d problem', 'Last %d problems', $number) . '', $number, )); @@ -85,17 +82,17 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . sprintf( - __('%1$s: %2$s'), - __('Status'), + __s('%1$s: %2$s'), + __s('Status'), Problem::getStatus($job->fields['status']), ); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName( 'glpi_entities', @@ -109,15 +106,15 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if ($job->fields['begin_waiting_date']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Put on hold on %s') . '', + __s('Put on hold on %s') . '', Html::convDateTime($job->fields['begin_waiting_date']), ), ); @@ -125,31 +122,31 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -159,29 +156,29 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Ticket::getPriorityName($job->fields['priority']), )); if ($job->fields['itilcategories_id']) { $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], @@ -197,28 +194,28 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -227,7 +224,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -238,28 +235,28 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -268,11 +265,11 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); } } @@ -303,16 +300,13 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $result = $DB->request($query); $number = count($result); - $problems = []; - $used = []; - $pdf->setColumnsSize(100); - $title = '' . _n('Ticket', 'Tickets', 2) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('Ticket', 'Tickets', 2) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { $pdf->displayTitle('' . sprintf( - _n('Last %d ticket', 'Last %d tickets', $number) . '', + _sn('Last %d ticket', 'Last %d tickets', $number) . '', $number, )); @@ -324,17 +318,17 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $pdf->setColumnsAlign('center'); $col = 'ID ' . $job->fields['id'] . ', ' . sprintf( - __('%1$s: %2$s'), - __('Status'), + __s('%1$s: %2$s'), + __s('Status'), Problem::getStatus($job->fields['status']), ); if (count($_SESSION['glpiactiveentities']) > 1) { if ($job->fields['entities_id'] == 0) { - $col = sprintf(__('%1$s (%2$s)'), $col, __('Root entity')); + $col = sprintf(__s('%1$s (%2$s)'), $col, __s('Root entity')); } else { $col = sprintf( - __('%1$s (%2$s)'), + __s('%1$s (%2$s)'), $col, Dropdown::getDropdownName( 'glpi_entities', @@ -348,37 +342,37 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $pdf->setColumnsAlign('left'); $col = '' . sprintf( - __('Opened on %s') . '', + __s('Opened on %s') . '', Html::convDateTime($job->fields['date']), ); if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Solved on %s') . '', + __s('Solved on %s') . '', Html::convDateTime($job->fields['solvedate']), ), ); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('Closed on %s') . '', + __s('Closed on %s') . '', Html::convDateTime($job->fields['closedate']), ), ); } if ($job->fields['time_to_resolve']) { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, '' . sprintf( - __('%1$s: %2$s') . '', - __('Time to resolve'), + __s('%1$s: %2$s') . '', + __s('Time to resolve'), Html::convDateTime($job->fields['time_to_resolve']), ), ); @@ -388,28 +382,28 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Last update') . '', + __s('%1$s: %2$s'), + __s('Last update') . '', $lastupdate, )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Ticket::getPriorityName($job->fields['priority']), )); if ($job->fields['itilcategories_id']) { $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], @@ -425,28 +419,28 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::REQUESTER); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -455,7 +449,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s'), __('Requester') . '', ''); + $texte = '' . sprintf(__s('%1$s: %2$s'), __s('Requester') . '', ''); $pdf->displayText($texte, $col, 1); } @@ -466,28 +460,28 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) if (empty($col)) { $col = $dbu->getUserName($d['users_id']); } else { - $col = sprintf(__('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); + $col = sprintf(__s('%1$s, %2$s'), $col, $dbu->getUserName($d['users_id'])); } } } $grps = $job->getGroups(CommonITILActor::ASSIGN); if (count($grps)) { if (empty($col)) { - $col = sprintf(__('%1$s %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } else { - $col = sprintf(__('%1$s - %2$s'), $col, _n('Group', 'Groups', 2) . ' '); + $col = sprintf(__s('%1$s - %2$s'), $col, _sn('Group', 'Groups', 2) . ' '); } $first = true; foreach ($grps as $d) { if ($first) { $col = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); } else { $col = sprintf( - __('%1$s, %2$s'), + __s('%1$s, %2$s'), $col, Dropdown::getDropdownName('glpi_groups', $d['groups_id']), ); @@ -496,29 +490,25 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $problem) } } if ($col) { - $texte = '' . sprintf(__('%1$s: %2$s') . '', __('Assigned to'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', __s('Assigned to'), ''); $pdf->displayText($texte, $col, 1); } - $texte = '' . sprintf(__('%1$s: %2$s') . '', ('Title'), ''); + $texte = '' . sprintf(__s('%1$s: %2$s') . '', ('Title'), ''); $pdf->displayText($texte, $job->fields['name'], 1); $item_col = ''; $item_ticket = new Item_Ticket(); $data = $item_ticket->find(['tickets_id' => $job->fields['id']]); foreach ($data as $val) { - if (!empty($val['itemtype']) && ($val['items_id'] > 0)) { - if ($object = $dbu->getItemForItemtype($val['itemtype'])) { - if ($object->getFromDB($val['items_id'])) { - $item_col .= $object->getTypeName(); - $item_col .= ' - ' . $object->getNameID() . '
'; - } - } + if (!empty($val['itemtype']) && $val['items_id'] > 0 && ($object = $dbu->getItemForItemtype($val['itemtype'])) && $object->getFromDB($val['items_id'])) { + $item_col .= $object->getTypeName(); + $item_col .= ' - ' . $object->getNameID() . '
'; } } $texte = '' . sprintf( - __('%1$s: %2$s') . '', - __('Items of the ticket', 'behaviors'), + __s('%1$s: %2$s') . '', + __s('Items of the ticket', 'behaviors'), '', ); $pdf->displayText($texte, $item_col, 1); diff --git a/inc/problemtask.class.php b/inc/problemtask.class.php index aa99ff4..0d19cc8 100755 --- a/inc/problemtask.class.php +++ b/inc/problemtask.class.php @@ -36,7 +36,7 @@ class PluginPdfProblemTask extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new ProblemTask()); + $this->obj = ($obj ?: new ProblemTask()); } public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $job) @@ -61,23 +61,23 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $job) $pdf->setColumnsSize(100); $title = '' . ProblemTask::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); + $title = sprintf(__s('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(30, 10, 20, 20, 20); $pdf->displayTitle( - '' . __('Type'), - __('Date'), - __('Duration'), - __('Writer'), - __('Planning') . '', + '' . __s('Type'), + __s('Date'), + __s('Duration'), + __s('Writer'), + __s('Planning') . '', ); foreach ($result as $id => $data) { @@ -90,34 +90,30 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $job) } else { if (isset($data['state']) && $data['state']) { $planification = sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('item', 'State'), Planning::getState($data['state']), ); } $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('Begin'), + __s('%1$s: %2$s'), + __s('Begin'), Html::convDateTime($data['begin']), ); $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('End'), + __s('%1$s: %2$s'), + __s('End'), Html::convDateTime($data['end']), ); $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('By'), + __s('%1$s: %2$s'), + __s('By'), $dbu->getUserName($data['users_id_tech']), ); } - if ($data['taskcategories_id']) { - $lib = Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']); - } else { - $lib = ''; - } + $lib = $data['taskcategories_id'] ? Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']) : ''; $pdf->displayLine( '' . Toolbox::stripTags($lib), Html::convDateTime($data['date']), @@ -127,7 +123,7 @@ public static function pdfForProblem(PluginPdfSimplePDF $pdf, Problem $job) 1, ); $pdf->displayText( - '' . sprintf(__('%1$s: %2$s') . '', __('Description'), ''), + '' . sprintf(__s('%1$s: %2$s') . '', __s('Description'), ''), Toolbox::stripTags($data['content']), 1, ); diff --git a/inc/profile.class.php b/inc/profile.class.php index 8f40a86..3621642 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -34,12 +34,17 @@ class PluginPdfProfile extends Profile { public static $rightname = 'profile'; + public static function getTypeName($nb = 0) + { + return _sn('PDF export', 'PDF export', $nb, 'pdf'); + } + public function rawSearchOptions() { $tab = []; $tab[] = ['id' => 'common', - 'name' => __('Print to pdf', 'pdf')]; + 'name' => __s('PDF export', 'pdf')]; $tab[] = ['id' => '2', @@ -67,11 +72,11 @@ public function showForm($ID, $options = []) $checked = 1; } echo ""; - echo "'; echo ""; - echo '
" . __('Print to pdf', 'pdf'); + echo "
" . __s('PDF export', 'pdf'); echo '
' . __('Print to pdf', 'pdf') . ''; + echo '' . __s('PDF export', 'pdf') . ''; Html::showCheckbox(['name' => '_plugin_pdf', 'checked' => $checked]); echo "
\n"; @@ -91,7 +96,7 @@ public function showForm($ID, $options = []) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item->getType() == 'Profile') { - return __('Print to pdf', 'pdf'); + return self::createTabEntry(self::getTypeName(), 0, $item::getType(), PluginPdfConfig::getIcon()); } return ''; @@ -99,7 +104,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if ($item instanceof \Profile) { + if ($item instanceof Profile) { $prof = new self(); $ID = $item->getField('id'); $prof->showForm($ID); @@ -147,7 +152,7 @@ public static function createFirstAccess($ID) public static function getAllRights($all = false) { $rights = [['itemtype' => 'PluginPdf', - 'label' => __('Print to pdf', 'pdf'), + 'label' => __s('PDF export', 'pdf'), 'field' => 'plugin_pdf']]; return $rights; @@ -172,8 +177,7 @@ public static function initProfile() } foreach ($DB->request( - 'glpi_profilerights', - ['profiles_id' => $_SESSION['glpiactiveprofile']['id'], + ['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/remote.class.php b/inc/remote.class.php deleted file mode 100644 index fe18e67..0000000 --- a/inc/remote.class.php +++ /dev/null @@ -1,158 +0,0 @@ -. - * - * @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 - * -------------------------------------------------------------------------- - */ - -class PluginPdfRemote -{ - public static $rightname = 'plugin_pdf'; - - public static function methodGetTabs($params, $protocol) - { - /** @var array $PLUGIN_HOOKS */ - global $PLUGIN_HOOKS; - - if (isset($params['help'])) { - return ['help' => 'bool,optional', - 'type' => 'string']; - } - - if (!Session::getLoginUserID()) { - return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); - } - - if (!isset($params['type'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_MISSINGPARAMETER, - '', - 'type', - ); - } - $type = $params['type']; - - 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); - - return $itempdf->defineAllTabs(); - } - - return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_FAILED); - } - - public static function methodGetPdf($params, $protocol) - { - /** @var array $PLUGIN_HOOKS */ - global $PLUGIN_HOOKS; - - if (isset($params['help'])) { - return ['help' => 'bool,optional', - 'type' => 'string', - 'id' => 'integer', - 'landscape' => 'bool,optional', - 'tabs' => 'string,optional', - 'alltabs' => 'bool,optional']; - } - - if (!Session::getLoginUserID()) { - return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); - } - if (!isset($params['type'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_MISSINGPARAMETER, - '', - 'type', - ); - } - $dbu = new DbUtils(); - $type = $params['type']; - if (!$item = $dbu->getItemForItemtype($type)) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_BADPARAMETER, - '', - 'type', - ); - } - if (!isset($params['id'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_MISSINGPARAMETER, - '', - 'id', - ); - } - if (!is_numeric($params['id'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_BADPARAMETER, - '', - 'id', - ); - } - $id = intval($params['id']); - - $landscape = (isset($params['landscape']) ? intval($params['landscape']) : false); - - if (!$item->can($id, READ)) { - return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_NOTFOUND); - } - - if (isset($params['tabs'])) { - if (isset($params['alltabs'])) { - return PluginWebservicesMethodCommon::Error( - $protocol, - WEBSERVICES_ERROR_BADPARAMETER, - '', - 'tabs+alltabs', - ); - } - $tabs = explode(',', $params['tabs']); - } else { - $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); - if (isset($params['alltabs'])) { - $tabs = $itempdf->defineAllTabs(); - $tabs = array_keys($tabs); - } - $out = $itempdf->generatePDF([$id], $tabs, $landscape, false); - - return ['name' => "$type-$id.pdf", - 'base64' => base64_encode($out)]; - } - - return PluginWebservicesMethodCommon::Error($protocol, WEBSERVICES_ERROR_FAILED); - } -} diff --git a/inc/reservation.class.php b/inc/reservation.class.php index 1dc77af..69c4545 100644 --- a/inc/reservation.class.php +++ b/inc/reservation.class.php @@ -36,7 +36,7 @@ class PluginPdfReservation extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Reservation()); + $this->obj = ($obj ?: new Reservation()); } public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -70,12 +70,12 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); - if (!count($result)) { - $pdf->displayTitle('' . __('No current and future reservations', 'pdf') . ''); + if (count($result) === 0) { + $pdf->displayTitle('' . __s('No current and future reservations', 'pdf') . ''); } else { - $pdf->displayTitle('' . __('Current and future reservations') . ''); + $pdf->displayTitle('' . __s('Current and future reservations') . ''); $pdf->setColumnsSize(14, 14, 26, 46); - $pdf->displayTitle('' . __('Start date'), __('End date'), __('By'), __('Comments') . + $pdf->displayTitle('' . __s('Start date'), __s('End date'), __s('By'), __s('Comments') . ''); foreach ($result as $data) { @@ -110,12 +110,12 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) $pdf->setColumnsSize(100); - if (!count($result)) { - $pdf->displayTitle('' . __('No past reservations', 'pdf') . ''); + if (count($result) === 0) { + $pdf->displayTitle('' . __s('No past reservations', 'pdf') . ''); } else { - $pdf->displayTitle('' . __('Past reservations') . ''); + $pdf->displayTitle('' . __s('Past reservations') . ''); $pdf->setColumnsSize(14, 14, 26, 46); - $pdf->displayTitle('' . __('Start date'), __('End date'), __('By'), __('Comments') . + $pdf->displayTitle('' . __s('Start date'), __s('End date'), __s('By'), __s('Comments') . ''); foreach ($result as $data) { @@ -138,7 +138,7 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) } } } else { - $pdf->displayTitle('' . __('Item not reservable', 'pdf') . ''); + $pdf->displayTitle('' . __s('Item not reservable', 'pdf') . ''); } $pdf->displaySpace(); @@ -175,30 +175,26 @@ public static function pdfForUser(PluginPdfSimplePDF $pdf, User $user) $result = $DB->request($query); - if (!count($result)) { - $pdf->displayTitle('' . __('No current and future reservations', 'pdf') . ''); + if (count($result) === 0) { + $pdf->displayTitle('' . __s('No current and future reservations', 'pdf') . ''); } else { - $pdf->displayTitle('' . __('Current and future reservations') . ''); + $pdf->displayTitle('' . __s('Current and future reservations') . ''); $pdf->setColumnsSize(10, 10, 10, 20, 15, 35); $pdf->displayTitle( - '' . __('Start date'), - __('End date'), - __('Item'), - __('Entity'), - __('By'), - __('Comments') . + '' . __s('Start date'), + __s('End date'), + __s('Item'), + __s('Entity'), + __s('By'), + __s('Comments') . '', ); } $ri = new ReservationItem(); foreach ($result as $data) { - if ($ri->getFromDB($data['reservationitems_id'])) { - if ($item = getItemForItemtype($ri->fields['itemtype'])) { - if ($item->getFromDB($ri->fields['items_id'])) { - $name = $item->fields['name']; - } - } + if ($ri->getFromDB($data['reservationitems_id']) && ($item = getItemForItemtype($ri->fields['itemtype'])) && $item->getFromDB($ri->fields['items_id'])) { + $name = $item->fields['name']; } $pdf->displayLine( Html::convDateTime($data['begin']), @@ -228,29 +224,25 @@ public static function pdfForUser(PluginPdfSimplePDF $pdf, User $user) $result = $DB->request($query); - if (!count($result)) { - $pdf->displayTitle('' . __('No past reservations', 'pdf') . ''); + if (count($result) === 0) { + $pdf->displayTitle('' . __s('No past reservations', 'pdf') . ''); } else { - $pdf->displayTitle('' . __('Past reservations') . ''); + $pdf->displayTitle('' . __s('Past reservations') . ''); $pdf->setColumnsSize(10, 10, 10, 20, 15, 35); $pdf->displayTitle( - '' . __('Start date'), - __('End date'), - __('Item'), - __('Entity'), - __('By'), - __('Comments') . + '' . __s('Start date'), + __s('End date'), + __s('Item'), + __s('Entity'), + __s('By'), + __s('Comments') . '', ); } foreach ($result as $data) { - if ($ri->getFromDB($data['reservationitems_id'])) { - if ($item = getItemForItemtype($ri->fields['itemtype'])) { - if ($item->getFromDB($ri->fields['items_id'])) { - $name = $item->fields['name']; - } - } + if ($ri->getFromDB($data['reservationitems_id']) && ($item = getItemForItemtype($ri->fields['itemtype'])) && $item->getFromDB($ri->fields['items_id'])) { + $name = $item->fields['name']; } $pdf->displayLine( Html::convDateTime($data['begin']), diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 5c06d71..f1406f1 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -1,5 +1,37 @@ . + * + * @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 + * -------------------------------------------------------------------------- + */ + +use Glpi\RichText\RichText; + /** * ------------------------------------------------------------------------- * LICENSE @@ -78,7 +110,6 @@ public function __construct($format = 'A4', $orient = '') $pdf->SetCreator('GLPI'); $pdf->SetAuthor('GLPI'); $font = 'helvetica'; - $fonsize = 8; if (isset($_SESSION['glpipdffont']) && $_SESSION['glpipdffont']) { $font = $_SESSION['glpipdffont']; } @@ -129,7 +160,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, ''); } } @@ -275,7 +306,7 @@ private function displayInternal($gray, $padd, $defalign, $miny, $msgs) $ln = 1; // down } $this->pdf->SetX($this->colsx[$i]); - $align = (isset($this->align[$i]) ? $this->align[$i] : $defalign); + $align = ($this->align[$i] ?? $defalign); $this->pdf->writeHTMLCell( $this->colsw[$i], // $w (float) Cell width. If 0, the cell extends up to the right margin. $max, // $h (float) Cell minimum height. The cell extends automatically if needed. @@ -345,18 +376,13 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100) $this->setColumnsSize(100); $text = $name . ' ' . $content; - $content = Glpi\RichText\RichText::getEnhancedHtml($text); + $content = RichText::getEnhancedHtml($text); if (!preg_match("//", $content) && !preg_match('/

/', $content)) { $content = nl2br($content); } $this->displayInternal(240, 0.5, self::LEFT, $minline * 5, [$content]); /* Restore */ - list( - $this->cols, - $this->colsx, - $this->colsw, - $this->align, - ) = $save; + [$this->cols, $this->colsx, $this->colsw, $this->align, ] = $save; } /** diff --git a/inc/software.class.php b/inc/software.class.php index 652d4c7..21a3526 100644 --- a/inc/software.class.php +++ b/inc/software.class.php @@ -36,7 +36,7 @@ class PluginPdfSoftware extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Software()); + $this->obj = ($obj ?: new Software()); } public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) @@ -46,10 +46,10 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) PluginPdfCommon::mainTitle($pdf, $software); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Name') . '', $software->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Name') . '', $software->fields['name']), '' . sprintf( - __('%1$s: %2$s'), - __('Publisher') . '', + __s('%1$s: %2$s'), + __s('Publisher') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_manufacturers', $software->fields['manufacturers_id'], @@ -59,16 +59,16 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Location') . '', + __s('%1$s: %2$s'), + __s('Location') . '', Dropdown::getDropdownName( 'glpi_locations', $software->fields['locations_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_softwarecategories', $software->fields['softwarecategories_id'], @@ -78,51 +78,51 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Technician in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Technician in charge of the hardware') . '', $dbu->getUserName($software->fields['users_id_tech']), ), '' . sprintf( - __('%1$s: %2$s'), - __('Associable to a ticket') . '', - ($software->fields['is_helpdesk_visible'] ? __('Yes') : __('No')), + __s('%1$s: %2$s'), + __s('Associable to a ticket') . '', + ($software->fields['is_helpdesk_visible'] ? __s('Yes') : __s('No')), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group in charge of the hardware') . '', + __s('%1$s: %2$s'), + __s('Group in charge of the hardware') . '', Dropdown::getDropdownName( 'glpi_groups', $software->fields['groups_id_tech'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('User') . '', + __s('%1$s: %2$s'), + __s('User') . '', $dbu->getUserName($software->fields['users_id']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Group') . '', + __s('%1$s: %2$s'), + __s('Group') . '', Dropdown::getDropdownName('glpi_groups', $software->fields['groups_id']), ), ); $pdf->displayLine( '' . sprintf( - __('Last update on %s'), + __s('Last update on %s'), Html::convDateTime($software->fields['date_mod']), ), ); if ($software->fields['softwares_id'] > 0) { - $col2 = ' ' . __('from') . ' ' . + $col2 = ' ' . __s('from') . ' ' . Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwares', $software->fields['softwares_id'], @@ -133,9 +133,9 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Upgrade') . '', - ($software->fields['is_update'] ? __('Yes') : __('No')), + __s('%1$s: %2$s'), + __s('Upgrade') . '', + ($software->fields['is_update'] ? __s('Yes') : __s('No')), $col2, ), ); diff --git a/inc/softwarelicense.class.php b/inc/softwarelicense.class.php index f8db310..3f71264 100644 --- a/inc/softwarelicense.class.php +++ b/inc/softwarelicense.class.php @@ -36,7 +36,7 @@ class PluginPdfSoftwareLicense extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new SoftwareLicense()); + $this->obj = ($obj ?: new SoftwareLicense()); } public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareLicense $license, $main = true, $cpt = true) @@ -48,13 +48,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareLicense $license if (Session::isMultiEntitiesMode() && !$main) { $entity = ' (' . Dropdown::getDropdownName('glpi_entities', $license->fields['entities_id']) . ')'; } - $pdf->displayTitle('' . sprintf(__('%1$s: %2$s'), __('ID') . '', $ID . '' . $entity)); + $pdf->displayTitle('' . sprintf(__s('%1$s: %2$s'), __s('ID') . '', $ID . '' . $entity)); $pdf->setColumnsSize(50, 50); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), Software::getTypeName(1) . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwares', @@ -62,8 +62,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareLicense $license )), ), '' . sprintf( - __('%1$s: %2$s'), - __('Type') . '', + __s('%1$s: %2$s'), + __s('Type') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwarelicensetypes', $license->fields['softwarelicensetypes_id'], @@ -73,45 +73,45 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareLicense $license $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Name') . '', + __s('%1$s: %2$s'), + __s('Name') . '', $license->fields['name'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Serial number') . '', + __s('%1$s: %2$s'), + __s('Serial number') . '', $license->fields['serial'], ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Purchase version') . '', + __s('%1$s: %2$s'), + __s('Purchase version') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwareversions', $license->fields['softwareversions_id_buy'], )), ), '' . sprintf( - __('%1$s: %2$s'), - __('Inventory number') . '', + __s('%1$s: %2$s'), + __s('Inventory number') . '', $license->fields['otherserial'], ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Version in use') . '', + __s('%1$s: %2$s'), + __s('Version in use') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwareversions', $license->fields['softwareversions_id_use'], )), ), '' . sprintf( - __('%1$s: %2$s'), - __('Expiration') . '', + __s('%1$s: %2$s'), + __s('Expiration') . '', Html::convDate($license->fields['expire']), ), ); @@ -119,17 +119,17 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareLicense $license $col2 = ''; if ($cpt) { $col2 = '' . sprintf( - __('%1$s: %2$s'), - __('Affected computers') . '', + __s('%1$s: %2$s'), + __s('Affected computers') . '', Item_SoftwareLicense::countForLicense($ID), ); } $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('quantity', 'Number') . '', (($license->fields['number'] > 0) ? $license->fields['number'] - : __('Unlimited')), + : __s('Unlimited')), ), $col2, ); @@ -161,30 +161,30 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $softwar $number = count($result); $pdf->setColumnsSize(100); - $title = '' . _n('License', 'Licenses', $number) . ''; + $title = '' . _sn('License', 'Licenses', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(15, 15, 10, 10, 10, 10, 10, 10, 10); $pdf->setColumnsAlign('left', 'left', 'left', 'right', 'right'); $pdf->displayTitle( - '' . __('Name') . '', - '' . __('Entity') . '', - '' . __('Serial number') . '', + '' . __s('Name') . '', + '' . __s('Entity') . '', + '' . __s('Serial number') . '', '' . _x('quantity', 'Number') . '', - '' . __('Affected computers') . '', - '' . __('Type') . '', - '' . __('Purchase version') . '', - '' . __('Version in use') . '', - '' . __('Expiration') . '', + '' . __s('Affected computers') . '', + '' . __s('Type') . '', + '' . __s('Purchase version') . '', + '' . __s('Version in use') . '', + '' . __s('Expiration') . '', ); $totnbre = $totaffect = 0; foreach ($result as $data) { @@ -197,7 +197,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $softwar Dropdown::getDropdownName('glpi_entities', $license->fields['entities_id']), $license->fields['serial'], ($license->fields['number'] > 0) ? $license->fields['number'] - : __('Unlimited'), + : __s('Unlimited'), Item_SoftwareLicense::countForLicense($license->getField('id')), Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwarelicensetypes', @@ -218,7 +218,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $softwar $pdf->displayLine( ' ', ' ', - '' . __('Total') . '', + '' . __s('Total') . '', '' . $totnbre . '', '' . $totaffect . '', ' ', diff --git a/inc/softwareversion.class.php b/inc/softwareversion.class.php index a4dc3b3..3c1fb1b 100644 --- a/inc/softwareversion.class.php +++ b/inc/softwareversion.class.php @@ -36,7 +36,7 @@ class PluginPdfSoftwareVersion extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new SoftwareVersion()); + $this->obj = ($obj ?: new SoftwareVersion()); } public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareVersion $version) @@ -44,15 +44,15 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareVersion $version $ID = $version->getField('id'); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . sprintf(__('%1$s: %2$s'), __('ID') . '', $ID . '')); + $pdf->displayTitle('' . sprintf(__s('%1$s: %2$s'), __s('ID') . '', $ID . '')); $pdf->setColumnsSize(50, 50); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Name') . '', $version->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Name') . '', $version->fields['name']), '' . sprintf( - __('%1$s: %2$s'), - _n('Software', 'Software', 2) . '', + __s('%1$s: %2$s'), + _sn('Software', 'Software', 2) . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_softwares', $version->fields['softwares_id'], @@ -62,16 +62,16 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, SoftwareVersion $version $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Status') . '', + __s('%1$s: %2$s'), + __s('Status') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_states', $version->fields['states_id'], )), ), '' . sprintf( - __('%1$s: %2$s'), - __('Operating system') . '', + __s('%1$s: %2$s'), + __s('Operating system') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_operatingsystems', $version->fields['operatingsystems_id'], @@ -110,23 +110,23 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $item) $pdf->setColumnsSize(100); $title = '' . SoftwareVersion::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $_SESSION['glpilist_limit'] . ' / ' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(13, 13, 30, 14, 30); $pdf->displayTitle( '' . $title . '', - '' . __('Status') . '', - '' . __('Operating system') . '', - '' . _n('Installation', 'Installations', 2) . '', - '' . __('Comments') . '', + '' . __s('Status') . '', + '' . __s('Operating system') . '', + '' . _sn('Installation', 'Installations', 2) . '', + '' . __s('Comments') . '', ); $pdf->setColumnsAlign('left', 'left', 'left', 'right', 'left'); @@ -143,7 +143,7 @@ public static function pdfForSoftware(PluginPdfSimplePDF $pdf, Software $item) $tot += $nb; } $pdf->setColumnsAlign('left', 'right', 'left', 'right', 'left'); - $pdf->displayTitle('', '', '' . sprintf(__('%1$s: %2$s'), __('Total') . '', ''), $tot, ''); + $pdf->displayTitle('', '', '' . sprintf(__s('%1$s: %2$s'), __s('Total') . '', ''), $tot, ''); } $pdf->displaySpace(); } diff --git a/inc/ticket.class.php b/inc/ticket.class.php index b74611c..a09d9ed 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -36,7 +36,7 @@ class PluginPdfTicket extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Ticket()); + $this->obj = ($obj ?: new Ticket()); } public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) @@ -53,7 +53,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $pdf->setColumnsSize(100); $pdf->displayTitle('' . - (empty($job->fields['name']) ? __('Without title') : $name = $job->fields['name']) . ''); + (empty($job->fields['name']) ? __s('Without title') : $name = $job->fields['name']) . ''); if (count($_SESSION['glpiactiveentities']) > 1) { $entity = ' (' . Dropdown::getDropdownName( @@ -71,33 +71,31 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $recipient->getFromDB($job->fields['users_id_recipient']); $recipient_name = $recipient->getName(); } - - $due = $commenttto = $commentttr = $interntto = ''; $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Opening date') . '', + __s('%1$s: %2$s'), + __s('Opening date') . '', Html::convDateTime($job->fields['date']), ), - '' . sprintf(__('%1$s: %2$s'), __('By') . '', $recipient_name), + '' . sprintf(__s('%1$s: %2$s'), __s('By') . '', $recipient_name), ); $ttr = '' . sprintf( - __('%1$s: %2$s'), - __('Time to resolve') . '', + __s('%1$s: %2$s'), + __s('Time to resolve') . '', Html::convDateTime($job->fields['time_to_resolve']), ); $tto = '' . sprintf( - __('%1$s: %2$s'), - __('Internal time to own') . '', + __s('%1$s: %2$s'), + __s('Internal time to own') . '', Html::convDateTime($job->fields['internal_time_to_own']), ); if ($job->fields['olas_id_tto'] > 0) { $tto .= '' . sprintf( - __('%1$s: %2$s'), - __('OLA') . '', + __s('%1$s: %2$s'), + __s('OLA') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_olas', $job->fields['olas_id_tto'], @@ -108,15 +106,15 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $nextaction = new OlaLevel_Ticket(); if ($nextaction->getFromDBForTicket($job->fields['id'], SLM::TTO)) { $tto .= '
' . sprintf( - __('%1$s: %2$s'), - sprintf(__('Next escalation: %s') . '', ''), + __s('%1$s: %2$s'), + sprintf(__s('Next escalation: %s') . '', ''), Html::convDateTime($nextaction->fields['date']), ); if ($olalevel->getFromDB($nextaction->fields['olalevels_id'])) { $tto .= ' ' . sprintf( - __('%1$s: %2$s'), - __('Escalation level') . '', + __s('%1$s: %2$s'), + __s('Escalation level') . '', $olalevel->getName(), ); } @@ -125,8 +123,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) if ($job->fields['slas_id_ttr'] > 0) { $ttr .= '' . sprintf( - __('%1$s: %2$s'), - __('SLA') . '', + __s('%1$s: %2$s'), + __s('SLA') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_slas', $job->fields['slas_id_ttr'], @@ -137,15 +135,15 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $nextaction = new SlaLevel_Ticket(); if ($nextaction->getFromDBForTicket($job->fields['id'], SLM::TTR)) { $ttr .= '
' . sprintf( - __('%1$s: %2$s'), - sprintf(__('Next escalation: %s') . '', ''), + __s('%1$s: %2$s'), + sprintf(__s('Next escalation: %s') . '', ''), Html::convDateTime($nextaction->fields['date']), ); if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) { $ttr .= ' ' . sprintf( - __('%1$s: %2$s'), - __('Escalation level') . '', + __s('%1$s: %2$s'), + __s('Escalation level') . '', $slalevel->getName(), ); } @@ -156,20 +154,20 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $lastupdate = Html::convDateTime($job->fields['date_mod']); if ($job->fields['users_id_lastupdater'] > 0) { $lastupdate = sprintf( - __('%1$s by %2$s'), + __s('%1$s by %2$s'), $lastupdate, $dbu->getUserName($job->fields['users_id_lastupdater']), ); } $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Last update') . '', $lastupdate), + '' . sprintf(__s('%1$s: %2$s'), __s('Last update') . '', $lastupdate), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Time to own') . '', + __s('%1$s: %2$s'), + __s('Time to own') . '', Html::convDateTime($job->fields['time_to_own']), ), $ttr, @@ -178,21 +176,21 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $pdf->displayLine( $tto, '' . sprintf( - __('%1$s: %2$s'), - __('Internal time to resolve') . '', + __s('%1$s: %2$s'), + __s('Internal time to resolve') . '', Html::convDateTime($job->fields['internal_time_to_resolve']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Type') . '', + __s('%1$s: %2$s'), + __s('Type') . '', Toolbox::stripTags(Ticket::getTicketTypeName($job->fields['type'])), ), '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_itilcategories', $job->fields['itilcategories_id'], @@ -203,15 +201,15 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $status = ''; if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { - $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['solvedate'])); + $status = sprintf(__s('%1$s %2$s'), '-', Html::convDateTime($job->fields['solvedate'])); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - $status = sprintf(__('%1$s %2$s'), '-', Html::convDateTime($job->fields['closedate'])); + $status = sprintf(__s('%1$s %2$s'), '-', Html::convDateTime($job->fields['closedate'])); } if ($job->fields['status'] == Ticket::WAITING) { $status = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), '-', Html::convDateTime($job->fields['begin_waiting_date']), ); @@ -219,13 +217,13 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Status') . '', + __s('%1$s: %2$s'), + __s('Status') . '', Toolbox::stripTags($job->getStatus($job->fields['status'])) . $status, ), '' . sprintf( - __('%1$s: %2$s'), - __('Request source') . '', + __s('%1$s: %2$s'), + __s('Request source') . '', Toolbox::stripTags(Dropdown::getDropdownName( 'glpi_requesttypes', $job->fields['requesttypes_id'], @@ -235,26 +233,26 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Urgency') . '', + __s('%1$s: %2$s'), + __s('Urgency') . '', Toolbox::stripTags($job->getUrgencyName($job->fields['urgency'])), ), '' . sprintf( - __('%1$s: %2$s'), - __('Approval') . '', + __s('%1$s: %2$s'), + __s('Approval') . '', TicketValidation::getStatus($job->fields['global_validation']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Impact') . '', + __s('%1$s: %2$s'), + __s('Impact') . '', Toolbox::stripTags($job->getImpactName($job->fields['impact'])), ), '' . sprintf( - __('%1$s: %2$s'), - __('Location') . '', + __s('%1$s: %2$s'), + __s('Location') . '', Dropdown::getDropdownName( 'glpi_locations', $job->fields['locations_id'], @@ -264,8 +262,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Priority') . '', + __s('%1$s: %2$s'), + __s('Priority') . '', Toolbox::stripTags($job->getPriorityName($job->fields['priority'])), ), ); @@ -275,7 +273,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) // Requester $users = []; $listusers = ''; - $requester = '' . sprintf(__('%1$s: %2$s') . '', __('Requester'), $listusers); + $requester = '' . sprintf(__s('%1$s: %2$s') . '', __s('Requester'), $listusers); foreach ($job->getUsers(CommonITILActor::REQUESTER) as $d) { if ($d['users_id']) { $tmp = '' . Toolbox::stripTags($dbu->getUserName($d['users_id'])) . ''; @@ -287,52 +285,49 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) } $user = new User(); - if ($info = $user->getFromDB($d['users_id']) - && $infouser) { - if ($user->fields['phone'] || $user->fields['mobile'] - || $user->fields['usercategories_id'] || $user->fields['locations_id']) { - $tmp .= ' ('; - $first = true; - if ($user->fields['phone']) { - $tmp .= sprintf(__('%1$s: %2$s'), __('Phone'), $user->fields['phone']); - $first = false; - } - if ($user->fields['mobile']) { - if (!$first) { - $tmp .= ' - '; - } - $tmp .= sprintf(__('%1$s: %2$s'), __('Mobile phone'), $user->fields['mobile']); - $first = false; + if (($info = $user->getFromDB($d['users_id']) + && $infouser) && ($user->fields['phone'] || $user->fields['mobile'] || $user->fields['usercategories_id'] || $user->fields['locations_id'])) { + $tmp .= ' ('; + $first = true; + if ($user->fields['phone']) { + $tmp .= sprintf(__s('%1$s: %2$s'), __s('Phone'), $user->fields['phone']); + $first = false; + } + if ($user->fields['mobile']) { + if (!$first) { + $tmp .= ' - '; } - if ($user->fields['usercategories_id']) { - if (!$first) { - $tmp .= ' - '; - } - $tmp .= sprintf( - __('%1$s: %2$s'), - __('Category'), - Dropdown::getDropdownName( - 'glpi_usercategories', - $user->fields['usercategories_id'], - ), - ); - $first = false; + $tmp .= sprintf(__s('%1$s: %2$s'), __s('Mobile phone'), $user->fields['mobile']); + $first = false; + } + if ($user->fields['usercategories_id']) { + if (!$first) { + $tmp .= ' - '; } - if ($user->fields['locations_id']) { - if (!$first) { - $tmp .= ' - '; - } - $tmp .= sprintf( - __('%1$s: %2$s'), - __('Location'), - Dropdown::getDropdownName( - 'glpi_locations', - $user->fields['locations_id'], - ), - ); + $tmp .= sprintf( + __s('%1$s: %2$s'), + __s('Category'), + Dropdown::getDropdownName( + 'glpi_usercategories', + $user->fields['usercategories_id'], + ), + ); + $first = false; + } + if ($user->fields['locations_id']) { + if (!$first) { + $tmp .= ' - '; } - $tmp .= ')'; + $tmp .= sprintf( + __s('%1$s: %2$s'), + __s('Location'), + Dropdown::getDropdownName( + 'glpi_locations', + $user->fields['locations_id'], + ), + ); } + $tmp .= ')'; } $users[] = $tmp; } @@ -344,8 +339,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $groups = []; $listgroups = ''; $requestergroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Requester group'), + __s('%1$s: %2$s') . '', + __s('Requester group'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::REQUESTER) as $d) { @@ -360,7 +355,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) // Observer $users = []; $listusers = ''; - $watcher = '' . sprintf(__('%1$s: %2$s') . '', __('Watcher'), $listusers); + $watcher = '' . sprintf(__s('%1$s: %2$s') . '', __s('Watcher'), $listusers); foreach ($job->getUsers(CommonITILActor::OBSERVER) as $d) { if ($d['users_id']) { $tmp = Toolbox::stripTags($dbu->getUserName($d['users_id'])); @@ -380,8 +375,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $groups = []; $listgroups = ''; $watchergroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Watcher group'), + __s('%1$s: %2$s') . '', + __s('Watcher group'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::OBSERVER) as $d) { @@ -397,8 +392,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $users = []; $listusers = ''; $assign = '' . sprintf( - __('%1$s: %2$s') . '', - __('Assigned to technicians'), + __s('%1$s: %2$s') . '', + __s('Assigned to technicians'), $listusers, ); foreach ($job->getUsers(CommonITILActor::ASSIGN) as $d) { @@ -420,8 +415,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $groups = []; $listgroups = ''; $assigngroup = '' . sprintf( - __('%1$s: %2$s') . '', - __('Assigned to groups'), + __s('%1$s: %2$s') . '', + __s('Assigned to groups'), $listgroups, ); foreach ($job->getGroups(CommonITILActor::ASSIGN) as $d) { @@ -437,8 +432,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $suppliers = []; $listsuppliers = ''; $assignsupplier = '' . sprintf( - __('%1$s: %2$s') . '', - __('Assigned to a supplier'), + __s('%1$s: %2$s') . '', + __s('Assigned to a supplier'), $listsuppliers, ); foreach ($job->getSuppliers(CommonITILActor::ASSIGN) as $d) { @@ -454,10 +449,10 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) $pdf->setColumnsSize(100); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Title') . '', $job->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __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); @@ -472,28 +467,28 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) } $pdf->displayText( - '' . sprintf(__('%1$s: %2$s') . '', __('Description'), ''), + '' . sprintf(__s('%1$s: %2$s') . '', __s('Description'), ''), $content, 1, ); // Linked tickets - $tickets = Ticket_Ticket::getLinkedTicketsTo($ID); + $tickets = Ticket_Ticket::getLinkedTo(Ticket::class, $ID); if (count($tickets)) { $ticket = new Ticket(); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s') . '', - _n('Linked ticket', 'Linked tickets', 2), + __s('%1$s: %2$s') . '', + _sn('Linked ticket', 'Linked tickets', 2), '', )); foreach ($tickets as $linkID => $data) { $tmp = sprintf( - __('%1$s %2$s'), + __s('%1$s %2$s'), Ticket_Ticket::getLinkName($data['link']), - sprintf(__('%1$s %2$s'), __('ID'), $data['tickets_id']), + sprintf(__s('%1$s %2$s'), __s('ID'), $data['tickets_id']), ); if ($ticket->getFromDB($data['tickets_id'])) { - $tmp = sprintf(__('%1$s: %2$s'), $tmp, $ticket->getName()); + $tmp = sprintf(__s('%1$s: %2$s'), $tmp, $ticket->getName()); } $pdf->displayText('', $tmp, 1); } @@ -504,7 +499,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Ticket $job) public static function pdfStat(PluginPdfSimplePDF $pdf, Ticket $job) { - $now = time(); + time(); $date_creation = strtotime($job->fields['date']); $date_takeintoaccount = $date_creation + $job->fields['takeintoaccount_delay_stat']; if ($date_takeintoaccount == $date_creation) { @@ -512,79 +507,74 @@ public static function pdfStat(PluginPdfSimplePDF $pdf, Ticket $job) } $pdf->setColumnsSize(100); - $pdf->displayTitle('' . _n('Date', 'Dates', 2) . ''); + $pdf->displayTitle('' . _sn('Date', 'Dates', 2) . ''); $pdf->setColumnsSize(50, 50); $pdf->setColumnsAlign('right', 'left'); - $pdf->displayLine(Html::convDateTime($job->fields['date']), __('Opening date')); + $pdf->displayLine(Html::convDateTime($job->fields['date']), __s('Opening date')); if (!empty($job->fields['internal_time_to_own'])) { $pdf->displayLine( Html::convDateTime($job->fields['internal_time_to_own']), - __('Internal time to own'), + __s('Internal time to own'), ); } if (!empty($job->fields['takeintoaccount_delay_stat'])) { $pdf->displayLine( Html::convDateTime(date('Y-m-d H:i:s', $date_takeintoaccount)), - __('Take into account'), + __s('Take into account'), ); } if (!empty($job->fields['time_to_own'])) { - $pdf->displayLine(Html::convDateTime($job->fields['time_to_own']), __('Time to own')); + $pdf->displayLine(Html::convDateTime($job->fields['time_to_own']), __s('Time to own')); } if (!empty($job->fields['internal_time_to_resolve'])) { $pdf->displayLine( Html::convDateTime($job->fields['internal_time_to_resolve']), - __('Internal time to resolve'), + __s('Internal time to resolve'), ); } if (!empty($job->fields['time_to_resolve'])) { $pdf->displayLine( Html::convDateTime($job->fields['time_to_resolve']), - __('Time to resolve'), + __s('Time to resolve'), ); } if (in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) { - $pdf->displayLine(Html::convDateTime($job->fields['solvedate']), __('Resolution date')); + $pdf->displayLine(Html::convDateTime($job->fields['solvedate']), __s('Resolution date')); } if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - $pdf->displayLine(Html::convDateTime($job->fields['closedate']), __('Closing date')); + $pdf->displayLine(Html::convDateTime($job->fields['closedate']), __s('Closing date')); } $pdf->setColumnsSize(100); - $pdf->displayTitle('' . _n('Time', 'Times', 2) . ''); + $pdf->displayTitle('' . _sn('Time', 'Times', 2) . ''); $pdf->setColumnsSize(50, 50); if ($job->fields['takeintoaccount_delay_stat'] > 0) { $pdf->displayLine( - __('Take into account'), + __s('Take into account'), Toolbox::stripTags(Html::timestampToString($job->fields['takeintoaccount_delay_stat'], false)), ); } - if (in_array($job->fields['status'], $job->getSolvedStatusArray()) - || in_array($job->fields['status'], $job->getClosedStatusArray())) { - if ($job->fields['solve_delay_stat'] > 0) { - $pdf->displayLine( - __('Solution'), - Toolbox::stripTags(Html::timestampToString($job->fields['solve_delay_stat'], false)), - ); - } + if ((in_array($job->fields['status'], $job->getSolvedStatusArray()) || in_array($job->fields['status'], $job->getClosedStatusArray())) && $job->fields['solve_delay_stat'] > 0) { + $pdf->displayLine( + __s('Solution'), + Toolbox::stripTags(Html::timestampToString($job->fields['solve_delay_stat'], false)), + ); } - if (in_array($job->fields['status'], $job->getClosedStatusArray())) { - if ($job->fields['close_delay_stat'] > 0) { - $pdf->displayLine( - __('Closing'), - Toolbox::stripTags(Html::timestampToString($job->fields['close_delay_stat'], true)), - ); - } + if (in_array($job->fields['status'], $job->getClosedStatusArray()) && $job->fields['close_delay_stat'] > 0) { + $pdf->displayLine( + __s('Closing'), + Toolbox::stripTags(Html::timestampToString($job->fields['close_delay_stat'], true)), + ); } if ($job->fields['waiting_duration'] > 0) { $pdf->displayLine( - __('Pending'), + __s('Pending'), Toolbox::stripTags(Html::timestampToString($job->fields['waiting_duration'], false)), ); } @@ -601,11 +591,11 @@ public function defineAllTabsPDF($options = []) if (Session::haveRight('ticket', Ticket::READALL) // for technician || Session::haveRight('followup', ITILFollowup::SEEPRIVATE) || Session::haveRight('task', TicketTask::SEEPRIVATE)) { - $onglets['_private_'] = __('Private'); + $onglets['_private_'] = __s('Private'); } if (Session::haveRight('user', READ)) { - $onglets['_inforequester_'] = __('Requester information', 'pdf'); + $onglets['_inforequester_'] = __s('Requester information', 'pdf'); } return $onglets; diff --git a/inc/ticket_contract.class.php b/inc/ticket_contract.class.php index 1ee269c..ee33a23 100644 --- a/inc/ticket_contract.class.php +++ b/inc/ticket_contract.class.php @@ -36,7 +36,7 @@ class PluginPdfTicket_Contract extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new Ticket_Contract()); + $this->obj = ($obj ?: new Ticket_Contract()); } public static function pdfForTicket(PluginPdfSimplePDF $pdf, CommonDBTM $item) @@ -46,7 +46,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, CommonDBTM $item) $type = $item->getType(); $ID = $item->getField('id'); - $itemtable = getTableForItemType($type); + getTableForItemType($type); $con = new Contract(); $dbu = new DbUtils(); @@ -63,21 +63,21 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, CommonDBTM $item) $number = count($result); $pdf->setColumnsSize(100); - $title = '' . _n('Associated contract', 'Associated contracts', $number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $title = '' . _sn('Associated contract', 'Associated contracts', $number) . ''; + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, $number)); + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, $number)); $pdf->setColumnsSize(19, 19, 15, 10, 16, 11, 10); $pdf->displayTitle( - __('Name'), - __('Entity'), + __s('Name'), + __s('Entity'), _x('phone', 'Number'), - __('Contract type'), - __('Supplier'), - __('Start date'), - __('Initial contract period'), + __s('Contract type'), + __s('Supplier'), + __s('Start date'), + __s('Initial contract period'), ); foreach ($result as $row) { @@ -88,7 +88,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, CommonDBTM $item) $textduration = ''; if ($con->fields['duration'] > 0) { $textduration = sprintf( - __('Valid to %s'), + __s('Valid to %s'), Infocom::getWarrantyExpir( $con->fields['begin_date'], $con->fields['duration'], @@ -106,9 +106,9 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, CommonDBTM $item) str_replace('
', ' ', $con->getSuppliersNames()), Html::convDate($con->fields['begin_date']), sprintf( - __('%1$s - %2$s'), + __s('%1$s - %2$s'), sprintf( - _n('%d month', '%d months', $con->fields['duration']), + _sn('%d month', '%d months', $con->fields['duration']), $con->fields['duration'], ), $textduration, diff --git a/inc/ticketsatisfaction.class.php b/inc/ticketsatisfaction.class.php index 6d4555a..09fbecd 100644 --- a/inc/ticketsatisfaction.class.php +++ b/inc/ticketsatisfaction.class.php @@ -36,7 +36,7 @@ class PluginPdfTicketSatisfaction extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new TicketSatisfaction()); + $this->obj = ($obj ?: new TicketSatisfaction()); } public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) @@ -44,44 +44,44 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $survey = new TicketSatisfaction(); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Satisfaction survey') . ''); + $pdf->displayTitle('' . __s('Satisfaction survey') . ''); if (!$survey->getFromDB($ticket->getID())) { - $pdf->displayLine(__('No generated survey')); + $pdf->displayLine(__s('No generated survey')); } elseif ($survey->getField('type') == 2) { $url = Entity::generateLinkSatisfaction($ticket); - $pdf->displayLine(sprintf(__('%1$s (%2$s)'), __('External survey'), $url)); + $pdf->displayLine(sprintf(__s('%1$s (%2$s)'), __s('External survey'), $url)); } elseif ($survey->getField('date_answered')) { $sat = $survey->getField('satisfaction'); - $tabsat = [0 => __('None'), - 1 => __('1 star', 'pdf'), - 2 => __('2 stars', 'pdf'), - 3 => __('3 stars', 'pdf'), - 4 => __('4 stars', 'pdf'), - 5 => __('5 stars', 'pdf')]; + $tabsat = [0 => __s('None'), + 1 => __s('1 star', 'pdf'), + 2 => __s('2 stars', 'pdf'), + 3 => __s('3 stars', 'pdf'), + 4 => __s('4 stars', 'pdf'), + 5 => __s('5 stars', 'pdf')]; if (isset($tabsat[$sat])) { $sat = $tabsat[$sat] . " ($sat/5)"; } $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Response date to the satisfaction survey') . '', + __s('%1$s: %2$s'), + __s('Response date to the satisfaction survey') . '', Html::convDateTime($survey->getField('date_answered')), )); $pdf->displayLine('' . sprintf( - __('%1$s: %2$s'), - __('Satisfaction with the resolution of the ticket') . '', + __s('%1$s: %2$s'), + __s('Satisfaction with the resolution of the ticket') . '', $sat, )); $pdf->displayText( - '' . sprintf(__('%1$s: %2$s'), __('Comments') . '', ''), + '' . sprintf(__s('%1$s: %2$s'), __s('Comments') . '', ''), $survey->getField('comment'), ); } else { // No answer $pdf->displayLine(sprintf( - __('%1$s: %2$s'), - __('Creation date of the satisfaction survey'), + __s('%1$s: %2$s'), + __s('Creation date of the satisfaction survey'), Html::convDateTime($survey->getField('date_begin')), )); - $pdf->displayLine(__('No answer', 'pdf')); + $pdf->displayLine(__s('No answer', 'pdf')); } $pdf->displaySpace(); } diff --git a/inc/tickettask.class.php b/inc/tickettask.class.php index ce14193..a1d1e1c 100644 --- a/inc/tickettask.class.php +++ b/inc/tickettask.class.php @@ -36,7 +36,7 @@ class PluginPdfTicketTask extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new TicketTask()); + $this->obj = ($obj ?: new TicketTask()); } public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job, $private) @@ -71,23 +71,23 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job, $priva $pdf->setColumnsSize(100); $title = '' . TicketTask::getTypeName($number) . ''; - if (!$number) { - $pdf->displayTitle(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + if ($number === 0) { + $pdf->displayTitle(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } else { if ($number > $_SESSION['glpilist_limit']) { - $title = sprintf(__('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); + $title = sprintf(__s('%1$s (%2$s)'), $title, $_SESSION['glpilist_limit'] . '/' . $number); } else { - $title = sprintf(__('%1$s: %2$s'), $title, $number); + $title = sprintf(__s('%1$s: %2$s'), $title, $number); } $pdf->displayTitle($title); $pdf->setColumnsSize(20, 20, 20, 20, 20); $pdf->displayTitle( - '' . __('Type'), - __('Date'), - __('Duration'), - __('Writer'), - __('Planning') . '', + '' . __s('Type'), + __s('Date'), + __s('Duration'), + __s('Writer'), + __s('Planning') . '', ); @@ -96,47 +96,43 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job, $priva $planification = ''; if (isset($data['state'])) { $planification = sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('item', 'State'), Planning::getState($data['state']), ); } if (!empty($data['begin'])) { $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('Begin'), + __s('%1$s: %2$s'), + __s('Begin'), Html::convDateTime($data['begin']), ); $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('End'), + __s('%1$s: %2$s'), + __s('End'), Html::convDateTime($data['end']), ); } if ($data['users_id_tech'] > 0) { $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('By user', 'pdf'), + __s('%1$s: %2$s'), + __s('By user', 'pdf'), $dbu->getUserName($data['users_id_tech']), ); } if ($data['groups_id_tech'] > 0) { $planification .= '
' . sprintf( - __('%1$s: %2$s'), - __('By group', 'pdf'), + __s('%1$s: %2$s'), + __s('By group', 'pdf'), Dropdown::getDropdownName( 'glpi_groups', $data['groups_id_tech'], ), ); } - if ($data['taskcategories_id']) { - $lib = Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']); - } else { - $lib = ''; - } + $lib = $data['taskcategories_id'] ? Dropdown::getDropdownName('glpi_taskcategories', $data['taskcategories_id']) : ''; if ($data['is_private']) { - $lib = sprintf(__('%1$s (%2$s)'), $lib, __('Private')); + $lib = sprintf(__s('%1$s (%2$s)'), $lib, __s('Private')); } $pdf->displayLine( @@ -146,7 +142,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); @@ -160,7 +156,7 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $job, $priva } $pdf->displayText( - "" . sprintf(__('%1$s: %2$s') . "", __('Description'), ''), + "" . sprintf(__s('%1$s: %2$s') . "", __s('Description'), ''), $content, 1, ); diff --git a/inc/ticketvalidation.class.php b/inc/ticketvalidation.class.php index bf1d617..366ba99 100644 --- a/inc/ticketvalidation.class.php +++ b/inc/ticketvalidation.class.php @@ -36,7 +36,7 @@ class PluginPdfTicketValidation extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new TicketValidation()); + $this->obj = ($obj ?: new TicketValidation()); } public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) @@ -47,29 +47,28 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) $dbu = new DbUtils(); $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Approvals for the ticket', 'pdf') . ''); + $pdf->displayTitle('' . __s('Approvals for the ticket', 'pdf') . ''); if (!Session::haveRightsOr('ticketvalidation', TicketValidation::getValidateRights())) { return false; } - $ID = $ticket->getField('id'); + $ticket->getField('id'); $result = $DB->request( - 'glpi_ticketvalidations', - ['WHERE' => ['tickets_id' => $ticket->getField('id')], + ['FROM' => 'glpi_ticketvalidations'] + ['WHERE' => ['tickets_id' => $ticket->getField('id')], 'ORDER' => 'submission_date DESC'], ); $number = count($result); - if ($number) { + if ($number !== 0) { $pdf->setColumnsSize(20, 19, 21, 19, 21); $pdf->displayTitle( _x('item', 'State'), - __('Request date'), - __('Approval requester'), - __('Approval date'), - __('Approver'), + __s('Request date'), + __s('Approval requester'), + __s('Approval date'), + __s('Approver'), ); foreach ($result as $row) { @@ -83,26 +82,26 @@ public static function pdfForTicket(PluginPdfSimplePDF $pdf, Ticket $ticket) ); $tmp = trim($row['comment_submission']); $pdf->displayText('' . sprintf( - __('%1$s: %2$s'), - __('Request comments') . '', + __s('%1$s: %2$s'), + __s('Request comments') . '', '', - ), (empty($tmp) ? __('None') : $tmp), 1); + ), (empty($tmp) ? __s('None') : $tmp), 1); if ($row['validation_date']) { $tmp = trim($row['comment_validation']); $pdf->displayText( '' . sprintf( - __('%1$s: %2$s'), - __('Approval comments') . '', + __s('%1$s: %2$s'), + __s('Approval comments') . '', '', ), - (empty($tmp) ? __('None') : $tmp), + (empty($tmp) ? __s('None') : $tmp), 1, ); } } } else { - $pdf->displayLine(__('No item found')); + $pdf->displayLine(__s('No item found')); } $pdf->displaySpace(); } diff --git a/inc/user.class.php b/inc/user.class.php index 98456cc..838d5c8 100644 --- a/inc/user.class.php +++ b/inc/user.class.php @@ -36,7 +36,7 @@ class PluginPdfUser extends PluginPdfCommon public function __construct(?CommonGLPI $obj = null) { - $this->obj = ($obj ? $obj : new User()); + $this->obj = ($obj ?: new User()); } public static function pdfMain(PluginPdfSimplePDF $pdf, User $item) @@ -44,31 +44,31 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, User $item) /** @var DBmysql $DB */ global $DB; - $ID = $item->getField('id'); + $item->getField('id'); $pdf->setColumnsSize(50, 50); $pdf->displayTitle( - '' . sprintf(__('%1$s %2$s'), __('ID'), $item->fields['id']) . '', + '' . sprintf(__s('%1$s %2$s'), __s('ID'), $item->fields['id']) . '', sprintf( - __('%1$s: %2$s'), - __('Last update'), + __s('%1$s: %2$s'), + __s('Last update'), Html::convDateTime($item->fields['date_mod']), ), ); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Login') . '', $item->fields['name']), + '' . sprintf(__s('%1$s: %2$s'), __s('Login') . '', $item->fields['name']), '' . sprintf( - __('Last login on %s') . '', + __s('Last login on %s') . '', Html::convDateTime($item->fields['last_login']), ), ); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Surname'), $item->fields['realname'] . ''), + '' . sprintf(__s('%1$s: %2$s'), __s('Surname'), $item->fields['realname'] . ''), '' . sprintf( - __('%1$s - %2$s'), - __('First name') . '', + __s('%1$s - %2$s'), + __s('First name') . '', $item->fields['firstname'], ), ); @@ -76,52 +76,48 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, User $item) $end = ''; if ($item->fields['end_date']) { $end = ' - ' . sprintf( - __('%1$s - %2$s'), - __('Valid until') . '', + __s('%1$s - %2$s'), + __s('Valid until') . '', Html::convDateTime($item->fields['end_date']), ); } $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Active') . '', $item->fields['is_active']), + '' . sprintf(__s('%1$s: %2$s'), __s('Active') . '', $item->fields['is_active']), '' . sprintf( - __('%1$s : %2$s'), - __('Valid since') . '', + __s('%1$s : %2$s'), + __s('Valid since') . '', Html::convDateTime($item->fields['begin_date']) . $end, ), ); $emails = []; - foreach ($DB->request('glpi_useremails', ['users_id' => $item->getField('id')]) as $key => $email) { - if ($email['is_default'] == 1) { - $emails[] = $email['email'] . ' (' . __('Default email') . ')'; - } else { - $emails[] = $email['email']; - } + foreach ($DB->request(['FROM' => 'glpi_useremails', 'WHERE' => ['users_id' => $item->getField('id')]]) as $key => $email) { + $emails[] = $email['is_default'] == 1 ? $email['email'] . ' (' . __s('Default email') . ')' : $email['email']; } $pdf->setColumnsSize(100); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - _n('Email', 'Emails', Session::getPluralNumber()) . '', + __s('%1$s: %2$s'), + _sn('Email', 'Emails', Session::getPluralNumber()) . '', implode(', ', $emails), ), ); $pdf->setColumnsSize(50, 50); $pdf->displayLine( - '' . sprintf(__('%1$s: %2$s'), __('Phone') . '', $item->fields['phone']), - '' . sprintf(__('%1$s: %2$s'), __('Phone 2') . '', $item->fields['phone2']), + '' . sprintf(__s('%1$s: %2$s'), __s('Phone') . '', $item->fields['phone']), + '' . sprintf(__s('%1$s: %2$s'), __s('Phone 2') . '', $item->fields['phone2']), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Mobile phone') . '', + __s('%1$s: %2$s'), + __s('Mobile phone') . '', $item->fields['mobile'], ), '' . sprintf( - __('%1$s: %2$s'), - __('Category') . '', + __s('%1$s: %2$s'), + __s('Category') . '', Dropdown::getDropdownName( 'glpi_usercategories', $item->fields['usercategories_id'], @@ -131,12 +127,12 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, User $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Administrative number') . '', + __s('%1$s: %2$s'), + __s('Administrative number') . '', $item->fields['registration_number'], ), '' . sprintf( - __('%1$s: %2$s'), + __s('%1$s: %2$s'), _x('person', 'Title') . '', Dropdown::getDropdownName( 'glpi_usertitles', @@ -147,32 +143,32 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, User $item) $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Location') . '', + __s('%1$s: %2$s'), + __s('Location') . '', Dropdown::getDropdownName( 'glpi_locations', $item->fields['locations_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Language') . '', + __s('%1$s: %2$s'), + __s('Language') . '', Dropdown::getLanguageName($item->fields['language']), ), ); $pdf->displayLine( '' . sprintf( - __('%1$s: %2$s'), - __('Default profile') . '', + __s('%1$s: %2$s'), + __s('Default profile') . '', Dropdown::getDropdownName( 'glpi_profiles', $item->fields['profiles_id'], ), ), '' . sprintf( - __('%1$s: %2$s'), - __('Default entity') . '', + __s('%1$s: %2$s'), + __s('Default entity') . '', Dropdown::getDropdownName( 'glpi_entities', $item->fields['entities_id'], @@ -200,14 +196,14 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, User $user, $tech) $type_group = $CFG_GLPI['linkgroup_tech_types']; $field_user = 'users_id_tech'; $field_group = 'groups_id_tech'; - $title = __('Managed items'); + $title = __s('Managed items'); $conso = false; } else { $type_user = $CFG_GLPI['linkuser_types']; $type_group = $CFG_GLPI['linkgroup_types']; $field_user = 'users_id'; $field_group = 'groups_id'; - $title = __('Used items'); + $title = __s('Used items'); $conso = true; } @@ -216,12 +212,12 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, User $user, $tech) $pdf->setColumnsSize(15, 15, 15, 15, 15, 15, 10); $pdf->displayTitle( - __('Type'), - __('Entity'), - __('Name'), - __('Serial number'), - __('Inventory number'), - __('Status'), + __s('Type'), + __s('Entity'), + __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Status'), '', ); @@ -247,11 +243,11 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, User $user, $tech) $type_name = $item->getTypeName(); - if (count($result)) { + if (count($result) > 0) { foreach ($result as $data) { $name = $data['name']; if (empty($name)) { - $name = sprintf(__('%1$s (%2$s)'), $name, $data['id']); + $name = sprintf(__s('%1$s (%2$s)'), $name, $data['id']); } $linktype = ''; if ($data[$field_user] == $ID) { @@ -261,8 +257,8 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, User $user, $tech) $item->getTypeName(1), Dropdown::getDropdownName('glpi_entities', $data['entities_id']), $name, - isset($data['serial']) ? $data['serial'] : '', - isset($data['otherserial']) ? $data['otherserial'] : '', + $data['serial'] ?? '', + $data['otherserial'] ?? '', isset($data['states_id']) ? Dropdown::getDropdownName('glpi_states', $data['states_id']) : '', @@ -276,12 +272,12 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, User $user, $tech) if (!$empty) { $pdf->setColumnsSize(15, 15, 15, 15, 15, 15, 10); $pdf->displayTitle( - __('Type'), - __('Entity'), - __('Name'), - __('Serial number'), - __('Inventory number'), - __('Status'), + __s('Type'), + __s('Entity'), + __s('Name'), + __s('Serial number'), + __s('Inventory number'), + __s('Status'), '', ); } @@ -334,17 +330,17 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, User $user, $tech) $type_name = $item->getTypeName(); - if (count($result)) { + if (count($result) > 0) { foreach ($result as $data) { $name = $data['name']; if (empty($name)) { - $name = sprintf(__('%1$s (%2$s)'), $name, $data['id']); + $name = sprintf(__s('%1$s (%2$s)'), $name, $data['id']); } $linktype = ''; if (isset($groups[$data[$field_group]])) { $linktype = sprintf( - __('%1$s = %2$s'), - _n('Group', 'Groups', 1), + __s('%1$s = %2$s'), + _sn('Group', 'Groups', 1), $groups[$data[$field_group]], ); } @@ -364,16 +360,16 @@ public static function pdfItems(PluginPdfSimplePDF $pdf, User $user, $tech) } if ($empty) { $pdf->setColumnsSize(100); - $pdf->displayLine(sprintf(__('%1$s: %2$s'), $title, __('No item to display'))); + $pdf->displayLine(sprintf(__s('%1$s: %2$s'), $title, __s('No item to display'))); } $pdf->displaySpace(); if ($conso) { $pdf->setColumnsSize(100); - $pdf->displayTitle('' . __('Used consumables') . ''); + $pdf->displayTitle('' . __s('Used consumables') . ''); $pdf->setColumnsSize(70, 30); - $pdf->displayTitle(__('Name'), __('Use date')); + $pdf->displayTitle(__s('Name'), __s('Use date')); $iterator = $DB->request(['FROM' => 'glpi_consumables', 'LEFT JOIN' => ['glpi_consumableitems' @@ -405,9 +401,6 @@ public function defineAllTabsPDF($options = []) public static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGLPI $item, $tab) { - $tree = isset($_REQUEST['item']['_tree']); - $user = isset($_REQUEST['item']['_user']); - if ($item instanceof User) { switch ($tab) { case 'User$1': diff --git a/pdf.xml b/pdf.xml index 484fda5..b9a51c1 100644 --- a/pdf.xml +++ b/pdf.xml @@ -44,9 +44,9 @@ https://github.com/pluginsGLPI/pdf/releases/download/4.0.2/glpi-pdf-4.0.2.tar.bz2 - 4.1.0-beta2 + 4.1.0 ~11.0.0 - https://github.com/pluginsGLPI/pdf/releases/download/4.1.0-beta2/glpi-pdf-4.1.0-beta2.tar.bz2 + https://github.com/pluginsGLPI/pdf/releases/download/4.1.0/glpi-pdf-4.1.0.tar.bz2 4.0.1 diff --git a/phpstan.neon b/phpstan.neon index 1a1e4a6..3b12c3a 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 @@ -14,10 +15,3 @@ parameters: scanDirectories: - ../../inc - ../../src - stubFiles: - - ../../stubs/glpi_constants.php - 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/psalm.xml b/psalm.xml new file mode 100644 index 0000000..1095c55 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + 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/rector.php b/rector.php new file mode 100644 index 0000000..65a1f6e --- /dev/null +++ b/rector.php @@ -0,0 +1,102 @@ +. + * + * @author Nelly Mahu-Lasson, Remi Collet, Teclib + * @copyright Copyright (c) 2009-2022 PDF plugin team + * @copyright Copyright (C) 2018-2023 by Metabase plugin team. + * @license AGPL License 3.0 or (at your option) any later version + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html + * @link https://github.com/pluginsGLPI/pdf/ + * @link http://www.glpi-project.org/ + * @link https://github.com/pluginsGLPI/metabase + * @package pdf + * @since 2009 + * http://www.gnu.org/licenses/agpl-3.0-standalone.html + * -------------------------------------------------------------------------- + */ + +require_once __DIR__ . '/../../src/Plugin.php'; + +use Rector\Caching\ValueObject\Storage\FileCacheStorage; +use Rector\CodeQuality\Rector as CodeQuality; +use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector as DeadCode; +use Rector\ValueObject\PhpVersion; + +return RectorConfig::configure() + ->withPaths([ + __DIR__ . '/front', + __DIR__ . '/inc', + ]) + ->withPhpVersion(PhpVersion::PHP_82) + ->withCache( + cacheClass: FileCacheStorage::class, + cacheDirectory: sys_get_temp_dir() . '/metabase-rector', + ) + ->withRootFiles() + ->withParallel(timeoutSeconds: 300) + ->withImportNames(removeUnusedImports: true) + ->withRules([ + CodeQuality\Assign\CombinedAssignRector::class, + CodeQuality\BooleanAnd\RemoveUselessIsObjectCheckRector::class, + CodeQuality\BooleanAnd\SimplifyEmptyArrayCheckRector::class, + CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class, + CodeQuality\Catch_\ThrowWithPreviousExceptionRector::class, + CodeQuality\Empty_\SimplifyEmptyCheckOnEmptyArrayRector::class, + CodeQuality\Expression\InlineIfToExplicitIfRector::class, + CodeQuality\Expression\TernaryFalseExpressionToIfRector::class, + CodeQuality\For_\ForRepeatedCountToOwnVariableRector::class, + CodeQuality\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector::class, + CodeQuality\Foreach_\ForeachToInArrayRector::class, + CodeQuality\Foreach_\SimplifyForeachToCoalescingRector::class, + CodeQuality\Foreach_\UnusedForeachValueToArrayKeysRector::class, + CodeQuality\FuncCall\ChangeArrayPushToArrayAssignRector::class, + CodeQuality\FuncCall\CompactToVariablesRector::class, + CodeQuality\FuncCall\InlineIsAInstanceOfRector::class, + CodeQuality\FuncCall\IsAWithStringWithThirdArgumentRector::class, + CodeQuality\FuncCall\RemoveSoleValueSprintfRector::class, + CodeQuality\FuncCall\SetTypeToCastRector::class, + CodeQuality\FuncCall\SimplifyFuncGetArgsCountRector::class, + CodeQuality\FuncCall\SimplifyInArrayValuesRector::class, + CodeQuality\FuncCall\SimplifyStrposLowerRector::class, + CodeQuality\FuncCall\UnwrapSprintfOneArgumentRector::class, + CodeQuality\Identical\BooleanNotIdenticalToNotIdenticalRector::class, + CodeQuality\Identical\SimplifyArraySearchRector::class, + CodeQuality\Identical\SimplifyConditionsRector::class, + CodeQuality\Identical\StrlenZeroToIdenticalEmptyStringRector::class, + CodeQuality\If_\CombineIfRector::class, + CodeQuality\If_\CompleteMissingIfElseBracketRector::class, + CodeQuality\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, + CodeQuality\If_\ExplicitBoolCompareRector::class, + CodeQuality\If_\ShortenElseIfRector::class, + CodeQuality\If_\SimplifyIfElseToTernaryRector::class, + CodeQuality\If_\SimplifyIfNotNullReturnRector::class, + CodeQuality\If_\SimplifyIfNullableReturnRector::class, + CodeQuality\If_\SimplifyIfReturnBoolRector::class, + CodeQuality\Include_\AbsolutizeRequireAndIncludePathRector::class, + CodeQuality\LogicalAnd\AndAssignsToSeparateLinesRector::class, + CodeQuality\LogicalAnd\LogicalToBooleanRector::class, + CodeQuality\NotEqual\CommonNotEqualRector::class, + CodeQuality\Ternary\UnnecessaryTernaryExpressionRector::class, + DeadCode\Assign\RemoveUnusedVariableAssignRector::class, + ]) + ->withPhpSets(php74: true) // apply PHP sets up to PHP 7.4 +; diff --git a/setup.php b/setup.php index c978a12..bee7584 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'); + + +define('PLUGIN_PDF_VERSION', '4.1.0'); +define('PLUGIN_PDF_MIN_GLPI', '11.0.0'); +define('PLUGIN_PDF_MAX_GLPI', '11.0.99'); function plugin_init_pdf() { @@ -109,7 +111,7 @@ function plugin_init_pdf() function plugin_version_pdf() { - return ['name' => __('Print to pdf', 'pdf'), + return ['name' => __s('Print to pdf', 'pdf'), 'version' => PLUGIN_PDF_VERSION, 'author' => 'Teclib, Remi Collet, Nelly Mahu-Lasson', 'license' => 'GPLv3+', diff --git a/templates/config.html.twig b/templates/config.html.twig index be1ec3d..17bdf74 100644 --- a/templates/config.html.twig +++ b/templates/config.html.twig @@ -36,21 +36,21 @@ 'currency', selected_currency, currency_options, - __('Choose your international currency', 'pdf') + __s('Choose your international currency', 'pdf') ) }}

{% if is_branding_active %} @@ -62,7 +62,7 @@ {% else %} {% endif %} @@ -72,7 +72,7 @@ {{ fields.textareaField( 'add_text', add_text, - __('Text to add at the end of the PDF generation', 'pdf'), + __s('Text to add at the end of the PDF generation', 'pdf'), { 'rows': 5, 'style': 'width:95%' diff --git a/templates/preference_form.html.twig b/templates/preference_form.html.twig new file mode 100644 index 0000000..1d6ed58 --- /dev/null +++ b/templates/preference_form.html.twig @@ -0,0 +1,210 @@ +{# + # ------------------------------------------------------------------------- + # LICENSE + # + # This file is part of PDF plugin for GLPI. + # + # PDF is free software: you can redistribute it and/or modify + # it under the terms of the GNU Affero General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # PDF is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU Affero General Public License for more details. + # + # You should have received a copy of the GNU Affero General Public License + # along with Reports. If not, see . + # + # @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 + # -------------------------------------------------------------------------- + #} + + + +
+
+

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

+
+ +
+ {% if debug_mode %} +
+ + {{ __s('Debug mode enabled - showing internal references') }} +
+ {% endif %} + +
+
+
+ + + {{ __s('Available tables', 'pdf') }} + + +
+ + + + + {{ __s('Select tables to include in PDF export', 'pdf') }} + +
+ +
+ {% for option_key, option_title in options %} +
+
+
+
+ + +
+
+
+
+ {% endfor %} +
+
+
+
+ +
+
+
+ + +
+
+ + {% if item_id %} +
+
+ + +
+
+ {% endif %} +
+
+ + +
+ + + diff --git a/tools/move_to_po.php b/tools/move_to_po.php index 2c28b44..f3a7c45 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 */ @@ -72,7 +72,7 @@ if (!preg_match('/string to be translated/', $content, $reg)) { if (fwrite($lf_new, $content) === false) { echo 'unable to write in clean lang file'; - exit; + return; } } } @@ -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 = ''; @@ -183,7 +183,7 @@ if (fwrite($po, $content) === false) { echo 'unable to write in po file'; - exit; + return; } } } diff --git a/tools/pdftest.php b/tools/pdftest.php index 28cdda2..2ec4760 100644 --- a/tools/pdftest.php +++ b/tools/pdftest.php @@ -87,7 +87,7 @@ $pdf->setHeader('Another header'); $pdf->newPage(); $pdf->displayTitle('Part 2'); -$pdf->addPngFromFile(GLPI_ROOT . '/pics/logo-glpi-login.png', 168, 81); +$pdf->addPngFromFile(GLPI_ROOT . '/public/pics/logo-glpi-login.png', 168, 81); $pdf->displayTitle('End of Part 2'); if (file_put_contents('pdftest.pdf', $pdf->output())) {