132 lines
3.7 KiB
PHP
132 lines
3.7 KiB
PHP
<?php
|
|
|
|
class TimerecordingCarJournalController 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("TimerecordingCarJournal/Index");
|
|
$timerecordingcarjournals = TimerecordingCarJournalModel::getAll();
|
|
$this->layout()->set("timerecordingcarjournals", $timerecordingcarjournals);
|
|
|
|
}
|
|
|
|
protected function addAction()
|
|
{
|
|
$TimerecordingCars=TimerecordingCarModel::getAll();
|
|
$this->layout()->set("TimerecordingCars", $TimerecordingCars);
|
|
|
|
$this->layout()->setTemplate("TimerecordingCarJournal/Form");
|
|
|
|
}
|
|
|
|
protected function editAction()
|
|
{
|
|
$id = $this->request->id;
|
|
|
|
if (!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("g nicht gefunden", "error");
|
|
$this->redirect("TimerecordingCarJournal");
|
|
}
|
|
|
|
$timerecordingcarjournals = new TimerecordingCarJournal($id);
|
|
if ($timerecordingcarjournals->id != $id) {
|
|
$this->layout()->setFlash("g nicht gefunden", "error");
|
|
$this->redirect("TimerecordingCarJournal");
|
|
}
|
|
|
|
$this->layout()->set("timerecordingcarjournals", $timerecordingcarjournals);
|
|
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";
|
|
$timerecordingcarjournals = new TimerecordingCarJournal($id);
|
|
if (!$timerecordingcarjournals->id) {
|
|
$this->layout()->setFlash("g nicht gefunden", "error");
|
|
$this->redirect("TimerecordingCarJournal");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
$data = [];
|
|
$data['TimerecordingCar_id'] = trim($r->TimerecordingCar_id);
|
|
$data['journal'] = trim($r->journal);
|
|
$data['timestamp'] = trim($r->timestamp);
|
|
|
|
|
|
if (!$data['TimerecordingCar_id']) {
|
|
$data['TimerecordingCar_id']=NULL;
|
|
}
|
|
if (!$data['journal']) {
|
|
$data['journal']=NULL;
|
|
}
|
|
if (!$data['timestamp']) {
|
|
$data['timestamp']=NULL;
|
|
}
|
|
|
|
|
|
// var_dump($_FILES);
|
|
// var_dump($upload);
|
|
// exit;
|
|
|
|
|
|
if ($mode == "edit") {
|
|
$timerecordingcarjournals->update($data);
|
|
|
|
} else {
|
|
$timerecordingcarjournals = TimerecordingCarJournalModel::create($data);
|
|
}
|
|
// var_dump($filestore);
|
|
// exit;
|
|
$id = $timerecordingcarjournals->save();
|
|
|
|
if (!$id) {
|
|
$this->layout()->setFlash("g konnte nicht angelegt werden", "error");
|
|
$this->redirect("TimerecordingCarJournal");
|
|
}
|
|
|
|
if ($mode == "edit") {
|
|
$this->layout()->setFlash("g erfolgreich geändert", "success");
|
|
} else if ($mode = "add") {
|
|
$this->layout()->setFlash("g erfolgreich angelegt", "success");
|
|
}
|
|
$this->redirect("TimerecordingCarJournal");
|
|
}
|
|
|
|
|
|
protected function deleteAction()
|
|
{
|
|
$id = $this->request->id;
|
|
$timerecordingcarjournals = new TimerecordingCarJournal($id);
|
|
if (!$timerecordingcarjournals->id || $timerecordingcarjournals->id != $id) {
|
|
$this->layout()->setFlash("g nicht gefunden.", "error");
|
|
$this->redirect("TimerecordingCarJournal");
|
|
}
|
|
|
|
$timerecordingcarjournals->delete();
|
|
$this->redirect("TimerecordingCarJournal");
|
|
}
|
|
|
|
}
|