<?php
/**
 * RUHONDO BEACH RESORT HMS + POS System
 * User Profile Page
 * Developer: JOACHIM'S INNOTECH
 */

// Initialize system
require_once dirname(__DIR__) . '/config/config.php';
require_once dirname(__DIR__) . '/config/constants.php';
require_once dirname(__DIR__) . '/config/database.php';
require_once dirname(__DIR__) . '/config/helpers.php';
require_once dirname(__DIR__) . '/config/auth.php';
require_once dirname(__DIR__) . '/config/csrf.php';

// Require authentication
require_auth();

// Set page title
$page_title = 'My Profile';

// Get current user
$current_user = current_user();
$user_id = $current_user['user_id'];

// Handle form submissions
$message = '';
$error = '';
$active_tab = $_GET['tab'] ?? 'profile';

// Get user role name
$role_name = db_fetch_value("SELECT role_name FROM roles WHERE role_id = ?", [$current_user['role_id']]);

// Get user activity log
$activities = db_fetch_all(
    "SELECT * FROM audit_logs WHERE user_id = ? ORDER BY created_at DESC LIMIT 20",
    [$user_id]
);

// Get user sessions
$sessions = db_fetch_all(
    "SELECT * FROM user_sessions WHERE user_id = ? ORDER BY last_activity DESC LIMIT 10",
    [$user_id]
);

// Handle profile update
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
    // Verify CSRF token
    if (!verify_csrf_token($_POST[CSRF_TOKEN_NAME] ?? '')) {
        $error = 'Invalid security token. Please try again.';
    } else {
        $action = $_POST['action'];
        
        switch ($action) {
            case 'update_profile':
                // Get and validate input
                $first_name = sanitize_input($_POST['first_name'] ?? '');
                $last_name = sanitize_input($_POST['last_name'] ?? '');
                $email = sanitize_input($_POST['email'] ?? '');
                $phone = sanitize_input($_POST['phone'] ?? '');
                
                $errors = [];
                
                if (empty($first_name)) {
                    $errors[] = 'First name is required';
                }
                
                if (empty($last_name)) {
                    $errors[] = 'Last name is required';
                }
                
                if (empty($email)) {
                    $errors[] = 'Email is required';
                } elseif (!validate_email($email)) {
                    $errors[] = 'Invalid email format';
                }
                
                // Check if email already exists for another user
                $existing = db_fetch_one(
                    "SELECT user_id FROM users WHERE email = ? AND user_id != ?",
                    [$email, $user_id]
                );
                
                if ($existing) {
                    $errors[] = 'Email address is already in use by another account';
                }
                
                if (empty($errors)) {
                    // Update profile
                    $old_values = [
                        'first_name' => $current_user['first_name'],
                        'last_name' => $current_user['last_name'],
                        'email' => $current_user['email'],
                        'phone' => $current_user['phone']
                    ];
                    
                    $new_values = [
                        'first_name' => $first_name,
                        'last_name' => $last_name,
                        'email' => $email,
                        'phone' => $phone
                    ];
                    
                    db_update('users', $new_values, 'user_id = ?', [$user_id]);
                    
                    // Audit log
                    audit_log($user_id, AUDIT_UPDATE, 'users', $user_id, $old_values, $new_values);
                    
                    $message = 'Profile updated successfully';
                    
                    // Refresh user data
                    $current_user = current_user();
                } else {
                    $error = implode('<br>', $errors);
                }
                break;
                
            case 'change_password':
                $current_password = $_POST['current_password'] ?? '';
                $new_password = $_POST['new_password'] ?? '';
                $confirm_password = $_POST['confirm_password'] ?? '';
                
                $result = change_password($current_password, $new_password);
                
                if ($result === true) {
                    $message = 'Password changed successfully';
                } else {
                    $error = $result;
                }
                break;
                
            case 'upload_photo':
                if (isset($_FILES['profile_photo']) && $_FILES['profile_photo']['error'] === UPLOAD_ERR_OK) {
                    $upload_result = upload_file(
                        $_FILES['profile_photo'],
                        UPLOAD_PATH_IDS,
                        ['jpg', 'jpeg', 'png', 'gif']
                    );
                    
                    if ($upload_result['success']) {
                        // Delete old photo if exists
                        if (!empty($current_user['profile_image'])) {
                            delete_file(UPLOAD_PATH_IDS . $current_user['profile_image']);
                        }
                        
                        // Update user record
                        $old_value = $current_user['profile_image'];
                        db_update('users', ['profile_image' => $upload_result['filename']], 'user_id = ?', [$user_id]);
                        
                        // Audit log
                        audit_log($user_id, AUDIT_UPLOAD, 'users', $user_id, ['profile_image' => $old_value], ['profile_image' => $upload_result['filename']]);
                        
                        $message = 'Profile photo updated successfully';
                        
                        // Refresh user data
                        $current_user = current_user();
                    } else {
                        $error = 'Failed to upload photo: ' . implode(', ', $upload_result['errors']);
                    }
                } else {
                    $error = 'Please select a photo to upload';
                }
                break;
                
            case 'remove_photo':
                if (!empty($current_user['profile_image'])) {
                    delete_file(UPLOAD_PATH_IDS . $current_user['profile_image']);
                    db_update('users', ['profile_image' => null], 'user_id = ?', [$user_id]);
                    
                    audit_log($user_id, AUDIT_UPDATE, 'users', $user_id, ['profile_image' => $current_user['profile_image']], ['profile_image' => null]);
                    
                    $message = 'Profile photo removed successfully';
                    
                    // Refresh user data
                    $current_user = current_user();
                }
                break;
                
            case 'end_session':
                $session_id = $_POST['session_id'] ?? '';
                if ($session_id) {
                    db_delete('user_sessions', 'session_id = ?', [$session_id]);
                    $message = 'Session ended successfully';
                }
                break;
                
            case 'end_all_sessions':
                db_delete('user_sessions', 'user_id = ? AND session_id != ?', [$user_id, session_id()]);
                $message = 'All other sessions ended successfully';
                break;
        }
    }
}

