Skip to content

Commit d3d2131

Browse files
fixing the borrow book logic
1 parent 888a3b5 commit d3d2131

6 files changed

+77
-131
lines changed

bookcopy.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
include('config.php');
44
if(isset($_REQUEST['accNo'])){
5-
$accNo=$_REQUEST['accNo'];
6-
7-
$q="select * from books where accNo=$accNo";
5+
$accNo= explode("-", $_REQUEST['accNo']);
6+
$book_id = $accNo[0];
7+
$branch_id = $accNo[1];
8+
$q="SELECT * from book_copies where book_id=$book_id and branch_id = $branch_id";
89
$q_re=mysql_query($q);
9-
$qw=mysql_fetch_array($q_re);
10-
if($qw['bookcopies']==0){ ?>
11-
<input readonly="readonly" name="copy" type="text" id="get" value="
10+
$qw=mysql_fetch_array($q_re);
11+
if($qw['no_of_copies']=="0"){ ?>
12+
<input readonly="readonly" name="copy" type="text" id="get" value="0
1213
" style="padding:4px; width:65px;">
13-
14+
1415
<?php }
1516
else{?>
16-
<input readonly="readonly" name="copy" type="text" id="get" value="<?php echo $qw['bookcopies']; ?>" style="padding:4px; width:65px;">
17+
<input readonly="readonly" name="copy" type="text" id="get" value="<?php echo $qw['no_of_copies']; ?>" style="padding:4px; width:65px;">
1718
<?php } }?>

borrowBooks.php

+38-86
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
$(document).ready(function(){
5555

56-
$(".search").keyup(function()
56+
$(".search").keyup(function()
5757
{
5858
var searchbox = $(this).val();
5959
var dataString = 'searchword='+ searchbox;
@@ -72,7 +72,7 @@
7272
$("#display").html(h).hide();
7373
}});
7474

75-
75+
7676
}
7777
else
7878
{
@@ -89,7 +89,7 @@
8989
}});
9090

9191

92-
}return false;
92+
}return false;
9393

9494

9595
});
@@ -98,9 +98,9 @@
9898
jQuery(function($){
9999
$("#searchbox").Watermark("Search StudentID, Name");
100100
});
101-
102-
103-
101+
102+
103+
104104
</script>
105105
<script language="javascript" type="text/javascript">
106106
function timing()
@@ -153,7 +153,7 @@ function timing()
153153
<div style=" margin-left:7px; margin-top:13px; color:#030; font-size:15px; font-family:Verdana, Geneva, sans-serif; font-weight:bold;float:left">Error</div>
154154
</div>
155155

156-
<div style="font-size:15px; padding-top:40px; margin-left:20px; margin-right:20px; font-family:Arial, Helvetica, sans-serif; text-align:center">Tulo sa ang limit karun
156+
<div style="font-size:15px; padding-top:40px; margin-left:20px; margin-right:20px; font-family:Arial, Helvetica, sans-serif; text-align:center">You cannot issue more books.
157157
</div>
158158

159159
<div class="btnbox" id="closeerror">
@@ -199,7 +199,7 @@ function timing()
199199
.dewey{
200200
font-size:20px;
201201
font-family:Arial, Helvetica, sans-serif;
202-
202+
203203
font-weight:bold;}
204204
hr{
205205
background:#999;
@@ -253,7 +253,7 @@ function timing()
253253
$get=mysql_fetch_array($rs);
254254

255255
} ?>
256-
256+
257257
<table width="420" border="0" style="font-size:12px; font-family:Arial, 'Arial Black', 'Arial Narrow'; font-weight:bold;border:1px inset #999; margin-top:5px; margin-left:20px; float:left;">
258258
</tr>
259259
<tr><td>Name</td><td>Card No.</td>
@@ -267,47 +267,12 @@ function timing()
267267
</tr>
268268
</table>
269269
<table border="0" wi style="font-size:12px; font-family:Arial, 'Arial Black', 'Arial Narrow'; font-weight:bold; border:inset #999 1px;width: 420px; margin-top:10px; margin-bottom:20px; float:left; margin-left:20px;">
270-
<tr><td colspan="3">Book ID</td></tr>
270+
<tr><td colspan="3">Search Book</td></tr>
271271
<tr>
272272
<td colspan="3">
273-
<select
274-
<?php if(isset($_GET['card_no'])) {?>
275-
<?php }else{ ?> disabled="disabled"<?php } ?> name="classID" style=" padding:4px;" class="com" onChange="display(this.value)">
276-
<option ></option>
277-
<?php if(isset($_GET['book_id'])){
278-
$res=mysql_query("select b.book_id, title, author_name from book b JOIN book_authors ba ON b.book_id = ba.book_id where b.book_id=$_GET[book_id]");
279-
$r=mysql_fetch_array($res);
280-
281-
} ?>
282-
283-
<?php
284-
285-
include('config.php');
286-
$sql="SELECT * FROM bookclass";
287-
$rs=mysql_query($sql);
288-
$class=0;
289-
290-
while($row=mysql_fetch_array($rs)){
291-
$class++;
292-
?>
293-
<option
294-
<?php
295-
if($r['bookclass']==$row['classid']){
296-
echo 'selected="selected"';
297-
}else{}
298-
?>
299-
value="<?php
300-
echo $row['classid'];?>">
301-
<?php
302-
303-
echo $row['classid']."&nbsp;".$row['classname'];
304-
305-
?>
306-
</option>
307-
<?php
308-
}
309-
?>
310-
</select>
273+
<input
274+
<?php if(isset($_GET['card_no'])) { ?>
275+
<?php }else{ ?> disabled="disabled"<?php } ?> name="classID" style=" padding:4px;" class="com" onChange="display(this.value)" />
311276

