diff --git a/app/models/anime.php b/app/models/anime.php index 86be0a46df9e72d822504f34134d9c727dd8d7af..e9bc701fb0f3e4624181f8af6f53757eb47c1f7c 100644 --- a/app/models/anime.php +++ b/app/models/anime.php @@ -13,7 +13,7 @@ class Anime { } public function getAllAnime(){ - $this->db->query('SELECT * FROM ' . $this->table); + $this->db->query('SELECT * FROM ' . $this->table . ' ORDER BY anime_id'); return $this->db->fetchAllData(); } @@ -50,7 +50,7 @@ class Anime { foreach($data as $key => $value){ $data[$key] = $this->db->processDataType($value); } - $this->db->query('UPDATE ' . $this->table . 'SET title = '.$data['title'].', type = '.$data['type'].', status = '.$data['status'].', release_date = '.$data['release_date'].', episodes = '.$data['episodes'].', rating = '.$data['rating'].', score = '.$data['score'].', image = '.$data['image'].', trailer = '.$data['trailer'].', synopsis = '.$data['synopsis'].', studio_id = '.$data['studio_id'].' WHERE anime_id = '. $data['anime_id']); + $this->db->query('UPDATE ' . $this->table . ' SET title = '.$data['title'].', type = '.$data['type'].', status = '.$data['status'].', release_date = '.$data['release_date'].', episodes = '.$data['episodes'].', rating = '.$data['rating'].', score = '.$data['score'].', image = '.$data['image'].', trailer = '.$data['trailer'].', synopsis = '.$data['synopsis'].', studio_id = '.$data['studio_id'].' WHERE anime_id = '. $data['anime_id']); $this->db->execute(); return ($this->db->countRow() != 0); // if countRow == 0, query fails diff --git a/app/models/client.php b/app/models/client.php index d90eb0c0e51000aa2e0b24124de46ee3ca652bb9..703b2f840726c895ede4cb436a84820c27b3f8dd 100644 --- a/app/models/client.php +++ b/app/models/client.php @@ -13,7 +13,7 @@ class Client { } public function getAllClient(){ - $this->db->query('SELECT * FROM ' . $this->table); + $this->db->query('SELECT * FROM ' . $this->table . ' ORDER BY client_id'); return $this->db->fetchAllData(); } @@ -49,7 +49,7 @@ class Client { foreach($data as $key => $value){ $data[$key] = $this->db->processDataType($value); } - $this->db->query('UPDATE ' . $this->table . 'SET username = '.$data['username'].', email = '.$data['email'].', password = '.$data['password'].', admin_status = '.$data['admin_status'].', birthdate = '.$data['birthdate'].', bio = '.$data['bio'].', image = '.$data['image'].' WHERE client_id = '. $data['client_id']); + $this->db->query('UPDATE ' . $this->table . ' SET username = '.$data['username'].', email = '.$data['email'].', password = '.$data['password'].', admin_status = '.$data['admin_status'].', birthdate = '.$data['birthdate'].', bio = '.$data['bio'].', image = '.$data['image'].' WHERE client_id = '. $data['client_id']); $this->db->execute(); return ($this->db->countRow() != 0); // if countRow == 0, query fails diff --git a/app/models/studio.php b/app/models/studio.php index 65d68d9863ce3e218a6315a3c0af20ec7034673d..f2228b7ca57732d3ea8df4ddfc0bd9170c48fdaf 100644 --- a/app/models/studio.php +++ b/app/models/studio.php @@ -13,7 +13,7 @@ class Studio { } public function getAllStudio(){ - $this->db->query('SELECT * FROM '.$this->table); + $this->db->query('SELECT * FROM '.$this->table.' ORDER BY studio_id'); return $this->db->fetchAllData(); } @@ -34,14 +34,26 @@ class Studio { public function updateStudio($data){ foreach($data as $key => $value){ - $data[$key] = $this->db->processDataType($value); + $data[$key] = $this->db->processDataType($value); } - $this->db->query('UPDATE ' . $this->table . 'SET name = '.$data['name'].', description = '.$data['description'].', established_date = '.$data['established_date'].', image = '.$data['image'].' WHERE studio_id = '. $data['studio_id']); + + // Note: No single quotes around the values because processDataType is already adding them + $this->db->query( + 'UPDATE ' . $this->table . ' SET name = ' . $data['name'] . ', + description = ' . $data['description'] . ', + established_date = ' . $data['established_date'] . ', + image = ' . $data['image'] . ' + WHERE studio_id = ' . $data['studio_id'] + ); + $this->db->execute(); + return ($this->db->countRow() != 0); // if countRow == 0, query fails } + + public function deleteStudio($id){ $this->db->query('DELETE FROM ' . $this->table . ' WHERE studio_id = '. $id); $this->db->execute(); diff --git a/app/public/actions/addAnime.php b/app/public/actions/addAnime.php new file mode 100644 index 0000000000000000000000000000000000000000..097e92481721eec64ff04d13300d6e1be737ba20 --- /dev/null +++ b/app/public/actions/addAnime.php @@ -0,0 +1,123 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Anime.php'); + +$a = new Anime(); + +// Check if form data is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $data = [ + 'title' => $_POST['title'], + 'type' => $_POST['type'], + 'status' => $_POST['status'], + 'rating' => $_POST['rating'], + 'studio_id' => $_POST['studio_id'], + 'score' => null + ]; + + // Check if release_date is set and not empty + if (isset($_POST['release_date']) && !empty($_POST['release_date'])) { + $data['release_date'] = $_POST['release_date']; + } else { + $data['release_date'] = null; + } + + if (isset($_POST['episodes'])) { + $data['episodes'] = $_POST['episodes']; + } else { + $data['episodes'] = null; + } + + // Check if an image is uploaded + if (isset($_FILES['image']['name']) && $_FILES['image']['error'] == 0) { + // Define directory where the image will be stored + $target_dir = BASE_DIR . "/public/img/anime/"; // Ensure this directory exists and has proper permissions + $target_file = $target_dir . basename($_FILES['image']['name']); + + // Check file size (for example, limit to 5MB) + if ($_FILES['image']['size'] > 5000000) { + die("Sorry, your file is too large."); + } + + // Check if the file is an actual image + $check = getimagesize($_FILES['image']['tmp_name']); + if ($check === false) { + die("File is not an image."); + } + + // Only allow certain file formats (JPEG and PNG in this case) + $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") { + die("Sorry, only JPG, JPEG, and PNG files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) { + $data['image'] = str_replace(BASE_DIR, "", $target_file);; // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $data['image'] = null; + } + + if (isset($_FILES['trailer']['name']) && $_FILES['trailer']['error'] == 0) { + // Define directory where the trailer will be stored + $target_dir = BASE_DIR . "/public/vid/"; // Ensure this directory exists and is writable + $target_file = $target_dir . basename($_FILES['trailer']['name']); + + // Check file size (for example, limit to 50MB) + if ($_FILES['trailer']['size'] > 50000000) { + die("Sorry, your file is too large."); + } + + // Only allow certain file formats (MP4 in this case) + $videoFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($videoFileType != "mp4") { + die("Sorry, only MP4 files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['trailer']['tmp_name'], $target_file)) { + $data['trailer'] = str_replace(BASE_DIR, "", $target_file); // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $data['trailer'] = null; + } + + + if (isset($_POST['synopsis'])) { + $data['synopsis'] = $_POST['synopsis']; + } else { + $data['synopsis'] = null; + } + + $result = $a->insertAnime($data); + + if ($result) { + header("Location: /?admin"); + exit(); + } else { + echo "Failed to add anime. Please try again."; + } +} diff --git a/app/public/actions/addClient.php b/app/public/actions/addClient.php new file mode 100644 index 0000000000000000000000000000000000000000..91428e5609f475e68a0137b230732adc8f8fbc7c --- /dev/null +++ b/app/public/actions/addClient.php @@ -0,0 +1,96 @@ +<?php +session_start(); + +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Client.php'); + +$c = new Client(); + +// Check if form data is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $data = [ + 'username' => $_POST['username'], + 'email' => $_POST['email'], + 'password' => $_POST['password'], + 'admin_status' => $_POST['admin_status'] == "true" ? true : false + ]; + + // Check if birthdate is set and not empty + if (isset($_POST['birthdate']) && !empty($_POST['birthdate'])) { + $data['birthdate'] = $_POST['birthdate']; + } else { + $data['birthdate'] = null; + } + + // Check if bio is set + if (isset($_POST['bio'])) { + $data['bio'] = $_POST['bio']; + } else { + $data['bio'] = null; + } + + // Check if an image is uploaded + if (isset($_FILES['image']['name']) && $_FILES['image']['error'] == 0) { + // Define directory where the image will be stored + $target_dir = BASE_DIR . "/public/img/client/"; // Ensure this directory exists and has proper permissions + $target_file = $target_dir . basename($_FILES['image']['name']); + + // Check file size (for example, limit to 5MB) + if ($_FILES['image']['size'] > 5000000) { + die("Sorry, your file is too large."); + } + + // Check if the file is an actual image + $check = getimagesize($_FILES['image']['tmp_name']); + if ($check === false) { + die("File is not an image."); + } + + // Only allow certain file formats (JPEG and PNG in this case) + $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") { + die("Sorry, only JPG, JPEG, and PNG files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) { + $data['image'] = str_replace(BASE_DIR, "", $target_file);; // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $data['image'] = null; + } + + // Call the insertClient method + + if ($c->getClientByUsername($data['username'])) { + $_SESSION['error_message'] = "Username already exists!"; + header("Location: /?admin"); + exit(); + } elseif ($c->getClientByEmail($data['email'])) { + $_SESSION['error_message'] = "Email already exists!"; + header("Location: /?admin"); + exit(); + } else { + $result = $c->insertClient($data); + + if ($result) { + header("Location: /?admin"); + exit(); + } else { + $_SESSION['error_message'] = "Failed to add client"; + header("Location: /?admin"); + exit(); + } + } +} diff --git a/app/public/actions/addStudio.php b/app/public/actions/addStudio.php new file mode 100644 index 0000000000000000000000000000000000000000..c658cf53f705629c9f767ca12cd46447938542e1 --- /dev/null +++ b/app/public/actions/addStudio.php @@ -0,0 +1,79 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Studio.php'); + +$s = new Studio(); + +// Check if form data is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $data = [ + 'name' => $_POST['name'] + ]; + + // Check if established_date is set and not empty + if (isset($_POST['established_date']) && !empty($_POST['established_date'])) { + $data['established_date'] = $_POST['established_date']; + } else { + $data['established_date'] = null; + } + + // Check if description is set + if (isset($_POST['description'])) { + $data['description'] = $_POST['description']; + } else { + $data['description'] = null; + } + + // Check if an image is uploaded + if (isset($_FILES['image']['name']) && $_FILES['image']['error'] == 0) { + // Define directory where the image will be stored + $target_dir = BASE_DIR . "/public/img/studio/"; // Ensure this directory exists and has proper permissions + $target_file = $target_dir . basename($_FILES['image']['name']); + + // Check file size (for example, limit to 5MB) + if ($_FILES['image']['size'] > 5000000) { + die("Sorry, your file is too large."); + } + + // Check if the file is an actual image + $check = getimagesize($_FILES['image']['tmp_name']); + if ($check === false) { + die("File is not an image."); + } + + // Only allow certain file formats (JPEG and PNG in this case) + $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") { + die("Sorry, only JPG, JPEG, and PNG files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) { + $data['image'] = str_replace(BASE_DIR, "", $target_file);; // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $data['image'] = null; + } + + + // Call the insertClient method + $result = $s->insertStudio($data); + + if ($result) { + header("Location: /?admin"); + exit(); + } else { + echo "Failed to add studio. Please try again."; + } +} diff --git a/app/public/actions/deleteAnime.php b/app/public/actions/deleteAnime.php new file mode 100644 index 0000000000000000000000000000000000000000..b4ad2695ece07f2da61a9e120f6073510d7eb681 --- /dev/null +++ b/app/public/actions/deleteAnime.php @@ -0,0 +1,16 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Anime.php'); + +if (isset($_GET['id'])) { + $id = $_GET['id']; + + $a = new Anime(); + + if ($a->deleteAnime($id)) { + header('Location: /?admin?message=Deleted successfully'); + } else { + header('Location: /?admin?error=Failed to delete'); + } +} +?> diff --git a/app/public/actions/deleteClient.php b/app/public/actions/deleteClient.php new file mode 100644 index 0000000000000000000000000000000000000000..9bb902d71d074a4a5af95315686a7b275944add2 --- /dev/null +++ b/app/public/actions/deleteClient.php @@ -0,0 +1,16 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Client.php'); + +if (isset($_GET['id'])) { + $id = $_GET['id']; + + $c = new Client(); + + if ($c->deleteClient($id)) { + header('Location: /?admin?message=Deleted successfully'); + } else { + header('Location: /?admin?error=Failed to delete'); + } +} +?> diff --git a/app/public/actions/deleteStudio.php b/app/public/actions/deleteStudio.php new file mode 100644 index 0000000000000000000000000000000000000000..1d70e538e3cafc2923660bf9a588e2a401f4b249 --- /dev/null +++ b/app/public/actions/deleteStudio.php @@ -0,0 +1,16 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Studio.php'); + +if (isset($_GET['id'])) { + $id = $_GET['id']; + + $s = new Studio(); + + if ($s->deleteStudio($id)) { + header('Location: /?admin?message=Deleted successfully'); + } else { + header('Location: /?admin?error=Failed to delete'); + } +} +?> diff --git a/app/public/actions/editAnime.php b/app/public/actions/editAnime.php new file mode 100644 index 0000000000000000000000000000000000000000..a913f70eeed58927d0a43b7e7c6c4985bd2f7207 --- /dev/null +++ b/app/public/actions/editAnime.php @@ -0,0 +1,147 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Anime.php'); + +$a = new Anime(); + +// Check if form data is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + if (!isset($_POST['anime_id']) || empty($_POST['anime_id'])) { + echo "No anime ID provided. Cannot proceed with edit."; + exit(); + } + $data = [ + 'anime_id' => $_POST['anime_id'], + 'title' => $_POST['title'], + 'type' => $_POST['type'], + 'status' => $_POST['status'], + 'rating' => $_POST['rating'], + 'studio_id' => $_POST['studio_id'], + 'score' => null + ]; + + // Check if release_date is set and not empty + if (isset($_POST['release_date']) && !empty($_POST['release_date'])) { + $data['release_date'] = $_POST['release_date']; + } else { + $data['release_date'] = null; + } + + if (isset($_POST['episodes'])) { + $data['episodes'] = $_POST['episodes']; + } else { + $data['episodes'] = null; + } + + if (isset($_POST['synopsis'])) { + $data['synopsis'] = $_POST['synopsis']; + } else { + $data['synopsis'] = null; + } + + if (isset($_FILES['newImage']['name']) && $_FILES['newImage']['error'] == 0) { + // Define directory where the image will be stored + $target_dir = BASE_DIR . "/public/img/anime/"; // Ensure this directory exists and has proper permissions + $target_file = $target_dir . basename($_FILES['newImage']['name']); + + // Check file size (for example, limit to 5MB) + if ($_FILES['newImage']['size'] > 5000000) { + die("Sorry, your file is too large."); + } + + // Check if the file is an actual image + $check = getimagesize($_FILES['newImage']['tmp_name']); + if ($check === false) { + die("File is not an image."); + } + + // Only allow certain file formats (JPEG and PNG in this case) + $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") { + die("Sorry, only JPG, JPEG, and PNG files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['newImage']['tmp_name'], $target_file)) { + $data['image'] = str_replace(BASE_DIR, "", $target_file);; // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $animeId = $_POST['anime_id']; + $result = $a->getAnimeByID($animeId); + + if ($result) { + $data['image'] = $result['image']; + } else { + // Optionally handle the case where no existing image path is found. + // $data['image'] = 'default/path/for/no/image.jpg'; + // Or leave it as null if your application logic handles that case: + $data['image'] = null; + } + } + + if (isset($_FILES['newTrailer']['name']) && $_FILES['newTrailer']['error'] == 0) { + // Define directory where the trailer will be stored + $target_dir = BASE_DIR . "/public/vid/"; // Ensure this directory exists and is writable + $target_file = $target_dir . basename($_FILES['newTrailer']['name']); + + // Check file size (for example, limit to 50MB) + if ($_FILES['newTrailer']['size'] > 50000000) { + die("Sorry, your file is too large."); + } + + // Only allow certain file formats (MP4 in this case) + $videoFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($videoFileType != "mp4") { + die("Sorry, only MP4 files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['newTrailer']['tmp_name'], $target_file)) { + $data['trailer'] = str_replace(BASE_DIR, "", $target_file); // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $animeId = $_POST['anime_id']; + $result = $a->getAnimeByID($animeId); + + if ($result) { + $data['trailer'] = $result['trailer']; + } else { + // Optionally handle the case where no existing image path is found. + // $data['image'] = 'default/path/for/no/image.jpg'; + // Or leave it as null if your application logic handles that case: + $data['trailer'] = null; + } + } + + // Call the updateclient method + $result = $a->updateAnime($data); + + if ($result) { + header("Location: /?admin"); + exit(); + } else { + echo "Failed to edit anime. Please try again."; + } +} diff --git a/app/public/actions/editClient.php b/app/public/actions/editClient.php new file mode 100644 index 0000000000000000000000000000000000000000..a71d2ad858e817a6f933c030d6243291a8addf1f --- /dev/null +++ b/app/public/actions/editClient.php @@ -0,0 +1,97 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Client.php'); + +$c = new Client(); + +// Check if form data is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + // Assuming client_id is passed along in the form to identify which client to edit + if (!isset($_POST['client_id']) || empty($_POST['client_id'])) { + echo "No client ID provided. Cannot proceed with edit."; + exit(); + } + $data = [ + 'client_id' => $_POST['client_id'], + 'username' => $_POST['username'], + 'email' => $_POST['email'], + 'password' => $_POST['password'], + 'admin_status' => $_POST['admin_status'] == "true" ? true : false + ]; + + // Check if birthdate is set and not empty + if (isset($_POST['birthdate']) && !empty($_POST['birthdate'])) { + $data['birthdate'] = $_POST['birthdate']; + } else { + $data['birthdate'] = null; + } + + // Check if bio is set + if (isset($_POST['bio'])) { + $data['bio'] = $_POST['bio']; + } else { + $data['bio'] = null; + } + + // Check if an image is uploaded + if (isset($_FILES['newImage']['name']) && $_FILES['newImage']['error'] == 0) { + // Define directory where the image will be stored + $target_dir = BASE_DIR . "/public/img/client/"; // Ensure this directory exists and has proper permissions + $target_file = $target_dir . basename($_FILES['newImage']['name']); + + // Check file size (for example, limit to 5MB) + if ($_FILES['newImage']['size'] > 5000000) { + die("Sorry, your file is too large."); + } + + // Check if the file is an actual image + $check = getimagesize($_FILES['newImage']['tmp_name']); + if ($check === false) { + die("File is not an image."); + } + + // Only allow certain file formats (JPEG and PNG in this case) + $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") { + die("Sorry, only JPG, JPEG, and PNG files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['newImage']['tmp_name'], $target_file)) { + $data['image'] = str_replace(BASE_DIR, "", $target_file);; // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $clientId = $_POST['client_id']; + $result = $c->getClientByID($clientId); + + if ($result) { + $data['image'] = $result['image']; + } else { + // Optionally handle the case where no existing image path is found. + // $data['image'] = 'default/path/for/no/image.jpg'; + // Or leave it as null if your application logic handles that case: + $data['image'] = null; + } + } + + // Call the updateclient method + $result = $c->updateClient($data); + + if ($result) { + header("Location: /?admin"); + exit(); + } else { + echo "Failed to edit client. Please try again."; + } +} diff --git a/app/public/actions/editStudio.php b/app/public/actions/editStudio.php new file mode 100644 index 0000000000000000000000000000000000000000..8dbb9405dc23fdc03075ca29ff878bc0677d4ed8 --- /dev/null +++ b/app/public/actions/editStudio.php @@ -0,0 +1,94 @@ +<?php +require_once(dirname(__DIR__,2).'/define.php'); +require_once(BASE_DIR.'/models/Studio.php'); + +$s = new Studio(); + +// Check if form data is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + // Assuming studio_id is passed along in the form to identify which studio to edit + if (!isset($_POST['studio_id']) || empty($_POST['studio_id'])) { + echo "No studio ID provided. Cannot proceed with edit."; + exit(); + } + $data = [ + 'studio_id' => $_POST['studio_id'], + 'name' => $_POST['name'] + ]; + + // Check if established_date is set and not empty + if (isset($_POST['established_date']) && !empty($_POST['established_date'])) { + $data['established_date'] = $_POST['established_date']; + } else { + $data['established_date'] = null; + } + + // Check if description is set + if (isset($_POST['description'])) { + $data['description'] = $_POST['description']; + } else { + $data['description'] = null; + } + + // Check if an image is uploaded + if (isset($_FILES['newImage']['name']) && $_FILES['newImage']['error'] == 0) { + // Define directory where the image will be stored + $target_dir = BASE_DIR . "/public/img/studio/"; // Ensure this directory exists and has proper permissions + $target_file = $target_dir . basename($_FILES['newImage']['name']); + + // Check file size (for example, limit to 5MB) + if ($_FILES['newImage']['size'] > 5000000) { + die("Sorry, your file is too large."); + } + + // Check if the file is an actual image + $check = getimagesize($_FILES['newImage']['tmp_name']); + if ($check === false) { + die("File is not an image."); + } + + // Only allow certain file formats (JPEG and PNG in this case) + $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); + if ($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") { + die("Sorry, only JPG, JPEG, and PNG files are allowed."); + } + + // Check if file already exists, if so, append a number + $original_name = $target_file; + $counter = 1; + while (file_exists($target_file)) { + $info = pathinfo($original_name); + $target_file = $info['dirname'] . '/' . $info['filename'] . '_' . $counter . '.' . $info['extension']; + $counter++; + } + + // Try to move the uploaded file to the target directory + if (move_uploaded_file($_FILES['newImage']['tmp_name'], $target_file)) { + $data['image'] = str_replace(BASE_DIR, "", $target_file);; // Save the path relative to your server root in the database + } else { + die("There was an error uploading your file."); + } + } else { + $studioId = $_POST['studio_id']; + $result = $s->getStudioByID($studioId); + + if ($result) { + $data['image'] = $result['image']; + } else { + // Optionally handle the case where no existing image path is found. + // $data['image'] = 'default/path/for/no/image.jpg'; + // Or leave it as null if your application logic handles that case: + $data['image'] = null; + } + } + + // Call the updateStudio method + $result = $s->updateStudio($data); + + if ($result) { + header("Location: /?admin"); + exit(); + } else { + echo "Failed to edit studio. Please try again."; + } +} diff --git a/app/public/handler/admin.js b/app/public/handler/admin.js index 8a37895f2f7937ef06f382da0f5e444da457262e..78c6edb798fc52c62c4c96686135e6cb7ea7533d 100644 --- a/app/public/handler/admin.js +++ b/app/public/handler/admin.js @@ -18,3 +18,229 @@ function showTable(tableId) { const activeMenu = Array.from(menuItems).find(item => item.getAttribute('onclick').includes(tableId)); activeMenu.classList.add('active'); } + +document.addEventListener('DOMContentLoaded', function() { + document.querySelectorAll('.delete-btn-client').forEach(function(button) { + button.addEventListener('click', function(e) { + e.preventDefault(); + + let clientId = e.target.getAttribute('client-id'); + + if (confirm('Are you sure you want to delete this client?')) { + window.location.href = `/public/actions/deleteClient.php?id=${clientId}`; + } + }); + }); +}); + +document.addEventListener('DOMContentLoaded', function() { + document.querySelectorAll('.delete-btn-anime').forEach(function(button) { + button.addEventListener('click', function(e) { + e.preventDefault(); + + let animeId = e.target.getAttribute('anime-id'); + + if (confirm('Are you sure you want to delete this anime?')) { + window.location.href = `/public/actions/deleteAnime.php?id=${animeId}`; + } + }); + }); +}); + +document.addEventListener('DOMContentLoaded', function() { + document.querySelectorAll('.delete-btn-studio').forEach(function(button) { + button.addEventListener('click', function(e) { + e.preventDefault(); + + let studioId = e.target.getAttribute('studio-id'); + + if (confirm('Are you sure you want to delete this studio?')) { + window.location.href = `/public/actions/deleteStudio.php?id=${studioId}`; + } + }); + }); +}); + +let activeMenuItem = 'client'; + +// Function to set the active menu item +function setActiveMenuItem(menuItem) { + activeMenuItem = menuItem; +} + +function openAddModal() { + if (activeMenuItem === 'client') { + document.getElementById('addClientModal').style.display = 'block'; + } else if (activeMenuItem === 'anime') { + document.getElementById('addAnimeModal').style.display = 'block'; + } else if (activeMenuItem === 'studio') { + document.getElementById('addStudioModal').style.display = 'block'; + } +} + +function closeAddModal() { + if (activeMenuItem === 'client') { + document.getElementById('addClientModal').style.display = 'none'; + } else if (activeMenuItem === 'anime') { + document.getElementById('addAnimeModal').style.display = 'none'; + } else if (activeMenuItem === 'studio') { + document.getElementById('addStudioModal').style.display = 'none'; + } +} + +function openUpdateModal() { + if (activeMenuItem === 'client') { + document.getElementById('updateClientModal').style.display = 'block'; + } else if (activeMenuItem === 'anime') { + document.getElementById('updateAnimeModal').style.display = 'block'; + } else if (activeMenuItem === 'studio') { + document.getElementById('editStudioModal').style.display = 'block'; + } +} + +function closeUpdateModal() { + if (activeMenuItem === 'client') { + document.getElementById('updateClientModal').style.display = 'none'; + } else if (activeMenuItem === 'anime') { + document.getElementById('updateAnimeModal').style.display = 'none'; + } else if (activeMenuItem === 'studio') { + document.getElementById('updateStudioModal').style.display = 'none'; + } +} + +function openEditStudioModal(button) { + // Extract data from the button's data attributes. + const studioId = button.getAttribute('data-studio-id'); + const name = button.getAttribute('data-name'); + const description = button.getAttribute('data-description'); + const establishedDate = button.getAttribute('data-established-date'); + const imagePath = button.getAttribute('data-image'); + + if (establishedDate) { + document.getElementById('editEstablishedDate').value = establishedDate; + } else { + document.getElementById('editEstablishedDate').value = null; + } + + // Populate the modal's fields with the extracted data. + document.getElementById('editStudioId').value = studioId; + document.getElementById('editName').value = name; + document.getElementById('editDescription').innerText = description; + + const imageElement = document.getElementById('currentStudioImage'); + if(imagePath) { + imageElement.src = imagePath; + imageElement.alt = "Current Image"; + imageElement.style.display = ""; // show image + } else { + imageElement.style.display = "none"; // hide image + } + + // Display the modal. + const modal = document.getElementById('editStudioModal'); + modal.style.display = 'block'; +} + +function closeEditStudioModal() { + const modal = document.getElementById('editStudioModal'); + modal.style.display = 'none'; +} + +function openEditClientModal(button) { + const clientId = button.getAttribute('data-client-id'); + const username = button.getAttribute('data-username'); + const email = button.getAttribute('data-email'); + const password = button.getAttribute('data-password'); + const admin_status = button.getAttribute('data-admin-status'); + const birthdate = button.getAttribute('data-birthdate'); + const bio = button.getAttribute('data-bio'); + const imagePath = button.getAttribute('data-image'); + + + // Populate the modal's fields with the extracted data + document.getElementById('editClientId').value = clientId; + document.getElementById('editUsername').value = username; + document.getElementById('editEmail').value = email; + document.getElementById('editPassword').value = password; + document.getElementById('editAdminStatus').value = admin_status; + document.getElementById('editBio').value = bio; + + const imageElement = document.getElementById('currentImage'); + if(imagePath) { + imageElement.src = imagePath; + imageElement.alt = "Current Image"; + imageElement.style.display = ""; // show image + } else { + imageElement.style.display = "none"; // hide image + } + + + if (birthdate) { + document.getElementById('editBirthdate').value = birthdate; + } else { + document.getElementById('editBirthdate').value = null; + } + + // Display the modal + const modal = document.getElementById('editClientModal'); + modal.style.display = 'block'; +} + +function closeEditClientModal() { + const modal = document.getElementById('editClientModal'); + modal.style.display = 'none'; +} + +function openEditAnimeModal(button) { + // Get attributes from the button + const animeId = button.getAttribute('data-anime-id'); + const title = button.getAttribute('data-title'); + const type = button.getAttribute('data-type'); + const status = button.getAttribute('data-status'); + const release_date = button.getAttribute('data-release_date'); + const episodes = button.getAttribute('data-episodes'); + const rating = button.getAttribute('data-rating'); + const imagePath = button.getAttribute('data-image'); + const trailerPath = button.getAttribute('data-trailer'); + const synopsis = button.getAttribute('data-synopsis'); + const studio_id = button.getAttribute('data-studio-id'); + + // Populate the modal's fields with the extracted data + document.getElementById('editAnimeId').value = animeId; + document.getElementById('editTitle').value = title; + document.getElementById('editType').value = type; + document.getElementById('editStatus').value = status; + document.getElementById('editRelease_date').value = release_date; + document.getElementById('editEpisodes').value = episodes; + document.getElementById('editRating').value = rating; + + const imageElement = document.getElementById('currentAnimeImage'); + if(imagePath) { + imageElement.src = imagePath; + imageElement.alt = "Current Image"; + imageElement.style.display = ""; // show image + } else { + imageElement.style.display = "none"; // hide image + } + + const trailerElement = document.getElementById('currentTrailer'); + if(trailerPath) { + trailerElement.src = trailerPath; + trailerElement.alt = "Current Trailer"; + trailerElement.style.display = ""; + } else { + trailerElement.style.display = "none"; + } + + document.getElementById('editSynopsis').value = synopsis; + document.getElementById('editStudio_id').value = studio_id; + + // Display the modal + const modal = document.getElementById('editAnimeModal'); + modal.style.display = 'block'; +} + +function closeEditAnimeModal() { + const modal = document.getElementById('editAnimeModal'); + modal.style.display = 'none'; +} diff --git a/app/public/style/admin.css b/app/public/style/admin.css index c49cde119996ea25439096f532a448310207dd7d..2f5e74286607dd64fe7e2f6360f6794e0242f8c7 100644 --- a/app/public/style/admin.css +++ b/app/public/style/admin.css @@ -64,19 +64,25 @@ th, td { text-align: left; } -.actions { - min-width: 118px; -} th { background-color: #f5f5f5; } -.edit-btn, .delete-btn { +.btn-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + height: 100%; /* Take the full height of the cell */ +} + +.edit-btn, .delete-btn-client, .delete-btn-anime, .delete-btn-studio { padding: 5px 10px; - margin-right: 5px; + margin-bottom: 5px; /* Add space between buttons */ border: none; cursor: pointer; + width: 100%; /* Optional: to make buttons the same width */ } .edit-btn { @@ -84,11 +90,12 @@ th { color: white; } -.delete-btn { +.delete-btn-client, .delete-btn-anime, .delete-btn-studio { background-color: #f44336; /* Red */ color: white; } + /* ... Your previous styles ... */ .table { @@ -121,4 +128,55 @@ th { .add-btn:hover { background-color: #45a049; /* Slightly darker green for hover effect */ -} \ No newline at end of file +} + +.modal { + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0,0,0,0.4); +} + +.modal-content { + background-color: #fefefe; + margin: 15% auto; + padding: 20px; + border: 1px solid #888; + width: 50%; +} + +.close-btn { + color: #fefefe; + float: right; + font-size: 28px; + font-weight: bold; + cursor: pointer; +} + +.close-btn:hover, .close-btn:focus { + color: black; + text-decoration: none; + cursor: pointer; +} + +.form-vertical { + display: flex; + flex-direction: column; + gap: 10px; /* Provides space between each item */ + width: 45%px; /* Adjust based on your preference */ +} + +.checkbox-container { + display: flex; + align-items: center; /* Vertically centers checkbox with label */ + gap: 5px; /* Space between checkbox and label */ +} + +label[for="admin"] { + cursor: pointer; +} diff --git a/app/views/Admin/index.php b/app/views/Admin/index.php index 8559bedfcae2cf97355b7b6e2267aa85d43c4076..214a85c439522680d833cf04155329562edd4243 100644 --- a/app/views/Admin/index.php +++ b/app/views/Admin/index.php @@ -28,11 +28,138 @@ $s = new Studio(); <div class="manage-header"> <div class="menu"> - <button class="menu-item active" onclick="showTable('client')">Client</button> - <button class="menu-item" onclick="showTable('anime')">Anime</button> - <button class="menu-item" onclick="showTable('studio')">Studio</button> + <button class="menu-item active" + onclick="showTable('client'); setActiveMenuItem('client')">Client</button> + <button class="menu-item" + onclick="showTable('anime'); setActiveMenuItem('anime')">Anime</button> + <button class="menu-item" + onclick="showTable('studio'); setActiveMenuItem('studio')">Studio</button> </div> - <button class="add-btn">Add</button> + + <button class="add-btn" onclick="openAddModal()">Add</button> + + <div id="addClientModal" class="modal"> + <div class="modal-content"> + <span class="close-btn" onclick="closeAddModal()">×</span> + <h2>Add New Client</h2> + + <form class="form-vertical" action="/public/actions/addClient.php" method="post" enctype="multipart/form-data"> + <label for="username">Username:</label> + <input type="text" id="username" name="username" placeholder="Username" required> + + <label for="email">Email:</label> + <input type="email" id="email" name="email" placeholder="Email" required> + + <label for="password">Password:</label> + <input type="text" id="password" name="password" placeholder="Password" required> + + <label for="admin_status">Status:</label> + <select id="admin_status" name="admin_status"> + <option value="false">Client</option> + <option value="true">Admin</option> + </select> + + <label for="birthdate">Birthdate:</label> + <input type="date" id="birthdate" name="birthdate"> + + <label for="bio">Biography:</label> + <textarea name="bio" id="bio" placeholder="Biography"></textarea> + + <label for="image">Picture:</label> + <input type="file" id="image" name="image"> + + <input type="submit" value="Add Client"> + </form> + + </div> + </div> + + <div id="addAnimeModal" class="modal"> + <div class="modal-content"> + <span class="close-btn" onclick="closeAddModal()">×</span> + <h2>Add New Anime</h2> + + <form class="form-vertical" action="/public/actions/addAnime.php" method="post" enctype="multipart/form-data"> + <label for="title">Title:</label> + <input type="text" id="title" name="title" placeholder="Title" required> + + <label for="type">Type:</label> + <select id="type" name="type" placeholder="Type" required> + <option value="TV">TV</option> + <option value="MOVIE">Movie</option> + <option value="OVA">OVA</option> + </select> + + <label for="status">Status:</label> + <select id="status" name="status" placeholder="Status" required> + <option value="ON-GOING">On Going</option> + <option value="COMPLETED">Completed</option> + <option value="HIATUS">Hiatus</option> + <option value="UPCOMING">Upcoming</option> + </select> + + <label for="release_date">Release Date:</label> + <input type="date" id="release_date" name="release_date" placeholder="Release Date"> + + <label for="episodes">Episodes:</label> + <input type="number" id="episodes" name="episodes" min="0"> + + <label for="rating">Rating:</label> + <select id="rating" name="rating" placeholder="Rating" required> + <option value="G">G</option> + <option value="PG-13">PG-13</option> + <option value="R(17+)">R(17+)</option> + <option value="Rx">Rx</option> + </select> + + <label for="image">Cover Picture:</label> + <input type="file" id="image" name="image"> + + <label for="trailer">Trailer:</label> + <input type="file" id="trailer" name="trailer"> + + <label for="synopsis">Synopsis:</label> + <textarea id="synopsis" name="synopsis" placeholder="Synopsis"></textarea> + + <label for="studio_id">Studio:</label> + <select id="studio_id" name="studio_id" placeholder="Studio" required> + <?php + $studios = $s->getAllStudio(); + foreach($studios as $studio){ + echo " <option value=$studio[studio_id]>$studio[name]</option>"; + } + ?> + </select> + <input type="submit" value="Add Anime"> + </form> + + </div> + </div> + + <div id="addStudioModal" class="modal"> + <div class="modal-content"> + <span class="close-btn" onclick="closeAddModal()">×</span> + <h2>Add New Studio</h2> + + <form class="form-vertical" action="/public/actions/addStudio.php" method="post" enctype="multipart/form-data"> + <label for="name">Name:</label> + <input type="text" id="name" name="name" placeholder="Name" required> + + <label for="description">Description:</label> + <textarea name="description" id="description" placeholder="Description"></textarea> + + <label for="established_date">Established Date:</label> + <input type="date" id="established_date" name="established_date"> + + <label for="image">Picture:</label> + <input type="file" id="image" name="image"> + + <input type="submit" value="Add Studio"> + </form> + + </div> + </div> + </div> <div class="container"> @@ -60,8 +187,8 @@ $s = new Studio(); $clients = $c->getAllClient(); foreach($clients as $client){ $date = $client['birthdate'] ?? '-'; - $bio = $client['bio'] ?? ''; - $image = $client['image'] ?? '-'; + $bio = $client['bio'] === '' ? '-' : $client['bio']; + $image = is_null($client['image']) ? '-' : str_replace('/', '/<wbr>', $client['image']); $admin_status = ($client['admin_status']) ? 'true' : 'false'; echo " <tr> @@ -73,9 +200,22 @@ $s = new Studio(); <td>$date</td> <td>$bio</td> <td>$image</td> - <td class='actions'> - <button class='edit-btn'>Edit</button> - <button class='delete-btn'>Delete</button> + <td> + <div class='btn-container'> + <button class='edit-btn' + data-client-id=$client[client_id] + data-username='$client[username]' + data-email='$client[email]' + data-password='$client[password]' + data-admin-status='$admin_status' + data-birthdate='$client[birthdate]' ?? '' + data-bio='$client[bio]' + data-image='$client[image]' + onclick='openEditClientModal(this)'> + Edit + </button> + <button class='delete-btn-client' client-id=$client[client_id]>Delete</button> + </div> </td> </tr> "; @@ -85,22 +225,66 @@ $s = new Studio(); </table> </div> + <div id="editClientModal" class="modal"> + <div class="modal-content"> + <span class="close-btn" onclick="closeEditClientModal()">×</span> + <h2>Edit Client</h2> + + <form class="form-vertical" action="/public/actions/editClient.php" method="post" enctype="multipart/form-data"> + <!-- Hidden input for client_id --> + <input type="hidden" id="editClientId" name="client_id"> + + <label for="editUsername">Username:</label> + <input type="text" id="editUsername" name="username" required> + + <label for="editEmail">Email:</label> + <input type="email" id="editEmail" name="email" required> + + <label for="editBirthdate">Established Date:</label> + <input type="date" id="editBirthdate" name="birthdate"> + + <!-- Note: Consider if you really want to show and edit passwords this way --> + <label for="editPassword">Password:</label> + <input type="text" id="editPassword" name="password" required> + + <label for="editAdminStatus">Status:</label> + <select id="editAdminStatus" name="admin_status"> + <option value="false">Client</option> + <option value="true">Admin</option> + </select> + + <label for="editBio">Bio:</label> + <textarea id="editBio" name="bio"></textarea> + + <label for="currentImage">Current Image:</label> + <img src="" alt="No image available." id="currentImage" style="display: none;"> + + <label for="newImage">Update Image:</label> + <input type="file" id="newImage" name="newImage"> + + <input type="submit" value="Update Client"> + </form> + </div> + </div> + + <div id="anime" class="table"> <!-- Anime table goes here --> <table> <thead> <tr> <th>id</th> + <th>title</th> <th>type</th> <th>status</th> - <th>release_date</th> - <th>episodes</th> + <th>release</th> + <th>eps</th> <th>rating</th> <th>score</th> <th>image</th> <th>trailer</th> <th>synopsis</th> - <th>studio_id</th> + <th>studio</th> <th>actions</th> </tr> </thead> @@ -111,11 +295,13 @@ $s = new Studio(); $date = $anime['release_date'] ?? '-'; $episodes = $anime['episodes'] ?? ''; $score = $anime['score'] ?? '-'; - $image = substr($anime['image'], 18) ?? '-'; - $trailer = substr($anime['trailer'], 12) ?? '-'; + $image = is_null($anime['image']) ? '-' : str_replace('/', '/<wbr>', $anime['image']); + $trailer = is_null($anime['trailer']) ? '-' : str_replace('/', '/<wbr>', $anime['trailer']); + $synopsis = $anime['synopsis'] === '' ? '-' : $anime['synopsis']; echo " <tr> <td>$anime[anime_id]</td> + <td>$anime[title]</td> <td>$anime[type]</td> <td>$anime[status]</td> <td>$date</td> @@ -124,11 +310,27 @@ $s = new Studio(); <td>$score</td> <td>$image</td> <td>$trailer</td> - <td>$anime[synopsis]</td> + <td>$synopsis</td> <td>$anime[studio_id]</td> - <td class='actions'> - <button class='edit-btn'>Edit</button> - <button class='delete-btn'>Delete</button> + <td> + <div class='btn-container'> + <button class='edit-btn' + data-anime-id=$anime[anime_id] + data-title='$anime[title]' + data-type='$anime[type]' + data-status='$anime[status]' + data-release-date='$anime[release_date]' ?? '' + data-episodes=$anime[episodes] + data-rating='$anime[rating]' + data-image='$anime[image]' + data-trailer='$anime[trailer]' + data-synopsis='$anime[synopsis]' + data-studio-id=$anime[studio_id] + onclick='openEditAnimeModal(this)'> + Edit + </button> + <button class='delete-btn-anime' anime-id=$anime[anime_id]>Delete</button> + </div> </td> </tr> "; @@ -138,6 +340,81 @@ $s = new Studio(); </table> </div> + <div id="editAnimeModal" class="modal"> + <div class="modal-content"> + <span class="close-btn" onclick="closeEditAnimeModal()">×</span> + <h2>Edit Anime</h2> + + <form class="form-vertical" action="/public/actions/editAnime.php" method="post" enctype="multipart/form-data"> + <!-- Hidden input for anime_id --> + <input type="hidden" id="editAnimeId" name="anime_id"> + + <label for="editTitle">Title:</label> + <input type="text" id="editTitle" name="title" placeholder="Title" required> + + <label for="editType">Type:</label> + <select id="editType" name="type" placeholder="Type" required> + <option value="TV">TV</option> + <option value="MOVIE">Movie</option> + <option value="OVA">OVA</option> + </select> + + <label for="editStatus">Status:</label> + <select id="editStatus" name="status" placeholder="Status" required> + <option value="ON-GOING">On Going</option> + <option value="COMPLETED">Completed</option> + <option value="HIATUS">Hiatus</option> + <option value="UPCOMING">Upcoming</option> + </select> + + <label for="editRelease_date">Release Date:</label> + <input type="date" id="editRelease_date" name="release_date" placeholder="Release Date"> + + <label for="editEpisodes">Episodes:</label> + <input type="number" id="editEpisodes" name="episodes" min="0"> + + <label for="editRating">Rating:</label> + <select id="editRating" name="rating" placeholder="Rating" required> + <option value="G">G</option> + <option value="PG-13">PG-13</option> + <option value="R(17+)">R(17+)</option> + <option value="Rx">Rx</option> + </select> + + <label for="currentAnimeImage">Current Image:</label> + <img src="" alt="No image available." id="currentAnimeImage" style="display: none;"> + + <label for="newImage">Update Image:</label> + <input type="file" id="newImage" name="newImage"> + + <label for="currentTrailer">Current Trailer:</label> + <video width="320" height="240" controls id="currentTrailer" style="display: none;"> + <source src="" type="video/mp4" id="currentTrailer"> + Your browser does not support the video tag. + </video> + + <label for="newTrailer">Update Trailer:</label> + <input type="file" id="newTrailer" name="newTrailer"> + + <label for="editSynopsis">Synopsis:</label> + <textarea id="editSynopsis" name="synopsis" placeholder="Synopsis"></textarea> + + <label for="editStudio_id">Studio:</label> + <select id="editStudio_id" name="studio_id" placeholder="Studio" required> + <?php + $studios = $s->getAllStudio(); + foreach($studios as $studio){ + echo " <option value=$studio[studio_id]>$studio[name]</option>"; + } + ?> + </select> + <input type="submit" value="Update Anime"> + </form> + + </div> + </div> + + <div id="studio" class="table"> <!-- Studio table goes here --> <table> @@ -152,37 +429,89 @@ $s = new Studio(); </tr> </thead> <tbody> - <?php - $studios = $s->getAllStudio(); - foreach($studios as $studio){ - $desc = $studio['description'] ?? ''; - $date = $studio['established_date'] ?? '-'; - $image = substr($studio['image'], 19) ?? '-'; - echo " - <tr> - <td>$studio[studio_id]</td> - <td>$studio[name]</td> - <td>$desc</td> - <td>$date</td> - <td>$image</td> - <td class='actions'> - <button class='edit-btn'>Edit</button> - <button class='delete-btn'>Delete</button> - </td> - </tr> - "; - } + <?php + $studios = $s->getAllStudio(); + foreach($studios as $studio){ + $desc = $studio['description'] === '' ? '-' : $studio['description']; + $date = $studio['established_date'] ?? '-'; + $image = is_null($studio['image']) ? '-' : str_replace('/', '/<wbr>', $studio['image']); + echo " + <tr> + <td>$studio[studio_id]</td> + <td>$studio[name]</td> + <td>$desc</td> + <td>$date</td> + <td>$image</td> + <td> + <div class='btn-container'> + <button class='edit-btn' + data-studio-id=$studio[studio_id] + data-name='$studio[name]' + data-description='$studio[description]' + data-established-date='$studio[established_date]' ?? '' + data-image='$studio[image]' + onclick='openEditStudioModal(this)'> + Edit + </button> + <button class='delete-btn-studio' studio-id=$studio[studio_id]>Delete</button> + </div> + </td> + </tr>"; + } ?> </tbody> </table> + + <div id="editStudioModal" class="modal"> + <div class="modal-content"> + <span class="close-btn" onclick="closeEditStudioModal()">×</span> + <h2>Edit Studio</h2> + + <form class="form-vertical" action="/public/actions/editStudio.php" method="post" enctype="multipart/form-data"> + <input type="hidden" id="editStudioId" name="studio_id"> + + <label for="editName">Name:</label> + <input type="text" id="editName" name="name" placeholder="Name" required> + + <label for="editDescription">Description:</label> + <textarea name="description" id="editDescription" placeholder="Description"></textarea> + + <label for="editEstablishedDate">Established Date:</label> + <input type="date" id="editEstablishedDate" name="established_date"> + + <label for="currentStudioImage">Current Image:</label> + <img src="" alt="No image available." id="currentStudioImage" style="display: none;"> + + <label for="newImage">Update Image:</label> + <input type="file" id="newImage" name="newImage"> + + <input type="submit" value="Edit Studio"> + </form> + </div> + </div> + </div> </div> + + </div> </div> + + + </body> </html> +<script> + <?php if (isset($_SESSION['error_message'])): ?> + window.onload = function() { + alert('<?php echo $_SESSION['error_message']; ?>'); + }; + <?php unset($_SESSION['error_message']); // Clear the message so it doesn't persist ?> + <?php endif; ?> +</script> + <?php require_once(BASE_DIR.'/views/includes/footer.php'); ?> \ No newline at end of file