0% found this document useful (0 votes)
12 views

Project Code

Uploaded by

shahriarabu2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Project Code

Uploaded by

shahriarabu2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

#!

/bin/bash

# Define Constants
ENTER=13
TAB=9
BKSP=8

# Define Variables
passTerminator=1
bookStock=0
rentName=""
bookName=""

# Function Prototypes
menu() {
clear
echo "----------------------------------"
echo ">>> Library Management System <<<"
echo "----------------------------------"
echo "> 1. User Management Panel"
echo "> 2. Book Management Panel"
echo -n "> Enter the number & hit ENTER: "
read number
case $number in
1) userPanel ;;
2) bookPanel ;;
*) echo ">>> Invalid Input! <<<"
sleep 2
menu ;;
esac
}

userPanel() {
clear
echo "-----------------------------------------------"
echo ">>> Library Management System - User Panel <<<"
echo "-----------------------------------------------"
echo "> 1. Add User"
echo "> 2. Modify User"
echo "> 3. List User"
echo "> 4. List Rentals"
echo "> 5. Search User"
echo "> 6. Delete User"
echo "> 7. Open Main Menu"
echo "> 8. Close the Program..."
echo -n "> Enter the number & hit ENTER: "
read number
case $number in
1) addUser ;;
2) modifyUser ;;
3) listUser ;;
4) rentList ;;
5) searchUser 0 ;;
6) deleteUser ;;
7) menu ;;
😎 endScreen ;;
*) echo "Invalid Input!"
sleep 2
userPanel ;;
esac
}

bookPanel() {
clear
echo "-----------------------------------------------"
echo ">>> Library Management System - Book Panel <<<"
echo "-----------------------------------------------"
echo "> 1. Add Book"
echo "> 2. Modify Book"
echo "> 3. List Book"
echo "> 4. Rent Book"
echo "> 5. Search Book"
echo "> 6. Delete Book"
echo "> 7. Open Main Menu"
echo "> 8. Close the Program..."
echo -n "Enter the number & hit ENTER: "
read number
case $number in
1) addBook ;;
2) modifyBook 0 ;;
3) listBook ;;
4) rentBook ;;
5) searchBook 0 ;;
6) deleteBook ;;
7) menu ;;
😎 endScreen ;;
*) echo "Invalid Input!"
sleep 2
bookPanel ;;
esac
}

endScreen() {
clear
echo "----------------------------------------------"
echo ">>> Thank you <<<"
echo "----------------------------------------------"
exit 0
}

addUser() {
while true; do
clear
echo "Enter the First Name: "
read fname
echo "Enter the Last Name: "
read lname
echo "Enter Gender [M/F]: "
read gender
echo "Enter Student ID: "
read sid
echo "Enter Phone Number: "
read phone
echo "$fname $lname $gender $sid $phone" >> user_Records.txt
echo ">>> User Record Added Successfully <<<"
echo -n "Do you wanna enter more records [y/N]: "
read input
if [[ $input != "y" && $input != "Y" ]]; then
echo "Redirecting to User Panel."
sleep 2
userPanel
fi
done
}

modifyUser() {
clear
echo "Enter the name of the person you want to modify the detail: "
read find
flag=0
touch temporary.txt
while read -r line; do
fname=$(echo $line | awk '{print $1}')
lname=$(echo $line | awk '{print $2}')
gender=$(echo $line | awk '{print $3}')
sid=$(echo $line | awk '{print $4}')
phone=$(echo $line | awk '{print $5}')
if [[ "$fname" == "$find" ]]; then
echo ">>> Record Found, Allowing Modifications <<<"
echo "> Enter First Name: "
read fname1
echo "> Enter Last Name: "
read lname1
echo "> Enter Gender: "
read gender1
echo "> Enter Student ID: "
read sid1
echo "> Enter Phone Number: "
read phone1
echo "$fname1 $lname1 $gender1 $sid1 $phone1" >> temporary.txt
flag=1
else
echo "$line" >> temporary.txt
fi
done < user_Records.txt
mv temporary.txt user_Records.txt
if [[ $flag -eq 0 ]]; then
echo ">>> Record Not Found <<<"
sleep 2
fi
userPanel
}

listUser() {
clear
echo "-------------------------------"
echo ">>> List of Users Record <<<"
echo "-------------------------------"
while read -r line; do
fname=$(echo $line | awk '{print $1}')
lname=$(echo $line | awk '{print $2}')
gender=$(echo $line | awk '{print $3}')
sid=$(echo $line | awk '{print $4}')
phone=$(echo $line | awk '{print $5}')
echo "-------------------------------"
echo "> Full Name: $fname $lname"
echo "> Gender: $gender"
echo "> Student-ID: $sid"
echo "> Phone No.: $phone"
echo "-------------------------------"
done < user_Records.txt
echo "Press any key to get back to User Panel."
read -n 1
userPanel
}

searchUser() {
clear
echo "Search by First name of the student: "
read find
flag=0
while read -r line; do
fname=$(echo $line | awk '{print $1}')
if [[ "$fname" == "$find" ]]; then
echo ">>> Record Found <<<"
echo "-------------------------------"
echo "> Full Name: $line"
echo "-------------------------------"
flag=1
fi
done < user_Records.txt
if [[ $flag -eq 0 ]]; then
echo ">>> Record Not Found <<<"
fi
echo "Press any key to redirect back to Panel."
read -n 1
userPanel
}

