Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 200 additions and 57 deletions
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<li><a href="/app/Views/history/history.php">History</a></li> <li><a href="/app/Views/history/history.php">History</a></li>
<!-- Logout Button --> <!-- Logout Button -->
<li> <li>
<form method="post" action="/app/router.php"> <form method="post" action="/logout">
<button type="submit" name="userAction" value="logout">Logout</button> <button type="submit" name="userAction" value="logout">Logout</button>
</form> </form>
</li> </li>
......
File moved
File moved
File moved
File moved
File moved
File moved
<?php
if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
ob_start();
if (!isset($_SESSION["user_id"])) {
echo "here";
// User is not authenticated; redirect to login page
header("Location: /app/Views/login/login.php");
ob_end_flush();
}
require_once '../../Controllers/UserController.php';
$userController = new UserController();
$isAdmin = $userController->getUser($_SESSION['user_id'])['isAdmin'];
// Allow only admin to access this page
if (!$isAdmin){
header("Location: /app/Views/home/home.php");
ob_end_flush();
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
......
<?php
if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
ob_start();
if (!isset($_SESSION["user_id"])) {
echo "here";
// User is not authenticated; redirect to login page
header("Location: /app/Views/login/login.php");
ob_end_flush();
}
require_once '../../Controllers/UserController.php';
$userController = new UserController();
$isAdmin = $userController->getUser($_SESSION['user_id'])['isAdmin'];
// Allow only admin to access this page
if (!$isAdmin){
header("Location: /app/Views/home/home.php");
ob_end_flush();
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
......
<?php <?php
session_start(); if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
ob_start(); ob_start();
if (!isset($_SESSION["user_id"])) { if (!isset($_SESSION["user_id"])) {
echo "here"; echo "here";
...@@ -25,7 +28,9 @@ ...@@ -25,7 +28,9 @@
} else { } else {
$pembelians = $pembelianController->getAllPembelianWithDetails(); $pembelians = $pembelianController->getAllPembelianWithDetails();
} }
$paginationData = $pembelianController->paginateHistory($pembelians); $pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10;
$paginationData = $pembelianController->paginateHistory($pembelians,$_GET['page'],$pageSize);
$pembelians = $paginationData['pembelian']; $pembelians = $paginationData['pembelian'];
$totalEvents = $paginationData['total']; $totalEvents = $paginationData['total'];
$currentPage = $paginationData['page']; $currentPage = $paginationData['page'];
...@@ -61,18 +66,30 @@ ...@@ -61,18 +66,30 @@
endforeach;?> endforeach;?>
</div> </div>
<div class="pagination"> <div class="pagination">
<?php if ($currentPage > 1) : ?> <?php
<a href="?page=<?= $currentPage - 1 ?>">Previous</a> $searchParams = [
<?php endif; ?> 'search' => $searchQuery,
'min_stock' => $minStock,
<?php for ($i = 1; $i <= $maxPage; $i++) : ?> 'sort' => $sortKey,
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a> 'pageSize' => $pageSize, // Include page size
<?php endfor; ?> ];
<?php if ($currentPage < $maxPage) : ?> $maxButtons = 5; // Maximum number of pagination buttons to display
<a href="?page=<?= $currentPage + 1 ?>">Next</a> $halfMaxButtons = floor($maxButtons / 2);
<?php endif; ?>
</div> if ($currentPage > 1) : ?>
<a href="?page=<?= $currentPage - 1 ?>">Previous</a>
<?php endif; ?>
<?php
for ($i = max(1, $currentPage - $halfMaxButtons); $i <= min($maxPage, $currentPage + $halfMaxButtons); $i++) : ?>
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a>
<?php endfor; ?>
<?php if ($currentPage < $maxPage) : ?>
<a href="?page=<?= $currentPage + 1 ?>">Next</a>
<?php endif; ?>
</div>
</div> </div>
......
<?php <?php
session_start(); if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
ob_start(); ob_start();
if (!isset($_SESSION["user_id"])) { if (!isset($_SESSION["user_id"])) {
echo "here"; echo "here";
// User is not authenticated; redirect to login page // User is not authenticated; redirect to login page
header("Location: /app/Views/login/login.php"); header("Location: login");
ob_end_flush(); ob_end_flush();
} }
require_once '../../Controllers/PembelianController.php'; require_once (__DIR__.'/../../../Server/Controllers/PembelianController.php');
require_once '../../Controllers/TicketController.php'; require_once (__DIR__.'/../../../Server/Controllers/TicketController.php');
require_once '../../Controllers/UserController.php'; require_once (__DIR__.'/../../../Server/Controllers/UserController.php');
require_once '../../Controllers/EventController.php'; require_once (__DIR__.'/../../../Server/Controllers/EventController.php');
$eventController = new EventController(); $eventController = new EventController();
$pembelianController = new PembelianController(); $pembelianController = new PembelianController();
$ticketController = new TicketController(); $ticketController = new TicketController();
$userController = new UserController(); $userController = new \Server\Controllers\UserController();
// Handle search query // Handle search query
$searchQuery = isset($_GET['search']) ? $_GET['search'] : ''; $searchQuery = isset($_GET['search']) ? $_GET['search'] : '';
...@@ -28,13 +31,15 @@ ...@@ -28,13 +31,15 @@
if (!isset($_GET['page'])) { if (!isset($_GET['page'])) {
$_GET['page'] = 1; $_GET['page'] = 1;
} }
$paginationData = $eventController->paginateEvents($searchResults,$_GET['page']); $pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10;
$paginationData = $eventController->paginateEvents($searchResults,$_GET['page'],$pageSize);
$events = $paginationData['events']; $events = $paginationData['events'];
$totalEvents = $paginationData['total']; $totalEvents = $paginationData['total'];
$currentPage = $paginationData['page']; $currentPage = $paginationData['page'];
$maxPage = $paginationData['maxpage']; $maxPage = $paginationData['maxpage'];
$isAdmin = $userController->getUser($_SESSION['user_id'])['isAdmin']; $isAdmin = $userController->getUser($_SESSION['user_id'])['isadmin'];
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
...@@ -44,20 +49,20 @@ ...@@ -44,20 +49,20 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HOME • TICKET KU</title> <title>HOME • TICKET KU</title>
<link rel="stylesheet" type="text/css" href="/../../styles/global.css"> <link rel="stylesheet" type="text/css" href="/../../global.css">
<link rel="stylesheet" type="text/css" href="/../../styles/form.css"> <link rel="stylesheet" type="text/css" href="/../../form.css">
<link rel="stylesheet" type="text/css" href="/../../styles/footer.css"> <link rel="stylesheet" type="text/css" href="/../../footer.css">
<link rel="stylesheet" type="text/css" href="/../../styles/navbar.css"> <link rel="stylesheet" type="text/css" href="/../../navbar.css">
<link rel="stylesheet" type="text/css" href="/../../styles/container.css"> <link rel="stylesheet" type="text/css" href="/../../container.css">
<link rel="stylesheet" type="text/css" href="/../../styles/auth.css"> <link rel="stylesheet" type="text/css" href="/../../auth.css">
<link rel="stylesheet" type="text/css" href="/../../styles/dropdown.css"> <link rel="stylesheet" type="text/css" href="/../../dropdown.css">
<link rel="stylesheet" type="text/css" href="/../../styles/pagination.css"> <link rel="stylesheet" type="text/css" href="/../../pagination.css">
<link rel="stylesheet" type="text/css" href="/../../styles/media.css"> <link rel="stylesheet" type="text/css" href="/../../media.css">
</head> </head>
<body> <body>
<!-- Navbar --> <!-- Navbar -->
<?php include '../template/navbar.php';?> <?php include (__DIR__.'/../../components/navbar.php');?>
<div class="main-content"> <div class="main-content">
<div class="column"> <div class="column">
...@@ -65,38 +70,53 @@ ...@@ -65,38 +70,53 @@
<button onclick="openCreateEventPage()" id="createEventBtn" class="admin">Create Event</button> <button onclick="openCreateEventPage()" id="createEventBtn" class="admin">Create Event</button>
<?php endif; ?> <?php endif; ?>
<div class="row"> <div class="row">
<input type="text" id="searchInput" placeholder="Search.." value="<?= htmlspecialchars($searchQuery)?>" style="width:250%;"> <input type="text" id="searchInput" placeholder="Search.." value="<?= isset($searchQuery) ? htmlspecialchars($searchQuery) : '' ?>" style="width:250%;">
<select name="sort" id="sortSelect" class="styled-select"> <select name="sort" id="sortSelect" class="styled-select">
<option value="" <?= empty($sortKey) ? 'selected' : '' ?>>No Sorting</option> <option value="" <?= empty($sortKey) ? 'selected' : '' ?>>No Sorting</option>
<option value="name" <?= $sortKey === 'name' ? 'selected' : '' ?>>Sort by Name</option> <option value="name" <?= $sortKey === 'name' ? 'selected' : '' ?>>Sort by Name</option>
<option value="location" <?= $sortKey === 'location' ? 'selected' : '' ?>>Sort by Location</option> <option value="location" <?= $sortKey === 'location' ? 'selected' : '' ?>>Sort by Location</option>
</select> </select>
<!-- Change input type to "text" for minimum stock --> <!-- Change input type to "text" for minimum stock -->
<input type="text" id="minStockInput" name="min_stock" placeholder="Min Stock" value="<?= htmlspecialchars($minStock) ?>"> <input type="text" id="minStockInput" name="min_stock" placeholder="Min Stock" value="<?= isset($minStock) ? htmlspecialchars($minStock) : 0 ?>"
">
<button type="submit" id="search-button">Search</button> <button type="submit" id="search-button">Search</button>
</div> </div>
<?php foreach ($events as $event) : <?php foreach ($events as $event) :
include '../template/event.php'; include (__DIR__.'/../../components/event.php');
endforeach;?> endforeach;?>
<div class="pagination"> <div class="pagination">
<?php if ($currentPage > 1) : ?> <?php
<a href="?page=<?= $currentPage - 1 ?>">Previous</a> $searchParams = [
'search' => $searchQuery,
'min_stock' => $minStock,
'sort' => $sortKey,
'pageSize' => $pageSize, // Include page size
];
$maxButtons = 5; // Maximum number of pagination buttons to display
$halfMaxButtons = floor($maxButtons / 2);
if ($currentPage > 1) : ?>
<a href="?page=<?= $currentPage - 1 . '&' . http_build_query($searchParams) ?>">Previous</a>
<?php endif; ?> <?php endif; ?>
<?php for ($i = 1; $i <= $maxPage; $i++) : ?> <?php
<a href="?page=<?= $i ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a> for ($i = max(1, $currentPage - $halfMaxButtons); $i <= min($maxPage, $currentPage + $halfMaxButtons); $i++) : ?>
<a href="?page=<?= $i . '&' . http_build_query($searchParams) ?>" <?= ($i == $currentPage) ? 'class="active"' : '' ?>><?= $i ?></a>
<?php endfor; ?> <?php endfor; ?>
<?php if ($currentPage < $maxPage) : ?> <?php if ($currentPage < $maxPage) : ?>
<a href="?page=<?= $currentPage + 1 ?>">Next</a> <a href="?page=<?= $currentPage + 1 . '&' . http_build_query($searchParams) ?>">Next</a>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
<?php include '../template/footer.php';?> <?php include (__DIR__.'/../../components/footer.php');?>
<script defer> <script defer>
function toggleMenu() { function toggleMenu() {
...@@ -126,7 +146,7 @@ ...@@ -126,7 +146,7 @@
const sortKey = document.getElementById('sortSelect').value; const sortKey = document.getElementById('sortSelect').value;
// Construct the URL with search, min_stock, and sort parameters // Construct the URL with search, min_stock, and sort parameters
const url = `/app/Views/home/home.php?search=${encodeURIComponent(searchQuery)}&min_stock=${encodeURIComponent(minStock)}&sort=${encodeURIComponent(sortKey)}`; const url = `/home?search=${encodeURIComponent(searchQuery)}&min_stock=${encodeURIComponent(minStock)}&sort=${encodeURIComponent(sortKey)}`;
// Redirect to the updated URL // Redirect to the updated URL
window.location.href = url; window.location.href = url;
......
<?php
if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login • 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="../../auth.css">
</head>
<body>
<div class="login-container">
<h1>Login</h1>
<form id="loginForm" method="post" action="login">
<!-- Aslinya email atau username bisa(?) -->
<label for="email">Email or Username</label>
<input type="text" id="identifier" name="loginIdentifier" required>
<label for="password">Password</label>
<input type="password" id="password" name="loginPassword" required>
<?php
// Check if there is an error message in the session
if (isset($_SESSION['message'])) {
echo '<p>' . $_SESSION['message'] . '</p>';
unset($_SESSION['message']); // Remove the error message from the session
}
?>
<button type="submit" name="userAction" value="login">Login</button>
</form>
<p>Don't have an account? <a href="register">Register</a></p>
</div>
</body>
</html>
<?php <?php
session_start(); if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
...@@ -8,13 +11,13 @@ ...@@ -8,13 +11,13 @@
<title>Register • TICKET KU</title> <title>Register • TICKET KU</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../../../styles/auth.css"> <link rel="stylesheet" type="text/css" href="../../auth.css">
</head> </head>
<body> <body>
<div class="register-container"> <div class="register-container">
<h1>Register</h1> <h1>Register</h1>
<form id="registerForm" method="post" action="../../router.php"> <form id="registerForm" method="post" action="register">
<label for="userName">Name</label> <label for="userName">Name</label>
<input type="text" id="userName" name="userName" required> <input type="text" id="userName" name="userName" required>
...@@ -41,7 +44,7 @@ ...@@ -41,7 +44,7 @@
<button type="submit" name="userAction" value="createUser">Register</button> <button type="submit" name="userAction" value="createUser">Register</button>
</form> </form>
<p>Already have an account? <a href="login.php">Login</a></p> <p>Already have an account? <a href="login">Login</a></p>
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
<?php <?php
session_start(); if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
ob_start(); ob_start();
if (!isset($_SESSION["user_id"])) { if (!isset($_SESSION["user_id"])) {
echo "here"; echo "here";
......
<?php <?php
session_start(); if (session_status() == PHP_SESSION_NONE) {
// If a session is not already started, start a new one
session_start();
}
ob_start(); ob_start();
if (!isset($_SESSION["user_id"])) { if (!isset($_SESSION["user_id"])) {
echo "here"; echo "here";
......
File moved
<?php <?php
// app/Controllers/EventController.php
ob_start(); ob_start();
require_once(__DIR__ . '/../Models/Event.php'); include(__DIR__ . '../../Models/Event.php');
require_once(__DIR__ . '/TicketController.php'); require_once(__DIR__ . '/TicketController.php');
...@@ -10,7 +9,7 @@ class EventController { ...@@ -10,7 +9,7 @@ class EventController {
private $eventModel; private $eventModel;
public function __construct() { public function __construct() {
$this->eventModel = new EventModel(); $this->eventModel = new \Server\Models\EventModel();
} }
public function createEvent($event_name, $stock, $event_price, $event_date, $event_location, $gambar, $vid){ public function createEvent($event_name, $stock, $event_price, $event_date, $event_location, $gambar, $vid){
......
<?php
namespace Server\Controllers;
class HomeController {
public function __construct(){}
public function home()
{
include (__DIR__.'/../../Client/pages/home/home.php');
}
}
\ No newline at end of file
...@@ -10,11 +10,10 @@ class PembelianController { ...@@ -10,11 +10,10 @@ class PembelianController {
public function __construct() { public function __construct() {
$this->pembelianModel = new PembelianModel(); $this->pembelianModel = new \Server\Models\PembelianModel();
} }
public function createPembelian($ticketId, $userId, $createdTime) { public function createPembelian($ticketId, $userId, $createdTime) {
$pembelianModel = new PembelianModel();
return $this->pembelianModel->createPembelian($ticketId, $userId, $createdTime); return $this->pembelianModel->createPembelian($ticketId, $userId, $createdTime);
} }
......