session()->has('student_id') || $request->session()->has('student_log_id') || auth()->check(); } /** * Academic Calendar PDF Download */ public function downloadAcademicCalendar(Request $request) { if (!$this->isAuthenticated($request)) { return redirect()->route('students')->with('error', 'Please login first to download official academic documents!'); } $title = "Official Academic Calendar 2026"; $subtitle = "Semester Schedules, Lecture Weeks, Holidays & Important Deadlines"; $refNo = "REF: AC-2026-CAL"; $tables = [ [ 'title' => '1. SEMESTER DATES & LECTURE WEEKS', 'headers' => ['Academic Event / Phase', 'Start Date', 'End Date', 'Status'], 'rows' => [ ['Semester 1 Commencement', 'January 15, 2026', 'March 20, 2026', 'Active'], ['Mid-Semester Recess', 'March 21, 2026', 'March 29, 2026', 'Scheduled'], ['Practical Lab Intensive Weeks', 'March 30, 2026', 'May 15, 2026', 'Scheduled'], ['Semester 1 Final Examinations', 'June 01, 2026', 'June 20, 2026', 'Scheduled'], ['Semester 2 Commencement', 'July 15, 2026', 'November 30, 2026', 'Upcoming'] ] ], [ 'title' => '2. INSTITUTIONAL & PUBLIC HOLIDAYS', 'headers' => ['Holiday / Event Name', 'Date(s)', 'Impact on Classes'], 'rows' => [ ['National Independence Day', 'February 04, 2026', 'Campus Closed'], ['Sinhala & Tamil New Year Vacation', 'April 12 - April 18, 2026', 'No Lectures / Workshops'], ['Vesak Festival Holiday', 'May 23 - May 25, 2026', 'Campus Closed'], ['Annual Automotive Tech Symposium', 'August 20, 2026', 'Special Event (Mandatory Attendance)'] ] ], [ 'title' => '3. CRITICAL ACADEMIC DEADLINES', 'headers' => ['Deadline Description', 'Cut-off Date', 'Action Required'], 'rows' => [ ['Course Module Drop / Add Period', 'February 10, 2026', 'Submit online form'], ['Mid-Term Assignment 1 Submission', 'March 18, 2026', 'Upload via Portal'], ['Examination Fee Clearance', 'May 15, 2026', 'Settle at Finance Office'] ] ] ]; return $this->renderPdf($title, $subtitle, $refNo, $tables, "Academic_Calendar_2026.pdf"); } /** * Student Handbook PDF Download */ public function downloadStudentHandbook(Request $request) { if (!$this->isAuthenticated($request)) { return redirect()->route('students')->with('error', 'Please login first to download official academic documents!'); } $title = "Student Handbook & Code of Conduct"; $subtitle = "Academic Regulations, Workshop Safety Rules & Grading Policies"; $refNo = "REF: HB-2026-REG"; $tables = [ [ 'title' => '1. ATTENDANCE & ACADEMIC INTEGRITY POLICIES', 'headers' => ['Regulation Category', 'Requirement / Policy Detail', 'Penalty for Violation'], 'rows' => [ ['Class Attendance', 'Minimum 80% attendance required for practical labs and lectures.', 'Barred from Final Exams'], ['Academic Honesty', 'Zero tolerance for plagiarism, cheating, or proxy attendance.', 'Disciplinary Hearing & Grade F'], ['Enrollment Status', 'Students must maintain continuous registration every term.', 'De-registration after 30 days'] ] ], [ 'title' => '2. WORKSHOP & HIGH-VOLTAGE LAB SAFETY RULES', 'headers' => ['Safety Protocol', 'Required Equipment / PPE', 'Compliance Rule'], 'rows' => [ ['General Workshop PPE', 'Safety boots (steel toe), protective eyewear, lab coats', 'Mandatory at all times'], ['Hybrid / EV High Voltage Labs', 'Class 0 rated insulated safety gloves (1000V rated)', 'Strict supervision required'], ['Vehicle Lift Operation', 'Hydraulic lift locks must be verified before underbody work', 'Never operate alone'] ] ], [ 'title' => '3. ACADEMIC GRADING SCHEME', 'headers' => ['Grade', 'Percentage Range', 'GPA Value', 'Classification'], 'rows' => [ ['A+', '90% - 100%', '4.00', 'High Distinction'], ['A', '80% - 89%', '3.70', 'Distinction'], ['B', '70% - 79%', '3.00', 'Credit Pass'], ['C', '55% - 69%', '2.00', 'Pass'], ['F', 'Below 50%', '0.00', 'Fail (Re-sit Required)'] ] ] ]; return $this->renderPdf($title, $subtitle, $refNo, $tables, "Student_Handbook_2026.pdf"); } /** * Exam Code of Conduct PDF Download */ public function downloadExamCode(Request $request) { if (!$this->isAuthenticated($request)) { return redirect()->route('students')->with('error', 'Please login first to download official academic documents!'); } $title = "Exam Code of Conduct & Rules"; $subtitle = "Examination Hall Admission, Practical Station Rules & Disciplinary Code"; $refNo = "REF: EX-2026-RULES"; $tables = [ [ 'title' => '1. EXAMINATION HALL ADMISSION RULES', 'headers' => ['Rule Item', 'Requirement Detail', 'Enforcement'], 'rows' => [ ['Student Identification', 'Valid Student ID Card & Exam Admission Ticket required.', 'Strictly Enforced'], ['Entry Time Limit', 'Candidates admitted up to 30 minutes after commencement.', 'No extra time given'], ['Prohibited Items', 'Mobile phones, smartwatches, programmable notes, bags.', 'Immediate Confiscation'] ] ], [ 'title' => '2. PRACTICAL DIAGNOSTIC EXAMINATIONS', 'headers' => ['Station Requirement', 'Procedure Standard', 'Evaluator Note'], 'rows' => [ ['Station Attire', 'Clean workshop overall and non-slip safety shoes required.', 'Visual inspection at entry'], ['Tool Calibration', 'Verify diagnostic scan tools before beginning fault-finding.', 'Instructor verification'], ['Safety Shutoff', 'Always disengage high-voltage battery service plug first.', 'Immediate disqualification if missed'] ] ] ]; return $this->renderPdf($title, $subtitle, $refNo, $tables, "Exam_Code_of_Conduct_2026.pdf"); } /** * Student Helpdesk Guide PDF Download */ public function downloadHelpdeskGuide(Request $request) { if (!$this->isAuthenticated($request)) { return redirect()->route('students')->with('error', 'Please login first to download official academic documents!'); } $title = "Student Helpdesk & Support Directory"; $subtitle = "Portal Assistance, Technical Enquiries & Department Contact List"; $refNo = "REF: HD-2026-SUPP"; $tables = [ [ 'title' => '1. PORTAL & IT SUPPORT CHANNELS', 'headers' => ['Support Issue', 'Resolution Method', 'Response Time'], 'rows' => [ ['Password & PIN Reset', 'Self-service PIN reset or visit IT Help Desk (Level 2)', 'Instant / 15 Mins'], ['Module Material Access', 'Email portal-support@autoedu.lk with Student ID', 'Within 2 Hours'], ['Wi-Fi & Email Setup', 'Visit Student IT Counter with Student ID Card', 'Immediate'] ] ], [ 'title' => '2. DEPARTMENT CONTACT DIRECTORY', 'headers' => ['Department Name', 'Location', 'Extension', 'Official Email'], 'rows' => [ ['Student Affairs & Registration', 'Admin Block - Ground Floor', 'Ext. 101', 'students@autoedu.lk'], ['Finance & Tuition Payments', 'Admin Block - Room 104', 'Ext. 104', 'finance@autoedu.lk'], ['Examinations & Results Branch', 'Academic Wing - Room 202', 'Ext. 108', 'exams@autoedu.lk'], ['Automotive Workshop Office', 'Lab Complex - Block B', 'Ext. 112', 'workshop@autoedu.lk'] ] ] ]; return $this->renderPdf($title, $subtitle, $refNo, $tables, "Student_Helpdesk_Support_Guide.pdf"); } /** * Render HTML to DomPDF output */ private function renderPdf($title, $subtitle, $refNo, $tables, $filename) { $studentName = session('student_name', 'Authenticated Student'); $studentId = session('student_id', 'STU-2026-0042'); $dateStr = date('F d, Y'); $tablesHtml = ''; foreach ($tables as $table) { $tablesHtml .= '
' . htmlspecialchars($table['title']) . '
'; $tablesHtml .= ''; foreach ($table['headers'] as $th) { $tablesHtml .= ''; } $tablesHtml .= ''; foreach ($table['rows'] as $row) { $tablesHtml .= ''; foreach ($row as $cell) { $tablesHtml .= ''; } $tablesHtml .= ''; } $tablesHtml .= 'tbody>
' . htmlspecialchars($th) . '
' . htmlspecialchars($cell) . '
'; } $html = ' ' . htmlspecialchars($title) . '
AutoEdu Automotive Academy
Department of Automotive Engineering & Applied Research | ISO 9001 Certified
' . htmlspecialchars($refNo) . '

' . htmlspecialchars($title) . '

' . htmlspecialchars($subtitle) . '

Issued To: ' . htmlspecialchars($studentName) . ' Student ID: ' . htmlspecialchars($studentId) . ' Issue Date: ' . htmlspecialchars($dateStr) . '
' . $tablesHtml . ' '; try { $options = new Options(); $options->set('isHtml5ParserEnabled', true); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); return response($dompdf->output(), 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="' . $filename . '"', 'Cache-Control' => 'private, max-age=0, must-revalidate', 'Pragma' => 'public' ]); } catch (\Exception $e) { // Fallback response if rendering fails return response($html, 200, [ 'Content-Type' => 'text/html', ]); } } }