
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        Manage Download Daya Tampung Jalur Masuk
                    </h1>
                        <ol class="breadcrumb">
                        <li><a href="<?=base_index();?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=base_index();?>download-daya-tampung">Download Daya Tampung</a></li>
                        <li class="active">Download Daya Tampung List</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                    <div class="row">

        <div class="col-md-3">
          <div class="box box-solid">
            <div class="box-header with-border">
              <h3 class="box-title">Download Data </h3>

              <div class="box-tools">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
              </div>
            </div>


            <div class="box-body no-padding">
            <ul class="nav nav-pills nav-stacked">
    <li class="<?= ($path_act === 'periode' || $path_act === '') ? 'active' : ''; ?>">
        <a href="<?= base_index(); ?>download-daya-tampung/periode">
            <i class="fa fa-book"></i> Periode Perkuliahan
        </a>
    </li>
    <li class="<?= ($path_act === 'daya-tampung') ? 'active' : ''; ?>">
        <a href="<?= base_index(); ?>download-daya-tampung/daya-tampung">
            <i class="fa fa-book"></i> Daya Tampung
        </a>
    </li>
</ul>

            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>

                        <div class="col-xs-9">
                            <div class="box">
                             
                                <div class="box-body table-responsive" style="overflow:visible;">

<div class="box box-danger" >
            <div class="box-header with-border">
              <h3 class="box-title">Filter</h3>
            </div>
            <div class="box-body" >
           <form class="form-horizontal"  action="<?=base_admin();?>modul/download_daya_tampung/download_daya_tampung_file.php">
                     

                      <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Semester</label>
                        <div class="col-lg-5" >
                        <select id="sem_filter" name="sem_filter" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2" style="z-index: 1" required="">
                        <option value="">Pilih Semester</option>
              <?php 
              $url_rest = get_service_url('rest');
              $temp_data_semester = [
                'act' => 'GetSemester',
                  'token' => get_token(),
                  'filter' => "a_periode_aktif='1' and right(id_semester,1) in('1','2')",
                  'order' => 'id_semester desc'
              ];

            $temp_rec = json_decode($db->run($temp_data_semester,$url_rest));
            dump($temp_rec);

               $semester = $db->fetch_custom('select *,left(semester,4) as smt from semester order by semester desc');
                    foreach ($semester as $isi) {
                      if ($temp_rec->data[0]->id_semester==$isi->semester) {
                          echo "<option value='".$isi->semester."' selected>".$isi->nama_semester."</option>";
                          $smt_selected = $isi->semester;    
                        } else {
                          echo "<option value='".$isi->semester."'>".$isi->nama_semester."</option>";    
                        }
                      }
                       ?>
              </select>
              <div id="error_sem"></div>

 </div>
                      </div><!-- /.form-group -->

<div class="form-group">
                                        <label for="Semester" class="control-label col-lg-2">Program Studi</label>
                                        <div class="col-lg-5">
                                        <select id="jurusan" name="jurusan" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">

                                        <option value="all">Semua</option>
                               <?php
                                $jurusan_sms = "";
                                if ($_SESSION['level']!=1) {
                                  $jurusan_sms = "where id_sms='".$_SESSION['id_sms']."'";
                                } 
                               foreach ($db->fetch_custom("select * from jurusan $jurusan_sms") as $isi) {
                                  echo "<option value='$isi->id_sms'>$isi->jenjang $isi->nama_jurusan</option>";
                               } ?>
                              </select>
 <div id="error_prodi"></div>
                 </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  data-uri="<?=base_admin();?>modul/hapus_kelas/hapus.php" class="btn btn-primary" id="down_kelas_now"><i class="fa fa-cloud-download"></i> Download Daya Tampung Periode Perkuliahan</span>
                        </div>
                      </div><!-- /.form-group -->
                      <input type="hidden" name="jurusan" value="<?=$id_jur;?>">

                    </form>
            </div>
            <!-- /.box-body -->
          </div>
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div>
                    </div>
 


                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                             
                                <div class="box-body table-responsive" style="overflow:visible;">
       

  <div class="row" id="show_progress" style="display: none">
   <div class="col-md-11">
    Mohon Tunggu sedang Generate File <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</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>
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div>
                    </div>
                </section><!-- /.content -->
        <script type="text/javascript">
