122 lines
3.4 KiB
PHP
122 lines
3.4 KiB
PHP
<?php
|
|
class DevicemanufactorController 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("Devicemanufactor/Index");
|
|
$devicemanufactors = DevicemanufactorModel::getAll();
|
|
$this->layout()->set("devicemanufactors", $devicemanufactors);
|
|
|
|
}
|
|
|
|
protected function addAction()
|
|
{
|
|
$this->layout()->setTemplate("Devicemanufactor/Form");
|
|
|
|
}
|
|
|
|
protected function editAction()
|
|
{
|
|
$id = $this->request->id;
|
|
|
|
if (!is_numeric($id) || !$id) {
|
|
$this->layout()->setFlash("Gerätehersteller nicht gefunden", "error");
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
|
|
$devicemanufactors = new Devicemanufactor($id);
|
|
if ($devicemanufactors->id != $id) {
|
|
$this->layout()->setFlash("Gerätehersteller nicht gefunden", "error");
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
|
|
$this->layout()->set("devicemanufactors", $devicemanufactors);
|
|
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";
|
|
$devicemanufactor = new Devicemanufactor($id);
|
|
if (!$devicemanufactor->id) {
|
|
$this->layout()->setFlash("Gerätehersteller nicht gefunden", "error");
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
} else {
|
|
$mode = "add";
|
|
}
|
|
|
|
$data = [];
|
|
$data['name'] = trim($r->name);
|
|
$data['config_backup'] = trim($r->config_backup);
|
|
|
|
|
|
if (!$data['name']) {
|
|
$this->layout()->setFlash("Name darf nicht leer sein", "error");
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
|
|
|
|
// var_dump($_FILES);
|
|
// var_dump($upload);
|
|
// exit;
|
|
|
|
|
|
if ($mode == "edit") {
|
|
$devicemanufactor->update($data);
|
|
|
|
} else {
|
|
$devicemanufactor = DevicemanufactorModel::create($data);
|
|
}
|
|
// var_dump($filestore);
|
|
// exit;
|
|
$id = $devicemanufactor->save();
|
|
|
|
if (!$id) {
|
|
$this->layout()->setFlash("Gerätehersteller konnte nicht angelegt werden", "error");
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
if ($fsh) {
|
|
$fsh->save();
|
|
}
|
|
if ($mode == "edit") {
|
|
$this->layout()->setFlash("Gerätehersteller erfolgreich geändert", "success");
|
|
} else if ($mode = "add") {
|
|
$this->layout()->setFlash("Gerätehersteller erfolgreich angelegt", "success");
|
|
}
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
|
|
protected function deleteAction()
|
|
{
|
|
$id = $this->request->id;
|
|
$devicemanufactor = new Devicemanufactor($id);
|
|
if (!$devicemanufactor->id || $devicemanufactor->id != $id) {
|
|
$this->layout()->setFlash("Gerätehersteller nicht gefunden.", "error");
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
|
|
$devicemanufactor->delete();
|
|
$this->redirect("Devicemanufactor");
|
|
}
|
|
|
|
} |