From 17de4302c6c1bd3bac700d56fb39f627f6421e25 Mon Sep 17 00:00:00 2001 From: MKStoler1024 <158786854+MKStoler1024@users.noreply.github.com> Date: Sat, 1 Feb 2025 03:50:56 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=20.gitignore=20?= =?UTF-8?q?=E5=92=8C=20README=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ ws_server.php | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 ws_server.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a46dd5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/configs/* \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..76ac931 --- /dev/null +++ b/README.md @@ -0,0 +1,100 @@ +# ExamCloud + +ExamCloud 是一个用于管理和查看考试安排的系统。它包括以下几个主要功能: + +1. **考试看板配置查询**:用户可以通过输入配置 ID 来获取考试安排的详细信息。 +2. **考试安排显示**:显示考试的详细安排,包括科目、开始时间和结束时间。 +3. **管理员后台**:管理员可以登录后台管理考试配置文件,包括创建、编辑和删除配置文件。 + +## 文件结构 + +- `/index.php`:考试看板配置查询页面。 +- `/ExamCloudSchedule`:考试安排显示页面。 +- `/admin/login.php`:管理员登录页面。 +- `/admin/index.php`:管理员后台主页,显示所有配置文件。 +- `/admin/edit.php`:编辑或创建新的考试配置文件。 +- `/admin/detete.php`: 删除指定配置文件。 +- `/includes`: 管理员认证目录。 +- `/configs`: 安排存放目录。 + +## 使用方法 + +### 考试看板配置查询 + +1. 打开根目录页面。 +2. 输入配置 ID,例如 `room301`。 +3. 点击“获取配置”按钮,查看考试安排的详细信息。 +4. 点击“进入”按钮,跳转到考试安排显示页面。 + +### 考试安排显示 + +1. 上一部操作后会打开 `ExamCloudSchedule/index.html` 页面。 +2. 页面会根据 URL 参数 `configId` 显示相应的考试安排。 + +### 管理员后台 + +1. 打开 `admin` 目录,输入管理员用户名和密码进行登录。 +2. 登录后,跳转到 `admin/index.php` 页面,显示所有配置文件。 +3. 点击“新建配置”按钮,跳转到 `admin/edit.php` 页面,创建新的配置文件。 +4. 在配置文件列表中,可以点击“编辑”按钮编辑配置文件,点击“删除”按钮删除配置文件,点击“预览”按钮查看配置文件的详细信息。 + +## 配置文件格式 + +配置文件为 JSON 格式,包含以下字段: + +- `examName`:考试名称。 +- `message`:考试提示语。 +- `room`:考场号。 +- `examInfos`:考试科目安排列表,每个科目包含以下字段: + - `name`:科目名称。 + - `start`:开始时间。 + - `end`:结束时间。 + +示例配置文件: + +```json +{ + "examName": "期末考试", + "message": "请提前10分钟进入考场", + "room": "room301", + "examInfos": [ + { + "name": "数学", + "start": "2023-12-01T09:00:00", + "end": "2023-12-01T11:00:00" + }, + { + "name": "英语", + "start": "2023-12-01T13:00:00", + "end": "2023-12-01T15:00:00" + } + ] +} +``` + +## 开发环境 + +- PHP 7.4+ +- HTML5 +- JavaScript +- CSS3 + +## 安装和运行 + +1. 克隆项目到本地: + + ```bash + git clone https://github.com/yourusername/ExamCloud.git + ``` + +2. 将项目文件放置到 Web 服务器的根目录下。 +3. 确保 Web 服务器支持 PHP,并启动服务器。 +4. 访问 `index.php` 页面,开始使用系统。 + +## 贡献 + +欢迎提交问题和功能请求,您可以通过提交 Pull Request 来贡献代码。 + +## 许可证 + +本项目采用 MIT 许可证。 diff --git a/ws_server.php b/ws_server.php new file mode 100644 index 0000000..2baf968 --- /dev/null +++ b/ws_server.php @@ -0,0 +1,69 @@ +clients = new \SplObjectStorage; + $this->subscriptions = []; + } + + public function onOpen(ConnectionInterface $conn) { + $this->clients->attach($conn); + } + + public function onMessage(ConnectionInterface $from, $msg) { + $data = json_decode($msg, true); + if ($data['action'] === 'subscribe') { + $configId = $data['configId']; + $this->subscriptions[$configId][] = $from; + } + } + + public function onClose(ConnectionInterface $conn) { + $this->clients->detach($conn); + foreach ($this->subscriptions as $configId => $subscribers) { + $this->subscriptions[$configId] = array_filter($subscribers, function($subscriber) use ($conn) { + return $subscriber !== $conn; + }); + } + } + + public function onError(ConnectionInterface $conn, \Exception $e) { + $conn->close(); + } + + public function notifyClients($configId) { + if (isset($this->subscriptions[$configId])) { + foreach ($this->subscriptions[$configId] as $client) { + $client->send(json_encode(['action' => 'reload', 'configId' => $configId])); + } + } + } +} + +$server = IoServer::factory( + new HttpServer( + new WsServer( + new ConfigChangeNotifier() + ) + ), + 8080 +); + +$server->run(); +?>