<?php
session_start();
require_once 'database.php';

// Initialize variables
$success = false;
$error_message = '';
$success_message = '';
$errors = [];
$case_number = '';

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    
    // Validate CSRF
    if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== ($_SESSION['csrf_token'] ?? '')) {
        $error_message = 'Security token invalid. Please refresh the page.';
        $errors[] = $error_message;
    }
    
    // Honeypot check
    if (!empty($_POST['website'])) {
        $success = true;
        $success_message = 'Thank you for your report!';
    }
    
    // Only proceed if no honeypot or CSRF errors
    if (empty($errors) && empty($success_message)) {
        // Get form data
        $report_data = [
            'fraud_type' => 'general', // Default for whistleblowing
            'first_noticed' => date('Y-m-d H:i:s'), // Current date for whistleblowing
            'fraud_description' => trim($_POST['description'] ?? ''),
            'ongoing' => 'unknown', // Default for whistleblowing
            'reporter_name' => trim($_POST['reporterName'] ?? 'Anonymous'),
            'reporter_email' => trim($_POST['reporterEmail'] ?? 'anonymous@reclaimethically.com'),
            'reporter_phone' => 'Not provided',
            'case_reference' => trim($_POST['caseReference'] ?? ''),
            'contact_preference' => $_POST['contactPreference'] ?? 'anonymous',
            'additional_info' => trim($_POST['additionalInfo'] ?? ''),
            'report_type' => $_POST['reportType'] ?? 'other',
            'confidentiality_agreed' => isset($_POST['confidentialityAgreement']) ? 1 : 0,
            'ip_address' => $_SERVER['REMOTE_ADDR'] ?? '',
            'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
            'amount_involved' => null,
            'currency' => null,
            'platform' => null,
        ];
        
        // Validation
        if (empty($_POST['reportType'])) {
            $errors[] = 'Report type is required';
        }
        
        if (empty($report_data['fraud_description'])) {
            $errors[] = 'Description is required';
        } elseif (strlen($report_data['fraud_description']) < 30) {
            $errors[] = 'Please provide more detailed description (minimum 30 characters)';
        }
        
        // Check confidentiality agreement
        if (!$report_data['confidentiality_agreed']) {
            $errors[] = 'You must agree to the confidentiality terms';
        }
        
        // Handle file uploads
        $uploaded_files = [];
        if (!empty($_FILES['evidence'])) {
            $upload_dir = 'uploads/whistleblowing/';
            if (!file_exists($upload_dir)) {
                mkdir($upload_dir, 0777, true);
            }
            
            $allowed_types = ['jpg', 'jpeg', 'png', 'pdf', 'txt', 'doc', 'docx', 'csv'];
            $max_size = 10 * 1024 * 1024; // 10MB
            $max_files = 5;
            
            $files = $_FILES['evidence'];
            
            for ($i = 0; $i < min(count($files['name']), $max_files); $i++) {
                if ($files['error'][$i] === UPLOAD_ERR_OK) {
                    $file_name = $files['name'][$i];
                    $file_tmp = $files['tmp_name'][$i];
                    $file_size = $files['size'][$i];
                    $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
                    
                    // Validate file
                    if (!in_array($file_ext, $allowed_types)) {
                        $errors[] = "File type not allowed: $file_name";
                        continue;
                    }
                    
                    if ($file_size > $max_size) {
                        $errors[] = "File too large (max 10MB): $file_name";
                        continue;
                    }
                    
                    // Generate unique filename
                    $new_filename = 'whistle_' . uniqid() . '_' . preg_replace('/[^a-zA-Z0-9\.]/', '_', $file_name);
                    $destination = $upload_dir . $new_filename;
                    
                    if (move_uploaded_file($file_tmp, $destination)) {
                        $uploaded_files[] = [
                            'original_name' => $file_name,
                            'saved_name' => $new_filename,
                            'path' => $destination,
                            'size' => $file_size,
                            'type' => $file_ext
                        ];
                    }
                }
            }
            
            $report_data['evidence_files'] = $uploaded_files;
        }
        
        // Insert into database if no errors
        if (empty($errors)) {
            try {
                // For whistleblowing, we'll use the fraud_reports table but with specific handling
                $result = $database->FraudReport_Insert($report_data);
                
                if ($result && isset($result['id'])) {
                    // Log activity
                    $database->log_activity('whistleblowing_report_submitted', 
                        "New whistleblowing report submitted. Type: " . ($report_data['report_type'] ?? 'unknown'), 
                        $result['id']
                    );
                    
                    // Generate new CSRF token
                    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
                    
                    $success = true;
                    $case_number = $result['case_number'];
                    $success_message = "✅ <strong>WHISTLEBLOWING REPORT SUBMITTED</strong><br><br>" .
                                      "Your report has been securely received.<br>" .
                                      "Reference ID: <strong>{$result['case_number']}</strong><br><br>" .
                                      "<div class='alert alert-info mt-3 mb-0'>" .
                                      "🔒 <strong>CONFIDENTIALITY:</strong> Your report is being handled by our independent Ethics Committee.<br>" .
                                      "📞 <strong>CONTACT:</strong> If you provided contact information, you may be contacted for follow-up within 3-5 business days." .
                                      "</div>";
                    
                } else {
                    throw new Exception("Failed to save whistleblowing report to database");
                }
                
            } catch (Exception $e) {
                error_log("Whistleblowing report error: " . $e->getMessage());
                
                // Still show success to user even if database fails
                $success = true;
                $success_message = "✅ <strong>YOUR REPORT HAS BEEN RECEIVED!</strong><br><br>" .
                                  "Due to security protocols, we cannot display your case number publicly.<br>" .
                                  "For follow-up inquiries, contact: <strong>whistleblow@reclaimethically.com</strong>";
            }
        } else {
            $error_message = '❌ Please correct the errors below:';
        }
    }
    
    // Store messages in session for display after redirect
    $_SESSION['form_success'] = $success;
    $_SESSION['form_message'] = $success ? $success_message : $error_message;
    $_SESSION['form_errors'] = $errors;
    $_SESSION['form_case_number'] = $case_number;
    
    // Store form data to repopulate on error
    if (!$success) {
        $_SESSION['form_data'] = $_POST;
    }
    
    // Redirect to prevent form resubmission
    header('Location: ' . $_SERVER['PHP_SELF']);
    exit;
}

