Files
monpas/application/controllers/monpas/Sortering.php
T
MoniqueandClaude Opus 5.5 172fcf566c CodeIgniter 3.1.11 -> 3.4.5 (pocketarc fork) en PHP 8.3-fixes
- system/ vervangen door CodeIgniter 3.4.5 (pocketarc/codeigniter, PHP 8.2-8.5 compatibel)
- config.php, mimes.php, user_agents.php en error-views bijgewerkt naar 3.4.5
- composer.json: php-constraint "^7.4 || ^8.0" zodat composer install op 8.3 werkt
- PHP 8-fatals opgelost: count()/array-functies op FALSE/null, rekenen met lege
  strings, delen door nul, property zetten op FALSE, curly-brace string offsets,
  ongedefinieerde constanten, foute curl_setopt in Phantom_model::create_img
- dynamic properties gedeclareerd in libraries, optionele parameters voor verplichte opgelost
- vergelijkingen waar '' == 0 in PHP 8 anders uitvalt gecast naar (int)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 09:34:46 +02:00

231 lines
7.5 KiB
PHP

<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
class Sortering extends MY_Controller {
function __construct()
{
parent::__construct();
$models = array(
"shared/Users_model",
"shared/Organisaties_model",
"shared/Orgusers_model",
"shared/Session_model",
"monpas/Sorteringen_model",
"monpas/Sorteerlabels_model",
"monpas/Sorteerlabelsorg_model",
);
$this->load->model( $models );
$this->load->helper( 'string' );
if ( ! $this->check_online_status() )
{
echo json_encode( array('offline' => TRUE) );
die;
};// if
}
function checkrechten()
{
// if ( ! $this->userid ) die;
// $orguserid = $this->Orgusers_model->get_fieldvalue( array("user_id" => $this->userid, "organisatie_id" => $this->globorgid), "id" );
// $niveau = $this->Autorisaties_model->get_fieldvalue( array("orguser_id" => $orguserid), "nivo_id" );
//
// if ( $niveau == 1 || $niveau == 2 )
// {
// echo json_encode( TRUE );
// }
// else
// {
// echo json_encode( FALSE );
// }
}
// function checkadmin(){
// $orguserid = $this->Orgusers_model->get_fieldvalue( array("user_id" => $this->userid, "organisatie_id" => $this->globorgid), "id" );
// $niveau = $this->Autorisaties_model->get_fieldvalue( array("orguser_id" => $orguserid), "nivo_id" );
//
// return $niveau;
// }
function getSortering(){
$swvID = $this->uri->segment(4);
$criteria = $this->Sorteringen_model->get_criteriabijSWV($swvID);
foreach($criteria as $criterium){
$labels = $this->Sorteerlabels_model->get_labels($criterium->id);
$label = new stdClass();
$label->id = 0;
$label->sortering_id = $criterium->id;
$label->naam ='niet ingedeeld';
$label->volgorde = 'LAATST';
if (is_array($labels)) array_push($labels, $label);
$criterium->labels = $labels;
}
echo json_encode($criteria);
}
function getSchoolIndelingen(){
$swvid = $this->clean_input('swvid');
$criteriumid = $this->clean_input('criteriumid');
$labels = $this->Sorteerlabels_model->get_labels($criteriumid);
$label = new stdClass();
$label->waardeid = 0;
$label->sortering_id = $criteriumid;
$label->naam ='niet ingedeeld';
$label->volgorde = 'LAATST';
if (is_array($labels)) array_push($labels, $label);
$swv = $this->Organisaties_model->get_record_by_id($swvid);
$swv->kamers = $this->Organisaties_model->getorgsvanaf($swvid);
if(!$swv->kamers){
echo json_encode(false);
}
if(!is_array($swv->kamers)){
$swv->kamers = objectToArray($swv->kamers);
}
foreach($swv->kamers as $kamer){
$kamer->bgs = $this->Organisaties_model->getorgsvanaf($kamer->id);
if ($kamer->bgs){
foreach($kamer->bgs as $bg){
$bg->scholen =$this->Organisaties_model->getorgsvanaf($bg->id);
if($bg->scholen) {
foreach ($bg->scholen as $school) {
$school->opties = $labels;
$school->indeling = $this->Sorteringen_model->getSchoolIndeling($school->id, $criteriumid);
if ( !$school->indeling) {
$school->indeling = new stdClass();
$school->indeling->waardeid = 0;
$school->indeling->waarde = 'niet ingedeeld';
$school->indeling->volgorde = 'LAATST';
}
}
}
}
}
}
echo json_encode($swv);
}
function saveCriterium(){
$swvID = $this->clean_input('swvID');
$naam = $this->clean_input('criterium');
$label1 = $this->clean_input('label1');
$label2 = $this->clean_input('label2');
$nieuwelabels = $this->clean_input('labelArray');
$labels = [];
array_push($labels, $label1, $label2);
if($nieuwelabels){
foreach($nieuwelabels as $label){
if(!empty($label['nieuwLabel'])){
array_push($labels, $label['nieuwLabel']);
}
}
}
$criteriumid = $this->Sorteringen_model->insert_record
(array('swv_id'=>$swvID,
'naam' =>$naam));
foreach($labels as $label){
$this->Sorteerlabels_model->insert_record
(array('sortering_id'=>$criteriumid,
'naam'=>$label));
}
echo json_encode($criteriumid);
}
function editCriterium(){
$swvID = $this->clean_input('swvID');
$criteriumid = $this->clean_input('criteriumid');
$naam = $this->clean_input('criterium');
$editlabels = $this->clean_input('labels');
$nieuwelabels = $this->clean_input('labelArray');
$labels = [];
if($editlabels){
foreach($editlabels as $label){
if(!empty($label['label'] && $label['label'] != "niet ingedeeld")){
array_push($labels, $label);
}
}
foreach($labels as $label){
$labelid = $label['waardeid'];
$waarde = $label['label'];
$this->Sorteerlabels_model->update_record_where(array('naam'=>$waarde),
array('id'=>$labelid));
}
}
$labelsNieuw = [];
if($nieuwelabels){
foreach($nieuwelabels as $label){
if(!empty($label['nieuwLabel'])){
array_push($labelsNieuw, $label['nieuwLabel']);
}
}
foreach($labelsNieuw as $label){
$this->Sorteerlabels_model->insert_record
(array('sortering_id'=>$criteriumid,
'naam'=>$label));
}
}
$this->Sorteringen_model->update_record
(array('swv_id'=>$swvID,
'naam' =>$naam), $criteriumid);
echo json_encode(true);
}
function deleteCriterium(){
$criteriumid = $this->uri->segment(4);
$this->Sorteerlabels_model->delete_record_where(array('sortering_id' =>$criteriumid));
$this->Sorteringen_model->delete_record($criteriumid);
echo json_encode(true);
}
function deleteLabel(){
$labelid = $this->uri->segment(4);
$this->Sorteerlabels_model->delete_record($labelid);
echo json_encode(true);
}
function updateSortering(){
$orgid = $this->clean_input('orgid');
$keuzeid = $this->clean_input('keuzeid');
$criteriumid = $this->clean_input('criteriumid');
$voorheen = $this->Sorteringen_model->getSchoolIndeling($orgid, $criteriumid);
if($voorheen){
$this->Sorteerlabelsorg_model->delete_record_where(array(
'label_id'=>$voorheen->waardeid,
'organisatie_id'=>$orgid ));
}
$id = $this->Sorteerlabelsorg_model->insert_record(array(
'label_id'=>$keuzeid,
'organisatie_id'=>$orgid));
echo json_encode($id);
}
}