Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
43 views88 pages

Library Management System

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

Library Management System

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

1

Ex.no:01
Date:06.02.2024 IDENTIFY A SOFTWARE SYSTEM THAT NEEDS TO BE DEVELOPED

AIM
To identify a software system that needs to be developed.

LIBRARY MANAGEMENT SYSTEM


Manual process of keeping student records, book records, account details, managing

employee is very difficult. There are various problems also faced by the student in library such as

finding any particular book. Where Library Management System is library management software

for the purpose of monitoring and controlling the transactions in a library. This library management

system gives us the complete information about the library and the daily transactions done in a

Library. We need to maintain the record of new books and retrieve the details of books available in

the library which mainly focuses on basic operations in a library like adding new member, new

books, and searching up new information, searching books and members and facility to borrow and

return books. It features a familiar and well thought-out, an attractive user interface, combined with

strong searching, insertion and reporting capabilities. The report generation facility of library system

helps to get a good idea of which are the borrowed by the members, makes users possible to

generate hard copy. The following are the brief description on the functions achieved through this

project:

End-Users:

 Librarian: To maintain and update the records and also to cater the needs of the users.

 Reader: Need books to read and also places various requests to the librarian.

 Vendor: To provide and meet the requirement of the prescribed books.


2

RESULT
Thus, the software system that need to be developed was identified successfully.
3

Ex.no:02
Date:08.02.2024 CREATION OF SOFTWARE REQUIREMENT SPECIFICATION

AIM
To Document the Software Requirements Specification (SRS) for Library Management System.
LIBRARY MANAGEMENT SYSTEM
PROBLEM STATEMENT
Manual process of keeping student records, book records, account details, managing
employee is very difficult. There are various problems also faced by the student in library such as
finding any particular book. Where Library Management System is library management software
for the purpose of monitoring and controlling the transactions in a library. This library management
system gives us the complete information about the library and the daily transactions done in a
Library. We need to maintain the record of new books and retrieve the details of books available in
the library which mainly focuses on basic operations in a library like adding new member, new
books, and searching up new information, searching books and members and facility to borrow and
return books. It features a familiar and well thought-out, an attractive user interface, combined with
strong searching, insertion and reporting capabilities. The report generation facility of library system
helps to get a good idea of which are the borrowed by the members, makes users possible to
generate hard copy. The following are the brief description on the functions achieved through this
project:

Functional Requirements:

 Data Entry: The data entry requirements are concerned with how data is entered and
validated. The system shall allow a user to enter his/her data via a keyboard or choose an
item via a mouse. Whenever the "date" data is needed, it shall be entered only by choose date
from a online calendar. The system shall allow the user to enter the library card number and
ISBN both by typing or scanning. The system shall allow the user to enter book borrowing,
recalling data as frequently as required.
 User Interface: The user interface requirements are concerned with the user interface and
how information is presented to the user.
 Report Generation: The report generation requirements are concerned with the report
generation capabilities of the Library system. The system shall have a report feature that will
allow the user to generate a report showing the information of all the sign out book in a time
period which is the search criteria input by user. The information includes the number of
books, the time period and the information is grouped by book categories. The system shall
have a report feature that will allow the user to generate a report showing the information
4

about all the users who have overdue books and penalty. The system shall have a report
feature that will allow the user to generate a report showing the information of a particular
patron. The system shall have a report feature that will allow the user to generate a report
showing the information of book purchase information in a period including the book titles,
category, the author, the publisher, the price. It also shall give statistic data about the total
number of books purchased, the money paid by category. The system shall be generate those
reports to the display, a file or a printer which is linked to the system.
 Alerts and Notifications: It keeps track of the borrowed books and sends notifications to the
user and librarian about the overdue books.
 User Operations: The user can log in, view the catalog, search for books, checkout, reserve,
renew and return a book.
 Librarian Operations:The librarian registers new users, adds and maintains the books,
collects fines for overdue books, and issues books to users who need them.

Non-Functional Requirements:

 Usability Requirement: The system shall allow the users to access the system from the
Internet using HTML or it's derivative technologies like XML/CSS. The system uses a web
browser as an interface. Since all users are familiar with the general usage of browsers, no
special training is required. The system is user friendly and online help makes using the
system easy and also the product will support multiple languages such as Sinhala, Tamil and
English.
 Availability Requirement:The system is available 100% for the user and is used 24 hrs a
day and 365 days a year. The system shall be operational 24 hours a day and 7 days a week.
 Efficiency Requirement: Mean Time to Repair (MTTR) - Even if the system fails, the
system will be recovered back up within an hour or less.
 Accuracy:The system should accurately provide real time information taking into
consideration. various concurrency issues. The system shall provide 100% access reliability.
 Performance Requirement: The information is refreshed at regular intervals
depending upon whether some updates have occurred or not. The system shall respond to the
member in not less than two seconds from the time of the request submittal. The system shall
be allowed to take more time when doing large processing jobs.Responses to view
information shall take no longer than 5 seconds to appear on the screen.
5

 Reliability Requirement:The system has to be 100% reliable due to the importance of data
and the damages that can because by incorrect or incomplete data. The system will run 7
days a week, 24 hours a day.
 Maintainability and Portability Requirements:Changes (new patrons addition, password
changes, database changes) must be verified once per day at least. The system should
provide automatically notification to patrons by e-mail about item’s overdue, reservation
results, availability of reserved item and etc.

Software Requirements:

 Operating System: Windows 7, 8, 9, 10 .


 Language: Php, sql
 Database: MS SQL Server (back end)

Hardware Requirements:

 Processor: Intel core i3 or above for a stable experience and fast retrieval of data.
 Hard Disk: 40GB and above
 RAM: 256 MB or more, recommended 2 GB for fast reading and writing capabilities which
will result in better performance time
6

RESULT
The software requirement specification for Library Management was documented successfully
7

Ex.no:03
Date:13.02.2024 UML- USE CASE DIAGRAM

AIM
To identify Use Cases and develop the Use Case model for the identified requirements.

USE CASE DIAGRAM:

A use-case diagram is a graph of actors, a set of use cases enclosed by a system


boundary, communication (participation) associations between the actors and the use
cases, and generalization among the use cases. It shows the relationship among the actors
and use cases within a system. Use case diagram is used during the analysis phase of a
project. They separate the system into actors and use cases. Actor represents the roles that
can be played by user of the system. Use case describes the behavior of the system.
1. Use cases. A use case describes a sequence of actions that provide something of
measurable value to an actor and is drawn as a horizontal ellipse.
2. Actors. An actor is a person, organization, or external system that plays a role in one
or more interactions with your system. Actors are drawn as stick figures.
3. Associations. Associations between actors and use cases are indicated in use case
diagrams by solid lines. An association exists whenever an actor is involved with an
interaction described by a use case.
4. System boundary boxes (optional). A rectangle around the use cases is called the
system boundary box and is used to indicate the scope of the system.
5. Packages (optional). Packages are UML constructs that enable you to organize
model elements (such as use cases) into groups.
RELATIONSHIPS IN USE CASE DIAGRAM
Three relationships are supported among use cases by the UML standard, which
describes graphical notation for these relationships.
1. Include(<<include>>)
A given use case may include another. The first use case often depends on the
outcome of the included use case. This is useful for extracting truly common behaviours from
multiple use cases into a single description.
2. Extend(<<extend>>)
8

A given use case, (the extension) may extend another. This relationship indicates that
the behaviour of the extension use case may be inserted in the extended use case under some
conditions. This can be useful for dealing with special cases, or in accommodating new
requirements during system maintenance and extension.

3. Generalization
A generalization/ specialization relationship exists among use cases. A given use case may
be specialized form of an existing use case. The notation is a solid line ending in a hollow triangle
drawn from the specialized to the more general use case. This resembles the object-oriented concept
of sub-classing, in practice it can be both useful and effective to factor common behaviours,
constraints and assumptions to the general use case, describe them once, and deal same as except
details in the specialized cases.

PROCEDURE
1. Identify distinct actors and use cases.
2. The external actors are placed to the left of the use case and the internal actors to the right.
3. Select Model | Add Diagram | Use Case Diagram in Menu Bar or select Add Diagram | Use
Case Diagram in Context Menu in Star UML.
4. Name the diagram and draw the diagram using the symbols present in the Star UML toolbox
according to the identified actors and use cases.
5. Draw the relationship between the use cases and actors as extend, include and generalization
types using the symbols.
9

USE CASE DIAGRAM FOR LIBARAY MANAGEMENT SYSTEM:


10

USE CASE DIAGRAM FOR DATABASE:


11

USE CASE DIAGRAM FOR REGISTER USER:


12

RESULT

Thus the use case diagram was drawn successfully using Star UML for the identified requirements.
13

Ex.no:04
Date:20.02.2024 UML-CLASS DIAGRAM

AIM
To identify conceptual classes and develop a domain model with UML Class diagram

CLASS DIAGRAM
In the Unified Modelling Language (UML), a class diagrams a collection of static modelling elements,
such as classes and their relationships, connected as a graph to each other and to their contents; their internal
structures, and their relationships to other classes.

A class is drawn as a rectangle with three components separated by horizontal lines. The top name
compartment holds the class name, other general properties of the class, such as attributes, are in the middle
compartment, and the bottom compartment holds a list of operations. Either or both the attribute and
operation compartments may be suppressed.

