-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_film_perso.php
225 lines (210 loc) · 7.09 KB
/
form_film_perso.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
echo "<pre>";
// outputed values
$currentId = 0;
$cat_id = 0;
$sup_id = 0;
$fil_titre = '';
$fil_annee = '';
$fil_synopsis = '';
$fil_description = '';
$fil_acteurs = '';
$fil_filename = '';
$fil_affiche = '';
require_once ('vendor/autoload.php');
try {
$movie = \Jleagle\Imdb\IMDB::retrieve($_GET['Imdb']);
/*print_r($movie);*/
$fil_titre=$movie->title;
$fil_annee=$movie->year;
$monCat=$movie->genre;
$fil_acteurs=$movie->actors;
$fil_synopsis=$movie->plot;
$fil_synopsis=$movie->plot;
$fil_affiche=$movie->poster;
} catch (Exception $e) {
echo "non-existent";
}
//echo "Title:$fil_titre<br>Year:$fil_annee<br>Genre:$monCat<br>Actors:$fil_acteurs<br>Plot:$fil_synopsis<br>$fil_synopsis<br>$fil_affiche";
//exit;
echo "</pre>";
$dsn = 'mysql:dbname=movie_ganderer;host=127.0.0.1;charset=UTF8';
$user = 'root';
$password = '+webForce3';
// Effectuer la connexion
$pdo = new PDO($dsn, $user, $password);
//require 'inc/fonctions.php';
if (!empty($_POST)) {
//print_pre($_POST);
$fil_id = isset($_POST['fil_id']) ? intval(trim($_POST['fil_id'])) : 0;
$cat_id = isset($_POST['cat_id']) ? intval(trim($_POST['cat_id'])) : 0;
$sup_id = isset($_POST['sup_id']) ? intval(trim($_POST['sup_id'])) : 0;
$fil_titre = isset($_POST['fil_titre']) ? trim($_POST['fil_titre']) : '';
$fil_annee = isset($_POST['fil_annee']) ? trim($_POST['fil_annee']) : 0;
$fil_synopsis = isset($_POST['fil_synopsis']) ? trim($_POST['fil_synopsis']) : '';
$fil_description = isset($_POST['fil_description']) ? trim($_POST['fil_description']) : '';
$fil_acteurs = isset($_POST['fil_acteurs']) ? trim($_POST['fil_acteurs']) : '';
$fil_filename = isset($_POST['fil_filename']) ? trim($_POST['fil_filename']) : '';
$fil_affiche = isset($_POST['fil_affiche']) ? trim($_POST['fil_affiche']) : '';
// update
if ($fil_id > 0) {
$updateSQL = '
UPDATE film
SET fil_titre = :titre,
fil_annee = :annee,
fil_synopsis = :synopsis,
fil_description = :description,
fil_acteurs = :acteurs,
fil_filename = :filename,
fil_affiche = :affiche,
cat_id = :cat_id,
sup_id = :sup_id
WHERE fil_id = :fil_id
';
$pdoStatement = $pdo->prepare($updateSQL);
$pdoStatement->bindValue(':titre', $fil_titre);
$pdoStatement->bindValue(':annee', $fil_annee);
$pdoStatement->bindValue(':synopsis', $fil_synopsis);
$pdoStatement->bindValue(':description', $fil_description);
$pdoStatement->bindValue(':acteurs', $fil_acteurs);
$pdoStatement->bindValue(':filename', $fil_filename);
$pdoStatement->bindValue(':affiche', $fil_affiche);
$pdoStatement->bindValue(':fil_id', $fil_id);
$pdoStatement->bindValue(':cat_id', $cat_id);
$pdoStatement->bindValue(':sup_id', $sup_id);
if ($pdoStatement->execute()) {
header('Location: form_film.php?id='.$fil_id);
exit;
}
}
else {
$insertInto = '
INSERT INTO film (fil_titre, fil_annee, fil_synopsis, fil_description, fil_acteurs, fil_filename, fil_affiche,cat_id,sup_id)
VALUES (:titre, :annee, :synopsis, :description, :acteurs, :filename, :affiche, :cat_id, :sup_id)
';
$pdoStatement = $pdo->prepare($insertInto);
$pdoStatement->bindValue(':titre', $fil_titre);
$pdoStatement->bindValue(':annee', $fil_annee);
$pdoStatement->bindValue(':synopsis', $fil_synopsis);
$pdoStatement->bindValue(':description', $fil_description);
$pdoStatement->bindValue(':acteurs', $fil_acteurs);
$pdoStatement->bindValue(':filename', $fil_filename);
$pdoStatement->bindValue(':affiche', $fil_affiche);
$pdoStatement->bindValue(':cat_id', $cat_id);
$pdoStatement->bindValue(':sup_id', $sup_id);
if ($pdoStatement->execute()) {
$newId = $pdo->lastInsertId();
header('Location: form_film.php?id='.$newId);
exit;
}
}
}
if (isset($_GET['id'])) {
$currentId = intval($_GET['id']);
$sql = 'SELECT cat_id, sup_id, fil_titre, fil_annee, fil_synopsis, fil_description, fil_acteurs, fil_filename, fil_affiche
FROM film
WHERE fil_id = '.$currentId;
$pdoStatement = $pdo->query($sql);
if ($pdoStatement && $pdoStatement->rowCount() > 0) {
$resList = $pdoStatement->fetch();
foreach ($resList as $curIndex=>$curValue) {
$$curIndex = $curValue;
}
}
}
// Récupère toutes les catégories pour générer le menu déroulant des catégories
$sql = '
SELECT cat_id, cat_nom
FROM categorie
';
$pdoStatement = $pdo->query($sql);
if ($pdoStatement && $pdoStatement->rowCount() > 0) {
$categoriesList = $pdoStatement->fetchAll();
}
// Récupère tous les supports pour générer le menu déroulant des supports
$sql = '
SELECT sup_id, sup_nom
FROM support
';
$pdoStatement = $pdo->query($sql);
if ($pdoStatement && $pdoStatement->rowCount() > 0) {
$supportsList = $pdoStatement->fetchAll();
}
//retrieveInfo
//$movie=
?>
<html>
<head>
<title>GCLF</title>
</head>
<body>
<form>
<h3>faites votre requete</h3>
<input type="text" method="get" value="" name="Imdb">
<input type="submit" value="Valider"/>
</form>
<form action="" method="post">
<legend>Gestion de film</legend>
<fieldset>
<input type="hidden" name="fil_id" value="<?php echo $currentId; ?>" />
<table>
<tr>
<td>Titre : </td>
<td><input type="text" name="fil_titre" value="<?php echo $fil_titre; ?>"/></td>
</tr>
<tr>
<td>Catégorie : </td>
<td><select name="cat_id">
<option value="">choisissez</option>
<?php foreach ($categoriesList as $curCategorie) : ?>
<option value="<?php echo $curCategorie['cat_id']; ?>"<?php echo $cat_id == $curCategorie['cat_id'] ? ' selected="selected"' : ''; ?>><?php echo $curCategorie['cat_nom']; ?></option>
<?php endforeach; ?>
</select></td>
</tr>
<tr>
<td>Support : </td>
<td><select name="sup_id">
<option value="">choisissez</option>
<?php foreach ($supportsList as $curSupport) : ?>
<option value="<?php echo $curSupport['sup_id']; ?>"<?php echo $sup_id == $curSupport['sup_id'] ? ' selected="selected"' : ''; ?>><?php echo $curSupport['sup_nom']; ?></option>
<?php endforeach; ?>
</select></td>
</tr>
<tr>
<td>Année : </td>
<td><select name="fil_annee">
<option value="">choisissez :</option>
<?php for ($annee=date('Y');$annee>1970;$annee--) : ?>
<option value="<?php echo $annee; ?>"<?php echo $fil_annee==$annee ? ' selected="selected"' : ''; ?>><?php echo $annee; ?></option>
<?php endfor; ?>
</select></td>
</tr>
<tr>
<td>Synopsis : </td>
<td><textarea name="fil_synopsis" rows="5" cols="100"><?php echo $fil_synopsis; ?></textarea></td>
</tr>
<tr>
<td>Description : </td>
<td><textarea name="fil_description" rows="12" cols="100"><?php echo $fil_synopsis; ?></textarea></td>
</tr>
<tr>
<td>Acteur(s)/Actrice(s) : </td>
<td><input type="text" name="fil_acteurs" value="<?php echo $fil_acteurs; ?>"/></td>
</tr>
<tr>
<td>Fichier : </td>
<td><input type="text" name="fil_filename" value="<?php echo $fil_filename; ?>"/></td>
</tr>
<tr>
<td>Affiche : </td>
<td><input type="text" name="fil_affiche" value="<?php echo $fil_affiche; ?>"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Valider"/></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>