<?php 
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/**
* @version $Id: shop.pdf_output.php,v 1.2 2005/01/27 19:34:03 soeren_nb Exp $
* @package mambo-phpShop
* @subpackage HTML
* @copyright (C) 2004-2005 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*/
mm_showMyFileName( __FILE__ );

$showpage = mosGetParam( $_REQUEST, 'showpage');
$flypage = mosGetParam( $_REQUEST, 'flypage');
$product_id = mosGetParam( $_REQUEST, 'product_id');
$category_id = mosGetParam( $_REQUEST, 'category_id');

/* Who cares for Safe Mode ? Not me! */
if (@file_exists( "/usr/bin/htmldoc" )) {
	
	$load_page = $mosConfig_live_site . "/index2.php?option=com_phpshop&page=$page&flypage=$flypage&product_id=$product_id&category_id=$category_id&pop=1&hide_js=1&output=pdf";
	header( "Content-Type: application/pdf" );
	header( "Content-Disposition: inline; filename=\"pdf-mambo.pdf\"" );
	flush();
	//following line for Linux only - windows may need the path as well...
	passthru( "/usr/bin/htmldoc --no-localfiles --no-compression -t pdf14 --jpeg --webpage --header t.D --footer ./. --size letter --left 0.5in '$load_page'" );
} 
else {
	freePDF( $showpage, $flypage, $product_id, $category_id );
}

function freePDF( $showpage, $flypage, $product_id, $category_id ) {
	global $db, $sess, $auth, $my, $perm, $PHPSHOP_LANG, $mosConfig_live_site, $mosConfig_sitename, $mosConfig_offset, $mosConfig_hideCreateDate, $mosConfig_hideAuthor, 
	$mosConfig_hideModifyDate, $database, $mainframe, $mosConfig_absolute_path, $vendor_full_image, $vendor_name;
	
	ob_end_clean();
	error_reporting( 0 );
	ini_set( "allow_url_fopen", "1" );
	define('FPDF_FONTPATH', CLASSPATH.'pdf/font/');
	require( CLASSPATH.'pdf/html2fpdf_site.php');
	
	$pdf=new PDF();
	$pdf->AddPage();
	$pdf->SetFont('Arial','',11);
	$logo = IMAGEPATH . "vendor/$vendor_full_image";
	//$pdf->PutTitle($mosConfig_sitename);
	$pdf->InitLogo($logo);
	$pdf->PutAuthor( $vendor_name );
	
	switch( $showpage ) {  
	  
	case "shop.product_details":
	  
	  $_REQUEST['flypage'] = "shop.flypage_lite_pdf";
	  $_REQUEST['product_id'] = $product_id;
	  ob_start();
	  include( PAGEPATH . $showpage . '.php' );
	  $html = ob_get_contents();
	  
	  ob_end_clean();
	  $pdf->WriteHTML($html);
	  break;
	
	case "shop.browse":
	  $_REQUEST['category_id'] = $category_id;
	  ob_start();
	  include( PAGEPATH . 'shop.browse.php' );
	  $html = ob_get_contents();
	  ob_end_clean();
	  //echo $html; exit;
	  $pdf->WriteHTML($html);
	  break;
	}
	//Output the file
	$pdf->Output();		
}