// Include header
require_once dirname(__DIR__) . '/views/partials/header.php';
?>

<div class="row">
    <div class="col-md-3">
        <!-- Profile Image Card -->
        <div class="card card-primary card-outline">
            <div class="card-body box-profile">
                <div class="text-center">
                    <?php if (!empty($current_user['profile_image'])): ?>
                        <img class="profile-user-img img-fluid img-circle"
                             src="<?php echo uploads_url('ids/' . $current_user['profile_image']); ?>"
                             alt="User profile picture"
                             style="width: 100px; height: 100px; object-fit: cover;">
                    <?php else: ?>
                        <div class="profile-user-img img-fluid img-circle d-flex align-items-center justify-content-center bg-primary text-white mx-auto"
                             style="width: 100px; height: 100px; font-size: 2.5rem;">
                            <?php echo strtoupper(substr($current_user['first_name'], 0, 1) . substr($current_user['last_name'], 0, 1)); ?>
                        </div>
                    <?php endif; ?>
                </div>

                <h3 class="profile-username text-center"><?php echo escape_html($current_user['first_name'] . ' ' . $current_user['last_name']); ?></h3>

                <p class="text-muted text-center"><?php echo escape_html($role_name); ?></p>

                <ul class="list-group list-group-unbordered mb-3">
                    <li class="list-group-item">
                        <b>Username</b> <a class="float-right"><?php echo escape_html($current_user['username']); ?></a>
                    </li>
                    <li class="list-group-item">
                        <b>Email</b> <a class="float-right"><?php echo escape_html($current_user['email']); ?></a>
                    </li>
                    <li class="list-group-item">
                        <b>Member Since</b> <a class="float-right"><?php echo format_date($current_user['created_at'], 'M Y'); ?></a>
                    </li>
                    <li class="list-group-item">
                        <b>Last Login</b> <a class="float-right"><?php echo $current_user['last_login'] ? time_ago($current_user['last_login']) : 'Never'; ?></a>
                    </li>
                </ul>

                <!-- Photo Upload Form -->
                <form action="" method="POST" enctype="multipart/form-data" class="mb-2">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="action" value="upload_photo">
                    
                    <div class="input-group mb-2">
                        <input type="file" class="form-control form-control-sm" name="profile_photo" accept="image/*" required>
                        <button type="submit" class="btn btn-primary btn-sm">
                            <i class="fas fa-upload"></i> Upload
                        </button>
                    </div>
                </form>
                
                <?php if (!empty($current_user['profile_image'])): ?>
                <form action="" method="POST">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="action" value="remove_photo">
                    <button type="submit" class="btn btn-danger btn-sm btn-block" onclick="return confirm('Remove profile photo?')">
                        <i class="fas fa-trash"></i> Remove Photo
                    </button>
                </form>
                <?php endif; ?>
            </div>
        </div>

        <!-- About Me Card -->
        <div class="card card-primary">
            <div class="card-header">
                <h3 class="card-title">About Me</h3>
            </div>
            <div class="card-body">
                <strong><i class="fas fa-book mr-1"></i> Department</strong>
                <p class="text-muted"><?php echo escape_html($current_user['department'] ?? 'Not specified'); ?></p>

                <hr>

                <strong><i class="fas fa-phone mr-1"></i> Phone</strong>
                <p class="text-muted"><?php echo escape_html($current_user['phone'] ?? 'Not provided'); ?></p>

                <hr>

                <strong><i class="fas fa-map-marker-alt mr-1"></i> Location</strong>
                <p class="text-muted">Ruhondo Beach Resort, Rwanda</p>

                <hr>

                <strong><i class="fas fa-clock mr-1"></i> Timezone</strong>
                <p class="text-muted"><?php echo date_default_timezone_get(); ?></p>
            </div>
        </div>
    </div>

    <div class="col-md-9">
        <!-- Nav Tabs -->
        <div class="card">
            <div class="card-header p-2">
                <ul class="nav nav-pills">
                    <li class="nav-item">
                        <a class="nav-link <?php echo $active_tab == 'profile' ? 'active' : ''; ?>" href="#profile" data-toggle="tab">
                            <i class="fas fa-user mr-1"></i> Profile
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?php echo $active_tab == 'password' ? 'active' : ''; ?>" href="#password" data-toggle="tab">
                            <i class="fas fa-lock mr-1"></i> Change Password
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?php echo $active_tab == 'sessions' ? 'active' : ''; ?>" href="#sessions" data-toggle="tab">
                            <i class="fas fa-desktop mr-1"></i> Active Sessions
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?php echo $active_tab == 'activity' ? 'active' : ''; ?>" href="#activity" data-toggle="tab">
                            <i class="fas fa-history mr-1"></i> Recent Activity
                        </a>
                    </li>
                </ul>
            </div>

            <div class="card-body">
                <!-- Success/Error Messages -->
                <?php if ($message): ?>
                    <div class="alert alert-success alert-dismissible fade show">
                        <i class="fas fa-check-circle mr-2"></i>
                        <?php echo $message; ?>
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                    </div>
                <?php endif; ?>
                
                <?php if ($error): ?>
                    <div class="alert alert-danger alert-dismissible fade show">
                        <i class="fas fa-exclamation-circle mr-2"></i>
                        <?php echo $error; ?>
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                    </div>
                <?php endif; ?>

                <!-- Tab Content -->
                <div class="tab-content">
                    <!-- Profile Tab -->
                    <div class="tab-pane <?php echo $active_tab == 'profile' ? 'active' : ''; ?>" id="profile">
                        <form class="form-horizontal" method="POST">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="action" value="update_profile">
                            
                            <div class="form-group row">
                                <label for="first_name" class="col-sm-3 col-form-label">First Name</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="first_name" name="first_name" 
                                           value="<?php echo escape_html($current_user['first_name']); ?>" required>
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <label for="last_name" class="col-sm-3 col-form-label">Last Name</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="last_name" name="last_name" 
                                           value="<?php echo escape_html($current_user['last_name']); ?>" required>
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <label for="username" class="col-sm-3 col-form-label">Username</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="username" 
                                           value="<?php echo escape_html($current_user['username']); ?>" disabled>
                                    <small class="text-muted">Username cannot be changed</small>
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <label for="email" class="col-sm-3 col-form-label">Email</label>
                                <div class="col-sm-9">
                                    <input type="email" class="form-control" id="email" name="email" 
                                           value="<?php echo escape_html($current_user['email']); ?>" required>
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <label for="phone" class="col-sm-3 col-form-label">Phone</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="phone" name="phone" 
                                           value="<?php echo escape_html($current_user['phone']); ?>">
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <div class="offset-sm-3 col-sm-9">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fas fa-save mr-1"></i> Save Changes
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>

                    <!-- Change Password Tab -->
                    <div class="tab-pane <?php echo $active_tab == 'password' ? 'active' : ''; ?>" id="password">
                        <form class="form-horizontal" method="POST" id="passwordForm">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="action" value="change_password">
                            
                            <div class="form-group row">
                                <label for="current_password" class="col-sm-3 col-form-label">Current Password</label>
                                <div class="col-sm-9">
                                    <input type="password" class="form-control" id="current_password" name="current_password" required>
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <label for="new_password" class="col-sm-3 col-form-label">New Password</label>
                                <div class="col-sm-9">
                                    <input type="password" class="form-control" id="new_password" name="new_password" required>
                                    <small class="text-muted">
                                        Password must be at least 8 characters and contain uppercase, lowercase, number, and special character
                                    </small>
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <label for="confirm_password" class="col-sm-3 col-form-label">Confirm Password</label>
                                <div class="col-sm-9">
                                    <input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
                                </div>
                            </div>
                            
                            <!-- Password Strength Indicator -->
                            <div class="form-group row">
                                <div class="offset-sm-3 col-sm-9">
                                    <div class="progress" style="height: 5px;">
                                        <div class="progress-bar" id="passwordStrength" role="progressbar" style="width: 0%;"></div>
                                    </div>
                                    <small class="text-muted" id="passwordStrengthText">Enter password</small>
                                </div>
                            </div>
                            
                            <div class="form-group row">
                                <div class="offset-sm-3 col-sm-9">
                                    <button type="submit" class="btn btn-primary" id="changePasswordBtn">
                                        <i class="fas fa-key mr-1"></i> Change Password
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>

                    <!-- Sessions Tab -->
                    <div class="tab-pane <?php echo $active_tab == 'sessions' ? 'active' : ''; ?>" id="sessions">
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Device</th>
                                        <th>IP Address</th>
                                        <th>Last Activity</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($sessions as $session): 
                                        $is_current = $session['session_id'] === session_id();
                                    ?>
                                    <tr>
                                        <td>
                                            <?php
                                            $user_agent = $session['user_agent'] ?? 'Unknown';
                                            $browser = 'Unknown';
                                            $os = 'Unknown';
                                            
                                            if (preg_match('/MSIE/i', $user_agent) || preg_match('/Trident/i', $user_agent)) {
                                                $browser = 'Internet Explorer';
                                            } elseif (preg_match('/Firefox/i', $user_agent)) {
                                                $browser = 'Firefox';
                                            } elseif (preg_match('/Chrome/i', $user_agent)) {
                                                $browser = 'Chrome';
                                            } elseif (preg_match('/Safari/i', $user_agent)) {
                                                $browser = 'Safari';
                                            } elseif (preg_match('/Opera/i', $user_agent) || preg_match('/OPR/i', $user_agent)) {
                                                $browser = 'Opera';
                                            } elseif (preg_match('/Edge/i', $user_agent)) {
                                                $browser = 'Edge';
                                            }
                                            
                                            if (preg_match('/Windows/i', $user_agent)) {
                                                $os = 'Windows';
                                            } elseif (preg_match('/Mac/i', $user_agent)) {
                                                $os = 'macOS';
                                            } elseif (preg_match('/Linux/i', $user_agent)) {
                                                $os = 'Linux';
                                            } elseif (preg_match('/Android/i', $user_agent)) {
                                                $os = 'Android';
                                            } elseif (preg_match('/iPhone/i', $user_agent)) {
                                                $os = 'iOS';
                                            }
                                            
                                            echo "<i class='fas fa-" . ($os == 'Windows' ? 'windows' : ($os == 'macOS' ? 'apple' : 'desktop')) . " mr-2'></i>";
                                            echo "$browser on $os";
                                            ?>
                                        </td>
                                        <td><?php echo $session['ip_address'] ?? 'Unknown'; ?></td>
                                        <td><?php echo $session['last_activity'] ? time_ago($session['last_activity']) : 'Never'; ?></td>
                                        <td>
                                            <?php if ($is_current): ?>
                                                <span class="badge badge-success">Current Session</span>
                                            <?php else: ?>
                                                <span class="badge badge-secondary">Active</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if (!$is_current): ?>
                                                <form method="POST" style="display: inline;">
                                                    <?php echo csrf_field(); ?>
                                                    <input type="hidden" name="action" value="end_session">
                                                    <input type="hidden" name="session_id" value="<?php echo $session['session_id']; ?>">
                                                    <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('End this session?')">
                                                        <i class="fas fa-sign-out-alt"></i> End
                                                    </button>
                                                </form>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                        
                        <?php if (count($sessions) > 1): ?>
                        <form method="POST" class="mt-3">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="action" value="end_all_sessions">
                            <button type="submit" class="btn btn-warning" onclick="return confirm('End all other sessions? You will remain logged in on this device.')">
                                <i class="fas fa-sign-out-alt mr-1"></i> End All Other Sessions
                            </button>
                        </form>
                        <?php endif; ?>
                    </div>

                    <!-- Activity Tab -->
                    <div class="tab-pane <?php echo $active_tab == 'activity' ? 'active' : ''; ?>" id="activity">
                        <div class="timeline">
                            <?php foreach ($activities as $activity): ?>
                            <div class="timeline-item">
                                <span class="time">
                                    <i class="fas fa-clock"></i> <?php echo time_ago($activity['created_at']); ?>
                                </span>
                                <div class="timeline-body">
                                    <i class="fas <?php 
                                        switch($activity['action']) {
                                            case 'login': echo 'fa-sign-in-alt text-success'; break;
                                            case 'logout': echo 'fa-sign-out-alt text-warning'; break;
                                            case 'create': echo 'fa-plus-circle text-success'; break;
                                            case 'update': echo 'fa-edit text-info'; break;
                                            case 'delete': echo 'fa-trash text-danger'; break;
                                            default: echo 'fa-info-circle text-secondary';
                                        }
                                    ?> mr-2"></i>
                                    <strong><?php echo ucfirst($activity['action']); ?></strong>
                                    <?php if ($activity['table_name']): ?>
                                        on <?php echo str_replace('_', ' ', $activity['table_name']); ?>
                                        <?php if ($activity['record_id']): ?>
                                            #<?php echo $activity['record_id']; ?>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                    <br>
                                    <small class="text-muted">
                                        IP: <?php echo $activity['ip_address'] ?? 'Unknown'; ?>
                                        <?php if ($activity['old_values'] || $activity['new_values']): ?>
                                            <br>
                                            <a href="#" onclick="showAuditDetails(this)" data-old='<?php echo $activity['old_values']; ?>' data-new='<?php echo $activity['new_values']; ?>'>
                                                View Details
                                            </a>
                                        <?php endif; ?>
                                    </small>
                                </div>
                            </div>
                            <?php endforeach; ?>
                            
                            <?php if (empty($activities)): ?>
                                <div class="text-center text-muted py-4">
                                    <i class="fas fa-history fa-3x mb-3"></i>
                                    <p>No activity recorded yet</p>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Audit Details Modal -->
