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

                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                  <h3 class="box-title">List Jurusan</h3>
                                </div><!-- /.box-header -->

                                <div class="box-body table-responsive">
            <div class="row" id="show_progress" style="display: none">
   <div class="col-md-11">
    Mohon Tunggu sedang Download Data <img src="<?=base_admin();?>assets/dist/img/squares.gif">
    </div>
               <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 Akm</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>
                
 <button class="btn btn-primary btn-flat download-data-jurusan-now"><i class="fa fa-cloud-download"></i> Download Data Jurusan/Prodi Dari Feeder</button>
 <p></p>
                                    <table id="dtb_manual" class="table table-bordered table-striped">
                                   <thead>
                                     <tr>
                           <th style="width:25px" align="center">No</th>
                          <th>Kode Jurusan Dikti</th>
                          <th>Nama Jurusan</th>
                          <th>Status</th>
                          <th>Jenjang</th>
                          
                          <th>Action</th>
                         
                        </tr>
                                      </thead>
                                        <tbody>
                                         <?php 
      $dtb=$db->fetch_custom("select jurusan.kode_jurusan,jurusan.nama_jurusan,jurusan.id,status,jenjang from jurusan");
      $i=1;
      foreach ($dtb as $isi) {
        ?><tr id="line_<?=$isi->id;?>">
        <td align="center"><?=$i;?></td>
<td><?=$isi->kode_jurusan;?></td>
<td><?=$isi->nama_jurusan;?></td>
<td><?=$isi->status;?></td>
<td><?=$isi->jenjang;?></td>

        <td>
       
        <?=($role_act["up_act"]=="Y")?'<a href="'.base_index().'jurusan/edit/'.$isi->id.'" class="btn btn-primary btn-flat"><i class="fa fa-pencil"></i></a>':"";?>  
        <?=($role_act["del_act"]=="Y")?'<button class="btn btn-danger hapus btn-flat" data-uri="'.base_admin().'modul/jurusan/jurusan_action.php" data-id="'.$isi->id.'"><i class="fa fa-trash-o"></i></button>':"";?>
        </td>
        </tr>
        <?php
        $i++;
      }
      ?>
                                        </tbody>
                                    </table>
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div>
                    </div>
                </section><!-- /.content -->
        
<script type="text/javascript">


$(".download-data-jurusan-now").click(function(){
          total();
});

$(document).ready(function() {

$("#ok_info_download").click(function(){
  window.location.reload();
  });

});

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() {
          $("#show_progress").show();
          $("#down_kelas_now").attr("disabled", true);
          $(".batal").show();
          var start_time = new Date().getTime();
          var totaldata;
             $.ajax({
              url: "<?=base_admin();?>modul/jurusan/get_jumlah.php",
              type : "post",
              dataType: 'json',
              success: function(data) {
                  totaldata = data.jumlah;
                  total_data = parseInt(totaldata);
                  var bagi = Math.ceil(total_data/11);
                    getData(bagi,total_data,start_time);
              }
            });
}



    var random_number = Math.floor(1000 + Math.random() * 9000);
    var counters = 0;
    var persen = 0;
    var progress=11;
    var all_id = "";
    var error_msg = "";
    var token = "";
    var last = "";

    var data_recs = [];



    
window.getData=function(bagi,total_data,start_time)
{
    var start = start_time;


     
 
    if ((bagi*11)==progress) {
      data = {
          id_data : all_id,
          error_msg : error_msg,
          total_data : total_data,
          offset : counters,
          token : token,
          random_number : random_number,
          last : 'yes'
          }
    } else {
      data = {
            total_data : total_data,
            offset : counters,
            token : token,
            random_number : random_number,
            last : 'no'
          }
    }


    $.ajax({
        /* The whisperingforest.org URL is not longer valid, I found a new one that is similar... */
        url: "<?=base_admin();?>modul/jurusan/download_jurusan.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].limit);

            //data_rec.push(data[index].data_rec);
           
            $(".current-count").html(progress);
            $(".total-count").html(total_data);
            persen = parseInt(persen);
            proses(persen);
              
              counters+=11;
              progress+=11;
              token = data[index].token;

              //console.log(data[index].offset);
               if (counters < total_data) {
                  getData(bagi,total_data,start);
                } else {
                  var end_time = new Date().getTime();
                  waktu = "Total Waktu Download : "+millisToMinutesAndSeconds(end_time-start);
                  alert('Download Jurusan Selesai');
                  $("#isi_informasi_download").html(data[index].last_notif.concat(waktu));
                  $('#informasi_download').modal('show');
                  //console.log('done');
                } 
              });

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

    });
}

  $(".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);
             window.location.reload();
          }
          });
          $('#ucing').modal('hide');

        });



  });
</script>