-
Notifications
You must be signed in to change notification settings - Fork 0
/
book_inventory.php
188 lines (161 loc) · 5.33 KB
/
book_inventory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
function get_title(){
echo "bookstogo | Book Inventory";
}
function display_content() {
require_once('connection.php');
echo "
<div class='container-fluid bk-invnt-div'>
<div class='container'>
<div class='row'>
<form method='POST' action=''>
<div class='col-md-6'>
<h1>Book Inventory</h1>";
if (isset($_SESSION['username'])) {
echo'<a type="button" class="btn btn-default" href="add_book.php">Add</a>';
} else {
echo "";
}
echo"</div>
<div class='col-md-6'>
<div class='input-group search_trans'>
<span class='input-group-btn'>
<input type='text' class='form-control' placeholder='Search here' name='search_bk'>
</span>
<span class='input-group-btn'>
<select name='search_ddown' class='form-control'>
<option value='no_selected'>Search by:</option>
<option value='book_code'>Book Code</option>
<option value='book_title'>Book Title</option>
<option value='author'>Author</option>
<option value='category'>Category</option>
<option value='stocks'>Stock</option>
</select>
</span>
<span class='input-group-btn'>
<input type='submit' class='form-control' name='search-bk-btn' value='Search'>
</span>
</div>
</div>
</form>
</div>
</div>
</div>";
$sql = "SELECT * FROM books_record ORDER BY book_title ASC";
$show = mysqli_query($conn, $sql);
//----------------code for search-bk-btn----------------------
if (isset($_POST['search-bk-btn'])) {
$search_bk = $_POST['search_bk'];
$search_ddown = $_POST['search_ddown'];
$query = "SELECT * FROM books_record WHERE $search_ddown LIKE '%$search_bk%'";
if ($search_ddown == "no_selected") {
echo "Please select option provided on 'Search by:' drop-down.";
} else {
$result = mysqli_query($conn, $query);
echo "Search result for <em>$search_bk</em>. Found " .mysqli_num_rows($result). " result.<br><hr><br>";
if (mysqli_num_rows($result) > 0) {
echo "
<div class='container-fluid bk-invnt-div'>
<div class='container'>
<div>
<p><strong>(*Disclaimer: Some book titles and authors are searched from google. Credits to the owner.)</strong></p>
</div>
<div class='table-responsive'>
<table class='table table-bordered table-hover'>
<thead>
<tr>
<th>Book Code</th>
<th>Book Title</th>
<th>Author</th>
<th>Category</th>
<th>Stock</th>";
if(isset($_SESSION['username'])) {
echo "<th>Action</th>";
} else {
echo "<th style='display:none;'></th>";
}
echo "</tr>
</thead>
<tbody>";
while ($row = mysqli_fetch_assoc($result)) {
extract($row);
echo "<tr>
<td>".$row['book_code']."</td>
<td>".$row['book_title']."</td>
<td>".$row['author']."</td>
<td>".$row['category']."</td>
<td>".$row['stocks']."</td>";
if (isset($_SESSION['username'])) {
echo "<td>";
echo '<a type="button" class="btn btn-default" href="update_book.php?id='.$id.'">Update</a>
<a type="button" class="btn btn-default" href="delete_book.php?id='.$id.'">Delete</a>';
echo "</td>";
} else {
// echo "<td>Restricted. For Admin Only</td>";
echo "<td style='display:none;'></td>";
}
echo"</tr>";
}
echo "</tbody>
</table>
</div>
</div>
</div>";
}
}
}
//------------------------------------------------------------
else {
if (mysqli_num_rows($show) > 0) {
echo "
<div class='container-fluid bk-invnt-div'>
<div class='container'>
<div>
<p><strong>(*Disclaimer: Some book titles and authors are searched from google. Credits to the owner.)</strong></p>
</div>
<div class='table-responsive'>
<table class='table table-bordered table-hover'>
<thead>
<tr>
<th>Book Code</th>
<th>Book Title</th>
<th>Author</th>
<th>Category</th>
<th>Stock</th>";
if(isset($_SESSION['username'])) {
echo "<th>Action</th>";
} else {
echo "<th style='display:none;'></th>";
}
echo "</tr>
</thead>
<tbody>";
while ($row = mysqli_fetch_assoc($show)) {
extract($row);
echo "<tr>
<td>".$row['book_code']."</td>
<td>".$row['book_title']."</td>
<td>".$row['author']."</td>
<td>".$row['category']."</td>
<td>".$row['stocks']."</td>";
if (isset($_SESSION['username'])) {
echo "<td>";
echo '<a type="button" class="btn btn-default" href="update_book.php?id='.$id.'">Update</a>
<a type="button" class="btn btn-default" href="delete_book.php?id='.$id.'">Delete</a>';
echo "</td>";
} else {
// echo "<td>Restricted. For Admin Only</td>";
echo "<td style='display:none;'></td>";
}
echo"</tr>";
}
echo "</tbody>
</table>
</div>
</div>
</div>";
}
}
} //end of display content function
require_once('template.php');
?>