diff --git a/public/assets/scripts.js b/public/assets/scripts.js
index 013aa7d..5216633 100644
--- a/public/assets/scripts.js
+++ b/public/assets/scripts.js
@@ -11,8 +11,8 @@ function fileHelper(inputId, e)
const reader = new FileReader();
reader.onload = function(event) {
const base64String = event.target.result;
- //resizeImage(base64String, 512, 768, img => document.getElementById(inputId).value = img);
document.getElementById(inputId).value = base64String;
+ resizeAndPreview(inputId, base64String, 256, 384);
};
reader.readAsDataURL(file);
}
@@ -23,35 +23,45 @@ function fileHelper(inputId, e)
}
}
-function resizeImage(base64, maxWidth, maxHeight, callback)
-{
+function resizeAndPreview(input, base64, maxWidth, maxHeight, cb) {
const img = new Image();
img.src = base64;
img.onload = () => {
let width = img.width;
let height = img.height;
- if (width > height) {
- if (width > maxWidth) {
- height *= maxWidth / width;
- width = maxWidth;
- }
+ const imgAspectRatio = width / height;
+ const maxAspectRatio = maxWidth / maxHeight;
+
+ let newWidth, newHeight;
+
+ if (imgAspectRatio > maxAspectRatio) {
+ newWidth = maxWidth;
+ newHeight = maxWidth / imgAspectRatio;
} else {
- if (height > maxHeight) {
- width *= maxHeight / height;
- height = maxHeight;
- }
+ newHeight = maxHeight;
+ newWidth = maxHeight * imgAspectRatio;
}
const canvas = document.createElement('canvas');
- canvas.width = width;
- canvas.height = height;
+ canvas.width = maxWidth;
+ canvas.height = maxHeight;
const ctx = canvas.getContext('2d');
- ctx.drawImage(img, 0, 0, width, height);
+
+ ctx.fillStyle = 'black';
+ ctx.fillRect(0, 0, maxWidth, maxHeight);
+
+ const offsetX = (maxWidth - newWidth) / 2;
+ const offsetY = (maxHeight - newHeight) / 2;
+
+ ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight);
+
+
const resizedBase64 = canvas.toDataURL();
- console.log(resizedBase64)
- callback(resizedBase64);
- };
+ document.getElementById("preview-" + input).src=resizedBase64
+ document.getElementById(input).value = resizedBase64
+ cb(resizedBase64)
+ }
}
\ No newline at end of file
diff --git a/src/Controllers/DVD/DVDController.php b/src/Controllers/DVD/DVDController.php
new file mode 100644
index 0000000..3efcc07
--- /dev/null
+++ b/src/Controllers/DVD/DVDController.php
@@ -0,0 +1,22 @@
+dvd = $service->getLightModelById($id);
+
+ $view = new DVDView($data);
+ $view->render();
+ }
+}
\ No newline at end of file
diff --git a/src/Controllers/Manage/ManageDVDController.php b/src/Controllers/Manage/ManageDVDController.php
index 6e2c3c6..91a6857 100644
--- a/src/Controllers/Manage/ManageDVDController.php
+++ b/src/Controllers/Manage/ManageDVDController.php
@@ -4,23 +4,24 @@
{
use Controllers\BaseController;
- use Exception;
use Models\DVDModel;
- use Models\Exceptions\BadRouteException;
- use Models\Exceptions\RouteNotFoundException;
use Models\QueryModel\DVDQueryModel;
use Models\ViewModels\ManageDVDDetailViewModel;
use Models\ViewModels\ManageDVDDetailViewStateEnum;
use Models\ViewModels\ManageDVDListViewModel;
use Services\DVDService;
- use Utils\ImageUtils;
- use Utils\PHPUtils;
+ use Utils\JWTUtils;
use Views\Manage\DVD\Detail\ManageDVDDetailView;
use Views\Manage\DVD\List\ManageDVDListView;
class ManageDVDController extends BaseController
{
+ function __construct()
+ {
+ JWTUtils::isAuthorized(true);
+ }
+
public function get(int $id = null): void
{
if($id === null)
diff --git a/src/Controllers/Manage/ManageDashboardController.php b/src/Controllers/Manage/ManageDashboardController.php
index e6dc919..5133ddf 100644
--- a/src/Controllers/Manage/ManageDashboardController.php
+++ b/src/Controllers/Manage/ManageDashboardController.php
@@ -7,10 +7,16 @@
use Models\QueryModel\DVDQueryModel;
use Models\ViewModels\DashboardViewModel;
use Services\DVDService;
+ use Utils\JWTUtils;
use Views\Manage\Dashboard\DashboardView;
class ManageDashboardController extends BaseController
{
+ function __construct()
+ {
+ JWTUtils::isAuthorized(true);
+ }
+
public function get(): void
{
$viewModel = new DashboardViewModel();
diff --git a/src/Controllers/Manage/ManageOrderController.php b/src/Controllers/Manage/ManageOrderController.php
index 9e87746..0da7d0b 100644
--- a/src/Controllers/Manage/ManageOrderController.php
+++ b/src/Controllers/Manage/ManageOrderController.php
@@ -2,9 +2,15 @@
namespace Controllers\Manage
{
+
+ use Utils\JWTUtils;
+
class ManageOrderController
{
-
+ function __construct()
+ {
+ JWTUtils::isAuthorized(true);
+ }
}
}
diff --git a/src/Middlewares/Authentication.php b/src/Middlewares/Authentication.php
deleted file mode 100644
index 1bc0953..0000000
--- a/src/Middlewares/Authentication.php
+++ /dev/null
@@ -1,22 +0,0 @@
-isAdmin) && $jwt->isAdmin)) {
- // Redirect to an unauthorized page or show an error
- header('Location: /auth/error');
- exit;
- }
-}
\ No newline at end of file
diff --git a/src/Middlewares/Routing.php b/src/Middlewares/Routing.php
index b5110ba..8117425 100644
--- a/src/Middlewares/Routing.php
+++ b/src/Middlewares/Routing.php
@@ -7,6 +7,7 @@
use Controllers\Auth\LoginController;
use Controllers\Auth\LogoutController;
use Controllers\Auth\RegisterController;
+ use Controllers\DVD\DVDController;
use Controllers\Error\ErrorController;
use Controllers\Error\ErrorRouter;
use Controllers\Home\HomeController;
@@ -66,6 +67,9 @@ public function route(): void
},
"/manage/dvd" => function() {
return new ManageDVDController();
+ },
+ "/dvd" => function() {
+ return new DVDController();
}
);
diff --git a/src/Models/DVDLightModel.php b/src/Models/DVDLightModel.php
index 4825c0a..b76db4f 100644
--- a/src/Models/DVDLightModel.php
+++ b/src/Models/DVDLightModel.php
@@ -6,7 +6,9 @@ class DVDLightModel
{
public int $Id;
public ?string $LocalTitle;
+ public ?string $Synopsis;
public ?int $Notation;
+ public ?string $Note;
public ?string $Certification;
public ?bool $IsOffered;
public ?int $Quantity;
diff --git a/src/Models/ViewModels/DVDViewModel.php b/src/Models/ViewModels/DVDViewModel.php
new file mode 100644
index 0000000..53b05e6
--- /dev/null
+++ b/src/Models/ViewModels/DVDViewModel.php
@@ -0,0 +1,10 @@
+select(["Id", "LocalTitle", "Synopsis", "Notation", "Note", "Certification", "Quantity", "Price", "Year", "Image", "TypeId"])
+ ->from("dvds")
+ ->where("Id", "=", $id);
+
+ $query = $queryBuilder->getQuery();
+
+ $queryResult = $this->fetchStatement($query->sql, $query->params, DVDLightModel::class);
+
+ if($queryResult )
+ {
+ return $queryResult;
+ }
+
+ return null;
+ }
+
public function update(DVDModel $dvd)
{
$queryBuilder = (new UpdateQueryBuilder())
diff --git a/src/Utils/Components/FormImageComponent/FormImageComponent.template.php b/src/Utils/Components/FormImageComponent/FormImageComponent.template.php
index fcda37b..7ca9493 100644
--- a/src/Utils/Components/FormImageComponent/FormImageComponent.template.php
+++ b/src/Utils/Components/FormImageComponent/FormImageComponent.template.php
@@ -7,5 +7,5 @@
id="file-name; ?>"
required?"required":""; ?>
/>
-
-
\ No newline at end of file
+
+
diff --git a/src/Utils/JWTUtils.php b/src/Utils/JWTUtils.php
index 0065855..4faf3a3 100644
--- a/src/Utils/JWTUtils.php
+++ b/src/Utils/JWTUtils.php
@@ -119,6 +119,27 @@ public static function isValid(string $token): string
}
return true;
}
+
+ public static function isAuthorized($admin = false)
+ {
+ if (empty($_COOKIE['jwt'])) {
+ // Redirect to the login page if the user is not authenticated
+ http_response_code(401);
+ exit;
+ }
+
+ // Decode the JWT token to get user information
+ $jwt = JWTUtils::decode($_COOKIE['jwt']);
+
+ // If a specific role is required, check if the user has that role
+ if (!(isset($jwt) || !$jwt->isAdmin)) {
+ // Redirect to an unauthorized page or show an error
+ http_response_code(403);
+ exit;
+ }
+
+ return true;
+ }
}
}
diff --git a/src/Views/DVD/DVDView.js b/src/Views/DVD/DVDView.js
new file mode 100644
index 0000000..e69de29
diff --git a/src/Views/DVD/DVDView.php b/src/Views/DVD/DVDView.php
new file mode 100644
index 0000000..5b8550b
--- /dev/null
+++ b/src/Views/DVD/DVDView.php
@@ -0,0 +1,27 @@
+viewName="DVD/DVDView";
+ $this->subTitle="DVD";
+ $this->data = $viewModel;
+ }
+
+ public function render(): void
+ {
+ $layoutData = new LayoutViewModel();
+ $layoutData -> pageSubTitle = $this->subTitle;
+ parent::renderLayout($layoutData, $this->data);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Views/DVD/DVDView.style.css b/src/Views/DVD/DVDView.style.css
new file mode 100644
index 0000000..e69de29
diff --git a/src/Views/DVD/DVDView.template.php b/src/Views/DVD/DVDView.template.php
new file mode 100644
index 0000000..8acd8be
--- /dev/null
+++ b/src/Views/DVD/DVDView.template.php
@@ -0,0 +1,3 @@
+