<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;

use Illuminate\Http\Request;

class LandingPageController extends Controller
{
    //
    public function home()
    {
        $contributions="100";
        $students = DB::table('tbl_students_data')->get();
        $totalStudentsRegistered = DB::table('tbl_students_data')->count();
        $trainingStations = DB::table('tbl_training_stations')->count();

        $data=[
            'contributions' => $contributions,
            'students' => $students,
            'totalStudentsRegistered' => $totalStudentsRegistered,
            'trainingStations' => $trainingStations,
            

        ];

        return view('collegelanding')->with($data);
    }

    public function viewPdfPage()
    {

        $refno="SJAK2024091886";

        $member = \DB::table('certified_members')
        ->where('cert_serial', $refno)
        ->first();

        $member = \DB::table('certified_members as cm')
        ->join('tbl_courses as c', 'cm.courseCode', '=', 'c.id')
        ->where('cm.cert_serial', $refno)
        ->select('cm.*', 'c.course_name as course_name')
        ->first();
        

         $data=[
            'refno' => $refno,   
            'member' => $member,   
            
        ];

        return view('pdfviewer')->with($data);
    }


    public function regenerateCert(Request $request)
    {
        $refno = $request->refno;
      
        $member = \DB::table('certified_members as cm')
        ->join('tbl_courses as c', 'cm.courseCode', '=', 'c.id')
        ->where('cm.cert_serial', $refno)
        ->select('cm.*', 'c.course_name as course_name')
        ->first();
        
         $data=[
            'refno' => $refno,   
            'member' => $member,               
        ];

        return view('pdfviewer')->with($data);
    }
}
