// Initialize summernote plugin
$(function () {
    $('#summernote_library_course_details').summernote();
    $('.summernote_library_course_details1').summernote();
});


//CHANGE USER PERMISSIONS
$('.userpermission1').on('change', function () {
    $('.userpermission1').val(this.checked ? 1 : 0);
});
$('.userpermission2').on('change', function () {
    $('.userpermission2').val(this.checked ? 1 : 0);
});
$('.userpermission3').on('change', function () {
    $('.userpermission3').val(this.checked ? 1 : 0);
});
$('.userpermission4').on('change', function () {
    $('.userpermission4').val(this.checked ? 1 : 0);

});
$('.userpermission5').on('change', function () {
    $('.userpermission5').val(this.checked ? 1 : 0);
});
$('.userpermission6').on('change', function () {
    $('.userpermission6').val(this.checked ? 1 : 0);
});
$('.userpermission7').on('change', function () {
    $('.userpermission7').val(this.checked ? 1 : 0);
});

$('.userpermission8').on('change', function () {
    $('.userpermission8').val(this.checked ? 1 : 0);
});


//fetch all course index for library/library-course-details.php page
$(document).ready(function () {
    $('#all_library_course').on('change', function () {
        var courseType = $(this).val();
        if (courseType != "") {
            $.ajax({
                type: 'POST',
                url: '../ajax/search-course-data.php',
                data: {
                    course_id: courseType
                },
                success: function (response) {
                    $('#all_library_index').html(response);
                    console.log(response);
                }
            });
        } else {

        }
    });
});
//preview file
$(function(){
    $('#userPermission_dataTable').on('click','.preview-pdf',function(){
        var id=$(this).attr('data-id');
        ////alert(id);
        if(id!=""){
            $.ajax({
                type:"post",
                url:"pdf-print.php",
                data:{id:id},
                success:function(response){
                    //alert(response);
                    var obj=JSON.parse(response);
                    if(obj.status=="true"){
                        var pdf_file=obj.data['0'].preview_file;
                        // alert(pdf_file);
                        var data=`<iframe src="ebook-files/${pdf_file}#toolbar=0" width="100%" height="250px"></iframe>`;
                        $('#pdf-data').html(data);
                        $('#pdf_view').modal('show');
                    }
                    else{
                        alert(data.msg);
                    }

                }
            });
        }
    });
});
//downloaded_file
$(function(){
    $('#userPermission_dataTable').on('click','.preview-pdf1',function(){
        var id=$(this).attr('data-id');
        ////alert(id);
        if(id!=""){
            $.ajax({
                type:"post",
                url:"pdf-print.php",
                data:{id:id},
                success:function(response){
                    //alert(response);
                    var obj=JSON.parse(response);
                    if(obj.status=="true"){
                        var pdf_file=obj.data['0'].downloaded_file;
                        // alert(pdf_file);
                        var data=`<iframe src="ebook-files/${pdf_file}#toolbar=0" width="100%" height="350px"></iframe>`;
                        $('#pdf-data1').html(data);
                        $('#pdf_view1').modal('show');
                    }
                    else{
                        alert(data.msg);
                    }

                }
            });
        }
    });
});
$(document).ready(function () {
    $(document).on('click', '.show_property_details', function () {
        var course_details = $(this).attr("course-details");
        $('.course-detailsa').html(course_details);
    });

    $(document).on('click', '.show_users_details', function () {
        var dk_name = $(this).attr("dk_name");
        $('.dk_name').html(dk_name);

        var dk_unsername = $(this).attr("dk_unsername");
        $('.dk_unsername').html(dk_unsername);

        var dk_email = $(this).attr("dk_email");
        $('.dk_email').html(dk_email);

        var dk_phone = $(this).attr("dk_phone");
        $('.dk_phone').html(dk_phone);

        var dk_u_type = $(this).attr("dk_u_type");
        $('.dk_u_type').html(dk_u_type);

    });
});


//Assign batch assign 


