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

                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-body table-responsive">
                <div class="row" id="show_progress" style="display: none">
               <div class="col-md-11">
                        <div class="progress">
                          <div class="progress-bar progress-bar-striped" id="progressbar" role="progressbar"  aria-valuemin="0" aria-valuemax="100" style="width: 10%">
                            10%
                          </div>

                        </div></div><div class='col-md-1' id="message"><span class='current-count'>1</span>/<span class="total-count">13</span></div></div>
                      <div class="alert alert-danger alert-dismissible" id="ada_error" style="display: none">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h4><i class="icon fa fa-ban"></i> Error! , Contact saya ke wildannudin@gmail.com, screenshoot, kasih tahu saya error dibawah</h4><span class="isi_error"></span>
              </div>
 <a onclick="window.history.back(-1)" class="btn btn-success btn-flat"><i class="fa fa-step-backward"></i> Kembali</a>
    <a class="btn btn-primary" id="import_data"><i class="fa fa-cloud-upload"></i> Upload Data Excel</a>
    <button class="btn btn-info btn-flat up_feeder_now"><i class="fa fa-mail-forward"></i> Impor ke PDDIKTI feeder</button>
 <div class="row" id="progress_nya">
<br>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
              <div class="progress hidden" id="script-progress">
                          <div class="progress-bar progress-bar-striped active" id="progress-bar-start" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: ">

                          </div>
                        </div>
                    <div id="script-output"><em></em></div>
                </div>
            </div>

<div class="box box-danger">
<table class="table table-bordered table-striped">
      <tbody><tr>
<?php 
 $kuri = $db->fetch_custom_single("select kurikulum.*, nama_semester from kurikulum inner join semester on kurikulum.mulai_berlaku=semester.semester where kurikulum.id=?",array("id" =>$path_id));?>

          <td  width="20%">Nama Kurikulum <font color="#FF0000">*</font></td>
            <td colspan="5">: 
     <?=$kuri->nama_kur;?></td>
        </tr>
        <tr>
            <td >Program Studi <font color="#FF0000">*</font></td>
            <td>:  <?php echo $db->fetch_single_row('jurusan','kode_jurusan',$id_jur)->jenjang.' '.$db->fetch_single_row('jurusan','kode_jurusan',$id_jur)->nama_jurusan;?></td>
            <td >Mulai Berlaku <font color="#FF0000">*</font></td>
          <!--  <td colspan="3">:  2017/2018 Genap</td>-->
            <td colspan="9">:  <?=$kuri->nama_semester;?>    </td></tr>
      <tr>
          <td >Jumlah sks</td>
            <td>: 
      <?=$kuri->jml_sks_wajib+$kuri->jml_sks_pilihan;?><font color="#999999"><em> ( sks Wajib + sks Pilihan )</em></font>
            </td>
          <td > Jumlah Bobot Matakuliah Wajib <font color="#FF0000">*</font></td>
            <td>: 
      <?=$kuri->jml_sks_wajib;?> sks</td>
          <td >Jumlah Bobot Matakuliah Pilihan <font color="#FF0000">*</font></td>
            <td>: 
      <?=$kuri->jml_sks_pilihan;?> sks</td>
        </tr>
    </tbody></table>
            <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/matakuliah_kurikulum/download_data.php">
                      <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Semester</label>
                        <div class="col-lg-3">
                        <select id="sem_filter" name="sem_filter" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">
                        <option value="all">Semua</option>
             <?php
             for ($i=1; $i <9 ; $i++) { 
               echo '<option value="'.$i.'">'.$i.'</option>';
             }
                ?>
              </select>

 </div>
 <input type="hidden" name="id_kur" value="<?=$id_kur;?>">
                      </div><!-- /.form-group -->
                      <input type="hidden" name="jur_filter" value="<?=$id_jur;?>">