deleteUser() {
clear
echo "Enter the name of the person you want to delete the detail: "
read find
flag=0
touch temporary.txt
while read -r line; do
fname=$(echo $line | awk '{print $1}')
if [[ "$fname" == "$find" ]]; then
echo ">>> Record Deleted <<<"
flag=1
else
echo "$line" >> temporary.txt
fi
done < user_Records.txt
mv temporary.txt user_Records.txt
if [[ $flag -eq 0 ]]; then
echo ">>> Record Not Found <<<"
fi
sleep 2
userPanel
}

addBook() {
while true; do
clear
echo "Enter Book Name: "
read name
echo "Enter Book Author: "
read author
echo "Enter Book Publisher: "
read publisher
echo "Enter Book ID: "
read bookid
echo "Enter Book Quantity: "
read quantity
echo "$name $author $publisher $bookid $quantity" >> book_Records.txt
echo ">>> Book Record Added Successfully <<<"
echo -n "Do you wanna enter more records [y/N]: "
read input
if [[ $input != "y" && $input != "Y" ]]; then
echo "Redirecting to Book Panel."
sleep 2
bookPanel
fi
done
}

modifyBook() {
clear
echo "Enter the name of the book you want to see the detail: "
read find
flag=0
touch temporary.txt
while read -r line; do
name=$(echo $line | awk '{print $1}')
if [[ "$name" == "$find" ]]; then
echo ">>> Record Found, Allowing Modifications <<<"
echo "> Enter Book Name: "
read name1
echo "> Enter Author: "
read author1
echo "> Enter Publisher: "
read publisher1
echo "> Enter Book ID: "
read bookid1
echo "> Enter Quantity: "
read quantity1
echo "$name1 $author1 $publisher1 $bookid1 $quantity1" >> temporary.txt
flag=1
else
echo "$line" >> temporary.txt
fi
done < book_Records.txt
mv temporary.txt book_Records.txt
if [[ $flag -eq 0 ]]; then
echo ">>> Record Not Found <<<"
sleep 2
fi
bookPanel
}

listBook() {
clear
echo "-------------------------------"
echo ">>> List of Books Record <<<"
echo "-------------------------------"
while read -r line; do
name=$(echo $line | awk '{print $1}')
author=$(echo $line | awk '{print $2}')
publisher=$(echo $line | awk '{print $3}')
bookid=$(echo $line | awk '{print $4}')
quantity=$(echo $line | awk '{print $5}')
echo "-------------------------------"
echo "> Book Name: $name"
echo "> Author: $author"
echo "> Publisher: $publisher"
echo "> Book ID: $bookid"
echo "> Quantity: $quantity"
echo "-------------------------------"
done < book_Records.txt
echo "Press any key to get back to Book Panel."
read -n 1
bookPanel
}

searchBook() {
clear
echo "Search by First name of the book: "
read find
flag=0
while read -r line; do
name=$(echo $line | awk '{print $1}')
if [[ "$name" == "$find" ]]; then
echo ">>> Record Found <<<"
echo "-------------------------------"
echo "> Book Name: $line"
echo "-------------------------------"
flag=1
fi
done < book_Records.txt
if [[ $flag -eq 0 ]]; then
echo ">>> Record Not Found <<<"
fi
echo "Press any key to redirect back to Panel."
read -n 1
bookPanel
}

deleteBook() {
clear
echo "Enter the name of the book you want to delete the detail: "
read find
flag=0
touch temporary.txt
while read -r line; do
name=$(echo $line | awk '{print $1}')
if [[ "$name" == "$find" ]]; then
echo ">>> Record Deleted <<<"
flag=1
else
echo "$line" >> temporary.txt
fi
done < book_Records.txt
mv temporary.txt book_Records.txt
if [[ $flag -eq 0 ]]; then
echo ">>> Record Not Found <<<"
fi
sleep 2
bookPanel
}

rentBook() {
clear
echo "Enter the name of the book: "
read find
flag=0
touch temporary.txt
while read -r line; do
name=$(echo $line | awk '{print $1}')
author=$(echo $line | awk '{print $2}')
publisher=$(echo $line | awk '{print $3}')
bookid=$(echo $line | awk '{print $4}')
quantity=$(echo $line | awk '{print $5}')
if [[ "$name" == "$find" ]]; then
echo ">>> Record Found <<<"
echo "Enter your first name: "
read fname1
echo "Enter your last name: "
read lname1
if [[ $quantity -gt 0 ]]; then
echo "$fname1 $lname1 rented $name" >> rent_Records.txt
echo "$name $author $publisher $bookid $((quantity-1))" >>
temporary.txt
echo ">>> Book Rented Successfully <<<"
flag=1
else
echo "Book is out of stock!"
fi
else
echo "$line" >> temporary.txt
fi
done < book_Records.txt
mv temporary.txt book_Records.txt
if [[ $flag -eq 0 ]]; then
echo ">>> Record Not Found <<<"
fi
echo "Press any key to redirect back to Panel."
read -n 1
bookPanel
}

rentList() {
clear
echo "-------------------------------"
echo ">>> List of Rentals <<<"
echo "-------------------------------"
while read -r line; do
echo "$line"
done < rent_Records.txt
echo "Press any key to get back to User Panel."
read -n 1
userPanel
}
# Main Program
menu

You might also like