Skip to content
Snippets Groups Projects
Commit 9f960762 authored by Tabitha Permalla's avatar Tabitha Permalla
Browse files

Merge branch 'feat/pembelian' into 'master'

Feat/pembelian

See merge request if3110-2023-01-18/tugas-besar-1!4
parents 4ae6b7ea b549bda5
No related merge requests found
......@@ -33,7 +33,7 @@ class EventController {
return $this->eventModel->getAllEvents();
}
public function paginateEvents($page=1,$pagesize=10,$events) {
public function paginateEvents($events,$page=1,$pagesize=10) {
$maxpage = ceil(count($events)/$pagesize);
if ($page > $maxpage) {
$page = $maxpage;
......
......@@ -6,7 +6,8 @@ require_once(__DIR__ . '/../Models/Pembelian.php');
class PembelianController {
private $pembelianModel;
public function __construct() {
$this->pembelianModel = new PembelianModel();
}
......@@ -31,7 +32,7 @@ class PembelianController {
return $this->pembelianModel->getAllPembelian();
}
public function paginateHistory($page=1,$pagesize=10,$pembelian) {
public function paginateHistory($pembelian,$page=1,$pagesize=10) {
$maxpage = ceil(count($pembelian)/$pagesize);
if ($page > $maxpage) {
$page = $maxpage;
......@@ -41,5 +42,33 @@ class PembelianController {
return $selectedHistory;
}
// Returns true if purchase succeeds
public function purchaseTicket($ticketId,$userId) {
// $purchases = $this->getAllPembelian();
// foreach ($purchases as $purchase) :
// echo $purchase['pembelian_id'] . ': ' . $purchase['user_id'] . ', ' . $purchase['ticket_id'] . ', ' . $purchase['pembelian_created_time']."\n";
// endforeach;
$createdTime = date("Y-m-d H:i:s");
$this->createPembelian($ticketId,$userId,$createdTime);
// $purchases = $this->getAllPembelian();
// foreach ($purchases as $purchase) :
// echo $purchase['pembelian_id'] . ': ' . $purchase['user_id'] . ', ' . $purchase['ticket_id'] . ', ' . $purchase['pembelian_created_time']."\n";
// endforeach;
}
public function handleRequest() {
if (isset($_GET['action'])) {
if ($_GET['action'] === 'purchaseTicket') {
$ticketId = $_POST['ticketId'];
$userId = $_POST['userId'];
$this->purchaseTicket($ticketId,$userId);
} else {
// Handle other actions here, if needed
}
}
}
}
?>
......@@ -26,5 +26,11 @@ class TicketController {
public function deleteTicket($ticketId) {
return $this->ticketModel->deleteTicket($ticketId);
}
public function previewTicket($ticketId) {
$ticket = $this->getTicket($ticketId);
include(__DIR__ . '/../Views/pembelian/pembelian.php');
}
}
?>
<<!-- app/Views/purchase.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Ticket</title>
<!-- Include any CSS styles or external libraries here -->
</head>
<body>
<h1>Purchase Ticket</h1>
<!-- Display the ticket details -->
<h2>Ticket Details</h2>
<p>Ticket ID: <?php echo $ticket['ticket_id']; ?></p>
<p>Ticket Name: <?php echo $ticket['ticket_name']; ?></p>
<p>Price: <?php echo $ticket['ticket_price']; ?></p>
<!-- Purchase Form -->
<form id="purchaseForm" method="post" action="home.php?action=purchaseTicket">
<input type="hidden" name="ticketId" value="<?php echo $ticket['ticket_id']; ?>">
<input type="hidden" name="userId" value="<?php echo $_SESSION['user_id']; ?>">
<!-- Additional form fields or options can be added here -->
<button type="button" id="confirmPurchaseBtn">Confirm Purchase</button>
</form>
<!-- JavaScript code for the confirmation dialog -->
<script>
// Function to show the confirmation dialog
function showConfirmationDialog() {
if (confirm("Are you sure you want to purchase this ticket?")) {
// If the user confirms, submit the form
document.getElementById("purchaseForm").submit();
}
}
// Attach the confirmation dialog to the button click event
document.getElementById("confirmPurchaseBtn").addEventListener("click", showConfirmationDialog);
</script>
<!-- Include any additional content or messages here -->
</body>
</html>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment