This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtambah-kenshin.php
154 lines (118 loc) · 4.3 KB
/
tambah-kenshin.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
<?php require_once('includes/init.php'); ?>
<?php cek_login($role = array(1, 2)); ?>
<?php
$errors = array();
$sukses = false;
$nama_kenshin = (isset($_POST['nama_kenshin'])) ? trim($_POST['nama_kenshin']) : '';
$kriteria = (isset($_POST['kriteria'])) ? $_POST['kriteria'] : array();
//var_dump($result);
//exit();
if(isset($_POST['submit'])):
// Validasi
//if(!$nama_kenshin) {
//$errors[] = 'Nomor kenshin tidak boleh kosong';
//}
// Jika lolos validasi lakukan hal di bawah ini
if(empty($errors)):
$handle = $pdo->prepare('INSERT INTO kenshin (nama_kenshin) VALUES (:nama_kenshin)');
$handle->execute( array(
'nama_kenshin' => $nama_kenshin
) );
$sukses = "kenshin no. <strong>{$nama_kenshin}</strong> berhasil dimasukkan.";
$id_kenshin = $pdo->lastInsertId();
// Jika ada kriteria yang diinputkan:
if(!empty($kriteria)):
foreach($kriteria as $id_kriteria => $nilai):
$handle = $pdo->prepare('INSERT INTO nilai_kenshin (id_kenshin, id_kriteria, nilai) VALUES (:id_kenshin, :id_kriteria, :nilai)');
$handle->execute( array(
'id_kenshin' => $id_kenshin,
'id_kriteria' => $id_kriteria,
'nilai' =>$nilai
) );
endforeach;
endif;
redirect_to('list-kenshin.php?status=sukses-baru');
endif;
endif;
?>
<?php
$judul_page = 'Penilaian UKT Kenshi';
require_once('template-parts/header.php');
?>
<div class="main-content-row">
<div class="container clearfix">
<?php include_once('template-parts/sidebar-kenshin.php'); ?>
<div class="main-content the-content">
<h1>Penilaian UKT Kenshi</h1>
<?php if(!empty($errors)): ?>
<div class="msg-box warning-box">
<p><strong>Error:</strong></p>
<ul>
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<form action="tambah-kenshin.php" method="post">
<div class="field-wrap clearfix">
<label>Nama Kenshin <span class="red">*</span></label>
<select name="select" id="select">
<?php
$query = $pdo->prepare('SELECT * FROM kenshin WHERE kyu_id = ' . $_GET['kyu']);
$query->execute();
// menampilkan berupa nama field
$query->setFetchMode(PDO::FETCH_ASSOC);
while($hasil = $query->fetch()):
echo "<option value='".$hasil['id_kenshin']."'>".$hasil['nama_kenshin']."</option>";
endwhile;
?>
</select>
</div>
<h3>Nilai Kriteria</h3>
<?php
$query = $pdo->prepare('SELECT id_kriteria, nama, ada_pilihan FROM kriteria WHERE kyu_id = ' . $_GET['kyu'] . ' ORDER BY urutan_order ASC');
$query->execute();
// menampilkan berupa nama field
$query->setFetchMode(PDO::FETCH_ASSOC);
if($query->rowCount() > 0):
while($kriteria = $query->fetch()):
?>
<div class="field-wrap clearfix">
<label><?php echo $kriteria['nama']; ?></label>
<?php if(!$kriteria['ada_pilihan']): ?>
<input type="number" step="0.001" name="kriteria[<?php echo $kriteria['id_kriteria']; ?>]">
<?php else: ?>
<select name="kriteria[<?php echo $kriteria['id_kriteria']; ?>]">
<option value="0">-- Pilih Variabel --</option>
<?php
$query3 = $pdo->prepare('SELECT * FROM pilihan_kriteria WHERE id_kriteria = :id_kriteria ORDER BY urutan_order ASC');
$query3->execute(array(
'id_kriteria' => $kriteria['id_kriteria']
));
// menampilkan berupa nama field
$query3->setFetchMode(PDO::FETCH_ASSOC);
if($query3->rowCount() > 0): while($hasl = $query3->fetch()):
?>
<option value="<?php echo $hasl['nilai']; ?>"><?php echo $hasl['nama']; ?></option>
<?php
endwhile; endif;
?>
</select>
<?php endif; ?>
</div>
<?php
endwhile;
else:
echo '<p>Kriteria masih kosong.</p>';
endif;
?>
<div class="field-wrap clearfix">
<button type="submit" name="submit" value="submit" class="button">Konfirmasi Nilai</button>
</div>
</form>
</div>
</div><!-- .container -->
</div><!-- .main-content-row -->
<?php
require_once('template-parts/footer.php');