-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
// check if new video tag is empty | ||
function is_new_tag_empty(string $new_tag): bool | ||
{ | ||
if (empty($new_tag)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
// check if video tag already exists | ||
function is_video_tag_exists(object $pdo, string $new_tag): bool | ||
{ | ||
$query = "SELECT * FROM video_tags WHERE tag_name = :new_tag"; | ||
$stmt = $pdo->prepare($query); | ||
$stmt->bindParam(":new_tag", $new_tag, PDO::PARAM_STR); | ||
$stmt->execute(); | ||
$result = $stmt->fetch(PDO::FETCH_ASSOC); | ||
|
||
if ($result) { | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.tags { | ||
/* border: 1px solid red; */ | ||
min-height: calc(100vh - 70px); | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
grid-template-rows: 1fr 1fr; | ||
gap: 1rem; | ||
padding: 1rem; | ||
} | ||
|
||
.tags__section { | ||
border: 1px solid rgb(211, 211, 16); | ||
border-radius: 10px; | ||
} | ||
|
||
.tags__section__heading { | ||
font-size: 2rem; | ||
} | ||
|
||
.tags__section, | ||
.tags__section form { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 1rem; | ||
} | ||
|
||
.tags__btn { | ||
padding: 0.2rem 1.25rem; | ||
cursor: pointer; | ||
background-color: black; | ||
color: whitesmoke; | ||
} | ||
|
||
.tags__btn:hover { | ||
background-color: rgba(0, 0, 0, 0.929); | ||
color: rgba(245, 245, 245, 0.922); | ||
outline: 1px solid rgba(0, 255, 255, 0.865); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
$new_tag = $_POST['new_tag']; | ||
|
||
|
||
try { | ||
require_once "./db_handler.inc.php"; | ||
require_once "../models/video_tags.inc.php"; | ||
require_once "../controllers/video_tags.inc.php"; | ||
require_once "./config_session.inc.php"; | ||
|
||
// Error handlers | ||
$errors = []; | ||
|
||
// check if new tag is empty | ||
if (is_new_tag_empty($new_tag)) { | ||
$errors[] = "New tag cannot be empty"; | ||
} | ||
|
||
// check if tag already exists | ||
else if (is_video_tag_exists($pdo, $new_tag)) { | ||
$errors[] = "Tag already exists"; | ||
} | ||
|
||
|
||
if ($errors) { | ||
$_SESSION["errors_admin_manage_tags"] = $errors; | ||
header('Location: ../pages/admin_manage_tags.php'); | ||
die(); | ||
} | ||
|
||
// Create new video tag | ||
|
||
create_new_video_tag($pdo, $new_tag); | ||
|
||
|
||
|
||
header('Location: ../pages/admin_manage_tags.php?success=tag_created'); | ||
// close connection | ||
$pdo = null; | ||
$stmt = null; | ||
die(); | ||
} catch (PDOException $e) { | ||
die("Error while creating new video tag: " . $e->getMessage()); | ||
} | ||
} else { | ||
header("Location: ../pages/admin_manage_tags.php"); | ||
exit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
// create new video tag | ||
function create_new_video_tag(object $pdo, string $new_tag): void | ||
{ | ||
$query = "INSERT INTO video_tags (tag_name) VALUES (:new_tag)"; | ||
$stmt = $pdo->prepare($query); | ||
$stmt->bindParam(":new_tag", $new_tag, PDO::PARAM_STR); | ||
$stmt->execute(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
require_once "../includes/config_session.inc.php"; | ||
require_once "../views/video_tags.inc.php"; | ||
?> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Admin - Manage Video Tags</title> | ||
<link rel="stylesheet" href="../css/global.css" /> | ||
<link rel="stylesheet" href="../css/navbar.css" /> | ||
<link rel="stylesheet" href="../css/admin_manage_tags.css" /> | ||
</head> | ||
|
||
<body> | ||
<?php include_once('../includes/components/navbar.inc.php') ?> | ||
<?php | ||
// check is user is not logged in or is not admin | ||
if (!isset($_SESSION['user_id']) || !isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'admin') { | ||
// if not, redirect to home page | ||
header('Location: ../index.php'); | ||
exit(); | ||
} | ||
$user_name = $_SESSION['user_username']; | ||
?> | ||
|
||
<main class="tags"> | ||
<section class="tags__section"> | ||
<h3 class="tags__section__heading">Create video tag</h3> | ||
<form action="../includes/create_tag.inc.php" method="post"> | ||
<input type="text" name="new_tag" placeholder="Enter new video tag name"> | ||
<button type="submit" class="tags__btn">Create</button> | ||
</form> | ||
</section> | ||
<section class="tags__section"></section> | ||
<section class="tags__section"></section> | ||
<section class="tags__section"></section> | ||
</main> | ||
|
||
<?php | ||
check_and_print_video_tag_creation_errors(); | ||
|
||
if (isset($_GET["success"]) && $_GET["success"] === "tag_created") { | ||
echo <<<HTML | ||
<section class="modal modal--success"> | ||
<h1 class="modal__title">New video tag created!</h1> | ||
<span class="modal__close modal__close--success">X</span> | ||
</section> | ||
HTML; | ||
} | ||
?> | ||
|
||
<script src="../js/close_modal.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
// check and print video tag creation errors | ||
function check_and_print_video_tag_creation_errors() | ||
{ | ||
|
||
if (isset($_SESSION["errors_admin_manage_tags"])) { | ||
$errors = $_SESSION["errors_admin_manage_tags"]; | ||
if (count($errors) > 0) { | ||
echo "<section class='modal modal--error'>"; | ||
echo "<h1 class='modal__title'>Unable to create new tag: </h1>"; | ||
echo "<span class='modal__close modal__close--error'>X</span>"; | ||
foreach ($errors as $error) { | ||
echo "<p class='modal__item'>$error</p>"; | ||
} | ||
echo "</section>"; | ||
unset($_SESSION["errors_admin_manage_tags"]); | ||
} | ||
} | ||
} |