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

date_default_timezone_set('Africa/Lagos');

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

$output = '';

class coursePDF extends PDF_MC_TABLE
{	
public $gender;
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($gender, $level, $programme)
	{
            if ($level == 'ND' && $programme == 'PU')
            {
                $msg = 'National Diploma On Full-Time Programme '.$gender;
            }
            elseif ($level == 'ND' && $programme == 'DP')
            {
                $msg = 'National Diploma On Daily Part-Time Programme '.$gender;
            }elseif ($level == 'HND' && $programme == 'FT')
            {
                $msg = 'Higher National Diploma On Full-Time Programme '.$gender;
            }elseif ($level == 'HND' && $programme == 'DP')
            {
                $msg = 'Higher National Diploma On Daily Part-Time Programme '.$gender;
            }
	    
		$this->SetFont('Times','BU',14);
		$this->Cell(300,10,"GENDER'S 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(20,150,45));//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 ($gender !="" && $level !="" && $programme !="")
		{
		   $query = "SELECT courses, COUNT(sex) FROM schoolfees_tranzact JOIN admitted_student_details ON 
                    schoolfees_tranzact.formno = admitted_student_details.formno
                    WHERE admitted_student_details.programme = '$level' AND schoolfees_tranzact.formno LIKE '%$programme%' AND 
                    admitted_student_details.sex = '$gender' AND schoolfees_tranzact.responsecode = '00' GROUP BY schoolfees_tranzact.department";
                    $result = mysql_query($query) or die(mysql_error());
		}
        
		$this->Cell(20,10,'S/N',1,0,'C',true);
		$this->Cell(150,10,"Department",1,0,"C",true);
		$this->Cell(45,10,"Number of ".$gender." Students",1,1,"C",true);
		
		if ($result)
        {
            while($row = mysql_fetch_array($result))
            {
                $this->Row(Array(
                    ++$count,
                    strtoupper($row['courses']),
                    $row['COUNT(sex)'],
                    ));
            }
        
        }
	}
}


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

$pdf->Output();
?>