var modalTemplate = '<div class="modal-dialog modal-lg" role="document">\n' +
'  <div class="modal-content">\n' +
'    <div class="modal-header">\n' +
'      <div class="kv-zoom-actions btn-group">{toggleheader}{fullscreen}{borderless}{close}</div>\n' +
'      <h6 class="modal-title">{heading} <small><span class="kv-zoom-title"></span></small></h6>\n' +
'    </div>\n' +
'    <div class="modal-body">\n' +
'      <div class="floating-buttons btn-group"></div>\n' +
'      <div class="kv-zoom-body file-zoom-content"></div>\n' + '{prev} {next}\n' +
'    </div>\n' +
'  </div>\n' +
'</div>\n';

// Buttons inside zoom modal
var previewZoomButtonClasses = {
toggleheader: 'btn btn-default btn-icon btn-xs btn-header-toggle',
fullscreen: 'btn btn-default btn-icon btn-xs',
borderless: 'btn btn-default btn-icon btn-xs',
close: 'btn btn-default btn-icon btn-xs'
};

// Icons inside zoom modal classes
var previewZoomButtonIcons = {
prev: '<i class="icon-arrow-left32"></i>',
next: '<i class="icon-arrow-right32"></i>',
toggleheader: '<i class="icon-menu-open"></i>',
fullscreen: '<i class="icon-screen-full"></i>',
borderless: '<i class="icon-alignment-unalign"></i>',
close: '<i class="icon-cross3"></i>'
};

// File actions
var fileActionSettings = {
zoomClass: 'btn btn-link btn-xs btn-icon',
zoomIcon: '<i class="icon-zoomin3"></i>',
dragClass: 'btn btn-link btn-xs btn-icon',
dragIcon: '<i class="icon-three-bars"></i>',
removeClass: 'btn btn-link btn-icon btn-xs',
removeIcon: '<i class="icon-trash"></i>',
indicatorNew: '<i class="icon-file-plus text-slate"></i>',
indicatorSuccess: '<i class="icon-checkmark3 file-icon-large text-success"></i>',
indicatorError: '<i class="icon-cross2 text-danger"></i>',
indicatorLoading: '<i class="icon-spinner2 spinner text-muted"></i>'
};

$('.file-input').fileinput({
    browseLabel: 'Browse',
    browseIcon: '<i class="icon-file-plus"></i>',
    uploadLabel: '',
    uploadClass: 'hidden',
    uploadIcon: '',
    removeIcon: '<i class="icon-cross3"></i>',
    layoutTemplates: {
        icon: '<i class="icon-file-check"></i>',
        modal: modalTemplate
    },
    initialCaption: "No file selected",
    previewZoomButtonClasses: previewZoomButtonClasses,
    previewZoomButtonIcons: previewZoomButtonIcons,
    fileActionSettings: fileActionSettings
});

//action PENDAFTARAN DATA
$(".btn-data").on("click", function(e){
    e.preventDefault();
    saveMahasiswa();
})

function saveMahasiswa(){
    var isObject    = {};
    var nimpattern  = /^[0-9]{10}$/;
    var namapattern = /^[a-zA-Z ]{2,30}$/;
    isObject.namamhs    = $("#nama").val();
    isObject.nimmhs     = $("#nim").val();
    isObject.jurusan    = $("#mhsmajor").val();
    isObject.gender     = $('input[name="gender"]:checked').val();

    console.log(isObject);
    

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/jsondata/savemahasiswabym',
        data: {
            iparam	    : cryptoEncrypt(PHRASE, isObject),
        },
        success: function (response) {
            $('#modal-add').modal("hide");
            if(response.code == CODE_SUCCESS){

                // document.getElementById("form-data").reset();
                var object2 = isObject.nimmhs;
                swal({
                    title: "Alert",
                    text: "Data anda telah ditambahkan, silahkan upload berkas! ",
                    confirmButtonColor: "#66BB6A",
                    type: "success"
                }, function(){ 
                    // $("tbody").empty();
                    // loadElementsMhs();
                    // location.reload()
                    window.location = baseURL + "/mahasiswa/uploadberkas"
                });

            }else{
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });  
            };

            loaderPage(false);
            
        },
        error: function () {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Alert",
                    text:  xhr.status+"-"+xhr.statusText+" Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
}

