-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
123 lines (89 loc) · 2.77 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
<?php
session_start();
require('inc/functions.php');
require('inc/pdo.php');
$sql = "SELECT * FROM movies_full ORDER BY RAND() LIMIT 10";
$query = $pdo->prepare($sql);
$query->execute();
$movies = $query->fetchAll();
$categorys = array('drama','animation','comedy');
if (!empty($_POST['submited'])) {
debug($_POST);
$genres = array();
if(!empty($_POST['genres'])) {
$genres = $_POST['genres'];
}
$sql = "SELECT * FROM movies_full WHERE 1 = 1";
foreach($genres as $genre) {
$sql .= " AND genres LIKE :$genre";
}
if(!empty($_POST['year1']) && !empty($_POST['year2'])) {
$year1 = $_POST['year1'];
$year2 = $_POST['year2'];
$sql .= " AND (year BETWEEN :year1 AND :year2)";
}
$sql .= " ORDER BY RAND() LIMIT 10";
// prepare
$query = $pdo->prepare($sql);
// protection injection sql
foreach($genres as $genre) {
$query->bindValue(':'.$genre,'%'. $genre . '%');
}
if(!empty($_POST['year1']) && !empty($_POST['year2'])) {
$query->bindValue(':year1',$year1);
$query->bindValue(':year2',$year2);
}
// execute
$query->execute();
$movies = $query->fetchAll();
}
// debug($_POST);
// debug($movies);
require('inc/header.php'); ?>
<!-- gestion du filtre de recherche -->
<button type="button" id="button" name="button">Filtres</button>
<section id="filtre_search">
<form method="POST">
<h1>Filtre de recherche</h1>
<label for="titre">Titre Ordre croissant</label>
<input type="checkbox" name="titre" value="">
<label for="years">Choix des Années </label>
<select name="year1" id="year1">
<?php for ($i = 1887; $i < 2015; $i++) {
echo '<option value="'.$i.'">'.$i.'</option>';
} ?>
</select>
<select name="year2" id="year2">
<?php for ($i = 1888; $i < 2015; $i++) {
echo '<option value="'.$i.'">'.$i.'</option>';
} ?>
</select>
<?php foreach($categorys as $category) { ?>
<label for="<?= $category; ?>"><?= ucfirst($category); ?></label>
<input type="checkbox" name="genres[]" value="<?= $category; ?>">
<?php } ?>
<input type="submit" id="btn" name="submited" value="Rechercher">
</form>
</section>
<!-- afficher les films -->
<?php foreach ($movies as $movie): ?>
<div class="film">
<ul>
<li><?php echo imageMovie($movie); ?></li>
<li><a href="details.php?slug=<?= $movie['slug']; ?>">Voir</a></li>
</ul>
</div>
<?php endforeach; ?>
<div class="button">
<p><a href="index.php">+ de films</a></p>
</div>
<!-- gestion du filtre de recherche en javascript -->
<script type="text/javascript">
var filtre = document.getElementById('filtre_search');
var btn = document.getElementById('button');
btn.addEventListener('click' ,function(event){
event.preventDefault();
filtre.style.display = 'block';
})
</script>
<?php require('inc/footer.php');