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("Voiceplanzone/Form"); if(strtolower($this->action) == "add" && $this->request->voiceplan_id) { $this->layout()->set("voiceplan_id", $this->request->voiceplan_id); $this->layout()->set("voiceplan", new Voiceplan($this->request->voiceplan_id)); } } protected function viewAction() { $this->layout()->setTemplate("Voiceplanzone/View"); $id = $this->request->id; if(!is_numeric($id) || $id < 1) { $this->layout()->setFlash("Tarifzone nicht gefunden.", "error"); $this->redirect("Voiceplan"); } $zone = new Voiceplanzone($id); if(!$zone->id) { $this->layout()->setFlash("Tarifzone nicht gefunden.", "error"); $this->redirect("Voiceplan"); } $this->layout()->set("zone", $zone); $pagination = []; $pagination['start'] = 0; $pagination['count'] = 20; $pagination['maxItems'] = 0; if(is_numeric($this->request->s)) { $pagination['start'] = intval($this->request->s); } $pagination['maxItems'] = VoiceplandestinationModel::count(['voiceplanzone_id' => $id]); $destinations = VoiceplandestinationModel::search(['voiceplanzone_id' => $id], $pagination); $this->layout()->set("destinations", $destinations); $this->layout()->set("pagination", $pagination); } protected function editAction() { $id = $this->request->id; if(!is_numeric($id) || $id < 1) { $this->layout()->setFlash("Tarifzone nicht gefunden.", "error"); $this->redirect("Voiceplan"); } $zone = new Voiceplanzone($id); if(!$zone->id) { $this->layout()->setFlash("Tarifzone nicht gefunden.", "error"); $this->redirect("Voiceplan"); } $this->layout()->set("zone", $zone); return $this->addAction(); } protected function saveAction() { $r = $this->request; //var_dump($r);exit; $id = $r->id; if(is_numeric($id) && $id > 0) { $mode = "edit"; $zone = new Voiceplanzone($id); if(!$zone->id) { $this->layout()->setFlash("Tarifzone nicht gefunden", "error"); $this->redirect("Voiceplan"); } } else { $id = false; $mode = "add"; } $data["voiceplan_id"] = $r->voiceplan_id; $data["name"] = $r->name; $data['purchase_price'] = (str_replace(",",".",$r->purchase_price)) ? str_replace(",",".",$r->purchase_price) : 0; $data['price'] = (str_replace(",",".",$r->price)) ? str_replace(",",".",$r->price) : 0; if($r->increment) { $increments = explode("/",$r->increment); if(count($increments) != 2) { $this->layout()->setFlash("Ungültige Taktung", "error"); if($mode == "edit") { $this->redirect("Voiceplanzone", "edit", ["id" => $id]); } else { $this->layout()->set("zone", VoiceplanzoneModel::create($data)); return $this->addAction(); } } $data["increment_first"] = $increments[0]; $data["increment"] = $increments[1]; } if(!$data['name'] || !$data['voiceplan_id']) { $this->layout()->setFlash("Name und Tarifpaket sind erforderlich", "error"); if($mode == "edit") { $this->redirect("Voiceplanzone", "edit", ["id" => $id]); } else { $this->layout()->set("destination", VoiceplanzoneModel::create($data)); return $this->addAction(); } } if($mode == "edit") { $zone->update($data); } else { $zone = VoiceplanzoneModel::create($data); } $id = $zone->save(); if(!$id) { $this->layout()->setFlash("Fehler beim Speichern!", "error"); $this->layout()->set("zone", $zone); return $this->addAction(); } $this->redirect("Voiceplan", "view", ["id" => $zone->voiceplan_id]); } }