<?php
session_start();
require_once('../connection.php');


if (!isset($_SESSION['userID'])) {
    header('Location: ../login/login-form.php');
    exit();
}

$first_name = $_SESSION['first_name'];
$email = $_SESSION['email'];

?>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>GLH | Become a Producer</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
    
    <style>
        
    .sidebar { 
        background-color: #3b3b3b;
        height: 100%;
        width: 260px;
        position: fixed;
        z-index: 1;
        top: 0;
        left: 0;
        overflow-x: hidden;
        padding-top: 20px;
    }


    .dash {
        padding: 20px;
        transition: margin-left .3s;
    }


    @media screen and (min-width: 768px) {
    .sidebar {
        display: block !important;
    }
    
    .dash {
        margin-left: 260px;
        padding-right: 20px; 
    }
    
    .sidebar-open, .sidebar-hidden {
        display: none !important;
    }
    }
        
    
    .logo {
        margin-left: 15px;
        margin-top: 10px; 
        margin-bottom: 30px; 
        display: block;    
    }
    
    hr.solid-top {
        border-top: 1px solid #bbb;
        border-radius: 5px;
        width: 90%;
        margin-left: 13px;
    }
    
    .sidebar-links {
        padding: 6px 8px 6px 16px;
        text-decoration: none;
        font-size: 14px; 
        display: block;
        border-color: transparent;
    }
    
    .sidebar-links a:hover {
        background-color: #90d5ff;
    }
    
    .sidebar-links button {
        background-color: transparent;
        color: white;
        border-color: transparent;
        border-radius: 3px;
    }
    
    .sidebar-links button:hover {
        background-color: #90d5ff;
        color: black;
    }
    
    hr.solid-bottom {
        border-top: 1px solid #bbb;
        border-radius: 5px;
        width: 90%;
        margin-left: 13px;
    }

    .user-profile {
        margin-top: 61.8vh;
    }
    
    .dash {
        padding-right: 260px;
        padding: 20px;
        transition: margin-left .3s;
    }

    .sidebar-open {
        background: transparent;
        border: none;
        color: black;
        font-size: 30px;
    }

    .sidebar-hidden {
        background: transparent;
        border: none;
        color: white;
        font-size: 30px;
        float: right;
        margin-right: 8px;
        margin-top: -115px;
    }

    </style>
</head>
<body>
    
    <header class="sidebar" id="sidebar">
        <div class="logo">
            <a href="../index.php">
                <img src="../glh.png" class="logo" alt="logo" width="150" height="60">
            </a>
        </div>
        
        <button class="sidebar-hidden" onclick="hideNav()"><i class="bi bi-x"></i></button>
        
        <hr class="solid-top">
        
        <div class="sidebar-links">
            <div class="home-page">
                <a href="../index.php">
                    <button><i class="bi bi-house"></i> Home</button>
                </a>
            </div>
            <div class="orders">
                <a href="orders.php"><button><i class="bi bi-receipt-cutoff"></i> Order History</button></a>
            </div>
            <div class="dashboard">
                <a href="dashboard.php"><button><i class="bi bi-laptop"></i> Dashboard</button></a>
            </div>
            <div class="producer-dash">
                <a href="producer-dashboard.php"><button><i class="bi bi-laptop"></i> Producer Dashboard</button></a>
            </div>
        </div>
            
            <hr class="solid-bottom">
            
            <div class="sidebar-links">
                <div class="user-profile">
                    <a href="account.php">
                        <button><i class="bi bi-person-exclamation"></i> Account Details</button>
                    </a>
                </div>
                <div class="logout">
                    <a href="logout.php">
                        <button><i class="bi bi-box-arrow-left"></i> Logout</button>
                    </a>
                </div>
            </div>
    </header>
    
    
    
    <div class="dash">
        <button class="sidebar-open" onclick="showNav()"><i class="bi bi-list"></i></button>
        
        <div class="form-wrapper">
        <div class="form-card">
            <form method="POST" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data">
                
                <h3>Become a producer</h3><br>
                
                <input type="text" name="name" placeholder="Name" required><br><br>
                <input type="text" name="email" placeholder="Email" required><br><br>
                <input type="text" name="phone_number" placeholder="Phone Number" required><br><br>
                <input type="textarea" name="description" placeholder="description" required><br><br>
                
                <input type="submit" class="submit-button" name="submit" value="Send ticket"><br><br>
                
                <?php
            
                    if (isset($_POST['submit'])) {
                        $name = $_POST['name'];
                        $email = $_POST['email'];
                        $phone_number = $_POST['phone_number'];
                        $description = $_POST['description'];
                        
                        
                        try {
        
                            $stmt = $conn->prepare("INSERT INTO requests (name, email, phone_number, description) VALUES (?, ?, ?, ?)");
                            $stmt->bind_param("ssss", $name, $email, $phone_number, $description);
                    

                            if ($stmt->execute()) {
                                echo "<script>
                                    alert('You have successfully sent a producer ticket.');
                                    window.location.href = 'producer.php';
                                    </script>";
                                exit();
                        
                            } else {
                                echo "<script>
                                    alert('There was an issue submitting your ticket.');
                                    window.location.href = 'producer.php';
                                </script>";
                                exit();
                            }
                            } catch (Exception $e) {
                        } 
                    }
                
                
                
                ?>
                        
    </div>
        
    
<script>
function showNav() {
  document.getElementById("sidebar").style.display = "block";
}

function hideNav() {
  document.getElementById("sidebar").style.display = "none";
}
</script>
    
    
</body>
</html>
