Files
monpas/application/controllers/monpas/Compactsop.php
T
2022-09-08 13:18:52 +02:00

172 lines
5.8 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Compactsop extends MY_Controller{
function __construct(){
parent::__construct();
$models = array(
"Docx_model",
"monpas/Arrangementen_model",
"monpas/Arrangementen_piv_aantal_model",
"monpas/Compactsop_model",
"monpas/Compactsoponderdelen_model",
"monpas/Diversiteits_model",
"monpas/Filledversions_model",
"monpas/Groepen_model",
"monpas/Ijkpunten_model",
"monpas/Indicatoren_model",
"shared/Kalenderjaren_model",
"shared/Aantalleerlingen_model",
"shared/Licenties_model",
"monpas/Menus_model",
"monpas/Modules_model",
"monpas/Ondersteuningtijden_model",
"monpas/Oordelen_model",
"monpas/Orgversies_model",
"shared/Schooljaren_model",
"monfin2/Finbestemmingen_model",
"monpas/Versies_model",
"Phantom_model",
"monpas/Scores_model",
"monpas/Sop_model",
"monpas/Sopinhouden_model",
"monpas/Sopviews_model",
"monpas/Tlvs_model"
);
$this->load->model($models);
$this->load->helper('string');
}
function getrechten(){
if (!$this->userid) die;
$editok = false;
$autorisatie = $this->Autorisaties_model->check_autorisatie($this->userrole,259 );
if ( $autorisatie> 0) $editok = true;
echo json_encode($editok);
}
function getorgsoort(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$soort = $this->Organisaties_model->get_fieldvalue(['id' => $this->globorgid], 'soort');
echo json_encode($soort);
}
function getSchooljaren(){
if (!$this->userid) die;
$schooljaren = $this->Schooljaren_model->getschooljaren();
echo json_encode($schooljaren);
}
function getCompactSop(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$schooljaar = $this->uri->segment(4);
$compactsopID = $this->Compactsop_model->get_fieldvalue(['organisatie_id'=>$orgid, 'schooljaarnummer'=>$schooljaar], 'id');
echo json_encode($compactsopID);
}
function download_pdf(){
$fileID = $this->uri->segment( 4 );
$this->Compactsop_model->downloadCompactSop ( $fileID );
}
function getOnderdelenEnVersies(){
if (!$this->userid) die;
$schooljaar = $this->uri->segment(4);
$orgsoort = $this->uri->segment(5);
$compacteversies = new Compacteversies($schooljaar, $orgsoort);
$onderdelen = $compacteversies->getOnderdelen();
echo json_encode($onderdelen);
}
function getOrganisatiegegevens(){
if (!$this->userid) die;
$school = $this->Schooldetails_model->getschool($this->globorgid);
if(!$school){
$school = $this->Organisaties_model->get_record_by_id($this->globorgid);
}
echo json_encode($school);
}
function saveSchool(){
if (!$this->userid) die;
$id = $this->clean_input('id');
if($id != $this->globorgid) return;
$straat = strip_slashes($this->clean_input('straat'));
$plaats = strip_slashes($this->clean_input('plaats'));
$foon = strip_slashes($this->clean_input('telefoon'));
$mail = strip_slashes($this->clean_input('email1'));
$web = strip_slashes($this->clean_input('web'));
$data = [
'straat' => $straat,
'plaats' => $plaats,
'telefoon' => $foon,
'email1' => $mail,
'web' => $web,
'organisatie_id' => $id
];
$this->Organisaties_model->update_record(['plaats' =>$plaats], $id);
$detailid = $this->Schooldetails_model->get_fieldvalue(['organisatie_id'=>$id], 'id');
if($detailid){
$this->Schooldetails_model->update_record($data,$detailid);
}
else{
$detailid = $this->Schooldetails_model->insert_record($data);
}
echo json_encode($detailid);
}
function maakPDF(){
if (!$this->userid) die;
$schooljaarnr = $this->clean_input('schooljaarnr');
$onderdelen = $this->input->post('onderdelen');
$omvangjaren = $this->clean_input('jaren');
$paginas = $this->clean_input('paginas');
$compact = new Compacteonderdelen($schooljaarnr, $onderdelen, $omvangjaren);
$compacteonderdelen = $compact->getCompacteOnderdelen();
$schoolID = $this->globorgid;
$html = (new Compactepaginas($compacteonderdelen, $paginas))->getHtml();
file_put_contents(MYROOTPATH.'public/tmp/temp'.$schoolID.'.html', $html);
echo json_encode($this->globorgid);
}
public function uploadLogo($schoolID)
{
$savePath = MYROOTPATH.'public/images/logos/';
$this->load->helper('string');
$pathParts = pathinfo($_FILES['image_file']['name']);
$extension = $pathParts['extension'];
$filename = random_string('alnum', 15).'.'.$extension;
$source = $_FILES['image_file']['tmp_name'];
$target = $savePath.$filename;
rename($source, $target );
//TODO: unlink eventueel oud logo
$logo = $this->Schooldetails_model->getLogo($schoolID);
$padNaam = $savePath.$logo;
unlink($padNaam);
$this->Schooldetails_model->update_record_where(['logo'=>$filename], ['organisatie_id' =>$schoolID]);
}
function getLogo(){
$schoolID = $this->clean_input('schoolID');
$logo =$this->Schooldetails_model->getLogo($schoolID);
$this->json($logo);
}
}