diff --git a/home.php b/home.php new file mode 100644 index 0000000000000000000000000000000000000000..1525b333d14d8070bd7b17b482ef5d6ca441cdae --- /dev/null +++ b/home.php @@ -0,0 +1,279 @@ +<?php +// home.php +session_start(); +// var_dump($_POST); +// require_once './app/EventController.php'; +require_once './app/Controllers/PembelianController.php'; +require_once './app/Controllers/TicketController.php'; +require_once './app/Controllers/UserController.php'; +require_once './app/Controllers/EventController.php'; + +$eventController = new EventController(); +$pembelianController = new PembelianController(); +$ticketController = new TicketController(); +$userController = new UserController(); + +// Check if form is submitted for event +if ($_SERVER["REQUEST_METHOD"] == "POST") { + var_dump($_POST); // Output for debugging purposes + + if (isset($_POST['action'])) { + if ($_POST['action'] === 'createEvent') { + $eventStock = $_POST['stock']; + $eventDate = $_POST['event_date']; + $eventName = $_POST['name']; + $eventLocation = $_POST['location']; + // $uploadedFilePath = $_POST['gambar']; + // $ = $_POST['vid']; + + $imageFilePath = isset($_FILES['gambar']) && $_FILES['gambar']['error'] === 0 ? $_FILES['gambar'] : null; // Check if 'gambar' is set in the files array + $vidFilePath = isset($_FILES['vid']) && $_FILES['vid']['error'] === 0 ? $_FILES['vid'] : null; // Check if 'vid' is set in the files array + + // Check if the values are not empty + if (!empty($eventName) && !empty($eventStock) && !empty($eventDate) && !empty($eventLocation) + && $imageFilePath !== null && $vidFilePath !== null) { + var_dump($_FILES); // Output for debugging purposes + + // // Check for file upload + // $uploadedFile = isset($_FILES['gambar']) ? $_FILES['gambar'] : null; + + // var_dump($uploadedFile); // Output for debugging purposes + + // if ($uploadedFile !== null && $uploadedFile['error'] === 0) { + // // Handle file upload + // $uploadedFilePath = 'assets/' . $uploadedFile['name']; + // move_uploaded_file($uploadedFile['tmp_name'], $uploadedFilePath); + // } + + $eventController->createEvent($eventStock, $eventDate, $eventName, $imageFilePath, $eventLocation, $vidFilePath); + } else { + echo "Please fill in all the fields for creating an event."; + } + } elseif ($_POST['action'] === 'updateEvent') { + $eventIdUpdate = $_POST['eventIdUpdate']; + $eventStock = $_POST['eventStock']; + $eventDate = $_POST['event_date']; + $eventName = $_POST['eventName']; + $eventLocation = $_POST['eventLocation']; + + $imageFilePath = isset($_FILES['gambar']) && $_FILES['gambar']['error'] === 0 ? $_FILES['gambar'] : null; // Check if 'gambar' is set in the files array + $vidFilePath = isset($_FILES['vid']) && $_FILES['vid']['error'] === 0 ? $_FILES['vid'] : null; // Check if 'vid' is set in the files array + + var_dump($_FILES); // Output for debugging purposes + // Check if the values are not empty + if (!empty($eventIdUpdate) && !empty($eventName) && !empty($eventStock) && !empty($eventDate) + && !empty($eventDetails) && !empty($eventLocation) && $imageFilePath !== null && $vidFilePath !== null) { + // $uploadedFilePath = isset($_FILES['gambar']) ? $_FILES['gambar'] : null; // Check if 'gambar' is set in the files array + + // $uploadedFile = isset($_FILES['gambar']) ? $_FILES['gambar'] : null; + // // Check for file upload + // if ($uploadedFilePath !== null && $uploadedFilePath['error'] === 0) { + // // Handle file upload + // $uploadedFilePath = 'assets/' . $uploadedFile['name']; + // move_uploaded_file($uploadedFile['tmp_name'], $uploadedFilePath); + // } + + $eventController->updateEvent($eventIdUpdate, $eventStock, $eventDate, $eventName, $imageFilePath, $eventLocation, $vidFilePath); + } else { + echo "Please fill in all the fields for updating an event."; + } + } elseif ($_POST['action'] === 'deleteEvent') { + $eventController->deleteEvent($_POST['eventIdDelete']); + } + } +} + + +// check form submitted for User +if ($_SERVER["REQUEST_METHOD"] == "POST") { + if (isset($_POST['userAction'])) { + $userController = new UserController(); + + if ($_POST['userAction'] === 'createUser') { + $userName = $_POST['userName']; + $userUsername = $_POST['userUsername']; + $userEmail = $_POST['userEmail']; + $userPassword = $_POST['userPassword']; + $isAdmin = isset($_POST['isAdmin']) ? 1 : 0; + + echo $userController->registerUser($userName, $userUsername, $userEmail, $userPassword, $isAdmin); + } elseif ($_POST['userAction'] === 'updateUser') { + $userIdUpdate = $_POST['userIdUpdate']; + $userNameUpdate = $_POST['userNameUpdate']; + $userUsernameUpdate = $_POST['userUsernameUpdate']; + $userEmailUpdate = $_POST['userEmailUpdate']; + $userPasswordUpdate = password_hash($_POST['userPasswordUpdate'], PASSWORD_DEFAULT); + $isAdminUpdate = isset($_POST['isAdminUpdate']) ? 1 : 0; + + $userController->updateUser($userIdUpdate, $userNameUpdate, $userUsernameUpdate, $userEmailUpdate, $userPasswordUpdate, $isAdminUpdate); + } elseif ($_POST['userAction'] === 'deleteUser') { + $userIdDelete = $_POST['userIdDelete']; + $userController->deleteUser($userIdDelete); + } elseif ($_POST['userAction'] === 'login') { + $loginEmail = $_POST['loginEmail']; + $loginPassword = $_POST['loginPassword']; + echo $userController->loginByEmail($loginEmail,$loginPassword); + // } elseif ($_POST['userAction'] === 'logout') { + // echo $userController->logout(); + } + } +} + + +// Fetch all records for display +$events = $eventController->getAllEvents(); +$pembelian = $pembelianController->getAllPembelian(); +// $tickets = $ticketController->getAllTickets(); +$users = $userController->getAllUsers(); +?> + +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>CRUD Test</title> + <link rel="stylesheet" type="text/css" href="./styles/global.css"> + <link rel="stylesheet" type="text/css" href="./styles/navbar.css"> + <link rel="stylesheet" type="text/css" href="./styles/form.css"> +</head> + +<body> +<!-- Navbar --> + <div class="navbar"> + <div class="navbar-toggle" onclick="toggleMenu()">☰</div> + <ul> + <li><a href="#">Home</a></li> + <li><a href="#">Events</a></li> + <li><a href="#">Profile</a></li> + <li><a href="#">History</a></li> + <!-- Logout Button --> + <li> + <form method="post" action="app/router.php"> + <button type="submit" name="userAction" value="logout">Logout</button> + </form> + </li> + </ul> + </div> + <h1>EDIT DATA</h1> + + <!-- Event CRUD Form --> + <!-- Event CRUD Form --> + <div class="event-form"> + <h2>Events</h2> + + <!-- Create Event --> + <form method="post" action="home.php" enctype="multipart/form-data"> + <label>Create Event:</label> + <input type="text" name="stock" placeholder="Stock"> + <input type="datetime-local" name="event_date"> + <input type="text" name="name" placeholder="Name"> + <input type="text" name="location" placeholder="Location"> + + <!-- Drag-and-drop area for image upload --> + <div id="drop-area-create"> + <p>Drag and drop an image file here or click to select one.</p> + <input type="file" id="file-input-create" name="gambar" accept="image/*"> + </div> + + <!-- <input type="text" name="vid" placeholder="Video URL"> --> + <div id="drop-area-create"> + <p>Drag and drop an video file here or click to select one.</p> + <input type="file" id="file-input-create" name="vid" accept="video/*"> + </div> + + <button type="submit" name="action" value="createEvent">Create</button> + </form> + + <!-- Update Event --> + <form method="post" action="home.php" enctype="multipart/form-data"> + <label>Update Event:</label> + <input type="text" name="eventIdUpdate" placeholder="Event ID"> + <input type="text" name="eventStock" placeholder="Stock"> + <input type="datetime-local" name="event_dateUpdate"> + <input type="text" name="eventName" placeholder="Name"> + <input type="text" name="eventLocation" placeholder="Location"> + + <!-- Drag-and-drop area for image upload --> + <div id="drop-area-update"> + <p>Drag and drop an image file here or click to select one.</p> + <input type="file" id="file-input-update" name="gambar" accept="image/*"> + </div> + + <!-- <input type="text" name="vid" placeholder="Video URL"> --> + <div id="drop-area-update"> + <p>Drag and drop an video file here or click to select one.</p> + <input type="file" id="file-input-update" name="vid" accept="video/*"> + </div> + + <button type="submit" name="action" value="updateEvent">Update</button> + </form> + + <!-- Delete Event --> + <form method="post" action="home.php"> + <label>Delete Event:</label> + <input type="text" name="eventIdDelete" placeholder="Event ID"> + <button type="submit" name="action" value="deleteEvent">Delete</button> + </form> + </div> + + + + <!-- User CRUD Form --> + <div class="user-form"> + <h2>Users</h2> + + <!-- Create User --> + <form method="post" action="home.php"> + <label>Create User:</label> + <input type="text" name="userName" placeholder="Name"> + <input type="text" name="userUsername" placeholder="Username"> + <input type="email" name="userEmail" placeholder="Email"> + <input type="password" name="userPassword" placeholder="Password"> + <input type="checkbox" name="isAdmin" value="1"> Admin + <button type="submit" name="userAction" value="createUser">Create</button> + </form> + + <!-- Update User --> + <form method="post" action="home.php"> + <label>Update User:</label> + <input type="text" name="userIdUpdate" placeholder="User ID"> + <input type="text" name="userNameUpdate" placeholder="Name"> + <input type="text" name="userUsernameUpdate" placeholder="Username"> + <input type="email" name="userEmailUpdate" placeholder="Email"> + <input type="password" name="userPasswordUpdate" placeholder="Password"> + <input type="checkbox" name="isAdminUpdate" value="1"> Admin + <button type="submit" name="userAction" value="updateUser">Update</button> + </form> + + <!-- Delete User --> + <form method="post" action="home.php"> + <label>Delete User:</label> + <input type="text" name="userIdDelete" placeholder="User ID"> + <button type="submit" name="userAction" value="deleteUser">Delete</button> + </form> + + <!-- Login --> + <form method="post" action="home.php"> + <label>Login:</label> + <input type="email" name="loginUsername" placeholder="Email"> + <input type="password" name="loginPassword" placeholder="Password"> + <button type="submit" name="userAction" value="login">Login</button> + </form> + </div> + + + <!-- <div class="footer"> + © <?php echo date("Y"); ?> Ticket Ku. All rights reserved. + </div> --> + + <script defer> + function toggleMenu() { + const navbar = document.querySelector('.navbar ul'); + navbar.classList.toggle('show'); + } + </script> +</body> + +</html> diff --git a/index.php b/index.php new file mode 100644 index 0000000000000000000000000000000000000000..be535ae63bde661e79da27d2426504dec13974f1 --- /dev/null +++ b/index.php @@ -0,0 +1,151 @@ +<?php + session_start(); + include './db/connect.php'; + require_once './app/Controllers/EventController.php'; + + $eventController = new EventController(); + + // Handle search query + $searchQuery = isset($_GET['search']) ? $_GET['search'] : ''; + $sortKey = isset($_GET['sort']) ? $_GET['sort'] : 'name'; + $minStock = isset($_GET['min_stock']) ? $_GET['min_stock'] : null; + + // Get search results or all events + $searchResults = $eventController->searchEvents($searchQuery, $sortKey, $minStock); +?> + +<!DOCTYPE html> +<html lang="en"> + +<head> + <title>TICKET KU</title> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" type="text/css" href="./styles/global.css"> + <link rel="stylesheet" type="text/css" href="./styles/navbar.css"> +</head> + +<body> + + <div class="index"> + <!-- Navbar --> + <div class="navbar"> + <div class="navbar-toggle" onclick="toggleMenu()">☰</div> + <ul> + <li><a href="#">Home</a></li> + <li><a href="#">Events</a></li> + <li><a href="#">Profile</a></li> + <li><a href="#">History</a></li> + <!-- Logout Button --> + <li> + <form method="post" action="home.php"> + <button type="submit" name="userAction" value="logout">Logout</button> + </form> + </li> + </ul> + </div> + <script defer> + function toggleMenu() { + const navbar = document.querySelector('.navbar ul'); + navbar.classList.toggle('show'); + } + </script> + + <div class="hero"> + <img src="./assets/images/Hero.png" alt="Hero Image"> + <h1 class="hero-title">Ticket Ku</h1> + </div> + <div class="button"> + <li><a href="home.php">Edit</a></li> + </div> + <div class="events"> + <h2>All Events</h2> + <ul> + <?php + require_once './app/Controllers/EventController.php'; + $eventController = new EventController(); + $allEvents = $eventController->getAllEvents(); + + foreach ($allEvents as $event) { + echo "<li>"; + echo "<strong>Event ID:</strong> " . $event['event_id'] . "<br>"; + echo "<strong>Stock:</strong> " . $event['event_stock'] . "<br>"; + echo "<strong>Created Time:</strong> " . $event['event_date'] . "<br>"; + echo "<strong>Name:</strong> " . $event['event_name'] . "<br>"; + echo "<strong>Image:</strong> <img src='" . $event['gambar'] . "' alt='Event Image' width='100'><br>"; + echo "<strong>Location:</strong> " . $event['event_location'] . "<br>"; + echo "<strong>Video:</strong> <video src='" . $event['vid'] . "' controls width='150'></video><br>"; + echo "</li>"; + } + + include './db/init.php'; + ?> + + </ul> + </div> + <!-- Search Bar with Filter --> + <div class="search-bar"> + <form method="get" action="index.php"> + <input type="text" name="search" placeholder="Search events..." value="<?= htmlspecialchars($searchQuery) ?>"> + <?php if (!empty($searchQuery) || !empty($minStock) || !empty($sortKey)) : ?> + <select name="sort"> + <option value="" <?= empty($sortKey) ? 'selected' : '' ?>>No Sorting</option> + <option value="name" <?= $sortKey === 'name' ? 'selected' : '' ?>>Sort by Name</option> + <option value="location" <?= $sortKey === 'location' ? 'selected' : '' ?>>Sort by Location</option> + </select> + <?php else : ?> + <select name="sort"> + <option value="" selected>No Sorting</option> + <option value="name">Sort by Name</option> + <option value="location">Sort by Location</option> + </select> + <?php endif; ?> + <!-- Change input type to "text" for minimum stock --> + <input type="text" name="min_stock" placeholder="Min Stock" value="<?= htmlspecialchars($minStock) ?>"> + <button type="submit" id="search-button">Search</button> + </form> + </div> + + <!-- Display Search Results or All Events --> + <div class="events"> + <h2><?= !empty($searchQuery) || !empty($minStock) ? 'Search Results' : 'All Events' ?></h2> + <ul> + <?php + foreach ($searchResults as $event) { + echo "<li>"; + echo "<strong>Event ID:</strong> " . $event['event_id'] . "<br>"; + echo "<strong>Stock:</strong> " . $event['event_stock'] . "<br>"; + echo "<strong>Created Time:</strong> " . $event['event_date'] . "<br>"; + echo "<strong>Name:</strong> " . $event['event_name'] . "<br>"; + echo "<strong>Image:</strong> <img src='" . $event['gambar'] . "' alt='Event Image' width='100'><br>"; + echo "<strong>Location:</strong> " . $event['event_location'] . "<br>"; + echo "</li>"; + } + ?> + </ul> + </div> + <div class="footer"> + © 2023 Ticket Ku. All rights reserved. + </div> + </div> + + <script> + // disable search button temporarily (DEBOUNCE) + function disableSearchButton() { + const searchButton = document.getElementById("search-button"); + searchButton.disabled = true; + + setTimeout(() => { + searchButton.disabled = false; + }, 1200); // 0.8s delay + } + + document.querySelector(".search-bar form").addEventListener("submit", function (e) { + e.preventDefault(); + disableSearchButton(); + }); + </script> + +</body> + +</html>