-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectcourse.php
143 lines (143 loc) · 5.69 KB
/
selectcourse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
require "sessionstart.php";
echo '<meta charset="utf-8" />';
if (isset($_POST['chk'])) {
$chk = $_POST['chk'];
array_shift($chk);
if ($chk == NULL) {
echo '<script>alert("你没有选择任何课程!");</script>';
echo '<meta http-equiv="refresh" content="0; url=index.php?page=selectcourse">';
}
else {
require "constants.php";
require "connectdatabase.php";
$stu = mysql_query("SELECT * FROM studentinformation WHERE id='" . $user . "'");
$stu = mysql_fetch_array($stu);
foreach ($chk as $e) {
$checklist = mysql_query("SELECT * FROM courseinformation WHERE id='" . $e . "'");
$checklist = mysql_fetch_array($checklist);
if ($checklist == NULL) {
echo '<script>alert("课程\'' . $checklist['name'] . '\'不存在,在此之前的课已选中。");</script>';
echo '<meta http-equiv="refresh" content="0; url=index.php?page=selectcourse">';
die("");
}
else if ($checklist['selectedNumber'] >= $checklist['capacity']) {
echo '<script>alert("课程\'' . $checklist['name'] . '\'人数已满,在此之前的课已选中。");</script>';
echo '<meta http-equiv="refresh" content="0; url=index.php?page=selectcourse">';
die("");
}
$course = mysql_query("SELECT * FROM coursechoose WHERE id='" . $user . "' AND courseID='" . $checklist['id'] . "'");
if (mysql_fetch_array($course) == NULL) {
$flag = mysql_query("INSERT INTO coursechoose VALUES ('" . $user . "', '" . $stu['name'] .
"', '" . $checklist['name'] . "', '" . $checklist['id'] . "', '" .
$checklist['teacherID'] . "', '0', NULL)");
if ($flag == true) {
$checklist = mysql_query("SELECT selectedNumber FROM courseinformation WHERE id='" . $e . "'");
$checklist = mysql_fetch_array($checklist);
$selected = $checklist['selectedNumber'] + 1;
mysql_query("UPDATE courseinformation SET selectedNumber='" . $selected . "' WHERE id='" . $e . "'");
}
}
}
echo '<script>alert("保存成功!");</script>';
echo '<meta http-equiv="refresh" content="0; url=index.php?page=selectcourse">';
}
die("");
}
?>
<link rel="stylesheet" type="text/css" href="css/common.css" />
<div id="main" style="line-height:28px;width:100%;">
<h3>可选课程列表</h3>
<form action="selectcourse.php" method="post">
<p><span class="smalltitle">必修课程</span></p>
<table style="border:1px solid #99F;">
<tr style="background-color:#CCC;">
<td style="width:24px;"><input style="display:none;" type="checkbox" name="chk[]" checked=1 /></td>
<td style="width:72px;">课程编号</td>
<td>课程名称</td>
<td>教师姓名</td>
<td style="width:72px;">已选人数</td>
<td style="width:72px;">限制人数</td>
<td>上课时间</td>
<td style="width:72px;">上课地点</td>
<td style="width:72px;">课程学分</td>
</tr>
<?php
require "connectdatabase.php";
$checklist = mysql_query("SELECT * FROM courseinformation WHERE comp='1' ORDER BY id");
$i = 0;
while ($row = mysql_fetch_array($checklist)) {
$choose = mysql_query("SELECT * FROM coursechoose WHERE courseID='" . $row['id'] . "' AND id='" . $user . "'");
if (mysql_fetch_array($choose) == NULL) {
$i++;
if ($i % 2 == 0) {
$highlight = " style=\"background-color:#DDD;\"";
}
else {
$highlight = " style=\"background-color:#EEE;\"";
}
echo "<tr" . $highlight . ">";
echo "<td>";
echo '<input class="hideborder" type="checkbox" name="chk[]" value="' . $row['id'] . '" checked=1 />';
echo '</td>';
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['teacher'] . "</td>";
echo "<td>" . $row['selectedNumber'] . "</td>";
echo "<td>" . $row['capacity'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['place'] . "</td>";
echo "<td>" . $row['credit'] . "</td>";
echo "</tr>";
}
}
?>
</table>
<p><span class="smalltitle">选修课程</span></p>
<table style="border:1px solid #99F;">
<tr style="background-color:#CCC;">
<td style="width:24px;"></td>
<td style="width:72px;">课程编号</td>
<td>课程名称</td>
<td>教师姓名</td>
<td style="width:72px;">已选人数</td>
<td style="width:72px;">限制人数</td>
<td>上课时间</td>
<td style="width:72px;">上课地点</td>
<td style="width:72px;">课程学分</td>
</tr>
<?php
require "connectdatabase.php";
$checklist = mysql_query("SELECT * FROM courseinformation WHERE comp='0' ORDER BY id");
$i = 0;
while ($row = mysql_fetch_array($checklist)) {
$choose = mysql_query("SELECT * FROM coursechoose WHERE courseID='" . $row['id'] . "' AND id='" . $user . "'");
if (mysql_fetch_array($choose) == NULL) {
$i++;
if ($i % 2 == 0) {
$highlight = " style=\"background-color:#DDD;\"";
}
else {
$highlight = " style=\"background-color:#EEE;\"";
}
echo "<tr" . $highlight . ">";
echo '<td><input class="hideborder" type="checkbox" name="chk[]" value="' . $row['id'] . '" /></td>';
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['teacher'] . "</td>";
echo "<td>" . $row['selectedNumber'] . "</td>";
echo "<td>" . $row['capacity'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['place'] . "</td>";
echo "<td>" . $row['credit'] . "</td>";
echo "</tr>";
}
}
?>
</table>
<p>
<input type="submit" value="保存" style="display:inline-block;width:60px;" />
<input type="reset" value="重置" style="display:inline-block;width:60px;" />
</p>
</form>
</div>