118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Schoolgegevens extends MY_Controller{
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
$models = array( "shared/Users_model",
|
|
'shared/Organisaties_model',
|
|
'monpas/Schooldetails_model',
|
|
'monpas/Groepen_model',
|
|
'monpas/Groepenxusers_model',
|
|
"shared/Orgusers_model",
|
|
"shared/Autorisaties_model");
|
|
$this->load->model($models);
|
|
$this->load->helper('string');
|
|
if ( ! $this->check_online_status() ) {
|
|
echo json_encode( array('offline' => TRUE) );
|
|
die;
|
|
};// if
|
|
}
|
|
|
|
function getschool(){
|
|
if (!$this->userid) die;
|
|
$schoolid = $this->uri->segment(4);
|
|
|
|
$org = $this->Organisaties_model->getorg($schoolid);
|
|
$bgbrin = $this->Organisaties_model->get_fieldvalue (array("id"=> $org->valtonder_id), 'brin');
|
|
$org->bgbrin=$bgbrin;
|
|
$details = $this->Schooldetails_model->get_details($schoolid);
|
|
|
|
echo json_encode(array('org'=>$org, 'details'=>$details));
|
|
}
|
|
function updatedetails(){
|
|
if (!$this->userid) die;
|
|
$orgid = $this->clean_input("orgid");
|
|
$this->Organisaties_model->update_record(array('naam'=>$this->input->post("naam")), $orgid);
|
|
$detailsid = $this->input->post("detailsid");
|
|
$data=array("straat" => $this->input->post("straat"),
|
|
"plaats" => $this->input->post("plaats"),
|
|
'telefoon' => $this->input->post("telefoon"),
|
|
'email1' => $this->input->post("email1"),
|
|
"web" => $this->input->post("web"),
|
|
"directie" => $this->input->post("directie"),
|
|
"ib" => $this->input->post("ib"),
|
|
"email2" => $this->input->post("email2") );
|
|
//update or insert
|
|
|
|
|
|
if ($detailsid <= 0){
|
|
$data["organisatie_id"]=$orgid;
|
|
$detailsid = $this->Schooldetails_model->insert_record($data);
|
|
}
|
|
else {
|
|
$this->Schooldetails_model->update_record($data, $detailsid);
|
|
}
|
|
echo json_encode($detailsid);
|
|
}
|
|
|
|
function updateinsertLK(){
|
|
if (!$this->userid) die;
|
|
$userid = $this->clean_input("id");
|
|
$orgid = $this->clean_input("orgid");
|
|
|
|
$data = array("aanhef" => $this->clean_input("aanhef"),
|
|
"voornaam" => $this->clean_input("voornaam"),
|
|
"tussenvoegsel" => $this->clean_input("tussenvoegsel"),
|
|
"achternaam" => $this->clean_input("achternaam"),
|
|
"email" => $this->clean_input("email") );
|
|
if ($userid <=0){
|
|
|
|
$userid=$this->Users_model->insert_record($data);
|
|
$data=array("user_id" => $userid,
|
|
"organisatie_id" => $orgid);
|
|
$orguserid = $this->Orgusers_model->insert_record($data);
|
|
$data=array("nivo_id" =>10,
|
|
"orguser_id" => $orguserid);
|
|
$this->Autorisaties_model->insert_record($data);
|
|
}
|
|
else{
|
|
$this->Users_model->update_record($data, $userid);
|
|
}
|
|
$lk= $this->Users_model->getleerkracht($userid);
|
|
echo json_encode($lk);
|
|
}
|
|
function getleerkrachten(){
|
|
if (!$this->userid) die;
|
|
$schoolid = $this->uri->segment(4);
|
|
$lk = $this->Users_model->getleerkrachten($schoolid);
|
|
echo json_encode($lk);
|
|
}
|
|
function deleteleerkracht(){
|
|
if (!$this->userid) die;
|
|
$userid = $this->input->post("userid");
|
|
$schoolid = $this->input->post("schoolid");
|
|
|
|
$errorstring = "";
|
|
|
|
if (!$this->writer) return;
|
|
|
|
// lk is gekoppeld aan groep?
|
|
$orguser = $this->Orgusers_model->get(['user_id'=>$userid, 'organisatie_id'=>$schoolid], false, true);
|
|
// if ($this->Groepenxusers_model->get(array("orguser_id"=> $orguser->id),false, false) ){
|
|
// $errorstring = " Leerkracht is gekoppeld aan een groep en mag niet verwijderd worden.";
|
|
// }
|
|
|
|
// als nivo < 10 alleen verwijderen via accounts
|
|
$autorisatienivo = $this->Autorisaties_model->get(['orguser_id' =>$orguser->id], 'nivo_id', true);
|
|
if ($autorisatienivo != 10) $errorstring += " Deze gebruiker mag alleen verwijderd worden via accounts.";
|
|
|
|
if ($errorstring <= ''){
|
|
$this->Autorisaties_model->update_record_where(['nivo_id'=>100], ['orguser_id' =>$orguser->id]);
|
|
// $this->Orgusers_model->delete_record_where(array("user_id" => $userid));
|
|
// $this->Users_model->delete_record($userid);
|
|
}
|
|
$this->json($errorstring);
|
|
}
|
|
|
|
}
|