<?php
declare(strict_types=1);
session_start();
if (empty($_SESSION['miter'])) {
header('Location: ../../index.php');
exit;
}
require_once __DIR__ . '/../admin/otc.php';
if (!isset($o_file_date) || empty($o_file_date)) {
error_log('rasp.php: Critical failure - otc.php did not provide $o_file_date.');
http_response_code(500);
exit('Critical System Error: Timestamp generation failed.');
}
$raw_rasp = $_POST['rasp'] ?? '';
$rasp_post = str_replace(["\r\n", "\r", "\n"], '<br>', trim($raw_rasp));
$mor_gdate = date('Y-m-d H:i:s');
$safe_file_id = basename((string)$o_file_date);
$rasp_file = __DIR__ . '/../../rasps/' . $safe_file_id . '.txt';
$rasp_data_array = [
$rasp_post,
trim($_POST['url'] ?? ''),
$o_date ?? $mor_gdate,
$mor_gdate
];
if (empty($rasp_post)) {
http_response_code(400);
exit('Error: Rasps Can Not Be Empty.');
}
if (file_put_contents($rasp_file, implode("\n", $rasp_data_array), LOCK_EX) === false) {
error_log('rasp.php: Atomic write failed for ' . $rasp_file);
http_response_code(500);
exit('Write Failure.');
}
header('Location: ../../index.php?rasp=', true, 303);
exit;
?>