'; echo '' . $title . ''; echo '
'; echo '
'; if ($type === 'success') { echo '
'; } elseif ($type === 'info') { echo '
'; } else { echo '
'; } echo '
'; echo '

' . $title . '

'; echo '

' . $message . '

'; if ($cta_href) { echo '
' . $cta_label . '
'; } echo '
'; exit; } if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') { ui_exit( $translations['tvalidat_err_acces_titre'] ?? 'Accès incorrect', $translations['tvalidat_err_acces_msg'] ?? 'Accès invalide.', 405, 'info', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } $email = trim((string) ($_POST['email'] ?? '')); if ($email === '' || ! filter_var($email, FILTER_VALIDATE_EMAIL) || preg_match('/[\r\n]/', $email)) { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['tvalidat_err_email_invalide'] ?? 'Email invalide.', 400, 'error', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } $pending = $_SESSION['pending_validation_resend'] ?? null; if ( empty($pending['authorized']) || empty($pending['compte_id']) || empty($pending['email']) || empty($pending['expires_at']) || (int) $pending['expires_at'] < time() || ! hash_equals((string) $pending['email'], $email) ) { unset($_SESSION['pending_validation_resend']); ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['tvalidat_err_action_non_autorisee'] ?? 'Action non autorisée. Merci de vous reconnecter.', 403, 'error', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } try { $stmt = $pdo->prepare(" SELECT id, email, role, reference_id, email_valide FROM compte WHERE id = :id AND email = :email LIMIT 1 "); $stmt->execute([ 'id' => (int) $pending['compte_id'], 'email' => $email, ]); $compte = $stmt->fetch(PDO::FETCH_ASSOC); if (! $compte) { unset($_SESSION['pending_validation_resend']); ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['tvalidat_err_compte_introuvable'] ?? 'Compte introuvable.', 404, 'error', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } if (! empty($compte['email_valide'])) { unset($_SESSION['pending_validation_resend']); ui_exit( $translations['tvalidat_info_titre'] ?? 'Information', $translations['tvalidat_info_email_deja_valide'] ?? 'Votre adresse email est déjà validée.', 200, 'info', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } $prenom = ''; $nom = ''; if (($compte['role'] ?? '') === 'praticien') { $stmt = $pdo->prepare("SELECT prenom, nom FROM praticien WHERE id = :id LIMIT 1"); $stmt->execute(['id' => (int) $compte['reference_id']]); $profil = $stmt->fetch(PDO::FETCH_ASSOC); } elseif (($compte['role'] ?? '') === 'client') { $stmt = $pdo->prepare("SELECT prenom, nom FROM client WHERE id = :id LIMIT 1"); $stmt->execute(['id' => (int) $compte['reference_id']]); $profil = $stmt->fetch(PDO::FETCH_ASSOC); } else { $profil = false; } if ($profil) { $prenom = trim((string) ($profil['prenom'] ?? '')); $nom = trim((string) ($profil['nom'] ?? '')); } $token = bin2hex(random_bytes(32)); $token_validation_expire = (new DateTime('+6 hours'))->format('Y-m-d H:i:s'); $stmt = $pdo->prepare(" UPDATE compte SET token_validation = :token, token_validation_expire = :token_expire, token_autologin = NULL, token_autologin_expire = NULL WHERE id = :id LIMIT 1 "); $stmt->execute([ 'token' => $token, 'token_expire' => $token_validation_expire, 'id' => (int) $compte['id'], ]); } catch (Throwable $e) { error_log('renvoyer_validat_mail.php - DB error: ' . $e->getMessage()); ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_serveur'] ?? 'Erreur serveur.', 500, 'error', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } $validation_url = "https://uslugi.fr/validation.php?token=" . urlencode($token); $validation_url_html = htmlspecialchars($validation_url, ENT_QUOTES, 'UTF-8'); $prenom_nom = trim($prenom . ' ' . $nom); $to_name = $prenom_nom !== '' ? $prenom_nom : $email; $sujet = $translations['mail_valid_sujet'] ?? 'Validation de votre adresse email'; $html = "
" . htmlspecialchars(sprintf($translations['mail_valid_bonjour_nom'] ?? 'Bonjour %s,', $to_name), ENT_QUOTES, 'UTF-8') . "

" . htmlspecialchars($translations['tvalidat_mail_intro'] ?? 'Voici un nouveau lien pour valider votre adresse email.', ENT_QUOTES, 'UTF-8') . "

" . htmlspecialchars($translations['mail_valid_action'] ?? 'Cliquez sur le bouton ci-dessous pour confirmer votre adresse.', ENT_QUOTES, 'UTF-8') . "

" . htmlspecialchars($translations['mail_valid_btn'] ?? 'Valider mon adresse email', ENT_QUOTES, 'UTF-8') . "
"; $text = strip_tags( sprintf($translations['mail_valid_bonjour_nom'] ?? 'Bonjour %s,', $to_name) . "\n\n" . ($translations['tvalidat_mail_intro'] ?? 'Voici un nouveau lien pour valider votre adresse email.') . "\n" . ($translations['mail_valid_action'] ?? 'Cliquez sur le lien suivant pour confirmer votre adresse.') . "\n" . $validation_url . "\n\n" . ($translations['mail_valid_expire'] ?? 'Ce lien expire prochainement.') . "\n" . ($translations['mail_valid_ignore'] ?? 'Si vous n\'êtes pas à l\'origine de cette demande, ignorez ce message.') . "\n\n" . ($translations['mail_valid_signature'] ?? 'USLUGI.FR') ); list($sent, $err) = uslugi_mail( $email, $sujet, $html, $text, ['to_name' => $to_name] ); unset($_SESSION['pending_validation_resend']); if (! $sent) { error_log("Renvoi validation mail NOT sent to {$email}: {$err}"); ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['tvalidat_err_envoi'] ?? 'Le mail n’a pas pu être envoyé. Merci de réessayer plus tard.', 500, 'error', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } ui_exit( $translations['tvalidat_success_titre'] ?? 'Email envoyé', $translations['tvalidat_success_msg'] ?? 'Un nouveau lien de validation vient d’être envoyé à votre adresse email.', 200, 'success', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' );