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
| <?php
mysql_connect("*******", "*******", "********");
mysql_select_db("********");
if (isset($_GET['supprimer_film'])) // Si on demande de supprimer un film
{
// On protège la variable "id" pour éviter une faille SQL
$_GET['supprimer_film'] = addslashes($_GET['supprimer_film']);
mysql_query('DELETE FROM film WHERE id=\'' . $_GET['supprimer_film'] . '\'');
mysql_query('DELETE FROM horaire WHERE idfilm=\'' . $_GET['supprimer_film'] . '\'');
}
if (
isset($_POST['nomfilm']) AND
isset($_POST['realisateurfilm']) AND
isset($_POST['synopsis']) AND
isset($_POST['bandeannoncefilm']) AND
isset($_POST['jourdebut']))
{
$nomfilm = $_POST['nomfilm'];
$acteurfilm = $_POST['acteurfilm'];
$realisateurfilm = $_POST['realisateurfilm'];
$synopsis = $_POST['synopsis'];
$bandeannoncefilm = $_POST['bandeannoncefilm'];
$jourdebut = $_POST['jourdebut'];
$prochainement = $_POST['prochainement'];
$publicfilm = $_POST['publicfilm'];
$genrefilm = $_POST['genrefilm'];
$indicefilm = $_POST['indicefilm'];
$handicape = $_POST['handicape'];
$date_exploser = explode('/', $jourdebut);
$jourfin = date("Y-m-d", mktime(0,0,0,$date_exploser[1], $date_exploser[2]+7, $date_exploser[0]));
$horaire = $_POST['horaire'];
// On vérifie si c'est une modification de film ou pas
if ($_POST['id'] == 0 AND
isset($_FILES['affichefilm'])&&($_FILES['affichefilm']['error'] == 0))
{
$heure = $_POST['heure'];
$minute = $_POST['minute'];
$dureefilm = $heure."h".$minute;
$affichefilm = $_FILES['affichefilm']['name'];
$ext = $_FILES['affichefilm']['name'];
$ext = strrchr(strtolower($ext), '.');
// Ce n'est pas une modification, on crée une nouvelle entrée dans la table
mysql_query("INSERT INTO film VALUES('', '".utf8_decode($nomfilm)."', 'images/', '".utf8_decode($realisateurfilm)."', '".utf8_decode($acteurfilm)."', '".utf8_decode($synopsis)."', '".utf8_decode($bandeannoncefilm)."', '".$dureefilm."', '".$jourdebut."', '".$jourfin."', '".$prochainement."', '".utf8_decode($publicfilm)."', '".utf8_decode($genrefilm)."', '" .$indicefilm. "', '" .$handicape. "', '', '', '')");
$dernier_id = mysql_insert_id();
//Renomnage de l'image puis upload.
$nomfichier = mysql_insert_id().$ext;
move_uploaded_file($_FILES['affichefilm']['tmp_name'], '../images/films/'.$nomfichier);
$test = mysql_query("UPDATE film SET affichefilm='images/films/".$nomfichier."' WHERE id='".$dernier_id."'");
$horaire = $_POST["horaire"];
//Boucle pour rentrer les valeurs des horaires pour chaque jours b.
for ($b=0; $b<7; $b++){
mysql_query("INSERT INTO horaire VALUES('', '".$dernier_id."', '".$b."', '".$horaire[$b][0].$horaire[$b][1].$horaire[$b][2]."<br />".$horaire[$b][3]."')");
}
echo '<h2 align="center">Nouveau film enregistré</h2><br />';
}
else
{
$dureefilm = $_POST['dureefilm'];
// On protège la variable "id" pour éviter une faille SQL
$_POST['id'] = addslashes($_POST['id']);
// C'est une modification, on met juste à jour
mysql_query("UPDATE film SET nomfilm='".utf8_decode($nomfilm)."', realisateurfilm='".utf8_decode($realisateurfilm)."', acteurfilm='".utf8_decode($acteurfilm)."', synopsis='".utf8_decode($synopsis)."', bandeannoncefilm='".utf8_decode($bandeannoncefilm)."', dureefilm='" . $dureefilm . "', genrefilm='" .utf8_decode($genrefilm) . "', indicefilm='". $indicefilm ."', publicfilm='" . $publicfilm ."', datedebutfilm='" . $jourdebut . "', datefinfilm='" . $jourfin . "', prochainement='" . $prochainement . "', handicape='" . $handicape . "' WHERE id='" . $_POST['id'] . "'");
mysql_query("DELETE FROM horaire WHERE idfilm='" . $_POST['id'] . "'");
for ($b=0; $b<7; $b++){
mysql_query("INSERT INTO horaire VALUES('', '" . $_POST['id'] . "', '".$b."', '".$horaire[$b][0].$horaire[$b][1].$horaire[$b][2]."<br />".$horaire[$b][3]."')");
}
echo '<h2 align="center">Modification film enregistrée</h2><br />';
}
}
?>
<h3 align="center"><a href="admin_rediger.php">Ajouter un film</a></h3><br />
<table width="500px;" border="1" align="center"><tr>
<th>Titre du film</th>
<th>Modification</th>
<th>Suppression</th>
</tr>
<?php
$retour = mysql_query('SELECT * FROM film ORDER BY id DESC');
while ($donnees = mysql_fetch_array($retour)) // On fait une boucle pour lister les films
{
?>
<tr>
<td align="left"><?php echo htmlentities(trim($donnees['nomfilm'])); ?></td>
<td align="center"><?php echo '<a href="admin_rediger.php?modifier_film=' . $donnees['id'] . '">'; ?>Modifier</a></td>
<td align="center"><?php echo '<a href="admin_modifier.php?supprimer_film=' . $donnees['id'] . '">'; ?>Supprimer</a></td>
</tr>
<?php
} // Fin de la boucle qui liste les films
?> |
Partager