 
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        Manage Kurikulum
                    </h1>
                        <ol class="breadcrumb">
                        <li><a href="<?=base_index();?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=base_index();?>kurikulum">Kurikulum</a></li>
                        <li class="active">Kurikulum List</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-6">
                            <div class="box">
                             <div class="box-header with-border">
              <h3 class="box-title">Filter</h3>
            </div>
            <div class="box-body">
           <form class="form-horizontal" method="post" action="<?=base_admin();?>modul/kurikulum/download_data.php">
                      <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Semester</label>
                        <div class="col-lg-10">
                        <select id="sem_filter" name="sem_filter" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">
                        <option value="all">Semua</option>
               <?php 
          $jurusan_sem = "";
        if ($_SESSION['level']!=1) {
              $jurusan_sem = "where kurikulum.kode_jurusan='".$_SESSION['jurusan']."'";
        }
               foreach ($db->fetch_custom("select kurikulum.mulai_berlaku,nama_semester from kurikulum inner join semester on
 kurikulum.mulai_berlaku=semester.semester $jurusan_sem order by kurikulum.mulai_berlaku desc") as $isi) {
                  echo "<option value='$isi->mulai_berlaku'>$isi->nama_semester</option>";
               } ?>
              </select>

 </div>
                      </div><!-- /.form-group -->
  <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Prodi</label>
                        <div class="col-lg-10">
                        <select id="jur_filter" name="jur_filter" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">
                        <option value="all">Semua</option>
              </select>

 </div>
                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Kode Matakuliah" class="control-label col-lg-2">Status</label>
                        <div class="col-lg-10">
                       <select class="form-control" name="status" id="status_filter">
                    <option value="all">Semua</option>
                    <option value="0">Belum Di proses</option>
                    <option value="1">Sukses</option>
                    <option value="2">Error</option>
                  </select> </div>
                      </div><!-- /.form-group -->
                      <div class="form-group">
                        <label for="tags" class="control-label col-lg-2">&nbsp;</label>
                        <div class="col-lg-10">
                          <span id="filter" class="btn btn-primary"><i class="fa fa-refresh"></i> Filter</span>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
            </div>
            <!-- /.box-body -->

            </div>
            </div>
            <!-- col 2 -->
              <div class="col-xs-6">
                            <div class="box">
                             <div class="box-header with-border">
              <h3 class="box-title">Download Kurikulum Dari Feeder</h3>
            </div>
            <div class="box-body">
           <form class="form-horizontal" method="post" action="<?=base_admin();?>modul/kurikulum/download_data.php">
                      <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Semester</label>
                        <div class="col-lg-10">
                        <select id="sem_down" name="sem_down" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">
               <?php 
        $tahun_sekarang = date('Y');
               foreach ($db->fetch_custom("select *,left(semester,4) as tahun from semester order by semester desc") as $isi) {

                  if ($isi->tahun<=$tahun_sekarang) {
                   echo "<option value='$isi->semester'>$isi->nama_semester</option>";
                  }
                  
               } ?>
              </select>

 </div>
                      </div><!-- /.form-group -->
  <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Prodi</label>
                        <div class="col-lg-10">
                        <select id="jur_down" name="jur_down" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">
                        <?php
                         $where_jurusan = "";
        if ($_SESSION['level']!=1) {
             
              $where_jurusan = "where jurusan.kode_jurusan='".$_SESSION['jurusan']."'";
        }
                        foreach ($db->fetch_custom("select id_sms,concat(jenjang,' ',nama_jurusan) as nama_jurusan from jurusan $where_jurusan") as $key) {
                          echo "<option value='$key->id_sms'>$key->nama_jurusan</option>";
                        }
                        ?>
              </select>

 </div>
                      </div><!-- /.form-group -->
                      <div class="form-group">
                        <label for="tags" class="control-label col-lg-2">&nbsp;</label>
                        <div class="col-lg-10">
                          <span id="down_feeder" class="btn btn-primary"><i class="fa fa-download"></i> Download Kurikulum</span>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
                    <div class="alert alert_hasil alert-info alert-dismissible" style="display: none">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <span id="data_hasil_down"></span>
              </div>
            </div>
            <!-- /.box-body -->

            </div>
            </div>

            </div>

             <div class="row">
                        <div class="col-xs-12">
                        <div class="box">
 
                                <div class="box-body table-responsive">
                                  <?php
       foreach ($db->fetch_all("sys_menu") as $isi) {
                      if ($path_url==$isi->url) {
                          if ($role_act["insert_act"]=="Y") {
                    ?>
                      <a class="btn btn-primary" id="import_data"><i class="fa fa-cloud-upload"></i> Upload Data Excel</a>
                          <?php
                          }
                       }
}
?>
<p>&nbsp;</p>
                                    <table id="dtb_kurikulum" class="table table-bordered table-striped">
                                   <thead>
                                       <tr>
                                     <th rowspan="2" style="text-align: center;vertical-align: middle;">
                                       Nama Kurikulum
                                     </th>
                                     <th rowspan="2" style="text-align: center;vertical-align: middle;">Mulai Berlaku</th>
                                     <th colspan="3" style="text-align: center;vertical-align: middle;">Aturan SKS</th>
                                    
                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">Prodi</th>
                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">Status</th>
                                     <th rowspan="2" style="text-align: center;vertical-align: middle;">Action</th>
                                   </tr>
                                     <tr>
                                     <th>Lulus</th>
                          <th>Wajib</th>
                          <th>Pilihan</th>
                          
                          
                       
                         
                        </tr>
                                      </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div>
                    </div>
    <div class="modal" id="modal_import_data" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"><div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&nbsp;</span></button> <h4 class="modal-title">Import Excel </h4> </div> <div class="modal-body" id="isi_import_data"> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div>

        <?php
       foreach ($db->fetch_all("sys_menu") as $isi) {
                      if ($path_url==$isi->url) {
                          if ($role_act["insert_act"]=="Y") {
                    ?>
          <a href="<?=base_index();?>kurikulum/tambah" class="btn btn-primary btn-flat"><i class="fa fa-plus"></i> Tambah</a>
                          <?php
                          } 
                       } 
}
      
  foreach ($db->fetch_all("sys_menu") as $isi) {

  //jika url = url dari table menu
  if ($path_url==$isi->url) {
    //check edit permission
  if ($role_act["up_act"]=="Y") {
  $edit = '<a href="'.base_index()."kurikulum/kurmat/'+aData[indek]+'".'" class="btn btn-primary btn-flat" data-toggle="tooltip" data-title="Lihat Detail Matakuliah"><i class="fa fa-search"></i></a> <a href="'.base_index()."kurikulum/edit/'+aData[indek]+'".'" class="btn btn-primary btn-flat"><i class="fa fa-pencil"></i></a>';
  } else {
    $edit ="";
  }
  if ($role_act['del_act']=='Y') {
   $del = "<span data-id='+aData[indek]+' data-uri=".base_admin()."modul/kurikulum/kurikulum_action.php".' class="btn btn-danger hapus btn-flat"><i class="fa fa-trash"></i></span>';
  } else {
    $del="";
  }
                   } 
  }
  $nama_kur ='<a data-toggle="tooltip" data-title="Lihat Detail Matakuliah" href="'.base_index()."kurikulum/kurmat/'+aData[indek]+'".'">'."'+aData[kur]+'".'</a>';
?>  
                </section><!-- /.content -->
        <script type="text/javascript">


  //filter 
$('#sem_filter').on('change', function() {
      $.ajax({
          url : "<?=base_admin();?>modul/kurikulum/jurusan_data.php",
          type : "post",
          data : {semester : $(this).val() },
          success : function(data) {
              $("#jur_filter").html(data);
              $("#jur_filter").trigger('chosen:updated');
          }

      });
});


var dataTable = $("#dtb_kurikulum").DataTable({
           "fnCreatedRow": function( nRow, aData, iDataIndex ) {
            var indek = aData.length-1;
            var kur = 0;
    $('td:eq('+kur+')', nRow).html('<?=$nama_kur;?>');
     $('td:eq('+indek+')', nRow).html('<?=$edit;?> <?=$del;?>');

       $(nRow).attr('id', 'line_'+aData[indek]);
   },
           'bProcessing': true,
            'bServerSide': true,
        "columnDefs": [ {
              "targets": [5],
              "orderable": false,
              "searchable": false

            } ],
            "ajax":{
              url :"<?=base_admin();?>modul/kurikulum/kurikulum_data.php",
            type: "post",  // method  , by default get
            <?php
            if ($_SESSION['level']!=1) {
              ?>
             data: function ( d ) {
              d.jurusan_user = <?=$_SESSION['jurusan'];?>
              },
              <?php
            }
            ?>
          error: function (xhr, error, thrown) {
            console.log(xhr);
              $(".dtb_krs-error").html("");
              $("#dtb_krs").append('<tbody class="dtb_krs-error"><tr><th colspan="4">No data found in the server</th></tr></tbody>');
              $("#dtb_krs_processing").css("display","none");

            },
      
          },

        });


$('#filter').on('click', function() {
  dataTable = $("#dtb_kurikulum").DataTable({
           "fnCreatedRow": function( nRow, aData, iDataIndex ) {
            var indek = aData.length-1;
             var kur = 0;
    $('td:eq('+kur+')', nRow).html('<?=$nama_kur;?>');           
     $('td:eq('+indek+')', nRow).html('<?=$edit;?> <?=$del;?>');
       $(nRow).attr('id', 'line_'+aData[indek]);
   },
   destroy : true,
           'bProcessing': true,
            'bServerSide': true,
                 "columnDefs": [ {
              "targets": [0,5],
              "orderable": false,
              "searchable": false

            } ],
            "ajax":{
              url :"<?=base_admin();?>modul/kurikulum/kurikulum_data.php",
            type: "post",  // method  , by default get
            data: function ( d ) {
                    d.jurusan = $("#jur_filter").val();
                    d.semester = $("#sem_filter").val();
                    d.status_filter = $("#status_filter").val();
                  }
          }
        });

      });

        $("#import_data").click(function() {
          $.ajax({
              url : "<?=base_admin();?>modul/kurikulum/import_data.php",
              type : "GET",
              success: function(data) {
                  $("#isi_import_data").html(data);
                  dataTable.draw();
              }
          });
      $('#modal_import_data').modal({ keyboard: false,backdrop:'static',show:true });
    });

$(".table").on('click','.hapus',function(event) {

    event.preventDefault();
    var currentBtn = $(this);

    uri = currentBtn.attr('data-uri');
    id = currentBtn.attr('data-id');


    $('#ucing')
        .modal({ keyboard: false })
        .one('click', '#delete', function (e) {

                $.ajax({
          type: "POST",
          data : 'id='+id,
          url: uri+"?act=delete&id="+id,
          success: function(data){
            console.log(data);
              dataTable.draw(false);
          }
          });
          $('#ucing').modal('hide');

        });



  });

$('#down_feeder').on('click', function() {

    sem = $("#sem_down").val();
    jur = $("#jur_down").val();

     $("#loadnya").show();
          $.ajax({
              type: "POST",
              url: "<?=base_admin();?>modul/kurikulum/down_kur.php",
              data: {semester:sem,jurusan:jur},
              success: function(result) {
                 $("#loadnya").hide();
                 $(".alert_hasil").show();
                 $("#data_hasil_down").html(result);
                 dataTable.draw(false);
                 $(".alert_hasil").fadeOut(5000);
                 console.log(result);
              },
              //async:false
      });

});
</script>