-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_gca.php
187 lines (159 loc) · 4.36 KB
/
verify_gca.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
180
181
182
183
184
185
186
187
<?php require_once 'users/init.php' ?>
<?php require_once 'php/db.php' ?>
<?php if (!securePage($_SERVER['PHP_SELF'])) { die(); } ?>
<?php
$err = "";
$updated = false;
// check id email and access are set in input parameters
$email = isset($_GET['email']) ? $_GET['email'] : (isset($_POST['email']) ? $_POST['email'] : "");
$access = isset($_GET['gcaUser']) ? $_GET['gcaUser'] : (isset($_POST['gcaUser']) ? $_POST['gcaUser'] : "");
if ($email && $access) {
$modules = "born_accessible";
if ($access == "false") {
$modules = "";
}
$db = new SMART_DB();
if ($db->connect()) {
if ($db->prepare("UPDATE users SET modules = ? WHERE email = ?")) {
if ($db->bind_param("ss", array($modules, $email))) {
if ($db->execute()) {
$updated = true;
}
else {
$err = "Failed to update database. Please try again.";
}
}
else {
$err = "Failed binding parameters. Please try again.";
}
}
else {
$err = "Failed to prepare database statement. Please try again.";
}
}
else {
$err = "Failed to connect to database. Please try again.";
}
$db->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Confirm GCA Access Rights - Ace SMART</title>
<link rel="stylesheet" type="text/css" href="css/a11y.css<?= '?v=' . $smart_version ?>"/>
<link rel="stylesheet" type="text/css" href="css/tabs.css<?= '?v=' . $smart_version ?>"/>
<style type="text/css">
body {
background-color: rgb(255,255,255) !important;
}
h1 {
font-size: 2.3rem !important;
}
h2 {
font-size: 1.8rem !important;
color: rgb(0,0,0) !important;
}
h1,h2 {
text-indent: 2rem !important;
}
div.alert {
background-color: rgb(245,245,245);
width: 47rem;
padding: 1rem;
margin-top: 2rem;
margin-bottom: 2rem;
}
p.confirm {
color: rgb(0,0,180);
font-weight: bold;
}
form#nextStep {
margin-left: 2rem;
margin-top: 2rem;
}
form#nextStep > * {
margin-bottom: 1rem;
}
section#userList {
margin-top: 3rem;
}
</style>
</head>
<body>
<header>
<h1 class="ace_login_hd">
<span><img src="/images/daisy_high.jpg" alt="DAISY"></span>
<span>Ace <span class="smart_hd">SMART</span></span>
</h1>
<h2>Access to Born Accessible Tab</h2>
</header>
<main>
<?php
if ($updated) {
$status_msg = $access == "true" ? "now has" : "no longer has";
echo <<<HTML
<div class="alert" role="alert">
<p class="confirm">Database successfully updated!</p>
<p>User {$email} {$status_msg} access to the Born Accessible tab.</p>
</div>
HTML;
}
else if ($err) {
echo <<<HTML
<div class="alert" role="alert">
<p class="confirm">Database update failed!</p>
<p>{$err}</p>
</div>
HTML;
}
?>
<section id="confirm">
<form id="nextStep" method="post" action="verify_gca.php">
<div><label>Email: <input type="text" name="email" id="email"/></label></div>
<div role="radiogroup" aria-labelledby="access-label">
<span id="access-label">Access:</span>
<label><input type="radio" id="gca-yes" name="gcaUser" value="true" checked> Grant</label>
<label><input type="radio" id="gca-no" name="gcaUser" value="false"> Revoke</label>
</div>
<input type="submit" value="Update">
</form>
</section>
<section id="userList">
<h2>User Access List</h2>
<ul>
<?php
$db = new SMART_DB();
if ($db->connect()) {
$user_query = "SELECT fname, lname, email FROM users WHERE modules LIKE '%born_accessible%' ORDER BY fname, lname, email";
if ($db->prepare($user_query)) {
if ($db->execute()) {
$emails = $db->get_results();
if (!$emails) {
echo "<li>No active GCA members found.</li>";
}
else {
foreach ($emails as $row) {
echo "<li>${row['fname']} ${row['lname']} — ${row['email']}</li>";
}
}
$db->close();
}
else {
echo "<li>Failed to execute query.</li>";
}
}
else {
echo "<li>Failed to prepare query.</li>";
}
}
else {
echo "<li>Failed to connect to database.</li>";
}
?>
</ul>
</section>
</main>
</body>
</html>