A separator line is not drawn for a missing compartment if a compartment is suppressed; no inference can be
drawn about the presence or absence of elements in it. The class name and other properties should be
displayed in up to three sections. A stylistic convention of UML is to use an italic font forabstract classes
and a normal (roman) font for concrete classes.

PROCEDURE
1. Identify the classes that are taking part in the diagram.
2. Select Model | Add Diagram | Class Diagram in the Menu Bar or select Add Diagram | Class
Diagram in Context Menu.

3. Select class diagram, specify the attributes, operations or methods, parameters, datatype by
selecting following.
1. Select Model | Add | Class in Menu Bar or Add | Classing Context Menu.
2. Select Model | Add | Attribute in Menu Bar or Add | Attribute in Context Menu.
3. Select Model | Add | Operation in Menu Bar or Add | Operation in Context Menu.
4. Select Model | Add | Parameter in Menu Bar or Add | Parameter in Context Menu.
5. Select Model | Add | Datatype in Menu Bar or Add | Datatype in Context Menu.
4. Create the class diagram for the project.
5. Explicitly denote the relation between classes by generalizations, associations, multiplicities and
cardinalities.
6. Save the file.
14

CLASS DIAGRAM
15

RESULT
Thus the class diagram is drawn successfully using starUML for the identified requirements.
16

Ex.no:05 a)
Date:27.02.2024 UML-SEQUENCE DIAGRAMS AND COLLABORATION DIAGRAMS

AIM
To draw sequence and collaboration diagrams for the identified scenarios and the interaction between
objects.

INTERACTION DIAGRAM

Sequence diagram describes the behaviour of the system by viewing the interaction between the
system and its environment. It represents the class at the top and their lifetime, their interactions as
relations.

A collaboration diagram, also called a communication diagram or interaction diagram, is an


illustration of the relationships and interactions among software objects in the Unified Modelling Language
(UML).

SEQUENCE DIAGRAM:

PROCEDURE

1. Identify the initiator of the process.


2. Associate each actor with a class whether it uses or provides services.

3. Each actor is represented as a rectangle.

4. The sequence of flow is denoted by the name of the operations to be done.

5. The actors are separated by vertical dashed lines and sequence flow is indicated through arrows.
6. Select Model | Add Diagram | Sequence Diagram in Menu Bar or select Add Diagram | Sequence
Diagram in Context Menu in Star UML.
7. Create the sequence diagrams, showing the interaction between the objects.

8. Save the file.


17

SEQUENCE DIAGRAM 1:
18

SEQUENCE DIAGRAM 2:
19

COLLABORATION DIAGRAM 1:
20

RESULT
Thus the sequence and the collaboration diagrams for the identified scenarios and the interaction between
objects are drawn successfully for the requirements.
21

Ex.no:06 a)
Date:01.03.2024 UML-STATE CHART DIAGRAM

AIM
To draw the state chart diagram for the identified requirements

STATE CHART DIAGRAM

A State chart diagram describes a state machine. State machine can be defined as a machine which
defines different states of an object and these states are controlled by external or internal events. State chart
diagram is used to describe the states of different objects in its life cycle. So the emphasis is given on the
state changes upon some internal or external events. These states of objects are important to analyze and
implement them accurately. States can be identified as the condition of objects when a particular event
occurs.The state chart diagram shows the sequence of states that an object goes through during its life in
response to outside message. Set of values that describe an object at a specific point in time.A State chart
diagram describes a state machine. State machine can be defined as a machine which defines different states
of an object and these states are controlled by external or internal events. State chart diagram is used to
describe the states of different objects in its life cycle. So the emphasis is given on the state changes upon
some internal or external events. These states of objects are important to analyze and implement them
accurately. States can be identified as the condition of objects when a particular event occurs. The state chart
diagram shows the sequence of states that an object goes through during its life in response to outside
message. Set of values that describe an object at a specific point in time.

PROCEDURE

1. Identify important objects to be analysed.


2. Identify the states.
3. Identify the events.
4. Select Model | Add Diagram | State chart Diagram in Menu Bar or select Add Diagram | Statechart
Diagram in Context Menu.
5. Create state transition diagram for project.
6. Use the tools and draw the overall diagram.
7. Save the file.
22

STATE CHART DIAGRAM


23

RESULT
Thus the state chart diagram is drawn for the identified requirements successfully for the requirements.
24

Ex.no:06 b)
Date:01.03.2024 UML-ACTIVITY DIAGRAM

AIM
To draw activity the diagram for the identified requirements.

ACTIVITY DIAGRAM

An activity diagram is a variation or special case of a state machine, in which the states are activities

representing the performance of operations and the transitions are triggered by the completion of the

operations. Unlike state diagrams that focus on the events occurring to a single object as it responds to

messages, an activity diagram can be used to model an entire business process. The purpose of an activity

diagram is to provide a view of flows and what is going on inside a use case or among several classes.An

activity is shown as a round box, containing the name of the operation. When an operation symbol appears

within an activity diagram or other state diagram, it indicates the execution of the operation. Executing a

particular step within the diagram represents a state within the execution of the overall method. It may be

applied to any purpose such as visualizing the steps of a computer algorithm, but is considered especially

useful for visualizing business workflows and processes, or use cases. Some of the outstanding notation

includes parallel activities, swim lanes, and action-object flow relationship. An activity diagram allows the

reader to see the system execution and how it changes direction based upon different conditions and stimuli.

PROCEDURE
1. Identify the activities, association, conditions and constraints.
2. Name the correct alternative types.
3. It is essential for the diagram to have a start and end points.
4. Select Model | Add Diagram | Activity Diagram in Menu Bar or select Add Diagram | Activity
Diagram in Context Menu in Star UML.
5. Select activity diagram and create activity diagram for requirements of project using the tools.
6. Save the file.
25

ACTIVITY DIAGRAM
26

RESULT
Thus the activity diagram is drawn successfully for the requirements.
27

Ex.no:07
Date:05.03.2024 & Implement the system as per the detailed design
19.03.2024

AIM
To implement the Library Management System with database connectivity

SOURCE CODE

Addadmin.php
<?php

require('dbconn.php');

?>

<!DOCTYPE html>

<html>

<!-- Head -->

<head>

<title>Library Management </title>

<!-- Meta-Tags -->

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta name="keywords" content="Library Member Login Form Widget Responsive, Login Form Web Template, Flat
Pricing Tables, Flat Drop-Downs, Sign-Up Web Templates, Flat Web Templates, Login Sign-up Responsive Web Template, Smartphone
Compatible Web Template, Free Web Designs for Nokia, Samsung, LG, Sony Ericsson, Motorola Web Design" />

<script type="application/x-javascript">addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);


function hideURLbar(){ window.scrollTo(0,1); } </script>

<!-- //Meta-Tags -->

<!-- Style --><link rel="stylesheet" href="css/style.css" type="text/css" media="all">

<!-- Fonts -->

<link href="//fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">

<!-- //Fonts -->

</head>

<!-- //Head -->

<!-- Body -->

<body>

<style>

