hasRight('bericht', 'write')) bericht_ajax_fail('Permission denied', 403); $berichtid = (int) ($_POST['berichtid'] ?? 0); $label = trim((string) ($_POST['label'] ?? '')); if (!$berichtid) bericht_ajax_fail('berichtid fehlt'); if (empty($label)) bericht_ajax_fail('Label erforderlich'); $src = new Bericht($db); if ($src->fetch($berichtid) <= 0) bericht_ajax_fail('Bericht nicht gefunden', 404); // Vorlage als neuer Bericht $tpl = new Bericht($db); $tpl->element_type = $src->element_type; $tpl->fk_element = 0; $tpl->titel = $src->titel; $tpl->auftragsnummer = ''; $tpl->template_odt = $src->template_odt; $tpl->page_format = $src->page_format; $tpl->page_orientation = $src->page_orientation; $tpl->is_template = 1; $tpl->template_label = $label; if ($tpl->create($user) <= 0) bericht_ajax_fail('Erstellen fehlgeschlagen', 500); // Seiten kopieren (mit source_path-Referenz — die Vorlagen zeigen auf die Quell-Assets) $src_pages = BerichtPage::fetchAllForBericht($db, $src->id); foreach ($src_pages as $order => $p) { $np = new BerichtPage($db); $np->fk_bericht = $tpl->id; $np->page_order = $order + 1; $np->source_type = $p->source_type; $np->source_path = $p->source_path; $np->source_page = $p->source_page; $np->note = $p->note; $np->layout = $p->layout; $np->image_scale = $p->image_scale; $np->image_align = $p->image_align; $np->create(); } bericht_ajax_ok(array('template_id' => $tpl->id, 'label' => $label));