<div class="form-group">
                        <label for="Kode Matakuliah" class="control-label col-lg-2">Jenis MK</label>
                        <div class="col-lg-3">
                    <select class="form-control" name="jns_mk" id="jns_mk">
                    <option value="all">Semua</option>
                    <option value="W">Wajib Nasional</option>
                    <option value="A">Wajib Program Studi</option>
                    <option value="B">Pilihan</option>
                     <option value="C">Peminatan</option>
                    <option value="S">Tugas Akhir / Skripsi</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-3">
                       <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 btn-flat"><i class='fa fa-refresh'></i> Filter</span>
                  <button type="submit" class="btn btn-success"><i class="fa fa-cloud-download"></i> Download</button>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
            </div>
            <!-- /.box-body -->
          </div>
                                    <table id="dtb_matakuliah_kurikulum" class="table table-bordered table-striped">
                                   <thead>
                                     <tr>
                                       <th><input type="checkbox"  id="bulkDelete"  /> <button id="deleteTriger"><i class="fa fa-trash"></i></button></th>

                          <th>Kode MK</th>
													<th>Nama MK</th>
                          <th>Semester</th>
													<th>Jenis MK</th>
                          <th>Total SKS</th>
                          <th>Status</th>
													
													
                          <th>Action</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                                       <div class="row">
        <div class="col-lg-12">
            <div class="pull-right">
                <button type="button" data-id="<?=$id_kur;?>" data-uri="<?=base_admin();?>modul/matakuliah_kurikulum/matakuliah_kurikulum_action.php" class="btn btn-danger" id="kosongkan_data"><i class="fa fa-bitbucket"></i> Hapus Data Massal</button>
            </div>
        </div>
        <!-- /.col-lg-12 -->
    </div>
        
        </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>
<div class="modal modal-danger" id="mass_info" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog"> <div class="modal-content"><div class="modal-header"> <h4 class="modal-title">Hapus Data Massal</h4> </div> <div class="modal-body" style="height: 62px;"> 
<input type="hidden" id="id_kur_del" value="<?=$id_kur;?>">
<div class="form-group">
                        <label for="Kode Matakuliah" class="control-label col-lg-3" style="padding-top:6px">Status</label>
                        <div class="col-lg-9">
                       <select class="form-control" name="status_delete" id="status_delete">
                    <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> <div class="modal-footer"> 
 <button type="button" id="delete" class="btn btn-danger">Delete</button> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> </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();?>matakuliah-kurikulum/tambah/<?=$id_kur;?>/<?=$id_jur;?>" 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()."matakuliah-kurikulum/edit/'+aData[indek]+'".'/'.$id_kur.'/'.$id_jur.'" 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/matakuliah_kurikulum/matakuliah_kurikulum_action.php".' class="btn btn-danger hapus btn-flat"><i class="fa fa-trash"></i></span>';
  } else {
    $del="";
  }
                   } 
  }
  
?>  
                </section><!-- /.content -->
        <script type="text/javascript">

    $.ajax({
     url: '<?=base_admin();?>modul/kurikulum/create_json.php?jurusan='+<?=$id_jur;?>,
      });

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

            } ],
            "ajax":{
              url :"<?=base_admin();?>modul/matakuliah_kurikulum/matakuliah_kurikulum_data.php",
            type: "post",  // method  , by default get
            data: function ( d ) {
                      d.jurusan = "<?=$id_jur;?>";
                      d.id_kur = "<?=$id_kur;?>";
                  },
          error: function (xhr, error, thrown) {
            console.log(xhr);
              $(".dtb_akm-error").html("");
              $("#dtb_akm").append('<tbody class="dtb_akm-error"><tr><th colspan="9">No data found in the server</th></tr></tbody>');
              $("#dtb_akm_processing").css("display","none");

            }
          },
             "language": {
            "infoPostFix":"<br><b>Jumlah :</b> <br> Belum diproses(0): <b>_BELUM_</b> <br>Sukses(1): <b>_SUKSES_</b> <br> Error(2): <b> _ANEH_ </b>"
        },

        });


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

            } ],
            "ajax":{
              url :"<?=base_admin();?>modul/matakuliah_kurikulum/matakuliah_kurikulum_data.php",
            type: "post",  // method  , by default get
            data: function ( d ) {
                    d.id_kur = "<?=$id_kur;?>";
                    d.jurusan = "<?=$id_jur;?>";
                    d.jns_mk = $("#jns_mk").val();
                    d.semester = $("#sem_filter").val();
                    d.status_filter = $("#status_filter").val();
                  },
          error: function (xhr, error, thrown) {
            console.log(xhr);
              $(".dtb_akm-error").html("");
              $("#dtb_akm").append('<tbody class="dtb_akm-error"><tr><th colspan="9">No data found in the server</th></tr></tbody>');
              $("#dtb_akm_processing").css("display","none");

            }
          },
             "language": {
            "infoPostFix":"<br><b>Jumlah :</b> <br> Belum diproses(0): <b>_BELUM_</b> <br>Sukses(1): <b>_SUKSES_</b> <br> Error(2): <b> _ANEH_ </b>"
        },

        });

      });

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

