367 lines
12 KiB
PHP
367 lines
12 KiB
PHP
<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
|
|
|
|
class Berichten extends MY_Controller {
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$models = array(
|
|
"shared/Users_model",
|
|
"shared/Orgusers_model",
|
|
"shared/Autorisaties_model",
|
|
"monpas/Berichten_model",
|
|
"monpas/Modules_model",
|
|
"monpas/Modulebericht_model",
|
|
"monpas/Getoondeberichten_model",
|
|
"shared/Session_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 getberichten()
|
|
{
|
|
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 )
|
|
{
|
|
$berichten = $this->Berichten_model->getalleberichten();
|
|
}
|
|
else
|
|
{
|
|
$inlog = $this->Users_model->get_fieldvalue( array("id" => $this->userid), "inlogdatum" );
|
|
|
|
$berichten = $this->Berichten_model->getberichten( $this->userid);
|
|
}
|
|
|
|
$berichten = $this->displayMessages( $berichten );
|
|
|
|
echo json_encode( $berichten );
|
|
}
|
|
|
|
function getberichtenVoorpagina()
|
|
{
|
|
$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 )
|
|
{
|
|
$berichten = $this->Berichten_model->getalleberichten();
|
|
}
|
|
else
|
|
{
|
|
$frontpage = true;
|
|
$berichten = $this->Berichten_model->getberichten( $this->userid, $frontpage);
|
|
|
|
foreach($berichten ? $berichten :[] as $bericht){
|
|
$getoond = $this->Getoondeberichten_model->insert_record(array("bericht_id" => $bericht->id, "user_id" => $this->userid));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$berichten = $this->displayMessages( $berichten );
|
|
|
|
|
|
echo json_encode( $berichten );
|
|
}
|
|
|
|
function getAdminBerichten()
|
|
{
|
|
if ( ! $this->userid ) die;
|
|
$admin = $this->checkadmin();
|
|
if(!$admin = 1 || !$admin = 2){
|
|
return;
|
|
}
|
|
|
|
$berichten = $this->Berichten_model->getalleberichten();
|
|
if ( ! $berichten )
|
|
{
|
|
$berichten = FALSE;
|
|
}
|
|
else
|
|
{
|
|
$berichten = $this->displayMessages( $berichten );
|
|
|
|
}
|
|
echo json_encode( $berichten );
|
|
}
|
|
|
|
private function displayMessages( $berichten )
|
|
{
|
|
foreach ( $berichten ? $berichten : [] as $bericht )
|
|
{
|
|
$bericht->datum = mysql2date( $bericht->startdatum );
|
|
$bericht->inhoud = nl2br( base64_decode( $bericht->inhoud ) );
|
|
}
|
|
return $berichten;
|
|
}
|
|
|
|
function getmodules()
|
|
{
|
|
if ( ! $this->userid ) die;
|
|
$admin = $this->checkadmin();
|
|
if(!$admin = 1 || !$admin = 2){
|
|
return;
|
|
}
|
|
$berichtid = $this->uri->segment( 4 );
|
|
$clusters = $this->Modules_model->getclusters();//haal alle cluster op
|
|
|
|
if ( ! $clusters )
|
|
{
|
|
echo json_encode( FALSE );
|
|
|
|
return;
|
|
}
|
|
for ( $i = 0; $i < count( $clusters ); $i ++ )
|
|
{//haal bijbehorende modules op
|
|
$clusterid = $clusters[ $i ]->clusterid;
|
|
$clusters[ $i ]->modules = $this->Modules_model->getmodulesbijcluster( $clusterid );
|
|
}
|
|
|
|
$bclusters = $this->Berichten_model->getberichtclusters( $berichtid );// haal de clusters op waaraan het bericht is gelinkt
|
|
|
|
|
|
if ( $bclusters )
|
|
{
|
|
for ( $i = 0; $i < count( $bclusters ); $i ++ )
|
|
{//haal bijbehorende modules op waaraan het bericht is gelinkt
|
|
$bclusterid = $bclusters[ $i ]->clusterid;
|
|
$bclusters[ $i ]->bmodules = $this->Berichten_model->getberichtmodules( $bclusterid, $berichtid );
|
|
|
|
}
|
|
}
|
|
$clusterZ = new stdClass();//cluster object voor ongeclusterde modules
|
|
$clusterZ->clusterid = 0;
|
|
$clusterZ->naam = "Ongeclusterd";
|
|
$clusterZ->modules = $this->Modules_model->getmodulesbijcluster( 0 );
|
|
|
|
if ( isset( $clusterZ->modules ) )
|
|
{
|
|
foreach ( $clusterZ->modules as $moduleZ )
|
|
{
|
|
|
|
$gelinkt = $this->Berichten_model->getberichtenbijmodule( $berichtid, $moduleZ->modulenr );//haal berichten op die bij de ongeclusterde modules horen
|
|
if ( $gelinkt )
|
|
{
|
|
$moduleZ->vinkje = 'T';
|
|
}
|
|
else
|
|
{
|
|
$moduleZ->vinkje = 'F';
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( $bclusters )
|
|
{
|
|
|
|
$y = 0;
|
|
$n = $y;
|
|
for ( $y = 0; $y < count( $clusters ); $y ++ )
|
|
{ ////ga per cluster een bericht bij hoort, dan true
|
|
if ( isset( $bclusters[ $n ] ) )
|
|
if ( $clusters[ $y ]->clusterid == $bclusters[ $n ]->clusterid )
|
|
{
|
|
// $clusters[$y]->vinkje = 'T';
|
|
$s = 0;
|
|
$v = $s;
|
|
$aantal = count( $clusters[ $y ]->modules );//ga per module na of er een bericht bij hoort, dan true
|
|
$clusters[ $y ]->aantal = $aantal;
|
|
for ( $s = 0; $s < $aantal; $s ++ )
|
|
{
|
|
if ( isset( $bclusters[ $n ]->bmodules[ $v ] ) )
|
|
{
|
|
if ( $clusters[ $y ]->modules[ $s ]->modulenr == $bclusters[ $n ]->bmodules[ $v ]->modulenr )
|
|
{
|
|
$clusters[ $y ]->modules[ $s ]->vinkje = 'T';
|
|
$v ++;
|
|
}
|
|
else
|
|
{
|
|
$clusters[ $y ]->modules[ $s ]->vinkje = 'F';
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$clusters[ $y ]->modules[ $s ]->vinkje = 'F';
|
|
}
|
|
}
|
|
$n ++;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if ( $clusterZ->modules )
|
|
{//voeg de ongeclusterde modules met berichtinfo toe aan de clusterarray
|
|
array_unshift( $clusters, $clusterZ );
|
|
}
|
|
echo json_encode( $clusters );
|
|
}
|
|
|
|
public function saveBericht()
|
|
{
|
|
$admin = $this->checkadmin();
|
|
if(!$admin = 1 || !$admin = 2){
|
|
return;
|
|
}
|
|
$berichtID = $this->uri->segment( 4 );
|
|
$datum = str_replace( '/', '-', $this->input->post( 'datum' ));
|
|
$samenvatting = $this->input->post( 'samenvatting' );
|
|
$inhoud = $this->input->post( 'inhoud' );
|
|
$samenvatting = stripslashes( implode( "", explode( "\\", $samenvatting )));
|
|
if (! $samenvatting || ! strlen( $samenvatting )> 3){
|
|
$this->deletebericht($berichtID);
|
|
}
|
|
|
|
if (! $inhoud || ! strlen( $inhoud )> 9){
|
|
$this->deletebericht($berichtID);
|
|
}
|
|
$inhoud = base64_encode( $inhoud );
|
|
|
|
if (!$datum)
|
|
{ $datum = date( 'Y-m-d G:i:s' );
|
|
}
|
|
|
|
$berichtID = $this->Berichten_model->save_record( [
|
|
'startdatum' => date2mysql( $datum ),
|
|
'samenvatting' => $samenvatting,
|
|
'inhoud' => $inhoud
|
|
], $berichtID );
|
|
|
|
echo json_encode( $berichtID );
|
|
}
|
|
|
|
public function create_empty_bericht()
|
|
{
|
|
$admin = $this->checkadmin();
|
|
if(!$admin = 1 || !$admin = 2){
|
|
return;
|
|
}
|
|
$this->Berichten_model->insert_record( ['startdatum' => date( 'Y-m-d H:i:s' )] );
|
|
}
|
|
|
|
function koppelmodule()
|
|
{
|
|
$admin = $this->checkadmin();
|
|
if(!$admin = 1 || !$admin = 2){
|
|
return;
|
|
}
|
|
$vinkje = $this->clean_input( "modulevinkje" );
|
|
$berichtid = $this->clean_input( "berichtid" );
|
|
$modulenr = $this->clean_input( "moduleid" );
|
|
|
|
$mededeling = "er is iets mis gegaan";
|
|
if ( $vinkje && $berichtid && $modulenr )
|
|
{
|
|
if ( $vinkje == 'T' )
|
|
{
|
|
$this->Modulebericht_model->insert_record( array("modulenr" => $modulenr, "bericht_id" => $berichtid) );
|
|
$mededeling = "het bericht is gekoppeld";
|
|
}
|
|
if ( $vinkje == 'F' )
|
|
{
|
|
$this->Modulebericht_model->delete_record_where( array("modulenr" => $modulenr, "bericht_id" => $berichtid) );
|
|
$mededeling = "de koppeling is verwijderd";
|
|
}
|
|
}
|
|
echo json_encode( $mededeling );
|
|
}
|
|
|
|
function koppelcluster()
|
|
{
|
|
$admin = $this->checkadmin();
|
|
if(!$admin = 1 || !$admin = 2){
|
|
return;
|
|
}
|
|
$vinkje = $this->clean_input( "clustervinkje" );
|
|
$berichtid = $this->clean_input( "berichtid" );
|
|
$clusterid = $this->clean_input( "clusterid" );
|
|
$mededeling = "er is iets mis gegaan";
|
|
if ( $vinkje && $berichtid && $clusterid >= 0 )
|
|
{
|
|
$modules = $this->Modules_model->get_records_where( array("cluster_id" => $clusterid) );
|
|
if ( $vinkje == 'T' )
|
|
{
|
|
foreach ( $modules as $module )
|
|
{
|
|
|
|
$newid = $this->Modulebericht_model->insert_record( array("modulenr" => $module->sysnr, "bericht_id" => $berichtid) );
|
|
}
|
|
$mededeling = "het bericht is gekoppeld";
|
|
}
|
|
if ( $vinkje == 'F' )
|
|
{
|
|
foreach ( $modules as $module )
|
|
{
|
|
$this->Modulebericht_model->delete_record_where( array("modulenr" => $module->sysnr, "bericht_id" => $berichtid) );
|
|
}
|
|
$mededeling = "de koppelingen zijn verwijderd";
|
|
}
|
|
}
|
|
echo json_encode( $mededeling );
|
|
}
|
|
|
|
|
|
function berichtomwegtegooien($berichtid){
|
|
if ( ! $this->userid ) die;
|
|
$admin = $this->checkadmin();
|
|
if(!$admin = 1 || !$admin = 2){
|
|
return;
|
|
}
|
|
$berichtid = $this->uri->segment( 4 );
|
|
if ( $berichtid )
|
|
{
|
|
$this->deletebericht($berichtid);
|
|
echo json_encode( 'bericht verwijderd' );
|
|
}
|
|
else
|
|
{
|
|
echo json_encode( 'er is iets misgegaan' );
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function deletebericht($berichtid)
|
|
{if ( ! $this->userid ) die;
|
|
$this->Berichten_model->delete_record( $berichtid );
|
|
$this->Modulebericht_model->delete_record_where( array('bericht_id' => $berichtid) );
|
|
$this->Getoondeberichten_model->delete_record_where( array('bericht_id' => $berichtid) );
|
|
return(true);
|
|
|
|
}
|
|
} |