<?php
$filename = isset( $_GET['filename'] ) ? $_GET['filename'] : '';
if( $_SERVER['REQUEST_METHOD'] === 'POST' &&
isset( $_POST['annotations'] ) &&
isset( $_POST['filename'] ) ) {
$script_dir = dirname( __FILE__ );
$target_dir = $script_dir . "/nn";
if( !is_dir( $target_dir ) ) {
mkdir( $target_dir, 0755, true );
}
$sanitized_filename = basename( $_POST['filename'] );
$sanitized_filename = preg_replace( '/\.pdf$/', '', $sanitized_filename );
$target_file = "$target_dir/{$sanitized_filename}.json";
$annotations_data = $_POST['annotations'];
file_put_contents( $target_file, $annotations_data );
header( 'Content-Type: application/json' );
echo json_encode( ['success' => true] );
exit;
}
$script_dir = dirname( __FILE__ );
$alpha_file = realpath( "$script_dir/alpha/$filename" );
$beta_file = realpath( "$script_dir/beta/$filename" );
$pdf_path = "/alpha/$filename";
if( !$alpha_file && $beta_file ) {
$pdf_path = "/beta/$filename";
}
$base_url = rtrim( dirname( $_SERVER['SCRIPT_NAME'] ), '/' ) . '/';
?>
<!DOCTYPE html>
<html dir="ltr" lang="en" mozdisallowselectionprint>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<base href="<?= $base_url ?>" />
<title>NotaNexus: <?= $filename ?></title>
<link rel='stylesheet' type='text/css' href='styles/main.css'>
</head>
<body tabindex="1">
<div id='pdf' data-filename='<?= $pdf_path ?>'></div>
<script type="module" src='js/pdf.min.mjs'></script>
<script type='module' src='js/viewer.js'></script>
</body>
</html>