-
Notifications
You must be signed in to change notification settings - Fork 0
/
want.php
197 lines (188 loc) · 8.63 KB
/
want.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/** DATABASE SETUP **/
require_once "local-config.php";
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
if (isset($_POST["removeID"]) && $_POST["removeID"] != "") {
$remove_stmt = "DELETE FROM wantToWatchList WHERE docID=? AND userID=?;";
if($remove_watch = mysqli_prepare($link, $remove_stmt)){
mysqli_stmt_bind_param($remove_watch, "ii", $watchID_param, $userID_param);
$watchID_param = intval($_POST["removeID"]);
$userID_param = $_SESSION["userID"];
if(!mysqli_stmt_execute($remove_watch)){
echo "Failed to remove. Try again!";
}
}
}
if (isset($_POST["priority"])) {
$priority_stmt = "UPDATE wantToWatchList SET priority= ? WHERE docID=? AND userID=?;";
if($priority_watch = mysqli_prepare($link, $priority_stmt)){
mysqli_stmt_bind_param($priority_watch, "iii", $priority_param, $watchID_param, $userID_param);
$priority_param = intval($_POST["priority"]);
$watchID_param = intval($_POST["docID"]);
$userID_param = $_SESSION["userID"];
if(!mysqli_stmt_execute($priority_watch)){
echo "Failed to remove. Try again!";
}
}
}
if (isset($_POST["switchID"])) {
$insert_watched_stmt = "INSERT INTO watchedList(docID, userID, dateWatched) VALUES (?, ?, ?)";
if($insert_watched = mysqli_prepare($link, $insert_watched_stmt)){
mysqli_stmt_bind_param($insert_watched, "iis", $watchedID_param, $userID_param, $date_param);
$watchedID_param = intval($_POST["switchID"]);
$userID_param = $_SESSION["userID"];
$date_param = "00/00/0000";
if(!mysqli_stmt_execute($insert_watched)){
echo "Failed to add documentary to Watched List. Try again!";
}
}
$add_stmt = "Add wantToWatchList SET priority= ? WHERE docID=? AND userID=?;";
$remove_stmt = "DELETE FROM wantToWatchList WHERE docID=? AND userID=?;";
if($remove_watch = mysqli_prepare($link, $remove_stmt)){
mysqli_stmt_bind_param($remove_watch, "ii", $watchID_param, $userID_param);
$watchID_param = intval($_POST["switchID"]);
$userID_param = $_SESSION["userID"];
if(!mysqli_stmt_execute($remove_watch)){
echo "Failed to remove from Watch List. Try again!";
}
}
}
if (isset($_POST["order"]) && $_POST["order"] == "ASC"){
$res_query_watch = "select * from wantToWatchList NATURAL JOIN documentaryTitleYear NATURAL JOIN documentaryTitleOverview NATURAL JOIN documentaryInfo where userID =" . $_SESSION["userID"] . " ORDER BY priority;";
}else if(isset($_POST["order"]) && $_POST["order"] == "DES"){
$res_query_watch = "select * from wantToWatchList NATURAL JOIN documentaryTitleYear NATURAL JOIN documentaryTitleOverview NATURAL JOIN documentaryInfo where userID =" . $_SESSION["userID"] . " ORDER BY priority DESC;";
}else{
$res_query_watch = "select * from wantToWatchList NATURAL JOIN documentaryTitleYear NATURAL JOIN documentaryTitleOverview NATURAL JOIN documentaryInfo where userID =" . $_SESSION["userID"] . ";";
}
$res_watch = $link -> query($res_query_watch);
if ($res_watch === false) {
die("MySQL database failed");
}
$data_watch = $res_watch->fetch_all(MYSQLI_ASSOC);
if (isset($data_watch)) {
$watchList = count($data_watch);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Want to Watch</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body{ font: 14px sans-serif; text-align: center; }
</style>
</head>
<body class="bg-lightYellow">
<!-- Navigation bar code -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark" aria-label="Main Navigation Bar">
<div class="container-xl">
<a class="navbar-brand" href="index.php">Documentary Database</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsTop" aria-controls="navbarsTop" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsTop">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="index.php">Search</a>
</li>
<li class="nav-item">
<a class="nav-link" href="watched.php">Watched List</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="want.php">Want to Watch List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="reset-password.php">Reset Password</a>
</li>
</ul>
<span class="navbar-text">
Hello, <?= $_SESSION["username"]?>!
</span>
<a style="margin-left: 15px" class="btn btn-danger" href="logout.php">Log out</a>
</div>
</div>
</nav>
<br>
<h1>My Want to Watch List</h1>
<form action ="want.php" method ="post">
<input type="hidden" name="order" value = "ASC"></input>
<button type="submit" class="btn btn-success">Ascending By Priority</button>
</form>
<br>
<form action ="want.php" method ="post">
<input type="hidden" name="order" value = "DES"></input>
<button type="submit" class="btn btn-success">Descending By Priority</button>
</form>
<?php if(count($data_watch)){
foreach ($data_watch as $doc) {
?>
<div style="margin-left: 25%">
<div class="card" style="width: 66%">
<div class="card-body">
<h5 class="card-title"><?=$doc["title"]?></h5>
<h6 class="card-subtitle mb-2"><?=$doc["year"]?></h7>
<p class="card-text-center"><?=$doc["overview"]?></p>
<p class="card-text"><strong>Average Rating: <?=$doc["averageRating"]?></strong></p>
<p class="card-text"><strong>Current Watch Priority: <?=$doc["priority"]?></strong></p>
<form action="want.php" method="post">
<?php if(isset($_POST["order"])){ ?>
<input type="hidden" name="order" value=<?=$_POST["order"]?>> </input>
<?php } ?>
<input type="hidden" value=<?=$doc["docID"]?> name="removeID"></input>
<button type="submit" class="btn btn-danger">Remove from Watch list</button>
</form>
<br>
<form action="want.php" method="post">
<?php if(isset($_POST["order"])){ ?>
<input type="hidden" name="order" value=<?=$_POST["order"]?>> </input>
<?php } ?>
<input type="hidden" value=<?=$doc["docID"]?> name="switchID"></input>
<button type="submit" class="btn btn-success">Switch to Watched List!</button>
</form>
<br>
<form action="want.php" method="post">
<?php if(isset($_POST["order"])){ ?>
<input type="hidden" name="order" value=<?=$_POST["order"]?>> </input>
<?php } ?>
<input type="hidden" value=<?=$doc["docID"]?> name="docID"></input>
<input type="number" name="priority" max = 10 min = 1 value=<?=$doc["priority"]?> ></input>
<!--
DELIMITER $$
CREATE TRIGGER priorityError
BEFORE ASSERTION on wantToWatchList
BEGIN
IF priority NOT BETWEEN (1 AND 10)
ASSERTION wantToWatchList(priority)
VALUES (NULL);
END IF
END
$$
DELIMITER ;
-->
<button type="submit" class="btn btn-primary">Update Priority Value</button>
</form>
<br>
<!-- <form action="detailed.php" method="post" class="mb-2 text-center">
<input type="hidden" value=<?=$db["docID"]?> name="reviews"></input>
<button type="submit" class="btn btn-primary">Reviews</button>
</form> -->
</div>
</div>
</div>
<?php }
}else{ ?>
<h4>No documentaries added.</h4>
<?php
}
?>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
</body>
</html>