-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.php
197 lines (163 loc) · 6 KB
/
transaction.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
189
190
191
192
193
194
195
196
197
<?php
function get_title() {
echo "bookstogo | Transaction";
}
function display_content () {
require_once('connection.php');
echo"
<div class='container-fluid trans-div'>
<div class='container'>
<div class='row'>
<form method='POST' action=''>
<div class='col-md-6'>
<h1>Borrow Transaction</h1>
</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_brw'>
</span>
<span class='input-group-btn'>
<select name='search_ddown' class='form-control'>
<option value='no_selected'>Search by:</option>
<option value='student_number'>Student Number</option>
<option value='student_name'>Student Name</option>
<option value='book_code'>Book Code</option>
<option value='book_title'>Book Title</option>
<option value='author'>Author</option>
<option value='stocks'>Stock</option>
<option value='date_borrowed'>Date Borrowed</option>
<option value='due_date'>Due Date</option>
</select>
</span>
<span class='input-group-btn'>
<input type='submit' class='form-control' name='search_brw_btn' value='Search'>
</span>
</div>
</div>
</form>
</div>
</div>
</div>"; //end of first container
$sql = "SELECT sr.student_number,sr.student_name,br.book_code,br.book_title,br.author,br.stocks,bt.date_borrowed,bt.due_date,bt.id FROM borrowed_trans bt JOIN students_record sr ON bt.student_number_id = sr.student_number JOIN books_record br ON bt.book_record_id=br.id ORDER BY date_borrowed DESC";
$show = mysqli_query($conn,$sql);
//---------code for search borrow transaction------------
if (isset($_POST['search_brw_btn'])) {
$search_brw = $_POST['search_brw'];
$search_ddown = $_POST['search_ddown'];
$query = "SELECT * FROM borrowed_trans bt JOIN students_record sr ON bt.student_number_id = sr.student_number JOIN books_record br ON bt.book_record_id=br.id WHERE $search_ddown LIKE '%$search_brw%'";
if ($_POST['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_brw</em>. Found " .mysqli_num_rows($result). " result.<br><hr><br>";
if (mysqli_num_rows($result) > 0) {
echo "<div class='container-fluid trans-div'>
<div class='container'>
<div class='table-responsive'>
<table class='table table-bordered table-hover'>
<thead>
<tr>
<th>Student Number</th>
<th>Student Name</th>
<th>Book Code</th>
<th>Book Title</th>
<th>Author</th>
<th>Stock</th>
<th>Date Borrowed</th>
<th>Due Date</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['student_number']."</td>
<td>".$row['student_name']."</td>
<td>".$row['book_code']."</td>
<td>".$row['book_title']."</td>
<td>".$row['author']."</td>
<td>".$row['stocks']."</td>
<td>".$row['date_borrowed']."</td>
<td>".$row['due_date']."</td>";
if (isset($_SESSION['username'])) {
echo" <td>";
echo'<a type="button" class="btn btn-default" href="return_book.php?bt-id='.$id.'">Return Book</a>';
echo" </td>";
} else {
// echo "<td>Restricted. For Admin Only</td>";
echo "<td style='display:none;'></td>";
}
echo" </tr>";
} //end of while
echo "</tbody>
</table>
</div>
</div>
</div>
";
} //end of if num rows $result
}
} //end of search brw btn
//---------------------------------
else {
if (mysqli_num_rows($show) > 0) {
echo"
<div class='container-fluid trans-div'>
<div class='container '>
<div class='table-responsive'>
<table class='table table-bordered table-hover'>
<thead>
<tr>
<th>Student Number</th>
<th>Student Name</th>
<th>Book Code</th>
<th>Book Title</th>
<th>Author</th>
<th>Stock</th>
<th>Date Borrowed</th>
<th>Due Date</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['student_number']."</td>
<td>".$row['student_name']."</td>
<td>".$row['book_code']."</td>
<td>".$row['book_title']."</td>
<td>".$row['author']."</td>
<td>".$row['stocks']."</td>
<td>".$row['date_borrowed']."</td>
<td>".$row['due_date']."</td>";
if (isset($_SESSION['username'])) {
echo" <td>";
echo'<a type="button" class="btn btn-default" href="return_book.php?bt-id='.$id.'">Return Book</a>';
echo"</td>";
} else {
// echo "<td>Restricted. For Admin Only</td>";
echo "<td style='display:none;'></td>";
}
echo"</tr>";
} //end of while
echo "</tbody>
</table>
</div>
</div>
</div>";
} //end of if-show
} //end of else
} //end of display content function
require_once('template.php');
?>