-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
122 lines (105 loc) · 3.91 KB
/
Copy pathindex.php
File metadata and controls
122 lines (105 loc) · 3.91 KB
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
<?php
session_start();
if ($_SESSION["logged_in"] != "true") {
header("Location: login.html");
}
?>
<html>
<head>
<title>Tracker</title>
<link rel="stylesheet" type="text/css" href="styles/main_page.css">
<link rel="stylesheet" type="text/css" href="styles/menu_bar.css">
<link rel="stylesheet" type="text/css" href="styles/border.css">
<link rel="stylesheet" type="text/css" href="styles/nice_button.css">
<link rel='stylesheet' type="text/css" href='https://fonts.googleapis.com/css?family=Rubik'>
</head>
<body>
<script type="text/javascript">
// https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit
function post(path, params, method) {
method = method || "post"; // Set method to post by default if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
function watchEpisode(button) {
var show_id = button.id;
post("update_show.php", {id: show_id});
}
function deleteShow(button) {
var show_id = button.id;
post("update_show.php", {id: show_id, mode: "delete"});
}
</script>
<div class="menuBar">
<a class="logo left" href="index.php" style="font-size: 35px;">TRACKER</a>
<a class="right" href="logout.php">LOGOUT</a>
<a class="right" href="add_show.php">ADD SHOW</a>
</div>
<h1>Shows</h1>
<div id="shows" style="text-align: center;">
<?php
session_start();
$tracker_user = $_SESSION["username"];
$config = include('config.php');
$server = $config["server"];
$db_name = "tracker";
$username = "tracker";
$password = $config["db_pass"];
$conn = mysqli_connect($server, $username, $password, $db_name);
if (!$conn) {
die("Error: " . mysqli_connect_error());
}
$query = "SELECT * FROM shows WHERE user='{$tracker_user}';";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) <= 0) {
echo "<p>No shows added</p>";
} else {
while ($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
$name = $row["show_name"];
$seasons = $row["seasons"];
$episodes = $row["episodes"];
$current_season = $row["current_season"];
$current_episode = $row["current_episode"];
$eps_left_season = $episodes - $current_episode;
$eps_left_show = ($seasons * $episodes) - ((($current_season - 1) * $episodes) + $current_episode);
if ($current_season > $seasons) {
echo "
<div class=\"border\">
<h3>{$name}</h3>
<h1 class=\"centered\">Show finished!</h1>
<button id=\"{$id}\" onclick=\"deleteShow(this)\" class=\"niceButton\">DELETE<br>SHOW</button><br><br>
</div>";
} else {
echo "
<div class=\"border\">
<h2>{$name}</h2>
<p style=\"font-weight: bold;\">Currently: Season {$current_season} Episode {$current_episode}</p>
<!--<p>Seasons: {$seasons}</p>-->
<p>{$eps_left_season} episodes left until the next season</p>
<p>{$eps_left_show} episodes left in the show</p><br>
<button id=\"{$id}\" onclick=\"watchEpisode(this)\" class=\"niceButton\">I WATCHED AN<br>EPISODE</button><br><br>
</div>
";
}
}
}
mysqli_close($conn);
?>
</div>
</body>
</html>