-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
151 lines (114 loc) · 5.53 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="style.css" rel="stylesheet">
<title>Reels from the Crypt</title>
</head>
<body>
<header>
<div class="banner">
<div class="banner_left">
<h1>Reels <br>from <br>the <br>Crypt</h1>
</div>
<div class="banner_right">
<div class="dropdown">
<button class="drop_button">Order By</button>
<form method="get" class="dropdown_content">
<span class="label_button_flex_row"><input id="added" name="id" type="radio" value="id">
<label for="id">Last added</label></span>
<span class="label_button_flex_row"><input id="title" name="sort" type="radio" value="title">
<label for="title">Title</label></span>
<span class="label_button_flex_row"><input id="year" name="sort" type="radio" value="year">
<label for="year">Year</label></span>
<span class="label_button_flex_row"><input id="director" name="sort" type="radio" value="director">
<label for="director">Director</label></span>
<span class="label_button_flex_row"><input id="produced" name="sort" type="radio" value="produced">
<label for="produced">Country</label></span>
<span class="label_button_flex_row"><input id="language" name="sort" type="radio" value="language">
<label for="language">Language</label></span>
<label class="sort_select" for="sort_direction"><input id="sort_direction" name="sort_desc" type="checkbox"><span>Sort asc/desc</span></label>
<div id="sort_submit"><input type="submit" value="sort"></div>
</form>
</div>
<a href="#add_item">New Film</a>
</div>
</div>
</header>
<main>
<h1 class="collection_header">Favourites</h1>
<div class="main_container">
<?php
require_once('access_db.php');
function print_results($results)
{
foreach ($results as $film){
echo "<div>";
echo "<div class='item' style='background-image: url({$film['image_url']})'>";
echo '</div>';
echo "<div>";
echo '<p>' . $film['Title'] . '</p>';
echo '<p>' . $film['Director'] . '</p>';
echo '<p>' . $film['Year'] . '</p>';
echo '<p>' . $film['Produced'] . '</p>';
echo '<p>' . $film['Language'] . '</p>';
echo '<p>' . $film['Running time'] . ' mins' . '</p>';
echo '</div>';
echo '</div>';
}
}
$columns_to_sort = ['title','director','year','produced','language'];
if (isset($_GET['sort']) && (in_array($_GET['sort'], $columns_to_sort))){
$sort = $_GET['sort'];
}
else {
$sort = 'id';
}
if (isset($_GET['sort_desc']) && ($_GET['sort_desc'] === 'on')) {
$sort_direction = 'DESC';
}
else {
$sort_direction = 'ASC';
}
$query = $db->prepare("SELECT `Title`, `Director`, `Year`,`Produced`,`Language`, `image_url`, `Running time` FROM `films` WHERE `favourite`='y' ORDER BY `" . "$sort" . "` " . "$sort_direction");
$query->execute();
$results = $query->fetchAll();
print_results($results);
?>
</div>
<h1 class="collection_header">Collection</h1>
<div class="main_container">
<?php
$query = $db->prepare("SELECT `Title`, `Director`, `Year`, `Produced`,`Language`, `image_url`, `Running time` FROM `films` ORDER BY `" . "$sort" . "` " . "$sort_direction");
$query->execute();
$results = $query->fetchAll();
print_results($results);
?>
</div>
<div class="add_new_item">
<h1 class="add_new_item_header">Add New Film</h1>
<form id="add_item" method='post' action="add_item.php">
<label for='title'>Title</label>
<input required id='title' name='title' type='text' placeholder='Film Title'>
<label for='director'>Director</label>
<input id='director' name='director' type='text' placeholder='Director'>
<label for='year'>Year released</label>
<input required id='year' name='year' type='number' placeholder='Release year' maxlength='4'>
<label for='runtime'>Runtime (mins)</label>
<input id='runtime' name='runtime' type='number' placeholder='Runtime'>
<label for='country'>Produced (country)</label>
<input id='country' name='country' type='text' placeholder='Produced (country)'>
<label for='language'>Language</label>
<input id='language' name='language' type='text' placeholder='Language'>
<label for='image_url'>Image URL</label>
<input id='image_url' name='image_url' type='text' placeholder='url'>
<label class="add_to_favourites" for="favourite"><input id="sort_direction" name="favourite" type="checkbox"><span>Add to favourites</span></label>
<input id='submit' name='submit' type='submit' value="submit">
</form>
<a class="back_to_top" href="#">back to top</a>
</div>
</main>
</body>
</html>