-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck_session_time.php
94 lines (89 loc) · 3.28 KB
/
check_session_time.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
<?php
include("db.php");
$session_id = $_REQUEST['session_id'];
$user_id = $_REQUEST['user_id'];
if ($user_id == '')
{
die("no user_id");
}
if ($session_id == '')
{
die("no session_id");
}
if(!preg_match('/^\d+$/',$user_id))
{
die("invalid user_id");
}
if(!preg_match('/^\d+$/',$session_id))
{
die("invalid session_id");
}
$query = "select student,teacher,student_login_time,teacher_login_time,actual_start_time,timestampdiff(second, actual_start_time, now()),length_minutes from session where session_id=$session_id";
$result = mysqli_query($mysql_link, $query);
if ($result && mysqli_num_rows($result))
{
if ($row = mysqli_fetch_row($result))
{
$student = $row[0];
$teacher = $row[1];
$student_login_time = $row[2];
$teacher_login_time = $row[3];
$actual_start_time = $row[4];
$seconds_after_start = $row[5];
$length_minutes = $row[6];
$seconds_before_end = $length_minutes*60 - $seconds_after_start;
if ($user_id == $student)
{
// update logout time
$query = "update session set student_logout_time=NOW() where session_id=$session_id";
$result = mysqli_query($mysql_link, $query) or die(mysqli_error($mysql_link));
if ($student_login_time == '')
{
// only set login time if not already set
$query = "update session set student_login_time=NOW() where session_id=$session_id";
$result = mysqli_query($mysql_link, $query) or die(mysqli_error($mysql_link));
if ($actual_start_time == '' && $teacher_login_time != '')
{
// mark session as actually started
$query = "update session set actual_start_time=NOW() where session_id=$session_id";
$result = mysqli_query($mysql_link, $query) or die(mysqli_error($mysql_link));
}
}
}
else if ($user_id == $teacher)
{
// update logout time
$query = "update session set teacher_logout_time=NOW() where session_id=$session_id";
$result = mysqli_query($mysql_link, $query) or die(mysqli_error($mysql_link));
if ($teacher_login_time == '')
{
// only set login time if not already set
$query = "update session set teacher_login_time=NOW() where session_id=$session_id";
$result = mysqli_query($mysql_link, $query) or die(mysqli_error($mysql_link));
if ($actual_start_time == '' && $student_login_time != '')
{
// mark session as actually started
$query = "update session set actual_start_time=NOW() where session_id=$session_id";
$result = mysqli_query($mysql_link, $query) or die(mysqli_error($mysql_link));
}
}
}
else
{
print "You are not authorized to log into this session";
exit;
}
if ($actual_start_time != '')
{
if ($seconds_after_start < 0 || $seconds_before_end < 0)
{
print "Session finished";
exit;
}
}
print "ok";
exit;
}
}
print "session finished";
?>