//$(document).ready(function() {
//        $('#studentd_name_id').on('change', function() {
//            var pTypeid = $(this).val();
//            if (pTypeid != "") {
//                //			alert(pType);
//                $.ajax({
//                    type: 'POST',
//                    url: 'ajax/check-user.php',
//                    data: {
//                        p_type_id: pTypeid
//                    },
//                    success: function(response) {
//                        var data = JSON.parse(response);
//                    if (data.status == "true") {
//                        alert(data.msg);
////                        window.location.reload();
//                    } else {
//                        alert(data.msg);
//                    }
//                    }
//                });
//            } else {
//
//            }
//        });
//    });



//batch  assign to student 
$(function () {
    $('#batch_ask_assign').validate({
        rules: {
            student_name_idas: {
                required: true,
                remote: "ajax/check-user.php"
            },
            student_batch_id: {
                required: true
            }
        },
        messages: {
            student_name_idas: {
                remote: "This student already have assigned the batch. Please select another one or update."
            }
        },
        submitHandler: function (form) {

            $.ajax({
                type: 'post',
                url: 'ajax/assign-batch.php',
                data: $(form).serialize(),
                success: function (result) {
                    // alert(result);
                    //alert(result);
                    var data = JSON.parse(result);
                    if (data.status == "true") {
                        alert(data.msg);
                        window.location.reload();
                    } else {
                        alert(data.msg);
                    }
                }
            });
            return false;
        }

    });
});

//Check User is HR or not 
$(function () {
    $('#check-user-hr').validate({
        rules: {
            student_name_idas: {
                required: true,
                remote: "ajax/check-user-hr.php"
            },
            student_batch_id: {
                required: true
            }
        },
        messages: {
            student_name_idas: {
                remote: "This User already have assigned to HR. Please select another one or update."
            }
        },
        submitHandler: function (form) {

            $.ajax({
                type: 'post',
                url: 'ajax/assign-hr.php',
                data: $(form).serialize(),
                success: function (result) {
                    // alert(result);
                    //alert(result);
                    var data = JSON.parse(result);
                    if (data.status == "true") {
                        alert(data.msg);
                        window.location.reload();
                    } else {
                        alert(data.msg);
                    }
                }
            });
            return false;
        }

    });
});


//update batch  assign to student 
$(function () {
    $('#update_batch_ask_assign').validate({
        rules: {
            student_name_idasup: {
                required: true,
                //                remote:"ajax/update-check-user.php"
            },
            student_batch_idup: {
                required: true
            }
        },
        //        messages: { 
        //            student_name_idasup:{
        //                remote:"This student already have assigned the batch. Please select another one."
        //            }
        //        },
        submitHandler: function (form) {

            $.ajax({
                type: 'post',
                url: 'ajax/update-assign-batch.php',
                data: $(form).serialize(),
                success: function (result) {
                    // alert(result);
                    //alert(result);
                    var data = JSON.parse(result);
                    if (data.status == "true") {
                        alert(data.msg);
                        window.location.href = "batch-assign.php";
                    } else {
                        alert(data.msg);
                    }
                }
            });
            return false;
        }

    });
});



//show course title for make brochure in customize-course/brochure.php page
$(document).ready(function () {
    $('#course_Category_id').on('change', function () {
        var pType = $(this).val();
        if (pType != "") {
            $.ajax({
                type: 'POST',
                url: 'searchdata.php',
                data: {
                    course_id: pType
                },
                success: function (response) {
                    //                         alert(response);
                    $('#all_course_title').html(response);
                    console.log(response);
                }
            });
        } else {

        }
    });
});


//show course title for make brochure in video/video-content.php page
$(document).ready(function () {
    $('#video_course_Category_id').on('change', function () {
        var pType = $(this).val();
        if (pType != "") {
            $.ajax({
                type: 'POST',
                url: 'searchdata.php',
                data: {
                    course_id: pType
                },
                success: function (response) {
                    //                         alert(response);
                    $('#all_video_course_title').html(response);
                    console.log(response);
                }
            });
        } else {

        }
    });
});


//show course title for ebook-assign.to-batch.php page
$(document).ready(function () {
    $('#ebook_courses_id').on('change', function () {
        var pType = $(this).val();
        if (pType != "") {
            $.ajax({
                type: 'POST',
                url: 'searchdata.php',
                data: {
                    course_id: pType
                },
                success: function (response) {
                                            // alert(response);
                    $('#all_eBook_title').html(response);
                    console.log(response);
                }
            });
        } else {

        }
    });
});

