-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabel_barang.php
317 lines (298 loc) · 10.6 KB
/
tabel_barang.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
session_start();
if (isset($_POST['logout'])) {
session_destroy();
header("location:login.php?status=logout");
}
if (!isset($_SESSION['user_login'])) {
header("location:login.php");
}
include('connect.php');
?>
<?php
include("connect.php");
$result = mysqli_query($conn, "SELECT * FROM barang ORDER BY id DESC");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" href="resource/icon.png" />
<title>TABEL BARANG</title>
<link rel='stylesheet' href='resource/bootstrap.min.css'>
<link rel="stylesheet" href="resource/icon.css">
<style>
* {
box-sizing: border-box;
}
.tableFixHead { margin-right:15px; margin-left:15px;overflow-y: auto; height: 450px;}
/* Just common table stuff. */
table { border-collapse: collapse; width: 100%; }
th, td { padding: 0px 0px; }
th { background:#eee; }
#confirmBox
{
display: none;
background-color: #eee;
border-radius: 5px;
border: 1px solid #aaa;
position: fixed;
width: 300px;
left: 50%;
margin-left: -150px;
padding: 6px 8px 8px;
box-sizing: border-box;
text-align: center;
}
#confirmBox button
{
background-color: #ccc;
display: inline-block;
border-radius: 3px;
border: 1px solid #aaa;
padding: 2px;
text-align: center;
width: 80px;
cursor: pointer;
}
#confirmBox button:hover
{
background-color: #ddd;
}
#confirmBox .message
{
text-align: left;
margin-bottom: 8px;
}
#myInput {
background-image: url('searchicon.png');
background-position: 10px 10px;
background-size:20px;
background-repeat: no-repeat;
font-size: 16px;
padding: 12px 20px 12px 40px;
margin-bottom: 20px;
margin-top: 20px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 10px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
body{
font-family: 'Trebuchet MS', serif;
}
</style>
</head>
<body>
<?php
include('resource/navbar.php');
?>
<div class="contanier-fluid">
<div class="row">
<div class="col-12 text-center" style="margin-top:30px;margin-bottom:0px;">
<h2 class='display-4'>TABEL BARANG</h2>
</div>
</div>
<div class="row">
<div class="col-3"></div>
<div class="col-1"><i class="material-icons align-text-top"></i>
<a href="form_barang.php" class='btn btn-dark ' style='margin-top: -5px;margin-left: 60px'><i class="material-icons align-text-top">playlist_add</i></a>
</div>
<div class="col-4">
<input type="text" class='form-control' id="myInput" placeholder="Cari..." title="Type in a name">
</div>
<div class="col-3"></div>
</div>
<div class="row">
<div class="col-12">
<div class="tableFixHead">
<table class='table table-hover' id="myTable" >
<thead>
<tr class="header">
<th onclick="sortTable(0)">Nama Barang<i class="material-icons align-text-top">sort</i></th>
<th>Jumlah</th>
<th>Rusak</th>
<th>Servis</th>
<th>Yang Tersedia</th>
<th onclick="sortTable(5)">Tahun Beli <i class="material-icons align-text-top">sort</i></th>
<th onclick="sortTable(6)">Pemilik <i class="material-icons align-text-top">sort</i></th>
<th onclick="sortTable(7)">Lokasi <i class="material-icons align-text-top">sort</i></th>
<th>Opsi</th>
</tr>
</thead>
<tbody id='myTable1'>
<?php
if(isset($_POST['lokasi'])){
$loc = (string)$_POST['lokasi'];
$sql = mysqli_query($conn,"select * from barang where lokasi ='$loc'");
if($loc == ''){
$sql = mysqli_query($conn,"select * from barang");
}
}
elseif (isset($_GET['back'])) {
$sql = mysqli_query($conn,"select * from barang");
}
else{
$sql = mysqli_query($conn,"select * from barang");
}
while($user_data = mysqli_fetch_array($sql)) {
$available = $user_data['jumlah'] - $user_data['jumlah_rusak'] - $user_data['jumlah_servis']-$user_data['jumlah_pinjam'];
echo "<tr>";
echo "<td class='align-middle text-capitalize'>".$user_data['nama_barang']."</td>";
echo "<td class='align-middle'>".$user_data['jumlah']."</td>";
echo "<td class='align-middle'>".$user_data['jumlah_rusak']."</td>";
echo "<td class='align-middle'>".$user_data['jumlah_servis']."</td>";
echo "<td class='align-middle'>".$available."</td>";
$owner = $user_data['owner'];
$data1 = mysqli_query($conn,"select owner from owner where id = $owner");
$d1 = mysqli_fetch_array($data1);
echo "<td class='align-middle'>".$user_data['tahun_beli']."</td>";
echo "<td class='align-middle'>".$d1['owner']."</td>";
$lokasi = $user_data['lokasi'];
$data2 = mysqli_query($conn,"select lokasi from lokasi where id = $lokasi");
$d2 = mysqli_fetch_array($data2);
echo "<td class='align-middle'>".$d2['lokasi']."</td>";
?>
<td><a class='btn btn-primary btn-sm' href="edit_barang.php?id=<?php echo $user_data['id']; ?>"><i class='material-icons align-text-top'>create</i></a>
<a class='btn btn-danger btn-sm confirmation' href="delete_barang.php?id=<?php echo $user_data['id']; ?>"><i class='material-icons align-text-top'>delete</i></a> </td></tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var elems = document.getElementsByClassName('confirmation');
var confirmIt = function (e) {
if (!confirm('Apakah anda yakin ingin menghapus?')) e.preventDefault();
};
for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', confirmIt, false);
}
</script>
<script>function doConfirm(msg, yesFn, noFn)
{
var confirmBox = $("#confirmBox");
confirmBox.find(".message").text(msg);
confirmBox.find(".yes,.no").unbind().click(function()
{
confirmBox.hide();
});
confirmBox.find(".yes").click(yesFn);
confirmBox.find(".no").click(noFn);
confirmBox.show();
}</script>
<script src="resource/jquery-3.3.1.slim.min.js" ></script>
<script src="resource/popper.min.js" ></script>
<script src="resource/bootstrap1.min.js"></script>
<script src="resource/bootstrap.min.js" ></script>
<script src="resource/bootstrap.bundle.min.js"></script>
<script src="resource/jquery.min.js"></script>
<script>
// function myFunction() {
// var input, filter, table, tr, td, i, txtValue;
// input = document.getElementById("myInput");
// filter = input.value.toUpperCase();
// table = document.getElementById("myTable");
// tr = table.getElementsByTagName("tr");
// for (i = 0; i < tr.length; i++) {
// td = tr[i].getElementsByTagName("td")[0];
// if (td) {
// txtValue = td.textContent || td.innerText;
// if (txtValue.toUpperCase().indexOf(filter) > -1) {
// tr[i].style.display = "";
// } else {
// tr[i].style.display = "none";
// }
// }
// }
// }
function sortTable(n) {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
table = document.getElementById("myTable");
switching = true;
//Set the sorting direction to ascending:
dir = "asc";
/*Make a loop that will continue until
no switching has been done:*/
while (switching) {
//start by saying: no switching is done:
switching = false;
rows = table.rows;
/*Loop through all table rows (except the
first, which contains table headers):*/
for (i = 1; i < (rows.length - 1); i++) {
//start by saying there should be no switching:
shouldSwitch = false;
/*Get the two elements you want to compare,
one from current row and one from the next:*/
x = rows[i].getElementsByTagName("TD")[n];
y = rows[i + 1].getElementsByTagName("TD")[n];
/*check if the two rows should switch place,
based on the direction, asc or desc:*/
if (dir == "asc") {
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
//if so, mark as a switch and break the loop:
shouldSwitch= true;
break;
}
} else if (dir == "desc") {
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
//if so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
}
if (shouldSwitch) {
/*If a switch has been marked, make the switch
and mark that a switch has been done:*/
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
//Each time a switch is done, increase this count by 1:
switchcount ++;
} else {
/*If no switching has been done AND the direction is "asc",
set the direction to "desc" and run the while loop again.*/
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}
}
}
</script>
<script>
$(document).ready(function(){
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myTable1 tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
<script>var $th = $('.tableFixHead').find('thead th')
$('.tableFixHead').on('scroll', function() {
$th.css('transform', 'translateY('+ this.scrollTop +'px)');
});
</script>
</body>
</html>