
    function get_backup_file() {
            

              $("#list_backup").html('');

              $.ajax({
                url: "models/crul_backup.php",
                type:"POST",
                dataType : "JSON",
                data: {"type":"list"} ,
                complete:function(){
                  //hideLoader();
                },
                beforeSend:function(){
                  //showLoader("Deleting Product");
            },
                success: function(res) {
                  console.log(res)
                  var k = res.length;
                  var cnt =0;
                  if(k <= 10){
                    cnt = 0;
                  }else{
                    cnt = k - 10;
                  }
                  for (var i in res) {
                   console.log( res[i])
                   
                //   alert(res[i])

                    $("#list_backup").append(` <button onclick="delete_file('`+i+`')" class="btn btn-danger" > <i class="icon-trash"></i> </button> <a class="btn btn-info " download href="backup/`+i+`"> Click to Download Backup File `+i+` </a> <br><br>`)

                  }
                }
            });
            
    }



    function delete_file(itemid) {
        // bootstrap modal confirmation box
        swal({
            title: Translation("هل انت متأكد؟!"),
            text: Translation("سوف لن تستطيع استرجاع المعلومات المرتبطة بهذا السجل في حالة المسح"),
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#EF5350",
            confirmButtonText: Translation("موافق: امسح!"),
            cancelButtonText: Translation("الغاء الامر"),
            closeOnConfirm: false,
            closeOnCancel: true
        },
        function(isConfirm){
            if (isConfirm) {
              $.ajax({
                url: "models/crul_backup.php",
                type:"POST",
                dataType : "JSON",
                data: {"type":"delete","file_name":itemid} ,
                complete:function(){
                 
                },
                beforeSend:function(){
                 
                },
                success: function(res) {

                  if(res.is_success == true){
                    swal({
                            title: Translation("حذف!"),
                            text: Translation(res.data),
                            confirmButtonColor: "#66BB6A",
                            type: "success"
                        });
                   get_backup_file();
                  }else{
                    swal({
                            title: "Cancelled",
                            text: Translation(res.data),
                            confirmButtonColor: "#2196F3",
                            type: "error"
                        });
                  }
                }
            });
            }
        }); // /confirm
    }





$(document).ready(function() {

  
    get_backup_file();

    $('#backup_btn').on('click',function(event) {
        event.preventDefault();
          


            $("#backup_btn").attr('disabled',true);
            $.ajax({
                url: "backup/dump_database.php",
                type:"POST",
                dataType:"JSON"
            })
            .done(function(res) {
                //alert(res);
                if(res.is_success==false){
                    swal({
                        title:"error",
                        text: res.data,
                        confirmButtonColor: "#66BB6A",
                        type: "warning"
                    });
                    
                }
                else{
                    
                    noty({
                                    width: 200,
                                    text: "Successfuly Generated Backup File",
                                    type: 'success',
                                    dismissQueue: true,
                                    timeout: 3000,
                                    layout: 'topRight',
                                    callback: {
                                        onShow: function() {},
                                        afterShow: function() {},
                                        onClose: function() {location.reload();},
                                        afterClose: function() {},
                                        onCloseClick: function() {},
                                      },
                              });

                    $("#download_backup").append('<a class="btn btn-warning " download href="backup/'+res.data+'"><i class=""></i> Click to Download Backup File </a>')
                }
                $("#backup_btn").attr('disabled',false);
            })
            .fail(function(err) {
                 swal({
                    title: "Error",
                    text: err,
                    confirmButtonColor: "#66BB6A",
                    type: "error"
                });
                $("#backup_btn").attr('disabled',false);
            })
            .always(function() {
                console.log("complete");
            });
        

    });



});






$(function() {
//var singleSelect = $('.datatable-column-search-inputs').DataTable();





});
