diff --git a/application/controllers/monpas/Streefcijfers.php b/application/controllers/monpas/Streefcijfers.php index 5269cc1..c447154 100644 --- a/application/controllers/monpas/Streefcijfers.php +++ b/application/controllers/monpas/Streefcijfers.php @@ -15,6 +15,7 @@ class Streefcijfers extends MY_Controller{ };// if } + function gethierarchie($selfid){ if (!$this->userid) die; $organisatie= $this->Organisaties_model->get_record_by_id($selfid); @@ -127,8 +128,19 @@ class Streefcijfers extends MY_Controller{ return $ambitieorgs; } + function checkrecht(){ + if (!$this->userid) die; + $manage = 'F'; + if($this->super) $manage = 'T'; + else { + $result = $this->Autorisatiesnivos_model->checkmanage($this->userid, $this->orgid); + if($result) $manage = 'T'; + } + $this->json($manage); + } -function mh_getorgversies_ambities(){ + +function getambitie(){ if (!$this->userid) die; $orgid = $this->uri->segment(4); $module = $this->session->userdata('module'); @@ -148,31 +160,41 @@ function mh_getorgversies_ambities(){ } $toporgs = rtrim($toporgs, ',' ); - $orgversies = $this->Orgversies_model->getorgversies($toporgs, $module); - if(!$orgversies) echo json_encode("geen orgversies"); + $ambitie = $this->Ambities_model->mh_get_ambitie($module, $ambitieorgs, $toporgs); + if(!$ambitie) return json_encode("Er is geen actieve versie bij het instrument"); - $ambities = []; - foreach($orgversies as $orgversie) { - $ambitie = $this->Ambities_model->get_ambities_orgversie($orgversie->id, $ambitieorgs, $toporgs); - if ($ambitie) $ambtities [] = $ambitie; - else { - $aantalY = $this->Ijkpunten_model->telijkpunten($orgversie->id); - $ambities[] = ['id' => 0, - 'gemscore' => 80, - 'aantalY' => $aantalY, - 'xijkpunten' => round($aantalY * 0.8), - 'z_procent' => 60, - 'orgversieid' => $orgversie->id, - 'geldigvanaf' => $orgversie->geldigvanaf, - 'geldigtm' => $orgversie->geldigtm, - 'periodenummer' => $orgversie->periodenummer, - 'actief' => $orgversie->actief, - 'naam' => $orgversie->naam, - 'soort' => 0]; - } + echo json_encode($ambitie); - echo json_encode($ambities); +} + +function saveAmbitie(){ + if (!$this->userid) die; + + $orgversieid = $this->clean_input("orgversieid"); + $orgid = $this->clean_input("orgid"); + + + + if($this->super == false){ + if ($orgid != $this->orgid) return; + $result = $this->Autorisatiesnivos_model->checkmanage($this->userid, $this->orgid); + if(!$result) return; } + $bestaand = $this->Ambities_model->get_fieldvalue(['organisatie_id'=>$orgid, + 'orgversie_id' =>$orgversieid], 'id'); + if(!$bestaand) { + $id = $this->Ambities_model->insert_record([ + 'organisatie_id' => $orgid, + 'orgversie_id' => $orgversieid, + 'gem_score' => $this->clean_input("gemscore"), + 'x_ijkpunten' => $this->clean_input("xijkpunten"), + 'z_procent' => $this->clean_input("zprocent") + + ]); + } + $this->json($id); + + } diff --git a/application/models/monpas/Ambities_model.php b/application/models/monpas/Ambities_model.php index d6bc79d..901921f 100644 --- a/application/models/monpas/Ambities_model.php +++ b/application/models/monpas/Ambities_model.php @@ -103,31 +103,42 @@ class Ambities_model extends MY_Model{ return $ambitie; } -function get_ambities_orgversie($orgversieid, $ambitieorgs, $toporgs) -{ - $this->sql = " - SELECT A.id, - A.gem_score AS gemscore, - A.z_procent AS zprocent, - OV.id AS orgversie_id, - DATE_FORMAT( OV.geldigvanaf, '%d-%m-%Y') as geldigvanaf, - DATE_FORMAT( OV.geldigtm, '%d-%m-%Y') as geldigtm, - OV.periodenummer, OV.actief, V.naam, - O.soort +function mh_get_ambitie($moduleid, $ambitieorgs, $toporgs){ + $this->sql = " SELECT COALESCE(A.id, 0) AS ambitieID, + COALESCE(A.gem_score, 80) AS gemscore, + COUNT(Y.id) AS aantalY, + COALESCE(A.x_ijkpunten, ROUND(COUNT(Y.id) * 0.8)) AS xijkpunten, + COALESCE(A.z_procent, 60) AS zprocent, + OV.id AS orgversie_id, + DATE_FORMAT( OV.geldigvanaf, '%d-%m-%Y') as geldigvanaf, + DATE_FORMAT( OV.geldigtm, '%d-%m-%Y') as geldigtm, + OV.periodenummer, V.naam, + COALESCE(O.soort, 0) AS soort, + O.id AS orgID, + CASE WHEN O.soort IS NULL THEN + 'standaard' + WHEN O.soort = 1 THEN + 'swv' + WHEN O.soort = 2 THEN + 'regio' + WHEN O.soort = 3 THEN + 'bestuur' + WHEN O.soort = 4 THEN + 'school' + END AS ambitievan + FROM tb_orgversies OV - JOIN tb_versies V ON OV.versie_id = V.id - JOIN tb_ambities A ON A.orgversie_id = OV.id - JOIN tb_organisaties O ON A.organisatie_id = O.id - WHERE A.organisatie_id IN ({$ambitieorgs}) + JOIN tb_versies V ON OV.versie_id = V.id + JOIN tb_ijkpunten Y ON V.id = Y.versie_id + LEFT JOIN tb_ambities A ON A.orgversie_id = OV.id + LEFT JOIN tb_organisaties O ON A.organisatie_id = O.id + WHERE (A.organisatie_id IN ({$ambitieorgs}) OR A.id IS NULL) AND OV.organisatie_id IN ({$toporgs}) - AND OV.id = {$orgversieid} + AND V.modulenr = {$moduleid} + AND OV.actief = 1 + AND Y.disabled = 'F' ORDER BY soort DESC - LIMIT 1; - - - - "; - + LIMIT 1 "; return $this->get_query_result(); } diff --git a/application/models/monpas/Orgversies_model.php b/application/models/monpas/Orgversies_model.php index de11ba2..cb82f08 100644 --- a/application/models/monpas/Orgversies_model.php +++ b/application/models/monpas/Orgversies_model.php @@ -43,29 +43,6 @@ class Orgversies_model extends MY_Model{ return $this->get_query_result(); } - - function getorgversies($toporgs, $module){ - $this->sql="SELECT OV.id, - periodenummer, - OV.actief, - DATE_FORMAT(geldigvanaf,'%d-%m-%Y') as geldigvanaf, - DATE_FORMAT(geldigtm,'%d-%m-%Y') as geldigtm, - V.naam, - COUNT(Y.id) AS aantalY - - - FROM tb_orgversies OV - JOIN tb_versies V ON V.id = versie_id - JOIN tb_ijkpunten Y ON V.id = Y.versie_id - WHERE OV.organisatie_id IN ({$toporgs}) - AND V.modulenr = {$module} - AND Y.disabled = 'F' "; - - $this->sql .=" GROUP BY OV.id - ORDER BY periodenummer DESC"; - return $this->get_query_result(); - } - function getVersieinfo($orgversieid){ $this->sql="SELECT OV.id AS orgversieid, OV.organisatie_id, diff --git a/application/models/shared/Autorisatienivos_model.php b/application/models/shared/Autorisatienivos_model.php index b5203cd..3ee20ff 100644 --- a/application/models/shared/Autorisatienivos_model.php +++ b/application/models/shared/Autorisatienivos_model.php @@ -50,5 +50,17 @@ class Autorisatienivos_model extends MY_Model{ return $this->get_query_row('nivo'); } + function checkmanage($userid, $orgid){ + $this->sql=" SELECT nivo + FROM tb_autorisatienivos AN + JOIN tb_autorisaties A ON A.nivo_id = AN.id + JOIN tb_orgusers OU ON OU.id = A.orguser_id + WHERE OU.user_id = {$userid} + AND OU.organisatie_id = {$orgid} + AND AN.nivo IN (1, 4, 16, 64, 256) "; + return $this->get_query_row('nivo'); + } + + } \ No newline at end of file diff --git a/application/views/monpas/pages/compactsop.php b/application/views/monpas/pages/compactsop.php index 554e053..8cef403 100644 --- a/application/views/monpas/pages/compactsop.php +++ b/application/views/monpas/pages/compactsop.php @@ -1,7 +1,8 @@