-
Notifications
You must be signed in to change notification settings - Fork 0
/
selfcheck.php
executable file
·293 lines (275 loc) · 11.2 KB
/
selfcheck.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
<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
//the initial authentication and pull of data
if (empty(session_id()) && !isset($_SESSION) && session_status() == PHP_SESSION_NONE) {
session_start();
}
//include($_SERVER['DOCUMENT_ROOT'].'/webFiles/login/top.php');
$SETTINGS['header'] = $_SERVER['DOCUMENT_ROOT'] . '/webFiles/fs_header.php';
$SETTINGS['footer'] = $_SERVER['DOCUMENT_ROOT'] . '/webFiles/fs_footer.php';
include_once('vars/privateVar.php');
include_once('functions/functions.php');
//unset($_SESSION['libSession']['selfCheck']);
$top_html = '<style>input[type=text] {width:auto;}</style><div style="padding:1em;">
<div style="width:100%;min-height:80px;text-align:left;margin-bottom:2em;" id="toplogo"><a href="https://library.wou.edu/" target="_blank"><img src="/webFiles/images/logos/woulib_logos/HL_logo_2Color_on_transparent.png" alt="WOU Library logo space" style="max-height:130px;"></a></div>';
//get expiration from session variable
$now = new DateTime();
include $SETTINGS['header'];
print $top_html;
$selfCheck = 'yes';
if (isset($_SESSION['libSession']['selfCheck'])) {
showForms();
} else {
if (empty($_POST['login'])) {
loginForm();
} else {
if (isset($_POST['login']) && isset($_POST['password']) && strtolower($_POST['login']) == $secretName && $_POST['password'] == $secretCode) {
$_SESSION['libSession']['selfCheck'] = 'yes';
showForms();
} else {
print '<h3>Incorrect username/password</h3>';
loginForm();
}
}
}
?>
</body>
</html>
<?php
function loginForm()
{
print '<h3>This system is logged out. Please contact the Checkout Desk for assistance.</h3>';
print '<form action="" method="post" id="loginForm">';
print '<div style="width:5em;">Staff Username:</div><input name="login"></br>';
print '<div style="width:5em;">Staff Password:</div><input type="password" name="password">';
print '</br><div style="width:5em;"></div><input type="submit">';
print '</form>';
}
function showForms()
{
global $apikey;
?>
<h2>Self Checkout</h2>
<script>
// Set the date we're counting down to
var countDownDate = new Date();
countDownDate.setMinutes(countDownDate.getMinutes() + 1);
function focusAndOpenKeyboard(el, timeout) {
if (!timeout) {
timeout = 100;
}
if (el) {
// Align temp input element approximately where the input element is
// so the cursor doesn't jump around
var __tempEl__ = document.createElement('input');
__tempEl__.style.position = 'absolute';
__tempEl__.style.top = (el.offsetTop + 7) + 'px';
__tempEl__.style.left = el.offsetLeft + 'px';
__tempEl__.style.height = 0;
__tempEl__.style.opacity = 0;
// Put this temp element as a child of the page <body> and focus on it
document.body.appendChild(__tempEl__);
__tempEl__.focus();
// The keyboard is open. Now do a delayed focus on the target element
setTimeout(function() {
el.focus();
el.click();
// Remove the temp element
document.body.removeChild(__tempEl__);
}, timeout);
}
}
</script>
<noscript>You need to enable JavaScript to run this app.</noscript>
<?php
if (!empty($_REQUEST['IDnumber']) && preg_match('/v0/i', $_REQUEST['IDnumber'])) {
$IDnumber = preg_replace('/2v/i', 'V', $_REQUEST['IDnumber']);
//set a session variable to unset at the end of cko
$queryParams = '?' . urlencode('apikey') . '=' . urlencode($apikey);
$service_url = 'https://api-na.hosted.exlibrisgroup.com/almaws/v1/users/' . $IDnumber;
//user CURL to get record
$curl_response = getAlmaRecord($service_url, $queryParams);
$patronRecord = json_decode($curl_response);
$ptype = !empty($patronRecord->user_group->value) ? urlencode(trim(stripslashes($patronRecord->user_group->value))) : '';
//I don't think this is working
$expires = !empty($patronRecord->expiry_date) ? urlencode(trim(stripslashes($patronRecord->expiry_date))) : '';
$expires = str_replace('Z', '', $expires);
if (empty($expires) && !empty($ptype)) {
$expires = date('m-d-Y', strtotime('3 years'));
} elseif (empty($expires) && empty($ptype)) {
$expires = date('m-d-Y', strtotime('6 months ago'));
} elseif ($expires == strtotime('December 31, 1969')) {
$expires = date('m-d-Y', strtotime('3 years'));
} else {
$expires = date('m-d-Y', strtotime($expires . ' +2 weeks'));
}
print !empty($patronRecord->pref_first_name) ? $patronRecord->pref_first_name : $patronRecord->first_name;
print ' ';
print !empty($patronRecord->pref_middle_name) ? $patronRecord->pref_middle_name : $patronRecord->middle_name;
print ' ';
print !empty($patronRecord->pref_last_name) ? $patronRecord->pref_last_name : $patronRecord->last_name;
//pref_middle_name//pref_last_name
if ($expires > date('m-d-Y', strtotime('now'))) {
?>
<p>Scan the barcode of the items you want to check out</p>
<form action="" method="post" id="checkoutForm">
<input name="barcode" id="barcode">
<!--<input type="submit">-->
<div id="loading"></div>
</form>
<div id="ItemsOut"></div>
<div id="FailedCKO"></div> <!-- Display the countdown timer in an element -->
<?php
} else {
print '<p>Your account is expired. Please see the Checkout Desk.</p>';
}
?>
<hr>
<p>Session will automatically time out if there is no activity for 1 minute. Remaining time: <span id="count"></span></p>
<input name="logout" id="logout" type="button" value="End Session">
<script>
var x = 0;
$(document).ready(function() {
countDown(countDownDate);
$('#barcode').trigger('click');
$("#barcode").select();
$('#barcode').focus();
$('#barcode').get(0).focus();
$('#barcode').trigger('touchstart');
var myElement = $('#barcode');
var modalFadeInDuration = 300;
focusAndOpenKeyboard(myElement, modalFadeInDuration); // or without the second argument
});
function countDown(countDownDate) {
// Update the count down every 1 second
x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
//var days = Math.floor(distance / (1000 * 60 * 60 * 24));
//var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
$("#count").html(minutes + "m " + seconds + "s ");
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
$("#count").html('Expired');
window.location.href = location.href;
}
}, 1000);
}
</script>
<?php
} else {
?>
<p>Scan your WOU ID/barcode</p>
<form action="" method="post" id="patronForm">
<input name="IDnumber" id="IDnumber">
<!--<input type="submit">-->
<div id="loading"></div>
</form>
<script>
$(document).ready(function() {
$("#IDnumber").select();
$('#IDnumber').focus();
$('#IDnumber').get(0).focus();
$('#IDnumber').trigger('click');
$('#IDnumber').trigger('touchstart');
// Usage example
var myElement = $('#IDnumber');
var modalFadeInDuration = 300;
focusAndOpenKeyboard(myElement, modalFadeInDuration); // or without the second argument
});
</script>
<?php
}
?>
<script>
$('.input').keypress(function(e) {
if (e.which == 13) {
$('form').submit();
return false; //<---- Add this line
}
});
$('#checkoutForm').submit(function(evt) {
evt.preventDefault();
var barcode = $('#barcode').val();
createLoan(barcode);
});
$('#logout').click(function() {
window.location.href = location.href;
});
function createLoan(barcode) {
event.preventDefault();
//reset the timer
countDownDate = new Date();
countDownDate.setMinutes(countDownDate.getMinutes() + 1);
clearInterval(x);
countDown(countDownDate);
$('#loading').html('<img src="/webFiles/resolver/ajax-loader.gif" border="0">');
$.getJSON("/webFiles/login/alma/alma_processor.php?mylib=yes&type=checkout&pid= <?php print $IDnumber; ?>&barcode=" + barcode).done(function(result) {
countDownDate = new Date();
countDownDate.setMinutes(countDownDate.getMinutes() + 1);
//console.log(result);
if ((result['web_service_result'] && result['web_service_result']['errorsExist'] && result['web_service_result']['errorsExist'] === true) || (result['errorsExist'] && result['errorsExist'] === true)) {
alert('This item was NOT checked out. Please contact the Checkout Desk for assistance.');
var errorText = '<p><strong>';
$.each(result['errorList']['error'], function(key, val) {
errorText += val['errorMessage'] + '. ';
});
$('#FailedCKO').append(errorText + barcode + ' NOT checked out. Please contact the Checkout Desk for assistance.</strong></p>');
$('#barcode').val('');
} else {
var due_date = result['due_date'];
var d = new Date(due_date);
due_date = d.toLocaleString();
// alert ('result['title'] Due Date: ' + due_date);
if ($('#ItemsOut').is(':empty')) {
$('#ItemsOut').append('<p><strong>The following have been checked out to you:</strong></p>');
}
$('#ItemsOut').append('<p>' + result['title'] + ' Due Date: ' + due_date + '</p>');
}
$('#loading').html('');
$('#barcode').val('');
}).fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
alert("Request Failed: " + err);
$('#barcode').val('');
$('#FailedCKO').append('<p>' + barcode + ' NOT checked out. Please contact the Checkout Desk for assistance.</p>');
});
}
function focusAndOpenKeyboard(el, timeout) {
if (!timeout) {
timeout = 100;
}
if (el) {
// Align temp input element approximately where the input element is
// so the cursor doesn't jump around
var __tempEl__ = document.createElement('input');
__tempEl__.style.position = 'absolute';
__tempEl__.style.top = (el.offsetTop + 7) + 'px';
__tempEl__.style.left = el.offsetLeft + 'px';
__tempEl__.style.height = 0;
__tempEl__.style.opacity = 0;
// Put this temp element as a child of the page <body> and focus on it
document.body.appendChild(__tempEl__);
__tempEl__.focus();
// The keyboard is open. Now do a delayed focus on the target element
setTimeout(function() {
el.focus();
el.click();
// Remove the temp element
document.body.removeChild(__tempEl__);
}, timeout);
}
}
</script>
<?php
}
?>