$(document).ready(function() {


$('#sem_filter').on('change', function() {
    if($(this).val()=="") {
       $("#sem_filter").parent().parent().addClass('has-error');
       $("#error_sem").html('<span for="semester_up" class="help-block">Pilih Semester.</span>');
    } else {
       $("#sem_filter").parent().parent().removeClass('has-error');
       $("#error_sem").html('');
    }
});



$("#down_kelas_now").click(function(){
    if ($("#sem_filter").val()=="") {
      $("#sem_filter").parent().parent().addClass('has-error');
      $("#error_sem").html('<span for="sem_filter" class="help-block">Pilih Semester.</span>');
    } else {
          $("#isi_drop_up").hide();
          $("#isi_drop").hide();
          total();

    }


   
});


});


$(document).ready(function() {

$("#ok_info_download").click(function(){
   var currentBtn = $(this);
   uri = currentBtn.attr('data-uri');

   //alert(uri);
        $.ajax({
            type: "POST",
            data: {uri:uri},
            url: "<?=base_admin();?>modul/download_daya_tampung/tampung/download_daya_tampung_action.php?act=delete_download",
            success: function(data){
              console.log(data);
              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){
   $("#progressbar").css("width",percent+"%");
      $("#progressbar").html(percent+"%");
/*    if(percent>10){
      
     
      } else {
        $("#progressbar").css("width",10+"%");
        $("#progressbar").html(10+"%");
      }*/
    } 

function total() {
          $("#show_progress").show();
          $("#down_krs_now").attr("disabled", true);
          var start_time = new Date().getTime();
          var totaldata;
          var datas = {
          sem_filter : $("#sem_filter").val(),
          jurusan : $("#jurusan").val(),
            nama_kelas : $("#nama_kelas").val(),
            matkul : $("#matkul").val(),
        }
       
             $.ajax({
              url: "<?=base_admin();?>modul/download_daya_tampung/tampung/get_jumlah.php",
              type : "post",
              dataType: 'json',
              //'async':false,
              data : datas,
              success: function(data) {
                  totaldata = data.jumlah;
                  total_data = parseInt(totaldata);
                  var bagi = Math.ceil(total_data/8);
                    
                    getData(bagi,total_data,start_time);

              }
            });

    //return totaldata;
}



    var random_number = Math.floor(1000 + Math.random() * 9000);
    var counters = 0;
    var persen = 0;
    var progress=8;
    var all_id = "";
    var error_msg = "";
    var token = "";
    var last = "";
    var jurusan_attribute = "";
    var data_recs = [];

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


     
 
    if ((bagi*8)==progress) {
      data = {
          sem_filter : $("#sem_filter").val(),
          jurusan : $("#jurusan").val(),
          matkul : $("#matkul").val(),
          id_data : all_id,
          total_data : total_data,
          offset : counters,
          token : token,
          jurusan_attribute : jurusan_attribute,
          random_number : random_number,
          last : 'yes'
          }
    } else {
      data = {
            sem_filter : $("#sem_filter").val(),
            jurusan : $("#jurusan").val(),
            matkul : $("#matkul").val(),
            total_data : total_data,
            offset : counters,
            token : token,
            jurusan_attribute : jurusan_attribute,
            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/download_daya_tampung/tampung/download_daya_tampung_file.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;
            }

            data_recs.push(data[index].data_rec);

            jurusan_attribute = data[index].jurusan_attribute;
           
            $(".current-count").html(progress);
            $(".total-count").html(total_data);
            persen = parseInt(persen);
            proses(persen);
              
              counters+=8;
              progress+=8;
              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 Generate : "+millisToMinutesAndSeconds(end_time-start);
                  alert('Generate File Download Selesai');
                  $("#ok_info_download").attr("data-uri",data[index].data_uri);
                  $("#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);
        
        }

    });
}

</script>