<?php
/* GET: pageid → liefert fabric_json + note der Seite */
require_once __DIR__.'/_inc.php';

global $db;

$pageid = (int) ($_GET['pageid'] ?? 0);
if (!$pageid) bericht_ajax_fail('pageid fehlt');

$res = $db->query("SELECT fabric_json, note, rotation, COALESCE(layout,'single') AS layout,"
    ." COALESCE(image_scale,1.0) AS image_scale, COALESCE(image_align,'fit') AS image_align"
    ." FROM ".$db->prefix()."bericht_page WHERE rowid = ".((int) $pageid));
if (!$res) bericht_ajax_fail($db->lasterror());
$row = $db->fetch_object($res);
if (!$row) bericht_ajax_fail('Page nicht gefunden', 404);

bericht_ajax_ok(array(
    'fabric_json' => $row->fabric_json,
    'note'        => $row->note,
    'rotation'    => (int) $row->rotation,
    'layout'      => $row->layout,
    'image_scale' => (float) $row->image_scale,
    'image_align' => $row->image_align,
));
