diff --git a/app/Client/pages/event/create.php b/app/Client/pages/event/create.php index 476cc49acfd78c636c3375dea324a3eb342b412c..b486caa397b265e68072d2f4b78ee48646346236 100644 --- a/app/Client/pages/event/create.php +++ b/app/Client/pages/event/create.php @@ -1,3 +1,24 @@ +<?php + 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> <html lang="en"> diff --git a/app/Client/pages/event/update.php b/app/Client/pages/event/update.php index 60eaff84d79cbae435db05388900d99a4643acdf..3d638008c04ae889ba49048259af52b843fa0c29 100644 --- a/app/Client/pages/event/update.php +++ b/app/Client/pages/event/update.php @@ -1,3 +1,24 @@ +<?php + 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> <html lang="en"> diff --git a/app/Server/Controllers/SubscriptionController.php b/app/Server/Controllers/SubscriptionController.php new file mode 100644 index 0000000000000000000000000000000000000000..b42c39a91d42425233b49e40080e6abfdba1e9af --- /dev/null +++ b/app/Server/Controllers/SubscriptionController.php @@ -0,0 +1,25 @@ +<?php +ob_start(); +require_once(__DIR__ . '/../Models/Subscription.php'); + + +class SubscriptionController { + private $subscriptionModel; + + public function __construct() { + $this->subscriptionModel = new SubscriptionModel(); + } + + public function createSubscription($creator_id, $subscriber_id, $creator_name) { + return $this->subscriptionModel->createSubscription($creator_id, $subscriber_id, $creator_name); + } + + public function getSubscription($subscriber_id) { + return $this->subscriptionModel->getSubscription($subscriber_id); + } + + public function updateSubscription($creator_id, $subscriber_id, $status) { + return $this->subscriptionModel->updateSubscription($creator_id, $subscriber_id, $status); + } +} +?> \ No newline at end of file diff --git a/app/Server/Models/Subscription.php b/app/Server/Models/Subscription.php new file mode 100644 index 0000000000000000000000000000000000000000..46dcabc8b0770086e43d488ef5364d90d0f1b21f --- /dev/null +++ b/app/Server/Models/Subscription.php @@ -0,0 +1,32 @@ +<?php + require_once(__DIR__ . '/../../db/connect.php'); + + class SubscriptionModel { + public function createSubscription($creator_id, $subscriber_id, $creator_name) { + global $db; + + $stmt = $db->prepare("INSERT INTO subscription (creator_id, subscriber_id, creator_name) VALUES (?, ?, ?)"); + if ($stmt->execute([$creator_id, $subscriber_id, $creator_name])) { + return "Subscription created successfully"; + } + } + + public function getSubscription($subscriber_id) { + global $db; + + $stmt = $db->prepare("SELECT * FROM subscription WHERE subscriber_id = ?"); + $stmt->execute([$subscriber_id]); + + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } + + public function updateSubscription($creator_id, $subscriber_id, $status) { + global $db; + + $stmt = $db->prepare("UPDATE subscription SET status = ? WHERE creator_id = ? AND subscriber_id = ?"); + if ($stmt->execute([$status, $creator_id, $subscriber_id])) { + return "Subscription updated successfully"; + } + } + } +?> \ No newline at end of file diff --git a/db/init.sql b/db/init.sql index 2260e6011f4701b1ec4506bee5c96de4a4b8e595..0beaedfc29604f9454f333b3a4411b5108553768 100644 --- a/db/init.sql +++ b/db/init.sql @@ -36,4 +36,13 @@ CREATE TABLE IF NOT EXISTS pembelian ( pembelian_created_time DATETIME, 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 enum('PENDING','ACCEPTED','REJECTED') NOT NULL DEFAULT 'PENDING', + creator_name char(255) NOT NULL, + PRIMARY KEY (creator_id, subscriber_id), + FOREIGN KEY (subscriber_id) REFERENCES users(user_ID) ON DELETE CASCADE ); \ No newline at end of file