<?php
if( !hasPermission($_SESSION['user_detail']['role_id'], 'lr_add') ) {
  echo '<script>window.location.href="index.php?page=no_permission.php"</script>';die();
}
?>
<section class="content-header">
   <div class="row">
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 bottom20">
         <h3 class="capital font15 padding5 bold">DOCUMENT UPLOAD - <?php echo $_GET['id'];?></h3>
      </div>
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 text-right bottom20">
         <h3><a href="index.php?page=truck_mst/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW TRUCK DETAILS</a></h3>
      </div>
   </div>
</section>
<hr class="bottom35">
<section class="hitz-top-header">
  <div class="row bottom40">
    <div class="col-xs-12">
       <div class="box box-success">
          <div class="box-body">
             <form action="truck_mst/permit_insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                <div class="row">
                   <div class="col-md-6">
                      <div class="col-md-12">
                         <div class="form-group pading-left15">
                            <label class="capital">ATTECHMENT</label><span style="color: red">*</span>
                             <input type="file" size="35" id="rc_img" name="rc_img" placeholder="VENDOR NAME" autocomplete="off" class="image" />
                              <input type="hidden" name="old_rc_img" value="">
                            <input type="hidden" name="id" id="ref_no" value="<?php echo $_GET['eid'];?>">
                         </div>
                      </div>
                      <div class="col-md-12">
                         <div class="form-group pading-left15">
                            <label class="capital">REMARK</label><span style="color: red">*</span>
                             <input type="text" size="35" id="remark" name="remark" placeholder="REMARK" autocomplete="off" class="form-control" />
                         </div>
                      </div>
                   </div>
                </div>
                <hr>
                <div class="row" align="center">
                   <button id="btn" class="btn btn-primary ajax-submit capital" type="submit"> Save & List</button>
                   <a href="index.php?page=truck_mst/list.php" class="btn btn-danger capital"> Cancel</a>
                </div>
             </form>
          </div>
       </div>
    </div>
  </div>
  <div class="row bottom40">
    <div class="col-xs-7">
       <div class="box box-success">
          <div class="box-body">
            <div class="card-body table-responsive">
              <table id="example1" class="table table-bordered table-striped list_data">
                <thead>
                  <tr>
                    <th width="10">Sr.no</th>
                    <th width="70">REMARK</th>
                    <th width="40">Actions</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td colspan="3"><?php echo "ATTECHMENT NOT FOUND"; ?></td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
       </div>
    </div>
  </div>
</section>
<div id="product-template" style="display:none;">
   <table>
      <tr>
         <td>
            <a href="javascript:;" class="btn green btn-block add-more" style="display: block;"><i class="fa fa-plus"></i></a>
            <a href="javascript:;" class="btn btn-dangerred btn-block remove-me" style="display: none;"><i class="fa fa-minus"></i></a>
         </td>
         <td><input type="file" name="product[%i%]" value="" class="form-control product-name" data-count="" style="height: 34px !important;"></td>
      </tr>
   </table>
</div>
<script type="text/javascript">
  jQuery(document).ready(function() {
    loadDataTable();
    var $length = 0;
    jQuery(document).on('click', '.add-more', function(e) {
      $length = jQuery('#product-wapper').find('table tbody tr').length;
      var $clone = jQuery('#product-template table tr').clone();
      $clone.find('input').each(function() {
        this.name = this.name.replace('[%i%]', '[' + $length + ']');
      });
 
      $clone.find('.product-name').attr('data-count', $length);
 
      jQuery('#product-wapper table tbody').append($clone);
 
      jQuery('#product-wapper table tbody').find('.remove-me').show();
      jQuery('#product-wapper table tbody').find('.add-more').hide();
 
      jQuery('#product-wapper table tbody').find('.remove-me:last').hide();
      jQuery('#product-wapper table tbody').find('.add-more:last').show();
    });
   
    jQuery(document).on('click', '.remove-me', function(e) {
      e.preventDefault();
      jQuery(this).closest('tr').remove();
    });
    $('#status').select2();
    jQuery('.filter').change(function(){
      loadDataTable();
    });
  });
  function loadDataTable(){
    if(typeof dTable!='undefined'){dTable.fnDestroy();}

    dTable=jQuery('.list_data').dataTable({
        "bProcessing"       : true,
        "order"             : [ [0, 'asc'] ],
        "aLengthMenu"       : [ [5, 10, 15, 20, 25, 50, 100], [5, 10, 15, 20, 25, 50, 100] ],
        'iDisplayLength'    : 10,
        "aoColumns"         : [
            {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}
        ],
        "bServerSide"       : true,
        "sAjaxSource"       : 'truck_mst/permit_data_fetch.php?lr_no=' + jQuery('#ref_no').val(),
    });
  }

  function confirmDelete(e) {
      var $i = $(e).attr("id");
      console.log($i);
      swal({
          title: "Are you sure?",
          text: "You will not be able to recover this imaginary file!",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "Yes, delete it!",
          closeOnConfirm: false
      }, function (isConfirm) {
          if (!isConfirm) return;
          $.ajax({
              url: "truck_mst/permit_delete.php",
              type: "POST",
              data: 'delete='+$i,
              dataType: "json",
              success: function () {
                swal({title: "Deleted!", text: "Data successfully Deleted!", type: "success"},
                  function(){ 
                    location.reload();
                  }
                );
              },

              error: function (xhr, ajaxOptions, thrownError) {
                swal("Error deleting!", "Please try again", "error");
              }
          });
      });
    } 
</script>