//hapus semua data
$("#kosongkan_data").click(function(event){

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

          uri = currentBtn.attr('data-uri');
          id = currentBtn.attr('data-id');
          status = $("#status_delete").val();

          $('#mass_info')
              .modal({ keyboard: false })
              .one('click', '#delete', function (e) {
                console.log(e);
              $("#loadnya").show();
              $('#mass_info').modal('hide');
                      $.ajax({
                type: "POST",
                data: {id:id,status:status},
                url: uri+"?act=delete_all",
                success: function(data){

                   $("#loadnya").hide();
                    console.log(data);
                    dataTable.draw(false);
                }
                });
             
                

              });

      });


$(".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');

        });



  });

$("#bulkDelete").on('click',function() { // bulk checked
          var status = this.checked;
          $(".deleteRow").each( function() {
            $(this).prop("checked",status);
          });
        });

$('#deleteTriger').on("click", function(event){
          if( $('.deleteRow:checked').length > 0 ){
            event.preventDefault();


            var ids = [];
            $('.deleteRow').each(function(){
              if($(this).is(':checked')) {
                ids.push($(this).val());
              }
            });
            var ids_string = ids.toString();



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

 $("#loadnya").show();
          $.ajax({
              type: "POST",
              url: "<?=base_admin();?>modul/matakuliah_kurikulum/matakuliah_kurikulum_action.php?act=del_massal",
              data: {data_ids:ids_string},
              success: function(result) {

                 $("#loadnya").hide();
                dataTable.draw(false);
              },
              //async:false
            });
          $('#ucing').modal('hide');



        });


          }
        });


$(".up_feeder_now").click(function(){
         $("#loadnya").show();
          var start_time = new Date().getTime();
          $("#show_progress").show();
          total_data = parseInt(total());

          var bagi = Math.ceil(total_data/7);
          
          getData(bagi,total_data,start_time);
          //$("#loadnya").hide();
   
});


function millisToMinutesAndSeconds(s) {
  var ms = s % 1000;
  s = (s - ms) / 1000;
  var secs = s % 60;
  s = (s - secs) / 60;
  var mins = s % 60;
  var hrs = (s - mins) / 60;

  return (hrs < 1 ? '' : hrs+' Jam : ') + (mins < 1 ? '' : mins+' Menit : ') + secs + ' detik';
}

 function proses(percent){
    if(percent>10){
      
      $("#progressbar").css("width",percent+"%");
      $("#progressbar").html(percent+"%");
      } else {
        $("#progressbar").css("width",10+"%");
        $("#progressbar").html(10+"%");
      }
    } 

