<link rel="stylesheet" type="text/css" href="<?php echo base_url()."resources/css/delegasi/dropzone.css" ?>">
<style type="text/css">
  .progress-bar-striped, .progress-striped .progress-bar{
    background-color: #729700;
  }
  #tabs2 .dropzone_content,#tabs2 .dz-message{
    background-color: #449D44;
    color: #fff;
  }
  #div_tombol_upload{
     background-color: #006634;
    color: #fff;
  }
  .version_shading {
    height: 200px;
    top: -89px;
  }
  a.btn {color:#FFF;}
  .usual{color:#444;}
  #wrap {
    display: grid;
    grid-template-columns: 60% 38%;
    grid-gap: 10px;
    margin: auto;
    background-color: #fff;
    color: #444;
  }
   .box {
    background: rgba(0, 0, 0, 0) linear-gradient(to bottom, #ffffff, #f5f5f5) repeat scroll 0 0;
    border-color: #e1e1e1;
    border-image: none;
    border-radius: 3px;
    border-style: solid;
    border-width: 1px 1px 2px;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.15);
    color: #444;
    padding: 20px;
    font-size: 150%;
    position: relative;
    box-shadow: none;
    border: 1px solid #eee;
    text-align: center;

  }
  .hidden{display: none}
</style>
<div id="wrap">
  <?php
    if ($idalur==1) {
       $folder="masuk";
    }else{
      $folder="keluar";
    } 
    $hide_dropzone="hidden"; ?>
  <div class="box">
            <table class="table table-bordered" style="font-size: 12px;">
              <thead>
                <th>Nomor</th>
                <th>Nama File</th>
                <?php if ($status_kirim==0): ?>
                      <th style="width: 100px">Status File</th>
                      <th>Aksi</th>
                <?php endif ?>
              </thead>
              <tbody>
              <?php foreach ($delegasi_file->result() as $row) {
                    if (file_exists(FCPATH."resources/file/delegasi/".$folder."/".$row->file) ){
                      $ada_file='<a style="color:#fff" class="btn btn-sm btn-primary'.$hidden.'" href="#" onClick="lihat_file(\''.$row->file.'\')">Lihat</a>';
                      $hidden="";
                    }else{
                      $hidden="hidden";
                      $ada_file="Gagal, upload ulang.";
                    }
                  echo   '<tr>';
                  echo            '<td>'.++$no.'</td>';
                  echo            '<td>'.$row->file.'</td>';
                  echo            '<td>'.$ada_file.'</td>';
                      if ($status_kirim==0) {
                  echo            '<td><a class="btn btn-sm btn-warning" style="color:#fff" href="#" onClick="batalkan(\''.base64_encode($this->encrypt->encode($idalur)).'\',\''.base64_encode($this->encrypt->encode($row->id)).'\',\''.base64_encode($this->encrypt->encode($row->file)).'\')">Batalkan</a></td>';
                      }
                  echo            '</td>';
                  echo  '</tr>';
                    } ;?>
                    <?php if ($status_kirim==0): ?>
                        <tr><td></td>
                          <td colspan="2">Tambah lampiran :</td><td><a class="btn btn-success" style="color:#fff"  href="#" onClick="show_dropzone()">Tambah</a></td>
                        <tr>
                    <?php endif ?>
              </tbody>
            </table>
    </div>
    <div class="box">
      <?php if ($status_kirim==0) {
                if ($delegasi_file->num_rows > 0){
                    echo '<h2>Mohon perhatiannya !</h2>';
                    echo '<h4>Sebelum klik tombol kirim, pastikan seluruh data sudah benar, dan dokumen lampiran sudah di upload seluruhnya, karena apabila setelah tombol kirim di tekan, anda tidak bisa merubah data kembali.</h4>
                    <br><a href="#" onclick="kirim_delegasi()" class="btn btn-danger"  style="color:#fff" >KIRIM</a>';              
                }else{
                    echo '<h2>Informasi !</h2>';
                    echo '<h4>Silahkan upload dokumen lampiran terlebih dahulu klik tombol tambah </h4>';              
                }
            } else {
            echo "<h2>Informasi</h2>";
            echo "<h4>Delegasi sudah terkirim ke pengadilan tujuan.</h4>";
      }?>
    </div>
</div>

<div class="progress progress-xs progress-striped active" hidden>
    <div class="progress-bar progress-bar-success" style="width: 1%"></div>
</div>
<div class="dropzone_content <?php echo $hide_dropzone?> bg-success" >
    <form id="myDropzone" action="<?php echo base_url('manage_delegasi_perkara/simpanDokumen').'/'.$idalur.'/'.$enc_delegasi.'/'.$enc_perkara.'/'.$enc_pn_asal.'/'.'/'.$enc_pn_tujuan.'/'.base64_encode($this->encrypt->encode($nomor_perkara))?>" class="dropzone" method="post">
      <input type="file" multiple name="file" size="20" hidden/>
       <div class="dz-message"><h2>Dropzone Area </h2> Untuk menambahkan lampiran file yang akan dikirim, silahkan klik disini atau Drag dan drop file ke kotak ini.
       <br> <span class="note">Maksimal 10 file untuk sekali kirim , dengan ekstensi file : zip,pdf,docx,doc, xls, xlsx,jpg,rar</span><br>
    </div>
    </form>
     <div id="div_tombol_upload" class="text-center">
        <button id="start_upload" type="submit" class="btn btn-primary">Lampirkan</button>
        <button id="cancel_upload" type="submit" class="btn btn-warning">Batal Semua Lampiran</button>
        <br><br>Klik tombol Lampirkan, untuk memasukkan file ke dalam daftar antrian
        <br>atau klik kotak Dropzone Area untuk menambahkan file yang lain</br>
     </div>
</div>
<script src="<?php echo base_url();?>resources/css/delegasi/dropzone.js"></script>
<script src="<?php echo base_url();?>resources/css/delegasi/my_dropzone.js"></script>
<script type="text/javascript">
$(function(){
  var tab_edoc="<?php echo $this->session->userdata('tab_edoc');?>";
  if (tab_edoc==1){
    $('.tabs7').click();
  }
  $('.tabs7').click(function(event) {
      <?php echo $this->session->set_userdata('tab_edoc',0);?>
      $("html, body").animate({ scrollTop: $(document).height() }, 2000); 
  });

});
    function lihat_file(filename){
      var folder="<?php echo $folder;?>";
      window.open('<?php echo base_url('resources/file/delegasi');?>'+'/'+folder+'/'+filename,'_blank');
    }
    function batalkan(idalur,id,filename){
        openLoadingDialog();
        $.ajax({
          url: "<?php echo base_url('manage_delegasi_perkara/hapus_file');?>"+'/'+idalur+'/'+id+'/'+filename,
        })
        .success(function() {
            location.reload();
        })
    }
    function show_dropzone(){
        $(".dropzone_content").removeClass('hidden');
        $("html, body").animate({ scrollTop: $(document).height() }, 1000); 
    }

    function kirim_delegasi(){
      openLoadingDialog();
      var enc_alur="<?php echo base64_encode($this->encrypt->encode($idalur));?>";
      var enc_delegasi="<?php echo $enc_delegasi;?>";
      var enc_perkara="<?php echo $enc_perkara;?>";
      var enc_pn_asal="<?php echo $enc_pn_asal;?>";
      var enc_pn_tujuan="<?php echo $enc_pn_tujuan;?>";
      $.ajax({
        url: "<?php echo base_url('manage_delegasi_perkara/senddatato_delegasi');?>",
        type: 'POST',
        dataType: 'json',
        data: {enc_alur:enc_alur,
               enc_delegasi:enc_delegasi,
               enc_perkara:enc_perkara,
               enc_pn_asal:enc_pn_asal,
               enc_pn_tujuan:enc_pn_tujuan},

      })
      .success(function(json) {
        if (json.status_kirim=='1'){
          alert('Sukses, Delegasi terkirim')
          location.reload();
        }else{
          alert('Gagal, Delegasi tidak terkirim')
          location.reload();
        }
      })
      .fail(function() {
        alert('Gagal, Delegasi tidak terkirim')
          location.reload();
      })
      .always(function() {
           $('.progress').show();
          $('.progress-bar').css('width','50%');
      });     
    }

    
</script>

