Fixed Voicenumber and Updated Voiceplan

This commit is contained in:
Frank Schubert
2023-11-14 20:15:06 +01:00
parent 003ab67145
commit cc4a751407
20 changed files with 232 additions and 662 deletions

View File

@@ -125,16 +125,19 @@ class VoiceplanController extends mfBaseController {
$data['name'] = $r->name;
$data['description'] = $r->description;
/*if($r->increment) {
if($r->increment) {
$increments = explode("/",$r->increment);
if(count($increments) != 2) {
if(count($increments) != 2 || !is_numeric($increments[0]) || !is_numeric($increments[1])) {
$this->layout()->setFlash("Ungültige Taktung", "error");
return $this->editAction();
}
$data["increment_first"] = $increments[0];
$data["increment"] = $increments[1];
}*/
} else {
$this->layout()->setFlash("Ungültige Taktung", "error");
return $this->editAction();
}
if(!$data['name']) {
$this->layout()->setFlash("Bitte Name eingeben", "error");
@@ -153,8 +156,36 @@ class VoiceplanController extends mfBaseController {
return $this->editAction();
}
// import zones
if(is_array($_FILES) && array_key_exists("voiceplanzonefile", $_FILES) && !$_FILES['voiceplanzonefile']['error']) {
if($r->copy_from_plan_id) {
// get old voiceplan, clone zones and save destinations
$old_voiceplan = new Voiceplan($r->copy_from_plan_id);
if(!$old_voiceplan->id) {
$this->layout()->setFlash("Source Voiceplan nicht gefunden. Keine Zonen und Destinations kopiert!", "warning");
$this->redirect("Voiceplan", "view", ["id" => $id]);
}
foreach($old_voiceplan->zones as $old_zone) {
$new_zone = clone($old_zone);
$new_zone->voiceplan_id = $id;
$new_zone->increment_first = $voiceplan->increment_first;
$new_zone->increment = $voiceplan->increment;
if(!$new_zone->save()) {
$this->layout()->setFlash("Fehler beim Kopieren der Source Zone!", "error");
$this->redirect("Voiceplan", "view", ["id" => $id]);
}
foreach($new_zone->cloned_destinations as $cd) {
$cd->voiceplanzone_id = $new_zone->id;
if(!$cd->save()) {
$this->layout()->setFlash("Fehler beim Speichern der kopierten Destinations!", "error");
$this->redirect("Voiceplan", "view", ["id" => $id]);
}
}
}
} elseif(is_array($_FILES) && array_key_exists("voiceplanzonefile", $_FILES) && !$_FILES['voiceplanzonefile']['error']) {
// import zones
// look for uploaded import file
try {
// returns File object or throws Exception on error
@@ -199,7 +230,7 @@ class VoiceplanController extends mfBaseController {
$this->layout()->setFlash("Fehler beim Upload des Destinationfiles: ".$ex->getMessage(), "error");
return $this->editAction();
}
$vpf = VoiceplanFileModel::create([
'voiceplan_id' => $id,
'file_id' => $file->id,
@@ -215,11 +246,17 @@ class VoiceplanController extends mfBaseController {
$this->layout()->setFlash("Fehler beim Importieren!", "error");
return $this->editAction();
}
if($voiceplan->import_errors) {
$this->layout()->setFlash(implode("<br />\n", $voiceplan->import_errors), "warning");
}
}
}
$this->layout()->setFlash("Sprachtarifpaket erfolgreich gespeichert!", "success");
$this->redirect("Voiceplan", "view", ["id" => $id]);
$this->redirect("Voiceplan", "Index");
}
}