Files
monpas/application/controllers/monpas/Beheer.php
T
2022-04-28 20:47:54 +02:00

223 lines
8.0 KiB
PHP

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Beheer extends MY_Controller{
function __construct(){
parent::__construct();
$models = array( "shared/Users_model",
"monpas/Menus_model",
"monpas/Modules_model",
"monpas/Versies_model",
"monpas/Ijkpunten_model",
"monpas/Indicatoren_model",
"monpas/Compactsoponderdelen_model");
$this->load->model($models);
$this->load->helper('string');
if ( ! $this->check_online_status() ) {
echo json_encode( array('offline' => TRUE) );
die;
};// if
}
function getmodules(){
$modules = $this->Modules_model->getmodulesmetlijst();
echo json_encode($modules);
}
function getallmodules(){
$modules = $this->Modules_model->getallmodulesmetcluster();
echo json_encode($modules);
}
function getversies(){
if (!$this->userid) die;
$module=$this->uri->segment(4);
$versies=$this->Versies_model->getallversies($module);
if ($versies){
foreach($versies as $versie){
$versie->ingangsdatum = mysql2date($versie->ingangsdatum);
$versie->systemnorm = str_replace('.', ',', $versie->systemnorm);
$versie->deleteok = true;
//TODO deleteok bepalen
}
}
echo json_encode($versies);
}
function insertversie(){
//TODO clean input
if (!$this->userid || !$this->super) die;
$naam = $this->clean_input("nieuwnaam");
$module = $this->clean_input("module");
$id = $this->Versies_model->insert_record(array( 'naam' =>$naam ,
'modulenr' =>$module,
'ingangsdatum' =>date('Y-m-d')));
$versie = $this->Versies_model->getversie($id);
$versie->ingangsdatum =mysql2date($versie->ingangsdatum);
$versie->systemnorm = str_replace('.', ',', $versie->systemnorm);
$versie->deleteok = true;
echo json_encode($versie);
}
function updateversie(){
//TODO clean input
if (!$this->userid || !$this->super) die;
$data = array('naam' => $this->clean_input('naam') ,
'ingangsdatum' =>date2mysql($this->clean_input('ingangsdatum')),
'systemnorm' => str_replace(',', '.', $this->clean_input('systemnorm') ));
$this->Versies_model->update_record($data, $this->clean_input('id'));
}
function deleteversie(){
// TODO clean input en controleer foreign key afhankelijkheden
if (!$this->userid || !$this->super) die;
$errortekst='';
if (! $this->writer) {$errortekst ="U bent niet geautoriseerd om versies te verwijderen.";}
else {
$versieid = $this->uri->segment(4);
$this->Versies_model->delete_record($versieid);
}
echo json_encode($errortekst);
}
function getijkpunten(){
//TODO clean input
if (!$this->userid ) die;
$versieid = $this->uri->segment(4);
$ijkpunten = $this->Ijkpunten_model->getijkpunten1($versieid);
if ($ijkpunten){
foreach($ijkpunten as $ijkpunt){
$ijkpunt->indicatoren= $this->Indicatoren_model->getindicatoren($ijkpunt->id);
}; // foreach
}; // if ijkpunten
echo json_encode($ijkpunten);
}
function insertijkpunt(){
if (!$this->userid ) die;
$data=array('nummer' => $this->clean_input("nummer"),
"versie_id" => $this->clean_input("versie_id"),
'omschrijving' => $this->clean_input('omschrijving'),
'toelichting' => $this->clean_input('toelichting') );
$id = $this->Ijkpunten_model->insert_record( $data);
$ijkpunt = $this->Ijkpunten_model->getijkpunt($id);
echo json_encode($ijkpunt);
}
function updateijkpunt(){
if (!$this->userid ) die;
//TODO clean input
$data= array('nummer' => $this->clean_input("nummer"),
"versie_id" => $this->clean_input("versie_id"),
"omschrijving" => $this->clean_input("omschrijving"),
"toelichting" =>$this->clean_input("toelichting") );
$this->Ijkpunten_model->update_record($data, $this->clean_input('id'));
}
function deleteijkpunt(){
//TODO clean input
if (!$this->userid || ($this->Autorisaties_model->check_autorisatie($this->userrole, WRITER) <= 0)) {die;};
$ijkid =$this->uri->segment(4);
$this->Ijkpunten_model->delete_record($ijkid);
}
function insertindicator(){
//TODO clean input
if (!$this->userid || ($this->Autorisaties_model->check_autorisatie($this->userrole, WRITER) <= 0)) {die;};
$data=array("ijkpunt_id" => $this->clean_input('ijkpunt_id'),
"nummer" => $this->clean_input('nummer' ),
"gewicht" => str_replace(',','.', $this->clean_input('gewicht')),
"inspectie" =>$this->clean_input('inspectie'),
"omschrijving1" => $this->clean_input('omschrijving1'),
"omschrijving2" => $this->clean_input('omschrijving2')
);
$id = $this->Indicatoren_model->insert_record($data);
$indicator = $this->Indicatoren_model->getindicator($id);
$indicator->deleteok = true;
echo json_encode($indicator);
}
function deleteindicator(){
//TODO clean input
if (!$this->writer || !$this->userid) return;
$this->Indicatoren_model->delete_record($this->uri->segment(4));
echo json_encode(true);
}
function updateindicator(){
//TODO clean input
if (!$this->writer || !$this->userid) return;
$indicatorid = $this->clean_input("id");
$data = array('nummer' => $this->clean_input("nummer"),
"omschrijving1" => $this->clean_input("omschrijving1"),
"omschrijving2" => $this->clean_input("omschrijving2"),
"inspectie" => $this->clean_input("inspectie"),
"gewicht" => $this->clean_input("gewicht"));
$this->Indicatoren_model->update_record($data, $indicatorid);
}
function disableijkpunt(){
if (!$this->userid ) die;
$ijkpuntid = $this->clean_input("id");
$disabled = $this->clean_input("disabled");
$this->Ijkpunten_model->update_record(['disabled' => $disabled ], $ijkpuntid);
}
function moduleinsop(){
if (!$this->userid) die;
$modulenr = $this->clean_input("sysnr");
$inSOP = $this->clean_input("inSOP");
$blokjesnaam = $this->clean_input("blokjesnaam");
$sopnaam = $this->clean_input("sopnaam");
$sopID = $this->Compactsoponderdelen_model->get_fieldvalue(['module_nr' =>$modulenr], 'id');
if ($sopID ) {
$this->Compactsoponderdelen_model->update_record(
['in_sop' => $inSOP,
'sopnaam' => $sopnaam,
'blokjesnaam' => $blokjesnaam], $sopID);
} else {
$sopID = $this->Compactsoponderdelen_model->insert_record(
['sopnaam' => $sopnaam,
'blokjesnaam' => $blokjesnaam,
'module_nr' => $modulenr,
'in_sop' => $inSOP
]
);
}
echo json_encode($sopID);
}
function savesopnaam(){
if (!$this->userid) die;
$modulenr = $this->clean_input("sysnr");
$sopnaam = $this->clean_input("sopnaam");
$sopID = $this->Compactsoponderdelen_model->get_fieldvalue(['module_nr' =>$modulenr], 'id');
if ($sopID ) {
$this->Compactsoponderdelen_model->update_record(['sopnaam' => $sopnaam], $sopID);
} else {
$sopID = $this->Compactsoponderdelen_model->insert_record(
['sopnaam' => $sopnaam,
'blokjesnaam' => '',
'module_nr' => $modulenr,
'in_sop' => 'F'
]
);
}
echo json_encode($sopID);
}
function saveblokjesnaam(){
if (!$this->userid) die;
$modulenr = $this->clean_input("sysnr");
$blokjesnaam = $this->clean_input("blokjesnaam");
$sopID = $this->Compactsoponderdelen_model->get_fieldvalue(['module_nr' =>$modulenr], 'id');
if ($sopID) {
$this->Compactsoponderdelen_model->update_record(['blokjesnaam' => $blokjesnaam], $sopID);
} else {
$sopID = $this->Compactsoponderdelen_model->insert_record(
['sopnaam' => '',
'blokjesnaam' => $blokjesnaam,
'module_nr' => $modulenr,
'in_sop' => 'F'
]
);
}
echo json_encode($sopID);
}
}