<?php
@session_start();
$redirect = isset($_GET['redirect']) ? $_GET['redirect'] : '';
$ref = $_SESSION['compagnie_ref'] ?? '';
if($ref){
  $centralCfg = __DIR__.'/gestion_compagnies/config/connexion.php';
  if(is_file($centralCfg)){
    @require_once $centralCfg; // $gc_pdo
    if(isset($gc_pdo) && $gc_pdo instanceof PDO){
      try {
        $col = $gc_pdo->query("SHOW COLUMNS FROM compagnies_table LIKE 'validation_note'")->fetch();
        if($col){
          $st = $gc_pdo->prepare("UPDATE compagnies_table SET validation_note=0 WHERE compagnie_ref=? LIMIT 1");
          $st->execute([$ref]);
          $_SESSION['payment_validated_seen']=true; // éviter ré-affichage immédiat
        }
      } catch(Throwable $e){ /* silent */ }
    }
  }
}
if($redirect && preg_match('~^[A-Za-z0-9_./-]+$~',$redirect) && strpos($redirect,'..')===false){
  header('Location: '.$redirect);
} else {
  header('Location: index.php');
}
exit;