<?php
/**
 * VCB-AI Enterprise Demo Request Form
 * Saves demo requests 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'] ?? '');
    $job_title = trim($_POST['job_title'] ?? '');
    $company_size = trim($_POST['company_size'] ?? '');
    $product_interest = trim($_POST['product_interest'] ?? '');
    $use_case = trim($_POST['use_case'] ?? '');
    $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 enterprise_demo_requests (
                id INT AUTO_INCREMENT PRIMARY KEY,
                name VARCHAR(255) NOT NULL,
                email VARCHAR(255) NOT NULL,
                company VARCHAR(255) NOT NULL,
                phone VARCHAR(50),
                job_title VARCHAR(100),
                company_size VARCHAR(50),
                product_interest VARCHAR(100),
                use_case TEXT,
                timeline VARCHAR(50),
                comments TEXT,
                ip_address VARCHAR(45),
                user_agent TEXT,
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
            )");
            
            // Insert request
            $stmt = $pdo->prepare("INSERT INTO enterprise_demo_requests (name, email, company, phone, job_title, company_size, product_interest, use_case, timeline, comments, ip_address, user_agent) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
            $stmt->execute([
                $name,
                $email,
                $company,
                $phone,
                $job_title,
                $company_size,
                $product_interest,
                $use_case,
                $timeline,
                $comments,
                $_SERVER['REMOTE_ADDR'] ?? '',
                $_SERVER['HTTP_USER_AGENT'] ?? ''
            ]);

            // --- PHP mail() notification (primary) ---
            $notifyTo = 'hello@vcb-ai.online';
            $mailSubject = '[VCB Demo] ' . ($product_interest ?: 'Enterprise') . ' — from ' . $name . ' at ' . $company;
            $mailBody  = "Enterprise Demo Request\r\n";
            $mailBody .= "=======================\r\n";
            $mailBody .= "Name:          $name\r\n";
            $mailBody .= "Email:         $email\r\n";
            $mailBody .= "Company:       $company\r\n";
            $mailBody .= "Phone:         " . ($phone ?: 'Not provided') . "\r\n";
            $mailBody .= "Job Title:     " . ($job_title ?: 'Not provided') . "\r\n";
            $mailBody .= "Company Size:  " . ($company_size ?: 'Not provided') . "\r\n";
            $mailBody .= "Product:       " . ($product_interest ?: 'Not provided') . "\r\n";
            $mailBody .= "Timeline:      " . ($timeline ?: 'Not provided') . "\r\n\r\n";
            $mailBody .= "Use Case:\r\n$use_case\r\n\r\n";
            $mailBody .= "Comments:\r\n$comments\r\n\r\n";
            $mailBody .= "IP: " . ($_SERVER['REMOTE_ADDR'] ?? 'unknown') . "\r\n";
            $mailHeaders  = "From: noreply@vcb-ai.online\r\n";
            $mailHeaders .= "Reply-To: $email\r\n";
            $mailHeaders .= "X-Mailer: PHP/" . phpversion();
            @mail($notifyTo, $mailSubject, $mailBody, $mailHeaders);
            $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' => 'Enterprise Demo Request: ' . ($product_interest ?: 'General'),
                        'message' => "Job Title: $job_title\nCompany Size: $company_size\nProduct Interest: $product_interest\nTimeline: $timeline\n\nUse Case: $use_case\n\nComments: $comments",
                        'form_type' => 'Enterprise Demo Request',
                        '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! Your demo request has been submitted. Our team will contact you within 24 hours to schedule.';
            $messageType = 'success';
            
            // Clear form
            $name = $email = $company = $phone = $job_title = $company_size = $product_interest = $use_case = $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>Request Enterprise Demo | VCB-AI</title>
    <meta name="description" content="Schedule a personalized demo of VCB-AI's enterprise solutions including LIANELA, Sales Agent, and Agentic AI.">
    <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&family=Inter:wght@300;400;500&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp: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: {
                        'display': ['Quicksand', 'sans-serif'],
                        'body': ['Inter', 'sans-serif'],
                    }
                }
            }
        }
    </script>
    <style>
        body { font-family: 'Inter', sans-serif; }
        h1, h2, h3, h4, h5, h6 { font-family: 'Quicksand', sans-serif; font-weight: 600; }
        
        .form-input {
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 12px;
            padding: 14px 18px;
            color: #111;
            font-size: 16px;
            width: 100%;
            transition: all 0.3s ease;
        }
        
        .form-input:focus {
            outline: none;
            border-color: #000;
            box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
        }
        
        .form-input::placeholder {
            color: #9ca3af;
        }
        
        .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='%236b7280'%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;
        }
    </style>
</head>
<body class="bg-gray-50 text-gray-900 min-h-screen">
    
    <!-- Header -->
    <header class="bg-gradient-to-b from-black via-black/95 to-black/90 backdrop-blur-md border-b border-white/10">
        <nav class="max-w-6xl mx-auto px-6 flex items-center justify-between h-24 sm:h-32">
            <a href="/" class="flex items-center gap-3 group">
                <img src="/logoWtext-transparent-BlackBack.png" alt="VCB Logo" class="h-40 sm:h-64 w-auto">
            </a>
            <a href="/" class="flex items-center gap-2 px-5 py-2.5 text-white hover:bg-white/10 border border-white/30 hover:border-white/50 rounded-full transition-all text-base font-bold uppercase tracking-widest">
                <span class="material-symbols-sharp 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-black mb-6">
                    <span class="material-symbols-sharp text-3xl text-white">play_circle</span>
                </div>
                
                <h1 class="text-3xl sm:text-4xl font-bold mb-4">
                    Request Enterprise Demo
                </h1>
                
                <p class="text-gray-500 max-w-md mx-auto">
                    See VCB-AI's enterprise solutions in action. Get a personalized walkthrough tailored to your needs.
                </p>
            </div>
            
            <!-- What You'll See -->
            <div class="mb-8 p-6 rounded-xl bg-black text-white">
                <h3 class="font-bold mb-4 flex items-center gap-2">
                    <span class="material-symbols-sharp">checklist</span>
                    What You'll Experience
                </h3>
                <div class="grid grid-cols-2 gap-3 text-sm">
                    <div class="flex items-center gap-2 text-gray-300">
                        <span class="material-symbols-sharp text-white text-base">check</span>
                        Live product demonstration
                    </div>
                    <div class="flex items-center gap-2 text-gray-300">
                        <span class="material-symbols-sharp text-white text-base">check</span>
                        Custom use case discussion
                    </div>
                    <div class="flex items-center gap-2 text-gray-300">
                        <span class="material-symbols-sharp text-white text-base">check</span>
                        Integration capabilities
                    </div>
                    <div class="flex items-center gap-2 text-gray-300">
                        <span class="material-symbols-sharp text-white text-base">check</span>
                        Pricing & ROI analysis
                    </div>
                </div>
            </div>
            
            <?php if ($message): ?>
            <!-- Message -->
            <div class="mb-8 p-4 rounded-xl border <?php echo $messageType === 'success' ? 'bg-emerald-50 border-emerald-200 text-emerald-700' : 'bg-red-50 border-red-200 text-red-700'; ?>">
                <div class="flex items-center gap-3">
                    <span class="material-symbols-sharp"><?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 rounded-2xl p-8 shadow-sm border border-gray-100">
                <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-gray-700 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-gray-700 mb-2">Work Email *</label>
                            <input type="email" name="email" required 
                                   value="<?php echo htmlspecialchars($email ?? ''); ?>"
                                   placeholder="john@company.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-gray-700 mb-2">Company *</label>
                            <input type="text" name="company" required
                                   value="<?php echo htmlspecialchars($company ?? ''); ?>"
                                   placeholder="Your Company (Pty) Ltd"
                                   class="form-input">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 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>
                    
                    <!-- Job Title & Company Size -->
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Job Title</label>
                            <input type="text" name="job_title" 
                                   value="<?php echo htmlspecialchars($job_title ?? ''); ?>"
                                   placeholder="e.g., CTO, HR Director"
                                   class="form-input">
                        </div>
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Company Size</label>
                            <select name="company_size" class="form-input form-select">
                                <option value="">Select...</option>
                                <option value="1-50" <?php echo ($company_size ?? '') === '1-50' ? 'selected' : ''; ?>>1-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="501-1000" <?php echo ($company_size ?? '') === '501-1000' ? 'selected' : ''; ?>>501-1000 employees</option>
                                <option value="1000+" <?php echo ($company_size ?? '') === '1000+' ? 'selected' : ''; ?>>1000+ employees</option>
                            </select>
                        </div>
                    </div>
                    
                    <!-- Product Interest -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Product Interest</label>
                        <select name="product_interest" class="form-input form-select">
                            <option value="">Which product are you interested in?</option>
                            <option value="lianela" <?php echo ($product_interest ?? '') === 'lianela' ? 'selected' : ''; ?>>LIANELA V3 - Disciplinary Hearings</option>
                            <option value="sales-agent" <?php echo ($product_interest ?? '') === 'sales-agent' ? 'selected' : ''; ?>>Sales Agent - AI Sales Automation</option>
                            <option value="agentic-ai" <?php echo ($product_interest ?? '') === 'agentic-ai' ? 'selected' : ''; ?>>Agentic AI - Autonomous Agents</option>
                            <option value="gogga" <?php echo ($product_interest ?? '') === 'gogga' ? 'selected' : ''; ?>>Gogga - SA Language Voice AI</option>
                            <option value="darkmatter" <?php echo ($product_interest ?? '') === 'darkmatter' ? 'selected' : ''; ?>>DarkMatter - Legal Intelligence</option>
                            <option value="multiple" <?php echo ($product_interest ?? '') === 'multiple' ? 'selected' : ''; ?>>Multiple Products</option>
                            <option value="not-sure" <?php echo ($product_interest ?? '') === 'not-sure' ? 'selected' : ''; ?>>Not sure yet</option>
                        </select>
                    </div>
                    
                    <!-- Timeline -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Implementation Timeline</label>
                        <select name="timeline" class="form-input form-select">
                            <option value="">When are you looking to implement?</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>
                    
                    <!-- Use Case -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Tell us about your use case</label>
                        <textarea name="use_case" rows="3" 
                                  placeholder="What challenges are you looking to solve?"
                                  class="form-input resize-none"><?php echo htmlspecialchars($use_case ?? ''); ?></textarea>
                    </div>
                    
                    <!-- Comments -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Additional Comments</label>
                        <textarea name="comments" rows="2" 
                                  placeholder="Any specific questions or requirements?"
                                  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-black text-white font-bold uppercase tracking-wider rounded-xl hover:bg-gray-800 transition-all duration-300">
                            <span class="material-symbols-sharp">calendar_month</span>
                            Request Demo
                        </button>
                    </div>
                </div>
            </form>
            
            <!-- Trust Badges -->
            <div class="mt-12 pt-8 border-t border-gray-200">
                <div class="flex flex-wrap items-center justify-center gap-6 text-sm text-gray-400">
                    <div class="flex items-center gap-2">
                        <span class="material-symbols-sharp text-emerald-500 text-lg">verified</span>
                        <span>No commitment required</span>
                    </div>
                    <div class="flex items-center gap-2">
                        <span class="material-symbols-sharp text-blue-500 text-lg">schedule</span>
                        <span>30-minute sessions</span>
                    </div>
                    <div class="flex items-center gap-2">
                        <span class="material-symbols-sharp text-amber-500 text-lg">support_agent</span>
                        <span>Expert-led demos</span>
                    </div>
                </div>
            </div>
        </div>
    </main>
    
    <!-- Footer -->
    <footer class="py-12 bg-gray-50 border-t border-gray-100">
        <div class="max-w-6xl mx-auto px-6">
            <div class="flex flex-col md:flex-row justify-between items-center gap-6">
                <div class="flex items-center gap-4">
                    <img src="/logo-transparent-WhiteBack.png" alt="VCB Logo" class="h-32 w-auto">
                    <div class="flex flex-col">
                        <span class="text-sm text-slate-600">© 2026 Viable Core Business. All rights reserved.</span>
                        <span class="text-xs text-slate-400">Built in South Africa 🇿🇦</span>
                    </div>
                </div>
                <div class="flex gap-6">
                    <a href="/contact.php" class="text-sm text-slate-500 hover:text-black transition-colors">Contact</a>
                    <a href="/LEGAL.html" class="text-sm text-slate-500 hover:text-black transition-colors">Legal</a>
                    <a href="/" class="text-sm text-slate-500 hover:text-black transition-colors">Home</a>
                </div>
            </div>
        </div>
    </footer>
</body>
</html>
