197 lines
6.0 KiB
PHP
197 lines
6.0 KiB
PHP
<?php
|
|
|
|
class FilestoreController extends mfBaseController
|
|
{
|
|
protected function init()
|
|
{
|
|
$this->needlogin = true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me", $me);
|
|
|
|
if (!$me->is(["Admin", "netowner", "pipeplanner", "lineplanner", "pipeworker", "netoperator", "lineworker"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction()
|
|
{
|
|
$this->layout()->setTemplate("Filestore/Index");
|
|
$files = FilestoreModel::getAll();
|
|
|
|
|
|
|
|
// pagination defaults
|
|
$pagination = [];
|
|
$pagination['start'] = 0;
|
|
$pagination['count'] = 25;
|
|
$pagination['maxItems'] = 0;
|
|
if(is_numeric($this->request->s)) {
|
|
$pagination['start'] = intval($this->request->s);
|
|
}
|
|
$pagination['maxItems'] = FilestoreModel::count();
|
|
$this->layout()->set("files", $files);
|
|
$this->layout()->set("pagination", $pagination);
|
|
|
|
|
|
}
|
|
|
|
protected function addAction()
|
|
{
|
|
$this->layout()->setTemplate("Filestore/Form");
|
|
}
|
|
|
|
protected function saveAction()
|
|
{
|
|
$r = $this->request;
|
|
$id = $r->id;
|
|
//var_dump($r->get());exit;
|
|
if (is_numeric($id) && $id > 0) {
|
|
$mode = "edit";
|
|
$filestore = new Filestore($id);
|
|
if (!$filestore->id) {
|
|
$this->layout()->setFlash("Datei nicht gefunden", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
|
|
$dataHistory = [];
|
|
$dataHistory['name'] = $filestore->name;
|
|
$dataHistory['description'] = $filestore->description;
|
|
$dataHistory['file_id'] = $filestore->file_id;
|
|
$dataHistory['filestore_id'] = $filestore->id;
|
|
$dataHistory['create'] = $filestore->create;
|
|
$dataHistory['create_by'] = $filestore->create_by;
|
|
$dataHistory['edit'] = date("U");
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
$data = [];
|
|
$data['name'] = trim($r->name);
|
|
$data['description'] = trim($r->description);
|
|
|
|
if (!$data['name']) {
|
|
$this->layout()->setFlash("Name darf nicht leer sein", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
|
|
if (array_key_exists("filestore", $_FILES) && !$_FILES['filestore']['error']) {
|
|
$upload_error = false;
|
|
|
|
//var_dump($_FILES);exit;
|
|
$upload = new mfUpload("filestore");
|
|
$upload->setSavepath(MFUPLOAD_FILE_SAVE_PATH . "/netzbetrieb");
|
|
|
|
if (!$upload->getSize()) {
|
|
$this->layout()->setFlash("Dateiupload fehlgeschlagen: Dokument darf nicht leer sein!", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
if (substr(strtolower($upload->getFilename()), -3, 3) == "pdf" && !$upload->validatePDF()) {
|
|
$this->layout()->setFlash("Dateiupload fehlgeschlagen: PDF-Validierung fehlgeschlagen!", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
try {
|
|
$upload->save();
|
|
} catch (Exception $e) {
|
|
$this->layout()->setFlash("Dateiupload fehlgeschlagen1", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
$file_data = [];
|
|
$file_data['name'] = $upload->getOriginalFilename();
|
|
$file_data['filename'] = ($r->file_filename) ? $r->file_filename : $upload->getOriginalFilename();
|
|
$file_data['subfolder'] = "netzbetrieb";
|
|
$file_data['store_filename'] = $upload->getFilename();
|
|
$file_data['orig_filename'] = $upload->getOriginalFilename();
|
|
|
|
|
|
$file = FileModel::create($file_data);
|
|
$file_id = $file->save();
|
|
if (!$file_id) {
|
|
$this->layout()->setFlash("Dateiupload fehlgeschlagen3", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
$data['file_id'] = $file_id;
|
|
|
|
if ($mode == "edit") {
|
|
|
|
$fsh = FilestoreHistoryModel::create($dataHistory);
|
|
}
|
|
} else {
|
|
if ($mode == "add") {
|
|
$this->layout()->setFlash("Keine Datei angegeben", "error");
|
|
$this->redirect("Filestore", "add");
|
|
}
|
|
|
|
}
|
|
|
|
// var_dump($_FILES);
|
|
// var_dump($upload);
|
|
// exit;
|
|
|
|
|
|
if ($mode == "edit") {
|
|
$filestore->update($data);
|
|
|
|
} else {
|
|
$filestore = FilestoreModel::create($data);
|
|
}
|
|
// var_dump($filestore);
|
|
// exit;
|
|
$id = $filestore->save();
|
|
|
|
if (!$id) {
|
|
$this->layout()->setFlash("Dateiupload fehlgeschlagen33", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
if ($fsh) {
|
|
$fsh->save();
|
|
}
|
|
$this->layout()->setFlash("Dateiupload erfolgreich hochgeladen", "success");
|
|
$this->redirect("Filestore");
|
|
}
|
|
|
|
protected function editAction()
|
|
{
|
|
$r = $this->request;
|
|
$id = $r->id;
|
|
//var_dump($r->get());exit;
|
|
if (!is_numeric($id) && $id < 1) {
|
|
|
|
$this->layout()->setFlash("Datei nicht gefunden", "error");
|
|
$this->redirect("Filestore");
|
|
|
|
}
|
|
$filestore = new Filestore($id);
|
|
|
|
if (!$filestore->id) {
|
|
$this->layout()->setFlash("Datei nicht gefunden", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
$this->layout()->set("file", $filestore);
|
|
|
|
return $this->addAction();
|
|
}
|
|
|
|
protected function deleteAction()
|
|
{
|
|
$id = $this->request->id;
|
|
|
|
|
|
$filstore = new Filestore($id);
|
|
|
|
if (!$filstore->id || $filstore->id != $id) {
|
|
$this->layout()->setFlash("Datei nicht gefunden.", "error");
|
|
$this->redirect("Filestore");
|
|
}
|
|
foreach ($filstore->histories as $h) {
|
|
$h->file->delete();
|
|
$h->delete();
|
|
|
|
}
|
|
$filstore->file->delete();
|
|
// check if Product is unused
|
|
$filstore->delete();
|
|
$this->redirect("Filestore");
|
|
}
|
|
} |