<?php

function all_print_offer($offer_id){
	
	$g_path = get_item('select value from settings where name = "putanja.abs" ');
	$l_path = $g_path.'app/webroot/res/files/';
	$l_name = 'ponuda_temp_'.$offer_id.'.pdf';
	
	// Pozovi CakePHP print_offer funkciju
	$_SERVER['REQUEST_URI'] = '/malo/reports/print_offer/'.$offer_id;
	$_GET['url'] = 'reports/print_offer/'.$offer_id;
	
	// Uhvati output
	ob_start();
	
	// Include CakePHP
	define('DS', DIRECTORY_SEPARATOR);
	if (!defined('ROOT')) {
		define('ROOT', $g_path);
	}
	define('APP_DIR', 'app');
	define('WEBROOT_DIR', 'webroot');
	if (!defined('WWW_ROOT')) {
		define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);
	}
	
	// Pozovi index.php koji će pozvati print_offer
	chdir($g_path);
	include($g_path . 'index.php');
	
	$pdf_content = ob_get_clean();
	
	// Spremi PDF
	if(strlen($pdf_content) > 100){
		file_put_contents($l_path.$l_name, $pdf_content);
		return array('result' => 1, 'file' => $l_name);
	}
	
	return array('result' => 0);
}

?>
