<?php
// learning_passport.php
// RS Learning Lab – Learning Passport PDF Generator

// -------------------------------
// INPUT DATA (FROM SESSION / DB / GET)
// -------------------------------
$student_name   = $_GET['name']  ?? 'Student Name';
$roll_no        = $_GET['roll']  ?? 'N/A';
$class          = $_GET['class'] ?? 'N/A';

$primary_style   = $_GET['primary']   ?? 'Kinesthetic';
$secondary_style = $_GET['secondary'] ?? 'Active';

// Internal LEI signal (demo version)
$lei_signal = $_GET['lei'] ?? 'Moderate';

// Learning signals (comma separated)
$signals_raw = $_GET['signals'] ?? 
    'Learns best through hands-on practice,Engages quickly with applied tasks';

$signals = array_map('trim', explode(',', $signals_raw));

// -------------------------------
// FILE PATHS
// -------------------------------
$baseDir   = __DIR__;
$tmpHtml   = $baseDir . "/passport_tmp.html";
$outputPdf = $baseDir . "/passport_" . time() . ".pdf";

// -------------------------------
// HTML CONTENT FOR PASSPORT
// -------------------------------
$html = "
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Learning Passport</title>
<style>
body {
    font-family: Arial, sans-serif;
    padding: 40px;
    color: #0f172a;
}
.header {
    border-bottom: 3px solid #0b8c9f;
    padding-bottom: 10px;
    margin-bottom: 25px;
}
.header h1 {
    margin: 0;
    color: #0b8c9f;
}
.section {
    margin-bottom: 25px;
}
.section h2 {
    color: #ff7a00;
    font-size: 18px;
    margin-bottom: 10px;
}
.box {
    background: #f8fafc;
    padding: 15px;
    border-radius: 8px;
}
ul {
    margin: 0;
    padding-left: 20px;
}
.footer {
    position: fixed;
    bottom: 20px;
    font-size: 11px;
    color: #475569;
}
.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    background: #0b8c9f;
    color: #fff;
    font-size: 13px;
}
</style>
</head>

<body>

<div class='header'>
    <h1>RS Learning Lab – Learning Passport</h1>
    <p>A growth-based learning profile (Not a marksheet)</p>
</div>

<div class='section'>
    <h2>Student Details</h2>
    <div class='box'>
        <strong>Name:</strong> {$student_name}<br>
        <strong>Roll No:</strong> {$roll_no}<br>
        <strong>Class:</strong> {$class}
    </div>
</div>

<div class='section'>
    <h2>Learning Style Profile</h2>
    <div class='box'>
        <p><strong>Primary Learning Style:</strong> {$primary_style}</p>
        <p><strong>Secondary Learning Style:</strong> {$secondary_style}</p>
    </div>
</div>

<div class='section'>
    <h2>Learning Signals</h2>
    <div class='box'>
        <ul>";

foreach ($signals as $s) {
    $html .= "<li>{$s}</li>";
}

$html .= "
        </ul>
    </div>
</div>

<div class='section'>
    <h2>Learning Effectiveness Index (LEI)</h2>
    <div class='box'>
        <span class='badge'>LEI Signal: {$lei_signal}</span>
        <p style='margin-top:10px;'>
            LEI reflects learning consistency and improvement patterns.  
            This is an internal growth signal, not a score or rank.
        </p>
    </div>
</div>

<div class='section'>
    <h2>Important Note</h2>
    <div class='box'>
        <p>
        This Learning Passport focuses on <strong>how a student learns</strong>,
        how they improve through practice, and how they apply concepts.
        <br><br>
        This document is not an examination result, marksheet, or government certificate.
        </p>
    </div>
</div>

<div class='footer'>
    Generated by RS Learning Lab · Founder: Gokula Krishnan
</div>

</body>
</html>
";

// -------------------------------
// WRITE TEMP HTML
// -------------------------------
file_put_contents($tmpHtml, $html);

// -------------------------------
// GENERATE PDF USING WKHTMLTOPDF
// -------------------------------
//$wkhtml = "wkhtmltopdf";
//$command = "$wkhtml \"$tmpHtml\" \"$outputPdf\"";
//shell_exec($command);
echo $html;
exit;

// -------------------------------
// SERVE PDF FOR DOWNLOAD
// -------------------------------
if (file_exists($outputPdf)) {
    header('Content-Type: application/pdf');
    header('Content-Disposition: inline; filename="Learning_Passport.pdf"');
    readfile($outputPdf);
    exit;
} else {
    echo "PDF generation failed.";
}
