<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php
$id = $_GET['id'];
$bank = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal WHERE id_bank='$id'"));
$mpl = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM mata_pelajaran WHERE kode_mapel='$bank[nama]'"));
  ?>	
 <?php if($bank['pembahasan']=='0'){{$bahas="Tidak";}} ?>
<?php if($bank['pembahasan']=='1'){{$bahas="Ya";}} ?> 
<style>
/* custom checkbox */
.checkbox {
    display: block;
    position: relative;
    padding-left: 35px;
    margin-bottom: 5px;
    cursor: pointer;
    font-size: 12px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
 
/* hide the browser's default checkbox */
.checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}
 
/* create custom checkbox */
.check {
    position: absolute;
    top: 0;
    left: 0;
    height: 25px;
    width: 25px;
    background-color: #eee;
    border: 1px solid #ccc;
}
 
/* on mouse-over, add border color */
.checkbox:hover input ~ .check {
    border: 2px solid #2489C5;
}
 
/* add background color when the checkbox is checked */
.checkbox input:checked ~ .check {
    background-color: #2489C5;
    border:none;
}
 
/* create the checkmark and hide when not checked */
.check:after {
    content: "";
    position: absolute;
    display: none;
}
 
/* show the checkmark when checked */
.checkbox input:checked ~ .check:after {
    display: block;
}
 
/* checkmark style */
.checkbox .check:after {
    left: 9px;
    top: 5px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 3px 3px 0;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
}
</style>
<?php if ($ac == '') { ?>
  <div class="row">
     <div class="col-md-12">
		<div class="card">
             <div class="card-header">	
                 <div class="example-content"> 
			            <a href="?pg=banksoal" class="btn btn-sm btn-outline-danger right" >Kembali</a>
                    </div>			 
                  <h5 class="card-title">Edit 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">
											   <input type="hidden" name="idm" value="<?= $id ?>" >
                                                   <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 form-control-sm" name="kode" value="<?= $bank['kode'] ?>" placeholder="Masukan Kode Bank Soal" required>
                                                         </div>
                                                    </div>
													 <div class="col-md-8">
													<div class="form-group">
                                                        <label class="bold">Mata Pelajaran</label>
                                                       <select class="form-select form-control-sm" name="nama" required="true">														
														<option value="<?= $bank['nama'] ?>"><?= $mpl['nama_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') : ?>
													   <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)) :
                                                                        if (in_array($pk['id_pk'], unserialize($bank['idpk']))) : ?>
                                                                            <option value="<?= $pk['id_pk'] ?>" selected><?= $pk['id_pk'] ?></option>"
                                                                        <?php else : ?>
                                                                            <option value="<?= $pk['id_pk'] ?>"><?= $pk['id_pk'] ?></option>"
                                                                        <?php endif; ?>
                                                                    <?php 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 form-control-sm' required='true'>
														<option value="<?= $bank['level'] ?>"><?= $bank['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-select select2' multiple='multiple' style='width:100%' required='true'>
														  <option value='semua'>Semua Kelas</option>
                                                                        <?php $lev = mysqli_query($koneksi, "SELECT * FROM kelas"); ?>
                                                                        <?php while ($kelas = mysqli_fetch_array($lev)) : ?>
                                                                            <?php if (in_array($kelas['id_kelas'], unserialize($bank['kelas']))) : ?>
                                                                                <option value="<?= $kelas['id_kelas'] ?>" selected><?= $kelas['id_kelas'] ?></option>
                                                                            <?php else : ?>
                                                                                <option value="<?= $kelas['id_kelas'] ?>"><?= $kelas['id_kelas'] ?></option>
                                                                            <?php endif; ?>
                                                                        <?php endwhile ?>
                                                                    </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='<?= $bank[groupsoal] ?>'><?= $bank['groupsoal'] ?></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 } ?>
																
													
												
												<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='<?= $bank[pembahasan] ?>'><?= $bahas ?></option>
															<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=ubah',
											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>
									