-
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
6 changed files
with
113 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 |
---|---|---|
|
@@ -84,4 +84,8 @@ | |
color: rgba(243, 211, 28, 0.966); | ||
} | ||
|
||
.video__id__span { | ||
display: none; | ||
} | ||
|
||
/* Modifiers */ |
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,57 @@ | ||
<?php | ||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
$json = file_get_contents('php://input'); | ||
$data = json_decode($json); | ||
$rating = $data->rating; | ||
$video_id = $data->video_id; | ||
|
||
|
||
try { | ||
require_once "./db_handler.inc.php"; | ||
require_once "../models/videos.inc.php"; | ||
require_once "./config_session.inc.php"; | ||
|
||
// Error handlers | ||
$errors = []; | ||
|
||
|
||
// check if user is logged in | ||
if (!isset($_SESSION["user_id"])) { | ||
$errors[] = "You need to be logged in to rate this video"; | ||
} | ||
|
||
|
||
// check if rating is not empty or zero | ||
else if (empty($rating) || $rating == 0) { | ||
$errors[] = "Rating cannot be empty or zero"; | ||
} | ||
|
||
// check if video is not empty and does exist | ||
else if (empty($video_id) || !fetch_video_by_id($pdo, $video_id)) { | ||
$errors[] = "Video does not exist"; | ||
} | ||
|
||
|
||
|
||
if ($errors) { | ||
$_SESSION["error_star_rating"] = $errors; | ||
die(); | ||
} | ||
|
||
// Rate video | ||
|
||
submit_star_rating($pdo, $video_id, $rating); | ||
|
||
header('Location: ../pages/video_page.php?video_id=' . $video_id . '&success=video_rated'); | ||
// close connection | ||
$pdo = null; | ||
$stmt = null; | ||
die(); | ||
} catch (PDOException $e) { | ||
die("Error while rating this video: " . $e->getMessage()); | ||
} | ||
} else { | ||
header("Location: ../pages/video_page.php?video_id=" . $video_id); | ||
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
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
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