<div class="modal fade" id="auditDetailsModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Audit Details</h5>
                <button type="button" class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-6">
                        <h6>Old Values</h6>
                        <pre id="oldValues" class="bg-light p-2 rounded" style="max-height: 200px; overflow: auto;"></pre>
                    </div>
                    <div class="col-md-6">
                        <h6>New Values</h6>
                        <pre id="newValues" class="bg-light p-2 rounded" style="max-height: 200px; overflow: auto;"></pre>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
$(document).ready(function() {
    // Password strength checker
    $('#new_password').on('input', function() {
        const password = $(this).val();
        let strength = 0;
        const $strengthBar = $('#passwordStrength');
        const $strengthText = $('#passwordStrengthText');
        
        if (password.length >= 8) strength += 25;
        if (password.match(/[a-z]+/)) strength += 25;
        if (password.match(/[A-Z]+/)) strength += 25;
        if (password.match(/[0-9]+/)) strength += 12.5;
        if (password.match(/[@$!%*?&]+/)) strength += 12.5;
        
        $strengthBar.css('width', strength + '%');
        
        if (strength < 50) {
            $strengthBar.removeClass('bg-success bg-info bg-warning').addClass('bg-danger');
            $strengthText.text('Weak password');
        } else if (strength < 75) {
            $strengthBar.removeClass('bg-danger bg-success bg-warning').addClass('bg-warning');
            $strengthText.text('Medium password');
        } else if (strength < 90) {
            $strengthBar.removeClass('bg-danger bg-warning bg-success').addClass('bg-info');
            $strengthText.text('Strong password');
        } else {
            $strengthBar.removeClass('bg-danger bg-warning bg-info').addClass('bg-success');
            $strengthText.text('Very strong password');
        }
    });
    
    // Password match validation
    $('#passwordForm').on('submit', function(e) {
        const newPass = $('#new_password').val();
        const confirmPass = $('#confirm_password').val();
        
        if (newPass !== confirmPass) {
            e.preventDefault();
            alert('New password and confirm password do not match');
        }
    });
    
    // Handle tab activation from URL
    const urlParams = new URLSearchParams(window.location.search);
    const tab = urlParams.get('tab');
    if (tab) {
        $('.nav-pills a[href="#' + tab + '"]').tab('show');
    }
});

function showAuditDetails(element) {
    const oldValues = $(element).data('old');
    const newValues = $(element).data('new');
    
    $('#oldValues').text(oldValues ? JSON.stringify(JSON.parse(oldValues), null, 2) : 'No old values');
    $('#newValues').text(newValues ? JSON.stringify(JSON.parse(newValues), null, 2) : 'No new values');
    
    $('#auditDetailsModal').modal('show');
}
</script>

<?php
// Include footer
require_once dirname(__DIR__) . '/views/partials/footer.php';
?>