<?php
require_once("./includes/initialize.php");
global $database;
// require_once("./includes/pdf_mc_table.php");
// include('pdf_mc_table.php');
date_default_timezone_set('Africa/Lagos');

session_start();
$allsession = ONLINEPAY:: showsession();
// $adm_list =ONLINEPAY::showpayment_online("admitted_students");

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

$count=0;

$output = '';



class coursePDF extends PDF_MC_TABLE
{	
public $start_date;
public $end_date;
public $department;
public $session;
public $level;
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(20);
	}
	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,$prog, $level, $session)
	{
	   // $this->Image('images/img2.png',0,0,210,300);
	    
		$this->SetFont('Times','BU',14);
		$this->Cell(189,20,'ADMITTED LIST',0,0,'C');
		$this->Ln(10);
		$this->SetFont('Times','',10);
		$this->Cell(189,10,'Admitted Session: '.$session,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,25,29,40,50,14,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);
		if ($department !="" && $level !="" && $session !="")
		{
		    $adm_list = ONLINEPAY:: search_session($department, $prog, $level, $session);
		}
		elseif ($department =="" && $level !="" && $session !="")
		{
		    $adm_list = ONLINEPAY:: search_level($level, $session);
		    
		    $query = "SELECT department, COUNT(formno) FROM admission_list WHERE level = '$level' AND session = '$session' GROUP BY department";
            $result = mysql_query($query) or die(mysql_error());
		}
		$this->Cell(10,10,'S/N',1,0,'C',true);
		$this->Cell(25,10,"Form No.",1,0,"C",true);
		$this->Cell(29,10,"Surname",1,0,"C",true);
		$this->Cell(40,10,"Other Names",1,0,"C",true);
		$this->Cell(50,10,"Department",1,0,"C",true);
		$this->Cell(14,10,"Level",1,0,"C",true);
		$this->Cell(22,10,"Session",1,1,"C",true);
		$total = 0;
		foreach ($adm_list as $list)
		{
		    $this->Row(Array(
			    ++$count,
			    $list->formno,
			    trim(strtoupper($list->surname)),
			    trim(strtoupper($list->othernames)),
			    trim(strtoupper($list->department)),
			    $list->level,
			    $list->session,
		        ));
		}
		$this->AddPage();
		if ($result){
		    $this->SetWidths(Array(40,55));//width for each column
		    $this->SetAligns(Array('C','C'));
    		$this->Cell(40,10,'Number of Students',1,0,'C',true);
    		$this->Cell(55,10,"Department",1,1,"C",true);
    		while($row = mysql_fetch_array($result)){
    		    $this->Row(Array(
                    $row['COUNT(formno)'],
                    $row['department'],
                    ));
            }
		}
	}
}


$pdf = new coursePDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Head();
$pdf->Background();
$pdf->Ln(6);


$pdf->headerTable($department,$prog, $level, $session);

$pdf->Output();
?>