101 lines
4.0 KiB
PHP
101 lines
4.0 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Pdfmaker extends MY_Controller{
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
$models = array(
|
|
"Phantom_model",
|
|
"monpas/Compactsop_model",
|
|
"monpas/Schooldetails_model"
|
|
|
|
);
|
|
$this->load->model($models);
|
|
$this->load->helper('string');
|
|
// if ( ! $this->check_online_status() ) {
|
|
// echo json_encode( array('offline' => TRUE) );
|
|
// die;
|
|
// };// if
|
|
}
|
|
|
|
function pdfSVG(){
|
|
// if (!$this->userid) die;
|
|
$inputstring = $this->input->post('data');
|
|
$input = json_decode($inputstring);
|
|
$inhoud = $input->pagina;
|
|
$schooljaar = $input->titel;
|
|
$orgsoort = $input->orgsoort;
|
|
//maak goede titel
|
|
switch($orgsoort){
|
|
case 1 : $profiel = 'SWOP';
|
|
break;
|
|
case 2 : $profiel = 'ROP';
|
|
break;
|
|
case 3 : $profiel = 'BOP';
|
|
break;
|
|
default : $profiel = 'SOP';
|
|
}
|
|
$soptitel = 'Compact '.$profiel. ' ' . $schooljaar;
|
|
$schoolid = $input->schoolid;
|
|
$schooljaarnummer = $input->schooljaarnr;
|
|
$organisatie = $this->Organisaties_model->get(['id' => $schoolid],false, true);
|
|
$data['inhoud' ]= $inhoud;
|
|
$html = $this->load->view('monpas/compactsop/sopcompact.php', $data, TRUE);
|
|
$date = date('dmY');
|
|
$zoek = [" ", "'", "/"];
|
|
$bestandstitel = str_replace($zoek, "", $soptitel);
|
|
$schoolid = str_replace($zoek, "",$schoolid);
|
|
$sopschoolnaam = str_replace("'", "'", $organisatie->naamkort);
|
|
$bestandsschoolnaam = str_replace($zoek, "",$sopschoolnaam);;
|
|
|
|
$frameworklogo= $this->config->item('vendor_url').'/images/logos/frameworklogo.png';
|
|
//
|
|
$logonaam = $this->Schooldetails_model->get(["organisatie_id" =>$schoolid],'logo', true);
|
|
if (! $logonaam) $logonaam="monpaslogo.png";
|
|
$schoollogo = $this->config->item('vendor_url').'/images/logos/'.$logonaam;
|
|
chmod($schoollogo, 0777);
|
|
|
|
$headerdata = ['titel' =>$soptitel,
|
|
'schoolnaam' =>$sopschoolnaam ? $sopschoolnaam : '',
|
|
'logoframework' =>$frameworklogo,
|
|
'logoschool' =>$schoollogo
|
|
];
|
|
// $footerdata = [];
|
|
$header = $this->load->view( "monpas/compactsop/compactheader", $headerdata, TRUE ) ;
|
|
// $footer = $this->load->view ("monpas/compactsop/compactfooter", $footerdata, TRUE);
|
|
$filenaam = $this->compactsoppath.'sop.pdf';
|
|
|
|
$bestandsnaam = "compactsop".$bestandsschoolnaam.$schoolid.$bestandstitel.'-'.$date.'.pdf';
|
|
$downloadnaam = $this->compactsoppath.$bestandsnaam;
|
|
|
|
// TODO check if exists
|
|
$data = [ 'organisatie_id' =>$schoolid,
|
|
'schooljaarnummer' => $schooljaarnummer];
|
|
$csop = $this->Compactsop_model->get($data,false, true);
|
|
|
|
if ($csop && $csop->id){
|
|
unlink($this->compactsoppath.$csop->pdfnaam);
|
|
$this->Compactsop_model->update_record(['pdfnaam'=>$bestandsnaam], $csop->id);
|
|
$sopid = $csop->id;
|
|
} else {
|
|
$data['pdfnaam'] = $bestandsnaam;
|
|
$sopid = $this->Compactsop_model->insert_record($data);
|
|
}
|
|
$margins = [15, 15,10, 5, 150]; //100 was 45 = headerheight
|
|
|
|
$pdf= $this->Phantom_model->create_and_get_pdf($html, $filenaam, $header, TRUE, $margins,'portrait',TRUE,TRUE);
|
|
file_put_contents($downloadnaam, $pdf);
|
|
chmod($downloadnaam, 0777);
|
|
|
|
|
|
|
|
// header( 'Content-Description: File Transfer' );
|
|
header( 'Content-Type: application/pdf' );
|
|
header( 'Content-disposition:inline; filename="' .$bestandsnaam.'"');
|
|
// header( 'Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0' );
|
|
// header( 'Pragma: public' );
|
|
// header( 'Content-Length: ' . filesize( $downloadnaam ) );
|
|
readfile($downloadnaam);
|
|
|
|
}
|
|
} |