diff --git a/composer.json b/composer.json index 6956948..8aa7ff7 100644 --- a/composer.json +++ b/composer.json @@ -54,10 +54,11 @@ "barryvdh/laravel-ide-helper": "^2.8", "brianium/paratest": "^7.1", "fakerphp/faker": "^1.9.1", + "laravel/sail": "^1.0", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^7.0", "phpunit/phpunit": "^10.0", - "laravel/sail": "^1.0", + "robmorgan/phinx": "^0.16.12", "spatie/laravel-ignition": "^2.0" }, "autoload": { diff --git a/composer.lock b/composer.lock index 1f076a1..4fc42f7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "36e0265c4d1a5422d60fbaef9b95eb98", + "content-hash": "32b2751ff3f31f7f8d63c265a0b8f5dd", "packages": [ { "name": "akaunting/laravel-setting", @@ -7088,6 +7088,388 @@ ], "time": "2023-03-13T10:11:07+00:00" }, + { + "name": "cakephp/chronos", + "version": "3.5.1", + "source": { + "type": "git", + "url": "https://github.com/cakephp/chronos.git", + "reference": "00c16f165a762226d58f9cf88f43e54e41093f84" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/chronos/zipball/00c16f165a762226d58f9cf88f43e54e41093f84", + "reference": "00c16f165a762226d58f9cf88f43e54e41093f84", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/clock": "^1.0" + }, + "provide": { + "psr/clock-implementation": "1.0" + }, + "require-dev": { + "cakephp/cakephp-codesniffer": "^5.0", + "phpunit/phpunit": "^10.5.58 || ^11.5.3 || ^12.1.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Cake\\Chronos\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + }, + { + "name": "The CakePHP Team", + "homepage": "https://cakephp.org" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "https://cakephp.org", + "keywords": [ + "date", + "datetime", + "time" + ], + "support": { + "issues": "https://github.com/cakephp/chronos/issues", + "source": "https://github.com/cakephp/chronos" + }, + "time": "2026-09-06T02:30:12+00:00" + }, + { + "name": "cakephp/core", + "version": "5.4.2", + "source": { + "type": "git", + "url": "https://github.com/cakephp/core.git", + "reference": "55c9f6ec8a11f6c946cad5bc6e8da18d6d98ae06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/core/zipball/55c9f6ec8a11f6c946cad5bc6e8da18d6d98ae06", + "reference": "55c9f6ec8a11f6c946cad5bc6e8da18d6d98ae06", + "shasum": "" + }, + "require": { + "cakephp/utility": "^5.4.0", + "league/container": "^5.1", + "php": ">=8.2", + "psr/container": "^1.1 || ^2.0" + }, + "provide": { + "psr/container-implementation": "^2.0" + }, + "suggest": { + "cakephp/cache": "To use Configure::store() and restore().", + "cakephp/event": "To use PluginApplicationInterface or plugin applications.", + "league/container": "To use Container and ServiceProvider classes" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-5.next": "5.5.x-dev" + } + }, + "autoload": { + "files": [ + "functions.php" + ], + "psr-4": { + "Cake\\Core\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/core/graphs/contributors" + } + ], + "description": "CakePHP Framework Core classes", + "homepage": "https://cakephp.org", + "keywords": [ + "cakephp", + "core", + "framework" + ], + "support": { + "forum": "https://stackoverflow.com/tags/cakephp", + "irc": "irc://irc.freenode.org/cakephp", + "issues": "https://github.com/cakephp/cakephp/issues", + "source": "https://github.com/cakephp/core" + }, + "time": "2026-08-24T11:32:41+00:00" + }, + { + "name": "cakephp/database", + "version": "5.4.2", + "source": { + "type": "git", + "url": "https://github.com/cakephp/database.git", + "reference": "91cf7b16e9ebe0050c64db0f4634ac4a76782564" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/database/zipball/91cf7b16e9ebe0050c64db0f4634ac4a76782564", + "reference": "91cf7b16e9ebe0050c64db0f4634ac4a76782564", + "shasum": "" + }, + "require": { + "cakephp/chronos": "^3.3", + "cakephp/core": "^5.4.0", + "cakephp/datasource": "^5.4.0", + "cakephp/event": "^5.4.0", + "php": ">=8.2", + "psr/log": "^3.0" + }, + "require-dev": { + "cakephp/i18n": "^5.4.0", + "cakephp/log": "^5.4.0", + "cakephp/utility": "^5.4.0" + }, + "suggest": { + "cakephp/i18n": "If you are using locale-aware datetime formats.", + "cakephp/log": "If you want to use query logging without providing a logger yourself.", + "cakephp/utility": "If you want to use EnumLabelTrait." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-5.next": "5.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Cake\\Database\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/database/graphs/contributors" + } + ], + "description": "Flexible and powerful Database abstraction library with a familiar PDO-like API", + "homepage": "https://cakephp.org", + "keywords": [ + "abstraction", + "cakephp", + "database", + "database abstraction", + "pdo" + ], + "support": { + "forum": "https://stackoverflow.com/tags/cakephp", + "irc": "irc://irc.freenode.org/cakephp", + "issues": "https://github.com/cakephp/cakephp/issues", + "source": "https://github.com/cakephp/database" + }, + "time": "2026-08-28T06:30:11+00:00" + }, + { + "name": "cakephp/datasource", + "version": "5.4.2", + "source": { + "type": "git", + "url": "https://github.com/cakephp/datasource.git", + "reference": "cec80f34828d4aeaf24f75097055cd1466e1aec7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/datasource/zipball/cec80f34828d4aeaf24f75097055cd1466e1aec7", + "reference": "cec80f34828d4aeaf24f75097055cd1466e1aec7", + "shasum": "" + }, + "require": { + "cakephp/core": "^5.4.0", + "php": ">=8.2", + "psr/simple-cache": "^2.0 || ^3.0" + }, + "require-dev": { + "cakephp/cache": "^5.4.0", + "cakephp/collection": "^5.4.0", + "cakephp/utility": "^5.4.0" + }, + "suggest": { + "cakephp/cache": "If you decide to use Query caching.", + "cakephp/collection": "If you decide to use ResultSetInterface.", + "cakephp/utility": "If you decide to use EntityTrait." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-5.next": "5.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Cake\\Datasource\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/datasource/graphs/contributors" + } + ], + "description": "Provides connection managing and traits for Entities and Queries that can be reused for different datastores", + "homepage": "https://cakephp.org", + "keywords": [ + "cakephp", + "connection management", + "datasource", + "entity", + "query" + ], + "support": { + "forum": "https://stackoverflow.com/tags/cakephp", + "irc": "irc://irc.freenode.org/cakephp", + "issues": "https://github.com/cakephp/cakephp/issues", + "source": "https://github.com/cakephp/datasource" + }, + "time": "2026-08-24T11:32:41+00:00" + }, + { + "name": "cakephp/event", + "version": "5.4.2", + "source": { + "type": "git", + "url": "https://github.com/cakephp/event.git", + "reference": "28e2797bda517cbac7fa683415f7bbc2774de103" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/event/zipball/28e2797bda517cbac7fa683415f7bbc2774de103", + "reference": "28e2797bda517cbac7fa683415f7bbc2774de103", + "shasum": "" + }, + "require": { + "cakephp/core": "^5.4.0", + "php": ">=8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-5.next": "5.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Cake\\Event\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/event/graphs/contributors" + } + ], + "description": "CakePHP event dispatcher library that helps implementing the observer pattern", + "homepage": "https://cakephp.org", + "keywords": [ + "cakephp", + "dispatcher", + "event", + "observer pattern" + ], + "support": { + "forum": "https://stackoverflow.com/tags/cakephp", + "irc": "irc://irc.freenode.org/cakephp", + "issues": "https://github.com/cakephp/cakephp/issues", + "source": "https://github.com/cakephp/event" + }, + "time": "2026-08-24T11:32:41+00:00" + }, + { + "name": "cakephp/utility", + "version": "5.4.2", + "source": { + "type": "git", + "url": "https://github.com/cakephp/utility.git", + "reference": "98376e5bbcdd84fdda6d6c4207ef6111fc5aed23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/utility/zipball/98376e5bbcdd84fdda6d6c4207ef6111fc5aed23", + "reference": "98376e5bbcdd84fdda6d6c4207ef6111fc5aed23", + "shasum": "" + }, + "require": { + "cakephp/core": "^5.4.0", + "php": ">=8.2" + }, + "suggest": { + "ext-intl": "To use Text::transliterate() or Text::slug()", + "lib-ICU": "To use Text::transliterate() or Text::slug()" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-5.next": "5.5.x-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Cake\\Utility\\": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/utility/graphs/contributors" + } + ], + "description": "CakePHP Utility classes such as Inflector, String, Hash, and Security", + "homepage": "https://cakephp.org", + "keywords": [ + "cakephp", + "hash", + "inflector", + "security", + "string", + "utility" + ], + "support": { + "forum": "https://stackoverflow.com/tags/cakephp", + "irc": "irc://irc.freenode.org/cakephp", + "issues": "https://github.com/cakephp/cakephp/issues", + "source": "https://github.com/cakephp/utility" + }, + "time": "2026-08-24T11:32:41+00:00" + }, { "name": "composer/class-map-generator", "version": "1.0.0", @@ -7946,6 +8328,90 @@ }, "time": "2023-03-06T14:23:15+00:00" }, + { + "name": "league/container", + "version": "5.2.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/container.git", + "reference": "58accbc032f0090a9bd08326f93062c5a658b2c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/container/zipball/58accbc032f0090a9bd08326f93062c5a658b2c5", + "reference": "58accbc032f0090a9bd08326f93062c5a658b2c5", + "shasum": "" + }, + "require": { + "php": "^8.1", + "psr/container": "^2.0.2", + "psr/event-dispatcher": "^1.0" + }, + "provide": { + "psr/container-implementation": "^1.0" + }, + "replace": { + "orno/di": "~2.0" + }, + "require-dev": { + "nette/php-generator": "^4.1", + "nikic/php-parser": "^5.0", + "phpstan/phpstan": "^2.1.11", + "phpunit/phpunit": "^10.5.45|^11.5.15|^12.0", + "roave/security-advisories": "dev-latest", + "scrutinizer/ocular": "^1.9", + "squizlabs/php_codesniffer": "^3.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-1.x": "1.x-dev", + "dev-2.x": "2.x-dev", + "dev-3.x": "3.x-dev", + "dev-4.x": "4.x-dev", + "dev-5.x": "5.x-dev", + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Container\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Phil Bennett", + "email": "mail@philbennett.co.uk", + "role": "Developer" + } + ], + "description": "A fast and intuitive dependency injection container.", + "homepage": "https://github.com/thephpleague/container", + "keywords": [ + "container", + "dependency", + "di", + "injection", + "league", + "provider", + "service" + ], + "support": { + "issues": "https://github.com/thephpleague/container/issues", + "source": "https://github.com/thephpleague/container/tree/5.2.0" + }, + "funding": [ + { + "url": "https://github.com/philipobenito", + "type": "github" + } + ], + "time": "2026-03-19T18:52:39+00:00" + }, { "name": "maximebf/debugbar", "version": "v1.18.2", @@ -8925,6 +9391,141 @@ }, "time": "2021-02-03T23:26:27+00:00" }, + { + "name": "psr/clock", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/clock.git", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Clock\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for reading the clock.", + "homepage": "https://github.com/php-fig/clock", + "keywords": [ + "clock", + "now", + "psr", + "psr-20", + "time" + ], + "support": { + "issues": "https://github.com/php-fig/clock/issues", + "source": "https://github.com/php-fig/clock/tree/1.0.0" + }, + "time": "2022-11-25T14:36:26+00:00" + }, + { + "name": "robmorgan/phinx", + "version": "0.16.12", + "source": { + "type": "git", + "url": "https://github.com/cakephp/phinx.git", + "reference": "1cce44387a9146dc04c312e6a231b17fb30385cd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cakephp/phinx/zipball/1cce44387a9146dc04c312e6a231b17fb30385cd", + "reference": "1cce44387a9146dc04c312e6a231b17fb30385cd", + "shasum": "" + }, + "require": { + "cakephp/database": "^5.0.2", + "composer-runtime-api": "^2.0", + "php-64bit": ">=8.1", + "psr/container": "^1.1|^2.0", + "symfony/config": "^4.0|^5.0|^6.0|^7.0|^8.0", + "symfony/console": "^6.0|^7.0|^8.0" + }, + "require-dev": { + "cakephp/cakephp-codesniffer": "^5.0", + "cakephp/i18n": "^5.0", + "ext-json": "*", + "ext-pdo": "*", + "phpunit/phpunit": "^10.5", + "symfony/yaml": "^4.0|^5.0|^6.0|^7.0|^8.0" + }, + "suggest": { + "ext-json": "Install if using JSON configuration format", + "ext-pdo": "PDO extension is needed", + "symfony/yaml": "Install if using YAML configuration format" + }, + "bin": [ + "bin/phinx" + ], + "type": "library", + "autoload": { + "psr-4": { + "Phinx\\": "src/Phinx/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Rob Morgan", + "email": "robbym@gmail.com", + "homepage": "https://robmorgan.id.au", + "role": "Lead Developer" + }, + { + "name": "Woody Gilk", + "email": "woody.gilk@gmail.com", + "homepage": "https://shadowhand.me", + "role": "Developer" + }, + { + "name": "Richard Quadling", + "email": "rquadling@gmail.com", + "role": "Developer" + }, + { + "name": "CakePHP Community", + "homepage": "https://github.com/cakephp/phinx/graphs/contributors", + "role": "Developer" + } + ], + "description": "Phinx makes it ridiculously easy to manage the database migrations for your PHP app.", + "homepage": "https://phinx.org", + "keywords": [ + "database", + "database migrations", + "db", + "migrations", + "phinx" + ], + "support": { + "issues": "https://github.com/cakephp/phinx/issues", + "source": "https://github.com/cakephp/phinx/tree/0.16.12" + }, + "time": "2026-07-03T07:27:17+00:00" + }, { "name": "sebastian/cli-parser", "version": "2.0.0", @@ -10127,6 +10728,155 @@ ], "time": "2023-01-24T07:20:39+00:00" }, + { + "name": "symfony/config", + "version": "v6.4.44", + "source": { + "type": "git", + "url": "https://github.com/symfony/config.git", + "reference": "6a5abf67fd5b138df96984fe6f8fd736fb7d6b29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/config/zipball/6a5abf67fd5b138df96984fe6f8fd736fb7d6b29", + "reference": "6a5abf67fd5b138df96984fe6f8fd736fb7d6b29", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/filesystem": "^5.4|^6.0|^7.0", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "symfony/finder": "<5.4", + "symfony/service-contracts": "<2.5" + }, + "require-dev": { + "symfony/event-dispatcher": "^5.4|^6.0|^7.0", + "symfony/finder": "^5.4|^6.0|^7.0", + "symfony/messenger": "^5.4|^6.0|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/yaml": "^5.4|^6.0|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Config\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Helps you find, load, combine, autofill and validate configuration values of any kind", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/config/tree/v6.4.44" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-08-20T09:38:57+00:00" + }, + { + "name": "symfony/filesystem", + "version": "v7.4.18", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "90d412aa5277c6819db39e7605aa46b1019e3232" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/90d412aa5277c6819db39e7605aa46b1019e3232", + "reference": "90d412aa5277c6819db39e7605aa46b1019e3232", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" + }, + "require-dev": { + "symfony/process": "^6.4|^7.0|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v7.4.18" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-08-23T10:03:40+00:00" + }, { "name": "symfony/yaml", "version": "v6.2.7", @@ -10263,6 +11013,6 @@ "php": "^8.1.0", "ext-json": "*" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" } diff --git a/phinx.php b/phinx.php new file mode 100644 index 0000000..02f3d58 --- /dev/null +++ b/phinx.php @@ -0,0 +1,42 @@ +safeLoad(); // safeLoad: non lancia errori se manca il .env +} + +// Helper: legge da $_ENV, getenv() o usa un default +$env = function (string $key, $default = null) { + $v = $_ENV[$key] ?? getenv($key); + if ($v === false || $v === null) { + return $default; + } + // toglie eventuali virgolette attorno al valore + return trim($v, "\"'"); +}; + +return [ + 'paths' => [ + 'migrations' => __DIR__ . '/db/migrations', + 'seeds' => __DIR__ . '/db/seeds', + ], + 'environments' => [ + 'default_migration_table' => 'phinxlog', + 'default_environment' => 'development', + 'development' => [ + 'adapter' => $env('DB_CONNECTION', 'mysql'), + 'host' => $env('DB_HOST', '127.0.0.1'), + 'name' => $env('DB_DATABASE', 'casadocdb'), + 'user' => $env('DB_USERNAME', 'root'), + 'pass' => $env('DB_PASSWORD', ''), + 'port' => (int) $env('DB_PORT', 3306), + 'charset' => 'utf8mb4', + ], + ], + 'version_order' => 'creation', +]; diff --git a/public/userportal/get-documents.php b/public/userportal/get-documents.php index 502ec0f..e458799 100644 --- a/public/userportal/get-documents.php +++ b/public/userportal/get-documents.php @@ -4,10 +4,15 @@ include('include/headscript.php'); $conn = new mysqli($servername, $username, $password, $database); $iduserlogin = $_SESSION['iduserlogin']; $idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0; -$docpage = isset($_GET['slug']) ? $_GET['slug'] : 'legal'; // Slug principale per la pagina -$subSlug = isset($_GET['subSlug']) ? $_GET['subSlug'] : null; // Slug aggiuntivo opzionale +$docpage = isset($_GET['slug']) ? $_GET['slug'] : ''; $showOnlyRequired = isset($_GET['showOnlyRequired']) && $_GET['showOnlyRequired'] === 'true'; -$sectionId = isset($_GET['sectionId']) ? $_GET['sectionId'] : null; +$sectionId = (isset($_GET['sectionId']) && $_GET['sectionId'] !== '' && $_GET['sectionId'] !== 'null') ? $_GET['sectionId'] : null; +$searchName = (isset($_GET['searchName']) && $_GET['searchName'] !== '' && $_GET['searchName'] !== 'null') ? $_GET['searchName'] : null; +// Tag: lista di ID separati da virgola +$tagIds = []; +if (isset($_GET['tags']) && $_GET['tags'] !== '' && $_GET['tags'] !== 'null') { + $tagIds = array_values(array_filter(array_map('intval', explode(',', $_GET['tags'])))); +} $queryHome = $conn->prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?"); $queryHome->bind_param('ii', $idhome, $iduserlogin); @@ -20,27 +25,42 @@ if (!$homeData) { die(json_encode(['error' => 'Casa non trovata o accesso non autorizzato'])); } -$queryPageId = $conn->prepare("SELECT idpages FROM pages WHERE slug = ?"); -$queryPageId->bind_param('s', $docpage); -$queryPageId->execute(); -$resultPageId = $queryPageId->get_result(); -$pageData = $resultPageId->fetch_assoc(); +// Modalità trasversale: se ci sono tag selezionati, si ignora la categoria +$crossCutting = !empty($tagIds); -if (!$pageData) { - header('HTTP/1.1 400 Bad Request'); - die(json_encode(['error' => 'Pagina non valida'])); +$page_id = null; +if (!$crossCutting) { + $queryPageId = $conn->prepare("SELECT idpages FROM pages WHERE slug = ?"); + $queryPageId->bind_param('s', $docpage); + $queryPageId->execute(); + $resultPageId = $queryPageId->get_result(); + $pageData = $resultPageId->fetch_assoc(); + + if (!$pageData) { + header('HTTP/1.1 400 Bad Request'); + die(json_encode(['error' => 'Pagina non valida'])); + } + $page_id = $pageData['idpages']; } -$page_id = $pageData['idpages']; - // Costruisci la query per i documenti $sql = " - SELECT d.*, s.section_name AS section_name + SELECT d.*, s.section_name AS section_name, + GROUP_CONCAT(DISTINCT t.tag_name ORDER BY t.tag_name SEPARATOR ', ') AS tags FROM documents d LEFT JOIN sections s ON d.idsections = s.idsections - WHERE d.page_id = ? + LEFT JOIN document_tags dt ON dt.document_id = d.document_id + LEFT JOIN tags t ON t.tag_id = dt.tag_id + WHERE 1=1 "; -$params = [$page_id]; +$params = []; +$types = ''; + +if (!$crossCutting) { + $sql .= " AND d.page_id = ?"; + $params[] = $page_id; + $types .= 'i'; +} if ($showOnlyRequired) { $sql .= " AND d.is_required = 1"; @@ -49,19 +69,33 @@ if ($showOnlyRequired) { if ($sectionId) { $sql .= " AND md5(s.section_name) = ?"; $params[] = $sectionId; + $types .= 's'; } -// Aggiungi filtro per subSlug (assumendo che i documenti abbiano un campo slug o un riferimento) -if ($subSlug) { - $sql .= " AND d.slug = ?"; // Assumo che 'documents' abbia un campo 'slug' per il filtraggio - $params[] = $subSlug; +if ($searchName) { + $sql .= " AND d.document_name = ?"; + $params[] = $searchName; + $types .= 's'; } -$sql .= " ORDER BY s.section_name, d.document_name"; +// Filtro per tag (OR): il documento deve avere ALMENO UNO dei tag selezionati +if (!empty($tagIds)) { + $placeholders = implode(',', array_fill(0, count($tagIds), '?')); + $sql .= " AND d.document_id IN ( + SELECT document_id FROM document_tags + WHERE tag_id IN ($placeholders) + )"; + foreach ($tagIds as $tid) { + $params[] = $tid; + $types .= 'i'; + } +} +$sql .= " GROUP BY d.document_id ORDER BY s.section_name, d.document_name"; $queryDocuments = $conn->prepare($sql); -$types = str_repeat('s', count($params) - 1) . 'i'; // 's' per stringhe, 'i' per page_id -$queryDocuments->bind_param($types, ...$params); +if (!empty($params)) { + $queryDocuments->bind_param($types, ...$params); +} $queryDocuments->execute(); $resultDocuments = $queryDocuments->get_result(); diff --git a/public/userportal/tabs/documenti.php b/public/userportal/tabs/documenti.php index 55721b5..07031b3 100644 --- a/public/userportal/tabs/documenti.php +++ b/public/userportal/tabs/documenti.php @@ -21,7 +21,7 @@ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { } // Imposta lo slug predefinito -$docpage = isset($_GET['docpage']) ? $_GET['docpage'] : 'legal'; +$docpage = isset($_GET['docpage']) ? $_GET['docpage'] : ''; // Recupera tutti i tag disponibili $stmt = $pdo->query("SELECT tag_id, tag_name FROM tags ORDER BY tag_name"); @@ -95,7 +95,7 @@ $allTags = $stmt->fetchAll(PDO::FETCH_ASSOC);