function total() {

          var totaldata;
          var datas = {
            jurusan : <?=$id_jur;?>,
            id_kur : <?=$id_kur;?>
        }
             $.ajax({
              url: "<?=base_admin();?>modul/kurikulum/get_jumlah.php",
              type : "post",
              dataType: 'json',
              'async':false,
              data : datas,
              success: function(data) {
                  totaldata = data.jumlah;
              }
            });

    return totaldata;
}



   
    var counters = 0;
    var jumlah_error_kur=0;
    var jumlah_sukses_kur= 0;
    var jumlah_error=0;
    var jumlah_sukses = 0;
    var jumlah_sukses_matkur=0;
    var jumlah_error_matkur=0;
    var persen = 0;
    var progress=7;
    var all_id = "";
    var error_msg_kur = "";
    var error_msg = "";
    var error_msg_matkur = "";
    var kur_id = "";
    var data_ids = "";
window.getData=function(bagi,total_data,start_time)
{
    var start = start_time;
 
    if ((bagi*7)==progress) {
      data = {
          jurusan : <?=$id_jur;?>,
          id_kur : <?=$id_kur;?>,
          jumlah_sukses_kur : jumlah_sukses_kur,
          jumlah_error_kur : jumlah_error_kur,
          jumlah_sukses : jumlah_sukses,
          jumlah_error : jumlah_error,
          jumlah_sukses_matkur : jumlah_sukses_matkur,
          jumlah_error_matkur : jumlah_error_matkur,
          id_data : all_id,
          error_msg_kur : error_msg_kur,
          error_msg : error_msg,
          error_msg_matkur : error_msg_matkur,
          total_data : total_data,
          offset : counters,
          kur_id : kur_id,
          all_id : all_id
          }
    } else {
      data = {
            jurusan : <?=$id_jur;?>,
            id_kur : <?=$id_kur;?>,
            total_data : total_data,
            offset : counters,
            kur_id : kur_id,
            all_id : all_id
          }
    }




    $.ajax({
        /* The whisperingforest.org URL is not longer valid, I found a new one that is similar... */
        url: "<?=base_admin();?>modul/kurikulum/push_kur_new.php",
        //async:false,
        data : data,
        type : "post",
        dataType: 'json',
        success:function(data){
          $.each(data, function(index) {
            persen = ((progress/total_data)*100).toFixed(1);
            if (persen>100) {
              persen=100+ "%";
              progress = total_data;
            } else {
              persen=persen+ "%";
              progress = progress;
            }
            console.log(data[index]);
         
            $(".current-count").html(progress);
            $(".total-count").html(total_data);
            persen = parseInt(persen);
            proses(persen);

            all_id+=data[index].all_id+',';
            kur_id=data[index].kur_id;
            error_msg_kur+=data[index].error_msg_kur+',';

            error_msg+=data[index].error_msg+',';
            error_msg_matkur+=data[index].error_msg_matkur+',';
              
              counters+=7;
              progress+=7;

              //console.log(data[index].offset);
              jumlah_error_kur+=parseInt(data[index].jumlah_error_kur);
              jumlah_sukses_kur+=parseInt(data[index].jumlah_sukses_kur);

              jumlah_error+=parseInt(data[index].jumlah_error);
              jumlah_sukses+=parseInt(data[index].jumlah_sukses);
              jumlah_error_matkur+=parseInt(data[index].jumlah_error_matkur);
              jumlah_sukses_matkur+=parseInt(data[index].jumlah_sukses_matkur);
               if (counters < total_data) {
                  getData(bagi,total_data,start);
                } else {
                 $("#loadnya").hide();
                  var end_time = new Date().getTime();
                  waktu = "Total Waktu Import : "+millisToMinutesAndSeconds(end_time-start);
                  alert('Import data ke Feeder Selesai');
                  $("#isi_informasi").html(data[index].last_notif.concat(waktu));
                  $('#informasi').modal('show');
                  //console.log('done');
                } 
              });

        },
      error: function (xhr, ajaxOptions, thrownError) {
        alert('oops ada error');
        $("#loadnya").hide();
         $("#ada_error").show();
        $(".isi_error").html(xhr.responseText);
        
        }

    });
}



</script>  
            