Files
monpas/application/controllers/monpas/Swvversies.php
T
2021-07-10 16:25:16 +02:00

159 lines
5.4 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Swvversies extends MY_Controller{
function __construct(){
parent::__construct();
$models = array( "monpas/Antwoordtypes_model",
"monpas/Antwoordopties_model",
"shared/Users_model",
'shared/Organisaties_model',
"monpas/Versies_model",
"monpas/Orgversies_model",
"monpas/Modules_model");
$this->load->model($models);
$this->load->helper('string');
if ( ! $this->check_online_status() ) {
echo json_encode( array('offline' => TRUE) );
die;
};// if
}
function getswvs(){
if (!$this->userid) die;
$orgs=null;
if ($this->super){
$swvs = $this->Organisaties_model->getorgs(1);
if ($swvs ){
foreach($swvs as $swv){
$swv->kamers = $this->Organisaties_model->getorgs(2, $swv->id);
}
}
}; // if super
echo json_encode($swvs);
}
function getkoppelingen(){
//TODO clean input
if (!$this->userid) die;
$orgid = $this->clean_input("orgid");
$module = $this->clean_input("module");
$koppelingen = $this->Orgversies_model->getallorgversies($orgid, $module);
if ($koppelingen){
if ($koppelingen[0]->id == null) {$koppelingen='';};
}
echo json_encode($koppelingen);
}
function insertkoppeling(){
if (!$this->userid) die;
$orgid = $this->clean_input("orgid");
$periodenummer = $this->Orgversies_model->getmaxperiode($orgid);
if ($periodenummer) {$nummer = $periodenummer->nummer + 1 ; }
else {$nummer = 1; };
// kijk of er al een actieve koppeling is, zo nee dan wordt dit de actieve koppeling
if ($this->Orgversies_model->get_records_where(array("organisatie_id" =>$orgid, "actief" =>1)) )
{$actief = 0 ;}
else {$actief = 1 ;};
$data = array("organisatie_id" => $orgid,
"periodenummer" => $nummer,
"actief" => $actief,
"versie_id" => $this->input->post("versieid"),
"geldigvanaf" => date2mysql($this->input->post("geldigvanaf")),
"geldigtm" => date2mysql($this->input->post("geldigtm")),
"invullentm" => date2mysql($this->input->post("invullentm")),
"vorm" => $this->input->post("vormid"),
"scoretype" => $this->input->post("scoretype"),
"score_omschrijving" => $this->clean_input('omschrijving')
);
$newid = $this->Orgversies_model->insert_record($data);
$koppeling = $this->Orgversies_model->getkoppeling($newid);
echo json_encode($koppeling);
}
function deletekoppeling(){
if (!$this->userid) die;
$orgversieid = $this->uri->segment(4);
$this->Orgversies_model->delete_record($orgversieid);
echo json_encode(true);
}
function updatekoppeling(){
if (!$this->userid) die;
$orgversieid = $this->clean_input("id");
$datumvanaf = date2mysql($this->clean_input("geldigvanaf"));
$datumtm = date2mysql($this->clean_input("geldigtm"));
$datuminvullen = date2mysql($this->clean_input("invullentm"));
$omschrijving = $this->clean_input('omschrijving')== false ? 'F' : 'T';
$this->Orgversies_model->update_record(array("geldigvanaf" =>$datumvanaf,
"geldigtm" =>$datumtm,
"invullentm" =>$datuminvullen,
"vorm" =>$this->input->post("vormid"),
"scoretype" =>$this->input->post("scoretype") ), $orgversieid);
echo json_encode(true);
}
function updatetoonomschrijving(){
if (!$this->userid) die;
$orgversieid = $this->clean_input("id");
$omschrijving = $this->clean_input('omschrijving');
$this->Orgversies_model->update_record(array(
"score_omschrijving" =>$omschrijving), $orgversieid);
echo json_encode(true);
}
function getantwoordtypes(){
$types = $this->Antwoordtypes_model->getalltypes();
echo json_encode($types);
}
function getAntwoordtypesEnOmschrijving(){
$types = $this->Antwoordtypes_model->getalltypes();
foreach($types as $type){
$type->opties = $this->Antwoordopties_model->getopties($type->sysnr);
}
echo json_encode($types);
}
function updateAntwoordopties(){if (!$this->userid) die;
$optieID = $this->clean_input('id');
$omschrijving = $this->input->post('omschrijving');
$this->Antwoordopties_model->update_record(['omschrijving' =>$omschrijving], $optieID);
$this->json(true);
}
function getversies(){
if (!$this->userid) die;
$module = $this->clean_input("module");
$versies = $this->Versies_model->getversiesbymodule($module);
echo json_encode($versies);
}
function maakactief(){
if (!$this->userid) die;
$orgversieid = $this->uri->segment(4);
$modulesysnr = $this->uri->segment(5);
$orgid = $this->Orgversies_model->get_fieldvalue(array("id"=>$orgversieid), 'organisatie_id');
$this->Orgversies_model->updateactief($orgid, $modulesysnr);
$data=array("actief"=>1);
$this->Orgversies_model->update_record($data, $orgversieid);
}
function maakinactief(){
if (!$this->userid) die;
$orgversieid = $this->uri->segment(4);
$data = array("actief " => 0);
$this->Orgversies_model->update_record($data, $orgversieid);
}
function getmodulesmetlijst(){
if (!$this->userid) die;
$modules = $this->Modules_model->getmodulesmetlijst();
echo json_encode($modules);
}
}