34132-vm/view_cv.php
Flatlogic Bot 7a4a20350d MagiCV
2025-09-17 12:13:33 +00:00

72 lines
2.2 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
require_once 'db/config.php';
if (!isset($_GET['id'])) {
header('Location: dashboard.php');
exit();
}
$cv_id = $_GET['id'];
$user_id = $_SESSION['user_id'];
$pdo = db();
$stmt = $pdo->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);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View CV: <?php echo htmlspecialchars($cv['title']); ?></title>
<link rel="stylesheet" href="public/css/style.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="container">
<h1><?php echo htmlspecialchars($cv['title']); ?></h1>
<p><strong>Name:</strong> <?php echo htmlspecialchars($cv_data['personal_info']['name'] ?? 'N/A'); ?></p>
<p><strong>Email:</strong> <?php echo htmlspecialchars($cv_data['personal_info']['email'] ?? 'N/A'); ?></p>
<hr>
<h2>Work Experience</h2>
<div><?php echo nl2br(htmlspecialchars(json_encode($cv_data['experience'] ?? []))); ?></div>
<h2>Education</h2>
<div><?php echo nl2br(htmlspecialchars(json_encode($cv_data['education'] ?? []))); ?></div>
<h2>Skills</h2>
<p><?php echo nl2br(htmlspecialchars($cv_data['skills'] ?? '')); ?></p>
<a href="/dashboard.php">Back to Dashboard</a>
</div>
</body>
</html>
<?php
}