├── README.md
├── SQL Schema Creation Cmds
├── SQL Table Import Scripts
└── book.java
└── src
├── Book_Search.php
├── Checkin_Books.php
├── Checkin_date.php
├── Checkout_Books.php
├── Create_New_Borrower.php
├── Fine_Management.php
├── Fine_Paid.php
├── Home.php
├── Individual_Fine.php
├── Pay_Fine.php
├── book_search.jpg
└── lib_pic.jpg
/README.md:
--------------------------------------------------------------------------------
1 | # Library-Management-System
2 | Library Management System allows users to easily search for a book, checkout a book, check-in a book, Add new borrowers to the system and computes fine for the borrowed books. Above all it authenticates the librarian to the library database system to prevent any kind of misuse of the system.
3 |
4 | Following is a brief description about the working of the system:-
5 |
6 | - Homepage - Authenticates the librarian, if failed no activity can be performed on the system.
7 |
8 | - Search a Book - Allows the user to search any book given any combination of Book id and/or Book Title and /or Book Author. This provides flexibility to the librarians in searching the book in any order.
9 |
10 | - Checkout a Book – Allows a user to check-out the book from a branch based on its availability and book borrowers credibility. Checkout is restricted for all borrowers who have exceeded 3 book loans or have any past fines due on them.
11 |
12 | - Checkin a Book - Allows a user to check-in the book. This feature first searches for all the book loans the borrower has taken which are not checked-in yet and then allows the user to check in the selected the book. It also intimates the user if the borrower has any fine due on that book.
13 |
14 | - Add New Borrower - Allows the user to add a new borrower to the library loan system. The system generates a unique card no for each borrower. Uniqueness is defined based on the first name, last name and address details of a borrower.
15 |
16 | - Compute Fine - This feature allows two types of fine computation. First – Computes the fine for all the borrowers who have taken a book loan. Second – Computes the fine for an individual book borrower who has taken a book loan.
17 |
18 | -----------------------------------------------------------------------------------------------------------------------------
19 | Design Decisions and Justifications:-
20 | -----------------------------------------------------------------------------------------------------------------------------
21 |
22 | I have added an additional feature in Library Management System to authenticate the users, making it secure for any database break-in attacks. This feature authenticates user’s based on their database credentials.
23 |
24 | Also while checking in a book, if no of books borrowed is more than 3(i.e. no of book loans >3) then the system rejects the checkin request. As this exceeds the maximum capacity of book loans permitted to a borrower.
25 |
26 | On the more I thought it’s good to intimate a user about the fine he/she has incurred while the borrower is trying to check-in the book. So if the user is doing a check-in after the due date, he/she is intimated about the fine, and if willing then the borrower can pay the fine after the book is checked in or pay later.
27 |
28 | Above all a user can search for individual book borrower based on their card no and /or cardholder’s name. Note: Fine is computed $0.25 per day starting from the due date till the date the book is checked in.
29 |
30 | -----------------------------------------------------------------------------------------------------------------------------
31 | Technical Dependencies:-
32 | -----------------------------------------------------------------------------------------------------------------------------
33 | * Source Code :- PHP v 5.3
34 | * Database :- Mysql v5.6.21
35 | * Operating System :- Windows/Mac/Linux
36 | * Browser to run the webpage:- Google Chrome / Mozilla Firefox
37 |
--------------------------------------------------------------------------------
/SQL Schema Creation Cmds:
--------------------------------------------------------------------------------
1 |
2 | C:\Users\cooltwin>mysql -h localhost -u root -p
3 | Enter password: xxxxxxxxx
4 |
5 | mysql> create database Library_Management_System;
6 | Query OK, 1 row affected (0.00 sec)
7 |
8 | mysql> use Library_Management_System;
9 | Database changed
10 |
11 | BOOK TABLE:-
12 |
13 | mysql> create table BOOK (Book_id char(10) not null, Title varchar(200) not null, Constraint pk_Book primary key(Book_id));
14 | Query OK, 0 rows affected (0.28 sec)
15 |
16 | mysql> source C:\Users\cooltwin\Desktop\database\db project\sql_book.sql
17 |
18 | LIBRARY_BRANCH TABLE :-
19 |
20 | mysql> create table LIBRARY_BRANCH (Branch_id int not null auto_increment, Branch_name varchar(100) not null, Address varchar(500), Constrait pk_Library_branch primary key(Branch_id), Constraint uk_Library_branch unique(Branch_name), Constraint uk_Lib_branch unique (Address));
21 | Query OK, 0 rows affected (0.28 sec)
22 |
23 | mysql> source C:\Users\cooltwin\Desktop\database\db project\sql_library_branch.sql
24 | Query OK, 1 row affected (0.03 sec)
25 | Query OK, 1 row affected (0.04 sec)
26 | Query OK, 1 row affected (0.06 sec)
27 | Query OK, 1 row affected (0.07 sec)
28 | Query OK, 1 row affected (0.03 sec)
29 |
30 | BOOK_COPIES TABLE:-
31 |
32 | mysql> create table BOOK_COPIES (Book_id char(10) not null, Branch_id int not null, No_of_copies int not null, Constraint pk_book_copies primary key(Book_id,Branch_id), Constraint fk_book_copies_bookid foreign key (Book_id) references BOOK(Book_id) on delete cascade on update cascade, Constraint fk_book_copies_branchid foreign key (Branch_id) references LIBRARY_BRANCH (Branch_id) on delete cascade on update cascade);
33 | Query OK, 0 rows affected (0.37 sec)
34 |
35 | mysql> source C:\Users\cooltwin\Desktop\database\db project\sql_book_copies.sql
36 |
37 |
38 | BORROWER TABLE:-
39 |
40 | mysql> create table borrower(Card_no int not null auto_increment, Fname varchar(20) not null, Lname varchar(30) not null, Add
41 | ress varchar(200) not null, Phone char(14) not null, constraint pk_borrower PRIMARY KEY(Card_no), constraint uk_borrower_card
42 | holder UNIQUE KEY(Fname, Lname, Address));
43 | Query OK, 0 rows affected (0.27 sec)
44 |
45 | mysql> source C:\Users\cooltwin\Desktop\database\db project\sql_borrower.sql
46 |
47 | mysql> alter table borrower modify column Phone null;
48 |
49 | BOOK_AUTHORS TABLE:-
50 |
51 | mysql> create table BOOK_AUTHORS(Book_id char(10) not null, Author_name varchar(200) not null, Type int not null, Constraint
52 | pk_book_authors PRIMARY KEY(Book_id, Author_name), Constraint fk_book_authors FOREIGN KEY(Book_id) references book(Book_id) o
53 | n delete cascade on update cascade);
54 | Query OK, 0 rows affected (0.29 sec)
55 |
56 | mysql> source C:\Users\cooltwin\Desktop\database\db project\sql_book_authors.sql
57 |
58 | BOOK_LOANS TABLE:-
59 |
60 | mysql> create table BOOK_LOANS (Loan_id int not null auto_increment, Book_id char(10) not null, Branch_id int not null, Card_no int not null,Date_out date not null,Due_date date not null, Date_in date,Constraint pk_book_loans primary key(Loan_id), Constraint fk_book_loans_bookid foreign key (Book_id) references BOOK(Book_id) on delete cascade on update cascade, Constraint fk_book_loans_branchid foreign key (Branch_id) references LIBRARY_BRANCH (Branch_id) on delete cascade on update cascade, Constraint fk_book_loans_cardno FOREIGN KEY(Card_no) references BORROWER(Card_no) on delete cascade on update cascade);
61 |
62 | mysql> source C:\Users\cooltwin\Desktop\database\db project\sql_book_loans.sql
63 |
64 | mysql> alter table book_loans auto_increment =12;
65 |
66 | FINES TABLE :-
67 |
68 | mysql> create table FINES (Loan_id int not null, Fine_amt numeric(6,2) not null, Paid boolean not null,Constraint pk_fines pr
69 | imary key(Loan_id), Constraint fk_fines_loanid foreign key (Loan_id) references BOOK_LOANS(Loan_id) on delete cascade on update cascade);
70 |
71 | mysql> source C:\Users\cooltwin\Desktop\database\db project\sql_fines.sql
72 |
73 |
--------------------------------------------------------------------------------
/SQL Table Import Scripts/book.java:
--------------------------------------------------------------------------------
1 | package db;
2 |
3 | import java.io.*;
4 | import java.util.*;
5 |
6 | public class book {
7 | public static void main(String args[]){
8 | String currentLine, field[];
9 | field = new String[3];
10 | try {
11 | File sqlFile = new File("C:\\Users\\cooltwin\\Desktop\\database\\db project\\sql_book.sql");
12 | sqlFile.getParentFile().mkdirs();
13 | PrintWriter writer1 = new PrintWriter(sqlFile);
14 | File csvFile = new File("C:\\Users\\cooltwin\\Desktop\\database\\db project\\SQL_library_project_data\\books_authors.csv");
15 | csvFile.getParentFile().mkdirs();
16 | Scanner scanner = new Scanner(csvFile);
17 | while(scanner.hasNextLine()) {
18 | currentLine = scanner.nextLine();
19 | field = currentLine.split("\t");
20 | writer1.println("INSERT INTO BOOK VALUES ('"+field[0]+"',\""+field[2]+"\");");
21 | }
22 | scanner.close();
23 | writer1.close();
24 | }catch(FileNotFoundException e) {
25 | System.out.println("file not found"+e);
26 | }
27 |
28 |
29 |
30 | }
31 |
32 | }
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/Book_Search.php:
--------------------------------------------------------------------------------
1 |
7 |
8 |
";
127 |
128 | // Checking query results in empty set, this means that either of the fields are wrongly entered
129 | if(!($row = mysql_fetch_array($result))){
130 | echo "Error!! Could not Search the book, No Such book exists";
131 | }
132 | //fetch tha data from the database
133 | while ($row = mysql_fetch_array($result)) {
134 | echo "
";
118 | $loan_id[$i] = $row3{'Loan_id'};
119 | $i++;
120 | }
121 | goto end; // if card holder already has taken 3 book loans, then stop the query
122 | }
123 | }
124 |
125 |
126 | //checking if borrower has any unpaid fines
127 | $result4 = mysql_query("SELECT SUM(Fine_amt) AS Total_Fine
128 | FROM FINES AS f, BOOK_LOANS AS l
129 | WHERE l.Card_no = $card_no AND l.Loan_id = f.loan_id AND Paid = 0;");
130 | if ($row4 = mysql_fetch_array($result4)) {
131 | if ($row4{'Total_Fine'} != NULL) {
132 | echo "Error !! Checkout failed, You have fine due of $" . $row4{'Total_Fine'} . " ";
133 | echo "Please first pay the fine and then try again to checkout the book ";
134 | goto end;
135 | }
136 | }
137 |
138 | //checking if the branch has sufficient copies of the book to given to the card holder
139 | $result5 = mysql_query("SELECT (c.No_of_copies - (IFNULL((SELECT COUNT(*) FROM BOOK_LOANS AS l
140 | WHERE c.Branch_id = l.Branch_id AND c.Book_id = l.Book_id GROUP BY Branch_id), 0))) AS
141 | No_of_copies_available
142 | FROM BOOK_COPIES AS c
143 | WHERE c.Book_id = $book_id AND c.Branch_id = $branch_id;");
144 | //fetch tha data from the database
145 | while ($row5 = mysql_fetch_array($result5)) {
146 | if ($row5{'No_of_copies_available'} == 0) {
147 | echo "Error!! Checkout failed, Sorry !! No Copies of this book is left in the library
148 | branch ";
149 | echo "Please check some other library branch ";
150 | goto end;
151 | }
152 | }
153 |
154 |
155 | // query satisfies all restrictions, so now creating a new tuple in database
156 | // Due_date is 14 days from date_out so its the 14th day so interval of 15 days from date_out
157 | $result6 = mysql_query("INSERT INTO BOOK_LOANS (Book_id, Branch_id, Card_no, Date_out, Due_date,
158 | Date_in) VALUES ('$book_id', $branch_id, $card_no,now(),DATE_ADD(now(),interval 15 day),
159 | '0000-00-00');");
160 | // Insertion will be successful if none of above happens
161 | echo "Checkout Successful !! Your book loan is successfully added to the database ";
162 | }
163 | end:
164 | $dbhandle->close();
165 | ?>
166 |
167 |
168 |
--------------------------------------------------------------------------------
/src/Create_New_Borrower.php:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
16 |
17 |
18 |
19 |
37 |
38 |
39 |
47 |
48 | 0 || $row1{'Date_in'} == '0000-00-00') {
84 | //book is returned after due date, charge fine
85 | //Fine Computation :-
86 |
87 | $current_date = time();
88 | $future_due_diff = $current_date - $due_date;
89 | $future_due = floor($future_due_diff / (60 * 60 * 24));
90 |
91 | if ($row1{'Date_in'} == '0000-00-00' && $future_due > 0) {
92 | // if book is not returned till today's date, and due date has passed
93 | $diff = $current_date - $due_date;
94 | } elseif ($row1{'Date_in'} != '0000-00-00') {
95 | // if book is returned but delayed from its due date
96 | $diff = $date_in - $due_date;
97 | } else {
98 | //if book is not returned till today, but due date has still not passed
99 | //do nothing
100 | $do_not_take_fine++;
101 | }
102 | $paid = 0;
103 | $date_diff = floor($diff / (60 * 60 * 24));
104 | $fine_amt = $date_diff * 0.25;
105 |
106 | $result2 = mysql_query("SELECT * FROM FINES WHERE Loan_id = $loan_id");
107 | // checking if this loan id is already there in fines table
108 | if ($row2 = mysql_fetch_array($result2)) {
109 | // Already paid the fine. do nothing
110 | // if not paid fine then update the fine table with new fine_amt
111 | if ($row2{'Paid'} == 0 && $do_not_take_fine == 0) {
112 | $result3 = mysql_query("UPDATE FINES SET Fine_amt = $fine_amt WHERE Loan_id = $loan_id");
113 | }
114 |
115 | } else {
116 | // this loan id is not present in fines table, it's a new entry, so use insert command
117 | if ($do_not_take_fine == 0)
118 | $result3 = mysql_query("INSERT INTO FINES VALUES($loan_id, $fine_amt, $paid);");
119 | }
120 | }
121 | // else Borrower has returned by the due date so no charge is to be fined on the borrower.
122 | }
123 | echo "
Fines table is updated successfully !!!";
124 | }
125 |
126 | $dbhandle->close();
127 | ?>
128 |
37 | 0){
121 | echo "Error!! You have not returned the book(s), You can't pay the fine now ";
122 | echo "Please return the book(s) and then try again, book(s) : ";
123 | $result3 = mysql_query("SELECT b.Title
124 | FROM BOOK AS b,BOOK_LOANS AS l
125 | WHERE l.Card_no = $borrower_card_no AND l.book_id = b.book_id;");
126 | while ($row3 = mysql_fetch_array($result3)) {
127 | echo "-- " . $row3{'Title'} . " ";
128 | }
129 | }
130 | else {
131 | //Borrower has returned all the books, he/she can be allowed to pay the fine
132 | echo "Good!! You have returned all the book(s)
";
133 | echo "You can now pay your fine
";
134 | echo "Your fine amt is $" . $fine_amt . "
154 | ";
160 | echo "1. You have not taken any book loan ";
161 | echo "2. You have entered wrong lname/fname/card_no ";
162 | echo "3. You have returned the book on time, i.e Good News !! You don't have any fine ";
163 | }
164 |
165 |
166 | $dbhandle->close();
167 | ?>
168 |