-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalternatif.php
158 lines (139 loc) · 6.31 KB
/
alternatif.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
<?php
include './src/koneksi.php';
if (isset($_SESSION['pesan'])) {
$pesan = $_SESSION['pesan'];
unset($_SESSION['pesan']);
}
if (empty($_SESSION['id'])) {
header('location:./loginfirst.php');
}
$query = "SELECT idalternatif FROM tbalternatif ORDER BY idalternatif DESC LIMIT 1";
$result = $koneksi->query($query);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$lastIdAlternatif = $row["idalternatif"];
$nextIdAlternatif = "A" . ($row["idalternatif"] + 1);
$IdAlternatif = ($row["idalternatif"] + 1);
} else {
$nextIdAlternatif = "A1";
$IdAlternatif = "1";
}
$vnama = "";
$vketerangan = "";
if (isset($_GET['hal'])) {
if ($_GET['hal'] == "edit") {
$tampil = mysqli_query($koneksi, "SELECT * FROM tbalternatif WHERE idalternatif = '$_GET[id]'");
$data = mysqli_fetch_array($tampil);
if ($data) {
$IdAlternatif = $data['idalternatif'];
$nextIdAlternatif = 'A' . $data['idalternatif'];
$vnama = $data['namaalternatif'];
$vketerangan = $data['keteranganalternatif'];
}
}
if ($_GET['hal'] == "hapus") {
$cek = mysqli_query($koneksi, "SELECT * FROM tbalternatif WHERE idalternatif = '$_GET[id]'");
$data = mysqli_fetch_array($cek);
if ($data) {
$hapus = mysqli_query($koneksi, "DELETE FROM tbalternatif WHERE idalternatif = '$_GET[id]'");
$hapus1 = mysqli_query($koneksi, "DELETE FROM tbhitung WHERE idalternatif = '$_GET[id]'");
if ($hapus && $hapus1) {
session_start();
$_SESSION['pesan'] = 'hapus()';
header('location:./alternatif.php');
} else {
session_start();
$_SESSION['pesan'] = 'gagalhapus()';
header('location:./alternatif.php');
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SPK | Metode MOOSRA</title>
<?php include './src/header.php'; ?>
</head>
<body onload="<?= @$pesan ?>" class="select-none">
<?php include './src/navbar.php'; ?>
<section id="isi" class="max-w-7xl mx-auto">
<form action="./src/aksicrud.php" method="post" class="max-w-5xl mx-auto mt-12">
<div class="text-3xl text-transparent bg-clip-text bg-gradient-to-r from-primary via-secondary to-secondary font-bold">Data Alternatif</div>
<hr class="w-12 h-1 outline-none border-none bg-gradient-to-r from-primary via-primary to-secondary rounded-full mb-4">
<div class="grid grid-cols-2 items-center justify-between gap-4">
<div class="form-control">
<label class="label">
<span class="label-text flex">Kode Alternatif<div class="text-red-600">*</div></span>
</label>
<input type="text" name="tkode" readonly class="input input-bordered input-disabled bg-gray-800 border-2 border-gray-700" value="<?= $nextIdAlternatif; ?>" />
<input type="text" name="tkode1" readonly class="input input-bordered hidden" value="<?= $IdAlternatif; ?>" />
</div>
<div class="form-control">
<label class="label">
<span class="label-text">Keterangan</span>
</label>
<input type="text" name="tketeranganalternatif" value="<?= $vketerangan ?>" class="input input-bordered" />
</div>
<div class="form-control col-span-2">
<label class="label">
<span class="label-text flex">Nama Alternatif<div class="text-red-600">*</div></span>
</label>
<input type="text" name="tnamaalternatif" required value="<?= $vnama ?>" class="input input-bordered" />
</div>
<div class="col-span-2 w-full mx-auto flex items-center justify-center gap-3">
<button type="submit" name="balternatif" class="btn btn-primary">Simpan</button>
<a href="./alternatif.php" class="btn btn-secondary">Reset</a>
</div>
</div>
</form>
</section>
<section id="tabel">
<div class="overflow-x-auto max-w-5xl my-8 mx-auto dark:bg-base-300 shadow-md shadow-gray-700 p-8 rounded-lg">
<table class="table text-center" id="myTable">
<!-- head -->
<thead>
<tr>
<th>Kode Alternatif</th>
<th>Name Alternatif</th>
<th>Keterangan</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php
$q = "SELECT * FROM tbalternatif";
$query = mysqli_query($koneksi, $q) or die(mysqli_error($koneksi));
if (mysqli_num_rows($query) > 0) {
// Menampilkan data jika ada
while ($data = mysqli_fetch_array($query)) :
?>
<!-- row 1 -->
<tr>
<th><?= "A" . $data['idalternatif'] ?></th>
<th><?= $data['namaalternatif'] ?></th>
<th><?= $data['keteranganalternatif'] ?></th>
<th>
<a href="./alternatif.php?hal=edit&id=<?= $data['idalternatif'] ?>" class="btn btn-sm btn-primary">Edit</a>
<a href="./alternatif.php?hal=hapus&id=<?= $data['idalternatif'] ?>" class="btn btn-sm btn-secondary">Hapus</a>
</th>
</tr>
<?php
endwhile;
}
?>
</tbody>
</table>
</div>
</section>
<script>
$(document).ready(function() {
// Inisialisasi DataTables
$('#myTable').DataTable();
});
</script>
</body>
</html>