This repository has been 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
/
Copy pathsubs.php
executable file
·216 lines (200 loc) · 8.33 KB
/
subs.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
// POST to receive data here:
//define('LISTS_STANDALONE', true);
include 'secrets.php';
include 'DirectoryServices/lists.php';
if (isset($_POST['method'])) {
$params = $_POST;
if (!isset($params['method']))
return http_return(["error" => "no method given"], 400);
$method = $params['method'];
unset($params['method']);
// Ad-hoc dues verification.
if ($method === 'dues') {
$db = mysqli_connect("localhost", "root", MYSQL_SECRET, $dbname);
if (!$db)
return http_return(["error" => "failed to connect to mysql"], 400);
$email = mysqli_real_escape_string($db, trim($params['email']));
$query = "SELECT * FROM `2021-2022` WHERE email = '$email'";
$result = $db->query($query);
return http_return(["result" => $result->fetch_array(MYSQLI_ASSOC)]);
}
try {
return http_return(["result" => dynamic_invoke("Lists::$method", $params, function($x) {
return http_return(["error" => "invalid parameter $x"], 400);
})]);
} catch (ReflectionException $e) {
return http_return(["error" => "no such method"], 400);
}
}
?>
<?php
// GET to show form here:
$title = "Subscriptions";
include 'header.php';
?>
<!-- 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>
<!-- Well -->
<div class="well">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center text-dark text-primary" style="padding-bottom: 24px;">
Select a person by their email address to display or update their subscriptions.
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="input-group form-group text-dark">
<span class="input-group-addon" id="sizing-addon1">@</span>
<input class="form-control input-lg" id="email-input" placeholder="Email..." type="email">
<span class="input-group-btn">
<button type="button" class="btn btn-primary btn-lg" data-toggle="tooltip" data-placement="bottom" title="Display the person's subscriptions." onclick="get()">FIND</button>
<button type="button" class="btn btn-primary btn-lg" data-toggle="tooltip" data-placement="bottom" title="Update the person's subscriptions." onclick="set()">UPDATE</button>
<button type="button" class="btn btn-primary btn-lg" data-toggle="tooltip" data-placement="bottom" title="Switch to another person." onclick="reset()">EXIT</button>
</span>
</div>
</div>
</div>
<div class="row" id="success-box" style="display: none">
<div class="col-lg-8 col-lg-offset-2">
<div class="alert alert-success"></div>
</div>
</div>
<div class="row" id="error-box" style="display: none">
<div class="col-lg-8 col-lg-offset-2">
<div class="alert alert-danger"></div>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="form-group text-dark">
<div class="checkbox">
<?php foreach (Lists::all(true) as $key => $value): ?>
<label class="btn btn-primary" style="width:100%;">
<input class="dynamic-box form-control" type="checkbox" autocomplete="off" name="list[]" value="<?php echo $key; ?>" id="<?php echo $key; ?>">
<?php echo $value; ?>
</label>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
<!-- /.well -->
<!-- Script -->
<script type="application/javascript">
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
String.prototype.capitalize = function() {
return this.replace(/(^|\s)([a-z])/g, function(m, p1, p2) {
return p1 + p2.toUpperCase();
});
};
$(".dynamic-box").prop("disabled", true);
function verify_email() {
var email = $("#email-input").val();
var error = "";
var emailPattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (!emailPattern.test(email)) {
error += "Please make sure the email is valid. <BR>";
}
if (error.length > 0) {
$(".alert-danger").html(error);
$("#error-box").show();
return null;
}
return email;
}
function get() {
var email = verify_email()
if (email == null) return;
$(".dynamic-box").prop("disabled", false);
$.post("subs.php", {
method: 'find',
email: email
}, function(data) {
$.post("subs.php", {
method: 'info',
email: email
}, function(data2) {
var name = email;
if (data2.result.length != 0) {
name = data2.result.cn[0].capitalize();
}
$.post("subs.php", {
method: 'dues',
email: email
}, function(data3) {
if (data3.result != null) {
name += " (Dues Paid)";
} else {
name += " (Dues UNPAID)";
}
$("#email-input").prop("disabled", true);
$(".dynamic-box").prop("checked", false);
for (var i = 0; i < data.result.length; i++) {
$("#" + data.result[i]).prop("checked", true);
}
$(".alert-success").html("Displaying subscriptions for <b>" + name + "</b>:");
$("#success-box").show();
});
});
});
}
function set() {
var email = verify_email()
if (email == null) return;
$(".dynamic-box").prop("disabled", false);
$.post("subs.php", {
method: 'find',
email: email
}, function(data) {
$.post("subs.php", {
method: 'info',
email: email
}, function(data2) {
var name = email;
if (data2.result.length != 0) {
name = data2.result.cn[0].capitalize();
}
/*
$("#email-input").prop("disabled", true);
$(".dynamic-box").prop("checked", false);
for (var i = 0; i < data.result.length; i++) {
$("#" + data.result[i]).prop("checked", true);
}
*/
$(".alert-success").html("");
$("#success-box").hide();
$(".alert-danger").html("This is currently unimplemented. <b>" + name + "</b>:");
$("#error-box").show();
});
});
}
// Reset the locked-in email and clear all checkboxes.
function reset() {
var email = verify_email()
if (email == null) return;
$("#email-input").prop("disabled", false);
$("#email-input").val("");
$(".dynamic-box").prop("checked", false);
$(".dynamic-box").prop("disabled", true);
$(".alert-success").html("");
$("#success-box").hide();
$(".alert-danger").html("");
$("#error-box").hide();
}
</script>
<?php
include 'footer.php';
?>