1 Star 0 Fork 0

Endericedragon/registration_php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
stuCourseAvailable.php 7.79 KB
一键复制 编辑 原始数据 按行查看 历史
<?php
if (isset($_COOKIE["cur_user"])) {
setcookie("cur_user", $_COOKIE["cur_user"], time() + 3600);
setcookie("cur_sid", $_COOKIE["cur_sid"], time() + 3600);
} else {
echo <<<EOF
<script>alert("You need to log in!")</script>
EOF;
echo <<<EOF
<script>url="index.php";window.location.href=url;</script>
EOF;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Course Available</title>
<link rel="stylesheet" href="bootstrap_min.css">
<style>
#no-result-warning {
font-family: Sansation, sans-serif;
color: gray;
}
.hide {
display: none;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<span>Registration</span>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Course Available</a>
</li>
<li class="nav-item">
<a class="nav-link" href="stuCourseSelected.php">Course Selected</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link disabled">Course Information</a>
</li>
</ul>
<form class="d-flex" method="get" action="stuCourseAvailable.php">
<input class="form-control me-2" type="search" placeholder="Search" name="keyword">
<button class="btn btn-outline-success me-2" type="submit">Search</button>
</form>
<form action="logOut.php" method="post" class="d-flex">
<button class="btn btn-outline-danger" type="submit">Log Out</button>
</form>
</div>
</div>
</nav>
<section>
<div class="container">
<table class="table">
<thead>
<tr>
<th>CID</th>
<th>Course Name</th>
<th>Course Time</th>
<th>Operation</th>
</tr>
</thead>
<tbody id="course-list">
</tbody>
</table>
<h3 class="text-center hide" id="no-result-warning">Nothing Found</h3>
</div>
</section>
<script src="bootstrap_js.js"></script>
<script>
function add_course(cid, cname, week_day, period) {
let target_table = document.getElementById("course-list");
let new_tr = document.createElement("tr");
new_tr.id = cid;
let temp_cid = document.createElement("td");
temp_cid.classList.add("align-middle");
let wrapper_cid = document.createElement("div");
wrapper_cid.innerHTML = cid;
temp_cid.appendChild(wrapper_cid);
new_tr.appendChild(temp_cid); // 烦了,删库跑路了(寻妹亲手写的注释)
let temp_cname = document.createElement("td");
temp_cname.classList.add("align-middle");
let wrapper_cname = document.createElement("div");
wrapper_cname.innerHTML = cname;
temp_cname.appendChild(wrapper_cname);
new_tr.appendChild(temp_cname);
let temp_ctime = document.createElement("td");
temp_ctime.classList.add("align-middle");
let wrapper_ctime = document.createElement("div");
wrapper_ctime.classList.add("align-middle");
wrapper_ctime.innerHTML = week_day + ", " + period;
temp_ctime.appendChild(wrapper_ctime);
new_tr.appendChild(temp_ctime);
let wrapper = document.createElement("td");
let form_view = document.createElement("form");
form_view.method = "get";
form_view.action = "courseInfo.php";
let view_button = document.createElement("button");
view_button.innerHTML = "&nbsp;&nbsp;view&nbsp;&nbsp;";
view_button.type = "submit";
view_button.classList.add("btn");
view_button.classList.add("btn-outline-dark");
view_button.name = "courseID";
view_button.value = cid;
form_view.appendChild(view_button);
wrapper.appendChild(form_view);
new_tr.appendChild(wrapper);
let form_choose = document.createElement("form");
form_choose.method = "get";
form_choose.action = "courseRegistration.php";
let choose_button = document.createElement("button");
choose_button.innerHTML = "choose";
choose_button.type = "submit";
choose_button.classList.add("btn");
choose_button.classList.add("btn-outline-success");
choose_button.classList.add("mt-1");
choose_button.name = "courseID";
choose_button.value = cid;
form_choose.appendChild(choose_button);
wrapper.appendChild(form_choose);
new_tr.appendChild(wrapper);
target_table.appendChild(new_tr);
}
</script>
</body>
</html>
<?php
if (isset($_COOKIE["cur_user"])) {
$week_name = array(
"1" => "Monday",
"2" => "Tuesday",
"3" => "Wednesday",
"4" => "Thursday",
"5" => "Friday",
"6" => "Saturday",
"7" => "Sunday",
);
$period_name = array(
"1" => "8:00 - 9:35",
"2" => "9:55 - 11:30",
"3" => "13:20 - 14:55",
"4" => "15:15 - 16:50",
"5" => "18:30 - 20:55",
);
$username = $_COOKIE["cur_user"];
$sid = $_COOKIE["cur_sid"];
$conn = new PDO("sqlite:storage.db");
if (isset($_GET["keyword"])) {
$keyword_filtered = htmlspecialchars(trim(stripslashes($_GET["keyword"])));
$sql_command = <<<EOF
select * from course where (
cname like '%$keyword_filtered%'
and
cid not in (
select cid from choose where sid=?
)
and
cid in (
select cid from courseAvailableDept where (
dept in (select dept from user where name=?)
)
)
and
ctime not in (
select ctime from course where cid in (
select cid from choose where sid=?
)
)
)
EOF;
} else {
$sql_command = <<<EOF
select * from course where (
cid not in (
select cid from choose where sid=?
)
and
cid in (
select cid from courseAvailableDept where (
dept in (select dept from user where name=?)
)
)
and
ctime not in (
select ctime from course where cid in (
select cid from choose where sid=?
)
)
)
EOF;
}
$sql_run = $conn->prepare($sql_command);
$sql_run->execute([$sid, $username, $sid]);
$no_result = true;
foreach ($sql_run as $row) {
$temp_cid = $row["cid"];
$temp_cname = $row["cname"];
$temp_date = $row["ctime"];
$td1 = $week_name[substr($temp_date, 0, 1)];
$td2 = $period_name[substr($temp_date, 2)];
echo <<<EOF
<script>
add_course("$temp_cid", "$temp_cname", "$td1", "$td2");
</script>
EOF;
$no_result = false;
}
if ($no_result) {
echo <<<EOF
<script>
document.getElementById("no-result-warning").classList.remove("hide");
</script>
EOF;
}
$conn = null;
}
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/endericedragon/registration_php.git
[email protected]:endericedragon/registration_php.git
endericedragon
registration_php
registration_php
master

搜索帮助