This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattendance_confirmation.php
83 lines (75 loc) · 3.89 KB
/
attendance_confirmation.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
<?php
//swiftから送られてきた値
$class_room_number = $_GET['class_room']; //教室番号
$day_of_the_week = date('w'); //本日の曜日の番号(0〜6)のいずれかを格納
$date = date('Y-m-d'); //本日の日付を取得
$time = date('H:i:s'); //現在の時間を取得
//担当教官、クラス記号、科目名、曜日、開始時間、終了時間、クラス記号のidを取得するsql
$link = mysqli_connect('mysql1.php.xdomain.ne.jp','ryotakaneko_1','ohs80538','ryotakaneko_smartendance');
mysqli_set_charset($link,'utf8');
$data = mysqli_query($link,"SELECT roma_name,class_symbol,subject,teaches.day_of_the_week,start_time,end_time,classes_id,class_rooms.class_room
FROM teaches
INNER JOIN instructors
ON teaches.instructor_id = instructors.id
INNER JOIN day_of_the_weeks
ON teaches.day_of_the_week = day_of_the_weeks.id
INNER JOIN class_times
ON teaches.time_id = class_times.times
INNER JOIN classes
ON teaches.classes_id = classes.id
INNER JOIN subjects
ON teaches.subject_id = subjects.id
INNER JOIN class_rooms
ON teaches.class_room_id = class_rooms.id
WHERE teaches.day_of_the_week = ".$day_of_the_week."
AND start_time <= '".$time."'
AND '".$time."' <= end_time
AND class_rooms.class_room = '".$class_room_number."'");
$record = [];
while($row = mysqli_fetch_assoc($data)){
$record[] = $row;
}
if($record != null){
//欠席している生徒の出席番号と名前を取り出すsql
$data1 = mysqli_query($link,"SELECT * FROM students WHERE NOT EXISTS (SELECT * FROM attend WHERE students.student_number = attend.student_number AND attend_day = '".$date."') ORDER BY attendance_number ASC");
$record1 = [];
$cnt = 0;
while($row = mysqli_fetch_assoc($data1)){
$record1[] = $row;
$cnt++;
}
$absenteeNumber = [];
$absenteeName = [];
$index = 0;
foreach($record1 as $val){
$absenteeNumber[] = $record1[$index]['attendance_number'];
$absenteeName[] = $record1[$index]['name'];
$index++;
}
//クラスの人数を取り出すsql
$data2 = mysqli_query($link,"SELECT COUNT(*) FROM students WHERE classes_id =".$record[0]['classes_id']);
$record2 = [];
while($row = mysqli_fetch_assoc($data2)){
$record2[] = $row;
}
//出席者の人数
$number_of_attendees = $record2[0]["COUNT(*)"] - $cnt;
$number_of_attendees = (String)$number_of_attendees;
$ary_data = array(
'classRoomNumber' => $class_room_number, //教室番号
'classSymbol' => $record[0]['class_symbol'], //クラス記号
'subject' => $record[0]['subject'], //科目名
'number_of_attendees' => $number_of_attendees, //出席者の人数
'class_size' => $record2[0]["COUNT(*)"], //クラスの人数
'absenteeNumber' => $absenteeNumber, //欠席者の出席(2次元配列)
'absenteeName' => $absenteeName //欠席者の名前(2次元配列)
);
}else{
$ary_data = array(
'result' => 'この教室では授業がありません。'
);
}
// 配列をjson_encode関数でJSON形式に変換します。
echo json_encode($ary_data, JSON_UNESCAPED_UNICODE);
mysqli_close($link);
?>