<?php
require_once("./includes/initialize.php");
global $database;

date_default_timezone_set('Africa/Lagos');

session_start();
    $department = $_SESSION['department'];
    $level = $_SESSION['level'];
    $programme = $_SESSION['programme'];
    if(isset($_POST['department']))
    {
        $department = $_POST['department'];
        $level = $_POST['level'];
        $programme = $_POST['programme'];
    }
$count=0;

$output = '';

class coursePDF extends PDF_MC_TABLE
{	
public $department;
public $programme;
public $level;
public $msg;
	function Head()
	{
		$this->Image('images/icon.png',5,5);
		$this->SetFont('Arial','B',14);
		$this->Cell(300,5,'OSUN STATE COLLEGE OF TECHNOLOGY, ESA-OKE.',0,0,'C');
		$this->Ln();
		$this->SetFont('Times','',12);
		$this->Cell(300,5,'P.M.B 1011, ESA-OKE, OSUN STATE.',0,0,'C');
		$this->Ln(10);
	}
	function Background(){
          $this->Image('images/img2.png',0,0,210,300);
   }

	function footer()
	{
		$this->SetY(-15);
		$this->SetFont('Times','',10);
		$this->Cell(300,2,'Directorate of ICT, Esa-Oke Copyright © 2019. All Rights Reserved.',0,0,'C');
		$this->Ln();
		$this->SetFont('Arial','',8);
		$this->Cell(300,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	}
	function headerTable($department, $level, $programme)
	{
            if ($level == 'ND' && $programme == 'PU')
            {
                $msg = 'National Diploma On Full-Time Programme '.$department;
            }
            elseif ($level == 'ND' && $programme == 'DP')
            {
                $msg = 'National Diploma On Daily Part-Time Programme '.$department;
            }elseif ($level == 'HND' && $programme == 'FT')
            {
                $msg = 'Higher National Diploma On Full-Time Programme '.$department;
            }elseif ($level == 'HND' && $programme == 'DP')
            {
                $msg = 'Higher National Diploma On Daily Part-Time Programme '.$department;
            }
	    
		$this->SetFont('Times','BU',14);
		$this->Cell(300,10,'MATRICULATION LIST',0,1,'C');
		$this->Cell(300,10,strtoupper($msg),0,0,'C');
		$this->Ln(5);
		$this->SetFont('Times','',10);
		$this->Cell(280,10,'Printed Date: '.date('d/m/Y h:i a'),0,1,'R');
		$this->SetFont('Times','B',10);
		$this->SetFillColor(150,255,150);
		$this->SetWidths(Array(10,30,30,40,60,70,15));//width for each column
		$this->SetAligns(Array('C','C','C','L','L','C','C'));
		$this->SetLineHeight(6);//Height of text lines
		$this->SetFont('Times','',12);
		
		if ($department !="" && $level !="" && $programme !="")
		{
		    $mat_list = ONLINEPAY::view_matricno($department, $level, $programme);
		}
        
		$this->Cell(10,10,'S/N',1,0,'C',true);
		$this->Cell(30,10,"Form No.",1,0,"C",true);
		$this->Cell(30,10,"Matric No.",1,0,"C",true);
		$this->Cell(40,10,"Surname",1,0,"C",true);
		$this->Cell(60,10,"Other Names",1,0,"C",true);
		$this->Cell(70,10,"Department",1,0,"C",true);
		$this->Cell(15,10,"Level",1,1,"C",true);
		
		foreach ($mat_list as $list)
		{
		    $this->Row(Array(
			    ++$count,
			    $list->formno,
			    $list->matricno,
			    trim(strtoupper($list->surname)),
			    trim(strtoupper($list->othernames)),
			    trim(strtoupper($list->department)),
			    $list->level,
		        ));
		}
	}
}


$pdf = new coursePDF('L','mm','A4');
$pdf->AliasNbPages();
$pdf->AddPage('C');
$pdf->Head();
// $pdf->Background();
$pdf->Ln(6);
$pdf->headerTable($department, $level, $programme);

$pdf->Output();
?>