<?php
/**
 * DarkMatter Enterprise Inquiry Form
 * Saves enterprise inquiries to MariaDB
 */

// Database configuration
$db_host = 'raven.aserv.co.za';
$db_port = 3306;
$db_name = 'vcbaioh8w6o6_vcb';
$db_user = 'vcbaioh8w6o6_svc';
$db_pass = '@nB6%#Z6!dvKMB';

$message = '';
$messageType = '';

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name'] ?? '');
    $email = trim($_POST['email'] ?? '');
    $company = trim($_POST['company'] ?? '');
    $phone = trim($_POST['phone'] ?? '');
    $company_size = trim($_POST['company_size'] ?? '');
    $requirements = trim($_POST['requirements'] ?? '');
    $budget = trim($_POST['budget'] ?? '');
    $timeline = trim($_POST['timeline'] ?? '');
    $comments = trim($_POST['comments'] ?? '');
    
    // Validation
    if (empty($name) || empty($email) || empty($company)) {
        $message = 'Please fill in all required fields.';
        $messageType = 'error';
    } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $message = 'Please enter a valid email address.';
        $messageType = 'error';
    } else {
        try {
            // Connect to database
            $pdo = new PDO(
                "mysql:host=$db_host;port=$db_port;dbname=$db_name;charset=utf8mb4",
                $db_user,
                $db_pass,
                [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
            );
            
            // Create table if not exists
            $pdo->exec("CREATE TABLE IF NOT EXISTS darkmatter_enterprise (
                id INT AUTO_INCREMENT PRIMARY KEY,
                name VARCHAR(255) NOT NULL,
                email VARCHAR(255) NOT NULL,
                company VARCHAR(255) NOT NULL,
                phone VARCHAR(50),
                company_size VARCHAR(50),
                requirements TEXT,
                budget VARCHAR(50),
                timeline VARCHAR(50),
                comments TEXT,
                ip_address VARCHAR(45),
                user_agent TEXT,
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
            )");
            
            // Insert inquiry
            $stmt = $pdo->prepare("INSERT INTO darkmatter_enterprise (name, email, company, phone, company_size, requirements, budget, timeline, comments, ip_address, user_agent) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
            $stmt->execute([
                $name,
                $email,
                $company,
                $phone,
                $company_size,
                $requirements,
                $budget,
                $timeline,
                $comments,
                $_SERVER['REMOTE_ADDR'] ?? '',
                $_SERVER['HTTP_USER_AGENT'] ?? ''
            ]);
            
            // Send email notification
            $configStmt = $pdo->prepare("SELECT key_name, key_value FROM config_keys WHERE is_active = 1");
            $configStmt->execute();
            $config = [];
            while ($row = $configStmt->fetch(PDO::FETCH_ASSOC)) {
                $config[$row['key_name']] = $row['key_value'];
            }
            
            if (!empty($config['emailjs_service_id'])) {
                $emailData = [
                    'service_id' => $config['emailjs_service_id'],
                    'template_id' => $config['emailjs_template_id'],
                    'user_id' => $config['emailjs_public_key'],
                    'accessToken' => $config['emailjs_private_key'],
                    'template_params' => [
                        'name' => $name,
                        'email' => $config['admin_email'],
                        'from_name' => $name,
                        'from_email' => $email,
                        'company' => $company,
                        'phone' => $phone ?: 'Not provided',
                        'subject' => 'DarkMatter Enterprise Inquiry',
                        'message' => "Company Size: $company_size\nBudget: $budget\nTimeline: $timeline\n\nRequirements: $requirements\n\nComments: $comments",
                        'form_type' => 'DarkMatter Enterprise',
                        'reply_to' => $email
                    ]
                ];
                
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, 'https://api.emailjs.com/api/v1.0/email/send');
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($emailData));
                curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                curl_exec($ch);
                curl_close($ch);
            }
            
            $message = 'Thank you for your enterprise inquiry! Our team will contact you within 24-48 hours.';
            $messageType = 'success';
            
            // Clear form
            $name = $email = $company = $phone = $company_size = $requirements = $budget = $timeline = $comments = '';
            
        } catch (PDOException $e) {
            $message = 'Sorry, there was an error processing your request. Please try again later.';
            $messageType = 'error';
            error_log('DB Error: ' . $e->getMessage());
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Enterprise Inquiry | #ProjectDarkMatter</title>
    <meta name="description" content="Enterprise solutions for DarkMatter - Custom RAG intelligence, dedicated legal workspaces, and private data sovereignty.">
    <link rel="icon" type="image/png" href="/logoWtext-transparent-BlackBack.png">
    
    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&display=swap" rel="stylesheet">
    
    <!-- Tailwind -->
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: {
                        sans: ['Quicksand', 'sans-serif'],
                    },
                    colors: {
                        navy: {
                            800: '#262626',
                            900: '#171717',
                        }
                    }
                }
            }
        }
    </script>
    <style>
        body { font-family: 'Quicksand', sans-serif; font-weight: 400; }
        
        .form-input {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.15);
            border-radius: 12px;
            padding: 14px 18px;
            color: white;
            font-size: 16px;
            width: 100%;
            transition: all 0.3s ease;
        }
        
        .form-input:focus {
            outline: none;
            border-color: rgba(255, 255, 255, 0.4);
            background: rgba(255, 255, 255, 0.08);
        }
        
        .form-input::placeholder {
            color: rgba(255, 255, 255, 0.4);
        }
        
        .form-select {
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='rgba(255,255,255,0.5)'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 12px center;
            background-size: 20px;
            -webkit-appearance: none;
            appearance: none;
            padding-right: 40px;
        }
        
        .form-select option {
            background: #171717;
            color: white;
        }
        
        .hero-pattern {
            background-color: #171717;
            background-image: radial-gradient(#262626 1px, transparent 1px);
            background-size: 30px 30px;
        }
    </style>
</head>
<body class="bg-navy-900 text-white min-h-screen hero-pattern">
    
    <!-- Header -->
    <header class="p-6 sm:p-8 border-b border-neutral-800">
        <nav class="max-w-4xl mx-auto flex items-center justify-between">
            <a href="/project-darkmatter.html" class="flex items-center gap-3">
                <img src="/darkmatter-logo.svg" alt="DarkMatter" class="h-10 sm:h-12 w-auto" onerror="this.style.display='none'">
                <span class="text-lg font-bold text-white">#ProjectDarkMatter</span>
            </a>
            <a href="/project-darkmatter.html" class="flex items-center gap-2 px-4 py-2 text-neutral-400 hover:text-white border border-neutral-700 hover:border-neutral-500 rounded-full transition-all text-sm font-medium">
                <span class="material-symbols-outlined text-lg">arrow_back</span>
                Back
            </a>
        </nav>
    </header>
    
    <!-- Main Content -->
    <main class="py-12 px-6">
        <div class="max-w-2xl mx-auto">
            
            <!-- Header -->
            <div class="text-center mb-12">
                <div class="inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-white/10 border border-white/20 mb-6">
                    <span class="material-symbols-outlined text-3xl text-white">domain</span>
                </div>
                
                <h1 class="text-3xl sm:text-4xl font-bold mb-4">
                    Enterprise Inquiry
                </h1>
                
                <p class="text-neutral-400 max-w-md mx-auto">
                    Custom intelligence deployment for law firms and enterprises. Let's discuss your requirements.
                </p>
            </div>
            
            <!-- Enterprise Features Banner -->
            <div class="mb-8 p-6 rounded-xl bg-white/5 border border-white/10">
                <h3 class="font-bold text-white mb-4 flex items-center gap-2">
                    <span class="material-symbols-outlined text-white">stars</span>
                    Enterprise Benefits
                </h3>
                <div class="grid grid-cols-2 gap-3 text-sm">
                    <div class="flex items-center gap-2 text-neutral-300">
                        <span class="material-symbols-outlined text-white text-base">check</span>
                        Exclusive RAG content
                    </div>
                    <div class="flex items-center gap-2 text-neutral-300">
                        <span class="material-symbols-outlined text-white text-base">check</span>
                        Custom RAG intelligence
                    </div>
                    <div class="flex items-center gap-2 text-neutral-300">
                        <span class="material-symbols-outlined text-white text-base">check</span>
                        Private data sovereignty
                    </div>
                    <div class="flex items-center gap-2 text-neutral-300">
                        <span class="material-symbols-outlined text-white text-base">check</span>
                        Dedicated workspaces
                    </div>
                    <div class="flex items-center gap-2 text-neutral-300">
                        <span class="material-symbols-outlined text-white text-base">check</span>
                        Enterprise SLA
                    </div>
                    <div class="flex items-center gap-2 text-neutral-300">
                        <span class="material-symbols-outlined text-white text-base">check</span>
                        Priority support
                    </div>
                </div>
            </div>
            
            <?php if ($message): ?>
            <!-- Message -->
            <div class="mb-8 p-4 rounded-xl border <?php echo $messageType === 'success' ? 'bg-emerald-500/10 border-emerald-500/30 text-emerald-400' : 'bg-red-500/10 border-red-500/30 text-red-400'; ?>">
                <div class="flex items-center gap-3">
                    <span class="material-symbols-outlined"><?php echo $messageType === 'success' ? 'check_circle' : 'error'; ?></span>
                    <p class="font-medium"><?php echo htmlspecialchars($message); ?></p>
                </div>
            </div>
            <?php endif; ?>
            
            <!-- Form -->
            <form method="POST" class="bg-white/5 rounded-2xl p-8 border border-white/10">
                <div class="space-y-6">
                    
                    <!-- Name & Email -->
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-neutral-300 mb-2">Full Name *</label>
                            <input type="text" name="name" required 
                                   value="<?php echo htmlspecialchars($name ?? ''); ?>"
                                   placeholder="John Smith"
                                   class="form-input">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-neutral-300 mb-2">Work Email *</label>
                            <input type="email" name="email" required 
                                   value="<?php echo htmlspecialchars($email ?? ''); ?>"
                                   placeholder="john@lawfirm.co.za"
                                   class="form-input">
                        </div>
                    </div>
                    
                    <!-- Company & Phone -->
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-neutral-300 mb-2">Company / Firm *</label>
                            <input type="text" name="company" required
                                   value="<?php echo htmlspecialchars($company ?? ''); ?>"
                                   placeholder="Smith & Associates Inc"
                                   class="form-input">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-neutral-300 mb-2">Phone Number</label>
                            <input type="tel" name="phone" 
                                   value="<?php echo htmlspecialchars($phone ?? ''); ?>"
                                   placeholder="+27 82 123 4567"
                                   class="form-input">
                        </div>
                    </div>
                    
                    <!-- Company Size & Timeline -->
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-neutral-300 mb-2">Company Size</label>
                            <select name="company_size" class="form-input form-select">
                                <option value="">Select...</option>
                                <option value="1-10" <?php echo ($company_size ?? '') === '1-10' ? 'selected' : ''; ?>>1-10 employees</option>
                                <option value="11-50" <?php echo ($company_size ?? '') === '11-50' ? 'selected' : ''; ?>>11-50 employees</option>
                                <option value="51-200" <?php echo ($company_size ?? '') === '51-200' ? 'selected' : ''; ?>>51-200 employees</option>
                                <option value="201-500" <?php echo ($company_size ?? '') === '201-500' ? 'selected' : ''; ?>>201-500 employees</option>
                                <option value="500+" <?php echo ($company_size ?? '') === '500+' ? 'selected' : ''; ?>>500+ employees</option>
                            </select>
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-neutral-300 mb-2">Implementation Timeline</label>
                            <select name="timeline" class="form-input form-select">
                                <option value="">When do you need this?</option>
                                <option value="immediate" <?php echo ($timeline ?? '') === 'immediate' ? 'selected' : ''; ?>>Immediately</option>
                                <option value="1-3months" <?php echo ($timeline ?? '') === '1-3months' ? 'selected' : ''; ?>>1-3 months</option>
                                <option value="3-6months" <?php echo ($timeline ?? '') === '3-6months' ? 'selected' : ''; ?>>3-6 months</option>
                                <option value="6months+" <?php echo ($timeline ?? '') === '6months+' ? 'selected' : ''; ?>>6+ months</option>
                                <option value="exploring" <?php echo ($timeline ?? '') === 'exploring' ? 'selected' : ''; ?>>Just exploring</option>
                            </select>
                        </div>
                    </div>
                    
                    <!-- Budget -->
                    <div>
                        <label class="block text-sm font-medium text-neutral-300 mb-2">Budget Range (Monthly)</label>
                        <select name="budget" class="form-input form-select">
                            <option value="">Select budget range...</option>
                            <option value="under-10k" <?php echo ($budget ?? '') === 'under-10k' ? 'selected' : ''; ?>>Under R10,000</option>
                            <option value="10k-25k" <?php echo ($budget ?? '') === '10k-25k' ? 'selected' : ''; ?>>R10,000 - R25,000</option>
                            <option value="25k-50k" <?php echo ($budget ?? '') === '25k-50k' ? 'selected' : ''; ?>>R25,000 - R50,000</option>
                            <option value="50k-100k" <?php echo ($budget ?? '') === '50k-100k' ? 'selected' : ''; ?>>R50,000 - R100,000</option>
                            <option value="100k+" <?php echo ($budget ?? '') === '100k+' ? 'selected' : ''; ?>>R100,000+</option>
                            <option value="discuss" <?php echo ($budget ?? '') === 'discuss' ? 'selected' : ''; ?>>Let's discuss</option>
                        </select>
                    </div>
                    
                    <!-- Requirements -->
                    <div>
                        <label class="block text-sm font-medium text-neutral-300 mb-2">Key Requirements</label>
                        <textarea name="requirements" rows="3" 
                                  placeholder="What specific features or integrations do you need?"
                                  class="form-input resize-none"><?php echo htmlspecialchars($requirements ?? ''); ?></textarea>
                    </div>
                    
                    <!-- Additional Comments -->
                    <div>
                        <label class="block text-sm font-medium text-neutral-300 mb-2">Additional Information</label>
                        <textarea name="comments" rows="3" 
                                  placeholder="Any other details that would help us understand your needs..."
                                  class="form-input resize-none"><?php echo htmlspecialchars($comments ?? ''); ?></textarea>
                    </div>
                    
                    <!-- Submit -->
                    <div class="pt-4">
                        <button type="submit" 
                                class="w-full flex items-center justify-center gap-3 px-8 py-4 bg-white text-navy-900 font-bold uppercase tracking-wider rounded-xl hover:bg-neutral-100 transition-all duration-300">
                            <span class="material-symbols-outlined">send</span>
                            Submit Inquiry
                        </button>
                    </div>
                </div>
            </form>
            
            <!-- Contact Alternative -->
            <div class="mt-8 text-center">
                <p class="text-sm text-neutral-500 mb-2">Prefer to talk directly?</p>
                <a href="mailto:enterprise@vcb-ai.online" class="inline-flex items-center gap-2 text-white font-medium hover:underline">
                    <span class="material-symbols-outlined text-lg">mail</span>
                    enterprise@vcb-ai.online
                </a>
            </div>
        </div>
    </main>
    
    <!-- Footer -->
    <footer class="p-6 sm:p-8 border-t border-neutral-800">
        <div class="max-w-4xl mx-auto flex flex-col sm:flex-row items-center justify-between gap-4 text-sm text-neutral-500">
            <p>© 2026 #ProjectDarkMatter. All rights reserved.</p>
            <div class="flex items-center gap-6">
                <a href="/LEGAL.html" class="hover:text-white transition-colors">Legal</a>
                <a href="/project-darkmatter.html" class="hover:text-white transition-colors">Back to DarkMatter</a>
            </div>
        </div>
    </footer>
</body>
</html>
