— Detail eines Berichts * POST /api/reports.php?id=&action=finalize — Finalisierung anstoßen * * Listing aller Berichte läuft über orders.php (pro Auftrag). */ require_once __DIR__.'/_inc.php'; api_authenticate(); global $db, $user; $id = (int) ($_GET['id'] ?? 0); $action = $_GET['action'] ?? ''; if (!$id) api_fail('id erforderlich'); $bericht = new Bericht($db); if ($bericht->fetch($id) <= 0) api_fail('Bericht nicht gefunden', 404); if ($action === 'finalize') { if (!$user->hasRight('bericht', 'write')) api_fail('Schreibrechte fehlen', 403); // Wir rufen generate_pdf.php intern auf, indem wir die Logik laden — einfacher: redirect // Hier simpler Ansatz: setze Status auf Final (echte PDF-Generierung sollte separat triggern) $bericht->status = Bericht::STATUS_FINAL; $bericht->update($user); api_ok(array('status' => 'final')); } // Detail $pages = BerichtPage::fetchAllForBericht($db, $bericht->id); $pages_out = array(); foreach ($pages as $p) { $pages_out[] = array( 'id' => (int) $p->id, 'page_order' => (int) $p->page_order, 'source_type'=> $p->source_type, 'source_path'=> $p->source_path, 'rotation' => (int) $p->rotation, 'note' => $p->note, 'layout' => $p->layout, ); } api_ok(array( 'report' => array( 'id' => (int) $bericht->id, 'ref' => $bericht->ref, 'titel' => $bericht->titel, 'auftragsnummer' => $bericht->auftragsnummer, 'element_type' => $bericht->element_type, 'fk_element' => (int) $bericht->fk_element, 'page_format' => $bericht->page_format, 'page_orientation'=> $bericht->page_orientation, 'status' => (int) $bericht->status, 'datec' => (int) $bericht->datec, ), 'pages' => $pages_out, ));