

                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                      Rencana Evaluasi
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="<?=base_index();?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=base_index();?>rencana-evaluasi">Rencana Evaluasi</a></li>
                        <li class="active">Edit Rencana Evaluasi</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
<div class="row">
    <div class="col-lg-12">
        <div class="box box-solid box-primary">
                                   <div class="box-header">
                                    <h3 class="box-title">Edit Rencana Evaluasi</h3>
                                    <div class="box-tools pull-right">
                                        <button class="btn btn-info btn-sm" data-widget="collapse"><i class="fa fa-minus"></i></button>
                                        <button class="btn btn-info btn-sm" data-widget="remove"><i class="fa fa-times"></i></button>
                                    </div>
                                </div>

                  <div class="box-body">
                     <form id="input_evaluasi" method="post" class="form-horizontal" action="<?=base_admin();?>modul/rencana_evaluasi/rencana_evaluasi_action.php?act=up">
<div class="form-group">
                        <label for="Kode Matakuliah" class="control-label col-lg-2">Kode Matakuliah</label>
                        <div class="col-lg-3">
                          <input type="text" name="kode_mk" value="<?=$data_edit->kode_mk;?>" class="form-control" required> 
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Nama Matakuliah" class="control-label col-lg-2">Nama Matakuliah</label>
                        <div class="col-lg-10">
                          <input type="text" name="nama_mk" value="<?=$data_edit->nama_mk;?>" placeholder="Nama Matakuliah" class="form-control"> 
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Basis Evaluasi" class="control-label col-lg-2">Basis Evaluasi</label>
                        <div class="col-lg-10">
                          <select name="id_basis_evaluasi" id="id_basis_evaluasi" data-placeholder="Pilih Basis Evaluasi..." class="form-control chzn-select" tabindex="2" required>
               <option value=""></option>
               <?php foreach ($db->fetch_all("jenis_evaluasi") as $isi) {

                  if ($data_edit->id_basis_evaluasi==$isi->id_jns_eval) {
                    echo "<option value='$isi->id_jns_eval' selected>$isi->nm_jns_eval</option>";
                  } else {
                  echo "<option value='$isi->id_jns_eval'>$isi->nm_jns_eval</option>";
                    }
               } ?>
              </select>
                        </div>
                      </div><!-- /.form-group -->
<?php
$komponen_evaluasi = array(
  'TGS' => 'Tugas',
  'QIZ' => 'Kuis',
  'UTS' => 'Ujian Tengah Semester',
  'UAS' => 'Ujian Akhir Semester'
)
?>
<div class="form-group hide-komponen" <?=($data_edit->id_basis_evaluasi!=4?'style="display:none"':'')?>>
                        <label for="Komponen Evaluasi" class="control-label col-lg-2">Komponen Evaluasi</label>
                        <div class="col-lg-10">
              <select name="komponen_evaluasi" id="komponen_evaluasi" class="form-control chzn-select" tabindex="2">
                <option value=""></option>

               <?php

                foreach ($komponen_evaluasi as $key => $val) {
                  if ($data_edit->komponen_evaluasi==$key) {

                    echo "<option value='$key' selected>$val</option>";
                  } else {
                    echo "<option value='$key'>$val</option>";
                  }
                 
               } ?>
              </select>
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Deskripsi" class="control-label col-lg-2">Deskripsi</label>
                        <div class="col-lg-10">
                          <textarea rows="3" name="deskripsi_indonesia" class="form-control"required><?=$data_edit->deskripsi_indonesia;?> </textarea>
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Deskripsi (inggris)" class="control-label col-lg-2">Deskripsi (inggris)</label>
                        <div class="col-lg-10">
                          <textarea rows="3" name="deskripsi_inggris" class="form-control"><?=$data_edit->deskripsi_inggris;?> </textarea>
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Bobot (%)" class="control-label col-lg-2">Bobot (%)</label>
                        <div class="col-lg-10">
                          <input type="number" name="bobot_evaluasi" value="<?=$data_edit->bobot_evaluasi;?>" class="form-control" required> 
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Jurusan" class="control-label col-lg-2">Prodi</label>
                        <div class="col-lg-10">
                          <select name="jurusan" data-placeholder="Pilih Jurusan..." class="form-control chzn-select" tabindex="2" required>

               <?php 
