File: /var/www/html/wp-content/themes/elearning-education/page-student-tasks.php
<?php
/*
Template Name: Student Tasks
*/
get_header();
if (!is_user_logged_in()) { echo '<p>请登录</p>'; get_footer(); return; }
$user_id = get_current_user_id();
global $wpdb;
$student = $wpdb->get_row($wpdb->prepare("SELECT class_id, name FROM {$wpdb->prefix}edu_students WHERE user_id = %d", $user_id));
if (!$student) { echo '<p>无班级信息</p>'; get_footer(); return; }
?>
<style> /* 同前,添加任务列表表格 */ </style>
<div class="game-container">
<h1>我的任务 (<?php echo esc_html($student->name); ?>)</h1>
<table id="tasks-table">
<tr><th>任务名称</th><th>类型</th><th>开始时间</th><th>结束时间</th><th>操作</th></tr>
</table>
</div>
<script>
fetch('<?php echo admin_url("admin-ajax.php"); ?>', {
method: 'POST',
body: new URLSearchParams({ action: 'load_student_tasks', nonce: '<?php echo wp_create_nonce("student_tasks"); ?>' })
}).then(res => res.json()).then(data => {
if (data.success) {
const table = document.getElementById('tasks-table');
data.data.forEach(task => {
const row = table.insertRow();
row.innerHTML = `<td>${task.name}</td><td>${task.type}</td><td>${task.start_time}</td><td>${task.end_time || '无限制'}</td>
<td><a href="/nev-scroll-game?release_id=${task.release_id}">开始游戏</a></td>`; // 链接到游戏页,传release_id
});
}
});
</script>
<?php get_footer(); ?>