Files
monpas/application/controllers/monpas/Sopoud.php
T
2021-07-13 14:58:26 +02:00

457 lines
17 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sopoud extends MY_Controller{
function __construct(){
parent::__construct();
$models = array("shared/Autorisaties_model",
"Docx_model",
"monpas/Hoofdstukken_model",
"monpas/Modules_model",
"monpas/Sop_model",
"monpas/Sopinhouden_model",
"Phantom_model");
$this->load->model($models);
$this->load->helper('string');
if ( ! $this->check_online_status() ) {
echo json_encode( array('offline' => TRUE) );
die;
};// if
}
function getrechten(){
if (!$this->userid) die;
$editok = false;
if ($this->Autorisaties_model->check_autorisatie($this->userrole,259 ) > 0) $editok = true;
echo json_encode($editok);
}
function getchapters(){
$chapters= $this->Hoofdstukken_model->getoldchapters();
foreach ($chapters as $chapter){
$chapter->aanwezig = false;
}
echo json_encode($chapters);
}
function getschooljaarversies($profielid, $chapterid){
$availversies = $this->Schooljaren_model->getschooljaren();
if ($availversies) {
foreach($availversies as $versie){
$versie->id = $versie->schooljaarnr;
}
}
$currentorgversie = $this->Sopinhouden_model->get_fieldvalue(array("profiel_id"=>$profielid, "chapter_id"=>$chapterid), "orgversieid");
if ($currentorgversie == NULL || $currentorgversie == 'undefined' || ! $currentorgversie){
$currentorgversie= $this->Sopinhouden_model->getschooljaar($profielid);
if ($currentorgversie == NULL && $availversies){
$currentorgversie = $availversies[0]->schooljaarnr;
}
}
$versies = array( "currentorgversie" =>$currentorgversie,"availversies" => $availversies);
return $versies;
}
function getlijstversies($profielid, $modulenr, $chapterid){
$orgid = $this->globorgid;
$profiel = $this->Sop_model->get_record_by_id($profielid);
$versies = $this->Filledversions_model->getfilledversionsperorg($orgid, $modulenr);
$fvid = 0;
$availversies = [];
if ($versies){
foreach($versies as $versie){
$versie->naam = $versie->periodenummer.': '.$versie->geldigvanaf.' - '.$versie->geldigtm;
$fvid = $this->Scores_model->fGetGevuldeVersies($versie->id, $orgid);
if($fvid && $fvid > 0){
$availversies []= $versie;
}
}
}
$currentorgversie = $this->Sopinhouden_model->get_fieldvalue(array("profiel_id"=>$profielid, "chapter_id"=>$chapterid), "orgversieid");
if ($currentorgversie == NULL){
$currentorgversies =$this->Filledversions_model->getversiesperorgperperiode($orgid, $modulenr,$profiel->van, $profiel->tm);
if ($currentorgversies){
$currentorgversie = $currentorgversies[0]->id;
}
else {
// zet currentorgversie op de eerste versie uit de lijst van versies, indien aanwezig
if ($availversies){
$currentorgversie = $availversies[0]->id;
}
};//ELSE
}; //IF ORGVERSIE == NULL
$versies= array('currentorgversie' => $currentorgversie, 'availversies'=>$availversies);
return $versies;
}
function Getversies($profielid,$chapterid){
$versies = [];
$hoofdstuk = $this->Hoofdstukken_model->get_record_by_id($chapterid);
if ($hoofdstuk->module == 0 ) return $versies;
$module = $this->Modules_model->get_record_by_id( $hoofdstuk->module);
if($module){
if (intval($module->versietype) == 1) {
$versies = $this->getschooljaarversies($profielid, $chapterid);
}
if (intval($module->versietype) == 2) {
$versies = $this->getlijstversies($profielid, $module->sysnr, $chapterid);
} ;
}
return $versies;
}
function controleerschool(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$school = false;
$organisatie = $this->Organisaties_model->get_record_by_id($orgid);
if ($organisatie && $organisatie->soort == 4) $school = true;
echo json_encode($school);
}
function getprofielen(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$profielen = $this->Sop_model->getprofielen($orgid);
echo json_encode($profielen);
}
function maaknewprofiel(){
if (!$this->userid) die;
$orgid =$this->globorgid;
$data = array( 'organisatie_id'=> $orgid,
'naam' =>$this->clean_input("naam"),
'van' => date2mysql($this->clean_input("van")),
'tm' => date2mysql($this->clean_input('tm')),
'versie' => 'OUD');
$newid = $this->Sop_model->insert_record($data);
$profiel =$this->Sop_model->getprofiel($newid);
echo json_encode($profiel);
}
function updateprofiel(){
if (!$this->userid) die;
$data = array('naam' =>$this->clean_input("naam"),
'van' => date2mysql($this->clean_input("van")),
'tm' => date2mysql($this->clean_input('tm')),
'versie' => 'OUD' );
$this->Sop_model->update_record($data, $this->clean_input('id'));
echo json_encode('ok');
}
function deleteprofiel(){
if (!$this->userid) die;
//delete het tb_profiel record en alle records in de hoofdstukken tabel
$targetid= $this->uri->segment(4);
$this->Sop_model->delete_record($targetid);
}
function getchaptercontent(){
if (!$this->userid) die;
$chapterid = $this->clean_input("chapterid");
$profielid = $this->clean_input("profielid");
$targetversieid = $this->clean_input("versieid");
$versies = $this->Getversies($profielid, $chapterid);
if (!$targetversieid && (count($versies) > 0 ) && $versies['currentorgversie']) {
$targetversieid = $versies['currentorgversie'];
}
$content = $this->Sopinhouden_model->get_records_where(array('profiel_id'=>$profielid, 'chapter_id'=>$chapterid),true);
if (!$content){
$returnarray = $this->Sopinhouden_model->maakcontent($chapterid,$profielid, $targetversieid);
$contenttekst = $returnarray['content'];
$inhoudid = $this->savecontent($chapterid,$profielid,$contenttekst, $returnarray['versie']);
$content = $this->Sopinhouden_model->get_records_where(array("id"=>$inhoudid),true);
}
if ($content && is_null($content->orgversieid)){
// kan nog voorkomen bij "oude hoofdstukken"
$targetversie = $this->getversieandsave($profielid, $chapterid, $targetversieid);
$content->orgversieid = $targetversie;
}
echo json_encode(array('inhoud'=>$content, 'versies'=>$versies));
}
function getversieandsave($profielid, $chapterid, $targetversieid){
$versie = $targetversieid;
$orgid = $this->globorgid;
$chapter = $this->Hoofdstukken_model->get_record_by_id($chapterid);
$module = $this->Modules_model->get_record_by_id($chapter->module);
if (!$module ) return $versie;
if ($versie == null || $versie==0){
if ($module->versietype == 1) {
// get schooljaar
$versie = $this->Sopinhouden_model->gettargetjaar($profielid, $orgid, $chapterid);
}
if ($module->versietype == 2) {
// orgversie
$versie = $this->Sopinhouden_model->gettargetversie($profielid, $orgid, $chapterid);
}
}
$data = array('orgversieid' => $versie);
$where = array("profiel_id" => $profielid,
"chapter_id" => $chapterid);
$this->Sopinhouden_model->update_record_where($data, $where);
return $versie;
}
function savecontent($chapterid, $profielid,$content,$versie =FALSE){
if (!$this->userid) die;
$data = array( 'profiel_id' => $profielid,
'chapter_id' => $chapterid,
'content' => $content,
'orgversieid' => $versie);
$newid=$this->Sopinhouden_model->insert_record($data);
return $newid;
}
function saveinhoud(){
if (!$this->userid) die;
$tekst = $this->input->post('tekst');
$inhoudid = $this->input->post('id');
$orgversie = $this->input->post('orgversie');
if ($orgversie == '') $orgversie =null; // dit kan bij hoofdstuk inleiding
$this->Sopinhouden_model->update_record(array('content'=>$tekst, 'orgversieid' =>$orgversie), $inhoudid);
}
function maakHtml($profielid, $word){
if (!$this->userid) die;
$profiel = $this->Sop_model->get_record_by_id($profielid);
$jaar1 = substr($profiel->van,0, 4);
$jaar2 = substr($profiel->tm, 0, 4);
$organisatie = $this->Organisaties_model->get_record_by_id($this->globorgid);
$bg = $this->Organisaties_model->get_record_by_id($organisatie->valtonder_id);
$data=array( "profielid" => $profielid,
"orgnaam" => $organisatie->naam,
"jaar1" => $jaar1,
"jaar2" => $jaar2,
"bgnaam" =>$bg->naam);
$html=$this->load->view("monpas/sop/sopvoorpagina", $data, true);
$html=$html;
for ($i=1; $i<=12;$i++){
$where=array("profiel_id" => $profielid,
"chapter_id" => $i);
$tekst=$this->Sopinhouden_model->get_fieldvalue($where,'content');
if ($tekst){
if ($word){
$html=$html."<pagebreak />".$tekst;
}
else {
$html=$html."<div style='page-break-after:always'></div>".$tekst;
};
};
}
$html=$html.'</body></html>';
return $html;
}
function maakpdf(){
$input = json_decode($this->input->get('json'));
$profielid = $input->profielid;
$html = $this->maakHtml($profielid, false);
$filenaam="sop".date('YmdHis');
$this->Phantom_model->create_pdf($html,$filenaam, FALSE,FALSE,FALSE);
}
function maakword(){
$profielid = $this->uri->segment(4);
$html = $this->maakHtml($profielid,true);
$html ="<!doctype html><html><body>".$html.'</body></html>';
$this->Docx_model->create_word_document($html, 'sop'.date('YmdHis'));
}
function getschooldetails(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$html = $this->Sopinhouden_model->getcolofon();
echo json_encode($html);
}
function getdiversiteit1(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$profielid = $this->uri->segment(4);
$versie = $this->uri->segment(5);
$module = 2;
$dvt234 = $this->Sopinhouden_model->getdiversiteit234($profielid,$versie, $module);
$grafiekdiversiteit1 = $dvt234['divgrafiek1'];
$image=$this->Phantom_model->create_img($grafiekdiversiteit1, 'test.png', FALSE, FALSE, array(650, 300));
$imagedata = "<img src='data:image/png;base64,".$image."' id='divimage1'/>";
echo json_encode(array(
// 'dvt1' =>$dvt1,
'dvt2' =>$dvt234['dvt2'],
'dvt3' =>$dvt234['dvt3'],
'dvt4' =>$dvt234['dvt4'],
'imagedata' =>$imagedata));
}
function getondersteuning1(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$profielid = $this->uri->segment(4);
$versie =$this->uri->segment(5);
$result = $this->Sopinhouden_model->getondersteuning12($profielid,$versie);
echo json_encode(array('os1' =>$result['os1'] ,
"os2"=> $result['os2']) );
}
function getenquetemodule(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$profielid = $this->uri->segment(4);
$module = $this->uri->segment(5);
$chapterid = $this->uri->segment(6);
$versieid = $this->uri->segment(7);
if ($versieid && $versieid !== 'undefined' && $versieid > 0){
$result = $this->Sopinhouden_model->getenquetetabellen($profielid,$module,$chapterid,$versieid);
$image = $this->Phantom_model->create_img($result['grafiek1'], 'test.png', FALSE, FALSE, array(650, 300));
$imageid = "mod".$module."image1";
$imagedata = "<img src='data:image/png;base64,".$image."' id='.$imageid.'/>";
echo json_encode(array('tabel1' =>$result['tabel1'] ,
'imagedata' => $imagedata,
"tabel2" => $result['tabel2']) );
} else {
// if not versieid
echo json_encode(array('tabel1' =>'' ,
'imagedata' => '',
"tabel2" => '') );
}
}
function getontwikkelagenda(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$profielid = $this->uri->segment(4);
$module = $this->uri->segment(5);
$versie = $this->uri->segment(6);
$result = $this->Sopinhouden_model->getOntwikkelagenda($profielid,$module,$versie);
$imageoa = $this->Phantom_model->create_img($result['tabel1'], 'test.png', FALSE, FALSE, array(650, 300));
$id = "oa1image1";
if ( $module = 4) { $id = "oa2image1";};
$imagedata = "<img src='data:image/png;base64,".$imageoa."' id='".$id."'/>";
echo json_encode(array('image1' => $imagedata ,
"tabel2" => $result['tabel2']) );
}
function deletehoofdstuk(){
//TODO clean input
if (!$this->userid) die;
$profielid = $this->uri->segment(4);
$chapterid = $this->uri->segment(5);
$where= array('profiel_id' =>$profielid,
'chapter_id'=>$chapterid);
$this->Sopinhouden_model->delete_record_where($where);
echo json_encode('ok');
}
function getchapterids(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$profielid = $this->uri->segment(4);
$ids = $this->Sop_model->getsopchapterids($profielid);
echo json_encode($ids);
}
function getenquetemoduleandsave(){
if (!$this->userid) die;
$orgid = $this->globorgid;
$profielid = $this->input->post("profielid");
$chapterid = $this->input->post("hoofdstuk");
$versie = $this->input->post("versie");
$chapter = $this->Hoofdstukken_model->get_record_by_id($chapterid);
$module = $this->Modules_model->get_record_by_id($chapter->module);
// $module = 1;
// if ($chapterid == 7 || $chapterid ==12) $module = 4;
$where= array( "profiel_id" =>$profielid,
"chapter_id" =>$chapterid);
$content= $this->Sopinhouden_model->get_fieldvalue($where,'content');
if ($content) {
switch ($chapterid){
case 6: $result = $this->Sopinhouden_model->getenquetetabellen($profielid,$module->sysnr,$chapterid,$versie);
$imagemb =$this->Phantom_model->create_img( $result['grafiek1'], 'test.png', FALSE, FALSE, array(650, 300));
$imagemb = "<div class='grafiekholdermonbas'><img src='data:image/png;base64,".$imagemb."' id='mod1image1'/></div>";
$search = '~<div class="grafiekholdermonbas">[\s\S]*?</div>~';
$content = preg_replace($search, $imagemb,$content);
$monbas1 ="<div class='tableholdermonbasteam'>".$result['tabel1']."</div>";
$search = '~<div class="tableholdermonbasteam">[\s\S]*?</div>~';
$content = preg_replace($search, $monbas1,$content);
$monbas2 ="<div class='tableholdermonbasschool'>".$result['tabel2']."</div>";
$search = '~<div class="tableholdermonbasschool">[\s\S]*?</div>~';
$content = preg_replace($search, $monbas2,$content);
break;
case 7:
$result =$this->Sopinhouden_model->getenquetetabellen($profielid,$module->sysnr,$chapterid,$versie);
$imagesm =$this->Phantom_model->create_img($result['grafiek1'], 'test.png', FALSE, FALSE, array(650, 300));
$imagedata = "<div class='grafiekholdersm'><img src='data:image/png;base64,".$imagesm."' id='mod4image1'/><?]/div>";
$search = '~<div class="grafiekholdersm">[\s\S]*?</div>~';
$content = preg_replace($search, $imagedata,$content);
$sm1 = "<div class='tableholdersm1'>".$result['tabel1']."</div>";
$search = '~<div class="tableholdersm1">[\s\S]*?</div>~';
$content = preg_replace($search, $sm1,$content);
$sm2 = "<div class='tableholdersm2'>".$result['tabel2']."</div>";
$search = '~<div class="tableholdersm2">[\s\S]*?</div>~';
$content = preg_replace($search, $sm2,$content);
break;
case 11:
// Ontwikkelagenda Monbas
$result = $this->Sopinhouden_model->getOntwikkelagenda($profielid,$module->sysnr,$versie);
$oa1 = "<div class='tableholderontwikkelagenda1'>".$result['tabel1']."</div>";
$search = "~<div class='tableholderontwikkelagenda1'>[\s\S]*?</div>~";
$content = preg_replace($search, $oa1,$content);
$oa2 = "<div class='tableholderontwikkelagenda2'>".$result['tabel2']."</div>";
$search = "~<div class='tableholderontwikkelagenda2'>[\s\S]*?</div>~";
$content = preg_replace($search, $oa2,$content);
break;
case 12:
// Ontwikkelagenda Schoolmeter
$result = $this->Sopinhouden_model->getOntwikkelagenda($profielid,$module->sysnr,$versie);
$oa1 = "<div class='tableholderontwikkelagenda1'>".$result['tabel1']."</div>";
$search = "~<div class='tableholderontwikkelagenda1'>[\s\S]*?</div>~";
$content = preg_replace($search, $oa1,$content);
$oa2 = "<div class='tableholderontwikkelagenda2'>".$result['tabel2']."</div>";
$search = "~<div class='tableholderontwikkelagenda2'>[\s\S]*?</div>~";
$content = preg_replace($search, $oa2,$content);
break;
}; // switch
$data=array("content" => $content) ;
$this->Sopinhouden_model->update_record_where($data,$where);
}; // if content
echo json_encode('ok');
}
function saveversie(){
$inhoudid = $this->clean_input('inhoudid');
$orgversieid = $this->clean_input('versie');
$chapterid = $this->clean_input('chapterid');
$profielid = $this->clean_input("profielid");
$chapteridlist = $this->clean_input("chapids");
$this->Sopinhouden_model->update_record(array("orgversieid"=>$orgversieid), $inhoudid);
$inhoud = $this->Sopinhouden_model->maakcontent($chapterid, $profielid);
$this->Sopinhouden_model->update_record(array('content'=>$inhoud['content']), $inhoudid);
if ($chapteridlist){
foreach($chapteridlist as $chapterid){
$where=array("chapter_id"=>$chapterid, "profiel_id"=>$profielid);
$this->Sopinhouden_model->update_record_where(array("orgversieid"=>$orgversieid), $where);
$inhoud = $this->Sopinhouden_model->maakcontent($chapterid, $profielid);
$this->Sopinhouden_model->update_record_where(array('content'=>$inhoud['content']), $where);
}; // foreach
}; // if list
echo json_encode(true);
}
}