body{

background-color: #808080;

</style>
28

<h1>LIBRARY MANAGEMENT </h1>

<div class="container">

<div class="login">

<h2>Create New Admin</h2>

<form action="index.php" method="post">

<div class="send-button">

<a href="index.php">BACK</a>

</div>

<!-- <input type="text" Name="RollNo" placeholder="ID number" required="">

<input type="password" Name="Password" placeholder="Password" required="">

<div class="send-button">

<!--<form>-->

<!-- <input type="submit" name="signin"; value="Sign In"> -->

</form>

</div>

<div class="clear"></div>

</div>

<div class="register">

<h2>Sign Up</h2>

<form action="addadmin.php" method="post">

<input type="text" Name="Name" placeholder="Name" required>

<input type="text" Name="Email" placeholder="Email" required>

<input type="password" Name="Password" placeholder="Password" required>

<input type="text" Name="PhoneNumber" placeholder="Phone Number" required>

<input type="text" Name="RollNo" placeholder="ID Number" required="


<br>

<br>

<div class="send-button">

<input type="submit" name="signup" value="Sign Up">

</form>

</div>

<p>By creating an account, you agree to our <a class="underline" href="terms.html">Terms</a></p>

<div class="clear"></div>

</div>

<div class="clear"></div>

</div>

<div class="footer w3layouts agileits">

<p>&copy; 2022 LMS Login. King A. Albaracin&Mariabil V. Caga-anan</a></p>

</div>

<?php
29

if(isset($_POST['signup']))

$name=$_POST['Name'];

$email=$_POST['Email'];

$password=$_POST['Password'];

$mobno=$_POST['PhoneNumber'];

$rollno=$_POST['RollNo'];

$category=$_POST['Category'];

$type='Admin';

$sql="insert into LMS.user (Name,Type,Category,RollNo,EmailId,MobNo,Password) values


('$name','$type','$category','$rollno','$email','$mobno','$password')";

if ($conn->query($sql) === TRUE) {

echo "<script type='text/javascript'>alert('Registration Successful')</script>";

echo header("Location: index.php");

} else {

//echo "Error: " . $sql . "<br>" . $conn->error;

echo "<script type='text/javascript'>alert('User Exists')</script>";

?>

</body>

<!-- //Body -->

</html>

Addbooks.php

<?php

require('dbconn.php');

?>

<?php

if ($_SESSION['RollNo']== 'admin') {

?>

<!DOCTYPE html>

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>LMS</title>

<link type="text/css" href="bootstrap/css/bootstrap.min.css" rel="stylesheet">

<link type="text/css" href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">

<link type="text/css" href="css/theme.css" rel="stylesheet">


30

<link type="text/css" href="images/icons/css/font-awesome.css" rel="stylesheet">

<link type="text/css" href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600'

rel='stylesheet'>

</head>

<body>

<div class="navbar navbar-fixed-top">

<div class="navbar-inner">

<div class="container">

<a class="btn btn-navbar" data-toggle="collapse" data-target=".navbar-inverse-collapse">

<i class="icon-reorder shaded"></i></a><a class="brand" href="index.php">LMS </a>

<div class="nav-collapse collapse navbar-inverse-collapse">

<ul class="nav pull-right">

<li class="nav-user dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">

<img src="images/user.png" class="nav-avatar" />

<b class="caret"></b></a>

<ul class="dropdown-menu">

<li><a href="index.php">Your Profile</a></li>

<!--li><a href="#">Edit Profile</a></li>

<li><a href="#">Account Settings</a></li-->

<li class="divider"></li>

<li><a href="logout.php">Logout</a></li>

</ul>

</li>

</ul>

</div>

<!-- /.nav-collapse -->

</div>

</div>

<!-- /navbar-inner -->

</div>

<!-- /navbar -->

<div class="wrapper">

<div class="container">

<div class="row">

<div class="span3">

<div class="sidebar">

<ul class="widget widget-menu unstyled">

<li class="active"><a href="index.php"><i class="menu-icon icon-home"></i>Home

</a></li>
31

<li class="active"><a href="../qr/index.php"><i class="menu-icon icon-home"></i>Visit Hours

</a></li>

<li><a href="message.php"><i class="menu-icon icon-inbox"></i>Messages</a>

</li>

<li><a href="recieve.php"><i class="menu-icon icon-inbox"></i>Recieve Message</a>

</li>

<li><a href="student.php"><i class="menu-icon icon-user"></i>Manage Students </a>

</li>

<li><a href="book.php"><i class="menu-icon icon-book"></i>All Books </a></li>

<li><a href="addbook.php"><i class="menu-icon icon-edit"></i>Add Books </a></li>

<li><a href="requests.php"><i class="menu-icon icon-tasks"></i>Issue/Return Requests </a></li>

<!--<li><a href="recommendations.php"><i class="menu-icon icon-list"></i>Book Recommendations </a></li> -->

<li><a href="current.php"><i class="menu-icon icon-list"></i>Currently Issued Books </a></li>

<li><a href="history.php"><i class="menu-icon icon-list"></i>Recent Deletion Books </a></li>

</ul>

<ul class="widget widget-menu unstyled">

<li><a href="logout.php"><i class="menu-icon icon-signout"></i>Logout </a></li>

</ul>

</div>

<!--/.sidebar-->

</div>

<!--/.span3-->

<!--/.span9-->

<div class="span9">

<div class="content">

<div class="module">

<div class="module-head">

<h3>Add Book</h3>

</div>

<div class="module-body">

<br>

<form class="form-horizontal row-fluid" action="addbook.php" method="post">

<div class="control-group">

<label class="control-label" for="Section"><b>Book Section:</b></label>

<div class="controls">

<select name = "Section" tabindex="1" value="SC" data-placeholder="" class="span6" required>

<!--<option value="<?php echo $status?>"><?php echo $status ?></option> -->

<option value=""></option>
32

<option value="General Reference">General Reference</option>

<option value="Reference">Reference</option>

<option value="Filipiniana">Filipiniana</option>

<option class="Periodical">Periodical</option>

<option value="Reserved Books"> Reserved Books</option>

<option value="Graduate Studies">Graduate Studies</option>

<option value="Special Collections">Special Collection</option>

<option value="Rare Book"> Rare Book</option>

<option value="Computer Internet Area">Computer Internet Area</option>

</select>

</div>

</div>

<div class="control-group">

<label class="control-label" for="Subject"><b>Subject</b></label>

<div class="controls">

<input type="text" id="Subject" name="Subject" placeholder="Subject" class="span8" required>

</div>

</div>

<div class="control-group">

<label class="control-label" for="book"><b>Textbook</b></label>

<div class="controls">

<input type="text" id="book" name="book" placeholder="Textbook" class="span8" required>

</div>

</div>

<div class="control-group">

<label class="control-label" for="Copyright"><b>Copyright</b></label>

<div class="controls">

<input type="text" id="Copyright" name="Copyright" placeholder="Copyright" class="span8" required>

</div>

</div>

<div class="control-group">

<label class="control-label" for="Title"><b>No. of Title</b></label>

<div class="controls">

<input type="text" id="Title" name="Title" placeholder="Volumes" class="span8" required>

</div>

</div>

<div class="control-group">

<label class="control-label" for="Availability"><b>Number of Copies</b></label>


33

<div class="controls">

<input type="text" id="availability" name="availability" placeholder="Number of Copies" class="span8" required>

</div>

</div>

<div class="control-group">

<label class="control-label" for="Author"><b>Author</b></label>

<div class="controls">

<input type="text" id="Author" name="Author" placeholder="Author" class="span8" required>

</div>

</div>

<div class="control-group">

<label class="control-label" for="ISBN"><b>ISBN</b></label>

<div class="controls">

<input type="text" id="ISBN" name="ISBN" placeholder="ISBN" class="span8" required>

</div>

</div>

<div class="control-group">

<label class="control-label" for="status"><b>Book Status:</b></label>

<div class="controls">

<select name = "status" tabindex="1" value="SC" data-placeholder="Select Status" class="span6" required>

<!--<option value="<?php echo $status?>"><?php echo $status ?></option> -->

<option value=""></option>

<option value="GOOD">GOOD</option>

<option value="DAMAGE">DAMAGE</option>

<option value="DILAPIDATED">DILAPIDATED</option>

</select>

</div>

</div>

<div class="control-group">

<div class="controls">

<button type="submit" name="submit"class="btn">Add Book</button>

</div>

</div>

</form>

</div>

</div>

</div><!--/.content-->

</div>
34

</div>

</div>

<!--/.container-->

</div>

<div class="footer">

<div class="container">

<b class="copyright">&copy; 2022 LMS Login. King A. Albaracin&Mariabil V. Caga-anan</b>All rights reserved.

</div>

</div>

<!--/.wrapper-->

<script src="scripts/jquery-1.9.1.min.js" type="text/javascript"></script>

<script src="scripts/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>

<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>

<script src="scripts/flot/jquery.flot.js" type="text/javascript"></script>

<script src="scripts/flot/jquery.flot.resize.js" type="text/javascript"></script>

<script src="scripts/datatables/jquery.dataTables.js" type="text/javascript"></script>

<script src="scripts/common.js" type="text/javascript"></script>

<?php

if(isset($_POST['submit']))

$Section = $_POST['Section'];

$Subject = $_POST['Subject'];

$book = $_POST['book'];

$Copyright = $_POST['Copyright'];

$Title = $_POST['Title'];

$availability = $_POST['availability'];

$Author = $_POST['Author'];

$ISBN = $_POST['ISBN'];

$status = $_POST['status'];

$sql1 = "INSERT INTO `book`( `Section`, `Subject`, `Textbook`, `Volume`, `Year`, `Availability`, `Author`, `ISBN`, `Status`) VALUES
('$Section','$Subject','$book','$Copyright','$Title','$availability','$Author','$ISBN','$status')";

if($conn->query($sql1) === TRUE){

$sql2="select max(BookId) as x from LMS.book";

$result=$conn->query($sql2);

$row=$result->fetch_assoc();

echo "<script type='text/javascript'>alert('Success')</script>";

else

{//echo $conn->error;
35

echo "<script type='text/javascript'>alert('Error')</script>";

?>

</body>

</html>

<?php }

else {

echo "<script type='text/javascript'>alert('Access Denied!!!')</script>";

} ?>

qrcode.php
<?php

if (!class_exists('QRcode', false)) {

if (!function_exists('str_split')) {

function str_split($string, $split_length=1) {

if ((strlen($string) > $split_length) OR (!$split_length)) {

do {

$c = strlen($string);

$parts[] = substr($string, 0, $split_length);

$string = substr($string, $split_length);

} while ($string !== false);

} else {

$parts = array($string);

return $parts;

public function __construct($code, $eclevel = 'L') {

$barcode_array = array();

if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {

return false;

// set error correction level

$this->level = array_search($eclevel, array('L', 'M', 'Q', 'H'));

if ($this->level === false) {

$this->level = QR_ECLEVEL_L;

if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) {


36

return false;

if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) {

return false;

$this->items = array();

$this->encodeString($code);

$qrTab = $this->binarize($this->data);

$size = count($qrTab);

$barcode_array['num_rows'] = $size;

$barcode_array['num_cols'] = $size;

$barcode_array['bcode'] = array();

foreach ($qrTab as $line) {

$arrAdd = array();

foreach (str_split($line) as $char) {

$arrAdd[] = ($char=='1')?1:0;

$barcode_array['bcode'][] = $arrAdd;

$this->barcode_array = $barcode_array;

protected function encodeMask($mask) {

$spec = array(0, 0, 0, 0, 0);

$this->datacode = $this->getByteStream($this->items);

if (is_null($this->datacode)) {

return NULL;

$spec = $this->getEccSpec($this->version, $this->level, $spec);

$this->b1 = $this->rsBlockNum1($spec);

$this->dataLength = $this->rsDataLength($spec);

$this->eccLength = $this->rsEccLength($spec);

$this->ecccode = array_fill(0, $this->eccLength, 0);

$this->blocks = $this->rsBlockNum($spec);

$ret = $this->init($spec);

if ($ret < 0) {

return NULL;

$this->count = 0;

$this->width = $this->getWidth($this->version);
37

$this->frame = $this->newFrame($this->version);

$this->x = $this->width - 1;

$this->y = $this->width - 1;

$this->dir = -1;

$this->bit = -1;

// inteleaved data and ecc codes

for ($i=0; $i< ($this->dataLength + $this->eccLength); $i++) {

$code = $this->getCode();

$bit = 0x80;

for ($j=0; $j<8; $j++) {

$addr = $this->getNextPosition();

$this->setFrameAt($addr, 0x02 | (($bit & $code) != 0));

$bit = $bit >>1;

// remainder bits

$j = $this->getRemainder($this->version);

for ($i=0; $i<$j; $i++) {

$addr = $this->getNextPosition();

$this->setFrameAt($addr, 0x02);

// masking

$this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);

if ($mask < 0) {

if (QR_FIND_BEST_MASK) {

$masked = $this->mask($this->width, $this->frame, $this->level);

} else {

$masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) %


8), $this->level);

} else {

$masked = $this->makeMask($this->width, $this->frame, $mask, $this->level);

if ($masked == NULL) {

return NULL;

$this->data = $masked;

protected function getNextPosition() {

do {
38

if ($this->bit == -1) {

$this->bit = 0;

return array('x'=>$this->x, 'y'=>$this->y);

$x = $this->x;

$y = $this->y;

$w = $this->width;

if ($this->bit == 0) {

$x--;

$this->bit++;

} else {

$x++;

$y += $this->dir;

$this->bit--;

if ($this->dir< 0) {

if ($y < 0) {

$y = 0;

$x -= 2;

$this->dir = 1;

if ($x == 6) {

$x--;

$y = 9;

} else {

if ($y == $w) {

$y = $w - 1;

$x -= 2;

$this->dir = -1;

if ($x == 6) {

$x--;

$y -= 8;

if (($x < 0) OR ($y < 0)) {

return NULL;

}
39

$this->x = $x;

$this->y = $y;

} while(ord($this->frame[$y][$x]) & 0x80);

return array('x'=>$x, 'y'=>$y);

// - - - - - - - - - - - - - - - - - - - - - - - - -

// QRrawcode

/**

* Initialize code.

* @param array $spec array of ECC specification

* @return 0 in case of success, -1 in case of error

*/

protected function init($spec) {

$dl = $this->rsDataCodes1($spec);

$el = $this->rsEccCodes1($spec);

$rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);

$blockNo = 0;

$dataPos = 0;

$eccPos = 0;

$endfor = $this->rsBlockNum1($spec);

for ($i=0; $i< $endfor; ++$i) {

$ecc = array_slice($this->ecccode, $eccPos);

$this->rsblocks[$blockNo] = array();

$this->rsblocks[$blockNo]['dataLength'] = $dl;

$this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);

$this->rsblocks[$blockNo]['eccLength'] = $el;

$ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);

$this->rsblocks[$blockNo]['ecc'] = $ecc;

$this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);

$dataPos += $dl;

$eccPos += $el;

$blockNo++;

if ($this->rsBlockNum2($spec) == 0) {

return 0;

}
40

$dl = $this->rsDataCodes2($spec);

$el = $this->rsEccCodes2($spec);

$rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);

if ($rs == NULL) {

return -1;

$endfor = $this->rsBlockNum2($spec);

for ($i=0; $i< $endfor; ++$i) {

$ecc = array_slice($this->ecccode, $eccPos);

$this->rsblocks[$blockNo] = array();

$this->rsblocks[$blockNo]['dataLength'] = $dl;

$this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);

$this->rsblocks[$blockNo]['eccLength'] = $el;

$ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);

$this->rsblocks[$blockNo]['ecc'] = $ecc;

$this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);

$dataPos += $dl;

$eccPos += $el;

$blockNo++;

return 0;

protected function getCode() {

if ($this->count < $this->dataLength) {

$row = $this->count % $this->blocks;

$col = $this->count / $this->blocks;

if ($col >= $this->rsblocks[0]['dataLength']) {

$row += $this->b1;

$ret = $this->rsblocks[$row]['data'][$col];

} elseif ($this->count < $this->dataLength + $this->eccLength) {

$row = ($this->count - $this->dataLength) % $this->blocks;

$col = ($this->count - $this->dataLength) / $this->blocks;

$ret = $this->rsblocks[$row]['ecc'][$col];

} else {

return 0;

$this->count++;

return $ret;
41

protected function writeFormatInformation($width, &$frame, $mask, $level) {

$blacks = 0;

$format = $this->getFormatInfo($mask, $level);

for ($i=0; $i<8; ++$i) {

if ($format & 1) {

$blacks += 2;

$v = 0x85;

} else {

$v = 0x84;

$frame[8][$width - 1 - $i] = chr($v);

if ($i< 6) {

$frame[$i][8] = chr($v);

} else {

$frame[$i + 1][8] = chr($v);

$format = $format >>1;

for ($i=0; $i<7; ++$i) {

if ($format & 1) {

$blacks += 2;

$v = 0x85;

} else {

$v = 0x84;

$frame[$width - 7 + $i][8] = chr($v);

if ($i == 0) {

$frame[8][7] = chr($v);

} else {

$frame[8][6 - $i] = chr($v);

$format = $format >>1;

return $blacks;

protected function mask2($x, $y) {

return ($x % 3);

}
42

protected function mask4($x, $y) {

return (((int)($y / 2)) + ((int)($x / 3))) & 1;

protected function mask5($x, $y) {

return (($x * $y) & 1) + ($x * $y) % 3;

protected function mask6($x, $y) {

return ((($x * $y) & 1) + ($x * $y) % 3) &1;

protected function mask7($x, $y) {

return ((($x * $y) % 3) + (($x + $y) & 1)) &1;

protected function generateMaskNo($maskNo, $width, $frame) {

$bitMask = array_fill(0, $width, array_fill(0, $width, 0));

for ($y=0; $y<$width; ++$y) {

for ($x=0; $x<$width; ++$x) {

if (ord($frame[$y][$x]) & 0x80) {

$bitMask[$y][$x] = 0;

} else {

$maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);

$bitMask[$y][$x] = ($maskFunc == 0)?1:0;

return $bitMask;

protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) {

$b = 0;

$bitMask = array();

$bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);

if ($maskGenOnly) {

return;

$d = $s;

for ($y=0; $y<$width; ++$y) {

for ($x=0; $x<$width; ++$x) {

if ($bitMask[$y][$x] == 1) {

$d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);

}
43

$b += (int)(ord($d[$y][$x]) & 1);

return $b;

protected function makeMask($width, $frame, $maskNo, $level) {

$masked = array_fill(0, $width, str_repeat("\0", $width));

$this->makeMaskNo($maskNo, $width, $frame, $masked);

$this->writeFormatInformation($width, $masked, $maskNo, $level);

return $masked;

protected function calcN1N3($length) {

$demerit = 0;

for ($i=0; $i<$length; ++$i) {

if ($this->runLength[$i] >= 5) {

$demerit += (N1 + ($this->runLength[$i] - 5));

if ($i& 1) {

if (($i>= 3) AND ($i< ($length-2)) AND ($this->runLength[$i] % 3 == 0)) {

$fact = (int)($this->runLength[$i] / 3);

if (($this->runLength[$i-2] == $fact)

AND ($this->runLength[$i-1] == $fact)

AND ($this->runLength[$i+1] == $fact)

AND ($this->runLength[$i+2] == $fact)) {

if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 *


$fact))) {

$demerit += N3;

} elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact)))


{

$demerit += N3;

return $demerit;

protected function evaluateSymbol($width, $frame) {

$head = 0;

$demerit = 0;
44

for ($y=0; $y<$width; ++$y) {

$head = 0;

$this->runLength[0] = 1;

$frameY = $frame[$y];

if ($y > 0) {

$frameYM = $frame[$y-1];

for ($x=0; $x<$width; ++$x) {

if (($x > 0) AND ($y > 0)) {

$b22 = ord($frameY[$x]) &ord($frameY[$x-1]) &ord($frameYM[$x])


&ord($frameYM[$x-1]);

$w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) |


ord($frameYM[$x-1]);

if (($b22 | ($w22 ^ 1)) & 1) {

$demerit += N2;

if (($x == 0) AND (ord($frameY[$x]) & 1)) {

$this->runLength[0] = -1;

$head = 1;

$this->runLength[$head] = 1;

} elseif ($x > 0) {

if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {

$head++;

$this->runLength[$head] = 1;

} else {

$this->runLength[$head]++;

$demerit += $this->calcN1N3($head+1);

for ($x=0; $x<$width; ++$x) {

$head = 0;

$this->runLength[0] = 1;

for ($y=0; $y<$width; ++$y) {

if (($y == 0) AND (ord($frame[$y][$x]) & 1)) {

$this->runLength[0] = -1;

$head = 1;

$this->runLength[$head] = 1;
45

} elseif ($y > 0) {

if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {

$head++;

$this->runLength[$head] = 1;

} else {

$this->runLength[$head]++;

$demerit += $this->calcN1N3($head+1);

return $demerit;

protected function mask($width, $frame, $level) {

$minDemerit = PHP_INT_MAX;

$bestMaskNum = 0;

$bestMask = array();

$checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);

if (QR_FIND_FROM_RANDOM !== false) {

$howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);

for ($i = 0; $i< $howManuOut; ++$i) {

$remPos = rand (0, count($checked_masks)-1);

unset($checked_masks[$remPos]);

$checked_masks = array_values($checked_masks);

$bestMask = $frame;

foreach ($checked_masks as $i) {

$mask = array_fill(0, $width, str_repeat("\0", $width));

$demerit = 0;

$blacks = 0;

$blacks = $this->makeMaskNo($i, $width, $frame, $mask);

$blacks += $this->writeFormatInformation($width, $mask, $i, $level);

$blacks = (int)(100 * $blacks / ($width * $width));

$demerit = (int)((int)(abs($blacks - 50) / 5) * N4);

$demerit += $this->evaluateSymbol($width, $mask);

if ($demerit < $minDemerit) {

$minDemerit = $demerit;

$bestMask = $mask;
46

$bestMaskNum = $i;

return $bestMask;

protected function identifyMode($pos) {

if ($pos>= strlen($this->dataStr)) {

return QR_MODE_NL;

$c = $this->dataStr[$pos];

if ($this->isdigitat($this->dataStr, $pos)) {

return QR_MODE_NM;

} elseif ($this->isalnumat($this->dataStr, $pos)) {

return QR_MODE_AN;

} elseif ($this->hint == QR_MODE_KJ) {

if ($pos+1 <strlen($this->dataStr)) {

$d = $this->dataStr[$pos+1];

$word = (ord($c) << 8) | ord($d);

if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) {

return QR_MODE_KJ;

return QR_MODE_8B;

protected function eatNum() {

$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);

$p = 0;

while($this->isdigitat($this->dataStr, $p)) {

$p++;

$run = $p;

$mode = $this->identifyMode($p);

if ($mode == QR_MODE_8B) {

$dif = $this->estimateBitsModeNum($run) + 4 + $ln

+ $this->estimateBitsMode8(1) // + 4 + l8

- $this->estimateBitsMode8($run + 1); // - 4 - l8

if ($dif> 0) {

return $this->eat8();
47

if ($mode == QR_MODE_AN) {

$dif = $this->estimateBitsModeNum($run) + 4 + $ln

+ $this->estimateBitsModeAn(1) // + 4 + la

- $this->estimateBitsModeAn($run + 1);// - 4 - la

if ($dif> 0) {

return $this->eatAn();

$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));

return $run;

protected function eatAn() {

$la = $this->lengthIndicator(QR_MODE_AN, $this->version);

$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);

$p = 0;

while($this->isalnumat($this->dataStr, $p)) {

if ($this->isdigitat($this->dataStr, $p)) {

$q = $p;

while($this->isdigitat($this->dataStr, $q)) {

$q++;

$dif = $this->estimateBitsModeAn($p) // + 4 + la

+ $this->estimateBitsModeNum($q - $p) + 4 + $ln

- $this->estimateBitsModeAn($q); // - 4 - la

if ($dif< 0) {

break;

} else {

$p = $q;

} else {

$p++;

$run = $p;

if (!$this->isalnumat($this->dataStr, $p)) {

$dif = $this->estimateBitsModeAn($run) + 4 + $la

+ $this->estimateBitsMode8(1) // + 4 + l8
48

- $this->estimateBitsMode8($run + 1); // - 4 - l8

if ($dif> 0) {

return $this->eat8();

$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));

return $run;

protected function eatKanji() {

$p = 0;

while($this->identifyMode($p) == QR_MODE_KJ) {

$p += 2;

$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));

return $run;

protected function eat8() {

$la = $this->lengthIndicator(QR_MODE_AN, $this->version);

$ln = $this->lengthIndicator(QR_MODE_NM, $this->version);

$p = 1;

$dataStrLen = strlen($this->dataStr);

while($p < $dataStrLen) {

$mode = $this->identifyMode($p);

if ($mode == QR_MODE_KJ) {

break;

if ($mode == QR_MODE_NM) {

$q = $p;

while($this->isdigitat($this->dataStr, $q)) {

$q++;

$dif = $this->estimateBitsMode8($p) // + 4 + l8

+ $this->estimateBitsModeNum($q - $p) + 4 + $ln

- $this->estimateBitsMode8($q); // - 4 - l8

if ($dif< 0) {

break;

} else {

$p = $q;

}
49

} elseif ($mode == QR_MODE_AN) {

$q = $p;

while($this->isalnumat($this->dataStr, $q)) {

$q++;

$dif = $this->estimateBitsMode8($p) // + 4 + l8

+ $this->estimateBitsModeAn($q - $p) + 4 + $la

- $this->estimateBitsMode8($q); // - 4 - l8

if ($dif< 0) {

break;

} else {

$p = $q;

} else {

$p++;

$run = $p;

$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));

return $run;

protected function splitString() {

while (strlen($this->dataStr) > 0) {

if ($this->dataStr == '') {

return 0;

$mode = $this->identifyMode(0);

switch ($mode) {

case QR_MODE_NM: {

$length = $this->eatNum();

break;

case QR_MODE_AN: {

$length = $this->eatAn();

break;

case QR_MODE_KJ: {

if ($hint == QR_MODE_KJ) {

$length = $this->eatKanji();
50

} else {

$length = $this->eat8();

break;

default: {

$length = $this->eat8();

break;

if ($length == 0) {

return 0;

if ($length < 0) {

return -1;

$this->dataStr = substr($this->dataStr, $length);

protected function toUpper() {

$stringLen = strlen($this->dataStr);

$p = 0;

while ($p < $stringLen) {

$mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint);

if ($mode == QR_MODE_KJ) {

$p += 2;

} else {

if ((ord($this->dataStr[$p]) >= ord('a')) AND (ord($this->dataStr[$p]) <= ord('z'))) {

$this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);

$p++;

return $this->dataStr;

protected function newInputItem($mode, $size, $data, $bstream=null) {

$setData = array_slice($data, 0, $size);

if (count($setData) < $size) {

$setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0));


51

if (!$this->check($mode, $size, $setData)) {

return NULL;

$inputitem = array();

$inputitem['mode'] = $mode;

$inputitem['size'] = $size;

$inputitem['data'] = $setData;

$inputitem['bstream'] = $bstream;

return $inputitem;

protected function encodeModeNum($inputitem, $version) {

$words = (int)($inputitem['size'] / 3);

$inputitem['bstream'] = array();

$val = 0x1;

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM,


$version), $inputitem['size']);

for ($i=0; $i< $words; ++$i) {

$val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100;

$val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10;

$val += (ord($inputitem['data'][$i*3+2]) - ord('0'));

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val);

if ($inputitem['size'] - $words * 3 == 1) {

$val = ord($inputitem['data'][$words*3]) - ord('0');

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);

} elseif (($inputitem['size'] - ($words * 3)) == 2) {

$val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10;

$val += (ord($inputitem['data'][$words*3+1]) - ord('0'));

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val);

return $inputitem;

/**

* encodeModeAn

* @param array $inputitem

* @param int $version

* @return array input item


52

*/

protected function encodeModeAn($inputitem, $version) {

$words = (int)($inputitem['size'] / 2);

$inputitem['bstream'] = array();

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02);

$inputitem['bstream'] = $this->appendNum(v, $this->lengthIndicator(QR_MODE_AN, $version),


$inputitem['size']);

for ($i=0; $i< $words; ++$i) {

$val = (int)$this->lookAnTable(ord($inputitem['data'][$i*2 ])) * 45;

$val += (int)$this->lookAnTable(ord($inputitem['data'][$i*2+1]));

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val);

if ($inputitem['size'] & 1) {

$val = $this->lookAnTable(ord($inputitem['data'][($words * 2)]));

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val);

return $inputitem;

/**

* encodeMode8

* @param array $inputitem

* @param int $version

* @return array input item

*/

protected function encodeMode8($inputitem, $version) {

$inputitem['bstream'] = array();

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4);

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B,


$version), $inputitem['size']);

for ($i=0; $i< $inputitem['size']; ++$i) {

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i]));

return $inputitem;

protected function encodeModeKanji($inputitem, $version) {

$inputitem['bstream'] = array();

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8);

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ,


$version), (int)($inputitem['size'] / 2));
53

for ($i=0; $i<$inputitem['size']; $i+=2) {

$val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]);

if ($val<= 0x9ffc) {

$val -= 0x8140;

} else {

$val -= 0xc140;

$h = ($val>> 8) * 0xc0;

$val = ($val& 0xff) + $h;

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val);

return $inputitem;

protected function encodeModeStructure($inputitem) {

$inputitem['bstream'] = array();

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03);

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1);

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1);

$inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2]));

return $inputitem;

protected function encodeBitStream($inputitem, $version) {

$inputitem['bstream'] = array();

$words = $this->maximumWords($inputitem['mode'], $version);

if ($inputitem['size'] > $words) {

$st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']);

$st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words,


array_slice($inputitem['data'], $words));

$st1 = $this->encodeBitStream($st1, $version);

$st2 = $this->encodeBitStream($st2, $version);

$inputitem['bstream'] = array();

$inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']);

$inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']);

} else {

switch($inputitem['mode']) {

case QR_MODE_NM: {

$inputitem = $this->encodeModeNum($inputitem, $version);

break;

case QR_MODE_AN: {
54

$inputitem = $this->encodeModeAn($inputitem, $version);

break;

case QR_MODE_8B: {

$inputitem = $this->encodeMode8($inputitem, $version);

break;

case QR_MODE_KJ: {

$inputitem = $this->encodeModeKanji($inputitem, $version);

break;

case QR_MODE_ST: {

$inputitem = $this->encodeModeStructure($inputitem);

break;

default: {

break;

return $inputitem;

protected function appendNewInputItem($items, $mode, $size, $data) {

$items[] = $this->newInputItem($mode, $size, $data);

return $items;

protected function insertStructuredAppendHeader($items, $size, $index, $parity) {

if ($size > MAX_STRUCTURED_SYMBOLS) {

return -1;

if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) {

return -1;

$buf = array($size, $index, $parity);

$entry = $this->newInputItem(QR_MODE_ST, 3, buf);

array_unshift($items, $entry);

return $items;

protected function calcParity($items) {


55

$parity = 0;

foreach ($items as $item) {

if ($item['mode'] != QR_MODE_ST) {

for ($i=$item['size']-1; $i>=0; --$i) {

$parity ^= $item['data'][$i];

return $parity;

protected function checkModeNum($size, $data) {

for ($i=0; $i<$size; ++$i) {

if ((ord($data[$i]) <ord('0')) OR (ord($data[$i]) >ord('9'))){

return false;

return true;

protected function estimateBitsModeNum($size) {

$w = (int)$size / 3;

$bits = $w * 10;

switch($size - $w * 3) {

case 1: {

$bits += 4;

break;

case 2: {

$bits += 7;

break;

default: {

break;

return $bits;

protected function lookAnTable($c) {

return (($c > 127)?-1:$this->anTable[$c]);

}
56

fals

protected function checkModeAn($size, $data) {

for ($i=0; $i<$size; ++$i) {

if ($this->lookAnTable(ord($data[$i])) == -1) {

return false;

return true;

protected function estimateBitsModeAn($size) {

$w = (int)($size / 2);

$bits = $w * 11;

if ($size & 1) {

$bits += 6;

return $bits;

protected function estimateBitsMode8($size) {

return $size * 8;

protected function estimateBitsModeKanji($size) {

return (int)(($size / 2) * 13);

protected function checkModeKanji($size, $data) {

if ($size & 1) {

return false;

for ($i=0; $i<$size; $i+=2) {

$val = (ord($data[$i]) << 8) | ord($data[$i+1]);

if (($val< 0x8140) OR (($val> 0x9ffc) AND ($val< 0xe040)) OR ($val> 0xebbf)) {

return false;

return true;

protected function check($mode, $size, $data) {

if ($size <= 0) {

return false;

}
57

switch($mode) {

case QR_MODE_NM: {

return $this->checkModeNum($size, $data);

case QR_MODE_AN: {

return $this->checkModeAn($size, $data);

case QR_MODE_KJ: {

return $this->checkModeKanji($size, $data);

case QR_MODE_8B: {

return true;

case QR_MODE_ST: {

return true;

default: {

break;

return false;

protected function estimateBitStreamSize($items, $version) {

$bits = 0;

if ($version == 0) {

$version = 1;

foreach ($items as $item) {

switch($item['mode']) {

case QR_MODE_NM: {

$bits = $this->estimateBitsModeNum($item['size']);

break;

case QR_MODE_AN: {

$bits = $this->estimateBitsModeAn($item['size']);

break;

case QR_MODE_8B: {

$bits = $this->estimateBitsMode8($item['size']);
58

break;

case QR_MODE_KJ: {

$bits = $this->estimateBitsModeKanji($item['size']);

break;

case QR_MODE_ST: {

return STRUCTURE_HEADER_BITS;

default: {

return 0;

$l = $this->lengthIndicator($item['mode'], $version);

$m = 1 << $l;

$num = (int)(($item['size'] + $m - 1) / $m);

$bits += $num * (4 + $l);

return $bits;

protected function estimateVersion($items) {

$version = 0;

$prev = 0;

do {

$prev = $version;

$bits = $this->estimateBitStreamSize($items, $prev);

$version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);

if ($version < 0) {

return -1;

} while ($version > $prev);

return $version;

protected function lengthOfCode($mode, $version, $bits) {

$payload = $bits - 4 - $this->lengthIndicator($mode, $version);

switch($mode) {

case QR_MODE_NM: {

$chunks = (int)($payload / 10);

$remain = $payload - $chunks * 10;


59

$size = $chunks * 3;

if ($remain >= 7) {

$size += 2;

} elseif ($remain >= 4) {

$size += 1;

break;

case QR_MODE_AN: {

$chunks = (int)($payload / 11);

$remain = $payload - $chunks * 11;

$size = $chunks * 2;

if ($remain >= 6) {

++$size;

break;

case QR_MODE_8B: {

$size = (int)($payload / 8);

break;

case QR_MODE_KJ: {

$size = (int)(($payload / 13) * 2);

break;

case QR_MODE_ST: {

$size = (int)($payload / 8);

break;

default: {

$size = 0;

break;

$maxsize = $this->maximumWords($mode, $version);

if ($size < 0) {

$size = 0;

if ($size > $maxsize) {


60

$size = $maxsize;

return $size;

protected function createBitStream($items) {

$total = 0;

foreach ($items as $key => $item) {

$items[$key] = $this->encodeBitStream($item, $this->version);

$bits = count($items[$key]['bstream']);

$total += $bits;

return array($items, $total);

protected function convertData($items) {

$ver = $this->estimateVersion($items);

if ($ver> $this->version) {

$this->version = $ver;

for (;;) {

$cbs = $this->createBitStream($items);

$items = $cbs[0];

$bits = $cbs[1];

if ($bits < 0) {

return -1;

$ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);

if ($ver< 0) {

return -1;

} elseif ($ver> $this->version) {

$this->version = $ver;

} else {

break;

return $items;

protected function appendPaddingBit($bstream) {

$bits = count($bstream);

$maxwords = $this->getDataLength($this->version, $this->level);


61

$maxbits = $maxwords * 8;

if ($maxbits == $bits) {

return 0;

if ($maxbits - $bits < 5) {

return $this->appendNum($bstream, $maxbits - $bits, 0);

$bits += 4;

$words = (int)(($bits + 7) / 8);

$padding = array();

$padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0);

$padlen = $maxwords - $words;

if ($padlen> 0) {

$padbuf = array();

for ($i=0; $i<$padlen; ++$i) {

$padbuf[$i] = ($i&1)?0x11:0xec;

$padding = $this->appendBytes($padding, $padlen, $padbuf);

return $this->appendBitstream($bstream, $padding);

protected function mergeBitStream($items) {

$items = $this->convertData($items);

$bstream = array();

foreach ($items as $item) {

$bstream = $this->appendBitstream($bstream, $item['bstream']);

return $bstream;

protected function getBitStream($items) {

$bstream = $this->mergeBitStream($items);

return $this->appendPaddingBit($bstream);

protected function getByteStream($items) {

$bstream = $this->getBitStream($items);

return $this->bitstreamToByte($bstream);

protected function allocate($setLength) {

return array_fill(0, $setLength, 0);


62

protected function newFromNum($bits, $num) {

$bstream = $this->allocate($bits);

$mask = 1 << ($bits - 1);

for ($i=0; $i<$bits; ++$i) {

if ($num& $mask) {

$bstream[$i] = 1;

} else {

$bstream[$i] = 0;

$mask = $mask >>1;

return $bstream;

protected function newFromBytes($size, $data) {

$bstream = $this->allocate($size * 8);

$p=0;

for ($i=0; $i<$size; ++$i) {

$mask = 0x80;

for ($j=0; $j<8; ++$j) {

if ($data[$i] & $mask) {

$bstream[$p] = 1;

} else {

$bstream[$p] = 0;

$p++;

$mask = $mask >>1;

return $bstream;

protected function appendBitstream($bitstream, $append) {

if ((!is_array($append)) OR (count($append) == 0)) {

return $bitstream;

if (count($bitstream) == 0) {

return $append;

return array_values(array_merge($bitstream, $append));


63

protected function appendNum($bitstream, $bits, $num) {

if ($bits == 0) {

return 0;

$b = $this->newFromNum($bits, $num);

return $this->appendBitstream($bitstream, $b);

protected function appendBytes($bitstream, $size, $data) {

if ($size == 0) {

return 0;

$b = $this->newFromBytes($size, $data);

return $this->appendBitstream($bitstream, $b);

protected function bitstreamToByte($bstream) {

$size = count($bstream);

if ($size == 0) {

return array();

$data = array_fill(0, (int)(($size + 7) / 8), 0);

$bytes = (int)($size / 8);

$p = 0;

for ($i=0; $i<$bytes; $i++) {

$v = 0;

for ($j=0; $j<8; $j++) {

$v = $v <<1;

$v |= $bstream[$p];

$p++;

$data[$i] = $v;

if ($size & 7) {

$v = 0;

for ($j=0; $j<($size & 7); $j++) {

$v = $v <<1;

$v |= $bstream[$p];

$p++;

}
64

$data[$bytes] = $v;

return $data;

protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) {

$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !==


false)?$replLen:strlen($repl));

return $srctab;

protected function getDataLength($version, $level) {

return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level];

protected function getECCLength($version, $level){

return $this->capacity[$version][QRCAP_EC][$level];

protected function getWidth($version) {

return $this->capacity[$version][QRCAP_WIDTH];

protected function getRemainder($version) {

return $this->capacity[$version][QRCAP_REMINDER];

protected function getMinimumVersion($size, $level) {

for ($i=1; $i<= QRSPEC_VERSION_MAX; ++$i) {

$words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level];

if ($words >= $size) {

return $i;

return -1;

protected function lengthIndicator($mode, $version) {

if ($mode == QR_MODE_ST) {

return 0;

if ($version <= 9) {

$l = 0;

} elseif ($version <= 26) {

$l = 1;

} else {

$l = 2;
65

return $this->lengthTableBits[$mode][$l];

protected function maximumWords($mode, $version) {

if ($mode == QR_MODE_ST) {

return 3;

if ($version <= 9) {

$l = 0;

} else if ($version <= 26) {

$l = 1;

} else {

$l = 2;

$bits = $this->lengthTableBits[$mode][$l];

$words = (1 << $bits) - 1;

if ($mode == QR_MODE_KJ) {

$words *= 2; // the number of bytes is required

return $words;

protected function getEccSpec($version, $level, $spec) {

if (count($spec) < 5) {

$spec = array(0, 0, 0, 0, 0);

$b1 = $this->eccTable[$version][$level][0];

$b2 = $this->eccTable[$version][$level][1];

$data = $this->getDataLength($version, $level);

$ecc = $this->getECCLength($version, $level);

if ($b2 == 0) {

$spec[0] = $b1;

$spec[1] = (int)($data / $b1);

$spec[2] = (int)($ecc / $b1);

$spec[3] = 0;

$spec[4] = 0;

} else {

$spec[0] = $b1;

$spec[1] = (int)($data / ($b1 + $b2));

$spec[2] = (int)($ecc / ($b1 + $b2));


66

$spec[3] = $b2;

$spec[4] = $spec[1] + 1;

return $spec;

protected function putAlignmentMarker($frame, $ox, $oy) {

$finder = array(

"\xa1\xa1\xa1\xa1\xa1",

"\xa1\xa0\xa0\xa0\xa1",

"\xa1\xa0\xa1\xa0\xa1",

"\xa1\xa0\xa0\xa0\xa1",

"\xa1\xa1\xa1\xa1\xa1"

);

$yStart = $oy - 2;

$xStart = $ox - 2;

for ($y=0; $y < 5; $y++) {

$frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]);

return $frame;

protected function putAlignmentPattern($version, $frame, $width) {

if ($version < 2) {

return $frame;

$d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0];

if ($d < 0) {

$w = 2;

} else {

$w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2);

if ($w * $w - 3 == 1) {

$x = $this->alignmentPattern[$version][0];

$y = $this->alignmentPattern[$version][0];

$frame = $this->putAlignmentMarker($frame, $x, $y);

return $frame;

$cx = $this->alignmentPattern[$version][0];

$wo = $w - 1;

for ($x=1; $x < $wo; ++$x) {


67

$frame = $this->putAlignmentMarker($frame, 6, $cx);

$frame = $this->putAlignmentMarker($frame, $cx, 6);

$cx += $d;

$cy = $this->alignmentPattern[$version][0];

for ($y=0; $y < $wo; ++$y) {

$cx = $this->alignmentPattern[$version][0];

for ($x=0; $x < $wo; ++$x) {

$frame = $this->putAlignmentMarker($frame, $cx, $cy);

$cx += $d;

$cy += $d;

return $frame;

protected function getVersionPattern($version) {

if (($version < 7) OR ($version > QRSPEC_VERSION_MAX)) {

return 0;

return $this->versionPattern[($version - 7)];

protected function getFormatInfo($mask, $level) {

if (($mask < 0) OR ($mask > 7)) {

return 0;

if (($level < 0) OR ($level > 3)) {

return 0;

return $this->formatInfo[$level][$mask];

protected function putFinderPattern($frame, $ox, $oy) {

$finder = array(

"\xc1\xc1\xc1\xc1\xc1\xc1\xc1",

"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",

"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",

"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",

"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",

"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",

"\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
68

);

for ($y=0; $y < 7; $y++) {

$frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]);

return $frame;

protected function createFrame($version) {

$width = $this->capacity[$version][QRCAP_WIDTH];

$frameLine = str_repeat ("\0", $width);

$frame = array_fill(0, $width, $frameLine);

// Finder pattern

$frame = $this->putFinderPattern($frame, 0, 0);

$frame = $this->putFinderPattern($frame, $width - 7, 0);

$frame = $this->putFinderPattern($frame, 0, $width - 7);

// Separator

$yOffset = $width - 7;

for ($y=0; $y < 7; ++$y) {

$frame[$y][7] = "\xc0";

$frame[$y][$width - 8] = "\xc0";

$frame[$yOffset][7] = "\xc0";

++$yOffset;

$setPattern = str_repeat("\xc0", 8);

$frame = $this->qrstrset($frame, 0, 7, $setPattern);

$frame = $this->qrstrset($frame, $width-8, 7, $setPattern);

$frame = $this->qrstrset($frame, 0, $width - 8, $setPattern);

// Format info

$setPattern = str_repeat("\x84", 9);

$frame = $this->qrstrset($frame, 0, 8, $setPattern);

$frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8);

$yOffset = $width - 8;

for ($y=0; $y < 8; ++$y,++$yOffset) {

$frame[$y][8] = "\x84";

$frame[$yOffset][8] = "\x84";

// Timing pattern

$wo = $width - 15;

for ($i=1; $i< $wo; ++$i) {

$frame[6][7+$i] = chr(0x90 | ($i& 1));


69

$frame[7+$i][6] = chr(0x90 | ($i& 1));

// Alignment pattern

$frame = $this->putAlignmentPattern($version, $frame, $width);

// Version information

if ($version >= 7) {

$vinf = $this->getVersionPattern($version);

$v = $vinf;

for ($x=0; $x<6; ++$x) {

for ($y=0; $y<3; ++$y) {

$frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));

$v = $v >>1;

$v = $vinf;

for ($y=0; $y<6; ++$y) {

for ($x=0; $x<3; ++$x) {

$frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));

$v = $v >>1;

// and a little bit...

$frame[$width - 8][8] = "\x81";

return $frame;

protected function newFrame($version) {

if (($version < 1) OR ($version > QRSPEC_VERSION_MAX)) {

return NULL;

if (!isset($this->frames[$version])) {

$this->frames[$version] = $this->createFrame($version);

if (is_null($this->frames[$version])) {

return NULL;

return $this->frames[$version];

protected function rsBlockNum($spec) {


70

return ($spec[0] + $spec[3]);

protected function rsBlockNum1($spec) {

return $spec[0];

protected function rsDataCodes1($spec) {

return $spec[1];

protected function rsEccCodes1($spec) {

return $spec[2];

protected function rsBlockNum2($spec) {

return $spec[3];

protected function rsDataCodes2($spec) {

return $spec[4];

protected function rsEccCodes2($spec) {

return $spec[2];

protected function rsDataLength($spec) {

return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);

} protected function rsEccLength($spec) {

return ($spec[0] + $spec[3]) * $spec[2];

protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {

foreach ($this->rsitems as $rs) {

if (($rs['pad'] != $pad) OR ($rs['nroots'] != $nroots) OR ($rs['mm'] != $symsize)

OR ($rs['gfpoly'] != $gfpoly) OR ($rs['fcr'] != $fcr) OR ($rs['prim'] != $prim)) {

continue;

return $rs;

$rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);

array_unshift($this->rsitems, $rs);

return $rs;

protected function modnn($rs, $x) {

while ($x >= $rs['nn']) {


71

$x -= $rs['nn'];

$x = ($x >> $rs['mm']) + ($x & $rs['nn']);

return $x; if (($symsize< 0) OR ($symsize> 8)) {

return $rs;

if (($fcr< 0) OR ($fcr>= (1<<$symsize))) {

return $rs;

if (($prim <= 0) OR ($prim >= (1<<$symsize))) {

return $rs;

if (($nroots< 0) OR ($nroots>= (1<<$symsize))) {

return $rs;

if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) {

return $rs;

$rs = array();

$rs['mm'] = $symsize;

$rs['nn'] = (1 << $symsize) - 1;

$rs['pad'] = $pad;

$rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0);

$rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0);

// PHP style macro replacement ;)

$NN =& $rs['nn'];

$A0 =& $NN;

// Generate Galois field lookup tables

$rs['index_of'][0] = $A0; // log(zero) = -inf

$rs['alpha_to'][$A0] = 0; // alpha**-inf = 0

$sr = 1;

for ($i=0; $i<$rs['nn']; ++$i) {

$rs['index_of'][$sr] = $i;

$rs['alpha_to'][$i] = $sr;

$sr<<= 1;

if ($sr& (1 << $symsize)) {

$sr ^= $gfpoly;

$sr&= $rs['nn'];
72

if ($sr != 1) {

// field generator polynomial is not primitive!

return NULL;

// Form RS code generator polynomial from its roots

$rs['genpoly'] = array_fill(0, ($nroots + 1), 0);

$rs['fcr'] = $fcr;

$rs['prim'] = $prim;

$rs['nroots'] = $nroots;

$rs['gfpoly'] = $gfpoly;

// Find prim-th root of 1, used in decoding

for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) {

; // intentional empty-body loop!

$rs['iprim'] = (int)($iprim / $prim);

$rs['genpoly'][0] = 1;

for ($i = 0,$root=$fcr*$prim; $i< $nroots; $i++, $root += $prim) {

$rs['genpoly'][$i+1] = 1;

// Multiply rs->genpoly[] by @**(root + x)

for ($j = $i; $j > 0; --$j) {

if ($rs['genpoly'][$j] != 0) {

$rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs,


$rs['index_of'][$rs['genpoly'][$j]] + $root)];

} else {

$rs['genpoly'][$j] = $rs['genpoly'][$j-1];

// rs->genpoly[0] can never be zero

$rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)];

// convert rs->genpoly[] to index form for quicker encoding

for ($i = 0; $i<= $nroots; ++$i) {

$rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]];

return $rs;

protected function encode_rs_char($rs, $data, $parity) {


73

$MM =& $rs['mm']; // bits per symbol

$NN =& $rs['nn']; // the total number of symbols in a RS block

$ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in
index (log) form to polynomial form

$INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in
polynomial form to index (log) form

$GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index
form

$NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the
number of parity symbols in a block

$FCR =& $rs['fcr']; // first consecutive root, index form

$PRIM =& $rs['prim']; // primitive element, index form

$IPRIM =& $rs['iprim']; // prim-th root of 1, index form

$PAD =& $rs['pad']; // the number of pad symbols in a block

$A0 =& $NN;

$parity = array_fill(0, $NROOTS, 0);

for ($i=0; $i< ($NN - $NROOTS - $PAD); $i++) {

$feedback = $INDEX_OF[$data[$i] ^ $parity[0]];

if ($feedback != $A0) {

// feedback term is non-zero

// This line is unnecessary when GENPOLY[NROOTS] is unity, as it must

// always be for the polynomials constructed by init_rs()

$feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback);

for ($j=1; $j < $NROOTS; ++$j) {

$parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])];

// Shift

array_shift($parity);

if ($feedback != $A0) {

array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]);

} else {

array_push($parity, 0);

return $parity;

} // end QRcode class

} // END OF "class_existsQRcode"
74

?>

OUTPUT
Login Page

Admin Site
75

Librarian Site

Faculty and Student Login


76

Attendance site
77

Generate ID card

QR code generator

AddBooks
78

Viewbook
79

RESULT
Thus the Library Management System with database connectivity was implemented successfully.
80

Ex.no:08 TEST THE SOFTWARE SYSTEM FOR ALL THE SCENARIOS IDENTIFIED
Date:02.04.2024 AS PER THE USE CASE DIAGRAM

AIM
To test the software system for all the scenarios as per the use case diagram

TESTING:

Black Box Testing:

Black box testing is a testing technique in which the internal workings of the software are not
known to the tester. The tester only focuses on the input and output of the software.

Decision table testing:

Decision Table Testing is a Black Box test design technique (behavioral or behavior-based
technique), used where different combinations of test input conditions result in different
outcomes. When a system has complex business rules, then the decision table testing technique
helps in identifying the correct test cases.

Condition1 Condition2 Expected Output


Alert "Incorrect
Username is empty Password is empty username or
password", redirect to
signup

Username is 'admin' Password is 'admin1234' Redirect to home page


Username and Display user details
Password set Match database record and redirect to home
Username and Do not match database record Alert "Incorrect
Password set username or
password"

White Box Testing

White box testing, also known as clear box testing, glass box testing, or structural testing, is a software
testing technique that evaluates the internal workings of an application, system, or component. Unlike black
box testing, where testers are primarily concerned with the external behavior of the software, white box
testing examines the internal structures, code paths, and implementation details of the software.
81

 Product :Library Management System


 Module :Book Available
 Techniques: Branch Coverage

def is_book_available(book_id):
if book_id in library_books:
if library_books[book_id]['status'] == 'available':
return True
else:
return False
else:return False

Action to Expected Result Actual Result Pass/Fail


perform
Test if a book If the book is in the
is available in library , return True. As expected Pass
the library. Else False

Input And Result:

Input Expected Result Actual Result Pass/Fail


Existing Book True True Pass
ID with status
'available'
Non-existing False False Pass
Book ID
Existing Book False False Pass
ID with status
'unavailable'

 Product :Library Management System


 Module :id card Generation
 Techniques:Statement Coverage

def generate_id_card(name, id_number):


if not name or not id_number:
return None
id_card = f"Name: {name}, ID: {id_number}"
return id_card
name = "John Doe"
82

id_number = "12345"
id_card = generate_id_card(name, id_number)
print(id_card)

Action to Expected Result Actual Result Pass/Fail


Perform
Call function Return ID card string "Name: John Doe, ID: Pass
with valid with provided name and 12345" is returned
name and ID ID number
number
Call function Return None None is returned Pass
with empty
name

Scenario:
Total Number of Statements =6
Number of Executed Statements=6
Formula:
Statement Coverage = (Total Executable Statements/Number of Executed Statements)*100%

=(6/6)*100%
=100%
The statement coverage for this scenario is 100%.
83

Result:
Thus, as per the use case diagram, the software system for all the scenarios was tested using black box and
white box testing techniques
84

Ex.no:09&10 IMPROVE THE REUSABILITY AND MAINTAINABILITY OF THE


Date:16.04.2024
SOFTWARE SYSTEM BY APPLYING APPROPRIATE DESIGN PATTERNS
AND TEST IT FOR VARIOUS SCENARIOS

AIM
To Improve the reusability and maintainability of the software system by applying appropriate design
patterns and test it for various scenarios.
DESIGN PATTERN
Design patterns are communicating objects and classes that are customized to solve a general design
problem in a particular context. Software design patterns are general, reusable solutions to common
problems that arise during the design and development of software. They represent best practices for solving
certain types of problems and provide a way for developers to communicate about effective design solutions.

OBSERVER DESIGN PATTERN:


The Observer pattern defines a one-to-many dependency between objects, where one object (the
subject) maintains a list of its dependents (observers) and notifies them of any state changes,
usually by calling one of their methods.
Observer pattern can be applied to a Library management system:
Subject (Publisher): This is the object that maintains a list of observers and sends notifications
to them when its state changes. It provides methods for attaching, detaching, and notifying
observers.
Observer (Subscriber): This is the interface or abstract class that defines the contract for
objects that want to be notified of changes in the subject&#39;s state. Observers implement an update
method that is called by the subject when a change occurs.
Concrete Subject (Concrete Publisher): This is a specific implementation of the subject
interface. It holds the actual state and triggers notifications to observers when the state changes.
Concrete Observer (Concrete Subscriber): This is a specific implementation of the observer
interface. It registers with a subject to receive notifications and defines how it responds to
updates from the subject.
85

Behaviour Design Pattern (Observer)

RESULT

Thus, the reusability and maintainability of the software system were improved by applying
appropriate design patterns and tested for various scenarios.
86

Ex.no:11

Date:23.04.2024 DATA FLOW DIAGRAM

AIM

To draw the Data Flow Diagram for Library Management System

DATA FLOW DIAGRAM:

A Data Flow Diagram (DFD) is a graphical representation of the flow of data within a system.

It's a modeling technique used in software engineering to visualize how data moves through

various processes or modules in a system. DFDs are particularly useful for understanding the

data flow and transformations that occur within a system without getting into the finer details of

implementation.

Here's a basic overview of the components and symbols used in a DFD:

Processes: Represented by rectangles, processes depict activities or transformations that occur

within the system. Each process takes input data, performs some operation, and produces output

data.

Data Flows: Represented by arrows, data flows indicate the movement of data between

processes, data stores, and external entities. They show the direction in which data is flowing.

Data Stores: Represented by open-ended rectangles, data stores depict where data is stored

within the system. They can represent databases, files, or any other storage mechanism.

External Entities: Represented by squares, external entities represent sources or destinations of

data that exist outside the system being modeled. These could be users, other systems, or

external data sources.


87

PROCEDURE:

Identify Classes: Review the DFD to identify processes, data stores, and external entities that

can be represented as classes.

Create Classes: Use modeling software to add classes to the Class Diagram.

Specify Details: Add attributes, operations, parameters, and data types to each class.

Denote Relationships: Establish relationships between classes using generalizations,

associations, multiplicities, and cardinalities.

Save: Save the Class Diagram file for future reference and collaboration.

1.Level 0 DFD
88

2. Level 1 DFD

RESULT
Thus the data flow diagram for identified requirements was drawn successfully.

You might also like