-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowEdit.php
177 lines (161 loc) · 7 KB
/
showEdit.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
<!DOCTYPE html>
<html lang="en">
<?php
require('connect-db.php');
session_start();
if (isset($_SESSION['user'])) {
$username = $_SESSION['user'];
}
?>
<head>
<link rel="apple-touch-icon" sizes="180x180" href="icon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="icon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="icon/favicon-16x16.png">
<link rel="manifest" href="icon/site.webmanifest">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Rubik&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<link rel="stylesheet" href="./themes/purple.css">
<link rel="stylesheet" id="switcher-id" href="">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Vivian Tran vt5en & Valerie Young vy5br">
<meta name="description" content="POTD 1">
<title>queueAble: Finding Time for What's Important</title>
<style type="text/css">
h1 {font-family: 'Rubik', Arial;
}
h2 {font-family: 'Rubik', 'Arial';
font-size: 25px;
}
p {font-family: 'Rubik', 'Arial';
}
</style>
</head>
<?php
//checks that the user is logged in
if (isset($_SESSION['user'])){
//checks that there is a donor selected to edit
if (!isset($_SESSION['id']))
{
echo "<script>
alert('Nothing to edit, returning to queues');
window.location.href='queue.php';
</script>";
}
$show_title = $_SESSION['id'];
$username = $_SESSION['user'];
$query = "SELECT * FROM shows WHERE show_title = :show_title AND username = :username";
$statement = $db->prepare($query);
$statement->bindParam(':show_title', $show_title);
$statement->bindParam(':username', $username);
$statement->execute();
// fetchAll() returns an array for all of the rows in the result set
$show_info = $statement->fetchAll();
// closes the cursor and frees the connection to the server so other SQL statements may be issued
$statement->closecursor();
$show_season = $show_info[0]['season'];
$show_episode = $show_info[0]['episode'];
//checks for post
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (!empty($_POST['action']) && ($_POST['action'] == 'Cancel'))
{
unset($_SESSION['id']);
header("Location: queue.php");
}
else
{
$show_title = $_SESSION['id'];
$show_episode = $_POST['episode'];
$show_season = $_POST['season'];
$username = $_SESSION['user'];
$query = "UPDATE shows SET season=:show_season, episode=:show_episode
WHERE username=:username AND show_title=:show_title";
$statement = $db->prepare($query);
$statement->bindValue(':show_title', $show_title);
$statement->bindValue(':username', $username);
$statement->bindValue(':show_season', $show_season);
$statement->bindValue(':show_episode', $show_episode);
$statement->execute();
$statement->closeCursor();
unset($_SESSION['id']);
echo "<script>
alert('Show updated');
window.location.href='queue.php';
</script>";
}
}
$query = "SELECT * FROM settings WHERE username=:username";
$statement = $db->prepare($query);
$statement->bindParam(':username', $username);
$statement->execute();
$settings_info = $statement->fetchAll();
$theme = $statement->fetchAll();
$statement->closecursor();
foreach ($settings_info as $row) {
$theme = $row['theme'];
if ($theme == "light"){
echo "<script>";
echo "document.getElementById('switcher-id').href = './themes/light.css';";
echo "</script>";
}
if ($theme == "sky"){
echo "<script>";
echo "document.getElementById('switcher-id').href = './themes/sky.css';";
echo "</script>";
}
if ($theme == "purple"){
echo "<script>";
echo "document.getElementById('switcher-id').href = './themes/purple.css';";
echo "</script>";
}
if ($theme == "dark"){
echo "<script>";
echo "document.getElementById('switcher-id').href = './themes/dark.css';";
echo "</script>";
}
}
?>
<div class="container" style="text-align: center;">
<h4>
Editing Show <?php if(isset($_SESSION['id'])){echo $_SESSION['id'];}?>
</h4>
<!-- a form -->
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" name="editForm" method="post">
<div class="form-row">
<div class = "col">
<label for="shelter_name">What season?</label>
<input type="text" class="form-control" id="season" name="season" placeholder="Enter the season" required
value="<?php echo $show_season;?>">
</div>
<div class = "col">
<label for="donation_amt">What episode?</label>
<input type="number" class="form-control" id="episode" name="episode" placeholder="Enter the episode" min="1" required
value="<?php echo $show_episode;?>">
</div>
</div>
<div class="row">
<div class="form-group col-md">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</br>
<div class="form-group col-md">
<input type="submit" value="Cancel" name="action" class="btn btn-secondary" />
</div>
</div>
</form>
</div>
<?php
}
else
{
echo "<script>
alert('Please log in.');
window.location.href='login.php';
</script>";
}
?>