<?php  
    require_once("./includes/initialize.php");
    global $database;
    
 function fetch_data()  
 {
     
    $department = $_POST['department'];
    $level = $_POST['level'];
    $session = $_POST['session'];
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];
    echo $department;
    $show = ONLINEPAY::search_all($department, $level, $session, $start_date, $end_date);
    $count = 0;
    foreach($show as $pay) 
    {
        $output.= '<tr>
				<td>'.++$count.'</td>
				<td>'.$pay->formno.'</td>
				<td>'.$pay->surname.'</td>
				<td>'.$pay->othernames.'</td>
				<td>'.$pay->department.'</td>
				<td>'.$pay->sex.'</td>
				<td>'.$pay->level.'</td>
				<td>'.$pay->session.'</td>
				<td>'.$pay->admitted_date.'</td>
			</tr>'; 
    }  
      return $output;  
 }  
 if(isset($_POST["Print_pdf"]))  
 {  
      require_once('TCPDF-master/tcpdf.php');  
      $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);  
      $obj_pdf->SetCreator(PDF_CREATOR);  
      $obj_pdf->SetTitle("Export HTML Table data to PDF using TCPDF in PHP");  
      $obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);  
      $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));  
      $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));  
      $obj_pdf->SetDefaultMonospacedFont('helvetica');  
      $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);  
      $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5', PDF_MARGIN_RIGHT);  
      $obj_pdf->setPrintHeader(false);  
      $obj_pdf->setPrintFooter(false);  
      $obj_pdf->SetAutoPageBreak(TRUE, 10);  
      $obj_pdf->SetFont('helvetica', '', 12);  
      $obj_pdf->AddPage();  
      $content = '';  
      $content .= '  
      <h3 align="center">Export HTML Table data to PDF using TCPDF in PHP</h3><br /><br />  
      <table border="1" cellspacing="0" cellpadding="5">  
           <tr>  
                <th width="5%">S/N</th>  
                <th width="10%">FORM NO</th>  
                <th width="20%">SURNAME</th>  
                <th width="30%">OTHER NAMES</th>  
                <th width="45%">DEPARTMENT</th>
                <th width="10%">SEX</th>
                <th width="10%">SESSION</th>
                <th width="10%">DATE/TIME</th>
           </tr>  
      ';  
      $content .= fetch_data();  
      $content .= '</table>';  
      $obj_pdf->writeHTML($content);  
      $obj_pdf->Output('sample.pdf', 'I');  
 }  
 ?>  