<?php
require_once('tcpdf/tcpdf.php');

class PhonalisaPDF extends TCPDF {

	// Colored table
	public function ColoredTable($header, $footer ,$data, $headerColumns = array()) {
		// Colors, line width and bold font
		$this->SetFillColor(255, 0, 0);
		$this->SetTextColor(255);
		$this->SetDrawColor(128, 0, 0);
		$this->SetLineWidth(0.3);
		$this->SetFont('', 'B');
		
		if (count($headerColumns) == 0) { 
			// 	Header
			$w = array(50, 40, 30, 30, 30);
		} else {
			$w = $headerColumns;
		}
		
		$num_headers = count($header);
		for($i = 0; $i < $num_headers; ++$i) {
			$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
		}
		
		$this->Ln();
		// Color and font restoration
		$this->SetFillColor(224, 235, 255);
		$this->SetTextColor(0);
		$this->SetFont('');
		// Data
		$fill = 0;
		foreach ($data as $row) {
			$this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
			$this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
			if (count($row) > 3) {
				$this->Cell($w[2], 6, $row[2], 'LR', 0, 'R', $fill);
			} else {
				$this->Cell($w[2], 6, $row[2], 'LR', 0, 'L', $fill);
			}
			if(count($row) > 3) $this->Cell($w[2], 6, $row[3], 'LR', 0, 'R', $fill);
			if(count($row) > 4) $this->Cell($w[3], 6, $row[4], 'LR', 0, 'R', $fill);
			$this->Ln();
			$fill=!$fill;
		}
		
		//$this->Cell(array_sum($w), 0, '', 'T');
		
		foreach ($footer as $row) {
			$this->Cell($w[0]+$w[1]+$w[2]+$w[3], 6, $row[0], 'LRT', 0, 'L', $fill);
			
			$this->Cell($w[3], 6, $row[1], 'LRT', 0, 'R', $fill);
			$this->Ln();
			$fill=!$fill;
		}
		$this->Cell(array_sum($w), 0, '', 'T');
		
	}
}