Files
thetool/application/TimerecordingCarDocuments/TimerecordingCarDocumentsController.php
Daniel Spitzer 7d176779c9 Zeiterfassung neues Feature:
Features für Project 7832:
* Das Pickerldatum Zusatzfeld
* Auftrennen PKW und Anhänger
* Dokumente Upload
* Standardsortierung
* Ausgeschieden Flag mit Datum
* zusätzliche migration
2025-03-10 08:04:56 +01:00

146 lines
4.2 KiB
PHP

<?php
class TimerecordingCarDocumentsController 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"])) {
$this->redirect("Dashboard");
}
}
protected function indexAction()
{
$this->layout()->setTemplate("TimerecordingCarDocuments/Index");
$timerecordingcardocumentss = TimerecordingCarDocumentsModel::getAll();
$this->layout()->set("timerecordingcardocumentss", $timerecordingcardocumentss);
}
protected function addAction()
{
$files=FileModel::getAll();
$this->layout()->set("files", $files);
$timerecordingCars=TimerecordingCarModel::getAll();
$this->layout()->set("timerecordingCars", $timerecordingCars);
$this->layout()->setTemplate("TimerecordingCarDocuments/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("bla nicht gefunden", "error");
$this->redirect("TimerecordingCarDocuments");
}
$timerecordingcardocumentss = new TimerecordingCarDocuments($id);
if ($timerecordingcardocumentss->id != $id) {
$this->layout()->setFlash("bla nicht gefunden", "error");
$this->redirect("TimerecordingCarDocuments");
}
$this->layout()->set("timerecordingcardocumentss", $timerecordingcardocumentss);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
//var_dump($r->get());exit;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$timerecordingcardocumentss = new TimerecordingCarDocuments($id);
if (!$timerecordingcardocumentss->id) {
$this->layout()->setFlash("gg nicht gefunden", "error");
$this->redirect("TimerecordingCarDocuments");
}
} else {
$mode = "add";
}
$data = [];
$data['file_id'] = trim($r->file_id);
$data['file_size'] = trim($r->file_size);
$data['timerecordingCar_id'] = trim($r->timerecordingCar_id);
$data['name'] = trim($r->name);
$data['description'] = trim($r->description);
$data['sort'] = trim($r->sort);
if (!$data['file_id']) {
$data['file_id']=NULL;
}
if (!$data['file_size']) {
$data['file_size']=NULL;
}
if (!$data['timerecordingCar_id']) {
$data['timerecordingCar_id']=NULL;
}
if (!$data['name']) {
$data['name']=NULL;
}
if (!$data['description']) {
$data['description']=NULL;
}
if (!$data['sort']) {
$data['sort']=NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$timerecordingcardocumentss->update($data);
} else {
$timerecordingcardocumentss = TimerecordingCarDocumentsModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $timerecordingcardocumentss->save();
if (!$id) {
$this->layout()->setFlash("bla konnte nicht angelegt werden", "error");
$this->redirect("TimerecordingCarDocuments");
}
if ($mode == "edit") {
$this->layout()->setFlash("bla erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("bla erfolgreich angelegt", "success");
}
$this->redirect("TimerecordingCarDocuments");
}
protected function deleteAction()
{
$id = $this->request->id;
$timerecordingcardocumentss = new TimerecordingCarDocuments($id);
if (!$timerecordingcardocumentss->id || $timerecordingcardocumentss->id != $id) {
$this->layout()->setFlash("bla nicht gefunden.", "error");
$this->redirect("TimerecordingCarDocuments");
}
$timerecordingcardocumentss->delete();
$this->redirect("TimerecordingCarDocuments");
}
}