<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

/**
 * Comparateur de bilans — historical direct URL, kept as a thin redirect so
 * no bookmark ever 404s: the Comparateur is now a tab of the Tableau de bord
 * (pages/dashboard.php, 'comparateur' tab), reusing
 * {@see \local_kid\output\comparateur_page} unchanged. Every original query
 * parameter is forwarded as-is (including the array-valued filters —
 * studentids[]/sourcekeys[]/competencyids[]/niveaucodes[] — which
 * moodle_url's array-value param API cannot carry, hence the raw query
 * string forwarding instead of a moodle_url-built target), only
 * `tab=comparateur` is added.
 *
 * Note: the target is built as an absolute `$CFG->wwwroot`-prefixed string
 * on purpose, not a root-relative `/local/kid/...` path — redirect()'s own
 * string-to-absolute-URL logic only prepends the scheme+host of wwwroot
 * (stripping any subdirectory, e.g. Moodle installed under `/docs`), so a
 * root-relative path here would silently escape the Moodle install path.
 *
 * @package local_kid
 */

require(__DIR__ . '/../../../config.php');
require_once($CFG->dirroot . '/local/kid/lib.php');

require_login();

$querystring = $_SERVER['QUERY_STRING'] ?? '';
$target = $CFG->wwwroot . '/local/kid/pages/dashboard.php?tab=comparateur' . ($querystring !== '' ? '&' . $querystring : '');
redirect($target);
