Skip to content

Commit

Permalink
edit video page started
Browse files Browse the repository at this point in the history
  • Loading branch information
kuldp18 committed Mar 29, 2024
1 parent ea71823 commit c39ea9c
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 7 deletions.
56 changes: 56 additions & 0 deletions css/edit_video.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.heading--small {
font-size: 2.5rem;
}

.edit {
border: 1px solid red;
min-height: calc(100vh - 70px);
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
padding-top: 1rem;
}

.edit__form {
display: flex;
flex-direction: column;
gap: 1rem;
/* border: 1px solid yellow; */
max-width: 50%;
font-size: 1.25rem;
padding: 2rem 1.5rem;
background-color: rgba(0, 0, 0, 0.861);
}

.edit__form__container {
display: flex;
gap: 1rem;
flex-wrap: wrap;
}

.edit__form__checkbox {
display: flex;
gap: 5px;
}

textarea {
font-size: inherit;
font-family: inherit;
padding: 0.5rem;
}

.edit__btn {
display: inline-block;
max-width: 100px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
background-color: rgb(17, 148, 148);
color: whitesmoke;
}

.edit__btn:hover {
opacity: 0.8;
}
11 changes: 11 additions & 0 deletions models/video_tags.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ function delete_video_tag(object $pdo, string $tag_id): void
$stmt->bindParam(":tag_id", $tag_id, PDO::PARAM_INT);
$stmt->execute();
}

// get video tags of a video by video_id
function get_video_tags_by_video_id(object $pdo, string $video_id): array
{
$query = "SELECT tag_name FROM video_tags WHERE tag_id IN (SELECT tag_id FROM video_tag_associations WHERE video_id = :video_id)";
$stmt = $pdo->prepare($query);
$stmt->bindParam(":video_id", $video_id, PDO::PARAM_STR);
$stmt->execute();
$tags = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $tags;
}
82 changes: 82 additions & 0 deletions pages/edit_video.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
require_once "../includes/db_handler.inc.php";
require_once "../includes/config_session.inc.php";
require_once "../models/videos.inc.php";
require_once "../models/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>Quirx - Edit Video</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="../css/global.css" />
<link rel="stylesheet" href="../css/navbar.css" />
<link rel="stylesheet" href="../css/edit_video.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/autoresize.jquery.js"></script>
</head>

<body>
<?php include_once('../includes/components/navbar.inc.php') ?>
<?php
// check if user is not logged in
if (!isset($_SESSION['user_id']) || !isset($_SESSION['user_role'])) {
// if not, redirect to home page
header('Location: ../index.php');
exit();
}
$user_id = $_SESSION['user_id'];
$video_id = $_GET['video_id'];

$video_details = fetch_video_by_id($pdo, $video_id);
$video_tag_list = get_video_tags($pdo);
$current_video_tags = get_video_tags_by_video_id($pdo, $video_id);

//print current video tags
print_r($current_video_tags);

?>

<main class="edit">
<h1 class="heading heading--small">Edit Video</h1>
<form action="" class="edit__form">
<input type="text" name="title" class="edit__form__input" placeholder="Edit video title" value="<?php
if (isset($video_details['video_title'])) {
echo $video_details['video_title'];
}
?>
">
<textarea name="description" maxlength="1000" class="upload__textarea" placeholder="Edit video description"><?php if (isset($video_details['video_desc'])) {
echo $video_details['video_desc'];
}
?>
</textarea>
<div class="edit__form__container">
<?php
foreach ($video_tag_list as $tag) {
echo '<div class="edit__form__checkbox">';
echo '<label for="' . $tag['tag_name'] . '">' . $tag['tag_name'] . '</label>';
$tagChecked = in_array($tag['tag_name'], $current_video_tags) ? 'checked' : '';
echo '<input type="checkbox" name="' . $tag['tag_name'] . '" value="' . $tag['tag_name'] . '" ' . $tagChecked . '>';
echo '</div>';
}
?>
</div>
<div class="edit__form__thumbnail">
<label for="thumbnail">Change or remove thumbnail:</label>
<input type="file" name="thumbnail" class="edit__form__input">
</div>
<input type="submit" value="Edit video" class="edit__btn">
</form>
</main>

<script>
$('textarea').autoResize();
</script>

</body>

</html>
17 changes: 10 additions & 7 deletions pages/user_dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@
Views: <?php echo $views; ?>
</div>
</div>
<form action="" class="btn__form video__item">
<button type="submit" name="edit" class="video__btn video__btn--edit">
<div class="btn__form video__item">
<a href="<?php echo './edit_video.php?video_id=' . $video_id ?>" name="edit" class="video__btn video__btn--edit">
<i class="fa-solid fa-pen"></i>
</button>
<button type="submit" name="delete" class="video__btn video__btn--delete">
<i class="fa-solid fa-trash"></i>
</button>
</form>
</a>
<form action="" method="post">
<input type="hidden" name="video_id" value="<?php echo $video_id ?>">
<button type="submit" class="video__btn video__btn--delete">
<i class="fa-solid fa-trash"></i>
</button>
</form>
</div>
</article>
<?php } ?>
</section>
Expand Down

0 comments on commit c39ea9c

Please sign in to comment.