//////////////////
//////////////////
///INPUT BERKAS///
//////////////////
//////////////////

$(".btn-save").on("click", function(e){
    e.preventDefault()
    saveFileMhss();
});

$(".btn-update").on("click", function(e){
    e.preventDefault()
    updateFileMhss();
});

function saveFileMhs(){
    // loaderPage(true);
    // console.log(nim);
    const fileupload1 = $('#file1').prop('files')[0];
    const fileupload2 = $('#file2').prop('files')[0];
    const fileupload3 = $('#file3').prop('files')[0];
    // const fileupload4 = $('#file4').prop('files')[0];

    let nimMhs = $("#nim").val();
    
    console.log(fileupload1);
    console.log(fileupload2);
    console.log(fileupload3);
    console.log(fileupload4);
    // console.log(nimMhs);
    return false
    // var regexpattern = /[\/.](pdf)$/i;
    // let nameF1 = fileupload1.name;
    // let nameF2 = fileupload2.name;
    // let nameF3 = fileupload3.name;
    // let nameF4 = fileupload4.name;

    if(loadstatus(nim) == 51 ){
        swal({
            title: "Alert",
            text:  "File Anda Valid, silahkan menunggu jadwal dibuat",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); 
        return false;
    } else if(loadstatus(nim) == 52){
        swal({
            title: "Alert",
            text:  "File Tidak Valid, silahkan update file",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); 
        return false;
    } else if (loadstatus(nim) == 53 ){
        swal({
            title: "Alert",
            text:  "File sedang dalam proses validasi, silahkan menunggu",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); 
        return false;
    }

    if(document.getElementById("file1").files.length == 0 || document.getElementById("file2").files.length == 0 || document.getElementById("file3").files.length == 0 || document.getElementById("file4").files.length == 0     ){
        swal({
            title: "Alert",
            text:  "File Tidak Boleh Kosong",
            confirmButtonColor: "#2196F3",
            type: "warning"
        });  
        return false;
    } else {
        var regexpattern = /[\/.](pdf)$/i;
        let nameF1 = fileupload1.name;
        let nameF2 = fileupload2.name;
        let nameF3 = fileupload3.name;
        let nameF4 = fileupload4.name;

        if(!regexpattern.test(nameF1)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  
            return false;
        } 
    
        if(!regexpattern.test(nameF2)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  
            return false;
        } 
    
        if(!regexpattern.test(nameF3)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  
            return false;
        } 
    
        if(!regexpattern.test(nameF4)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  
            return false;
        } 
    }

    // if(!regexpattern.test(nameF1)){
    //     swal({
    //         title: "Alert",
    //         text:  "File Harus Berupa PDF!",
    //         confirmButtonColor: "#2196F3",
    //         type: "warning"
    //     });  
    //     return false;
    // } 

    // if(!regexpattern.test(nameF2)){
    //     swal({
    //         title: "Alert",
    //         text:  "File Harus Berupa PDF!",
    //         confirmButtonColor: "#2196F3",
    //         type: "warning"
    //     });  
    //     return false;
    // } 

    // if(!regexpattern.test(nameF3)){
    //     swal({
    //         title: "Alert",
    //         text:  "File Harus Berupa PDF!",
    //         confirmButtonColor: "#2196F3",
    //         type: "warning"
    //     });  
    //     return false;
    // } 

    // if(!regexpattern.test(nameF4)){
    //     swal({
    //         title: "Alert",
    //         text:  "File Harus Berupa PDF!",
    //         confirmButtonColor: "#2196F3",
    //         type: "warning"
    //     });  
    //     return false;
    // } 

    let formData = new FormData();

    formData.append('fileupload1', fileupload1); // set file ke tipe data binary
    formData.append('fileupload2', fileupload2); // set file ke tipe data binary
    formData.append('fileupload3', fileupload3); // set file ke tipe data binary
    formData.append('fileupload4', fileupload4); // set file ke tipe data binary
    formData.append('nimMhs', nimMhs); 
    // console.log(formData);
   
    return false
    $.ajax({
        type        : 'POST',
        url         : baseURL + '/jsondata/saveberkasmahasiswaa',
        data        : formData,
        cache       : false,
        processData : false,
        contentType : false,
        success: function (response) {

            if(response.code == CODE_SUCCESS){
                loaderPage(false)
                // document.getElementById("form-data").reset();

                swal({
                    title: "Alert",
                    text: "Berkas mahasiswa telah ditambahkan ",
                    confirmButtonColor: "#66BB6A",
                    type: "success"
                },function(){ 
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    window.location = baseURL+"/mahasiswa/uploadberkas"
                });

            }else{
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });  
            };

            loaderPage(false);
            
        },
        error: function () {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Alert",
                    text:  xhr.status+"-"+xhr.statusText+" Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
    console.log(fileupload2);
    console.log(fileupload3);
    console.log(fileupload4);
}

function saveFileMhss(){
    loaderPage(true);

    const fileupload1 = $('#file1').prop('files')[0];
    const fileupload2 = $('#file2').prop('files')[0];
    const fileupload3 = $('#file3').prop('files')[0];
    
    let nimMhs  = $("#nim").val();
    let judul   = $("#laporan").val()

    ///////////////////////////////////////////////
    ////////validasi persetujuan pembbing//////////
    ///////////////////////////////////////////////

    if(loadstatus(nim) == 51 ){
        swal({
            title: "Alert",
            text:  "File Anda Valid, silahkan menunggu jadwal dibuat",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); loaderPage(false);
        return false;
    } else if(loadstatus(nim) == 52){
        swal({
            title: "Alert",
            text:  "File Tidak Valid, silahkan update file",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); loaderPage(false);
        return false;
    } else if (loadstatus(nim) == 53 ){
        swal({
            title: "Alert",
            text:  "File sedang dalam proses validasi, silahkan menunggu",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); loaderPage(false);
        return false;
    }

    if(document.getElementById("file1").files.length == 0 || document.getElementById("file2").files.length == 0 || document.getElementById("file3").files.length == 0 ){
        swal({
            title: "Alert",
            text:  "File Tidak Boleh Kosong",
            confirmButtonColor: "#2196F3",
            type: "warning"
        });  loaderPage(false);
        return false;
    } else {
        var regexpattern = /[\/.](pdf)$/i;
        let nameF1 = fileupload1.name;
        let nameF2 = fileupload2.name;
        let nameF3 = fileupload3.name;
        

        if(!regexpattern.test(nameF1) || !regexpattern.test(nameF2) || !regexpattern.test(nameF3)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  loaderPage(false);
            return false;
        } 
        loaderPage(false);
    }

    
    loaderPage(false);
    // arrayOfFiles.push(fileupload1);
    // arrayOfFiles.push(fileupload2);
    // arrayOfFiles.push(fileupload3);
    let formData = new FormData();

    formData.append('fileupload1', fileupload1); // set file ke tipe data binary
    formData.append('fileupload2', fileupload2);
    formData.append('fileupload3', fileupload3);
    formData.append('nimMhs', nimMhs); 
    formData.append('judul', judul);
    // console.log(formData);
   
    $.ajax({
        type        : 'POST',
        url         : baseURL + '/jsondata/saveberkasmahasiswaa',
        data        : formData,
        cache       : false,
        processData : false,
        contentType : false,
        success: function (response) {

            if(response.code == CODE_SUCCESS){
                loaderPage(false)
                // document.getElementById("form-data").reset();

                swal({
                    title: "Alert",
                    text: "Berkas anda telah ditambahkan ",
                    confirmButtonColor: "#66BB6A",
                    type: "success"
                },function(){ loaderPage(false);
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    window.location = baseURL+"/mahasiswa/uploadberkas"
                });

            }else{
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });  loaderPage(false);
            };

            loaderPage(false);
            
        },
        error: function () {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Alert",
                    text:  xhr.status+"-"+xhr.statusText+" Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
    // console.log(fileupload2);
    // console.log(fileupload3);
    // console.log(fileupload4);
}


loadstatus(nim);
function loadstatus(nim){
    var isObject = {};
    isObject.nim = nim;
    console.log(isObject.nim)
    var status;
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/jsondata/loadstatusberkasm',
        async: false,
        data: {
            iparam	    : cryptoEncrypt(PHRASE, isObject),
        },
        success: function(response){
                
            if(response.code == CODE_SUCCESS){
                let result  = cryptoDecrypt(PHRASE, response.data);
                let data    = result.data;
                console.log('ini data');
                console.log(data);
                $("#idberkas").val(data[0].idberkas);
                if(data[0].isvalidtu == 51 || data[0].isvalidtu == 53 || data[0].isvalidtu == 52){

                    $('.btn-save').prop('disabled', true);
                    var rowdata = '';
                    for(i in data){
                        rowdata += `  <ul class="media-list" style="margin-top:10px">
            
                                        <li class="media" >
                                            <div class="media-left media-middle medhov" onclick="showfile('`+baseURL+data[i].file_dir+`','`+data[i].file_name+`')">
                                                <a href="#">
                                                    <img src="`+baseURL+`/img/pdfp.png" class="img-circle img-md" alt="">
                                                </a>
                                            </div>
                            
                                            <div class="media-body medhov media-bodys" onclick="showfile('`+baseURL+data[i].file_dir+`','`+data[i].file_name+`')">
                                            <div class="media-heading text-semibold">`+data[i].file_name+`</div>
                                                <span class="text-muted __web-inspector-hide-shortcut__">File size : `+data[i].file_size+` Mb</span>
                                            </div>
                            
                                            <div class="media-right media-middle">
                                                
                                            </div>
                                        </li>
                                    </ul>`;
                    }

                    $('#listfile').empty();
                    $('#listfile').append(rowdata);
                    $("#inputberkas").hide();
                } 
                // else{
                   
                //     $("#listberkas").hide();
                // }

                // if(data[0].isvalidtu == 62){
                    
                // }

                $("#berinfo").html(data[0].param_desc)
                if(data[0].isvalidtu == 51){
                    $("#ketinfo").html(data[0].keterangan);
                } else {
                    if(data[0].keterangan != null || data[0].keterangan != ''){
                        $("#ketinfo").html(data[0].keterangan)
                    }else{
                        $("#ketinfo").html('-')
                    }
                }
                status = data[0].isvalidtu;
                $("#laporanset").val(data[0].judul_laporan)
                
                if(data[0].isvalidtu == 62){
                    $("#berinfo").html("Anda Belum Upload berkas")
                    $("#updateberkas").hide();
                    $("#ketinfo").html('-')
                }
            } else {
                $("#berinfo").html("Anda Belum Upload berkas")
                $("#updateberkas").hide();
                
                // swal({
                //     title: "Alert",
                //     text:  response.info+ " Silahkan coba kembali :)",
                //     confirmButtonColor: "#2196F3",
                //     type: "error"
                // });
            }

            
            
        },
        error: function(xhr) {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Galat",
                    text:  xhr.status+"-"+xhr.statusText+"<br> Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
    return status;
}

ishavepembimbing(nim);
function ishavepembimbing(nim){
    var isObject = {};
    isObject.nim = nim;
    // console.log(isObject.nim)
    var status;
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/jsondata/ishavepembimbing',
        // async: false,
        data: {
            iparam	    : cryptoEncrypt(PHRASE, isObject),
        },
        success: function(response){
                
            if(response.code == CODE_SUCCESS){
                let result  = cryptoDecrypt(PHRASE, response.data);
                let data    = result.data;
                let count   = data[0];
                console.log(data)

                if(data.length < 2){
                    $(".btn-save").prop('disabled',true);
                    $("#pembinfo").html('Anda belum memiliki <code>Pembimbing</code>, silahkan hubungi TU untuk mendapatkan pembimbing')
                }else{
                        var dosen;
                        if(data[1].gelar_dpn != null && data[1].gelar_blk != null){
                            dosen = data[1].gelar_dpn+" "+data[1].nama+", "+data[1].gelar_blk;
                            // cols += '<option value="'+data[i].NOPEG+'">'+data[i].gelar_dpn+" "+data[i].NAMA+", "+data[i].gelar_dpn+'</option> ';
                        }else if(data[1].gelar_dpn == null && data[1].gelar_blk != null){
                            dosen = data[1].nama+", "+data[1].gelar_blk;
                            // cols += '<option value="'+data[1].NOPEG+'">'+data[1].NAMA+", "+data[i].gelar_dpn+'</option> ';
                        }else if(data[1].gelar_dpn != null && data[1].gelar_blk == null){
                            dosen = data[1].gelar_dpn+" "+data[1].nama;
                            // cols += '<option value="'+data[1].NOPEG+'">'+data[1].gelar_dpn+" "+data[i].NAMA+'</option> ';
                        } else if(data[1].gelar_dpn == null && data[1].gelar_blk == null){
                            dosen = data[1].nama;
                            // cols += '<option value="'+data[i].NOPEG+'">'+data[i].NAMA+'</option> ';
                        }
                        
                    $("#pembinfo").html(dosen+" <i class='icon-checkmark4'></i>");
                }

            } else {
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });
            }
            
        },
        error: function(xhr) {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Galat",
                    text:  xhr.status+"-"+xhr.statusText+"<br> Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
    // return status;   
}

function showfile(path, name){  
    // var cols = `<input id="nim_mhs" value="`+nim+`" type="hidden" class="form-control" placeholder="Nama Perusahaan..">`;
    $('.modal-body').empty();
    // $('.modal-body').append(cols)
    $('.modal-body').append(`<embed src="`+path+`/`+name+`" type="application/pdf"   style="width: 100%; height: 100%; min-height: 480px; ">`);
    $("#modal-review").modal('show');
   
}

function updateFileMhss(){
    const fileupload1 = $('#file1upd').prop('files')[0];
    const fileupload2 = $('#file2upd').prop('files')[0];
    const fileupload3 = $('#file3upd').prop('files')[0];
 
    let nimMhs   = $("#nim").val();
    let idberkas = $("#idberkas").val();
    let roles    = role;
    // console.log(fileupload1);
    // console.log(fileupload2);
    // console.log(fileupload3);  
    // console.log(nimMhs);
    // console.log(idberkas);

    ///////////////////////////////////////////////
    ////////validasi persetujuan pembbing//////////
    ///////////////////////////////////////////////

    if(loadstatus(nim) == 51 ){
        swal({
            title: "Alert",
            text:  "File Anda Valid, silahkan menunggu jadwal dibuat",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); 
        return false;
    } else if(loadstatus(nim) == 52){
        // swal({
        //     title: "Alert",
        //     text:  "File Tidak Valid, silahkan update file",
        //     confirmButtonColor: "#2196F3",
        //     type: "warning"
        // }); 
        // return false;
    } else if (loadstatus(nim) == 53 ){
        swal({
            title: "Alert",
            text:  "File sedang dalam proses validasi, silahkan menunggu",
            confirmButtonColor: "#2196F3",
            type: "warning"
        }); 
        return false;
    }

    let formData = new FormData();

    if(!document.getElementById("file1upd").files.length == 0 ){
        var regexpattern = /[\/.](pdf)$/i;
        let nameF1 = fileupload1.name;
        

        if(!regexpattern.test(nameF1)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  
            return false;
        }else{
            formData.append('fileupload1', fileupload1);
        }
    } 

    if(!document.getElementById("file2upd").files.length == 0 ){
        var regexpattern = /[\/.](pdf)$/i;
        let nameF1 = fileupload2.name;
        

        if(!regexpattern.test(nameF1)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  
            return false;
        }else{
            formData.append('fileupload2', fileupload2);
        }
    } 

    if(!document.getElementById("file3upd").files.length == 0 ){
        var regexpattern = /[\/.](pdf)$/i;
        let nameF1 = fileupload3.name;
        

        if(!regexpattern.test(nameF1)){
            swal({
                title: "Alert",
                text:  "File Harus Berupa PDF!",
                confirmButtonColor: "#2196F3",
                type: "warning"
            });  
            return false;
        }else{
            formData.append('fileupload3', fileupload3);
        }
    } 

    formData.append('nimMhs', nimMhs); 
    formData.append('idberkas', idberkas);
    formData.append('role', roles)
    $.ajax({
        type        : 'POST',
        url         : baseURL + '/jsondata/updateberkasmahasiswa',
        data        : formData,
        cache       : false,
        processData : false,
        contentType : false,
        success: function (response) {

            if(response.code == CODE_SUCCESS){
                loaderPage(false)
                // document.getElementById("form-data").reset();

                swal({
                    title: "Alert",
                    text: "Berkas anda telah di update ",
                    confirmButtonColor: "#66BB6A",
                    type: "success"
                },function(){ 
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    // $("#file1").prop("disabled", true);
                    window.location = baseURL+"/mahasiswa/uploadberkas"
                });

            }else{
                swal({
                    title: "Alert",
                    text:  response.info+ " Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });  
            };

            loaderPage(false);
            
        },
        error: function () {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Alert",
                    text:  xhr.status+"-"+xhr.statusText+" Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });
    // console.log(fileupload2);
    // console.log(fileupload3);
    // console.log(fileupload4);
}

loaddatakp(nim)
function loaddatakp(nim){
    
    var isObject = {};
    isObject.nim = nim;
    console.log(isObject.nim) 
    var status;
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: baseURL + '/jsondata/loaddatakp',
        async: false,
        data: {
            iparam	    : cryptoEncrypt(PHRASE, isObject),
        },
        success: function(response){
                
            if(response.code == CODE_SUCCESS){
                let result  = cryptoDecrypt(PHRASE, response.data);
                let data    = result.data;
                let datas   = data[0];
                console.log(datas)
                // $('#nim').val(datas.nim);
                // $('#idkp').val(datas.id_kp);
                // $('#nopeg').val(datas.no_peg);
                if(datas.approve_proses_bimbingan != 1){
                    $('.btn-save').attr('disabled', true);
                    $("#approve").html('Proses Bimbingan Belum Selesai');
                    /* hinggil cantik*/
                    swal({
                        title: "Tidak dapat melakukan upload berkas",
                        text:  "Proses bimbingan belum selesai, hubungi dosen pembimbing untuk approve bimbingan.",
                        confirmButtonColor: "#2196F3",
                        type: "error"
                    });
                }else{
                    $("#approve").html('Proses Bimbingan Selesai');
                }
                
                if(datas.status_kp == 122){
                    $('.btn-update').attr('disabled', true);
                }
                ////buat disable kalo udah upload berkas
                // if(datas.id_berkas != null || datas.id_berkas == ''){
                //     $("#btn-add").attr('disabled', true)
                // }

                
            } else {
                $("#btn-add").attr('disabled', true)
                // $("#updateberkas").hide();
                // swal({
                //     title: "Alert",
                //     text:  response.info+ " Silahkan coba kembali :)",
                //     confirmButtonColor: "#2196F3",
                //     type: "error"
                // });
            }

            
            
        },
        error: function(xhr) {
            loaderPage(false);
            if(xhr.status != 200){
                swal({
                    title: "Galat",
                    text:  xhr.status+"-"+xhr.statusText+"<br> Silahkan coba kembali :)",
                    confirmButtonColor: "#2196F3",
                    type: "error"
                });                        
            }
        }
    });

}
