130 lines
4.1 KiB
PHP
130 lines
4.1 KiB
PHP
<?php
|
|
|
|
class TimerecordingCarMileageHistoryController 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("TimerecordingCarMileageHistory/Index");
|
|
$timerecordingcarmileagehistorys = TimerecordingCarMileageHistoryModel::getAll();
|
|
$this->layout()->set("timerecordingcarmileagehistorys", $timerecordingcarmileagehistorys);
|
|
|
|
}
|
|
|
|
protected function addAction()
|
|
{
|
|
$TimerecordingCars=TimerecordingCarModel::getAll();
|
|
$this->layout()->set("TimerecordingCars", $TimerecordingCars);
|
|
|
|
$this->layout()->setTemplate("TimerecordingCarMileageHistory/Form");
|
|
|
|
}
|
|
|
|
protected function editAction()
|
|
{
|
|
$id = $this->request->id;
|
|
|
|
if (!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("Kilometer History nicht gefunden", "error");
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
|
|
$timerecordingcarmileagehistorys = new TimerecordingCarMileageHistory($id);
|
|
if ($timerecordingcarmileagehistorys->id != $id) {
|
|
$this->layout()->setFlash("Kilometer History nicht gefunden", "error");
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
|
|
$this->layout()->set("timerecordingcarmileagehistorys", $timerecordingcarmileagehistorys);
|
|
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";
|
|
$timerecordingcarmileagehistorys = new TimerecordingCarMileageHistory($id);
|
|
if (!$timerecordingcarmileagehistorys->id) {
|
|
$this->layout()->setFlash("Kilometer History nicht gefunden", "error");
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
$data = [];
|
|
$data['TimerecordingCar_id'] = trim($r->TimerecordingCar_id);
|
|
$data['mileage'] = trim($r->mileage);
|
|
|
|
|
|
if (!$data['TimerecordingCar_id']) {
|
|
$this->layout()->setFlash("Fahrzeug darf nicht leer sein", "error");
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
if (!$data['mileage']) {
|
|
$this->layout()->setFlash("Kilometer darf nicht leer sein", "error");
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
|
|
|
|
// var_dump($_FILES);
|
|
// var_dump($upload);
|
|
// exit;
|
|
|
|
|
|
if ($mode == "edit") {
|
|
$timerecordingcarmileagehistorys->update($data);
|
|
|
|
} else {
|
|
$timerecordingcarmileagehistorys = TimerecordingCarMileageHistoryModel::create($data);
|
|
}
|
|
// var_dump($filestore);
|
|
// exit;
|
|
$id = $timerecordingcarmileagehistorys->save();
|
|
|
|
if (!$id) {
|
|
$this->layout()->setFlash("Kilometer History konnte nicht angelegt werden", "error");
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
|
|
if ($mode == "edit") {
|
|
$this->layout()->setFlash("Kilometer History erfolgreich geändert", "success");
|
|
} else if ($mode = "add") {
|
|
$this->layout()->setFlash("Kilometer History erfolgreich angelegt", "success");
|
|
}
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
|
|
|
|
protected function deleteAction()
|
|
{
|
|
$id = $this->request->id;
|
|
$timerecordingcarmileagehistorys = new TimerecordingCarMileageHistory($id);
|
|
if (!$timerecordingcarmileagehistorys->id || $timerecordingcarmileagehistorys->id != $id) {
|
|
$this->layout()->setFlash("Kilometer History nicht gefunden.", "error");
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
|
|
$timerecordingcarmileagehistorys->delete();
|
|
$this->redirect("TimerecordingCarMileageHistory");
|
|
}
|
|
|
|
}
|