needlogin = true; $me = new User(); $me->loadMe(); $this->me = $me; $this->layout()->set("me", $me); if (!$me->is(["employee"])) { $this->redirect("Dashboard"); } } protected function indexAction() { $this->layout()->setTemplate("Timerecording/Index"); $timerecordingCategoriess = TimerecordingCategoryModel::getAll(); $this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess); $timerecordings = TimerecordingModel::search(['user_id' => $this->me->id]); $this->layout()->set("timerecordings", $timerecordings); } protected function addAction() { $timerecordingCategoriess = TimerecordingCategoryModel::getAll(); $this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess); $this->layout()->setTemplate("Timerecording/Form"); } protected function editAction() { $id = $this->request->id; if (!is_numeric($id) || !$id) { $this->layout()->setFlash("Buchung nicht gefunden", "error"); $this->redirect("Timerecording"); } $timerecordings = new Timerecording($id); if ($timerecordings->id != $id) { $this->layout()->setFlash("Buchung nicht gefunden", "error"); $this->redirect("Timerecording"); } $this->layout()->set("timerecordings", $timerecordings); return $this->addAction(); } protected function saveAction() { $r = $this->request; $id = $r->id; $enddate = $r->enddate; if (!$enddate && $r->start && $r->end) { $starttime = strtotime($r->date . " " . $r->start . ":00"); $endtime = strtotime($r->date . " " . $r->end . ":00"); } elseif ($enddate) { $starttime = strtotime($r->date . " 00:00:00"); $endtime = strtotime($enddate . " 23:59:00"); } else if (!$enddate && !$r->start && !$r->end) { $starttime = strtotime($r->date . " 00:00:00"); $endtime = NULL; } if (is_numeric($id) && $id > 0) { $mode = "edit"; $timerecordings = new Timerecording($id); if (!$timerecordings->id) { $this->layout()->setFlash("Buchungen nicht gefunden", "error"); $this->redirect("Timerecording"); } } else { $mode = "add"; } $data = []; $data['user_id'] = $this->me->id; $data['start'] = $starttime; $data['end'] = $endtime; $data['timerecordingCategory_id'] = trim($r->timerecordingCategory_id); $data['commend'] = trim($r->commend); if (!$data['user_id']) { $this->layout()->setFlash("Benutzer darf nicht leer sein", "error"); $this->redirect("Timerecording"); } if ($data['start'] < 1577833200) { $this->layout()->setFlash("Ungültige Startzeit", "error"); $this->redirect("Timerecording"); } if ($data['end'] && $data['end'] < 1577833200) { $this->layout()->setFlash("Ungültige Endzeit", "error"); $this->redirect("Timerecording"); } if (!$data['timerecordingCategory_id']) { $data['timerecordingCategory_id'] = NULL; } if (!$data['commend']) { $data['commend'] = NULL; } if ($mode == "edit") { $timerecordings->update($data); } else { $timerecordings = TimerecordingModel::create($data); } // var_dump($filestore); // exit; $id = $timerecordings->save(); if (!$id) { $this->layout()->setFlash("Buchung konnte nicht angelegt werden", "error"); $this->redirect("Timerecording"); } if ($mode == "edit") { $this->layout()->setFlash("Buchung erfolgreich geändert", "success"); } else if ($mode = "add") { $this->layout()->setFlash("Buchung erfolgreich angelegt", "success"); } $this->redirect("Timerecording"); } protected function deleteAction() { $id = $this->request->id; $timerecordings = new Timerecording($id); if (!$timerecordings->id || $timerecordings->id != $id) { $this->layout()->setFlash("Buchung nicht gefunden.", "error"); $this->redirect("Timerecording"); } $timerecordings->delete(); $this->redirect("Timerecording"); } }