001.
$timeArr
=
array
(
002.
0 =>
array
(
"start"
=>
"08.00"
,
"stop"
=>
"08.30"
),
003.
1 =>
array
(
"start"
=>
"08.30"
,
"stop"
=>
"09.00"
),
004.
2 =>
array
(
"start"
=>
"09.00"
,
"stop"
=>
"09.30"
),
005.
3 =>
array
(
"start"
=>
"09.30"
,
"stop"
=>
"10.00"
),
006.
4 =>
array
(
"start"
=>
"10.00"
,
"stop"
=>
"10.30"
),
007.
5 =>
array
(
"start"
=>
"10.30"
,
"stop"
=>
"11.00"
),
008.
6 =>
array
(
"start"
=>
"11.00"
,
"stop"
=>
"11.30"
),
009.
7 =>
array
(
"start"
=>
"11.30"
,
"stop"
=>
"12.00"
),
010.
8 =>
array
(
"start"
=>
"12.00"
,
"stop"
=>
"12.30"
),
011.
9 =>
array
(
"start"
=>
"12.30"
,
"stop"
=>
"13.00"
),
012.
10 =>
array
(
"start"
=>
"13.00"
,
"stop"
=>
"13.30"
),
013.
11 =>
array
(
"start"
=>
"13.30"
,
"stop"
=>
"14.00"
),
014.
12 =>
array
(
"start"
=>
"14.00"
,
"stop"
=>
"14.30"
),
015.
13 =>
array
(
"start"
=>
"14.30"
,
"stop"
=>
"15.00"
),
016.
14 =>
array
(
"start"
=>
"15.00"
,
"stop"
=>
"15.30"
),
017.
15 =>
array
(
"start"
=>
"15.30"
,
"stop"
=>
"16.00"
),
018.
16 =>
array
(
"start"
=>
"16.00"
,
"stop"
=>
"16.30"
),
019.
17 =>
array
(
"start"
=>
"16.30"
,
"stop"
=>
"17.00"
),
020.
18 =>
array
(
"start"
=>
"17.00"
,
"stop"
=>
"17.30"
),
021.
19 =>
array
(
"start"
=>
"17.30"
,
"stop"
=>
"18.00"
),
022.
20 =>
array
(
"start"
=>
"18.00"
,
"stop"
=>
"18.30"
),
023.
21 =>
array
(
"start"
=>
"18.30"
,
"stop"
=>
"19.00"
),
024.
22 =>
array
(
"start"
=>
"19.00"
,
"stop"
=>
"19.30"
),
025.
23 =>
array
(
"start"
=>
"19.30"
,
"stop"
=>
"20.00"
)
026.
);
027.
028.
?>
029.
<div
class
=
"widget-content"
id=
"divprint"
>
030.
<?php
031.
for
(
$m
=1;
$m
<=
$_GET
[
"num_major"
];
$m
++){
032.
if
(isset(
$_GET
[
"major"
.
$m
.
""
])){
033.
unset(
$timeTeach
);
034.
035.
036.
connect_db();
037.
$select
=
"SELECT * FROM ((section INNER JOIN timetable ON section.Section_id = timetable.Section_id) INNER JOIN subject ON section.Subject_id = subject.Subject_id) WHERE timetable.Major_id='gis3' and section.Sem_id='1' and timetable.Day ='จันทร์' group by section.Subject_id,section.Section_no,section.Section_type,timetable.Day,timetable.Starttime,timetable.Endtime order by timetable.starttime"
;
038.
$query
= mysql_query(
$select
)
or
die
(
'query did not work'
);
039.
$num
=mysql_num_rows(
$query
);
040.
if
(
$num
== null){
041.
$timeTeach
[1][] =
array
(
'time'
=>
''
);
042.
}
043.
else
{
044.
while
(
$result
=mysql_fetch_array(
$query
)){
045.
$tid
=en2_day(
$result
[
"Day"
]);
046.
$timeTeach
[
$tid
][] =
array
(
'time'
=>
$result
[
"Starttime"
].
'-'
.
$result
[
"Endtime"
],
'title'
=>
"<b>"
.
$result
[
"Subject_id"
].
"</b>"
.
"<br>"
.
"("
.
$result
[
"Section_no"
].
"),"
.room(
$result
[
"Section_type"
],
$result
[
"Room_id"
]));
047.
}
048.
}
049.
050.
connect_db();
051.
$select1
=
"SELECT * FROM ((section INNER JOIN timetable ON section.Section_id = timetable.Section_id) INNER JOIN subject ON section.Subject_id = subject.Subject_id) WHERE timetable.Major_id='gis3' and section.Sem_id='1' and timetable.Day ='อังคาร' group by section.Subject_id,section.Section_no,section.Section_type,timetable.Day,timetable.Starttime,timetable.Endtime order by timetable.starttime"
;
052.
$query1
= mysql_query(
$select1
)
or
die
(
'query did not work'
);
053.
$num1
=mysql_num_rows(
$query1
);
054.
if
(
$num1
== null){
055.
$timeTeach
[2][] =
array
(
'time'
=>
''
);
056.
}
057.
else
{
058.
while
(
$result1
=mysql_fetch_array(
$query1
)){
059.
$tid
=en2_day(
$result1
[
"Day"
]);
060.
$timeTeach
[
$tid
][] =
array
(
'time'
=>
$result1
[
"Starttime"
].
'-'
.
$result1
[
"Endtime"
],
'title'
=>
"<b>"
.
$result1
[
"Subject_id"
].
"</b>"
.
"<br>"
.
"("
.
$result1
[
"Section_no"
].
"),"
.room(
$result1
[
"Section_type"
],
$result1
[
"Room_id"
]));
061.
}
062.
}
063.
064.
connect_db();
065.
$select2
=
"SELECT * FROM ((section INNER JOIN timetable ON section.Section_id = timetable.Section_id) INNER JOIN subject ON section.Subject_id = subject.Subject_id) WHERE timetable.Major_id='gis3' and section.Sem_id='1' and timetable.Day ='พุธ' group by section.Subject_id,section.Section_no,section.Section_type,timetable.Day,timetable.Starttime,timetable.Endtime order by timetable.starttime"
;
066.
$query2
= mysql_query(
$select2
)
or
die
(
'query did not work'
);
067.
$num2
=mysql_num_rows(
$query2
);
068.
if
(
$num2
== null){
069.
$timeTeach
[3][] =
array
(
'time'
=>
''
);
070.
}
071.
else
{
072.
while
(
$result2
=mysql_fetch_array(
$query2
)){
073.
$tid
=en2_day(
$result2
[
"Day"
]);
074.
$timeTeach
[
$tid
][] =
array
(
'time'
=>
$result2
[
"Starttime"
].
'-'
.
$result2
[
"Endtime"
],
'title'
=>
"<b>"
.
$result2
[
"Subject_id"
].
"</b>"
.
"<br>"
.
"("
.
$result2
[
"Section_no"
].
"),"
.room(
$result2
[
"Section_type"
],
$result2
[
"Room_id"
]));
075.
}
076.
}
077.
078.
connect_db();
079.
$select3
=
"SELECT * FROM ((section INNER JOIN timetable ON section.Section_id = timetable.Section_id) INNER JOIN subject ON section.Subject_id = subject.Subject_id) WHERE timetable.Major_id='gis3' and section.Sem_id='1' and timetable.Day ='พฤหัสบดี' group by section.Subject_id,section.Section_no,section.Section_type,timetable.Day,timetable.Starttime,timetable.Endtime order by timetable.starttime"
;
080.
$query3
= mysql_query(
$select3
)
or
die
(
'query did not work'
);
081.
$num3
=mysql_num_rows(
$query3
);
082.
if
(
$num3
== null){
083.
$timeTeach
[4][] =
array
(
'time'
=>
''
);
084.
}
085.
else
{
086.
while
(
$result3
=mysql_fetch_array(
$query3
)){
087.
$tid
=en2_day(
$result3
[
"Day"
]);
088.
$timeTeach
[
$tid
][] =
array
(
'time'
=>
$result3
[
"Starttime"
].
'-'
.
$result3
[
"Endtime"
],
'title'
=>
"<b>"
.
$result3
[
"Subject_id"
].
"</b>"
.
"<br>"
.
"("
.
$result3
[
"Section_no"
].
"),"
.room(
$result3
[
"Section_type"
],
$result3
[
"Room_id"
]));
089.
}
090.
}
091.
092.
connect_db();
093.
$select4
=
"SELECT * FROM ((section INNER JOIN timetable ON section.Section_id = timetable.Section_id) INNER JOIN subject ON section.Subject_id = subject.Subject_id) WHERE timetable.Major_id='gis3' and section.Sem_id='1' and timetable.Day ='ศุกร์' group by section.Subject_id,section.Section_no,section.Section_type,timetable.Day,timetable.Starttime,timetable.Endtime order by timetable.starttime"
;
094.
$query4
= mysql_query(
$select4
)
or
die
(
'query did not work'
);
095.
$num4
=mysql_num_rows(
$query4
);
096.
if
(
$num4
== null){
097.
$timeTeach
[5][] =
array
(
'time'
=>
''
);
098.
}
099.
else
{
100.
while
(
$result4
=mysql_fetch_array(
$query4
))
101.
{
102.
$tid
=en2_day(
$result4
[
"Day"
]);
103.
$timeTeach
[
$tid
][] =
array
(
'time'
=>
$result4
[
"Starttime"
].
'-'
.
$result4
[
"Endtime"
],
'title'
=>
"<b>"
.
$result4
[
"Subject_id"
].
"</b>"
.
"<br>"
.
"("
.
$result4
[
"Section_no"
].
"),"
.room(
$result4
[
"Section_type"
],
$result4
[
"Room_id"
]));
104.
}
105.
}
106.
107.
connect_db();
108.
$select5
=
"SELECT * FROM ((section INNER JOIN timetable ON section.Section_id = timetable.Section_id) INNER JOIN subject ON section.Subject_id = subject.Subject_id) WHERE timetable.Major_id='gis3' and section.Sem_id='1' and timetable.Day ='เสาร์' group by section.Subject_id,section.Section_no,section.Section_type,timetable.Day,timetable.Starttime,timetable.Endtime order by timetable.starttime"
;
109.
$query5
= mysql_query(
$select5
)
or
die
(
'query did not work'
);
110.
$num5
=mysql_num_rows(
$query5
);
111.
if
(
$num5
== null){
112.
$timeTeach
[6][] =
array
(
'time'
=>
''
);
113.
}
114.
else
{
115.
while
(
$result5
=mysql_fetch_array(
$query5
)){
116.
$tid
=en2_day(
$result5
[
"Day"
]);
117.
$timeTeach
[
$tid
][] =
array
(
'time'
=>
$result5
[
"Starttime"
].
'-'
.
$result5
[
"Endtime"
],
'title'
=>
"<b>"
.
$result5
[
"Subject_id"
].
"</b>"
.
"<br>"
.
"("
.
$result5
[
"Section_no"
].
"),"
.room(
$result5
[
"Section_type"
],
$result5
[
"Room_id"
]));
118.
}
119.
}
120.
121.
connect_db();
122.
$select6
=
"SELECT * FROM ((section INNER JOIN timetable ON section.Section_id = timetable.Section_id) INNER JOIN subject ON section.Subject_id = subject.Subject_id) WHERE timetable.Major_id='gis3' and section.Sem_id='1' and timetable.Day ='อาทิตย์' group by section.Subject_id,section.Section_no,section.Section_type,timetable.Day,timetable.Starttime,timetable.Endtime order by timetable.starttime"
;
123.
$query6
= mysql_query(
$select6
)
or
die
(
'query did not work'
);
124.
$num6
=mysql_num_rows(
$query6
);
125.
if
(
$num6
== null){
126.
$timeTeach
[7][] =
array
(
'time'
=>
''
);
127.
}
128.
else
{
129.
while
(
$result6
=mysql_fetch_array(
$query6
)){
130.
$tid
=en2_day(
$result6
[
"Day"
]);
131.
$timeTeach
[
$tid
][] =
array
(
'time'
=>
$result6
[
"Starttime"
].
'-'
.
$result6
[
"Endtime"
],
'title'
=>
"<b>"
.
$result6
[
"Subject_id"
].
"</b>"
.
"<br>"
.
"("
.
$result6
[
"Section_no"
].
"),"
.room(
$result6
[
"Section_type"
],
$result6
[
"Room_id"
]));
132.
}
133.
}
134.
$list
=
""
;
135.
echo
'<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed;">'
;
136.
echo
'<tr><th height="35" align="center" bgcolor="#515151"><span class="style3">วัน/เวลา</span></th>'
;
137.
echo
'<td width="7.68%" height="34" colspan="2" align="center" bgcolor="#515151"><span class="style2">08.00 - 09.00</span></td>'
;
138.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">09.00 - 10.00</span></td>'
;
139.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">10.00 - 11.00</span></td>'
;
140.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">11.00 - 12.00</span></td>'
;
141.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">12.00 - 13.00</span></td>'
;
142.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">13.00 - 14.00</span></td>'
;
143.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">14.00 - 15.00</span></td>'
;
144.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">15.00 - 16.00</span></td>'
;
145.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">16.00 - 17.00</span></td>'
;
146.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">17.00 - 18.00</span></td>'
;
147.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">18.00 - 19.00</span></td>'
;
148.
echo
'<td width="7.68%" colspan="2" align="center" bgcolor="#515151"><span class="style2">19.00 - 20.00</span></td>'
;
149.
echo
'</tr>'
;
150.
foreach
(
$timeTeach
as
$i
=>
$arr
){
151.
152.
153.
$timeT
=
$timeTeach
[
$i
];
154.
155.
$arrRange
= getTimeRange(
$timeT
,
$timeArr
);
156.
157.
$no
=
$i
+ 1;
158.
if
(
$no
==2){
159.
$day
=
"จันทร์"
;
160.
}
else
if
(
$no
==3){
161.
$day
=
"อังคาร"
;
162.
}
else
if
(
$no
==4){
163.
$day
=
"พุธ"
;
164.
}
else
if
(
$no
==5){
165.
$day
=
"พฤหัส"
;
166.
}
else
if
(
$no
==6){
167.
$day
=
"ศุกร์"
;
168.
}
else
if
(
$no
==7){
169.
$day
=
"เสาร์"
;
170.
}
else
if
(
$no
==8){
171.
$day
=
"อาทิตย์"
;
172.
}
173.
$list
=
'<tr >'
;
174.
$list
.=
'<td height="50" align="center" bgcolor="#A0A0A0"><span class="style3">'
.
$day
.
'</span></td>'
;
175.
$chkCol
= 0;
176.
$col
= 0;
177.
foreach
(
$timeArr
as
$timeA
)
178.
{
179.
$highlight
=
""
;
180.
$colspan
=
""
;
181.
if
(
$chkCol
< (
$col
-1) &&
$col
!= 0){
182.
$chkCol
++;
183.
continue
;
184.
}
185.
$title
=
" "
;
186.
$col
= 0;
187.
$chkCol
= 0;
188.
if
(isset(
$arrRange
[trim(
$timeA
[
'start'
])])){
189.
$col
=
$arrRange
[trim(
$timeA
[
'start'
])][
'colspan'
];
190.
$title
=
$arrRange
[trim(
$timeA
[
'start'
])][
'title'
];
191.
$highlight
=
"highlight"
;
192.
$colspan
=
'colspan="'
.
$col
.
'"'
;
193.
}
194.
$list
.=
'<td '
.
$colspan
.
' class="'
.
$highlight
.
' title" style="font-size:13px">'
.
$title
.
'</td>'
;
195.
196.
}
197.
$list
.=
'</tr>'
;
198.
echo
$list
;
199.
}
200.
echo
'</table>'
;
201.
echo
'<br>'
;
202.
echo
'<br>'
;
203.
echo
'<br>'
;
204.
echo
'<br>'
;
205.
echo
'<br>'
;
206.
echo
'<br>'
;
207.
echo
'<br>'
;
208.
echo
'<br>'
;
209.
echo
'<br>'
;
210.
echo
'<br>'
;
211.
}
212.
}
213.
?>
214.
</div>
215.
<?php }?>
216.
<?php
217.
function
room(
$type
,
$room_id
){
218.
if
(
$room_id
== null){
return
$type
;}
219.
else
{
return
$room_id
;}
220.
}
221.
function
en2_day(
$day
){
222.
if
(
$day
==
'จันทร์'
){
return
1;}
223.
elseif
(
$day
==
'อังคาร'
){
return
2;}
224.
elseif
(
$day
==
'พุธ'
){
return
3;}
225.
elseif
(
$day
==
'พฤหัสบดี'
){
return
4;}
226.
elseif
(
$day
==
'ศุกร์'
){
return
5;}
227.
elseif
(
$day
==
'เสาร์'
){
return
6;}
228.
elseif
(
$day
==
'อาทิตย์'
){
return
7;}
229.
}
230.
231.
function
getCol(
$haystack
,
$keyNeedle
){
232.
$i
= 0;
233.
foreach
(
$haystack
as
$arr
){
234.
if
(
$arr
[
'start'
] ==
$keyNeedle
){
235.
return
$i
;
236.
}
237.
$i
++;
238.
}
239.
}
240.
241.
function
getCol2(
$haystack
,
$keyNeedle
){
242.
$i
= 1;
243.
244.
foreach
(
$haystack
as
$arr
){
245.
if
(
$arr
[
'stop'
] ==
$keyNeedle
){
246.
247.
return
$i
;
248.
}
249.
$i
++;
250.
}
251.
}
252.
253.
function
getTimeRange(
$timeT
,
$timeCol
){
254.
$data
=
array
();
255.
foreach
(
$timeT
as
$timeA
){
256.
$time
=
$timeA
[
'time'
];
257.
if
(!
$time
)
continue
;
258.
$tm
=
explode
(
"-"
,
$time
);
259.
260.
$start
= getCol(
$timeCol
,
$tm
[0]);
261.
$end
= getCol2(
$timeCol
,
$tm
[1] );
262.
263.
$colspan
=
$end
-
$start
;
264.
$data
[
$tm
[0]] =
array
(
'colspan'
=>
$colspan
,
'title'
=>
$timeA
[
'title'
]);
265.
}
266.
return
$data
;
267.
}