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

date_default_timezone_set('Africa/Lagos');

session_start();

    $department = $_SESSION['department'];
    $level = $_SESSION['level'];
    $session = $_SESSION['session'];
    $semester = $_SESSION['semester'];
    
    if(isset($_POST['department']))
    {
        $department = $_POST['department'];
        $level = $_POST['level'];
        $session = $_POST['session'];
        $semester = $_POST['semester'];
    }

$count=0;

$output = '';



class coursePDF extends PDF_MC_TABLE
{	
public $department;
public $session;
public $level;
public $semester;
public $date;
	function Head()
	{
// 		$this->department = trim(strtoupper($department));
		$this->Image('images/icon.png',10,15);
		$this->SetFont('Arial','B',14);
		$this->Cell(189,5,'OSUN STATE COLLEGE OF TECHNOLOGY, ESA-OKE.',0,0,'C');
		$this->Ln();
		$this->SetFont('Times','',12);
		$this->Cell(189,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(189,2,'Directorate of ICT, Esa-Oke Copyright © 2018. All Rights Reserved.',0,0,'C');
		$this->Ln();
		$this->SetFont('Arial','',8);
		$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	}
	function headerTable($department, $level, $session, $semester)
	{
	   // $this->Image('images/img2.png',0,0,210,300);
	    
		$this->SetFont('Times','BU',14);
		$this->Cell(189,20,'Registered Students',0,0,'C');
		$this->Ln();
		$this->Cell(189,5,strtoupper($department.' '.$level.' I'),0,0,'C');
// 		$this->Ln();
// 		$this->Cell(189,10,strtoupper($level),0,0,'C');
		$this->Ln(5);
		$this->SetFont('Times','',10);
		$this->Cell(189,10,'Session: '.$session.' '.$semester.'  Semester',0,1,'L');
		$this->Cell(189,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,40,60,30,22));//width for each column
		$this->SetAligns(Array('C','C','L','L','C','C'));
		$this->SetLineHeight(5);//Height of text lines
		$this->SetFont('Times','',12);
		
		$get_id = ONLINEPAY::get_ses_sem_id($session,$semester);
        foreach ($get_id as $r){ $id = $r->ses_sem_id; }
        
        if ($level == 'ND')
        {
            $table = 'ndi_tbl';
            $rg = ONLINEPAY:: reg_students($table,$department,$id);
        }
        elseif ($level == 'ND II')
        {
            $table = 'ndii_tbl';
            $rg = ONLINEPAY:: reg_students($table,$department,$id);
        }
        elseif ($level == 'HND')
        {
            $table = 'hndi_tbl';
            $rg = ONLINEPAY:: reg_students($table,$department,$id);
        }
        elseif ($level == 'HND II')
        {
            $table = 'hndii_tbl';
            $rg = ONLINEPAY:: reg_students($table,$department,$id);
        }
		$this->Cell(10,10,'S/N',1,0,'C',true);
		$this->Cell(30,10,"Form 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(50,10,"Department",1,0,"C",true);
		$this->Cell(30,10,"Reg Date",1,0,"C",true);
		$this->Cell(22,10,"Remarks",1,1,"C",true);

		foreach($rg as $pay)
		{
		    $names = ONLINEPAY:: getdetails($pay->matricno);
            foreach ($names as $row)
            {
                $surname = $row->surname;
                $othernames = $row->othernames;
                $email = $row->email;
                $formno = $row->formno;
                $user_data = Userdata::mat($formno, $email);
                foreach ($user_data as $act_lev_mat)
                {
                    $matricno = $act_lev_mat->matricno;
                }
            }
		    $this->Row(Array(
			    ++$count,
			 //   $pay->matricno,
			    $matricno,
			    trim(strtoupper($surname)),
			    trim(strtoupper($othernames)),
			 //   trim(strtoupper($pay->department)),
			    $pay->regDate,
			    ' ',
		        ));
		}
	}
}


$pdf = new coursePDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Head();
// $pdf->Background();
// $pdf->Ln(6);
$pdf->headerTable($department, $level, $session, $semester);

$pdf->Output();
?>