-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
336 lines (315 loc) · 14.4 KB
/
report.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?php
/**
* Created by PhpStorm.
* User: kvu
* Date: 10/17/2014
* Time: 3:54 PM
*/
require_once 'src/OpenURL/ContextObject.php';
require_once 'src/OpenURL/Entity.php';
//require_once('src/recaptchalib.php');
include('config/settings.php');
include('SimpleLogger.php');
//require_once('src/SwiftMailer/lib/classes/Swift/SmtpTransport.php');
require_once 'vendor/autoload.php';
// Recaptcha V2
use Phelium\Component\reCAPTCHA;
$reCAPTCHA = new reCAPTCHA($recaptcha_public_key, $recaptcha_private_key);
$logger = new SimpleLogger("logs/");
$openurlraw = $_SERVER['QUERY_STRING'];
$description = $first_name = $last_name = $phone = $email = $summary = "";
$to = $from = $subject = "";
$body = "";
$submitted = "";
$recaptcha_failed = "";
// Swift Mailer config
$transport = (new Swift_SmtpTransport('mailout.du.edu', 25));
$mailer = new Swift_Mailer($transport);
$privatekey = $publickey = "";
# the error code from reCAPTCHA, if any
$error = null;
# the response from reCAPTCHA
$resp = null;
$privatekey = $recaptcha_private_key;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Let's save input data so that when a data-validation failure should occur, we can pre-fill the forms
$description = $_POST["description"];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$summary = $_POST["summary"];
// Recaptcha
if ($_POST["g-recaptcha-response"]) {
// Recaptcha V1
// $resp = recaptcha_check_answer($privatekey,
// $_POST["g-recaptcha-response"],
// $_SERVER["REMOTE_ADDR"]);
// if ($resp->is_valid) {
// Recaptcha V2
if ($reCAPTCHA->isValid($_POST['g-recaptcha-response'])) {
// Validate input data
$description = test_input($_POST["description"]);
$first_name = test_input($_POST["first_name"]);
$last_name = test_input($_POST["last_name"]);
$phone = test_input($_POST["phone"]);
$email = test_input($_POST["email"]);
$summary = test_input($_POST["summary"]);
$affiliation = test_input($_POST["affiliation"]);
$schoolAffiliation = test_input($_POST["school_affiliation"]);
$openurlclean = test_input($openurlraw);
$openurlclean = str_replace("amp;", "", $openurlclean);
// Send email
$body = compose_mail($description, $first_name, $last_name, $phone, $email, $summary, $openurlraw, $openurlclean, $openurl_base_url, $affiliation, $schoolAffiliation, $permalink_base_url, $logger);
$to = $email_destinations;
$subject = $email_subject_prefix . $summary;
//$logger->log("\n\nSUBJECT: " . $subject . "\nBODY:\n" . $body . "\n\n\n\n\n\n", "Form Submission");
$message = new Swift_Message($subject);
$message->setFrom($email);
$message->setTo($to);
$message->setBody($body);
$result = $mailer->send($message);
//$result = $mailer->send($message);
$submitted = "<div class=\"alert alert-success\" role=\"alert\">" . $success_response_text . "</div>";
// Clear input data when submitted
$description = $first_name = $last_name = $phone = $email = $summary = "";
}
else {
// Will need to pre-fill form. (Note: This form, except reCAPTCHA, is validated using jQuery from http://ajax.aspnetcdn.com.)
$recaptcha_failed = 'Please retry. reCAPTCHA said: "' . $resp->error . '"';
}
}
else {
// Will need to pre-fill form (Note: This form, except reCAPTCHA, is validated using jQuery from http://ajax.aspnetcdn.com.)
$recaptcha_failed = 'Please retry.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Report a Problem</title>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/flatly/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<style type="text/css">
label.valid {
display: none !important;
}
label.error {
font-weight: bold;
color: red;
padding: 2px 8px;
margin-top: 2px;
}
h4 {
color: red;
}
em {
color: red;
}
label.radio-inline {
padding-left: 5px;
margin-left: 0px !important;
}
</style>
<script type="text/javascript">
var RecaptchaOptions = {
theme : 'clean'
};
</script>
<!-- <script src='https://www.google.com/recaptcha/api.js'></script> -->
<?php echo $reCAPTCHA->getScript(); ?>
</head>
<body>
<div class="container">
<div class="row">
<h1>Report a Problem</h1>
<?php echo $submitted; ?>
<div class="col-md-7 well">
<form role="form" method="post" action="" id="contact-form" name="contact-form" class="form-horizontal">
<div class="form-group has-feedback">
<label class="control-label col-md-2" for="summary">Summary<em>*</em></label>
<div class="col-md-10">
<input type="text" class="form-control" id="summary" name="summary" value="<?php echo $summary; ?>" placeholder="">
<i class="fa form-control-feedback"></i>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-md-2" for="description">Description<em>*</em></label>
<div class="col-md-10">
<textarea class="form-control" id="description" name="description" rows="5"><?php echo $description; ?></textarea>
<i class="fa form-control-feedback"></i>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-md-2" for="email">E-mail<em>*</em></label>
<div class="col-md-7">
<input type="email" class="form-control" id="email" name="email" value="<?php echo $email; ?>" placeholder="">
<i class="fa form-control-feedback"></i>
</div>
</div>
<div class="form-group has-feedback">
<label class="control-label col-md-2">Name</label>
<div class="col-md-4">
<label class="control-label sr-only" for="first_name">First</label>
<input type="text" class="form-control " id="first_name" name="first_name" placeholder="First Name" value="<?php echo $first_name; ?>">
<i class="fa form-control-feedback"></i>
</div>
<div class="col-md-5">
<label class="control-label sr-only" for="last_name">Last</label>
<input type="text" class="form-control" id="last_name" name="last_name" value="<?php echo $last_name; ?>" placeholder="Last Name">
<i class="fa form-control-feedback"></i>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="phone">Phone</label>
<div class="col-md-5">
<input type="text" class="form-control" id="phone" name="phone" value="<?php echo $phone; ?>" placeholder="">
<i class="fa form-control-feedback"></i>
</div>
</div>
<div class="form-group col-md-6" style="">
<label class="control-label col-md-4">Affiliation<em>*</em></label>
<div class="radio col-md-8">
<label><input type="radio" name="affiliation" value="Student" checked>Student</label><br />
<label><input type="radio" name="affiliation" value="Faculty">Faculty</label><br />
<label><input type="radio" name="affiliation" value="Staff">Staff</label><br />
<label><input type="radio" name="affiliation" value="Library Staff">Library Staff</label><br />
<label><input type="radio" name="affiliation" value="Public / Other">Public / Other</label>
</div>
</div>
<div class="form-group col-md-6" style="">
<label class="control-label col-md-4">School Affiliation<em>*</em></label>
<div class="radio col-md-8">
<label><input type="radio" name="school_affiliation" value="DU" checked>DU</label><br />
<label><input type="radio" name="school_affiliation" value="Law">Law</label><br />
<label><input type="radio" name="school_affiliation" value="Iliff">Iliff</label><br />
<label><input type="radio" name="school_affiliation" value="Other">Other</label>
</div>
</div>
<div class="form-group">
<label class="control-label sr-only" for="openURL"></label>
<input type="hidden" name="openURL" value="<?php echo $openurlraw; ?>">
</div>
<div class="form-group">
<label class="control-label col-md-2" for="recaptcha">Help stop spam<em>*</em></label>
<div class="col-md-10">
<?php
// $publickey = $recaptcha_public_key;
// echo recaptcha_get_html($publickey, $error, "true");
// V2
echo $reCAPTCHA->getHtml();
?>
<h4><?php echo $recaptcha_failed;?></h4>
</div>
</div>
<div class="col-md-10 col-md-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<div class="col-md-5">
</div>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('#contact-form').validate(
{
rules: {
email: {
required: true,
email: true
},
description: {
required: true
},
summary: {
required: true
}
},
highlight: function (element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
$(element).closest('.form-control-feedback').removeClass('fa-check').addClass('fa-remove');
},
success: function (element) {
$(element).addClass('valid').closest('.form-group').removeClass('error').addClass('success has-success');
$(element).closest('.form-control-feedback').removeClass('fa-remove').addClass('fa-check');
}
});
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '<?php echo $google_analytics_id;?>', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function compose_mail($description, $first_name, $last_name, $phone, $email, $summary, $openurlraw, $openurlclean, $openurl_base_url, $affiliation, $schoolAffiliation, $permalink_base_url, $l) {
$body = "";
$body = $body . "Sender: \t\t" . $first_name . " " . $last_name . "\n\n";
$body = $body . "Sender Contact Info: \n\n";
$body = $body . "Email: \t" . $email . "\n\n";
$body = $body . "Phone: \t" . $phone . "\n\n";
$body = $body . "Affiliation: \t" . $affiliation . "\n\n";
$body = $body . "School Affiliation: \t" . $schoolAffiliation . "\n\n";
$body = $body . "Summary: \t\t" . $summary . "\n\n";
$body = $body . "Description: \t\t" . $description . "\n\n";
$body = $body . "OpenURL: \t\t" . $openurl_base_url . $openurlclean . "\n\n";
$body = $body . "IP Address: \t\t" . $_SERVER['REMOTE_ADDR'] . "\n\n";
$body = $body . "User Agent [Browser]: \t\t" . $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$body = $body . "Project: link-resolver\n\n";
$body = $body . "Tracker: Bug\n\n";
$body = primo_retrieval($body, $openurlraw, $permalink_base_url, $l);
return $body;
}
function primo_retrieval($body, $openurlraw, $permalink_base_url, $l) {
if(empty($openurlraw)) {
$body = $body . "OpenURL is empty\n";
} else {
$ctx = \OpenURL\ContextObject::loadKev($openurlraw);
$body = $body . "Genre: " . $ctx->getReferent()->getValue('genre') . "\n";
$body = $body . "Journal Title: " . $ctx->getReferent()->getValue('jtitle') . "\n";
$body = $body . "Book Title: " . $ctx->getReferent()->getValue('title') . "\n";
$body = $body . "Article Title: " . $ctx->getReferent()->getValue('atitle') . "\n";
$body = $body . "spage: " . $ctx->getReferent()->getValue('spage') . "\n";
$body = $body . "isbn: " . $ctx->getReferent()->getValue('isbn') . "\n";
$body = $body . "stitle: " . $ctx->getReferent()->getValue('stitle') . "\n";
$body = $body . "btitle: " . $ctx->getReferent()->getValue('btitle') . "\n";
$body = $body . "year: " . $ctx->getReferent()->getValue('year') . "\n";
$body = $body . "issue: " . $ctx->getReferent()->getValue('issue') . "\n";
$body = $body . "Author: " . $ctx->getReferent()->getValue('au') . "\n";
$body = $body . "Volume: " . $ctx->getReferent()->getValue('volume') . "\n";
$body = $body . "rfr_id: " . $ctx->getReferent()->getValue('id') . "\n";
$body = $body . $ctx->toKev() . "\n";
// Extract the doc id, build the permalink to the resource.
$data = $ctx->getReferent()->getValue('dat');
$pattern = '/01UODE_INST:[0-9][0-9]+/'; // Locate the doc id, which appears after the institution code
$matches = array();
if(preg_match($pattern, $data, $matches) === 1) {
$docid = substr($matches[0], 12); // Remove the institution code
$permalink = $permalink_base_url . "?docid=01UODE_ALMA" . $docid . "&context=L&vid=01UODE_MAIN&search_scope=everything_scope&tab=default_tab&lang=en_US";
$body = $body . "\nPermalink:\t\t" . $permalink . "\n";
}
else {
$body = $body . "\nPermalink is not available\n";
}
}
return $body;
}
?>