-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.php
135 lines (119 loc) · 4.35 KB
/
checkout.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
<?php
/*******************************************************
* checkout.php
* Called from main.php
* Calls patronEdit.php, patronFindCKO.php
*
* (1) Find patron info
* (2) See if patron has a valid barcode
* (3) Display patronInfo in a shortform at the top.
********************************************************/
session_start();
require_once('common.php');
/********** Check permissions for page access ***********/
$allowed = array("ADMIN","STAFF");
if (false === array_search($userdata['authlevel'],$allowed)) {
$_SESSION['notify'] = array("type"=>"info", "message"=>"You do not have permission to access this information - Listing Patrons");
header("location:main.php");
exit;
}
/********************************************************/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?=$institution?> Library Database</title>
<!-- Required meta tags -->
<title>Library Database — 2023</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="resources/bootstrap5.min.css" >
<!-- our project just needs Font Awesome Solid + Brands -->
<!-- <link href="resources/fontawesome-6.4.2/css/fontawesome.min.css" rel="stylesheet"> -->
<link href="resources/fontawesome6.min.css" rel="stylesheet">
<link href="resources/fontawesome-6.4.2/css/brands.min.css" rel="stylesheet">
<link href="resources/fontawesome-6.4.2/css/solid.min.css" rel="stylesheet">
<link rel="stylesheet" href="resources/library.css" >
<script src="resources/library.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
const bar = document.getElementById('barcode');
bar.addEventListener('keyup', (e) => {
if (e.key === 'Enter') processBarcode(e);
});
});
function dynamicData(str) {
if (str.length == 0) {
document.getElementById("dynTable").innerHTML = "";
return;
}
document.getElementById("barcode").value = "";
let xhr = new XMLHttpRequest();
xhr.onload = () => {
if (xhr.responseText == "LOGOUT") {
window.document.location="index.php?ERROR=Failed%20Auth%20Key";
return;
}
document.getElementById("dynTable").innerHTML = xhr.responseText;
}
xhr.open("GET", "patronFindCKO.php?q=" + str, true);
xhr.send();
}
function processBarcode(e) {
const str = e.target.value;
if (str.length == 0) {
document.getElementById("dynTable").innerHTML = "";
return;
}
//validation of the input...
if (isNaN(str)) {
displayNotification("error", "Invalid barcode");
return;
}
let xhr = new XMLHttpRequest();
xhr.onload = () => {
if (xhr.responseText == "LOGOUT") {
window.document.location="index.php?ERROR=Failed%20Auth%20Key";
return;
}
const data = JSON.parse(xhr.responseText);
if (data.patronID != null) {
window.location.href='patronEdit.php?ID='+data.patronID;
} else {
displayNotification("error", "Barcode not found");
}
}
xhr.onerror = () => {
displayNotification("error", "Barcode not found");
}
xhr.open("GET", "patronFindCKO.php?bar=" + str, true);
xhr.send();
}
</script>
</head>
<body>
<div class="container-md mt-2">
<!-- page header -->
<?php loadHeader("main.php"); ?>
<h2>CHECKOUT: <span class="small text-secondary">Select Patron</span></h2>
<div class="row mt-4">
<div class="input-group">
<div class="col-12 col-md-7 me-2">
<input class="form-control rounded" style="border-color:#CCC;" autofocus="" type="text" onkeyup="dynamicData(this.value)" placeholder="Enter First Name, Last Name, or Patron phone number ..." >
</div>
<div class="col-12 col-md-5 col-lg-3 me-2">
<input class="form-control rounded" style="border-color:#CCC;" type="text" name="barcode" id="barcode" placeholder="Type Barcode, press ENTER">
<span class="smaller text-secondary"> Starts with 20748...</span>
</div>
</div>
</div>
<!-- ******** Anchor for Javascript and PHP notification popups ********** -->
<div id="notif_container"></div>
<?php if ($notify["message"] != "") echo "<script> displayNotification(\"{$notify['type']}\", \"{$notify['message']}\")</script>"; ?>
<!-- ********************************************************************* -->
<!-- IMPORTANT - Do not remove next line. It's where the table appears (also for error from barcode input)-->
<div id="dynTable" class="mt-4"></div>
</div>
</body>
</html>