Files
monpas/application/models/Phantom_model.php
T

133 lines
4.0 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Description of Phantom_model
*
* @author Theo Weijmer
* @date juni 28, 2013 1:41 PM
*
*
*
*/
class Phantom_model extends CI_Model{
public function create_pdf($html, $file, $header=FALSE, $footer=FALSE, $margins=array(),$orientatie="PORTRAIT"){
if( ! is_array($margins) ) $margins = array();
$curl = curl_init();
$data = array('html'=>$html, 'file'=>$file, 'app'=>'MONPAS');
if( $header ) $data['header'] = $header;
if( $footer ) $data['footer'] = $footer;
if( $margins ) $data['margins'] = serialize($margins);
$data['orientation']=$orientatie;
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://print.pensare-services.nl/print',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data
));
$pdf = curl_exec($curl);
curl_close($curl);
// echo($pdf);
// die;
$date = new DateTime();
$file.= '_'.$date->format('U').'.pdf';
// CodeIgniter SPECIFIEK
$this->load->helper('download');
force_download($file, $pdf);
}
public function create_img($html, $file, $header=FALSE, $footer=FALSE, $margins=array()){
if( ! is_array($margins) ) $margins = array();
$curl = curl_init();
$data = array('html'=>$html, 'file'=>$file, 'app'=>'MONPAS');
if( $header ) $data['header'] = $header;
if( $footer ) $data['footer'] = $footer;
if( $margins ) $data['margins'] = serialize($margins);
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://print.pensare-services.nl/test/1',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data
));
$img= curl_exec($curl);
//file_put_contents( 'test.png', $img);
curl_close($curl);
// return $img;
return base64_encode($img);
// $date = new DateTime();
// $file = '~/Sites/monpas/public/img/'.$file.'_'.$date->format('U').'.png';
// // CodeIgniter SPECIFIEK
// $this->load->helper('download');
// force_download($file, $img);
}
function create_pdf_with_save($html, $file, $header = FALSE, $footer = FALSE, $margins = array(), $orientation='portrait', $path=FALSE)
{
$this->load->helper( 'file' );
$pdf = $this->create_and_get_pdf( $html, $file, $header, $footer, $margins, $orientation );
$date = new DateTime();
if ($path ) {
$file = $file;
$filePath = $path.$file;
}
else {
$file = $file . '_' . $date->format( 'U' );
$filePath = $this->compactsoppath . $file . '.pdf';
}
write_file( $filePath, $pdf );
return $file;
}
function create_and_get_pdf($html, $file, $header = FALSE, $footer = FALSE, $margins = array(), $orientation, $footerFirstpage=TRUE, $headerFirstpage=TRUE)
{
//margins [left, right, top, bottom, height header]
if ( ! is_array( $margins ) ) $margins = array();
$curl = curl_init();
$data = array('html' => $html, 'file' => $file, 'app' => 'Monpas');
if ( $header ) $data['header'] = $header;
if ( $footer ) $data['footer'] = $footer;
if ( $margins ) $data['margins'] = serialize( $margins );
$data['footerFirstpage'] = $footerFirstpage;
$data['headerFirstpage'] = $headerFirstpage;
$data['orientation'] = $orientation;
curl_setopt_array( $curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $_ENV['printserver'],
// CURLOPT_URL => 'http://pdf.pensare-services.nl/index.php/pdfcreate',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $data
) );
$pdf = curl_exec( $curl );
curl_close( $curl );
return $pdf;
}
}