-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssemblyChapel3.php
263 lines (241 loc) · 8.23 KB
/
AssemblyChapel3.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
$user_name = "root";
$pass_word = "";
$database = "schoolschedule";
$server = "127.0.0.1";
$db_handle = mysql_connect($server,$user_name,$pass_word);
$db_found = mysql_select_db($database,$db_handle);
$PrioritySubject=$_POST['PrioritySubject'];
$PeriodDay=$_POST['PeriodDay'];
$PeriodTime=$_POST['PeriodTime'];
$AssemblyPeriodTime = $_POST['AssemblyPeriodTime'];
$AssemblyDay = $_POST['AssemblyDay'];
//echo $_POST['PeriodTime']." ".$_POST['PeriodDay'];
//echo $PrioritySubject;
//echo $AssemblyPeriodTime;
//echo $AssemblyDay;
$SQLclass = "SELECT * FROM assignment WHERE PeriodTime='$PeriodTime' AND PeriodDay='$PeriodDay' OR SubjectID='CPL'";
$ParallelSubjectResult = mysql_query($SQLclass);
$num_rows = mysql_num_rows($ParallelSubjectResult);
//$SQL = "SELECT * FROM assignment WHERE PeriodTime = '$PeriodTime' AND PeriodDay='$PeriodDay'"; /*Check if the subject 'Chapel' has been inserted into the database*/
// $result = mysql_query($SQL);
// $num_rows = mysql_num_rows($result);
$ErrorMessage= "";
$OverlapError = "";
//while($db_field=mysql_fetch_assoc($ParallelSubjectResult)) {
// $ParallelTime = $db_field['PeriodTime'];
// $ParallelDay = $db_field['PeriodDay'];
//}
if($num_rows>0){
$ErrorMessage='There is already a subject on that PeriodTime and PeriodDay';
}
else {
$SQLWriteCpl = "INSERT INTO assignment (SubjectID,TeacherID,ClassID,IsFirstParallelSubject,IsSubjectForAllClasses, Periods)
VALUES ('$PrioritySubject','ALL','ALL','0','1','1')"; /* Insert the subject 'Cpl' into the table 'Assignment */
$result = mysql_query($SQLWriteCpl);
$SQLWriteCplIntoPeriodAssignment = "INSERT INTO periodassignment (SubjectID,TeacherID,ClassID,PeriodTime,PeriodDay)
VALUES ('$PrioritySubject','ALL','ALL','$PeriodTime','$PeriodDay')"; /* Insert the subject 'Cpl' into the table 'PeriodAssignment */
$result = mysql_query($SQLWriteAssIntoPeriodAssignment);
}
//echo $Teachers;
//echo $ParallelTime;
//echo $ParallelDay;
// if($ParallelTime != $PeriodTime){ /* Write PeriodDay and PeriodTime only if the cell in the Time Table is not occupied in the specified Period Time and Day */
// if($ParallelDay != $PeriodDay) {
// $SQLWriteCPL = "INSERT INTO assignment (SubjectID,PeriodTime,PeriodDay)
// VALUES ('$PrioritySubject','$PeriodTime','$PeriodDay')";
// $result = mysql_query($SQLWriteCPL);
// }
// }
// if($PeriodDay == $ParallelDay){ /* Write PeriodDay and PeriodTime only if the cell in the Time Table is not occupied in the specified Period Time and Day */
// if($PeriodTime != $ParallelTime){
// $SQLWriteCPL = "INSERT INTO assignment (SubjectID,PeriodTime,PeriodDay)
// VALUES ('$PrioritySubject','$PeriodTime','$PeriodDay')";
// $result = mysql_query($SQLWriteCPL);
// }
// else {
// $OverlapError="There is already a subject at Day ".$PeriodDay." during Period ".$PeriodTime;
// }
// }
// }
// if($num_rows>0) {
// $ErrorMessage = "Chapel already taken";
// }
// else {
//
// if($PeriodDay == $AssemblyDay){ /*Check if the PeriodTime overlaps if the day is the same so that the subject 'Chapel' can be written on the same day*/
// if($PeriodTime!=$AssemblyPeriodTime){ /* If PeriodTime is not the same, but PeriodDay is the same, then allow the subject 'CPL' to be written into the database */
// $SQLWriteCPL = "INSERT INTO assignment (SubjectID,PeriodTime,PeriodDay)
// VALUES ('$PrioritySubject','$PeriodTime','$PeriodDay')";
// $result = mysql_query($SQLWriteCPL);
// }
// else{
// $OverlapError = 'The Period is overlapping at Day '.$AssemblyDay.' during '.' Period '.$AssemblyPeriodTime;
// }
// }
//
// if($PeriodTime==$AssemblyPeriodTime){ /*Check if the PeriodTime overlaps if the day is the same so that the subject 'Chapel' can be written on the same day*/
// if($PeriodDay != $AssemblyDay){ /* If PeriodDay is not the same, but PeriodTime is the same, then allow the subject 'CPL'to be written into the database */
// $SQLWriteCPL = "INSERT INTO assignment (SubjectID,PeriodTime,PeriodDay,IsSubjectForAllClasses)
// VALUES ('$PrioritySubject','$PeriodTime','$PeriodDay','1')";
// $result = mysql_query($SQLWriteCPL);
// }
// else{
//
// $OverlapError = 'The Period is overlapping at Day '.$AssemblyDay.' during '.' Period '.$AssemblyPeriodTime;
//
// }
// }
// if($PeriodDay!=$AssemblyDay){ /*If the PeriodTime and PeriodDay are not the same, the PeriodTime can be written into the database as both PeriodTime and PeriodDay do not overlap*/
// if($PeriodTime!=$AssemblyPeriodTime){
// $SQLWriteCPL = "INSERT INTO assignment (SubjectID,PeriodTime,PeriodDay,IsSubjectForAllClasses)
// VALUES ('$PrioritySubject','$PeriodTime','$PeriodDay','1')";
// $result = mysql_query($SQLWriteCPL);
// }
// }
//
// }
?>
<center>
<h2>Choose a Period Time and Day for Chapel</h2>
<font color = "red">
<?php// echo $OverlapError; ?>
</font>
<table>
<form action="AssemblyChapel3.php" method="post">
<tr>
<td>
Subject:
</td>
<td>
Chapel
</td>
<td>
<font color="red"><?php echo $ErrorMessage; ?></font>
</td>
</tr>
<tr>
<td>
Period Time:
</td>
<td>
<select name='PeriodTime'>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</td>
</tr>
<tr>
<td>
Day:
</td>
<td>
<select name='PeriodDay'>
<option value="1">Monday</option>
<option value="2">Tuesday</option>
<option value="3">Wednesday</option>
<option value="4">Thursday</option>
<option value="5">Friday</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="PrioritySubject" value="CPL">
<input type="hidden" name="AssemblyPeriodTime" value="<?php $AssemblyPeriodTime ?>">
<input type="hidden" name="AssemblyDay" value="<?php $AssemblyDay ?>">
<input type="submit" value="Submit">
</td>
<td>
<a href="AssemblyChapel4.php"><button type="button">Done</button>
</td>
</tr>
</table>
</form>
</center>
<?php
$SQL = "SELECT * FROM periodassignment WHERE SubjectID = 'ASS'";
$result=mysql_query($SQL);
while($db_field=mysql_fetch_assoc($result)) {
$ASS=$db_field["SubjectID"];
$AssPeriodDay=$db_field["PeriodDay"];
$AssPeriodTime=$db_field["PeriodTime"];
?>
<table border="1" cellpadding="0" style="border-spacing: 0px; height: 40%; width: 50%;" align="center">
<div align="center" style="font-family: Arimo;">
<tr>
<td>
Subject:
</td>
<td>
<?php echo $ASS?>
</td>
</tr>
<tr>
<td>
Day
</td>
<td>
<?php echo $AssPeriodDay;?>
</td>
</tr>
<tr>
<td>
Period Time:
</td>
<td>
<?php echo $AssPeriodTime; ?>
</td>
</tr>
</div>
</table>
<?php
}
$SQL = "SELECT * FROM periodassignment WHERE SubjectID = 'CPL'";
$result=mysql_query($SQL);
while($db_field=mysql_fetch_assoc($result)) {
$CPL=$db_field["SubjectID"];
$CPLPeriodDay=$db_field["PeriodDay"];
$CPLPeriodTime=$db_field["PeriodTime"];
?>
<table border="1" cellpadding="0" style="border-spacing: 0px; height: 40%; width: 50%;" align="center">
<div align="center" style="font-family: Arimo;">
<tr>
<td>
Subject:
</td>
<td>
<?php echo $CPL?>
</td>
</tr>
<tr>
<td>
Day
</td>
<td>
<?php echo $CPLPeriodDay;?>
</td>
</tr>
<tr>
<td>
Period Time:
</td>
<td>
<?php echo $CPLPeriodTime; ?>
</td>
</tr>
</div>
</table>
<?php
}
?>