216 lines
6.8 KiB
PHP
216 lines
6.8 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Filefolders extends MY_Controller {
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$models = array( "shared/Filefolders_model",
|
|
"shared/Files_model",
|
|
"monpas/Orgversies_model",
|
|
"monpas/Modules_model",
|
|
"monpas/Teksten_model",
|
|
"Phantom_model");
|
|
$this->load->model($models);
|
|
|
|
$this->load->helper('string');
|
|
if (!$this->check_online_status() || ! $this->userid) {
|
|
echo json_encode(array('offline' => TRUE));
|
|
die;
|
|
};// if
|
|
}
|
|
|
|
function getfolders(){
|
|
$modulenr = $this->uri->segment(4);
|
|
if (! $modulenr || $modulenr <=0) {
|
|
echo $this->json(false);
|
|
return;
|
|
}
|
|
|
|
$orgID = $this->globorgid;
|
|
$folders = $this->Filefolders_model->get_folders($modulenr, $orgID);
|
|
if ($folders){
|
|
foreach($folders as $folder){
|
|
$folder->subfolders = $this->Filefolders_model->get_subfolders($folder);
|
|
$folder->files= $this->Files_model->get_files($folder->id);
|
|
}
|
|
}// if folders
|
|
$this->json($folders);
|
|
}
|
|
|
|
public function maakStandaardFolders(){
|
|
//CHECK MANAGER RIGHT
|
|
if (! $this->isManager() ) return;
|
|
|
|
$modulenr = $this->clean_input('modulenr');
|
|
$orgID = $this->globorgid;
|
|
$folders = false;
|
|
|
|
$org = $this->Organisaties_model->get(['id'=>$orgID], false,true);
|
|
if ($org->id != $org->valtonder_id) $targetOrgID = $this->Organisaties_model->getkamer($org->id);
|
|
else $targetOrgID = $org->id;
|
|
|
|
$cats = $this->Orgversies_model->getversiecats($targetOrgID,$modulenr);
|
|
if (! $cats) {
|
|
$org = $this->Organisaties_model->get(['id'=> $targetOrgID],false, true);
|
|
$cats = $this->Orgversies_model->getversiecats($org->valtonder_id, $modulenr);
|
|
}
|
|
if ($cats){
|
|
foreach($cats as $cat){
|
|
$folder =
|
|
$this->Filefolders_model->get_folder_by_cat($orgID, $cat->nummer, $cat->omschrijving, $modulenr);
|
|
if (! $folder){
|
|
$data=[ 'modulenr' =>$modulenr,
|
|
'organisatie_id' => $orgID,
|
|
'naam' => $cat->omschrijving,
|
|
'instrumentcat' =>$cat->nummer];
|
|
$newID = $this->Filefolders_model->insert_record($data);
|
|
$this->Filefolders_model->update_record( array('valtonder'=>$newID) , $newID);
|
|
$folders[] = $this->Filefolders_model->get_folder($newID);
|
|
}
|
|
}
|
|
}
|
|
$this->json($folders);
|
|
}
|
|
|
|
public function maakTopFolder(){
|
|
//CHECK MANAGER RIGHT
|
|
if (! $this->isManager() ) return;
|
|
$nummer = $this->clean_input('nummer');
|
|
$naam = stripslashes($this->clean_input('naam'));
|
|
$modulenr = $this->clean_input('modulenr');
|
|
|
|
|
|
$data = ['modulenr' => $modulenr,
|
|
'organisatie_id' => $this->globorgid,
|
|
'nummer' => $nummer,
|
|
'naam' => $naam];
|
|
|
|
$newID = $this->Filefolders_model->insert_record($data);
|
|
$this->Filefolders_model->update_record( array('valtonder'=>$newID), $newID);
|
|
$folder = $this->Filefolders_model->get_folder($newID);
|
|
$this->json($folder);
|
|
}
|
|
|
|
public function maakSubFolder(){
|
|
//CHECK MANAGER RIGHT
|
|
if (! $this->isManager() ) return;
|
|
|
|
$nummer = $this->clean_input('nummer');
|
|
$naam = stripslashes($this->clean_input('naam'));
|
|
$modulenr = $this->clean_input('modulenr');
|
|
$folderID = $this->clean_input('folderID');
|
|
|
|
$data=[ 'modulenr' =>$modulenr,
|
|
'organisatie_id' => $this->globorgid,
|
|
'nummer' => $nummer,
|
|
'naam' => $naam,
|
|
'valtonder' => $folderID];
|
|
$newID = $this->Filefolders_model->insert_record($data);
|
|
$folder = $this->Filefolders_model->get_folder($newID);
|
|
$this->json($folder);
|
|
}
|
|
|
|
public function editFolder(){
|
|
//CHECK MANAGER RIGHT
|
|
if (! $this->isManager() ) return;
|
|
|
|
$id = $this->clean_input("folderID");
|
|
$naam = $this->input->post("naam");
|
|
$nummer = $this->input->post("nummer");
|
|
$this->Filefolders_model->update_record(['nummer'=> $nummer,'naam'=>$naam], $id);
|
|
$folder = $this->Filefolders_model->get_folder($id);
|
|
$this->json($folder->id);
|
|
|
|
}
|
|
|
|
public function getafwijkendetekst(){
|
|
$modulenr = $this->clean_input('modulenr');
|
|
$paginanaam = $this->clean_input('paginanaam');
|
|
$afwijkend = $this->Teksten_model->gettekst($modulenr, $paginanaam);
|
|
|
|
echo json_encode($afwijkend);
|
|
}
|
|
|
|
public function deleteFolder(){
|
|
//CHECK MANAGER RIGHT
|
|
if (! $this->isManager() ) return;
|
|
|
|
$folderID = $this->uri->segment(4);
|
|
//TODO check of er geen files of subfolders zijn
|
|
if ($this->Files_model->get(['folder_id'=>$folderID],false,false) ) return;
|
|
|
|
|
|
$this->Filefolders_model->delete_record($folderID);
|
|
}
|
|
|
|
public function deleteFile(){
|
|
//check op eigenar
|
|
$fileID = $this->uri->segment(4);
|
|
if (! $this->magDelete($fileID) ) return;
|
|
$bestand = $this->Files_model->get(['id'=>$fileID], false, true);
|
|
$this->load->helper('file');
|
|
unlink('../dossier/'.$bestand->new_name);
|
|
unlink('../pdfdossier/'.$bestand->new_name);
|
|
$this->Files_model->delete_record($fileID);
|
|
}
|
|
|
|
|
|
|
|
public function saveFileNaam(){
|
|
//CHECK MANAGER RIGHT
|
|
if (! $this->isManager() ) return;
|
|
|
|
$id = $this->clean_input("id");
|
|
$naam = $this->input->post("naam");
|
|
$this->Files_model->update_record(['original_name'=>$naam], $id);
|
|
}
|
|
|
|
public function getFiles(){
|
|
//TODO check toegang
|
|
$folderID = $this->clean_input("folderID");
|
|
$files = $this->Files_model->get_files($folderID);
|
|
$this->json($files);
|
|
}
|
|
public function zoekFile(){
|
|
$modulenr = $this->clean_input("modulenr");
|
|
$zoekterm = strip_slashes($this->clean_input("zoekfile"));
|
|
$files= $this->Files_model->zoek_files($zoekterm, $this->globorgid);
|
|
$this->json($files);
|
|
}
|
|
|
|
public function getAuth(){
|
|
$aut = $this->Autorisaties_model->check_autorisatie($this->userrole, 343);
|
|
$this->json($aut);
|
|
}
|
|
|
|
private function isManager(){
|
|
if ($this->Autorisaties_model->check_autorisatie($this->userrole, 343) == 0 ) return false;
|
|
else return true;
|
|
}
|
|
|
|
private function magDelete($fileid){
|
|
$owner = $this->Files_model->get(['id'=>$fileid],owner,true);
|
|
if ($owner == $this->userid) return true;
|
|
else return false;
|
|
}
|
|
public function maakpdf(){
|
|
//TODO check toegang
|
|
$module = $this->uri->segment(4);
|
|
$modulenaam = $this->Modules_model->get(['sysnr'=>$module], 'naam',true);
|
|
$organisatie = $this->Organisaties_model->getOrganisatie($this->globorgid);
|
|
$folders = $this->Filefolders_model->get_folders($module, $this->globorgid);
|
|
if ($folders){
|
|
foreach($folders as $folder){
|
|
$folder->subfolders = $this->Filefolders_model->get_subfolders($folder);
|
|
$folder->files = $this->Files_model->get_files($folder->id);
|
|
}
|
|
}
|
|
$lijst = ['folders' => $folders,
|
|
'organisatie' => $organisatie,
|
|
'today' => date('d-m-Y'),
|
|
'modulenaam' => $modulenaam,
|
|
'baseURL' =>base_url()];
|
|
$html = $this->load->view( 'monpas/reports/filefolders', $lijst, true);
|
|
$this->Phantom_model->create_pdf( $html, 'filefolders', FALSE, FALSE, [] );
|
|
}
|
|
} |