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("TimerecordingPermit/Index"); $timerecordingCategoriess = TimerecordingCategoryModel::getAll(); $this->layout()->set("timerecordingCategoriess", $timerecordingCategoriess); $timerecordings = TimerecordingModel::getAllPermits(); $this->layout()->set("timerecordings", $timerecordings); } protected function addAction() { } protected function editAction() { } protected function saveAction() { } protected function sendMail($timerecordings, $type) { if ($type == "deny") { $sendtext = "abgelehnt"; } else if ($type == "approve") { $sendtext = "genehmigt"; } $user = UserModel::getOne($timerecordings->user_id); $timerecordingCategoriess = TimerecordingCategoryModel::search(['id' => $timerecordings->timerecordingCategory_id]); $body = 'Beantrag von: ' . $user->name . ' '; $body .= 'Buchungsart: ' . $timerecordingCategoriess[0]->name . ' '; if ($timerecordingCategoriess[0]->hourday == "1") { $body .= 'von: ' . date("d.m.Y H:i", $timerecordings->start) . ' bis: ' . date("H:i", $timerecordings->end) . ' '; } else if ($timerecordingCategoriess[0]->hourday == "2") { $body .= 'von: ' . date("d.m.Y", $timerecordings->start) . ' bis: ' . date("d.m.Y", $timerecordings->end) . ' '; } $body .= ucfirst($sendtext) . ' von: ' . $this->me->name . ' '; $email = new Emailnotification(); $email->setSubject('Antrag für ' . $timerecordingCategoriess[0]->name . ' ' . $sendtext); $email->setBody($body); $email->setFrom(TT_TIMERECORDING_EMAIL, TT_TIMERECORDING_EMAIL_NAME); $email->setTo($user->email); $email->send(); $email = new Emailnotification(); $email->setSubject('Antrag für ' . $timerecordingCategoriess[0]->name . ' ' . $sendtext . ' (' . $user->name . ')'); $email->setBody($body); $email->setFrom(TT_TIMERECORDING_EMAIL, TT_TIMERECORDING_EMAIL_NAME); $email->setTo(TT_TIMERECORDING_EMAIL); $email->send(); } protected function approveAction() { $id = $this->request->id; $timerecordings = new Timerecording($id); if (!$timerecordings->id || $timerecordings->id != $id) { $this->layout()->setFlash("Buchung nicht gefunden.", "error"); $this->redirect("TimerecordingPermit"); } $data = []; $data['approved'] = 1; $timerecordings->update($data); $timerecordings->save(); $this->sendMail($timerecordings, "approve"); $this->redirect("TimerecordingPermit"); } protected function denyAction() { $id = $this->request->id; $timerecordings = new Timerecording($id); if (!$timerecordings->id || $timerecordings->id != $id) { $this->layout()->setFlash("Buchung nicht gefunden.", "error"); $this->redirect("TimerecordingPermit"); } $this->sendMail($timerecordings, "deny"); $timerecordings->delete(); if ($this->request->ajax == 1) { die(); } $this->redirect("TimerecordingPermit"); } }