36416-vm/generate-pdf.php
Flatlogic Bot 6cef6ef090 Deris Ai
2025-11-28 17:47:44 +00:00

77 lines
2.3 KiB
PHP

<?php
require_once __DIR__ . '/libs/fpdf.php';
session_start();
// Basic validation
if (!isset($_SESSION['user_id']) || $_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST['score']) || empty($_POST['suggestions']) || empty($_POST['resume_text'])) {
// Redirect to dashboard if data is missing
header("Location: dashboard.php");
exit;
}
$score = $_POST['score'];
$suggestions = json_decode($_POST['suggestions'], true);
$resumeText = $_POST['resume_text'];
$userName = $_SESSION['user_name'] ?? 'User';
$projectName = $_SERVER['PROJECT_NAME'] ?? 'Deris AI';
class PDF extends FPDF
{
// Page header
function Header()
{
global $projectName;
// Logo
$this->Image('assets/pasted-20251128-163837-87f97f7a.png', 10, 6, 30);
$this->SetFont('Arial', 'B', 16);
$this->Cell(0, 10, $projectName . ' - Resume Analysis Report', 0, 1, 'C');
$this->Ln(20);
}
// Page footer
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial', 'I', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
}
// Report content
function ReportContent($score, $suggestions, $resumeText, $userName)
{
$this->SetFont('Arial', '', 12);
$this->Cell(0, 10, 'Report for: ' . $userName, 0, 1);
$this->Cell(0, 10, 'Date: ' . date('Y-m-d'), 0, 1);
$this->Ln(10);
// Score
$this->SetFont('Arial', 'B', 14);
$this->Cell(0, 10, 'Your Quick Score', 0, 1, 'C');
$this->SetFont('Arial', 'B', 48);
$this->Cell(0, 30, $score, 0, 1, 'C');
$this->Ln(10);
// Suggestions
$this->SetFont('Arial', 'B', 14);
$this->Cell(0, 10, 'Top Suggestions', 0, 1);
$this->SetFont('Arial', '', 12);
foreach ($suggestions as $suggestion) {
$this->MultiCell(0, 10, '- ' . $suggestion, 0, 1);
}
$this->Ln(10);
// Original resume text
$this->SetFont('Arial', 'B', 14);
$this->Cell(0, 10, 'Original Resume Text', 0, 1);
$this->SetFont('Arial', '', 10);
$this->MultiCell(0, 5, $resumeText, 1, 'L');
}
}
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->ReportContent($score, $suggestions, $resumeText, $userName);
$pdf->Output('D', 'Deris_AI_Report.pdf');