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

   $Hod = $_SESSION["$HoD"];


     $department= $_SESSION['dept'];
     $session= $_SESSION['sess'];
     $level= $_SESSION['lev'];
    $semester= $_SESSION['semester'];
    $ses_sem_id = $_SESSION['ses_sem_id'];
   
   
//   echo $department= $_SESSION['dept'];
//   echo  $session= $_SESSION['sess'];
//   echo  $level= $_SESSION['lev'];
//   echo $semester= $_SESSION['semester'];
//   echo $ses_sem_id = $_SESSION['ses_sem_id'];
   
   
  $output=''; $output2='';$prog='';
  $course_arr=array();
 $courses=''; $count=0;

  $allS = $_SESSION['students'];

 // $allC = $_SESSION['code'];
//print_r($allS);





















class coursePDF extends PDF_MC_TABLE
{
    public $allS;
    public $allC;
    public $department;
    public $semester;
    public $level;
    public $session;
    public $count;
    public $ses_sem_id;
    
    function Head($department, $session, $level, $semester)
    {
	    $this->department = trim(strtoupper($department));
	    
        $this->Image('../../student_portal/images/img1.png', 5, 5);
        $this->SetFont('Arial', 'B', 14);
        $this->Cell(189, 8, 'OSUN STATE COLLEGE OF TECHNOLOGY, ESA-OKE.', 0, 1, 'C');
        $this->Ln(5);
        $this->SetFont('Arial', 'B', 12);
        $this->Cell(189, 8, 'DEPARTMENT OF ' . trim(strtoupper($department)), 0, 1, 'C');
        
        $this->Ln(5);
         $this->Cell(189,8, 'STUDENTS TEST PASS / ATTENDANCE',0,1,'C');
        $this->Ln(5);
       $this->SetFont('Arial', '', 12);
       $this->Cell(60, 8, 'SESSION: '.$session, 0, 0, 'C');
       
       $this->Cell(60, 8, 'LEVEL: '.$level, 0, 0, 'C');
       
       $this->Cell(60, 8, 'SEMESTER: '.strtoupper($semester), 0, 1, 'C');
       // $this->Ln(20);
    }

    function Background()
    {
        $this->Image('images/img1.png', 40, 80, 150, 150);
    }

    function footer()
    {
        $this->SetY(-15);
        $this->SetFont('Times', '', 10);
        $this->Cell(189, 2, 'YOU WILL NOT BE ALLOWED INTO THE EXAMINATION HALL WITHOUT THIS TEST/EXAM PASS.', 0, 1, 'C');
        $this->Ln();
        $this->SetFont('Times', '', 8);
        $this->Cell(189, 2, strtoupper('Directorate of ICLSTS, 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');
    }

     
}


        

        
       
       // print_r($allS);
        
        if (isset($allS) AND (sizeof($allS)>0)){
    
    $count=1; $oldC=0; $valC=0;
//  foreach ($allS as $student){

//       // while ($row = mysql_fetch_array($result)) {
//             //while ($row= mysql_fetch_array($result)){
//             $code = $row{"courses"};
//             $date = $row{"regDate"};
//         }
        
}


$pdf = new coursePDF('P','mm','A4');
$pdf->AliasNbPages();

$pdf->AddPage();//AddPage([string orientation [, mixed size [, int rotation]]])
$pdf->Head($department, $session, $level, $semester);

$pdf->SetFont('Times','B',10);
$pdf->Cell(320,20,$ftab,0,0,'C');


$pdf->Ln(5);

$pdf->Cell(189,8,'Printed Date: '.date('d/m/Y h:i a'),0,1,'R');
$pdf->SetFont('Times','B',10);
$pdf->SetFillColor(150,255,150);
$pdf->SetWidths(Array(15,30,50,35,30,30));//width for each column
$pdf->SetAligns(Array('C','C','C','C','C','C','C','C'));
$pdf->SetLineHeight(5);//Height of text lines
$pdf->SetFont('Times','',12);
$pdf->Cell(15,10,'S/N',1,0,'C',true);
$pdf->Cell(30,10,"Matric No",1,0,"C",true);
$pdf->Cell(50,10,"Full Name",1,0,"C",true);
$pdf->Cell(35,10,"Courses",1,0,"C",true);
$pdf->Cell(30,10,"Sign In",1,0,"C",true);
$pdf->Cell(30,10,"Sign Out",1,1,"C",true);

 foreach($allS as $student)
 {
    //   $pic = substr($student[2],11);
    //     if ($pic !='avatar.jpg'){
    //  $path = '../../application_account/passport/'.$pic;
    //     }
        
        $valC++;
         $course_arr = explode(",",$student[3]);
         
      
        $cu_Cum='';
         foreach ($course_arr as $c){
            
              $cu_CUM .= trim(strtoupper($c));
              
         
        if ($mat==$student[0]){
           $student[0]=''; 
           $student[1]='';
           $count = '';
        }else {
            $count=$valC;
        }
        
 $pdf->Row(Array(
          $count,
          $student[0],
          strtoupper($student[1]),
          
         $cu_CUM,
          '',
           '',

    ));
    $mat = $student[0];
    
    $cu_CUM='';
    
}

//echo "Test: ".$count++." ValC: ".$valC ;
}
$pdf->Output();
?>

        