if ($_SESSION['level']==1) {
  $jur = $db->fetch_custom("select * from jurusan");
} else {
  $jur = $db->fetch_custom("select * from jurusan where kode_jurusan='".$_SESSION['jurusan']."'");
}
foreach ($jur as $isi) {

                  if ($data_edit->kode_jurusan==$isi->kode_jurusan) {
                    echo "<option value='$isi->kode_jurusan' selected>$isi->jenjang $isi->nama_jurusan</option>";
                  } else {
                    echo "<option value='$isi->kode_jurusan'>$isi->jenjang $isi->nama_jurusan</option>";
                  }
               } ?>
              </select>
                        </div>
                      </div><!-- /.form-group -->

                      <input type="hidden" name="id" value="<?=$data_edit->id;?>">
                      <div class="form-group">
                        <label for="tags" class="control-label col-lg-2">&nbsp;</label>
                        <div class="col-lg-10">
                         <a onclick="window.history.back(-1)" class="btn btn-success btn-flat"><i class="fa fa-step-backward"></i> Kembali</a>
                           <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Simpan</button>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
          
                  </div>
                  </div>
              </div>
</div>
                  
                </section><!-- /.content -->
        
<script type="text/javascript">
$( document ).ready(function() {

  //filter 
$('#id_basis_evaluasi').on('change', function() {
  if ($(this).val()!='4') {
      $(".hide-komponen").hide();
  } else {
      $(".hide-komponen").show();
  }
});

//trigger validation onchange
$('select').on('change', function() {
    $(this).valid();
});
$.validator.setDefaults({ ignore: ":hidden:not(select)" });

    $("#input_evaluasi").validate({
       focusInvalid: true,
       ignore : [],
        errorClass: "help-block",
        errorElement: "span",
        highlight: function(element, errorClass, validClass) {
            $(element).parents(".form-group").removeClass(
                "has-success").addClass("has-error");
        },
        unhighlight: function(element, errorClass, validClass) {
            $(element).parents(".form-group").removeClass(
                "has-error").addClass("has-success");
        },
        errorPlacement: function(error, element) {
            if (element.hasClass("chzn-select")) {
                var id = element.attr("id");
                error.insertAfter("#" + id + "_chosen");
            } else if (element.attr("accept") == "image/*") {
                element.parent().parent().parent().append(error);
            } else if (element.hasClass("waktu")) {
               element.parent().parent().append(error);
            }
            else if (element.hasClass("tgl_picker_input")) {
               element.parent().parent().append(error);
            } else if (element.hasClass("select2-hidden-accessible")) {
               element.parent().append(error);
            }
            else if (element.hasClass("file-upload-data")) {
               element.parent().parent().parent().append(error);
            }  else if (element.hasClass("dosen-ke")) {
                  error.appendTo('.error-dosen');
            } else if (element.hasClass("tgl_lahir_tanggal") || element.hasClass("tgl_lahir_bulan") || element.hasClass("tgl_lahir_tahun")) {
                 element.parent().parent().parent().append(error);
            } 
            else if (element.attr("type") == "checkbox") {
                element.parent().parent().append(error);
            } else if (element.attr("type") == "radio") {
                element.parent().parent().append(error);
            } else {
                error.insertAfter(element);
            }


        },

            submitHandler: function(form) {
               $('#loadnya').show();

                   $(form).ajaxSubmit({
                          type: "post",
                          url: $(this).attr('action'),
                          data: $("#input_evaluasi").serialize(),
                       //  enctype:  'multipart/form-data'
                        success: function(data){
                          console.log(data);
                          $('#loadnya').hide();
                              if (data=='good') { 
                          $('.notif_top_up').fadeIn(1000);
                         $(".notif_top_up").fadeOut(1000,function(){
                           window.history.back();
                        });

                              } else {
                                 $('.errorna').fadeIn();
                               
                              }
                      }
                    });
            }

        });
});
 </script>