function approve_click(clicked_id){
    var num = document.getElementById(clicked_id.id).value;
    var staff = $('#staffID').val();
    var request = $('#request'+num).val();
    
    if(staff===''){
        alert('Failed to identify staff details!\nLogout and Login again, or contact system admin');
    }else
    if(request===''){
        alert('Failed to identify leave request details');
    }else
    if(num===''){
        alert('Failed to identify modal number');
    }else
    {
        $.ajax({
            url:"validate/pass-request-approval.php",
            type:"POST",
            data:{staff:staff,request:request},
            success:function(data){
                var res = $.trim(data);

                if(res === 'SQL_error'){
                   alert("Server side error occured");
                }else
                if(res === 'request_error'){
                   alert("This request has already been approved!");
                }else
                if(res === 'approval_success'){
                   $('#myModalX'+num).modal("hide");
                   alert("Student Gate Pass Request Approval Successful!");
                   location.reload();
                }
            }
         });
    }
}

function denied_click(clicked_id){
    var num = document.getElementById(clicked_id.id).value;
    var deny = $('#denied'+num).val();
    var user = $('#staffID').val();
    var request = $('#request'+num).val(); 

    if(deny===''){
        alert('Enter reason for denial of gate pass request!');
        $('#denied').focus();
    }else
    if(user===''){
        alert('Failed to identify staff details!\nLogout and Login again, or contact system admin');
    }else
    if(request===''){
        alert('Failed to identify gate pass request details');
    }else
    if(num===''){
        alert('Failed to identify modal number');
    }else
    {
        $.ajax({
            url:"validate/pass-request.php",
            type:"POST",
            data:{user:user, deny:deny,request:request},
            success:function(data){
                var result = $.trim(data);

                 if(result === 'SQL_error'){
                    alert("Server side error occured");
                 }else
                 if(result === 'request_error'){
                    alert("This request has already been denied!");
                 }else
                 if(result === 'denial_success'){
                    $('#myModalX'+num).modal("hide");
                    alert("Gate Pass Request has been denied!");
                    location.reload();
                 }
            }
         });
    }
}
  