105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?php
|
|
|
|
class VoiceplandestinationController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->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");
|
|
|
|
$voiceplans = VoiceplanModel::getAll();
|
|
$this->layout()->set("voiceplans", $voiceplans);
|
|
|
|
$voiceplan_id = $this->request->voiceplan_id;
|
|
if($voiceplan_id) {
|
|
$voiceplan = new Voiceplan($voiceplan_id);
|
|
$this->layout()->set("voiceplan", $voiceplan);
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
$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['voiceplan_id'] = $r->voiceplan_id;
|
|
$data['destination'] = $r->destination;
|
|
$data['prefix'] = intval($r->prefix);
|
|
$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");
|
|
$this->layout()->set("destination", VoiceplandestinationModel::create($data));
|
|
return $this->addAction();
|
|
}
|
|
|
|
$data["increment_first"] = $increments[0];
|
|
$data["increment"] = $increments[1];
|
|
}
|
|
|
|
if(!$data['destination'] || !$data['prefix'] || !$data['voiceplan_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("Voiceplan", "view", ["id" => $destination->voiceplan_id]);
|
|
}
|
|
} |