<?php
session_start();
include "../../inc/config.php";
    $token = get_token();
    $url_rest = $db->get_service_url('rest');
    $id = $_POST['id_matkul'];
      $data_req_akt = [
        'act' => 'GetMataKuliah',
          'token' => $token,
          'filter' => "id_matkul='$id'",
          'order' => "",
          'limit' => "",
          'offset' => ""

      ];
      $check_akt_exist_json = json_decode($db->run($data_req_akt,$url_rest));
      $akt_data = $check_akt_exist_json->data[0];
      $id_matkul = $akt_data->id_matkul;

    $filter_kelas = "id_prodi='".$akt_data->id_prodi."'";

                $temp_data_kelas = [
      'act' => 'GetListKurikulum',
        'token' => $token,
        'filter' => $filter_kelas,
        'order' => "id_semester DESC",
        'limit' => "",
        'offset' => ""

    ];


    $kelas = json_decode($db->run($temp_data_kelas,$url_rest));


      ?>

<table id="tabelku" class="table table-bordered table-striped" cellspacing="0" width="100%">
        <tbody><tr>
          <td class="info2" width="20%"><strong>Program Studi</strong></td>
          <td width="30%"><?=$akt_data->nama_program_studi;?></td>
        </tr>
        <tr>
          <td class="info2"><strong>Kode Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->kode_mata_kuliah;?></td>
          <td class="info2"><strong>Jenis Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->id_jenis_mata_kuliah;?></td>
        </tr>
        <tr>
          <td class="info2"><strong>Nama Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->nama_mata_kuliah;?></td>
          <td class="info2"><strong>SKS Matakuliah</strong></td>
          <td colspan="3"><?=$akt_data->sks_mata_kuliah;?></td>
        </tr>
      </tbody></table>
<div class="alert alert-danger error_data_sks" style="display:none">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <span class="isi_warning_sks"></span>
</div>


<form id="update" method="post" class="form-horizontal" action="<?=base_admin();?>modul/manage_matakuliah/manage_matakuliah_action.php?act=input_to_kurikulum">
                      <div class="form-group">
                        <label for="pertemuan" class="control-label col-lg-2">Kurikulum</label>
                        <div class="col-lg-6">
                            <select class="form-control chzn-select" name="id_kurikulum">
                                <?php
                                foreach ($kelas->data as $data_kelas) {
                                    echo "<option value='$data_kelas->id_kurikulum'>$data_kelas->nama_kurikulum</option>";
                                }
?>
                            </select>
                        </div>
                      </div><!-- /.form-group -->
                       <div class="form-group">
                        <label for="pertemuan" class="control-label col-lg-2">Semester</label>
                        <div class="col-lg-2">
                          <input type="text" name="semester" class="form-control desimal" required>
                          <small>Isi Semester 1 S/d 8</small>
                        </div>
                      </div><!-- /.form-group -->

                       <div class="form-group">
                      <label for="Active" class="control-label col-lg-2">Wajib ? </label>
                      <div class="col-lg-6">
                        <input name="apakah_wajib" data-on-text="Wajib" data-off-text="Tidak" class="make-switch" type="checkbox">
                      </div>
                  </div><!-- /.form-group -->
                      <input type="hidden" name="id_matkul" value="<?=$id_matkul;?>">
                      <div class="form-group">
                        <label for="tags" class="control-label col-lg-2">&nbsp;</label>
                        <div class="col-lg-10">
                          <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Simpan</button>
                          <span class="btn btn-default btn-flat" data-dismiss="modal"><i class="fa fa-step-backward"></i> Batal</span>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
<script type="text/javascript">
(function($)
{$.fn.numberField=function(options)
{if(!options)
{options={}}
var defaultOptions={ints:2,floats:6,separator:"."};options=$.extend(defaultOptions,options);var intNumAllow=options.ints;var floatNumAllow=options.floats;var separator=options.separator;$(this).on('keydown keypress keyup paste input',function()
{while((this.value.split(separator).length-1)>1)
{this.value=this.value.slice(0,-1);if((this.value.split(separator).length-1)<=1)
{return!1}}
var re=new RegExp('[^0-9'+options.separator+']','g');this.value=this.value.replace(re,'');var allowedLength;var iof=this.value.indexOf(separator);if((iof!=-1)&&(this.value.substring(0,iof).length>intNumAllow))
{allowedLength=0}
else if(iof!=-1)
{allowedLength=iof+floatNumAllow+1}
else{allowedLength=intNumAllow}
this.value=this.value.substring(0,allowedLength);return!0});return $(this)}})(jQuery)
$(document).ready(function() {
      $('input.desimal').numberField(
    {
      ints: 1, // digits count to the left from separator
      floats: 0, // digits count to the right from separator
      separator: "."
  }
  );
 $(".chzn-select").chosen();
$.each($('.make-switch'), function () {
        $(this).bootstrapSwitch({
            onText: $(this).data('onText'),
            offText: $(this).data('offText'),
            onColor: $(this).data('onColor'),
            offColor: $(this).data('offColor'),
            size: $(this).data('size'),
            labelText: $(this).data('labelText')
        });
    });
$(".batal-edit").on("click",function(){
  $("#modal_edit").modal( 'hide' ).data( 'bs.modal', null );
});

    
     $("#update").validate({
        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("tgl_picker_input")) {
               element.parent().parent().append(error);
            } else if (element.hasClass("file-upload-data")) {
               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({
                url : $(this).attr("action"),
                dataType: "json",
                type : "post",
                error: function(data ) { 
                  $("#loadnya").hide();
                  console.log(data); 
                  $(".isi_warning_sks").html(data.responseText);
                  $(".error_data_sks").focus()
                  $(".error_data_sks").fadeIn();
                },
                success: function(data) {
                  $("#loadnya").hide();
                  if (data.status=='good') {
                    $(".isi_warning_sks").html('');
                    $(".error_data_sks").hide();
                    $(".notif_top_up").fadeIn(1000);
                    $('#modal_kelas_jadwal').modal('hide');
                    $(".notif_top_up").fadeOut(1000, function() {
                    dataTable.draw(false);
                    });
                  } else {
                      $(".isi_warning_sks").html(data.error_desc);
                      $(".error_data_sks").focus()
                      $(".error_data_sks").fadeIn();
                  }
                  console.log(data.status);

                }

            });
        }
    });
});
</script>