Skip to content
Snippets Groups Projects
Commit f2cc912b authored by Kenneth Dave's avatar Kenneth Dave
Browse files

fix: audio & image insertion

parents 538d4fbb e782246c
Branches
Tags
No related merge requests found
<?php
class DotEnv
{
/**
* The directory where the .env file can be located.
*
* @var string
*/
protected $path;
public function __construct(string $path)
{
if(!file_exists($path)) {
throw new \InvalidArgumentException(sprintf('%s does not exist', $path));
}
$this->path = $path;
}
public function load() :void
{
if (!is_readable($this->path)) {
throw new \RuntimeException(sprintf('%s file is not readable', $this->path));
}
$lines = file($this->path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) {
continue;
}
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}
}
\ No newline at end of file
......@@ -66,8 +66,10 @@ class Admin extends Controller {
return new $model;
}
public function addBook(){
if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin' ){
public function addBook()
{
try {
if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Buat path image audio
......@@ -93,16 +95,21 @@ class Admin extends Controller {
$this->model('BookModel')->insertBook($newTitle, $newContent, $selectedAuthor, $selectedCategory, $fileAudio, $fileImage);
move_uploaded_file($fileTmpAudio, $audioFilePath);
move_uploaded_file($fileTmpImage, $imageFilePath);
} else {
throw new Exception("Invalid input data.");
}
}
$data['book'] = $this->model('BookModel')->getAllBookAdmin();
$data['author'] = $this->model('AuthorModel')->getAuthor();
$this->view('admin/bookadmin', $data);
} else {
$this->view('error/404');
throw new Exception("Unauthorized access.");
}
} catch (Exception $e) {
$error_message = $e->getMessage();
$this->view('error/403', ['error' => $error_message]);
}
}
public function addUser(){
if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin' ){
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
......@@ -137,11 +144,12 @@ class Admin extends Controller {
}
}
public function editBook(){
public function editBook()
{
try {
if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Buat path image audio
$imageDir = LOCALURL . "/img/";
$audioDir = LOCALURL . "/audio/";
......@@ -167,17 +175,22 @@ class Admin extends Controller {
$this->model('BookModel')->updateBook($bookid, $newTitle, $selectedAuthor, $newContent, $selectedCategory, $fileAudio, $fileImage);
move_uploaded_file($fileTmpAudio, $audioFilePath);
move_uploaded_file($fileTmpImage, $imageFilePath);
} else {
throw new Exception("Invalid input data.");
}
$data['book'] = $this->model('BookModel')->getAllBookAdmin();
$data['author'] = $this->model('AuthorModel')->getAuthor();
$this->view('admin/bookadmin', $data);
}
} else{
$this->view('error/404');
} else {
throw new Exception("Unauthorized access.");
}
} catch (Exception $e) {
$error_message = $e->getMessage();
$this->view('error/403', ['error' => $error_message]);
}
}
public function editUser(){
if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') {
......
<?php
// Define dynamic content
$pageTitle = "Popup Page";
$popupTitle = "POPUP";
$buttonText = "Click me";
$popupContentTitle = "Add Book";
$popupContentText = "Are you sure you want to add this book?";
$continueButtonText = "Continue";
$cancelButtonText = "Cancel";
$currentFileName = basename(__FILE__, '.php');
// Define CSS and JavaScript file names based on the current file
$cssFileName = $currentFileName . '.css';
$jsFileName = $currentFileName . '.js';
// Include the template
include('popupTemplate.php');
?>
<?php
// Define dynamic content
$pageTitle = "Popup Page";
$popupTitle = "POPUP";
$buttonText = "Click me";
$deletePopupContentTitle = "Delete Bookmark";
$deletePopupContentText = "Are you sure you want to delete this book?";
$continueButtonText = "Continue";
$cancelButtonText = "Cancel";
$currentFileName = basename(__FILE__, '.php');
// Define CSS and JavaScript file names based on the current file
$cssFileName = $currentFileName . '.css';
$jsFileName = $currentFileName . '.js';
// Include the template
include('popupTemplate.php');
?>
<?php
// Define dynamic content
$pageTitle = "Popup Page";
$popupTitle = "POPUP";
$buttonText = "Click me";
$editPopupContentTitle = "Edit Bookmark";
$editPopupContentText = "Are you sure you want to edit this bookmark?";
$continueButtonText = "Continue";
$cancelButtonText = "Cancel";
$currentFileName = basename(__FILE__, '.php');
// Define CSS and JavaScript file names based on the current file
$cssFileName = $currentFileName . '.css';
$jsFileName = $currentFileName . '.js';
// Include the template
include('popupTemplate.php');
?>
<?php
// Define dynamic content
$pageTitle = "Popup Page";
$popupTitle = "POPUP";
$buttonText = "Click me";
$editPopupContentTitle = "Edit Bookmark";
$editPopupContentText = "Are you sure you want to edit this bookmark?";
$deletePopupContentTitle = "Delete Bookmark";
$deletePopupContentText = "Are you sure you want to delete this book?";
$continueButtonText = "Continue";
$cancelButtonText = "Cancel";
$currentFileName = basename(__FILE__, '.php');
// Define CSS and JavaScript file names based on the current file
$cssFileName = '/var/www/html/public/style/popupEditDelete.css';
$jsFileName = '/var/www/html/public/js/popupEditDelete.js';
// Include the template
include('popupTemplateMulti.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="<?php echo $cssFileName; ?>">
<title><?php echo $pageTitle; ?></title>
</head>
<body>
<!-- Edit Popup -->
<div id="editPopup" class="popup">
<div class="popup-content">
<h1><?php echo $editPopupContentTitle; ?></h1>
<p><?php echo $editPopupContentText; ?></p><br>
<div class="button-container">
<button id="continueButtonEdit"><?php echo $continueButtonText; ?></button>
<button id="cancelButtonEdit"><?php echo $cancelButtonText; ?></button>
</div>
</div>
</div>
<!-- Delete Popup -->
<div id="deletePopup" class="popup">
<div class="popup-content">
<h1><?php echo $deletePopupContentTitle; ?></h1>
<p><?php echo $deletePopupContentText; ?></p><br>
<div class="button-container">
<button id="continueButtonDelete"><?php echo $continueButtonText; ?></button>
<button id="cancelButtonDelete"><?php echo $cancelButtonText; ?></button>
</div>
</div>
</div>
</body>
</html>
<?php
// Define dynamic content
$pageTitle = "Popup Page";
$popupTitle = "POPUP";
$buttonText = "Click me";
$popupContentTitle = "Update Book";
$popupContentText = "Are you sure you want to update this book?";
$continueButtonText = "Continue";
$cancelButtonText = "Cancel";
$currentFileName = basename(__FILE__, '.php');
// Define CSS and JavaScript file names based on the current file
$cssFileName = $currentFileName . '.css';
$jsFileName = $currentFileName . '.js';
// Include the template
include('popupTemplate.php');
?>
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