-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.php
More file actions
100 lines (85 loc) · 3.06 KB
/
Copy pathreport.php
File metadata and controls
100 lines (85 loc) · 3.06 KB
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
<?php
include 'functions.php';
session_start();
if (!isset($_SESSION['loggedin'])) {
header('Location: login.php');
exit;
}
if (!$_SESSION['su']) {
$_SESSION['msg'] = 'Sorry, hanya admin yang bisa akses page ini';
header('Location: index.php');
exit;
}
$msg = "";
if (isset($_SESSION['msg'])) {
$msg = $_SESSION['msg'];
$_SESSION['msg'] = "";
}
?>
<?=template_header('Report')?>
<div class="container-fluid content home">
<h2><i class="fa fa-file-alt fa-lg" style="margin-right: 10px"></i>Report</h2>
<?php
if ($msg != '') {
echo '<p>'. $msg .'</p>';
}
?>
<div>
<form action="report.php" method="get">
<div class="form-group">
<label for="query">Search</label>
<input type="text" class="form-control" name="query" placeholder="Cari berdasarkan nama, npm dan prodi" required>
</div>
<input type="submit" class="btn btn-info" value="Search">
</form>
</div>
<?php
if (isset($_GET['query'])) {
$pdo = pdo_connect_mysql();
$query = $_GET['query'];
$sql = "SELECT id, name, npm, prodi FROM accounts WHERE (name LIKE '%". $query ."%') OR (prodi LIKE '%". $query ."%') OR (npm LIKE '%". $query ."%')";
$stmt = $pdo->query($sql);
if ($stmt) {
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($users) == 0) {
$_SESSION['msg'] = 'Data tidak ditemukan';
header('Location: report.php');
exit;
} else {
echo '<p>Ditemukan '. count($users) . ' hasil pencarian</p>';
echo '<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<td scope="col">#</td>
<td scope="col">Name</td>
<td scope="col">NPM</td>
<td scope="col">Prodi</td>
<td scope="col">Action</td>
</tr>
</thead>
<tbody>';
$num = 1;
foreach ($users as $user) {
echo '<tr>
<th scope="row">'. $num .'</td>
<td>'. $user['name'] .'</td>
<td>'. $user['npm'] .'</td>
<td>'. $user['prodi'] .'</td>
<td class="actions">
<a href="view.php?id='. $user['id'] .'" class="view"><i class="fas fa-eye fa-xs"></i></a>
</td>
</tr>';
$num++;
}
echo '</tbody>
</table>';
}
} else {
$_SESSION['msg'] = 'Samting wen wrong sar';
header('Location: report.php');
exit;
}
}
?>
</div>
<?=template_footer()?>