<?php
header('Content-Type: application/json');

if (!isset($_POST['cronEditorHidden'])) {
    echo json_encode([
        "ok" => false,
        "error" => "No cron text received."
    ]);
    exit;
}

$cronText = $_POST['cronEditorHidden'];

// Write to temp file
$tmpFile = "/tmp/cron_edit_" . uniqid() . ".txt";
file_put_contents($tmpFile, $cronText);

// Execute editor script
$output = shell_exec("/var/www/cgi-bin/systapp-admin/cron-edit/cron-edit.sh $tmpFile 2>&1");

// Remove temp file
unlink($tmpFile);

echo $output;
?>

