<?php
// Copyright 2007 FMWebschool Inc. this file is part of FMStudio

set_include_path(dirname(__FILE__).'/PEAR' . PATH_SEPARATOR . get_include_path());

require_once('lib/html2fpdf.php');

function FMStudio_PDF($fileName,$paper,$orientation,$options,$engine) {
	global $HTTP_SERVER_VARS;
	
	session_write_close();
	
	switch($engine) {
	case 'html2fpdf':
		if(!isset($HTTP_SERVER_VARS)) {
			$HTTP_SERVER_VARS = $_SERVER;
		}
		$html = ob_get_contents();
		ob_end_clean();
				error_reporting(E_ALL);
		$pdf = new HTML2FPDF(substr(strtoupper($orientation),0,1),'mm',$paper);
		$pdf->SetDisplayMode('fullpage','single');
		$pdf->usecss = true;
		$err = error_reporting(0);
		$pdf->UseTableHeader(true);
		$pdf->AddPage();
		$pdf->WriteHTML($html);
		//	die();
		//	var_dump($pdf);die();
//		header('content-type: application/pdf');

//		die('here');
		$pdf->Output($fileName,'I');
		break;
	default:
		die("The engine \"{$engine}\" is not currently supported by this version of the FMWebschool PDF Module.");
	}
}

ob_start();
?>