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
/
tambah-kriteria.php
174 lines (142 loc) · 5.26 KB
/
tambah-kriteria.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
<?php require_once('includes/init.php'); ?>
<?php
$errors = array();
$sukses = false;
$nama = (isset($_POST['nama'])) ? trim($_POST['nama']) : '';
$type = (isset($_POST['type'])) ? trim($_POST['type']) : '';
$bobot = (isset($_POST['bobot'])) ? trim($_POST['bobot']) : '';
$jenis_nilai = (isset($_POST['jenis_nilai'])) ? trim($_POST['jenis_nilai']) : 0;
$pilihan = (isset($_POST['pilihan'])) ? $_POST['pilihan'] : '';
$urutan_order = (isset($_POST['urutan_order'])) ? trim($_POST['urutan_order']) : '0';
$kyu_id = (isset($_POST['kyu_id'])) ? trim($_POST['kyu_id']) : '';
if(isset($_POST['submit'])):
// Validasi Nama Kriteria
if(!$nama) {
$errors[] = 'Nama kriteria tidak boleh kosong';
}
// Validasi Tipe
if(!$type) {
$errors[] = 'Type kriteria tidak boleh kosong';
}
// Validasi Bobot
if(!$bobot) {
$errors[] = 'Bobot kriteria tidak boleh kosong';
}
// Jika lolos validasi lakukan hal di bawah ini
if(empty($errors)):
$handle = $pdo->prepare('INSERT INTO kriteria (nama, type, bobot, urutan_order, ada_pilihan, kyu_id) VALUES (:nama, :type, :bobot, :urutan_order, :jenis_nilai, :kyu_id)');
$handle->execute( array(
'nama' => $nama,
'type' => $type,
'bobot' => $bobot,
'urutan_order' => $urutan_order,
'jenis_nilai' => $jenis_nilai,
'kyu_id' => $kyu_id,
) );
$id_kriteria = $pdo->lastInsertId();
if($id_kriteria && $jenis_nilai == 1 && !empty($pilihan)): foreach($pilihan as $pil):
$nama = (isset($pil['nama'])) ? trim($pil['nama']) : '';
$nilai = (isset($pil['nilai'])) ? floatval($pil['nilai']) : '';
$urutan_order = (isset($pil['urutan']) && $pil['urutan']) ? (int) trim($pil['urutan']) : 0;
if($nama != '' && ($nilai >= 0)):
$prepare_query = 'INSERT INTO pilihan_kriteria (nama, id_kriteria, nilai, urutan_order) VALUES (:nama, :id_kriteria, :nilai, :urutan_order)';
$data = array(
'nama' => $nama,
'id_kriteria' => $id_kriteria,
'nilai' => $nilai,
'urutan_order' => $urutan_order
);
$handle = $pdo->prepare($prepare_query);
$sukses = $handle->execute($data);
endif;
endforeach; endif;
redirect_to('list-kriteria.php?status=sukses-baru&kyu='.$kyu_id);
endif;
endif;
?>
<?php
$judul_page = 'Tambah User';
require_once('template-parts/header.php');
?>
<div class="main-content-row">
<div class="container clearfix">
<?php include_once('template-parts/sidebar-kriteria.php'); ?>
<div class="main-content the-content">
<h1>Tambah Kriteria</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 id="form-add">
<Input type="hidden" name="kyu_id" value="<?=$_GET['kyu']?>">
<div class="field-wrap clearfix">
<label>Nama Kriteria <span class="red">*</span></label>
<input type="text" name="nama" value="<?php echo $nama; ?>">
</div>
<div class="field-wrap clearfix">
<label>Type Kriteria <span class="red">*</span></label>
<select name="type">
<option value="c1" <?php selected($type, 'c1'); ?>>C-1</option>
<option value="c2" <?php selected($type, 'c2'); ?>>C-2</option>
<option value="c3" <?php selected($type, 'c3'); ?>>C-3</option>
<option value="c4" <?php selected($type, 'c4'); ?>>C-4</option>
<option value="c5" <?php selected($type, 'c5'); ?>>C-5</option>
</select>
</div>
<div class="field-wrap clearfix">
<label>Bobot Kriteria <span class="red">*</span></label>
<input type="number" name="bobot" value="<?php echo $bobot; ?>" step="0.01">
</div>
<div class="field-wrap clearfix">
<label>Urutan Order</label>
<input type="number" name="urutan_order" value="<?php echo $urutan_order; ?>">
</div>
<div class="field-wrap clearfix">
<label>Cara Penilaian</label>
<select name="jenis_nilai" id="jenis-nilai">
<option value="0">Inputan Langsung</option>
<option value="1">Menggunakan Pilihan Variabel</option>
</select>
</div>
<div class="field-wrap list-var clearfix sembunyikan">
<h3>Pilihan Variabel</h3>
<table id="pilihan-var" class="pure-table pure-table-striped">
<thead>
<tr>
<th>Nama Variabel</th>
<th style="width: 120px;">Nilai</th>
<th style="width: 50px;">Urutan</th>
<th>Hapus</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="align-right">
<a href="#" class="button tambah-pilihan">Tambah Pilihan</a>
</div>
</div>
<div class="field-wrap clearfix">
<button id="submit" type="submit" name="submit" value="submit" class="button">Tambah Kriteria</button>
</div>
</form>
<?php //endif; ?>
</div>
</div><!-- .container -->
</div><!-- .main-content-row -->
<script>
$(document).ready(function() {
$('#submit').click(function(e) {
e.preventDefault();
console.log($('#form-add').serialize());
});
});
</script>
<?php
require_once('template-parts/footer.php');