-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
executable file
·180 lines (170 loc) · 5.77 KB
/
index.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
<?php
include("config.php");
include("db.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Tutoring Session Login</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<center>
<?php
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
if ($_SESSION['username'] != '')
{
$username = $_SESSION['username'];
}
$room = "room.php";
if ($username == "")
{
show_login("");
}
else
{
if ($_SESSION['username'] == '')
{
if (preg_match('/[^\w\.@ ]/', $username) > 0)
{
show_login("Invalid username: must only contain letters, digits, spaces, dots, underscores and @");
}
else if (preg_match('/[\047\042\134]/', $password) > 0)
{
show_login("Invalid password");
}
else
{
$query = "select user_id,type from user where username='$username' and password='$password'";
$result = mysqli_query($mysql_link, $query);
if((!$result) || (! mysqli_num_rows($result)))
{
show_login("Incorrect username/password");
}
else
{
if ($row = mysqli_fetch_row($result))
{
$userid = $row[0];
$type = $row[1];
}
else
{
die("error getting info from db");
}
$_SESSION['user_id'] = $userid;
$_SESSION['username'] = $username;
$_SESSION['user_type'] = $type;
}
}
}
else
{
$type = $_SESSION['user_type'];
$userid = $_SESSION['user_id'];
}
if ($userid != "")
{
if ($type == "A")
{
// redirect to admin page
print "<meta http-equiv='Refresh' content='0; url=admin/'>";
return;
}
// List sessions
print "<p>Sessions due to start within the next 24 hours or the previous 2 hours are listed below. You will be given the option of logging into any sessions starting within the next $early_login_mins minutes, or sessions that have already started.</p>";
print "<table border=1><tr><th>Title</th><th>Scheduled Time ($tz)</th><th>Session Length (minutes)</th><th>Student</th><th>Teacher</th><th>Login</th></tr>\n";
if ($type == "T")
{
$qual = "teacher=$userid";
}
else
{
$qual = "student=$userid";
}
$query = "select session_id,title,date_format(scheduled_start_time, '$date_format'),length_minutes,student,teacher,timestampdiff(second, current_timestamp, scheduled_start_time) from session where $qual order by scheduled_start_time";
$result = mysqli_query($mysql_link, $query);
if ($result && mysqli_num_rows($result))
{
while ($row = mysqli_fetch_row($result))
{
$session_id = $row[0];
$title = $row[1];
$start_time = $row[2];
$length_minutes = $row[3];
$student = $row[4];
$teacher = $row[5];
$seconds_in_future = $row[6];
if (preg_match('/^\d+$/',$student))
{
$q2 = "select username from user where user_id=$student";
$result2 = mysqli_query($mysql_link, $q2);
if ($result2 && mysqli_num_rows($result2))
{
if ($row2 = mysqli_fetch_row($result2))
{
$student_name = $row2[0];
}
}
}
if (preg_match('/^\d+$/',$teacher))
{
$q2 = "select username from user where user_id=$teacher";
$result2 = mysqli_query($mysql_link, $q2);
if ($result2 && mysqli_num_rows($result2))
{
if ($row2 = mysqli_fetch_row($result2))
{
$teacher_name = $row2[0];
}
}
}
// list all sessions due to start in next 24 hours, or in
// past 2 hours
if ($seconds_in_future >= -7200 && $seconds_in_future < 86400)
{
print "<tr><td>$title</td><td>$start_time</td><td>$length_minutes</td><td>$student_name</td><td>$teacher_name</td>";
// allow users to log in up to early_login_mins mins before scheduled start time
if ($seconds_in_future < 60*$early_login_mins)
{
print "<td><form method=post action=\"$room\"><input type=\"hidden\" name=\"session_id\" value=\"$session_id\"><input type=submit value=\"Login\"></form></td>";
}
else
{
print "<td> </td>";
}
print "</tr>\n";
}
}
}
else
{
print "<tr><td align=center colspan=6>No scheduled sessions</td></tr>";
}
print "</table>";
}
}
function show_login($msg)
{
print "<form>";
print "<table>";
if ($msg != "")
{
print "<p class=error>$msg</p>";
}
print "<tr><td>Username:</td><td><input type=text maxlength=40 name=username value=\"$username\"></td></tr>";
print "<tr><td>Password:</td><td><input type=password maxlength=40 name=password value=\"$password\"></td></tr>";
print "</table>";
print "<p><input type=submit value=\"Login\"></p></form>";
}
?>
</center>
<?php
if ($_SESSION['username'] != "")
{
print '<p><a href="logout.php">Logout</a></p>';
}
?>
</body>
</html>