diff --git a/admin/edit.php b/admin/edit.php index df49738..9d146a6 100644 --- a/admin/edit.php +++ b/admin/edit.php @@ -3,168 +3,222 @@ require_once '../includes/auth.php'; checkLogin(); $id = $_GET['id'] ?? ''; -$config = ['examName' => '', 'message' => '', 'examInfos' => []]; +$config = ['examName' => '', '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'], + 'examName' => $_POST['examName'] ?? '', + 'message' => $_POST['message'] ?? '', + 'room' => $_POST['room'] ?? '', 'examInfos' => [] ]; - foreach ($_POST['subject'] as $index => $subject) { - $newConfig['examInfos'][] = [ - 'name' => $subject, - 'start' => $_POST['start'][$index], - 'end' => $_POST['end'][$index] - ]; + // 验证并处理科目数据 + 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 + ]; + } + } } - file_put_contents("../configs/{$id}.json", json_encode($newConfig, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); - header('Location: index.php'); - exit; + // 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' => []]; + } } ?> 编辑配置 + + + +
+
+
+

基本信息

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+

考试科目安排

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+ +
+
+
+
+ - - -
-
-
- - -
-
- - -
-
- - -
-
- - -
- -

考试科目安排

-
- -
-
- - -
-
- - -
-
- - -
- -
- -
- -
- -
-
\ No newline at end of file diff --git a/admin/index.php b/admin/index.php index 0b3819f..945b8ca 100644 --- a/admin/index.php +++ b/admin/index.php @@ -24,109 +24,137 @@ uksort($configs, function($a, $b) { 配置管理后台 +

考试配置管理 当前用户:

- 退出登录 + 退出登录
-
- 新建配置 -
- - - - - - - - - - - - - - - - +
+
+ +
+
+ 新建配置 +
+ -
- - - - - +
+
+

+
+
+ 最后修改:
+ 文件大小: KB +
+
+ 编辑 + 查看 + +
+
- -
配置ID最后修改时间文件大小操作
暂无配置文件
KB - 编辑 - 删除 - 预览 -
+ + - \ No newline at end of file