'Visual',2=>'Auditory',3=>'Kinesthetic',4=>'Reflective',5=>'Active', 6=>'Visual',7=>'Auditory',8=>'Kinesthetic',9=>'Reflective',10=>'Active', 11=>'Visual',12=>'Auditory',13=>'Kinesthetic',14=>'Reflective',15=>'Active', 16=>'Visual',17=>'Auditory',18=>'Kinesthetic',19=>'Reflective',20=>'Active' ]; $option_weight = ['A'=>1,'B'=>2,'C'=>3,'D'=>2]; $style_score = [ 'Visual'=>0, 'Auditory'=>0, 'Kinesthetic'=>0, 'Reflective'=>0, 'Active'=>0 ]; foreach ($answers as $i => $opt) { $q = $i + 1; if (!isset($question_map[$q])) continue; $style_score[$question_map[$q]] += $option_weight[$opt] ?? 0; } arsort($style_score); $styles = array_keys($style_score); $primary = $styles[0]; $secondary = $styles[1]; /* ------------------------------- STUDENT CONTEXT -------------------------------- */ $student_roll = $_GET['roll'] ?? 'UNKNOWN'; $student_name = $_GET['name'] ?? 'Student'; /* ------------------------------- GENERATE PDF -------------------------------- */ $dompdf = new Dompdf(); ob_start(); ?>
Name: = htmlspecialchars($student_name) ?>
Roll No: = htmlspecialchars($student_roll) ?>
Primary Style: = $primary ?>
Secondary Style: = $secondary ?>
RS Learning Lab – Learning Behaviour Platform
loadHtml($html); $dompdf->setPaper('A4'); $dompdf->render(); $pdfDir = __DIR__ . '/generated_pdfs/'; if (!is_dir($pdfDir)) { mkdir($pdfDir, 0777, true); } $pdfFile = $pdfDir . $student_roll . '_learning_style.pdf'; file_put_contents($pdfFile, $dompdf->output()); // Web path for download $pdfWebPath = "generated_pdfs/" . $student_roll . "_learning_style.pdf"; /* ------------------------------- SAVE TO DATABASE -------------------------------- */ // check if record already exists $check = $pdo->prepare("SELECT id FROM learning_style_results WHERE student_roll=?"); $check->execute([$student_roll]); if ($check->rowCount() > 0) { $stmt = $pdo->prepare(" UPDATE learning_style_results SET student_name=?, primary_style=?, secondary_style=?, scores_json=?, pdf_path=? WHERE student_roll=? "); $stmt->execute([ $student_name, $primary, $secondary, json_encode($style_score), $pdfWebPath, $student_roll ]); } else { $stmt = $pdo->prepare(" INSERT INTO learning_style_results (student_roll, student_name, primary_style, secondary_style, scores_json, pdf_path) VALUES (?,?,?,?,?,?) "); $stmt->execute([ $student_roll, $student_name, $primary, $secondary, json_encode($style_score), $pdfWebPath ]); } $result = true; } ?>