<?php
if(isset($_POST)){
$id_ujian = $_POST;
$insertQuery = "INSERT INTO tabel_soal SET id_ujian = '".$id_ujian."' , pertanyaan = '".$_POST."' ";
$insertSql = $obj->insertLastId($insertQuery);
$array = array('A','B','C','D','E');
foreach ($array as $jawab){
if($jawab == $_POST ){
$insertQuery1 = "INSERT INTO tabel_pil_jawaban SET id_soal = '".$insertSql."' , jawaban = '".$_POST[$jawab]."', status = '1' ";
$insertSql1 = $obj->insertLastId($insertQuery1);
}else{
$insertQuery2 = "INSERT INTO tabel_pil_jawaban SET id_soal = '".$insertSql."' , jawaban = '".$_POST[$jawab]."', status = '0' ";
$insertSql2 = $obj->insertLastId($insertQuery2);
}
}
echo "<script type='text/javascript'>window.location=('?page=Tambah_Soal&ujian=".$id_ujian."&status=sukses');</script>";
}
if(isset ($_GET)) {
$id_ujian = $_REQUEST;
foreach ($obj->getById('*','id_ujian',$id_ujian,'tabel_ujian') as $ujian);
if(empty($ujian)){
echo "<script type='text/javascript'>window.location=('?page=Home');</script>";
}else{
//ambil jumlah soal terakhir
$query = "SELECT count(*) as total FROM tabel_soal WHERE id_ujian = '".$id_ujian."'";
foreach ($obj->getCostume($query)as $jumSoal);
?>
<div class="row" id="notivi-id" style="display:none;">
<div class="col-md-6 col-md-offset-3">
<div id="notivasi" class="alert alert-dismissible text-center" role="alert">
<div class="message"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="alert alert-info" role="alert">
<h4><span class="glyphicon glyphicon-plus" aria-hidden=true></span> Tambahkan Soal Untuk Ujian <?php echo $ujian; ?> </h4>
</div>
</div>
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Soal Ke = <?php echo $jumSoal+1; ?></div>
<div class="panel-body">
<form method="POST" action="?page=Tambah_Soal">
<div class="form-group">
<label for="exampleInputEmail1">Pertanyaan :</label>
<textarea name="tanya" class="form-control" rows="3" required></textarea>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Pilihan Jawaban :</label>
</div>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
$(document).ready(function(){
$('#add').click(function(){
var inp = $('#box');
var i = $('input').size() + 1;
$('<div id="box' + i +'"><input type="text" id="name" class="name" name="name' + i +'" placeholder="input pilihan jawaban"/><img src="http://findicons.com/files/icons/753/gnome_desktop/64/gnome_edit_delete.png" title="Hapus" width="32" height="32" border="0" align="top" class="add" id="remove" /> </div>').appendTo(inp);
i++;
});
$('body').on('click','#remove',function(){
$(this).parent('div').remove();
});
});
</script>
</head>
<body>
<div class="bachors">
<div id="box">
<input name="name" type="text" id="name" class="name" placeholder="Input pilihan jawaban" required>
<img src="https://upload.wikimedia.org/wikipedia/commons/5/52/Fairytale_button_add.png" title="Tambah" width="32" height="32" border="0" align="top" class="add" id="add" />
</div>
</body>
</div>
<form action="" method="post" name="name">
<input type="hidden" name="id_ujian" value="<?php echo $id_ujian;?> ">
<button type="submit" name="simpan" class="btn btn-primary">Simpan</button>
</form>
</div>
</div>
<script>
$(document).ready(function() {
function pesan_tampil(clas,message){
$("#notivasi").addClass(clas);
$(".message").append(message);
$("#notivi-id").show();
$("#notivi-id").addClass('animated bounceInDown');
setTimeout(function(){
$("#notivi-id").slideUp();
}, 4000);
}
<?php
if(isset ($_GET)) {
if($_GET=='sukses') {
echo "pesan_tampil('alert-success','<strong>Success!!..</strong> Soal Ujian Telah ditambahkan');";
}else if($_GET=='gagal'){
echo "pesan_tampil('alert-warning','<strong>Maaf!!..</strong> Gagal Menambahkan Data');";
}
}
?>
});
</script>
<?php
}
}else{
echo "<script type='text/javascript'>window.location=('?page=Home');</script>";
}
?>
Silahkan
login untuk menjawab!