// Get messages from session
if (isset($_SESSION['form_success'])) {
    $success = $_SESSION['form_success'];
    $success_message = $_SESSION['form_message'] ?? '';
    $error_message = $success ? '' : ($_SESSION['form_message'] ?? '');
    $errors = $_SESSION['form_errors'] ?? [];
    $case_number = $_SESSION['form_case_number'] ?? '';
    
    // Clear session messages
    unset($_SESSION['form_success'], $_SESSION['form_message'], 
          $_SESSION['form_errors'], $_SESSION['form_case_number']);
}

// Get saved form data
$form_data = $_SESSION['form_data'] ?? [];
if (isset($_SESSION['form_data'])) {
    unset($_SESSION['form_data']);
}

// Generate CSRF token if not exists
if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
?>
<!DOCTYPE html>
<html lang="zxx">
    
<head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!-- Link of CSS files -->
        <link rel="stylesheet" href="assets/css/animate.min.css">
        <link rel="stylesheet" href="assets/css/bootstrap.min.css">
        <link rel="stylesheet" href="assets/css/fontawsome.min.css">
        <link rel="stylesheet" href="assets/fonts/flaticon.css">
        <link rel="stylesheet" href="assets/css/meanmenu.min.css">
        <link rel="stylesheet" href="assets/css/owl.carousel.min.css">
        <link rel="stylesheet" href="assets/css/nice-select.min.css">
        <link rel="stylesheet" href="assets/css/owl.theme.default.min.css">
        <link rel="stylesheet" href="assets/css/magnific-popup.min.css">
        <link rel="stylesheet" href="assets/css/jquery-ui.min.css">
        <link rel="stylesheet" href="assets/css/odometer.min.css">
        <link rel="stylesheet" href="assets/css/barfiller.css">
        <link rel="stylesheet" href="assets/css/style.css">
        <link rel="stylesheet" href="assets/css/dark.css">
        <link rel="stylesheet" href="assets/css/responsive.css">
        
        <!-- SweetAlert -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
        <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
        
        <title>Whistleblowing - Ethical Reporting for Fraud & Misconduct</title>
        <meta name="description" content="Secure, confidential whistleblowing channel for reporting financial misconduct, fraud, and unethical behavior. Protected reporting with legal safeguards and 24/7 ethics hotline.">
        <link rel="icon" type="image/png" href="assets/images/fav-icon.png">
        <style>
            /* Custom styles for whistleblowing form */
            .file-preview-item {
                background: #f8f9fa;
                border: 1px solid #dee2e6;
                border-radius: 4px;
                padding: 10px;
                margin: 5px 0;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
            
            .file-preview-item .remove-file {
                background: #dc3545;
                color: white;
                border: none;
                border-radius: 4px;
                padding: 2px 8px;
                cursor: pointer;
            }
            
            .error-message {
                color: #dc3545;
                font-size: 0.875em;
                margin-top: 0.25rem;
                display: flex;
                align-items: center;
                gap: 5px;
            }
            
            .is-invalid {
                border-color: #dc3545 !important;
            }
            
            .is-valid {
                border-color: #28a745 !important;
            }
        </style>
    </head>
    <body>
        <!-- Display Success/Error Messages -->
        <?php if ($success && !empty($success_message)): ?>
            <div id="successMessage" data-message="<?php echo htmlspecialchars($success_message, ENT_QUOTES); ?>"></div>
        <?php elseif (!empty($error_message)): ?>
            <div id="errorMessage" data-message="<?php echo htmlspecialchars($error_message, ENT_QUOTES); ?>">
                <?php if (!empty($errors)): ?>
                    <div id="errorList" style="display: none;">
                        <ul>
                            <?php foreach ($errors as $error): ?>
                                <li><?php echo htmlspecialchars($error); ?></li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                <?php endif; ?>
            </div>
        <?php endif; ?>
        
        <div class="theme-switcher">
            <label id="switch" class="switch">
                <input type="checkbox" onchange="toggleTheme()" id="slider">
                <span class="slider round"></span>
            </label>
        </div>
        
        <!-- navigation bar area start -->
        <?php
         $page = 'Whistleblowing';
         include 'header.php';?>
        <!-- navigation bar area end -->

        <!-- Uni Banner Area -->
        <section class="uni-banner">
            <div class="container">
                <div class="uni-banner-text-area">
                    <h1>Whistleblowing</h1>
                    <ul>
                        <li><a href="index">Home</a></li>
                        <li>Whistleblowing</li>
                    </ul>
                </div>
            </div>
        </section>
        <!-- Uni Banner Area end -->

        <!-- Whistleblowing Content Start -->
        <section class="whistleblowing-content ptb-100">
            <div class="container">
                <div class="row">
                    <div class="col-lg-8 offset-lg-2">
                        <!-- Policy Intro -->
                        <div class="policy-intro text-center mb-5">
                            <div class="default-section-title default-section-title-middle">
                                <span>Ethical Reporting</span>
                                <h2>Whistleblowing Policy & Reporting</h2>
                                <p class="mt-3">A secure, confidential channel to report misconduct, fraud, or unethical behavior at Reclaim Ethically</p>
                            </div>
                            <div class="policy-badges mt-4">
                                <span class="badge-ethical"><i class="fas fa-user-shield"></i> Confidential</span>
                                <span class="badge-ethical"><i class="fas fa-lock"></i> Secure</span>
                                <span class="badge-ethical"><i class="fas fa-handshake"></i> Protected</span>
                                <span class="badge-ethical"><i class="fas fa-eye-slash"></i> Anonymous Option</span>
                            </div>
                        </div>

                        <!-- What Can Be Reported -->
                        <div class="reportable-section mb-5">
                            <h3 class="section-title-with-icon">
                                <i class="fas fa-exclamation-circle"></i> What Can Be Reported
                            </h3>
                            <div class="row mt-4">
                                <div class="col-md-6">
                                    <div class="reportable-item">
                                        <div class="reportable-icon">
                                            <i class="fas fa-money-bill-wave"></i>
                                        </div>
                                        <h5>Financial Misconduct</h5>
                                        <ul>
                                            <li>Fraud or theft</li>
                                            <li>Bribery or corruption</li>
                                            <li>Accounting irregularities</li>
                                            <li>Money laundering</li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="reportable-item">
                                        <div class="reportable-icon">
                                            <i class="fas fa-balance-scale"></i>
                                        </div>
                                        <h5>Legal & Regulatory</h5>
                                        <ul>
                                            <li>Breach of laws or regulations</li>
                                            <li>Non-compliance with policies</li>
                                            <li>Environmental violations</li>
                                            <li>Safety breaches</li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="reportable-item">
                                        <div class="reportable-icon">
                                            <i class="fas fa-users"></i>
                                        </div>
                                        <h5>Workplace Conduct</h5>
                                        <ul>
                                            <li>Harassment or discrimination</li>
                                            <li>Bullying or intimidation</li>
                                            <li>Conflict of interest</li>
                                            <li>Unethical behavior</li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="reportable-item">
                                        <div class="reportable-icon">
                                            <i class="fas fa-database"></i>
                                        </div>
                                        <h5>Data & Security</h5>
                                        <ul>
                                            <li>Data privacy breaches</li>
                                            <li>Security violations</li>
                                            <li>Intellectual property theft</li>
                                            <li>Confidentiality breaches</li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Whistleblower Protections -->
                        <div class="protections-section mb-5">
                            <h3 class="section-title-with-icon">
                                <i class="fas fa-shield-alt"></i> Whistleblower Protections
                            </h3>
                            <div class="protection-grid mt-4">
                                <div class="protection-card">
                                    <i class="fas fa-user-secret"></i>
                                    <h5>Confidentiality</h5>
                                    <p>Your identity will be protected to the fullest extent possible by law.</p>
                                </div>
                                <div class="protection-card">
                                    <i class="fas fa-ban"></i>
                                    <h5>No Retaliation</h5>
                                    <p>Retaliation against whistleblowers is strictly prohibited and grounds for dismissal.</p>
                                </div>
                                <div class="protection-card">
                                    <i class="fas fa-gavel"></i>
                                    <h5>Legal Protection</h5>
                                    <p>Protected under whistleblower laws including the Sarbanes-Oxley Act and Dodd-Frank Act.</p>
                                </div>
                                <div class="protection-card">
                                    <i class="fas fa-history"></i>
                                    <h5>Follow-up Rights</h5>
                                    <p>Right to receive updates on investigation status (if not anonymous).</p>
                                </div>
                            </div>
                        </div>

                        <!-- Reporting Process -->
                        <div class="process-section mb-5">
                            <h3 class="section-title-with-icon">
                                <i class="fas fa-list-ol"></i> How the Process Works
                            </h3>
                            <div class="process-timeline mt-4">
                                <div class="process-step">
                                    <div class="step-number">1</div>
                                    <div class="step-content">
                                        <h5>Submit Report</h5>
                                        <p>Complete the secure form below or use alternative reporting methods.</p>
                                    </div>
                                </div>
                                <div class="process-step">
                                    <div class="step-number">2</div>
                                    <div class="step-content">
                                        <h5>Acknowledgment</h5>
                                        <p>Receive confirmation and unique case ID within 24 hours.</p>
                                    </div>
                                </div>
                                <div class="process-step">
                                    <div class="step-number">3</div>
                                    <div class="step-content">
                                        <h5>Investigation</h5>
                                        <p>Independent Ethics Committee reviews and investigates the matter.</p>
                                    </div>
                                </div>
                                <div class="process-step">
                                    <div class="step-number">4</div>
                                    <div class="step-content">
                                        <h5>Resolution</h5>
                                        <p>Appropriate action taken; feedback provided to reporter if not anonymous.</p>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- IMPORTANT: REPORTING FORM -->
                        <div class="reporting-form-section">
                            <div class="form-header text-center mb-4">
                                <h3><i class="fas fa-paper-plane"></i> Submit a Report</h3>
                                <p class="text-muted">All fields marked with * are required. You may submit anonymously.</p>
                            </div>

                            <form id="whistleblowingForm" class="whistleblowing-form" method="POST" enctype="multipart/form-data">
                                <!-- CSRF Token -->
                                <input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($_SESSION['csrf_token']); ?>">
                                <!-- Honeypot -->
                                <input type="text" name="website" style="display:none;">
                                
                                <!-- Additional Info Field -->
                                <input type="hidden" name="additionalInfo" id="additionalInfo" value="Whistleblowing Report">
                                
                                <!-- Confidential Notice -->
                                <div class="confidential-notice alert alert-info mb-4">
                                    <div class="d-flex">
                                        <i class="fas fa-lock fa-2x mr-3"></i>
                                        <div>
                                            <h5 class="alert-heading">Secure & Confidential</h5>
                                            <p class="mb-0">This form uses end-to-end encryption. Your report will be handled with strict confidentiality by our independent Ethics Committee.</p>
                                        </div>
                                    </div>
                                </div>

                                <!-- Report Type -->
                                <div class="form-group mb-4">
                                    <label for="reportType" class="form-label">Type of Concern *</label>
                                    <select class="form-control" id="reportType" name="reportType" required>
                                        <option value="">-- Select a category --</option>
                                        <option value="financial" <?php echo isset($form_data['reportType']) && $form_data['reportType'] == 'financial' ? 'selected' : ''; ?>>Financial Fraud or Misconduct</option>
                                        <option value="legal" <?php echo isset($form_data['reportType']) && $form_data['reportType'] == 'legal' ? 'selected' : ''; ?>>Legal or Regulatory Violation</option>
                                        <option value="workplace" <?php echo isset($form_data['reportType']) && $form_data['reportType'] == 'workplace' ? 'selected' : ''; ?>>Workplace Harassment or Discrimination</option>
                                        <option value="safety" <?php echo isset($form_data['reportType']) && $form_data['reportType'] == 'safety' ? 'selected' : ''; ?>>Health/Safety Violation</option>
                                        <option value="ethical" <?php echo isset($form_data['reportType']) && $form_data['reportType'] == 'ethical' ? 'selected' : ''; ?>>Ethical Breach or Conflict of Interest</option>
                                        <option value="data" <?php echo isset($form_data['reportType']) && $form_data['reportType'] == 'data' ? 'selected' : ''; ?>>Data Privacy or Security Breach</option>
                                        <option value="other" <?php echo isset($form_data['reportType']) && $form_data['reportType'] == 'other' ? 'selected' : ''; ?>>Other Serious Misconduct</option>
                                    </select>
                                    <div class="error-message"></div>
                                </div>

                                <!-- Description -->
                                <div class="form-group mb-4">
                                    <label for="description" class="form-label">Detailed Description *</label>
                                    <textarea class="form-control" id="description" name="description" rows="6" 
                                              placeholder="Please provide specific details including: individuals involved, dates, locations, and a complete description of the incident. Include any evidence or supporting information."
                                              required><?php echo isset($form_data['description']) ? htmlspecialchars($form_data['description']) : ''; ?></textarea>
                                    <small class="form-text text-muted">Be as detailed and factual as possible. Avoid speculation.</small>
                                    <div class="error-message"></div>
                                </div>

                                <!-- Evidence Upload -->
                                <div class="form-group mb-4">
                                    <label for="evidence" class="form-label">Upload Supporting Documents (Optional)</label>
                                    <div class="custom-file">
                                        <input type="file" class="custom-file-input" id="evidence" name="evidence[]" multiple>
                                        <label class="custom-file-label" for="evidence">Choose files (PDF, JPG, PNG, DOC)</label>
                                    </div>
                                    <small class="form-text text-muted">Maximum 5 files, 10MB each. Allowed: PDF, Images, Word documents</small>
                                    <div id="filePreview" class="mt-3"></div>
                                </div>

                                <!-- Contact Information (Optional) -->
                                <div class="form-group">
    <label for="contactPreference">How would you prefer we contact you?</label>
    <select class="form-control" id="contactPreference" name="contactPreference">
        <option value="anonymous" <?php echo isset($form_data['contactPreference']) && $form_data['contactPreference'] == 'anonymous' ? 'selected' : ''; ?>>I wish to remain anonymous</option>
        <option value="email" <?php echo isset($form_data['contactPreference']) && $form_data['contactPreference'] == 'email' ? 'selected' : ''; ?>>Email only</option>
        <option value="secure" <?php echo isset($form_data['contactPreference']) && $form_data['contactPreference'] == 'secure' ? 'selected' : ''; ?>>Secure encrypted message</option>
        <!-- Removed "phone" option -->
    </select>
</div>
<br><br><br><br>
                                <!-- Confidentiality Agreement -->
                                <div class="confidentiality-agreement mb-4 p-3 bg-warning-light rounded">
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" id="confidentialityAgreement" name="confidentialityAgreement" required>
                                        <label class="form-check-label" for="confidentialityAgreement">
                                            <strong>I understand and agree:</strong> This report will be handled with strict confidentiality. I acknowledge that Reclaim Ethically prohibits retaliation against whistleblowers and provides protections in accordance with applicable laws. I am submitting this report in good faith.
                                        </label>
                                    </div>
                                    <div class="error-message"></div>
                                </div>

                                <!-- Submit Button -->
                                <div class="form-submit text-center">
                                    <button type="submit" class="btn btn-primary btn-lg px-5 py-3">
                                        <i class="fas fa-paper-plane mr-2"></i> Submit Secure Report
                                    </button>
                                    <p class="mt-3 text-muted">
                                        <i class="fas fa-shield-alt"></i> Encrypted transmission • Case ID generated upon submission
                                    </p>
                                </div>
                            </form>

                            <!-- Alternative Methods -->
                            <div class="alternative-methods mt-5 pt-4 border-top">
                                <h4 class="text-center mb-4">Alternative Reporting Methods</h4>
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="method-card text-center p-4">
                                            <div class="method-icon mb-3">
                                                <i class="fas fa-envelope fa-2x"></i>
                                            </div>
                                            <h5>Secure Email</h5>
                                            <p><strong>whistleblow@reclaimethically.com</strong></p>
                                            <small class="text-muted">PGP Key available upon request</small>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="method-card text-center p-4">
                                            <div class="method-icon mb-3">
                                                <i class="fas fa-phone fa-2x"></i>
                                            </div>
                                            <h5>24/7 Hotline</h5>
                                            <p><strong>+1-800-ETHIC-RE</strong><br>(+1-800-384-4273)</p>
                                            <small class="text-muted">Multilingual operators available</small>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="method-card text-center p-4">
                                            <div class="method-icon mb-3">
                                                <i class="fas fa-lock fa-2x"></i>
                                            </div>
                                            <h5>Encrypted Portal</h5>
                                            <p><strong>https://secure.reclaimethically.com/whistleblowing</strong></p>
                                            <small class="text-muted">Additional secure reporting option</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- Whistleblowing Content End -->

        <!-- Footer area start -->
        <?php include 'footer.php';?>
        <!-- Footer area end -->

        

        <div class="go-top go-top-3"><i class="fas fa-chevron-up"></i></div>

        <!-- Link of JS files -->
        <script src="assets/js/jquery.min.js"></script>
        <script src="assets/js/jquery-ui.min.js"></script>
        <script src="assets/js/bootstrap.bundle.min.js"></script>
        <script src="assets/js/meanmenu.js"></script>
        <script src="assets/js/owl.carousel.min.js"></script>
        <script src="assets/js/magnific-popup.min.js"></script>
        <script src="assets/js/TweenMax.js"></script>
        <script src="assets/js/nice-select.min.js"></script>
        <script src="assets/js/form-validator.min.js"></script>
        <script src="assets/js/contact-form-script.js"></script>
        <script src="assets/js/ajaxchimp.min.js"></script>
        <script src="assets/js/countdown.min.js"></script>
        <script src="assets/js/appear.min.js"></script>
        <script src="assets/js/barfiller.js"></script>
        <script src="assets/js/odometer.min.js"></script>
        <script src="assets/js/custom.js"></script>
        
        <!-- Whistleblowing Form JavaScript -->
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                console.log('✅ Whistleblowing form loaded');
                
                // Show SweetAlert messages if they exist
                const successMessage = document.getElementById('successMessage');
                const errorMessage = document.getElementById('errorMessage');
                
                if (successMessage) {
                    const message = successMessage.getAttribute('data-message');
                    Swal.fire({
                        title: 'Report Submitted Successfully!',
                        html: message,
                        icon: 'success',
                        confirmButtonText: 'OK',
                        confirmButtonColor: '#3f9f42',
                        allowOutsideClick: false
                    }).then(() => {
                        // Reset form on success
                        document.getElementById('whistleblowingForm').reset();
                        document.getElementById('filePreview').innerHTML = '';
                    });
                }
                
                if (errorMessage) {
                    const message = errorMessage.getAttribute('data-message');
                    const errorList = document.getElementById('errorList');
                    let html = message;
                    
                    if (errorList) {
                        html += errorList.innerHTML;
                    }
                    
                    Swal.fire({
                        title: 'Form Errors',
                        html: html,
                        icon: 'error',
                        confirmButtonText: 'Fix Errors',
                        confirmButtonColor: '#dc3545'
                    });
                }
                
                // File upload handling
                const fileInput = document.getElementById('evidence');
                const filePreview = document.getElementById('filePreview');
                const customFileLabel = document.querySelector('.custom-file-label');
                
                if (fileInput) {
                    fileInput.addEventListener('change', function(e) {
                        const files = e.target.files;
                        
                        if (filePreview) {
                            filePreview.innerHTML = '';
                        }
                        
                        if (!files || files.length === 0) {
                            if (customFileLabel) {
                                customFileLabel.textContent = 'Choose files (PDF, JPG, PNG, DOC)';
                            }
                            return;
                        }
                        
                        // Update label
                        if (customFileLabel) {
                            if (files.length === 1) {
                                customFileLabel.textContent = files[0].name;
                            } else {
                                customFileLabel.textContent = files.length + ' files selected';
                            }
                        }
                        
                        // Validate and display files
                        Array.from(files).forEach((file, index) => {
                            const maxSize = 10 * 1024 * 1024; // 10MB
                            if (file.size > maxSize) {
                                Swal.fire({
                                    title: 'File Too Large',
                                    text: `File "${file.name}" exceeds 10MB limit and will not be uploaded.`,
                                    icon: 'error',
                                    confirmButtonText: 'OK'
                                });
                                return;
                            }
                            
                            const allowedTypes = ['jpg', 'jpeg', 'png', 'pdf', 'txt', 'doc', 'docx'];
                            const fileExt = file.name.split('.').pop().toLowerCase();
                            if (!allowedTypes.includes(fileExt)) {
                                Swal.fire({
                                    title: 'Invalid File Type',
                                    text: `File type .${fileExt} not allowed for "${file.name}".`,
                                    icon: 'error',
                                    confirmButtonText: 'OK'
                                });
                                return;
                            }
                            
                            const fileItem = document.createElement('div');
                            fileItem.className = 'file-preview-item';
                            fileItem.innerHTML = `
                                <div class="file-info">
                                    <i class="fas fa-file me-2 text-primary"></i>
                                    <span class="file-name">${file.name}</span>
                                    <small class="text-muted ml-2">(${formatFileSize(file.size)})</small>
                                </div>
                                <button type="button" class="remove-file" data-index="${index}">
                                    <i class="fas fa-times"></i>
                                </button>
                            `;
                            if (filePreview) {
                                filePreview.appendChild(fileItem);
                            }
                        });
                        
                        // Add remove functionality
                        document.querySelectorAll('.remove-file').forEach(btn => {
                            btn.addEventListener('click', function() {
                                const index = parseInt(this.getAttribute('data-index'));
                                const dt = new DataTransfer();
                                const files = fileInput.files;
                                
                                for (let i = 0; i < files.length; i++) {
                                    if (i !== index) {
                                        dt.items.add(files[i]);
                                    }
                                }
                                
                                fileInput.files = dt.files;
                                
                                // Trigger change event to update preview
                                fileInput.dispatchEvent(new Event('change'));
                            });
                        });
                    });
                }
                
                // Form validation
                const form = document.getElementById('whistleblowingForm');
                
                form.addEventListener('submit', function(e) {
                    console.log('Form submit event triggered');
                    
                    // Clear previous errors
                    document.querySelectorAll('.error-message').forEach(el => {
                        el.innerHTML = '';
                        el.style.display = 'none';
                    });
                    
                    document.querySelectorAll('.is-invalid').forEach(el => {
                        el.classList.remove('is-invalid');
                    });
                    
                    let isValid = true;
                    
                    // Validate required fields
                    const requiredFields = [
                        { id: 'reportType', name: 'Report Type' },
                        { id: 'description', name: 'Description' },
                        { id: 'confidentialityAgreement', name: 'Confidentiality Agreement' }
                    ];
                    
                    requiredFields.forEach(field => {
                        const element = document.getElementById(field.id);
                        const errorElement = element.parentElement.querySelector('.error-message') || 
                                           element.closest('.form-group')?.querySelector('.error-message') ||
                                           element.closest('.confidentiality-agreement')?.querySelector('.error-message');
                        
                        if (field.id === 'confidentialityAgreement') {
                            if (!element.checked) {
                                isValid = false;
                                if (errorElement) {
                                    errorElement.innerHTML = `<i class="fas fa-exclamation-circle me-1"></i> You must agree to the confidentiality terms`;
                                    errorElement.style.display = 'block';
                                }
                                element.classList.add('is-invalid');
                            }
                        } else if (element.tagName === 'SELECT') {
                            if (!element.value) {
                                isValid = false;
                                if (errorElement) {
                                    errorElement.innerHTML = `<i class="fas fa-exclamation-circle me-1"></i> ${field.name} is required`;
                                    errorElement.style.display = 'block';
                                }
                                element.classList.add('is-invalid');
                            }
                        } else if (element.tagName === 'TEXTAREA') {
                            const value = element.value.trim();
                            if (!value) {
                                isValid = false;
                                if (errorElement) {
                                    errorElement.innerHTML = `<i class="fas fa-exclamation-circle me-1"></i> ${field.name} is required`;
                                    errorElement.style.display = 'block';
                                }
                                element.classList.add('is-invalid');
                            } else if (value.length < 30) {
                                isValid = false;
                                if (errorElement) {
                                    errorElement.innerHTML = `<i class="fas fa-exclamation-circle me-1"></i> Please provide more detailed description (minimum 30 characters)`;
                                    errorElement.style.display = 'block';
                                }
                                element.classList.add('is-invalid');
                            }
                        }
                    });
                    
                    // Validate file sizes and types before submission
                    const files = fileInput?.files;
                    if (files && files.length > 0) {
                        const maxFiles = 5;
                        if (files.length > maxFiles) {
                            Swal.fire({
                                title: 'Too Many Files',
                                text: 'Maximum 5 files allowed. Please remove some files before submitting.',
                                icon: 'warning',
                                confirmButtonText: 'OK'
                            });
                            isValid = false;
                        }
                        
                        // Check each file size
                        Array.from(files).forEach(file => {
                            const maxSize = 10 * 1024 * 1024;
                            if (file.size > maxSize) {
                                Swal.fire({
                                    title: 'File Too Large',
                                    text: `File "${file.name}" exceeds 10MB limit. Please remove it before submitting.`,
                                    icon: 'error',
                                    confirmButtonText: 'OK'
                                });
                                isValid = false;
                            }
                        });
                    }
                    
                    if (!isValid) {
                        e.preventDefault();
                        
                        // Scroll to first error
                        const firstError = document.querySelector('.is-invalid');
                        if (firstError) {
                            firstError.scrollIntoView({ 
                                behavior: 'smooth', 
                                block: 'center' 
                            });
                        }
                    } else {
                        // Show loading message
                        Swal.fire({
                            title: 'Submitting Report...',
                            text: 'Please wait while we securely process your whistleblowing report.',
                            icon: 'info',
                            showConfirmButton: false,
                            allowOutsideClick: false,
                            didOpen: () => {
                                Swal.showLoading();
                            }
                        });
                    }
                });
                
                // Real-time validation
                form.addEventListener('input', function(e) {
                    const target = e.target;
                    const errorElement = target.parentElement.querySelector('.error-message') || 
                                       target.closest('.form-group')?.querySelector('.error-message');
                    
                    if (errorElement) {
                        errorElement.innerHTML = '';
                        errorElement.style.display = 'none';
                        target.classList.remove('is-invalid');
                    }
                    
                    // Validate description length
                    if (target.id === 'description') {
                        const value = target.value.trim();
                        if (value && value.length < 30) {
                            if (errorElement) {
                                errorElement.innerHTML = `<i class="fas fa-exclamation-circle me-1"></i> Minimum 30 characters required (${value.length}/30)`;
                                errorElement.style.display = 'block';
                                target.classList.add('is-invalid');
                            }
                        }
                    }
                });
                
                // Auto-save description to hidden additionalInfo field
                const descriptionField = document.getElementById('description');
                const additionalInfoField = document.getElementById('additionalInfo');
                
                if (descriptionField && additionalInfoField) {
                    descriptionField.addEventListener('input', function() {
                        additionalInfoField.value = this.value.substring(0, 200) + (this.value.length > 200 ? '...' : '');
                    });
                }
                
                // Helper function
                function formatFileSize(bytes) {
                    if (bytes === 0) return '0 Bytes';
                    const k = 1024;
                    const sizes = ['Bytes', 'KB', 'MB', 'GB'];
                    const i = Math.floor(Math.log(bytes) / Math.log(k));
                    return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
                }
                
                // Initialize Bootstrap file input
                if (typeof $ !== 'undefined') {
                    $(document).ready(function() {
                        // Initialize custom file input
                        $('.custom-file-input').on('change', function() {
                            let fileName = $(this).val().split('\\').pop();
                            $(this).next('.custom-file-label').addClass("selected").html(fileName);
                        });
                    });
                }
            });
        </script>
        
        <!-- Include existing styles from your page -->
        <style>
            /* ===== WHISTLEBLOWING PAGE SPECIFIC STYLES ===== */
            .whistleblowing-content {
                background: #f8f9fa;
            }
            
            .policy-intro .default-section-title h2 {
                color: #000000;
                font-size: 2.5rem;
                margin-bottom: 1rem;
            }
            
            .policy-badges {
                display: flex;
                justify-content: center;
                flex-wrap: wrap;
                gap: 15px;
                margin-top: 20px;
            }
            
            .badge-ethical {
                background: rgba(63, 159, 66, 0.1);
                color: #3f9f42;
                padding: 8px 20px;
                border-radius: 30px;
                font-weight: 600;
                display: inline-flex;
                align-items: center;
                gap: 8px;
                border: 1px solid rgba(63, 159, 66, 0.3);
            }
            
            .badge-ethical i {
                font-size: 14px;
            }
            
            /* Reportable Items */
            .reportable-section {
                background: white;
                padding: 30px;
                border-radius: 12px;
                box-shadow: 0 5px 20px rgba(0,0,0,0.05);
            }
            
            .section-title-with-icon {
                color: #000000;
                font-weight: 700;
                display: flex;
                align-items: center;
                gap: 15px;
                margin-bottom: 25px;
                padding-bottom: 15px;
                border-bottom: 2px solid #eef2ff;
            }
            
            .section-title-with-icon i {
                color: #3f9f42;
                font-size: 24px;
            }
            
            .reportable-item {
                background: #f9f9f9;
                padding: 25px;
                border-radius: 8px;
                border-left: 4px solid #3f9f42;
                transition: all 0.3s ease;
                height: 100%;
                margin-bottom: 20px;
            }
            
            .reportable-item:hover {
                transform: translateY(-5px);
                box-shadow: 0 10px 20px rgba(0,0,0,0.1);
            }
            
            .reportable-icon {
                width: 60px;
                height: 60px;
                background: rgba(63, 159, 66, 0.1);
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                margin-bottom: 20px;
                color: #3f9f42;
                font-size: 24px;
            }
            
            .reportable-item h5 {
                color: #000000;
                font-weight: 600;
                margin-bottom: 15px;
                font-size: 18px;
            }
            
            .reportable-item ul {
                list-style: none;
                padding-left: 0;
                margin: 0;
            }
            
            .reportable-item ul li {
                padding: 6px 0;
                padding-left: 25px;
                position: relative;
                color: #333;
                font-size: 14px;
                line-height: 1.4;
            }
            
            .reportable-item ul li:before {
                content: "•";
                color: #3f9f42;
                font-weight: bold;
                font-size: 20px;
                position: absolute;
                left: 0;
                top: 4px;
            }
            
            /* Protections */
            .protections-section {
                background: white;
                padding: 30px;
                border-radius: 12px;
                box-shadow: 0 5px 20px rgba(0,0,0,0.05);
            }
            
            .protection-grid {
                display: grid;
                grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
                gap: 20px;
            }
            
            .protection-card {
                background: #f9f9f9;
                padding: 25px;
                border-radius: 8px;
                text-align: center;
                border: 1px solid #e0e0e0;
                transition: all 0.3s ease;
            }
            
            .protection-card:hover {
                border-color: #3f9f42;
                transform: translateY(-5px);
            }
            
            .protection-card i {
                font-size: 36px;
                color: #3f9f42;
                margin-bottom: 15px;
            }
            
            .protection-card h5 {
                color: #000000;
                font-weight: 600;
                margin-bottom: 10px;
                font-size: 16px;
            }
            
            .protection-card p {
                color: #666;
                font-size: 14px;
                line-height: 1.5;
            }
            
            /* Process Timeline */
            .process-section {
                background: white;
                padding: 30px;
                border-radius: 12px;
                box-shadow: 0 5px 20px rgba(0,0,0,0.05);
            }
            
            .process-timeline {
                position: relative;
                padding-left: 30px;
            }
            
            .process-timeline:before {
                content: '';
                position: absolute;
                left: 15px;
                top: 0;
                bottom: 0;
                width: 2px;
                background: #3f9f42;
            }
            
            .process-step {
                position: relative;
                margin-bottom: 30px;
                display: flex;
                align-items: flex-start;
            }
            
            .step-number {
                width: 32px;
                height: 32px;
                background: #3f9f42;
                color: white;
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                font-weight: bold;
                font-size: 14px;
                position: absolute;
                left: -40px;
                top: 0;
                z-index: 1;
            }
            
            .step-content {
                margin-left: 30px;
            }
            
            .step-content h5 {
                color: #000000;
                font-weight: 600;
                margin-bottom: 8px;
                font-size: 18px;
            }
            
            .step-content p {
                color: #666;
                font-size: 14px;
                line-height: 1.6;
            }
            
            /* Reporting Form */
            .reporting-form-section {
                background: linear-gradient(135deg, #f0f9f0 0%, #e8f5e8 100%);
                padding: 40px;
                border-radius: 12px;
                box-shadow: 0 10px 30px rgba(63, 159, 66, 0.15);
                margin-top: 40px;
                border: 1px solid rgba(63, 159, 66, 0.2);
                position: relative;
                overflow: hidden;
            }
            
            .form-header {
                background: rgba(255, 255, 255, 0.9);
                padding: 25px;
                border-radius: 10px;
                margin-bottom: 30px;
                border: 1px solid rgba(63, 159, 66, 0.2);
                box-shadow: 0 4px 12px rgba(63, 159, 66, 0.1);
            }
            
            .form-header h3 {
                color: #2d8a2f;
                font-weight: 700;
                margin-bottom: 10px;
                display: flex;
                align-items: center;
                justify-content: center;
                gap: 10px;
                font-size: 28px;
            }
            
            .form-header p {
                color: #555;
                font-size: 16px;
            }
            
            .confidential-notice {
                background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(240, 255, 240, 0.95) 100%);
                border-left: 5px solid #3f9f42;
                border-radius: 10px;
                padding: 25px;
                margin-bottom: 30px;
                box-shadow: 0 5px 15px rgba(63, 159, 66, 0.1);
                border: 1px solid rgba(63, 159, 66, 0.2);
            }
            
            .confidential-notice i {
                color: #3f9f42;
                font-size: 28px;
            }
            
            .confidential-notice h5 {
                color: #2d8a2f;
                font-weight: 700;
                margin-bottom: 10px;
            }
            
            .form-control, .custom-file-input {
                border: 2px solid #c8e6c9;
                border-radius: 8px;
                padding: 12px 15px;
                transition: all 0.3s ease;
                background: rgba(255, 255, 255, 0.9);
            }
            
            .form-control:focus, .custom-file-input:focus {
                border-color: #3f9f42;
                box-shadow: 0 0 0 3px rgba(63, 159, 66, 0.25);
                background: white;
            }
            
            .custom-file-label {
                padding: 12px 15px;
                border: 2px solid #c8e6c9;
                border-radius: 8px;
                background: rgba(255, 255, 255, 0.9);
            }
            
            .contact-section {
                background: rgba(255, 255, 255, 0.9) !important;
                border: 2px dashed #a5d6a7 !important;
                padding: 25px !important;
                border-radius: 10px !important;
            }
            
            .contact-section h5 {
                color: #2d8a2f;
                display: flex;
                align-items: center;
                gap: 10px;
            }
            
            .confidentiality-agreement {
                background: rgba(255, 248, 225, 0.9) !important;
                border: 2px solid #ffd54f !important;
                padding: 25px !important;
                border-radius: 10px !important;
            }
            
            .form-submit .btn-primary {
                background: linear-gradient(135deg, #3f9f42 0%, #2d8a2f 100%);
                border: none;
                font-weight: 700;
                transition: all 0.3s ease;
                padding: 18px 50px;
                font-size: 18px;
                border-radius: 50px;
                box-shadow: 0 8px 20px rgba(63, 159, 66, 0.4);
                position: relative;
                overflow: hidden;
                z-index: 1;
            }
            
            .form-submit .btn-primary:hover {
                transform: translateY(-5px);
                box-shadow: 0 12px 25px rgba(63, 159, 66, 0.5);
            }
            
            .form-submit .btn-primary i {
                margin-right: 10px;
                font-size: 20px;
            }
            
            /* Alternative Methods */
            .alternative-methods {
                margin-top: 40px;
                padding-top: 30px;
                border-top: 2px solid rgba(63, 159, 66, 0.2) !important;
            }
            
            .alternative-methods h4 {
                color: #2d8a2f;
                font-weight: 700;
                margin-bottom: 30px;
                font-size: 24px;
            }
            
            .method-card {
                background: rgba(255, 255, 255, 0.9);
                border-radius: 10px;
                border: 2px solid rgba(63, 159, 66, 0.2);
                transition: all 0.3s ease;
                padding: 25px 15px;
                position: relative;
                overflow: hidden;
                display: flex;
                flex-direction: column;
                align-items: center;
                text-align: center;
                height: 100%;
            }
            
            .method-card:before {
                content: '';
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                height: 4px;
                background: linear-gradient(90deg, #3f9f42 0%, #2d8a2f 100%);
            }
            
            .method-card:hover {
                border-color: #3f9f42;
                transform: translateY(-5px);
                box-shadow: 0 10px 25px rgba(63, 159, 66, 0.15);
            }
            
            .method-icon {
                width: 70px;
                height: 70px;
                background: rgba(63, 159, 66, 0.1);
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                margin: 0 auto 20px;
                color: #3f9f42;
                font-size: 28px;
                border: 2px solid rgba(63, 159, 66, 0.2);
            }
            
            .method-card h5 {
                color: #2d8a2f;
                font-weight: 700;
                margin-bottom: 12px;
                font-size: 18px;
                min-height: 45px;
                display: flex;
                align-items: center;
                justify-content: center;
            }
            
            .method-card p {
                color: #333;
                margin-bottom: 8px;
                font-weight: 600;
                font-size: 15px;
            }
            
            .method-card small {
                color: #666;
                font-size: 12px;
            }
            
            /* Responsive Design */
            @media (max-width: 768px) {
                .policy-badges {
                    gap: 10px;
                }
                
                .badge-ethical {
                    padding: 6px 15px;
                    font-size: 14px;
                }
                
                .protection-grid {
                    grid-template-columns: 1fr;
                }
                
                .process-timeline:before {
                    left: 16px;
                }
                
                .step-number {
                    left: -38px;
                }
                
                .reporting-form-section {
                    padding: 25px 20px;
                }
                
                .method-card {
                    margin-bottom: 20px;
                }
            }
            
            @media (max-width: 576px) {
                .section-title-with-icon {
                    flex-direction: column;
                    align-items: flex-start;
                    gap: 10px;
                }
                
                .process-timeline {
                    padding-left: 25px;
                }
                
                .step-number {
                    width: 28px;
                    height: 28px;
                    font-size: 12px;
                    left: -32px;
                }
                
                .step-content {
                    margin-left: 25px;
                }
            }
        </style>
    </body>
</html>