<?php
session_start();
$basePath = dirname(__DIR__);
if (file_exists($basePath . '/config.php') || file_exists($basePath . '/install/install.lock')) { die('Installer is locked. To reinstall safely, back up the database, remove config.php and install/install.lock manually, then reload this page.'); }
if (empty($_SESSION['db_host'])) { header('Location: step4.php'); exit; }

$step = 6;
$stepNames = ['Welcome', 'Requirements', 'Permissions', 'Database', 'Import', 'Academy', 'Banking', 'Admin'];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $_SESSION['academy_name'] = trim($_POST['academy_name'] ?? 'CIX Orbit Academy');
    $_SESSION['company_name'] = trim($_POST['company_name'] ?? 'CIX Connect');
    $_SESSION['academy_url'] = trim($_POST['academy_url'] ?? 'https://cixorbitacademy.cixconnect.co.za/');
    $_SESSION['academic_email'] = trim($_POST['academic_email'] ?? 'academic@cixconnect.co.za');
    $_SESSION['office_phone'] = trim($_POST['office_phone'] ?? '012 004 0207');
    $_SESSION['whatsapp_number'] = trim($_POST['whatsapp_number'] ?? '083 759 8075');
    $_SESSION['slogan'] = trim($_POST['slogan'] ?? 'Learn. Build. Automate. Grow.');
    $_SESSION['timezone'] = trim($_POST['timezone'] ?? 'Africa/Johannesburg');
    $_SESSION['default_theme'] = trim($_POST['default_theme'] ?? 'orbit-dark');
    header('Location: step7.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CIX Orbit Academy - Academy Profile</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    <link rel="stylesheet" href="assets/css/install.css">
</head>
<body>
<div class="installer-wrapper">
    <div class="installer-card">
        <div class="installer-header">
            <h1><i class="fas fa-orbit"></i> CIX <span>Orbit</span> Academy</h1>
            <p>Complete LMS &amp; Student Management System</p>
        </div>
        <div class="step-indicator">
            <?php for ($i = 1; $i <= 8; $i++): ?>
            <div class="step-dot <?= $i === $step ? 'active' : ($i < $step ? 'completed' : '') ?>">
                <?= $i < $step ? '<i class="fas fa-check"></i>' : $i ?>
                <span class="step-label"><?= $stepNames[$i-1] ?></span>
            </div>
            <?php endfor; ?>
        </div>
        <div class="installer-content">
            <h2><i class="fas fa-university" style="color:var(--cix-orange)"></i> Academy Profile</h2>
            <p class="subtitle">Set up your academy details. These can be changed later in Settings.</p>
            <form method="POST" action="step6.php" data-validate>
                <div class="form-row">
                    <div class="form-group"><label>Academy Name <span class="required">*</span></label><input type="text" name="academy_name" class="form-control" value="CIX Orbit Academy" required></div>
                    <div class="form-group"><label>Company Name</label><input type="text" name="company_name" class="form-control" value="CIX Connect"></div>
                </div>
                <div class="form-group"><label>Website URL</label><input type="url" name="academy_url" class="form-control" value="https://cixorbitacademy.cixconnect.co.za/"></div>
                <div class="form-row">
                    <div class="form-group"><label>Academic Email <span class="required">*</span></label><input type="email" name="academic_email" class="form-control" value="academic@cixconnect.co.za" required></div>
                    <div class="form-group"><label>Slogan</label><input type="text" name="slogan" class="form-control" value="Learn. Build. Automate. Grow."></div>
                </div>
                <div class="form-row three">
                    <div class="form-group"><label>Office Phone</label><input type="text" name="office_phone" class="form-control" value="012 004 0207"></div>
                    <div class="form-group"><label>WhatsApp</label><input type="text" name="whatsapp_number" class="form-control" value="083 759 8075"></div>
                    <div class="form-group"><label>Timezone</label><select name="timezone" class="form-control"><option value="Africa/Johannesburg">Africa/Johannesburg</option><option value="UTC">UTC</option><option value="Europe/London">Europe/London</option><option value="America/New_York">America/New_York</option></select></div>
                </div>
                <div class="form-group"><label>Default Theme</label><select name="default_theme" class="form-control"><option value="orbit-dark">Orbit Dark</option><option value="cix-orange-lime">CIX Orange Lime</option><option value="academic-blue">Academic Blue</option><option value="clean-white">Clean White</option><option value="cyber-green">Cyber Green</option></select></div>
                <div class="btn-group">
                    <a href="step5.php" class="btn btn-secondary"><i class="fas fa-arrow-left"></i> Back</a>
                    <button type="submit" class="btn btn-primary">Save &amp; Continue <i class="fas fa-arrow-right"></i></button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="assets/js/install.js"></script>
</body>
</html>