312277
</td>
313278
</tr>
@@ -356,8 +321,8 @@ function timing()
356321
year += 1900
357322
}
358323

359-
var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
360-
324+
var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
325+
361326
var dayArray = new Array("Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday")
362327

363328
document.write( dayArray[day] + ", " + monthArray[month] + " " + date + ", " + year )
@@ -422,23 +387,18 @@ function OpenPopUp(borrowid, pageURL, title,w,h) {
422387
var targetWin = window.open('http://localhost/lib/default.php' + borrowid, 'name', 'location=no,menubar=no,wiscrollbars=no,resizable=no,fullscreen=no,width='+w+', height='+h+', top='+top+', left='+left);
423388
return false;
424389
}
425-
390+
426391

427392
</script>
428393
<script type="text/javascript">
429-
var auto_refresh = setInterval(
430-
function ()
431-
{
432-
$('#ass').load('loadpay.php').fadeIn("slow");
433-
}, 1000); // refresh every 10000 milliseconds
434394

435395
</script>
436396
<span id="ass"></span>
437397

438398
</td>
439399
<td class="value" align="center" style="width:25px;">
440400
<div id="id" title="Change default value">
441-
<a href="" style="margin-right:10px;" id=""
401+
<a href="" style="margin-right:10px;" id=""
442402
onclick="OpenPopUp(id,'','',300,100);" class='trnone'>
443403

444404
<img src="icons/b_edit.png" />
@@ -463,22 +423,23 @@ function ()
463423
$bday = $_POST['bday'];
464424
$byear = $_POST['byear'];
465425
$duedate = $byear.'-'.$bmonth.'-'.$bday.'-'.date('H:i:s');
466-
467-
426+
427+
468428
$classid=$_POST['classID'];
469-
$accNo=$_POST['bookid'];
429+
$accNo= explode("-", $_POST['bookid'])[0];
430+
$branch_id = explode("-", $_POST['bookid'])[1];
470431
$studentid=$_POST['studentid'];
471432
$dateborrow=$_POST['dateborrow'];
472433
$date=$_POST['ed'];
473434
$copy=$_POST['copy'];
474435
$theDate = isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : "";
475436
$mydate= $theDate.'-'.date("H:i:s");
476-
437+
477438
$copies=$_POST['copies'];
478439
if(isset($_POST['borrow']))
479440
{
480441
include('config.php');
481-
$strSQL = "SELECT * FROM tblborrow WHERE studentid = '$studentid' and status='Unsigned' ";
442+
$strSQL = "SELECT * FROM book_loans WHERE card_no = '$studentid' and date_in = '0000-00-00' ";
482443
$objExec = mysql_query($strSQL);
483444
$count=0;
484445
while($row=mysql_fetch_array($objExec)){
@@ -492,7 +453,7 @@ function ()
492453
});
493454
</script>
494455

