<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php include"sandik_bank/radio.php"; ?>
<?php if ($ac == '') { ?>
  <div class="row">
     <div class="col-md-12">
		<div class="card">
             <div class="card-header">									
                  <h5 class="card-title">Tambah Bank Soal</h5>
					</div>
                      <div class="card-body">
                             
                               <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
                                      <li class="nav-item" role="presentation">
                                        <button class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Bank Soal</button>
                                            </li>
                                          
                                                </ul>
                                                <div class="tab-content" id="pills-tabContent">
                                            <div class="tab-pane fade active show" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
                                            <div class="card" >
                                           <div class="card-header"> </div>                              
                                            <div class="row">
											<div class="col-md-2"></div>
											 <div class="col-md-8">
											 <div class="card-body">
											<div class="example-container">
                                            <div class="example-content">
                                               <form id="formtambahbank">
                                                    <div class="row">
                                                  <div class="col-md-4">
													<div class="form-group">
                                                        <label class="bold">Kode Bank Soal</label>
                                                      <input type="text" class="form-control" name="kode"  required>
                                                    </div>
                                                    </div>
													 <div class="col-md-8">
													<div class="form-group">												
                                                        <label class="bold">Mata Pelajaran</label>
                                                       <select class="form-select" name="nama" required="true">														
														<option value="">Pilih Mapel</option>
														<?php
															$pkQ = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran ORDER BY nama_mapel ASC");
															while ($pk = mysqli_fetch_array($pkQ)) {
																echo "<option value='$pk[kode_mapel]'>$pk[nama_mapel]</option>";
															}
															?>
														</select>
													</div>
													</div>
                                                    </div><p>
														<?php if ($setting['jenjang']=='SMA' OR $setting['jenjang']=='SMK' OR $setting['jenjang']=='PAKET-C') : ?>
													   <div class="col-md-12">
															<label class="bold">Program Keahlian</label>
															<select name='id_pk[]' class='form-select select2' multiple="multiple" style='width:100%' required='true'>
																<option value='semua'>Semua</option>
																<?php
																$pkQ = mysqli_query($koneksi, "SELECT * FROM pk ORDER BY program_keahlian ASC");
																while ($pk = mysqli_fetch_array($pkQ)) :
																	echo "<option value='$pk[id_pk]'>$pk[program_keahlian]</option>";
																endwhile;
																?>
															</select>
														</div><p>
													<?php endif; ?>
                                                    <div class="row">
                                                  <div class="col-md-4">
													<div class="form-group">
                                                        <label class="bold">Level Soal</label>
                                                       <select name='level' id='soallevel' class='form-select' required='true'>
														<option value=''>Pilih Level</option>
														<option value='semua'>Semua</option>
														<?php
														$lev = mysqli_query($koneksi, "SELECT * FROM level");
														while ($level = mysqli_fetch_array($lev)) {
															echo "<option value='$level[kode_level]'>$level[kode_level]</option>";
														}
														?>
													</select>
                                                    </div>
													</div>
                                                    <div class="col-md-8">
													<div class="form-group">
													<label class="bold">Pilih Kelas</label>
													 <select name='kelas[]' id='soalkelas' class='form-control form-control-sm select2' multiple='multiple' style='width:100%' required='true'>
														   </select>
															</div>
															</div>
															</div><p>
													<?php if($menu['soal']==1){ ?>
                                                     <div class="row">													
													<div class="col-md-4">
														<div class="form-group">
															 <label class="bold">Topik</label>
														   <select name='groupsoal' class='form-select form-control-sm' >
															<option value=''></option>
																<option value='Literasi'>Literasi</option>
																<option value='Numerasi'>Numerasi</option>                                     
															</select>
														</div>
													</div>
													<div class="col-md-4">
														<div class="form-group">
														   <label class="bold">Sub Topik</label>
															 <input type="text" name="subtopik" class='form-control form-control-sm' >
														</div>
													</div>
													 <div class="col-md-4">
													<div class="form-group">
														   <label class="bold">Level Kognitif</label>
															 <input type="text" name="kognitif" class='form-control form-control-sm' value="HOTS" >
														</div>
													</div>
													</div>
													<p>
													<?php } ?>
													<hr>
													 <h6 class="bold" style="text-align:center">Bobot Soal</h6><p>
													<div class="row">
                                                  <div class="col-md-4">
													<div class="form-group">
													  <label class="checkbox">
														<input type="checkbox" name="pg" value="pg" id="pg"> <span class="check"></span> PG
														</label> 
														<input type="number" name="bobot_pg" id="bobot_pg" class='form-control form-control=sm' value="0" style="display:none;">
													</div>
												</div>
													<div class="col-md-4">
													<div class="form-group">
													<label class="checkbox">
														 <input type="checkbox" name="esai" value="esai" id="esai"><span class="check"></span> Esai
														  </label> 
														<input type="number" name="bobot_esai" id="bobot_esai" class='form-control form-control-sm' value="0" style="display:none;">
														
													</div>
												</div>					
													<?php if($menu['soal']==0){ ?>	
												<div class="col-md-4">
													<div class='form-group'>
													 <label class="checkbox">
													   <input type="checkbox" name="kkm" value="kkm" id="kkm"> <span class="check"></span> Menggunakan KKM
														  </label> 
														 <input type="number" name="bobot_kkm" id="bobot_kkm" class='form-control form-control-sm' value="0" style="display:none;">
													</div>
												</div>
												<p>
												<?php } ?>
												<?php if($menu['soal']==1){ ?>	
												 <div class="col-md-4">
													<div class='form-group'>
													 <label class="checkbox">
													   <input type="checkbox" name="multi" value="multi" id="multi"> <span class="check"></span>PG Multi Choice
														  </label> 
														 <input type="number" name="bobot_multi" id="bobot_multi" class='form-control form-control-sm' value="0" style="display:none;">
													</div>
												</div><p>
												 <div class="col-md-4">
													<div class='form-group'>
													<label class="checkbox">
													   <input type="checkbox" name="bs" value="bs" id="bs"> <span class="check"></span>PG False True
													   </label>
								
														<input type="number" name="bobot_bs" id="bobot_bs" class='form-control form-control-sm' value="0" style="display:none;">
													</div>
												</div>
												<div class="col-md-4">
													<div class='form-group'>
													<label class="checkbox">
														<input type="checkbox" name="urut" value="urut" id="urut"> <span class="check"></span>Menjodohkan
														</label>
														 <input type="number" name="bobot_urut" id="bobot_urut" class='form-control form-control-sm' value="0" style="display:none;">
													</div>
												</div>
												<p>
												<?php } ?>
												</div>
												<hr>
												<div class='row'>
													 <div class='col-md-12'>
													   <label class="bold">Pembahasan Soal</label>
														 <select name='pembahasan' class='form-select form-control-sm' required>
															<option value='0'>Tidak</option>
															<option value='1'>Ya</option>
														   
														</select>
													</div>
												</div>
												<p>
												<div class='row'> 
											<div class='col-md-6'>
												<label class="bold">Guru Pengampu</label>
												<select name='guru' class='form-select form-control-sm' required='true'>
												   <?php
													if($user['level']=='admin'){
													$guruku = mysqli_query($koneksi, "SELECT * FROM users where level='guru' order by nama asc");
													}else{
													$guruku = mysqli_query($koneksi, "SELECT * FROM users where id_user='$user[id_user]'");
													}
													while ($guru = mysqli_fetch_array($guruku)) {
														echo "<option value='$guru[id_user]'>$guru[nama]</option>";
													}
													?>
												</select>
											</div>
                                                          
											<div class='col-md-6'>
												<label class="bold">Status Soal</label>
												<select name='status' class='form-select form-control-sm' required='true'>
													<option value='1'>Aktif</option>
													<option value='0'>Non Aktif</option>
												</select>
											</div>
											</div>
										  
										   <p>
										<div class='col-md-12'>
                                      <label class="bold">Soal Agama</label>
                                          <select name='agama' class='form-select form-control-sm'>
                                            <option value=''>Bukan Soal Agama</option>
                                              <?php
                                                $agam = mysqli_query($koneksi, "SELECT * FROM siswa group by agama");
                                                   while ($agama = mysqli_fetch_array($agam)) : ($agama['agama'] == $mapel['soal_agama']) ? $s = 'selected' : $s = '';
                                                       echo "<option value='" . $agama['agama'] . "' $s>$agama[agama]</option>";
                                                           endwhile;
                                                                 ?>
                                                                    </select>						
                                                               
																		
																</div>
											                  <p>
													<div class="d-grid gap-2">													
                                                   <button type="submit" class="btn btn-outline-primary">Simpan</button>													
                                                    </div>
													</div>
												  </form >
												</div>
												 </div>
													</div>
													  </div>
											  
                                                    </div>
                                                  
                                                </div>
                                            </div>
			
											
		                               <?php } ?>									
											
				
										 <script>
										$('#formtambahbank').submit(function(e) {
										e.preventDefault();
										$.ajax({
											type: 'POST',
											url: 'sandik_bank/crud_banksoal.php?pg=tambah',
											data: $(this).serialize(),
											success: function(data) {
												console.log(data);
												if (data == "OK") {
													iziToast.info(
											{
												title: 'Sukses!',
												message: 'Bank Soal berhasil disimpan',
												titleColor: '#FFFF00',
												messageColor: '#fff',
												backgroundColor: 'rgba(0, 0, 0, 0.5)',
												 progressBarColor: '#FFFF00',
												  position: 'topRight'
													});
													setTimeout(function() {
														window.location.replace('?pg=banksoal');
													}, 2000);
												} else {
													  iziToast.info(
											{
												title: 'Gagal!',
												message: 'Kode Bank Sudah Ada',
												titleColor: '#FFFF00',
												messageColor: '#fff',
												backgroundColor: 'rgba(0, 0, 0, 0.5)',
												 progressBarColor: '#FFFF00',
												  position: 'topRight'
													});
													setTimeout(function() {
														window.location.reload();
													}, 2000);
												}

											}
										});
										return false;
									});
									</script>	
								<script>	
									$("#soallevel").change(function() {
									var level = $(this).val();
									console.log(level);
									$.ajax({
										type: "POST",
										url: "sandik_bank/crud_banksoal.php?pg=ambil_kelas", 
										data: "level=" + level, 
										success: function(response) { 
											$("#soalkelas").html(response);
										}
									});
								});
							</script>
							<script>
							$('#pg').click(function() {
							   if($(this).is(":checked")){
								  $("#bobot_pg").show();
							   }
							   else{
								  $("#bobot_pg").hide();
							   }
							});
							</script>
							<script>
							$('#multi').click(function() {
							   if($(this).is(":checked")){
								  $("#bobot_multi").show();
							   }
							   else{
								  $("#bobot_multi").hide();
							   }
							});
							</script>
							<script>
							$('#bs').click(function() {
							   if($(this).is(":checked")){
								  $("#bobot_bs").show();
							   }
							   else{
								  $("#bobot_bs").hide();
							   }
							});
							</script>
							<script>
							$('#esai').click(function() {
							   if($(this).is(":checked")){
								  $("#bobot_esai").show();
							   }
							   else{
								  $("#bobot_esai").hide();
							   }
							});
							</script>
							<script>
							$('#urut').click(function() {
							   if($(this).is(":checked")){
								  $("#bobot_urut").show();
							   }
							   else{
								  $("#bobot_urut").hide();
							   }
							});
							</script>
							<script>
							$('#kkm').click(function() {
							   if($(this).is(":checked")){
								  $("#bobot_kkm").show();
							   }
							   else{
								  $("#bobot_kkm").hide();
							   }
							});
							</script>
									