bericht/ajax/save_as_template.php
Eduard Wisch 344f884a0f
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
feat: Bericht-Vorlagen + Whisper-Transkription + Cron-Fix
Bericht-Vorlagen (Phase 5.5):
- DB: is_template, template_label in llx_bericht
- Bericht::fetchAllTemplates() und createFromTemplate()
- fetchAllForElement() blendet Vorlagen aus
- ajax/save_as_template.php erzeugt Vorlage aus aktuellem Bericht
- Desktop-Editor: '📋 Als Vorlage' Button im Action-Bereich
- Bericht-Übersicht: Vorlagen-Dropdown beim + Neu Button
- api/templates.php: GET list + POST create_from_template

Schnell-Bericht (Phase 4.a/4.i):
- api/reports.php?action=create POST-Endpoint: Titel, Format,
  Orientation, ODT-Template, optional template_id
- api/odt_templates.php: Liste der Deckblatt-Vorlagen

Whisper-Transkription (Phase 5.7):
- api/transcribe.php: POST mit relpath, nutzt externen Whisper-
  HTTP-Endpoint (whisper.cpp server ODER OpenAI-kompatibel)
- Konfiguration im Admin: BERICHT_WHISPER_URL/MODE/API_KEY/LANG
- Sprache default 'de'

Cron-Fix:
- BerichtUploadToken::cleanupExpired() ist jetzt Instanz-Methode
  (Dolibarr ruft new Klasse($db) bei jobtype=method auf)
- Returnwert für Cron-Success/Failure
- Statische Variante als cleanupExpiredStatic() für direkte Aufrufe
- Damit läuft der tägliche Cron 'Expired Upload-Tokens bereinigen'
  nicht mehr hängend

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
[deploy]
2026-04-09 08:27:45 +02:00

50 lines
1.7 KiB
PHP

<?php
/* Speichert den aktuellen Bericht als Vorlage.
* Macht eine Kopie mit is_template=1, Label aus POST,
* Seiten werden mit kopiert (Referenzen auf source_path bleiben).
*
* POST: berichtid, label, token
*/
require_once __DIR__.'/_inc.php';
global $db, $user;
if (!$user->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));