001.
<?php
002.
003.
include
(
'database_connection.php'
);
004.
005.
list(
$year
,
$term
) =
explode
(
"/"
,
$_POST
[
"filter_year"
]);
006.
007.
function
show_date(
$tmp
) {
008.
if
(
$tmp
!=
"0000-00-00"
) {
009.
list(
$date
,
$time
) =
explode
(
" "
,
$tmp
);
010.
list(
$y
,
$m
,
$d
) =
explode
(
"-"
,
$date
);
011.
$y
+= 543;
012.
return
$d
.
"/"
.
$m
.
"/"
.
$y
;
013.
}
014.
}
015.
016.
?>
017.
018.
<html>
019.
<head>
020.
<title>พิมพ์กราฟ</title>
023.
<script src=
"js/Chart.bundle.js"
></script>
024.
<style type=
"text/css"
media=
"print"
>
025.
@page { size: landscape; }
026.
027.
@media print
028.
{
029.
.no-print, .no-print *
030.
{
031.
display: none !important;
032.
}
033.
}
034.
</style>
035.
036.
</head>
037.
038.
<body>
039.
<div
class
=
" box"
>
040.
<h1 align=
"center"
>สรุปรายงานนัดหมายอาจารย์ที่ปรึกษา</h1>
041.
<h3 align=
"center"
>ปีการศึกษา : <?php print (
$term
)?>/<?php print (
$year
+543)?> ประเภท : <?php print
$_POST
[
"filter_category"
]?></h3>
042.
043.
<br />
044.
<?php
if
(
$_POST
[
"print"
]!=
""
) { ?>
045.
<style>
046.
table {
047.
border-collapse: collapse;
048.
}
049.
table,th,tr,td {
050.
border: 1px solid #8b8b8b;
051.
}
052.
</style>
053.
054.
<div
class
=
"table-responsive"
>
055.
<table border=
"1"
cellpadding=
"5"
width=
"100%"
>
056.
<thead>
057.
<tr align=
"center"
>
058.
<th>รหัสนักศึกษา</th>
059.
<th>ชื่อ</th>
060.
<th>วันที่</th>
061.
<th>เวลา</th>
062.
<th>ประเภท</th>
063.
<th>ปีการศึกษา</th>
064.
<th>เรื่อง</th>
065.
</tr>
066.
</thead>
067.
<tbody>
068.
<?php
069.
070.
$column
=
array
(
'student_number'
,
'student_name'
,
'app_date'
,
'time_id'
,
'category_id'
,
'app_year'
,
'app_message'
);
071.
072.
$query
=
"SELECT * FROM appointment "
;
073.
074.
if
(isset(
$_POST
[
'filter_year'
],
$_POST
[
'filter_category'
]) &&
$_POST
[
'filter_year'
] !=
''
&&
$_POST
[
'filter_category'
] !=
''
)
075.
{
076.
list(
$year
,
$term
) =
explode
(
"/"
,
$_POST
[
'filter_year'
]);
077.
if
(
$term
==
"1"
) {
078.
$fyear
=
" app_date between '"
.
$year
.
"-06-15' and '"
.
$year
.
"-10-24' "
;
079.
}
elseif
(
$term
==
"2"
) {
080.
$fyear
=
" app_date between '"
.
$year
.
"-11-19' and '"
.(
$year
+1).
"-03-17' "
;
081.
}
else
{
082.
$fyear
=
" app_date between '"
.(
$year
+1).
"-04-08' and '"
.(
$year
+1).
"-06-09' "
;
083.
}
084.
#
$query
.=
' WHERE app_year = "'
.
$_POST
[
'filter_year'
].
'" AND category_id = "'
.
$_POST
[
'filter_category'
].
'" '
;
085.
$query
.=
' WHERE '
.
$fyear
.
' AND category_id = "'
.
$_POST
[
'filter_category'
].
'" '
;
086.
}
087.
088.
if
(isset(
$_POST
[
'order'
]))
089.
{
090.
$query
.=
'ORDER BY '
.
$column
[
$_POST
[
'order'
][
'0'
][
'column'
]].
' '
.
$_POST
[
'order'
][
'0'
][
'dir'
].
' '
;
091.
}
092.
else
093.
{
094.
$query
.=
'ORDER BY appstudent_id DESC '
;
095.
}
096.
097.
$statement
=
$connect
->prepare(
$query
);
098.
099.
$statement
->execute();
100.
101.
$result
=
$statement
->fetchAll();
102.
103.
104.
105.
$data
=
array
();
106.
107.
foreach
(
$result
as
$row
)
108.
{
109.
?>
110.
<tr align=
"center"
>
111.
<td><?php print
$row
[
"student_number"
]?></td>
112.
<td><?php print
$row
[
"student_name"
]?></td>
113.
<td><?php print show_date(
$row
[
'app_date'
])?></td>
114.
<td><?php print
$row
[
"time_id"
]?></td>
115.
<td><?php print
$row
[
"category_id"
]?></td>
116.
<td><?php print
$row
[
"app_year"
]?></td>
117.
<td><?php print
$row
[
"app_message"
]?></td>
118.
</tr>
119.
<?php } ?>
120.
<tbody>
121.
</table>
122.
123.
<br />
124.
<br />
125.
<br />
126.
</div>
127.
<?php }
else
{ ?>
128.
<?php
129.
130.
$query
=
"SELECT month(app_date) as app_month, year(app_date) as app_year, count( appstudent_id) as qty FROM appointment "
;
131.
if
(
$term
==
"1"
) {
132.
$fyear
=
" app_date between '"
.
$year
.
"-06-15' and '"
.
$year
.
"-10-24' "
;
133.
}
elseif
(
$term
==
"2"
) {
134.
$fyear
=
" app_date between '"
.
$year
.
"-11-19' and '"
.(
$year
+1).
"-03-17' "
;
135.
}
else
{
136.
$fyear
=
" app_date between '"
.(
$year
+1).
"-04-08' and '"
.(
$year
+1).
"-06-09' "
;
137.
}
138.
139.
$query
.=
' WHERE '
.
$fyear
.
' AND category_id = "'
.
$_POST
[
'filter_category'
].
'" '
;
140.
$query
.=
' group by app_month order by app_date'
;
141.
142.
$statement
=
$connect
->prepare(
$query
);
143.
144.
$statement
->execute();
145.
$result
=
$statement
->fetchAll();
146.
foreach
(
$result
as
$row
) {
147.
148.
$data
.= (
$data
!=
""
)?
","
:
""
;
149.
$data
.=
$row
[
'qty'
];
150.
151.
$labels
.= (
$labels
!=
""
)?
","
:
""
;
152.
$labels
.=
'"'
.
$row
[
'app_month'
].
'/'
.(
$row
[
'app_year'
]+543).
'"'
;
153.
154.
}
155.
?>
156.
<canvas id=
"myChart"
style=
"width: 75%; height: 50%;"
></canvas>
157.
<?php } ?>
158.
<button type=
"submit"
name=
"graph"
id=
"graph"
class
=
"no-print"
value=
"graph"
onclick=
"window.print();"
>พิมพ์กราฟ</button>
159.
160.
</div>
161.
</body>
162.
</html>
163.
164.
<?php
if
(
$_POST
[
"print"
]!=
""
) { ?>
165.
166.
<script type=
"text/javascript"
language=
"javascript"
>
167.
window.print();
168.
</script>
169.
170.
<?php }
else
{ ?>
171.
172.
<script>
173.
var
ctx = document.getElementById(
"myChart"
).getContext(
'2d'
);
174.
var
myChart =
new
Chart(ctx, {
175.
type:
'bar'
,
176.
data: {
177.
labels: [<?php print
$labels
?>],
178.
datasets: [{
179.
label:
'# จำนวน'
,
180.
data: [<?php print
$data
?>],
181.
backgroundColor: [
182.
'rgba(255, 99, 132, 0.2)'
,
183.
'rgba(54, 162, 235, 0.2)'
,
184.
'rgba(255, 206, 86, 0.2)'
,
185.
'rgba(75, 192, 192, 0.2)'
,
186.
'rgba(153, 102, 255, 0.2)'
,
187.
'rgba(255, 159, 64, 0.2)'
188.
],
189.
borderColor: [
190.
'rgba(255,99,132,1)'
,
191.
'rgba(54, 162, 235, 1)'
,
192.
'rgba(255, 206, 86, 1)'
,
193.
'rgba(75, 192, 192, 1)'
,
194.
'rgba(153, 102, 255, 1)'
,
195.
'rgba(255, 159, 64, 1)'
196.
],
197.
borderWidth: 1
198.
}]
199.
},
200.
options: {
201.
scales: {
202.
yAxes: [{
203.
ticks: {
204.
beginAtZero: true
205.
}
206.
}]
207.
}
208.
}
209.
210.
});
211.
212.
</script>
213.
214.
<?php } ?>