135 lines
3.8 KiB
PHP
135 lines
3.8 KiB
PHP
<?php
|
|
|
|
class TimerecordingHolidayController extends mfBaseController
|
|
{
|
|
|
|
protected function init()
|
|
{
|
|
$this->needlogin = true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me", $me);
|
|
|
|
if (!$me->can(["Fibu"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction()
|
|
{
|
|
|
|
$this->layout()->setTemplate("TimerecordingHoliday/Index");
|
|
$timerecordingholidays = TimerecordingHolidayModel::getAll();
|
|
$this->layout()->set("timerecordingholidays", $timerecordingholidays);
|
|
|
|
}
|
|
|
|
protected function addAction()
|
|
{
|
|
|
|
$this->layout()->setTemplate("TimerecordingHoliday/Form");
|
|
|
|
}
|
|
|
|
protected function editAction()
|
|
{
|
|
$id = $this->request->id;
|
|
|
|
if (!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("Feiertag nicht gefunden", "error");
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
|
|
$timerecordingholidays = new TimerecordingHoliday($id);
|
|
if ($timerecordingholidays->id != $id) {
|
|
$this->layout()->setFlash("Feiertag nicht gefunden", "error");
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
|
|
$this->layout()->set("timerecordingholidays", $timerecordingholidays);
|
|
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";
|
|
$timerecordingholidays = new TimerecordingHoliday($id);
|
|
if (!$timerecordingholidays->id) {
|
|
$this->layout()->setFlash("Feiertage nicht gefunden", "error");
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
if ($r->timestamp) {
|
|
$timestamp = strtotime($r->timestamp . " 00:00:00");
|
|
if ($timestamp< 1577833200)
|
|
{
|
|
$timestamp="";
|
|
}
|
|
}
|
|
|
|
$data = [];
|
|
$data['timestamp'] = trim($timestamp);
|
|
$data['description'] = trim($r->description);
|
|
|
|
|
|
if (!$data['timestamp']) {
|
|
$this->layout()->setFlash("Datum darf nicht leer sein", "error");
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
if (!$data['description']) {
|
|
$this->layout()->setFlash("Name darf nicht leer sein", "error");
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
|
|
|
|
// var_dump($_FILES);
|
|
// var_dump($upload);
|
|
// exit;
|
|
|
|
|
|
if ($mode == "edit") {
|
|
$timerecordingholidays->update($data);
|
|
|
|
} else {
|
|
$timerecordingholidays = TimerecordingHolidayModel::create($data);
|
|
}
|
|
// var_dump($filestore);
|
|
// exit;
|
|
$id = $timerecordingholidays->save();
|
|
|
|
if (!$id) {
|
|
$this->layout()->setFlash("Feiertag konnte nicht angelegt werden", "error");
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
|
|
if ($mode == "edit") {
|
|
$this->layout()->setFlash("Feiertag erfolgreich geändert", "success");
|
|
} else if ($mode = "add") {
|
|
$this->layout()->setFlash("Feiertag erfolgreich angelegt", "success");
|
|
}
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
|
|
|
|
protected function deleteAction()
|
|
{
|
|
$id = $this->request->id;
|
|
$timerecordingholidays = new TimerecordingHoliday($id);
|
|
if (!$timerecordingholidays->id || $timerecordingholidays->id != $id) {
|
|
$this->layout()->setFlash("Feiertag nicht gefunden.", "error");
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
|
|
$timerecordingholidays->delete();
|
|
$this->redirect("TimerecordingHoliday");
|
|
}
|
|
|
|
}
|