-
Notifications
You must be signed in to change notification settings - Fork 0
/
patronViewCKO.php
235 lines (203 loc) · 8.47 KB
/
patronViewCKO.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
<?php
/*******************************************************
* patronViewCKO.php
*
* This is a modification of patronView. It is specifically for checkout, presenting a summary of the patron information
* and then proceeding to checkout or to modify the patron record.
*
* TODO: This page needs to be actually written properly. It's just a copy of patronEdit so far. It's not used yet. It will be used by a patron to view his/her own record
*
* called from patronFindCKO (by clicking on a patron)
********************************************************/
session_start();
require_once('common.php');
/********** Check permissions for page access ***********/
$allowed = array("ADMIN","STAFF","PATRON");
if (false === array_search($userdata['authlevel'],$allowed)) {
$_SESSION['notify'] = array("type"=>"info", "message"=>"You do not have permission to access this information - View Patron Info");
header("location:main.php");
exit;
}
/********************************************************/
# Check authorization (ie. that the user is logged in) or go back to login page
if (!isset($_SESSION["authkey"]) || $_SESSION["authkey"] != AUTHKEY) {
header("Location:index.php?ERROR=Failed%20Auth%20Key");
exit;
}
# Check user access level for the page (ie. Does the user have appropriate permissions to do this?)
$db = connectToDB();
$error_message = "";
if(isset($_SESSION["success_message"])) {
$success_message = $_SESSION["success_message"];
unset($_SESSION["success_message"]);
}
else $success_message = "";
$patronID = filter_var($_GET['ID'], FILTER_SANITIZE_NUMBER_INT);
$patronData = "";
$sql = "SELECT * FROM patron WHERE id = ?";
if ($stmt = $db->prepare($sql)) {
$stmt->bind_param("i", $patronID);
$stmt->execute();
$patronData = $stmt->get_result()->fetch_assoc();
$stmt->close();
} else {
die("Invalid query: " . mysqli_error($db) . "\n<br>SQL: $sql");
}
$postal = $patronData['postalCode'];
if (strlen($postal) ==6 ) {
$postal = substr($postal,0,3)." ".substr($postal,4);
}
//Assemble patron data
$patName = $patronData['lastname'].", ".$patronData['firstname'];
$patAddress = $patronData['address'].", ".$patronData['city'].", ".$patronData['prov'].". ".$postal;
$sql = "SELECT * FROM libraryCard WHERE patronID = ? ORDER BY expiryDate DESC";
if ($stmt = $db->prepare($sql)) {
$stmt->bind_param("i", $patronID);
$stmt->execute();
$libCards = $stmt->get_result(); //->fetch_assoc();
$stmt->close();
} else {
die("Invalid query: " . mysqli_error($db) . "\n<br>SQL: $sql");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?=$institution?> Library Database</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>
<style>
/* for Patron View page only */
#pageheader {background-color:#DDF;}
</style>
</head>
<body>
<div class="container-md mt-2">
<!-- Page header -->
<div id="pageheader" class="alert alert-primary text-center rounded py-3">
<a class="float-start btn btn-outline-dark rounded" onclick="history.back()"><i class="fa fa-arrow-left"></i> Back</a>
<a class="btn btn-outline-dark float-end" href="logout.php"><i class="fa fa-sign-out"></i> Logout</a>
<h2 class="fw-bold">The <?=$institution?> Public Libary</h2>
<br clear="both">
<hr class="py-0 mb-0">
</div>
<!-- end page header -->
<div class="card border-primary mt-3">
<div class="card-body">
<div class="card-head alert alert-primary pb-0">
<div class="float-end mt-n2">
<a href="patronEdit.php?ID=<?=$patronID?>"><button class="btn btn-outline-primary">Edit Patron Record</button></a></div>
<h4>Patron Information</h4>
</div>
<div class="border rounded"><!-- border around patron info -->
<div class="row">
<div class="col-sm-8 col-md-6 col-lg-4">
<div class="input-group rounded">
<label for="lastname" class="input-group-prepend btn btn-secondary">Name</label>
<input class="form-control bgS rounded-end" type="text" id="lastname" name="lastname" readonly value="<?=$patName?>">
</div>
</div>
<div class="col-sm-8 col-md-6 col-lg-4">
<div class="input-group rounded">
<label for="birthdate" class="input-group-prepend btn btn-secondary">Birth date</label>
<input class="form-control bgS rounded-end" type="date" id="birthdate" name="birthdate" readonly value="<?=$patronData['birthdate'] ?>"><span class="text-danger"></span>
</div>
</div>
<div class="text-secondary col-sm-4 text-end"> Date added: <?php echo strtok($patronData['createDate'], " ")?></div>
</div>
<div class="row my-2">
<div class="col-md-6">
<div class="input-group rounded">
<label for="address" class="input-group-prepend btn btn-secondary">Address</label>
<input class="form-control bgS rounded-end" type="text" id="address" name="address" readonly value="<?=$patAddress?>"><span class="text-danger"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-8 col-md-4">
<div class="input-group rounded">
<label for="phone" class="input-group-prepend btn btn-secondary"><b>Phone</b></label>
<input class="form-control bgS" type="text" id="phone" name="phone" readonly value="<?=$patronData['phone']?>">
</div>
</div>
<div class="col-sm-8 col-md-6 col-lg-5">
<div class="input-group rounded">
<label for="email" class="input-group-prepend btn btn-secondary"><b>Email</b></label>
<input class="form-control bgS" type="text" id="email" name="email" readonly value="<?=$patronData['email']?>">
</div>
</div>
</div>
</div>
<div class="card-head alert alert-primary mb-0 pb-0"> <h4>Library Cards</h4> </div>
<?php
$num_rows = mysqli_num_rows($libCards);
if($num_rows > 0) {
//general HTML now being written
echo '<table class="table table-secondary table-striped table-hover table-bordered mb-0">';
echo '<thead>';
echo '<tr>';
echo '<th>Barcode</th>';
echo '<th>Status</th>';
echo '<th>Date Issued</th>';
echo '<th>Expiry Date</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
// printing table rows: student name, student number
while ($row = $libCards->fetch_assoc()){
echo "<tr>";
echo "<td>".$row['barcode']. "</td>";
echo "<td>".$row['status']. "</td>";
echo "<td>".strtok($row['createDate']," "). "</td>";
echo "<td>".$row['expiryDate']. "</td>";
echo "</tr>";
}
echo '</tbody>';
echo '</table>';
}
?>
</div></div> <!-- end of card-body and card -->
<div class="card border-secondary mt-3">
<div class="card-body">
<div class="card-head alert alert-success mb-0 pb-0"> <h4>Checkout Book</h4> </div>
<form id="form" action="<?php echo $_SERVER["PHP_SELF"];?>" method="GET">
<div class="row mt-4">
<div class="col-12 col-sm-9 col-md-6 col-lg-3 me-2">
<input class="form-control rounded" style="border-color:#CCC;" type="text" name="barcode" id="barcode" placeholder="Scan/Type Barcode, press ENTER" autofocus>
<span class="smaller text-secondary"> Starts with 30748...</span>
</div>
</div>
</form>
<div class="row mt-4">
<div class="col-12 col-md-7 me-2">
<div class="input-group">
<span style="display: block; padding: .375rem .75rem;">OR </span>
<input class="form-control rounded" style="border-color:#CCC;" autofocus="" type="text" onkeyup="dynamicData(this.value)" placeholder="Search by Title/Author" >
</div>
</div>
</div>
<p>
<a href="checkout2.php"><button class="btn btn-success">Checkout book</button></a>
</p>
</div></div> <!-- end of card-body and card -->
<!-- ******** 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>
<br><br><br>
</body>
</html>