This repository was archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlookup.php
More file actions
executable file
·191 lines (162 loc) · 6.38 KB
/
lookup.php
File metadata and controls
executable file
·191 lines (162 loc) · 6.38 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
<?php
include 'secrets.php';
$year = "2021-2022";
if (isset($_POST['id']) || isset($_POST['email'])) {
$db = mysqli_connect("localhost", "root", MYSQL_SECRET, $dbname);
if (!$db) {
die('<p class="error">Connect Error ('.mysqli_connect_errno().') '. mysqli_connect_error()."</p>");
}
$year = $_POST['year'];
if (isset($_POST['id'])) {
$id = hash('sha512', $_POST['id']);
$query = "SELECT * FROM `". $year ."` WHERE id='".$id."'";
$results = $db->query($query);
if ($results) {
$row = mysqli_fetch_array($results);
if (count($row) == 0) {
exit();
}
printf("Name: %s<BR>Email: %s<BR>", $row['name'], $row['email']);
exit();
}
} else if (isset($_POST['email'])) {
$email = trim($_POST['email']);
if (empty($email)) {
exit();
}
$email = mysqli_real_escape_string($db, $email);
$query = "SELECT * FROM `". $year ."` WHERE email LIKE '%$email%'";
$results = $db->query($query);
if ($results) {
while($row = mysqli_fetch_array($results)) {
printf("Name: %s<BR>Email: %s<BR>", $row['name'], $row['email']);
}
exit();
}
}
}
?>
<?php
$title = "Lookup Members";
include 'header.php';
?>
<style>
.error {
border-color: red;
}
</style>
<!-- Page Heading/Breadcrumbs -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"><?php echo $title ?></h1>
<ol class="breadcrumb">
<li><a href="index.php">Home</a>
</li>
<li class="active"><?php echo $title ?></li>
</ol>
</div>
</div>
<!-- /.row -->
<!-- Well -->
<div class="well">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-dark">
<select id="year" name="year" class="form-control" style="width: 200px; display: inline-block;" onchange="switchYear(event)">
<option disabled="disabled" selected="selected" value="">Select Year</option>
<option value="2021-2022">2021 - 2022</option>
<option value="2020-2021">2020 - 2021</option>
<option value="2019-2020">2019 - 2020</option>
<option value="2018-2019">2018 - 2019</option>
<option value="2017-2018">2017 - 2018</option>
</select>
<span id="year-error" class="help-block" style="color: red; display: none">Select a year</span>
<br />
<div class="form-group text-dark">
<label for="inputlg" style="font-size: 45px;">Enter ID:</label>
<input class="form-control input-lg" id="id-input" type="password" onkeyup="checkId(event)">
<span id="id-error-lookup" class="help-block" style="color: red; display: none">Could not find member by ID</span>
<span id="id-error-match" class="help-block" style="color: red; display: none">ID text does not match ID format</span>
</div>
<div class="form-group text-dark">
<label for="inputlg" style="font-size: 45px;">Search by Email:</label>
<input class="form-control input-lg" id="email-input" type="text" onkeyup="checkEmail(event)">
<span id="email-error" class="help-block" style="color: red; display: none">Could not find member by Email</span>
</div>
</div>
</div>
<div class="row">
<div id ="data" class="col-lg-8 col-lg-offset-2 text-center text-dark"> </div>
</div>
</div>
<!-- /.well -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<script type="application/javascript">
function checkId(event) {
if (event.which === 13) {
var id = $('#id-input').val();
var index = document.getElementById("year");
var year = index.options[index.selectedIndex].value;
if(year == "") {
$("#year-error").show();
return;
}
id = id.match(/00[0-9]{8}/gm);
if (id != null) {
$.post("lookup.php", {
id: id[0],
year: year
}, function(ret) {
if (ret.trim()) {
addData(ret)
} else {
$("#id-input").addClass("error")
$("#id-error-lookup").show()
}
});
} else {
$("#id-input").addClass("error")
$("#id-error-match").show()
// do something to say they don't exist
}
$('#id-input').val("");
} else {
$("#id-error-lookup").hide()
$("#id-error-match").hide()
}
}
function checkEmail(event) {
if (event.which === 13) {
var email = $('#email-input').val();
var index = document.getElementById("year");
var year = index.options[index.selectedIndex].value;
if(year == "") {
$("#year-error").show();
return;
}
$.post("lookup.php", {
email: email,
year: year
}, function(ret) {
if (ret.trim()) {
addData(ret)
} else {
$("#email-input").addClass("error")
$("#email-error").show()
}
});
} else {
$("#email-input").removeClass("error")
$("#email-error").hide()
}
}
function addData(data) {
$("#data").prepend(`<h2>${data}</h2>`)
}
function switchYear(event) {
$("#year-error").hide();
}
</script>
<?php
include 'footer.php';
?>