-
Notifications
You must be signed in to change notification settings - Fork 1
/
issuebook.php
349 lines (312 loc) · 11.1 KB
/
issuebook.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
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/********************************
* File Name: issuebook.php *
* Author: Tariq M.T.H *
* Output: Form to issue book *
********************************/
require('config.php');
require(WEBSITE_PATH.'./includes/db_connection.php');
require(WEBSITE_PATH.'./includes/session.php');
include(WEBSITE_PATH.'./includes/header.php');
include(WEBSITE_PATH.'./includes/logo.php');
include(WEBSITE_PATH.'./includes/menu.php');
// Issue Book
if (isset($_POST['book-issue-form']))
{
$select = "SELECT * FROM `tblissuedbooksdetail` WHERE user_id={$_POST['user_name']} AND return_status=3;";
$result = $conn->query($select);
if ($result && $result->num_rows > 1){
$row = $result->fetch_assoc();
$id = $row['id'];
$user_id = $row['user_id'];
$book_id = $row['book_id'];
$issue_date = trim($_POST['issue_date']);
$due_date = trim($_POST['due_date']);
}else{
$book_id = trim($_POST['book_name']);
$user_id = trim($_POST['user_name']);
$issue_date = trim($_POST['issue_date']);
if (isset($issue_date) && empty(trim($_POST['due_date']))){
$due_date = GetDueDate($issue_date);
}else{
$due_date = trim($_POST['due_date']);
}
}
//Return Book
if (isset($_POST['id']) && $_POST['id']!="")
{
//fine calculation
$damagedpage = $_POST['damagedpage'];
$extra = $_POST['extra'];
$fine_per_extra = $_POST['fine_per_extra'];
$damagepage_fine = GetDamagePageFine($damagedpage);
$extra_fine = GetExtraFine($extra, $fine_per_extra);
$day_fine = GetDayFine($due_date);
$fine = $damagepage_fine + $extra_fine + $day_fine;
$id = $_POST['id'];
$return_date = trim($_POST['return_date']);
$return_status = trim($_POST['return_status']);
$comments = trim($_POST['comments']);
//Return Book Query
$sql_update ="UPDATE `tblissuedbooksdetail`
SET `book_id` ={$book_id},
`user_id` ={$user_id},
`issue_date` ='{$issue_date}',
`due_date` ='{$due_date}',
`return_date` = now(),
`return_status` ={$return_status},
`day_fine` ={$day_fine},
`damagepage_fine` ={$damagepage_fine},
`extra_fine` ={$extra_fine},
`total_fine` ={$fine},
`comments` ='{$comments}'
WHERE id ={$id}";
}
//Issue Book Query
if (!empty($issue_date) && !empty($user_id) && !empty($book_id)){
$sql_insert = "INSERT INTO `tblissuedbooksdetail`(
`book_id`,
`user_id`,
`issue_date`,
`due_date`
)
VALUES(
{$book_id},
{$user_id},
now(),
'{$due_date}'
)";
}
$result=false;
$value = IsBookAvailable($conn, $book_id,$user_id);
$user = IsUserAvailable($conn,$user_id);
if (isset($_POST['id']) && !empty($_POST['id'])) {
//$result= $conn->query($sql_update);
}
if ($user && $value && empty($_POST['id'])) {
//$result= $conn->query($sql_insert);
}
if (isset($result) && !empty($sql_insert) && empty($sql_update) && !empty($value) && !empty($user))
{
$msg = "<div class='alert alert-success text-capitalize'>";
$msg .= " <b><u>Book Issued Successfully</u></b>,";
$msg .= " To view <b>Total Books Returned</b> click/tap <a href='issuedbooks_list.php?action=returned'>HERE</a>," ;
$msg .= " if you want To view <b>Total Books Issued</b> click/tap <a href='issuedbooks_list.php?action=issued'>HERE</a> or" ;
$msg .= " if you want To view <b>Total Books Issued & Returned</b> click/tap <a href='issuedbooks_list.php'>HERE</a>.";
$msg .= "</div>";
$result= $conn->query($sql_insert);
}elseif (isset($result) && isset($sql_update))
{
$msg = "<div class='alert alert-success text-capitalize'>";
$msg .= " <b><u>Book returned Successfully</u></b>,";
$msg .= " To view <b>Total Books Returned</b> click/tap <a href='issuedbooks_list.php?action=returned'>HERE</a>," ;
$msg .= " if you want To view <b>Total Books Issued</b> click/tap <a href='issuedbooks_list.php?action=issued'>HERE</a> or" ;
$msg .= " if you want To view <b>Total Books Issued & Returned</b> click/tap <a href='issuedbooks_list.php'>HERE</a>.";
$msg .= "</div>";
$result= $conn->query($sql_update);
}else{
$msg = "<div class='alert alert-danger text-capitalize'>Errors occured/Book not available/User not available/Issue date cannot be empty.</div>";
}
}
$id = '';
$book_name = '';
$user_id = '';
$issue_date = '';
$due_date = '';
$return_date = '';
$return_status = '';
$damagepage_fine = '';
$day_fine = '';
$extra_fine = '';
$fine = '';
$comments = '';
if (isset($_GET['id']))
{
$select = "SELECT * FROM `tblissuedbooksdetail` WHERE id={$_GET['id']}";
$result = $conn->query($select);
if ($result && $result->num_rows > 0){
$row = $result->fetch_assoc();
$id = $row['id'];
$user_id = $row['user_id'];
$book_id = $row['book_id'];
$issue_date = $row['issue_date'];
$due_date = $row['due_date'];
$return_date = $row['return_date'];
$return_status = $row['return_status'];
$damagepage_fine = $row['damagepage_fine'];
$day_fine = $row['day_fine'];
$extra_fine = $row['extra_fine'];
$fine = $row['total_fine'];
$comments = $row['comments'];
};
}
if (isset($_GET['action'])) {
$action = $_GET['action'];
}else{
$action = '';
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
}else{
$id = '';
}
if (isset($_GET['action']) && isset($_GET['id'])) {
$action = $_GET['action'];
$id= $_GET['id'];
$sql= "SELECT * FROM tblissuedbooksdetail WHERE id={$id}";
$result = $conn->query($sql);
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
$id = $row['id'];
$user_id = $row['user_id'];
$book_id = $row['book_id'];
$issue_date = $row['issue_date'];
$due_date = $row['due_date'];
$return_date = $row['return_date'];
$return_status = $row['return_status'];
$damagepage_fine = $row['damagepage_fine'];
$day_fine = $row['day_fine'];
$extra_fine = $row['extra_fine'];
$fine = $row['total_fine'];
$comments = $row['comments'];
}
}
if (isset($msg))
{
echo $msg;
}
?>
<?php
if (!IfIsUser($conn) && $_SESSION['user_name']) {
?>
<section id="content">
<div class="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col">
<h4>
<?php if (isset($_GET['id'])) { echo "Return Book"; }else{ echo "Issue Book" ; } ?><hr/>
</h4>
</div>
</div>
<div class="row">
<div class="col-12">
<!--Book Issue Form-->
<form name="book-issue-form" method="post" class="form">
<br />
<input type="hidden" name="book-issue-form" value="book-issue-form" />
<input type="hidden" name="id" value="<?php echo $id;?>" />
<?php if (isset($_GET['id'])) { ?>
<span class="f-img fa fa-recycle fa-5x"></span>
<?php }else{ ?>
<span class="f-img display-1 glyphicon glyphicon-list-alt"></span>
<?php } ?>
<h2>Book</h2>
<small>
<?php if ($_GET) { echo "Return Form"; }else{ echo "Issue Form"; } ?>
</small>
<p class="labelenglish"><b>Book Name:</b></p>
<select id="book_name" name="book_name" class="blank form-control-lg" required>
<?php
$book_name = GetBooks($conn);
foreach ($book_name as $row) {
$is_selected ="";
if($row['id'] == $book_id)
{
$is_selected ="selected";
}
echo "<option {$is_selected} value='{$row['id']}'>{$row['book_name']}</option>";
}
?>
</select>
<p class="labelenglish"><b>User Name:</b></p>
<select id="user_name" name="user_name" class="blank form-control-lg" required>
<?php
$user_name = GetUsers($conn);
foreach ($user_name as $row) {
$is_selected ="";
if($row['id'] == $user_id)
{
$is_selected ="selected";
}
echo "<option {$is_selected} value='{$row['id']}'>{$row['full_name']}</option>";
}
?>
</select>
<p class="labelenglish"><b>Issue Date:</b></p>
<?php
if (empty($issue_date)){
$issue_date = "";
}else{
$issue_date = date("Y-m-d",strtotime($issue_date));
}
?>
<input type="date" value="<?php echo $issue_date; ?>" name="issue_date" class="blank" />
<p class="labelenglish"><b>Due Date:</b></p>
<?php
if (empty($due_date)){
$due_date = "";
}else{
$due_date = date("Y-m-d",strtotime($due_date));
}
?>
<input type="date" value="<?php echo $due_date; ?>" name="due_date" class="blank" />
<?php
if (isset($_GET['id'])){
?>
<p class="labelenglish"><b>Return Date:</b></p>
<?php
if (empty($return_date)){
$return_date = "";
}else{
$return_date = date("Y-m-d",strtotime($return_date));
}
?>
<input type="date" value="<?php echo $return_date; ?>" name="return_date" class="blank" />
<p class="labelenglish"><b>Return Status:</b></p>
<select id="return_status" name="return_status" class="blank form-control-lg" value="<?php echo $return_status; ?>" required>
<option value="<?php echo 0; ?>">Issued</option>
<option value="<?php echo 1; ?>">Returned</option>
<option value="<?php echo 2; ?>">Right Off/Lost</option>
<option value="<?php echo 3; ?>" hidden>Requested</option>
</select>
<div>
<?php if (!IfIsUser($conn) && isset($id) && empty($action)) { ?>
<p class="labelenglish"><b>Total Fine:</b></p>
<input type="number" value="<?php if(!empty($fine)){echo $fine;}else{echo GetDayFine($due_date);}?>" name="fine" class="blank" readonly/>
<a class="btn btn-outline-danger bg-dark btn-md blank" href="<?php echo WEBSITE_URL. './issuebook.php?action=fine_calculator.php&id='.$id;?>" role="button">Fine Calculator</a>
<?php }elseif(!IfIsUser($conn) && isset($_GET['action'])){ ?>
<!--Fine Calculator-->
<?php include(WEBSITE_PATH.'./includes/fine_calculator.php');?>
<?php } ?>
</div>
<p class="labelenglish"><b>Comments:</b></p>
<textarea name="comments" class="blank" value="" rows="5" placeholder="Details about fine..."><?php echo $comments; ?></textarea>
<br />
<?php } ?>
<div class="">
<input type="reset" name="reset" value="Reset" class="btn btn-success"/>
<?php
if (isset($_GET['id'])) {
echo "<input type='submit' name='submit' value='Return' class='btn btn-success' />";
}
else{
echo "<input type='submit' name='submit' value='Issue' class='btn btn-success' />";
}
?>
</div>
<br />
</form>
</div>
</div>
</div>
</div>
</section>
<?php
}else{ echo "<div class='alert alert-danger'>Access Denied!</div>"; }
?>
</div>
</div>
<?php
include(WEBSITE_PATH.'./includes/footer.php');
?>