needlogin=true; $me = new User(); $me->loadMe(); $this->me = $me; $this->layout()->set("me",$me); if(!$me->isAdmin()) { $this->redirect("Dashboard"); } } protected function addAction() { $this->layout()->setTemplate("Voiceplandestination/Form"); $zones = VoiceplanzoneModel::getAll(); $this->layout()->set("zones", $zones); $zone_id = $this->request->voiceplanzone_id; if(strtolower($this->action) == "add" && $zone_id) { $zone = new Voiceplanzone($zone_id); $this->layout()->set("zone", $zones); $this->layout()->set("zone_id", $zone->id); } } protected function editAction() { $id = $this->request->id; if(!is_numeric($id) || $id < 1) { $this->layout()->setFlash("Destination nicht gefunden", "error"); $this->redirect("Voiceplan"); } $destination = new Voiceplandestination($id); if(!$destination->id) { $this->layout()->setFlash("Destination nicht gefunden", "error"); $this->redirect("Voiceplan"); } $this->layout()->set("destination", $destination); return $this->addAction(); } protected function saveAction() { $r = $this->request; //var_dump($r);exit; $id = $r->id; if(is_numeric($id) && $id > 0) { $mode = "edit"; $destination = new Voiceplandestination($id); if(!$destination->id) { $this->layout()->setFlash("Destination nicht gefunden", "error"); $this->redirect("Voiceplan"); } } else { $id = false; $mode = "add"; } $data = []; $data['voiceplanzone_id'] = $r->voiceplanzone_id; $data['destination'] = $r->destination; $data['prefix'] = intval($r->prefix); if(!$data['destination'] || !$data['prefix'] || !$data['voiceplanzone_id']) { $this->layout()->setFlash("Destination, Prefix und Tarifpaket sind erforderlich", "error"); $this->layout()->set("destination", VoiceplandestinationModel::create($data)); return $this->addAction(); } if($mode == "edit") { $destination->update($data); } else { $destination = VoiceplandestinationModel::create($data); } $id = $destination->save(); if(!$id) { $this->layout()->setFlash("Fehler beim Speichern!", "error"); $this->layout()->set("destination", $destination); return $this->addAction(); } $this->redirect("Voiceplanzone", "view", ["id" => $destination->voiceplanzone_id]); } }