'', 'message' => '', 'room' => '', 'examInfos' => []]; // Debug: 输出POST数据 error_log('POST data: ' . print_r($_POST, true)); // 保存逻辑 if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['id']); $newConfig = [ 'examName' => $_POST['examName'] ?? '', 'message' => $_POST['message'] ?? '', 'room' => $_POST['room'] ?? '', 'examInfos' => [] ]; // 验证并处理科目数据 if (isset($_POST['subject']) && is_array($_POST['subject'])) { foreach ($_POST['subject'] as $index => $subject) { if (!empty($subject) && isset($_POST['start'][$index]) && isset($_POST['end'][$index])) { // 格式化时间为标准格式 $startTime = date('Y-m-d\TH:i:s', strtotime($_POST['start'][$index])); $endTime = date('Y-m-d\TH:i:s', strtotime($_POST['end'][$index])); $newConfig['examInfos'][] = [ 'name' => $subject, 'start' => $startTime, 'end' => $endTime ]; } } } // Debug: 输出配置数据 error_log('Config to save: ' . print_r($newConfig, true)); // 保存配置 $jsonData = json_encode($newConfig, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); if ($jsonData === false) { error_log('JSON encode error: ' . json_last_error_msg()); } else { $saveResult = file_put_contents("../configs/{$id}.json", $jsonData); if ($saveResult === false) { error_log('File write failed for: ../configs/' . $id . '.json'); } else { header('Location: index.php'); exit; } } } // 加载现有配置 if (!empty($id) && file_exists("../configs/{$id}.json")) { $config = json_decode(file_get_contents("../configs/{$id}.json"), true); if ($config === null) { error_log('JSON decode error: ' . json_last_error_msg()); $config = ['examName' => '', 'message' => '', 'room' => '', 'examInfos' => []]; } } ?>