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
Commits on Source (19)
Showing
with 99 additions and 263 deletions
FROM php:8.0-apache
FROM php:8.1-apache
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y libxml2-dev libpq-dev
RUN docker-php-ext-install pgsql pdo pdo_pgsql && docker-php-ext-enable pgsql pdo pdo_pgsql
RUN a2enmod rewrite && service apache2 restart
RUN chown -R :www-data /var/www/html/
RUN docker-php-ext-install pdo pdo_mysql
\ No newline at end of file
WORKDIR /var
EXPOSE 80
\ No newline at end of file
<?php
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="../../../styles/auth.css">
</head>
<body>
<div class="login-container">
<h1>Login</h1>
<form id="loginForm" method="post" action="../../router.php">
<!-- 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.php">Register</a></p>
</div>
</body>
</html>
\ No newline at end of file
<?php
require_once './Controllers/PembelianController.php';
require_once './Controllers/TicketController.php';
require_once './Controllers/UserController.php';
require_once './Controllers/EventController.php';
$eventController = new EventController();
$pembelianController = new PembelianController();
$ticketController = new TicketController();
$userController = new UserController();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["eventAction"])) {
$eventController->handleRequest();
} elseif (isset($_POST["ticketAction"])) {
$ticketController->handleRequest();
} elseif (isset($_POST["userAction"])) {
$userController->handleRequest();
} elseif (isset($_POST["purchaseAction"])) {
$pembelianController->handleRequest();
}
} elseif ($_SERVER["REQUEST_METHOD"] == "GET") {
if (isset($_GET["eventAction"]) && isset($_GET["eventId"])) {
$eventController->handleRequest();
} elseif (isset($_GET["ticketAction"])) {
$ticketController->handleRequest();
} elseif (isset($_GET["userAction"])) {
$userController->handleRequest();
}
}
?>
\ No newline at end of file
<?php
function preprocess($str) {
return str_replace(' ', '%20', $str);
}
function formatPrice($price) {
return number_format($price,0,',','.');
}
function isEmailValid($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
?>
\ No newline at end of file
CREATE TABLE IF NOT EXISTS users (
user_ID SERIAL PRIMARY KEY,
user_name VARCHAR(255),
username VARCHAR(255) UNIQUE,
user_email VARCHAR(255) UNIQUE,
user_hashedPass VARCHAR(255),
isAdmin BOOLEAN
);
\ No newline at end of file
CREATE TABLE IF NOT EXISTS events (
event_id SERIAL PRIMARY KEY,
event_name VARCHAR(255),
event_stock INT,
event_price INT,
event_date TIMESTAMP,
event_location VARCHAR(255),
gambar VARCHAR(255),
vid VARCHAR(255)
);
\ No newline at end of file
CREATE TABLE IF NOT EXISTS tickets (
ticket_id SERIAL PRIMARY KEY,
ticket_name VARCHAR(255),
event_id INT,
FOREIGN KEY (event_id) REFERENCES events(event_id) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS pembelian (
pembelian_id SERIAL PRIMARY KEY,
ticket_id INT,
user_id INT,
pembelian_created_time TIMESTAMP,
FOREIGN KEY (ticket_id) REFERENCES tickets(ticket_id),
FOREIGN KEY (user_id) REFERENCES users(user_ID) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS subscription (
creator_id INT NOT NULL,
subscriber_id INT NOT NULL,
status VARCHAR(10) NOT NULL DEFAULT 'PENDING',
creator_name VARCHAR(255) NOT NULL,
PRIMARY KEY (creator_id, subscriber_id),
FOREIGN KEY (subscriber_id) REFERENCES users(user_ID) ON DELETE CASCADE
);
-- Generate and insert 100 dummy events with random data
DO $$
DECLARE
i INT;
BEGIN
FOR i IN 1..100 LOOP
INSERT INTO events (event_name, event_stock, event_price, event_date, event_location, gambar, vid)
VALUES (
'Event ' || i,
FLOOR(RANDOM() * 10) + 1,
FLOOR(RANDOM() * 91) + 10,
NOW() + (i || ' days')::INTERVAL,
'Location ' || i,
'assets/images/' || (i % 16 + 1) || '.jpg',
'assets/videos/video.mp4'
);
-- Generate and insert tickets corresponding to the event's event_stock
FOR j IN 1..(FLOOR(RANDOM() * 10) + 1) LOOP
INSERT INTO tickets (ticket_name, event_id)
VALUES (
'Ticket ' || j || ' for Event ' || i,
(SELECT MAX(event_id) FROM events)
);
END LOOP;
END LOOP;
END $$;
-- Insert user data
INSERT INTO users (user_name, username, user_email, user_hashedPass, isAdmin)
VALUES
('John Doe', 'john_doe', 'john@example.com', '$2y$10$8sA2N5Sx/1zMQv2yrTDAaOFlbGWECrrgB68axL.hBb78NhQdyAqWm', 'true'),
('Jane Smith', 'jane_smith', 'jane@example.com', '$2y$10$8sA2N5Sx/1zMQv2yrTDAaOFlbGWECrrgB68axL.hBb78NhQdyAqWm', 'false'),
('Admin User', 'admin_user', 'admin@example.com', '$2y$10$8sA2N5Sx/1zMQv2yrTDAaOFlbGWECrrgB68axL.hBb78NhQdyAqWm', 'true'),
('Alice Johnson', 'alice', 'alice@example.com', '$2y$10$8sA2N5Sx/1zMQv2yrTDAaOFlbGWECrrgB68axL.hBb78NhQdyAqWm', 'false'),
('Bob Williams', 'bob', 'bob@example.com', '$2y$10$8sA2N5Sx/1zMQv2yrTDAaOFlbGWECrrgB68axL.hBb78NhQdyAqWm', 'false');
<?php
$host = 'db';
$dbname = 'tubes1_WBD';
$user = 'root';
$pass = 'your_password';
try {
$db = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
// Execute SQL statements from init.sql
$sqlInit = file_get_contents(__DIR__ . '/init.sql');
$db->exec($sqlInit);
// echo "Connected successfully and database initialized!<br/>";
} catch (PDOException $e) {
// echo "Connection failed: " . $e->getMessage();
}
?>
<?php
include 'connect.php';
// Make sure $db is defined and not null
if (isset($db)) {
try {
$db->beginTransaction();
// Insert events and tickets as before
$sqlEvent = <<<EOF
INSERT INTO events (event_name, event_stock, event_price, event_date, event_location, gambar, vid) VALUES
('Music Concert', 2, 20, '2023-09-30 10:00:00', 'jakarta', 'assets/images/1.jpg', 'assets/videos/video.mp4'),
('Art Exhibition', 2, 15, '2023-10-05 15:30:00', 'prancis', 'assets/images/2.png', 'assets/videos/video.mp4'),
('Sports Tournament', 2, 40, '2023-11-12 18:45:00', 'italy', 'assets/images/3.jpg', 'assets/videos/video.mp4'),
('Comedy Show', 2, 30, '2023-12-03 20:00:00', 'jakarta', 'assets/images/4.jpg', 'assets/videos/video.mp4'),
('Tech Conference', 2, 60, '2024-01-18 14:15:00', 'ITB', 'assets/images/5.jpg', 'assets/videos/video.mp4');
EOF;
$sqlTicket = <<<EOF
INSERT INTO tickets (ticket_name, event_id) VALUES
('General Admission', 1),
('VIP Pass', 1),
('Standard Ticket', 2),
('Student Discount', 2),
('Early Bird Special', 3),
('Premium Access', 3),
('Weekend Pass', 4),
('Group Discount', 4),
('Conference Pass', 5),
('Exhibitor Pass', 5);
EOF;
$db->exec($sqlEvent);
$db->exec($sqlTicket);
// Dummy user data with hashed passwords
$userData = [
['John Doe', 'john_doe', 'john@example.com', password_hash('password_1', PASSWORD_DEFAULT), 1],
['Jane Smith', 'jane_smith', 'jane@example.com', password_hash('password_2', PASSWORD_DEFAULT), 0],
['Admin User', 'admin_user', 'admin@example.com', password_hash('password_3', PASSWORD_DEFAULT), 1],
['Alice Johnson', 'alice', 'alice@example.com', password_hash('password_4', PASSWORD_DEFAULT), 0],
['Bob Williams', 'bob', 'bob@example.com', password_hash('password_5', PASSWORD_DEFAULT), 0]
];
$sqlUser = "INSERT INTO users (user_name, username, user_email, user_hashedPass, isAdmin) VALUES (?, ?, ?, ?, ?)";
$stmt = $db->prepare($sqlUser);
foreach ($userData as $user) {
$stmt->execute($user);
}
$stmt->closeCursor();
// // Insert pembelian data
// $sqlPembelian = <<<EOF
// INSERT INTO pembelian (ticket_id, user_id, pembelian_created_time) VALUES
// (1, 1, '2023-10-01 12:30:00'),
// (3, 2, '2023-10-06 16:15:00'),
// (2, 3, '2023-11-15 20:00:00'),
// (5, 4, '2023-12-05 10:45:00'),
// (8, 5, '2024-01-20 08:30:00');
// EOF;
// $db->exec($sqlPembelian);
// Commit the transaction
$db->commit();
echo "Successfully inserted dummy data.<br/>";
} catch (PDOException $e) {
$db->rollBack();
echo "Error: " . $e->getMessage();
}
} else {
echo "Error: Database connection not established.";
}
$db = null;
?>
<?php
include 'connect.php';
$dotenvContents = file_get_contents(__DIR__ . '/../.env');
$dotenvLines = explode("\n", $dotenvContents);
foreach ($dotenvLines as $line) {
// Skip empty lines and comments
if (!empty($line) && strpos($line, '=') !== false && strpos($line, '#') !== 0) {
list($name, $value) = explode('=', $line, 2);
$_ENV[$name] = $value;
putenv("$name=$value");
}
}
error_reporting(E_ALL);
ini_set('display_errors', 1);
include 'reset.php';
include 'data.php';
$db = null;
// echo "Database initialization successful!";
?>
CREATE DATABASE IF NOT EXISTS tubes1_WBD;
USE tubes1_WBD;
CREATE TABLE IF NOT EXISTS events (
event_id INT AUTO_INCREMENT PRIMARY KEY,
event_name CHAR(255),
event_stock INT,
event_price INT,
event_date DATETIME,
event_location CHAR(255),
gambar VARCHAR(255),
vid VARCHAR(255)
);
CREATE TABLE IF NOT EXISTS tickets (
ticket_id INT AUTO_INCREMENT PRIMARY KEY,
ticket_name CHAR(255),
event_id INT,
FOREIGN KEY (event_id) REFERENCES events(event_id) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS users (
user_ID INT AUTO_INCREMENT PRIMARY KEY,
user_name CHAR(255),
username CHAR(255) UNIQUE,
user_email VARCHAR(255) UNIQUE,
user_hashedPass CHAR(255),
isAdmin BOOLEAN
);
CREATE TABLE IF NOT EXISTS pembelian (
pembelian_id INT AUTO_INCREMENT PRIMARY KEY,
ticket_id INT,
user_id INT,
pembelian_created_time DATETIME,
FOREIGN KEY (ticket_id) REFERENCES tickets(ticket_id),
FOREIGN KEY (user_id) REFERENCES users(user_ID) ON DELETE SET NULL
);
\ No newline at end of file
<?php
include 'connect.php';
try {
$db->exec("DROP TABLE IF EXISTS pembelian");
$db->exec("DROP TABLE IF EXISTS tickets");
$db->exec("DROP TABLE IF EXISTS events");
$db->exec("DROP TABLE IF EXISTS users");
// echo "Successfully reset the database<br/>";
} catch (PDOException $e) {
// echo "Error: " . $e->getMessage();
}
$db = null;
?>
\ No newline at end of file
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA]
php_value post_max_size 16M
php_value upload_max_filesize 16M
\ No newline at end of file
File moved