495-
<?php //echo "<div class='error'>tulo ra limit bai</div>";
456+
<?php echo "<div class='error'>You cannot issue more books.</div>";
496457
}
497458
elseif(empty($classid)){?>
498459
<script>
@@ -509,66 +470,57 @@ function ()
509470
</script>
510471
<?php }
511472
else{
512-
$strSQL = "SELECT * FROM tblborrow WHERE accNo = '$accNo' and studentid = '$studentid' and status='Unsigned' ";
473+
$strSQL = "SELECT * FROM book_loans WHERE book_id = '$accNo' and card_no = '$studentid' and branch_id = $branch_id and date_in = '0000-00-00' ";
513474
$objExec = mysql_query($strSQL);
514-
$row=mysql_fetch_array($objExec);
475+
$row=mysql_fetch_array($objExec);
515476
if($row){ ?>
516477
<script>
517478
$(document).ready(function(){
518479
$("#error2").fadeIn(1000);
519480
});
520481
</script>
521-
<?php //echo "<div class='error'>You can borrow only one type of books</div>";
482+
<?php echo "<div class='error'>You can borrow only one type of books</div>";
522483
}
523484
else{
524-
$sql="insert into tblborrow (accNo,classid,studentid,dateborrow,duedate,datereturn,status,amount,item) values(
485+
$sql="insert into book_loans (book_id,branch_id,card_no,date_out,due_date,date_in) values(
525486
'".$accNo."',
526-
'".$classid."',
487+
'".$branch_id."',
527488
'".$studentid."',
528489
'".date('Y-m-d H:i:s')."',
529490
'".$mydate."',
530-
'".$date."',
531-
'Unsigned',
532-
'".$_POST['pay']."',
533-
'1'
534-
491+
'0000-00-00'
535492
)";
536-
537493
$rs_update=mysql_query($sql);
538494
if($rs_update){
539495

540496

541-
$upd="select * from books where accNo='".$_GET['accNo']."'";
497+
$upd="select * from book_copies where book_id='".$_GET['accNo']."'";
542498
$obj = mysql_query($upd);
543499
$cop=mysql_fetch_array($obj);
544500

545501
if(isset($_GET['accNo'])){
546-
547-
$get=$cop['bookcopies']-1;
502+
503+
$get=$cop['no_of_copies']-1;
548504
}else{
549505

550506
$get=$copy-1;
551507
}
552-
553-
$update="update books set bookcopies='$get' where accNo='$accNo'";
508+
509+
$update="update book_copies set no_of_copies='$get' where book_id='$accNo'";
554510
$objExec = mysql_query($update);
555511
if($objExec){
556-
$up="update tblborrower set status='1' where studentid='$studentid'";
557-
$obj = mysql_query($up);
558-
$updateres="update tblbookreserve set status='0' where accNo='$accNo'";
559-
$objExec = mysql_query($updateres);
560512
?>
561513

562514
<script>
563515
$(document).ready(function(){
564516
$("#success").fadeIn(1000);
565517
});
566518
</script>
567-
<?php
519+
<?php
568520
//echo "Your Borrow has been Registered";
569521
}
570-
571-
522+
523+
572524
}
573525
}
574526
}

displaydewycat.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<?php
99

1010
$classid=$_REQUEST['classid'];
11-
$query="select * from books where bookclass='$classid' and status='1'";
11+
$q = $classid;
12+
$query="SELECT b.book_id, title, no_of_copies, bc.branch_id, branch_name FROM book b INNER JOIN book_copies bc ON b.book_id = bc.book_id INNER JOIN library_branch lb ON lb.branch_id = bc.branch_id RIGHT JOIN book_authors ba ON b.book_id = ba.book_id where
13+
b.book_id like '%$q%' or title like '%$q%' or author_name like '%$q%' ";
1214

1315
?>
1416

@@ -19,16 +21,16 @@
1921

2022
while($row=mysql_fetch_array($query_result))
2123
{
22-
24+
2325
?>
2426

2527
<option <?php
26-
if($row['bookcopies']==0){ ?> title="not available"
27-
disabled="disabled"
28+
if($row['no_of_copies']=="0"){ ?> title="not available"
29+
disabled="disabled"
2830
<?php } else{?> <?php } ?>
29-
30-
value="<?php echo $row['accNo']; ?>" title="<?php echo $row['bookcopies']."&nbsp;"."Books Available"; ?>">
31-
<?php echo $row['booktitle']; ?></option>
31+
32+
value="<?php echo "{$row['book_id']}-{$row['branch_id']}"; ?>" title="<?php echo $row['no_of_copies']."&nbsp;"."Books Available"; ?>">
33+
<?php echo "{$row['title']} - {$row['branch_name']}"; ?></option>
3234
<?php
3335
}
3436

loadpay.php

-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
<?php
2-
include('config.php');
3-
$sql="SELECT * FROM tblpayment";
4-
$rs=mysql_query($sql);
5-
6-
7-
$rowpay=mysql_fetch_array($rs);
8-
?>
9-
<input id="pay" align="center" name="pay" value="<?php echo $rowpay['amount']; ?>" type="text" style="width:155px; padding:4px" size="8">

0 commit comments

Comments
 (0)