prepare("SELECT * FROM cvs WHERE id = ? AND user_id = ?"); $stmt->execute([$cv_id, $user_id]); $cv = $stmt->fetch(); if (!$cv) { header('Location: dashboard.php'); exit(); } // Fetch the template $template_path = null; if (!empty($cv['template_id'])) { $stmt = $pdo->prepare("SELECT file_path FROM templates WHERE id = ?"); $stmt->execute([$cv['template_id']]); $template = $stmt->fetch(); if ($template && file_exists(__DIR__ . '/templates/' . $template['file_path'])) { $template_path = __DIR__ . '/templates/' . $template['file_path']; } } // If a template is found, render it. Otherwise, fall back to a default view. if ($template_path) { // The template file will have access to the $cv variable. require_once $template_path; } else { // Default view if no template is set or found $cv_data = json_decode($cv['content'], true); ?>