<?php
$imageEngineDocumentRoot = rtrim((string)($_SERVER['DOCUMENT_ROOT'] ?? ''), '/\\');
$imageEngineConfig = $imageEngineDocumentRoot !== '' ? $imageEngineDocumentRoot . '/config.php' : '';
if ($imageEngineConfig === '' || !file_exists($imageEngineConfig)) {
    http_response_code(500);
    exit('Image Engine configuration could not be loaded.');
}
require_once $imageEngineConfig;

$imageId = preg_replace('/[^0-9_]/', '', (string)($_REQUEST['imageid'] ?? ''));
if (!preg_match('/^\d+_\d+$/', $imageId)) {
    http_response_code(400);
    exit('A valid report image slot is required.');
}
$description = trim((string)($_REQUEST['desc'] ?? ''));
$editorUrl = '/' . ltrim(ROOT_URL, '/') . '/includes/imageengine/editor.php?imageid=' . rawurlencode($imageId) . '&desc=' . rawurlencode($description);
?>
<style>
  .image-engine-modal-frame { display:block; width:100%; height:calc(100vh - 175px); min-height:560px; border:0; border-radius:4px; background:#edf1f5; }
  @media (max-width: 767.98px) { .image-engine-modal-frame { height:calc(100vh - 140px); min-height:500px; } }
</style>
<iframe class="image-engine-modal-frame" title="Image Engine" src="<?= htmlspecialchars($editorUrl, ENT_QUOTES, 'UTF-8') ?>"></iframe>
