484 lines
16 KiB
PHP
484 lines
16 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Organisaties extends MY_Controller{
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
if ($this->nologin) return;
|
|
$models = array("monpas/Modules_model",
|
|
'shared/Organisaties_model',
|
|
'shared/Orgusers_model',
|
|
"shared/Users_model",
|
|
"monpas/Versies_model",
|
|
"monpas/Orgversies_model",
|
|
"monpas/Filledversions_model",
|
|
"monpas/Scores_model",
|
|
"monpas/Ambities_model",
|
|
"shared/Licenties_model");
|
|
$this->load->model($models);
|
|
$this->load->helper('string');
|
|
if ( ! $this->check_online_status() ) {
|
|
echo json_encode( array('offline' => TRUE) );
|
|
die;
|
|
};// if
|
|
}
|
|
|
|
function getorgsperlevel(){
|
|
$soort = $this->uri->segment(4);
|
|
$toporgid = $this->input->post("toporgid");
|
|
$orgs = $this->Organisaties_model->getorgsdetails($soort,$toporgid);
|
|
echo json_encode($orgs);
|
|
}
|
|
|
|
function getallowedorgs(){
|
|
$orgs =null;
|
|
if ($this->super || $this->userrole == 2){
|
|
$orgs = $this->Organisaties_model->getallorgs();
|
|
}
|
|
else {
|
|
$orgs = $this->Organisaties_model->getuserorgs($this->userid);
|
|
if (count($orgs) == 1) $orgs = null; // als er maar 1 organisatie is , kan de gebruiker niet switchen
|
|
}
|
|
echo json_encode($orgs);
|
|
}
|
|
function setgloborg(){
|
|
//TODO sanitize input
|
|
$newOrgid = $this->uri->segment(4);
|
|
$userrole = $this->Orgusers_model->getuserrole($this->userid, $newOrgid);
|
|
|
|
if ($this->super || $this->userrole ==2){
|
|
$this->Session_model->set_globorgid($newOrgid);
|
|
$module = $this->session->userdata('module');
|
|
$allowed = $this->Licenties_model->get_records_where(array("orgid"=> $newOrgid, "modulenr"=>$module));
|
|
if(!$allowed){
|
|
$this->Session_model->set_module(0);
|
|
};
|
|
}
|
|
// set nu ook de rol van de user in de geselecteerde organisatie;
|
|
else {
|
|
if ($userrole) {
|
|
$this->Session_model->set_orgid($newOrgid);
|
|
$this->Session_model->set_globorgid($newOrgid);
|
|
$this->Session_model->set_role($userrole->nivo);
|
|
}
|
|
}
|
|
echo json_encode(array("basepath"=>base_url()));
|
|
}
|
|
function insertorganisatie(){
|
|
if ($this->Autorisaties_model->check_autorisatie($this->userrole, SUPERUSER) > 0) {
|
|
$errortekst = '';
|
|
$neworg = null;
|
|
$nummer = $this->input->post("nummer");
|
|
if ($this->Organisaties_model->check_for_record(array("brin"=>$nummer))) {
|
|
$errortekst= "Nummer bestaat al.";
|
|
}
|
|
else {
|
|
$data=array( "soort" =>$this->input->post("soort"),
|
|
"brin" =>$this->input->post("nummer"),
|
|
"naamkort" =>$this->input->post("naamkort"),
|
|
"naam" =>$this->input->post("naam"),
|
|
"plaats" =>$this->input->post("plaats"),
|
|
"valtonder_id" =>$this->input->post("valtonder"),
|
|
"actief" =>1,
|
|
);
|
|
$newid = $this->Organisaties_model->insert_record($data);
|
|
$licenties = $this->input->post('licenties');
|
|
if ($licenties){
|
|
foreach($licenties as $licentie){
|
|
$this->Licenties_model->insert_record(array("orgid"=>$newid, "modulenr"=>$licentie));
|
|
}
|
|
}; //if
|
|
if ($this->input->post("soort") == 1){
|
|
$this->Organisaties_model->update_record(array("valtonder_id"=>$newid), $newid);
|
|
}
|
|
$neworg = $this->Organisaties_model->getorgdetails($newid);
|
|
};
|
|
}
|
|
else { $errortekst = "u bent niet geautoriseerd tot deze handeling" ;
|
|
$neworg = false;}; // als geen superuser
|
|
echo json_encode(array("errortekst" => $errortekst, "org" =>$neworg));
|
|
}
|
|
|
|
function deleteorg(){
|
|
//TODO clean input
|
|
if ($this->Autorisaties_model->check_autorisatie($this->userrole, SUPERUSER) > 0) {
|
|
$orgid = $this->uri->segment(4);
|
|
$errortekst = '';
|
|
|
|
if ($this->Orgusers_model->check_for_record(array("organisatie_id" =>$orgid)) ){
|
|
$errortekst = "Er zijn gebruikers gekoppeld aan deze organisatie.</br>";
|
|
}
|
|
if ($this->Organisaties_model->hasdependent($orgid) ) {
|
|
$errortekst .= " Er zijn afhankelijke organisaties. </br>" ;
|
|
}
|
|
//ambities, filled versions, orgversies,scores, licenties
|
|
if ($errortekst == ''){
|
|
$filledversions = $this->Filledversions_model->get_records_where(array("organisatie_id" =>$orgid));
|
|
if ($filledversions){
|
|
foreach($filledversions as $fv){
|
|
$this->Scores_model->delete_record_where(array("filledversion_id"=>$fv->id));
|
|
$this->Filledversions_model->delete_record($fv->id);
|
|
}
|
|
}
|
|
$this->Ambities_model->delete_record_where(array("organisatie_id"=>$orgid));
|
|
$this->Orgversies_model->delete_record_where(array("organisatie_id" =>$orgid));
|
|
$this->Licenties_model->delete_record_where(array("orgid" =>$orgid));
|
|
$this->Organisaties_model->delete_record($orgid);
|
|
}
|
|
}
|
|
else {$errortekst = "U bent niet geautoriseerd voor deze handeling.";};
|
|
echo json_encode($errortekst);
|
|
}
|
|
function update(){
|
|
//TODO clean input
|
|
if ($this->Autorisaties_model->check_autorisatie($this->userrole, SUPERUSER) > 0) {
|
|
$orgid =$this->input->post("id");
|
|
$errortekst = '';
|
|
$nummer = $this->input->post("nummer");
|
|
if ($this->Organisaties_model->check_for_record(array("brin"=>$nummer,
|
|
"id <> " =>$orgid))) {
|
|
$errortekst= "Nummer bestaat al.";
|
|
}
|
|
else {
|
|
$actief = 1;
|
|
if ($this->input->post("actief")=="false") $actief = 0;
|
|
// $monbas=1;
|
|
// if ($this->input->post("monbas")=="false") $monbas = 0;
|
|
// $mondiv = 1;
|
|
// if ($this->input->post("mondiv")=="false") $mondiv = 0;
|
|
|
|
$data=array( "brin" =>$this->input->post("nummer"),
|
|
"naamkort" =>$this->input->post("naamkort"),
|
|
"naam" =>$this->input->post("naam"),
|
|
"plaats" =>$this->input->post("plaats"),
|
|
"actief" =>$actief,
|
|
// "monbas" =>$monbas,
|
|
// "mondiv" =>$mondiv
|
|
);
|
|
$this->Organisaties_model->update_record($data,$orgid);
|
|
$this->Licenties_model->delete_record_where(array("orgid"=>$orgid));
|
|
$licenties = $this->input->post("licenties");
|
|
if ($licenties){
|
|
foreach ($licenties as $licentie){
|
|
$this->Licenties_model->insert_record(array("orgid"=>$orgid, "modulenr"=>$licentie));
|
|
}; // foreach
|
|
}; // if licenties
|
|
|
|
}
|
|
}
|
|
else {$errortekst = " U bent niet geautoriseerd voor deze handeling.";};
|
|
echo json_encode($errortekst);
|
|
}
|
|
function zoek(){
|
|
//TODO clean input
|
|
$errortekst="";
|
|
$zoekstr = $this->input->post("zoekstring");
|
|
$results = $this->Organisaties_model->zoekorgs($zoekstr);
|
|
if (!$results){$errortekst = "Geen resultaten gevonden";};
|
|
if (count($results) > 150) {
|
|
$errortekst ="Teveel overeenkomende gegevens gevonden. Maak uw zoekcriteria specifieker.";
|
|
$results = '';}
|
|
echo json_encode(array("results"=>$results, "errortekst" =>$errortekst));
|
|
}
|
|
function getselected(){
|
|
//TODO clean input
|
|
$orgid = $this->uri->segment(4);
|
|
$swvid = null;
|
|
$kamerid = null;
|
|
$bgid = null;
|
|
$schoolid = null;
|
|
$swvs = null;
|
|
$kamers = null;
|
|
$bgs = null;
|
|
$scholen = null;
|
|
|
|
$organisatie = $this->Organisaties_model->get_record_by_id($orgid);
|
|
|
|
if ($organisatie->soort == 1){
|
|
$swvid = $orgid;
|
|
}
|
|
|
|
if ($organisatie->soort == 2){
|
|
$swvid = $organisatie->valtonder_id;
|
|
$kamerid = $orgid;
|
|
}; // if soort =2
|
|
|
|
if ($organisatie->soort == 3){
|
|
$bgid = $organisatie->id;
|
|
$kamerid = $organisatie->valtonder_id;
|
|
$kamerorg = $this->Organisaties_model->get_record_by_id($kamerid);
|
|
$swvid = $kamerorg->valtonder_id;
|
|
}; // if soort = 3
|
|
|
|
if ($organisatie->soort == 4){
|
|
$schoolid = $orgid;
|
|
$bgid = $organisatie->valtonder_id;
|
|
$orgbg = $this->Organisaties_model->get_record_by_id($bgid);
|
|
$kamerid = $orgbg->valtonder_id;
|
|
$orgkamer = $this->Organisaties_model->get_record_by_id($kamerid);
|
|
$swvid = $orgkamer->valtonder_id;
|
|
}; // if soort = 4
|
|
|
|
$swvs=$this->Organisaties_model->getorgsdetails(1, false);
|
|
foreach ($swvs as $swv) {
|
|
if ($swv->id == $swvid){
|
|
$kamers = $this->Organisaties_model->getorgsdetails(2,$swvid);
|
|
if ($kamers){
|
|
if (!$kamerid) {$kamerid = $kamers[0]->id; };
|
|
foreach ($kamers as $kamer){
|
|
if ($kamer->id == $kamerid){
|
|
$bgs = $this->Organisaties_model->getorgsdetails(3, $kamerid);
|
|
if ($bgs){
|
|
if (!$bgid){$bgid = $bgs[0]->id;};
|
|
foreach ($bgs as $bg){
|
|
if ($bg->id == $bgid){
|
|
$scholen = $this->Organisaties_model->getorgsdetails(4,$bgid);
|
|
}
|
|
};// foreach bg
|
|
}; // if bgs
|
|
}; // if kamerid = kamerid
|
|
}; // foreach kamers
|
|
}; // if kamers
|
|
}; // if swvid
|
|
} ; // foreach swv
|
|
echo json_encode(array('swvid' =>$swvid,
|
|
'kamerid' =>$kamerid,
|
|
'bgid' =>$bgid,
|
|
'schoolid' =>$schoolid,
|
|
'swvs' =>$swvs,
|
|
'kamers' =>$kamers,
|
|
'bgs' =>$bgs,
|
|
'scholen' =>$scholen));
|
|
|
|
}
|
|
function getorgnivo(){
|
|
$nivo =$this->Organisaties_model->getsoortvanorginalorg($this->userid);
|
|
echo json_encode($nivo);
|
|
}
|
|
|
|
function getscholenvoormenu(){
|
|
$modulenr = $this->uri->segment(4);
|
|
$orgid = $this->globorgid;
|
|
$bgs=array();
|
|
$scholen=array();
|
|
$org = $this->Organisaties_model->get_record_by_id($orgid);
|
|
if ($org->soort == 1){
|
|
$kamers=$this->Organisaties_model->getorgsvanaf($orgid);
|
|
if ($kamers) {
|
|
foreach($kamers as $kamer){
|
|
$bg =$this->Organisaties_model->getorgsvanaf($kamer->id);
|
|
if ($bg){$bgs=array_merge($bgs,$bg); };
|
|
}
|
|
}
|
|
if ($bgs) {
|
|
foreach($bgs as $bg){
|
|
if($modulenr == 270) {
|
|
$schl = $this->Organisaties_model->getorgsvanafmetlicentie($bg->id, $modulenr);
|
|
}
|
|
else{
|
|
$schl = $this->Organisaties_model->getorgsvanaf($bg->id);
|
|
}
|
|
if ($schl){
|
|
$scholen=array_merge($scholen, $schl);
|
|
};
|
|
}
|
|
}
|
|
}; // if orgsoort ==1
|
|
if ($org->soort ==2){
|
|
$bgs = $this->Organisaties_model->getorgsvanaf($orgid);
|
|
if ($bgs){
|
|
foreach($bgs as $bg){
|
|
if($modulenr == 270) {
|
|
$schl = $this->Organisaties_model->getorgsvanafmetlicentie($bg->id, $modulenr);
|
|
}
|
|
else{
|
|
$schl = $this->Organisaties_model->getorgsvanaf($bg->id);
|
|
}
|
|
if ($schl){
|
|
$scholen=array_merge($scholen, $schl);
|
|
}; // if schl
|
|
}
|
|
}
|
|
}; // if orgsoort =2
|
|
if ($org->soort ==3 ){
|
|
if($modulenr == 270) {
|
|
$schl = $this->Organisaties_model->getorgsvanafmetlicentie($orgid, $modulenr);
|
|
}
|
|
else{
|
|
$schl = $this->Organisaties_model->getorgsvanaf($orgid);
|
|
}
|
|
}
|
|
if ($org->soort == 4){
|
|
$scholen[]= $org;
|
|
}
|
|
$school = true;
|
|
if ($org->soort != 4) $school=false;
|
|
|
|
|
|
echo json_encode(array('scholen'=>$scholen, 'school'=>$school));
|
|
|
|
|
|
}
|
|
|
|
function getscholen(){
|
|
$orgid = $this->globorgid;
|
|
$bgs=array();
|
|
$scholen=array();
|
|
$org = $this->Organisaties_model->get_record_by_id($orgid);
|
|
if ($org->soort == 1){
|
|
$kamers=$this->Organisaties_model->getorgsvanaf($orgid);
|
|
if ($kamers) {
|
|
foreach($kamers as $kamer){
|
|
$bg =$this->Organisaties_model->getorgsvanaf($kamer->id);
|
|
if ($bg){$bgs=array_merge($bgs,$bg); };
|
|
}
|
|
}
|
|
if ($bgs) {
|
|
foreach($bgs as $bg){
|
|
$schl = $this->Organisaties_model->getorgsvanaf($bg->id);
|
|
if ($schl){
|
|
$scholen=array_merge($scholen, $schl);
|
|
};
|
|
}
|
|
}
|
|
}; // if orgsoort ==1
|
|
if ($org->soort ==2){
|
|
$bgs = $this->Organisaties_model->getorgsvanaf($orgid);
|
|
if ($bgs){
|
|
foreach($bgs as $bg){
|
|
$schl = $this->Organisaties_model->getorgsvanaf($bg->id);
|
|
if ($schl){
|
|
$scholen=array_merge($scholen, $schl);
|
|
}; // if schl
|
|
}
|
|
}
|
|
}; // if orgsoort =2
|
|
if ($org->soort ==3 ){
|
|
$scholen = $this->Organisaties_model->getorgsvanaf($org->id);
|
|
}
|
|
if ($org->soort == 4){
|
|
$scholen[]= $org;
|
|
}
|
|
$school = true;
|
|
if ($org->soort != 4) $school=false;
|
|
echo json_encode(array('scholen'=>$scholen, 'school'=>$school));
|
|
}
|
|
|
|
function getsoscholen(){
|
|
$orgid = $this->globorgid;
|
|
$bgs=array();
|
|
$scholen=array();
|
|
$instrument = 270;
|
|
$org = $this->Organisaties_model->get_record_by_id($orgid);
|
|
if ($org->soort == 1){
|
|
$kamers=$this->Organisaties_model->getorgsvanaf($orgid);
|
|
if ($kamers) {
|
|
foreach($kamers as $kamer){
|
|
$bg =$this->Organisaties_model->getorgsvanaf($kamer->id);
|
|
if ($bg){$bgs=array_merge($bgs,$bg); };
|
|
}
|
|
}
|
|
if ($bgs) {
|
|
foreach($bgs as $bg){
|
|
$schl = $this->Organisaties_model->getorgsvanafmetlicentie($bg->id, $instrument);
|
|
if ($schl){
|
|
$scholen=array_merge($scholen, $schl);
|
|
};
|
|
}
|
|
}
|
|
}; // if orgsoort ==1
|
|
if ($org->soort ==2){
|
|
$bgs = $this->Organisaties_model->getorgsvanaf($orgid);
|
|
if ($bgs){
|
|
foreach($bgs as $bg){
|
|
$schl = $this->Organisaties_model->getorgsvanafmetlicentie($bg->id, $instrument);
|
|
if ($schl){
|
|
$scholen=array_merge($scholen, $schl);
|
|
}; // if schl
|
|
}
|
|
}
|
|
}; // if orgsoort =2
|
|
if ($org->soort ==3 ){
|
|
$scholen = $this->Organisaties_model->getorgsvanafmetlicentie($org->id, $instrument);
|
|
}
|
|
if ($org->soort == 4){
|
|
$scholen[]= $org;
|
|
}
|
|
$school = true;
|
|
if ($org->soort != 4) $school=false;
|
|
|
|
|
|
echo json_encode(array('soscholen'=>$scholen, 'school'=>$school));
|
|
}
|
|
|
|
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 getselectedschool(){
|
|
echo json_encode($this->selectedschool);
|
|
}
|
|
|
|
function getmodules(){
|
|
$orgid = $this->uri->segment(4); // als 0 dan nieuwe organisatie
|
|
$modules = $this->Modules_model->getallmodules();
|
|
if ($modules){
|
|
foreach($modules as $module){
|
|
$module->janee =$this->Licenties_model->getmodulelicentie($orgid, $module->sysnr);
|
|
}
|
|
}; // if modules
|
|
echo json_encode($modules);
|
|
}
|
|
|
|
function getRandomName(){
|
|
$this->load->helper('string');
|
|
return random_string("alnum", 20);
|
|
}
|
|
|
|
function deleteOldBijlage($orgID){
|
|
$oldBijlage = $this->Organisaties_model->get(['id'=>$orgID],'randomname', true);
|
|
if ($oldBijlage) unlink('./../docs/'.$oldBijlage);
|
|
}
|
|
|
|
function setNieuweBijlage($orgID, $randomname, $filename){
|
|
$this->Organisaties_model->update_record(['randomname'=>$randomname, 'bijlagefile'=>$filename], $orgID);
|
|
}
|
|
|
|
function saveBijlageFile(){
|
|
$randomname = $this->getRandomName();
|
|
|
|
$config['upload_path'] = './../docs/';
|
|
$config['allowed_types'] = '*';
|
|
$config['max_size'] = 10000;
|
|
$config['file_name'] = $randomname;
|
|
|
|
$this->load->library('upload', $config);
|
|
|
|
$orgID = $_POST['orgID'];
|
|
$filename = $_FILES['file']['name'];
|
|
$this->deleteOldBijlage($orgID);
|
|
|
|
if ( ! $this->upload->do_upload('file')) $error = $this->upload->display_errors();
|
|
else {
|
|
$error = FALSE;
|
|
$randomname = $this->upload->data('file_name');
|
|
$this->setNieuweBijlage($orgID, $randomname, $filename);
|
|
}
|
|
$this->json($error);
|
|
}
|
|
|
|
function deleteBijlage(){
|
|
// nog een controle op autorisatie?
|
|
if ( $this->Autorisaties_model->check_autorisatie($this->userrole, 1) <= 0 ) return;
|
|
$orgID = $this->clean_input('orgID');
|
|
$this->deleteOldBijlage($orgID);
|
|
$this->Organisaties_model->update_record(['bijlagefile'=>NULL, 'randomname'=>NULL],$orgID);
|
|
}
|
|
} // controller
|