Ajout d'un code en rapideeeeee
This commit is contained in:
		
							
								
								
									
										18
									
								
								TP3/code/css/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								TP3/code/css/style.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
table{
 | 
			
		||||
	width:100%;
 | 
			
		||||
}
 | 
			
		||||
img{
 | 
			
		||||
width:500px;
 | 
			
		||||
}
 | 
			
		||||
td + td + td + td{
 | 
			
		||||
width : 20%;
 | 
			
		||||
}
 | 
			
		||||
td:first-child + td{
 | 
			
		||||
width:10%;
 | 
			
		||||
}
 | 
			
		||||
td:first-child{
 | 
			
		||||
width:30%;
 | 
			
		||||
}
 | 
			
		||||
td:first-child + td + td {
 | 
			
		||||
width:30%;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								TP3/code/fiche.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								TP3/code/fiche.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
<?php
 | 
			
		||||
include './modeles/modeleFilms.php';
 | 
			
		||||
 | 
			
		||||
// Récupération de l'ID du film
 | 
			
		||||
$film_id = isset($_GET['film']) ? intval($_GET['film']) : 0;
 | 
			
		||||
 | 
			
		||||
// Vérification de l'ID du film
 | 
			
		||||
if ($film_id <= 0) {
 | 
			
		||||
    die("ID de film invalide");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Récupération des données du film
 | 
			
		||||
$film = getFilmById($film_id);
 | 
			
		||||
 | 
			
		||||
// Vérification si le film existe 
 | 
			
		||||
if (!$film) {
 | 
			
		||||
    die("Film non trouvé");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// on "charge" la vue 
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
include './vues/header.php';
 | 
			
		||||
include './vues/vueFiche.php';
 | 
			
		||||
include './vues/footer.php';
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										27
									
								
								TP3/code/films.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								TP3/code/films.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
<?php
 | 
			
		||||
include './modeles/modeleFilms.php';
 | 
			
		||||
 | 
			
		||||
// Récupération des paramètres. En gros on va chercher les valeurs passées dans l'URL
 | 
			
		||||
// Par exemple si 'https://iut-fbleau.fr/films.php?realisateur=1&tri=note&limit=10'
 | 
			
		||||
// Tout ce qui est après le '?' est considéré comme un paramètre
 | 
			
		||||
$realisateur_id = isset($_GET['realisateur']) ? $_GET['realisateur'] : null;
 | 
			
		||||
$tri = isset($_GET['tri']) ? $_GET['tri'] : 'titre'; // Isset permet de vérifier si une variable est définie
 | 
			
		||||
$limit = isset($_GET['limit']) ? $_GET['limit'] : null; // Si limit n'est pas défini, on ne l'utilise pas dans la requête SQL
 | 
			
		||||
 | 
			
		||||
// Récupération des données
 | 
			
		||||
$films = getFilms($realisateur_id, $tri, $limit);
 | 
			
		||||
$nombreTotal = getNombreFilmsTotal();
 | 
			
		||||
$realisateurs = getRealisateurs();
 | 
			
		||||
 | 
			
		||||
// Variables pour la vue
 | 
			
		||||
$realisateur_selectionne = $realisateur_id;
 | 
			
		||||
$tri_actuel = $tri;
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// on "charge" la vue 
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
include './vues/header.php';
 | 
			
		||||
include './vues/vueFilms.php';
 | 
			
		||||
include './vues/footer.php';
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										105
									
								
								TP3/code/modeles/modeleFilms.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								TP3/code/modeles/modeleFilms.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,105 @@
 | 
			
		||||
<?php
 | 
			
		||||
function _getConnection()
 | 
			
		||||
{
 | 
			
		||||
	static $_conn = NULL;
 | 
			
		||||
	if ($_conn === NULL){
 | 
			
		||||
		$_conn = mysqli_connect("localhost", "votre_utilisateur", "votre_mot_de_passe", "votre_base_de_donnees");
 | 
			
		||||
		if (!$_conn) {
 | 
			
		||||
			die("Erreur de connexion : " . mysqli_connect_error());
 | 
			
		||||
		}
 | 
			
		||||
		mysqli_set_charset($_conn, "utf8");
 | 
			
		||||
	}
 | 
			
		||||
	return $_conn;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getFilms($realisateur_id = null, $tri = 'titre', $limit = null)
 | 
			
		||||
{
 | 
			
		||||
	$conn = _getConnection();
 | 
			
		||||
	
 | 
			
		||||
	// Construction de la requête de base
 | 
			
		||||
	$sql = "SELECT SQL_CALC_FOUND_ROWS f.idFilm, f.titre, f.annee, f.genre, a.nom, a.prenom 
 | 
			
		||||
			FROM Film f 
 | 
			
		||||
			INNER JOIN Artiste a ON f.idMes = a.idArtiste";
 | 
			
		||||
	
 | 
			
		||||
	// Ajout du filtre par réalisateur si spécifié
 | 
			
		||||
	if ($realisateur_id !== null && $realisateur_id !== '') {
 | 
			
		||||
		$sql .= " WHERE f.idMes = " . intval($realisateur_id);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// Ajout du tri
 | 
			
		||||
	$colonnes_autorisees = ['titre', 'annee', 'genre', 'nom'];
 | 
			
		||||
	if (in_array($tri, $colonnes_autorisees)) {
 | 
			
		||||
		$sql .= " ORDER BY ";
 | 
			
		||||
		if ($tri === 'nom') {
 | 
			
		||||
			$sql .= "a.nom, a.prenom";
 | 
			
		||||
		} else if ($tri === 'titre' || $tri === 'annee' || $tri === 'genre') {
 | 
			
		||||
			$sql .= "f." . $tri;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	// Ajout de la limite si spécifiée
 | 
			
		||||
	if ($limit !== null) {
 | 
			
		||||
		$sql .= " LIMIT " . intval($limit);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	$result = mysqli_query($conn, $sql);
 | 
			
		||||
	
 | 
			
		||||
	if (!$result) {
 | 
			
		||||
		die("Erreur dans la requête : " . mysqli_error($conn));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	$films = [];
 | 
			
		||||
	while ($row = mysqli_fetch_assoc($result)) {
 | 
			
		||||
		$films[] = $row;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return $films;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getNombreFilmsTotal()
 | 
			
		||||
{
 | 
			
		||||
	$conn = _getConnection();
 | 
			
		||||
	$result = mysqli_query($conn, "SELECT FOUND_ROWS() as total");
 | 
			
		||||
	$row = mysqli_fetch_assoc($result);
 | 
			
		||||
	return $row['total'];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getRealisateurs()
 | 
			
		||||
{
 | 
			
		||||
	$conn = _getConnection();
 | 
			
		||||
	$sql = "SELECT DISTINCT a.idArtiste, a.nom, a.prenom 
 | 
			
		||||
			FROM Artiste a 
 | 
			
		||||
			INNER JOIN Film f ON a.idArtiste = f.idMes 
 | 
			
		||||
			ORDER BY a.nom, a.prenom";
 | 
			
		||||
	
 | 
			
		||||
	$result = mysqli_query($conn, $sql);
 | 
			
		||||
	
 | 
			
		||||
	if (!$result) {
 | 
			
		||||
		die("Erreur dans la requête : " . mysqli_error($conn));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	$realisateurs = [];
 | 
			
		||||
	while ($row = mysqli_fetch_assoc($result)) {
 | 
			
		||||
		$realisateurs[] = $row;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return $realisateurs;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getFilmById($id)
 | 
			
		||||
{
 | 
			
		||||
	$conn = _getConnection();
 | 
			
		||||
	$sql = "SELECT f.idFilm, f.titre, f.annee, f.genre, f.resume, a.nom, a.prenom 
 | 
			
		||||
			FROM Film f 
 | 
			
		||||
			INNER JOIN Artiste a ON f.idMes = a.idArtiste 
 | 
			
		||||
			WHERE f.idFilm = " . intval($id);
 | 
			
		||||
	
 | 
			
		||||
	$result = mysqli_query($conn, $sql);
 | 
			
		||||
	
 | 
			
		||||
	if (!$result) {
 | 
			
		||||
		die("Erreur dans la requête : " . mysqli_error($conn));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return mysqli_fetch_assoc($result);
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										3
									
								
								TP3/code/vues/footer.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								TP3/code/vues/footer.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
      </main>
 | 
			
		||||
	</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										14
									
								
								TP3/code/vues/header.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								TP3/code/vues/header.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="fr">
 | 
			
		||||
	<head>
 | 
			
		||||
		<meta charset="UTF-8" />
 | 
			
		||||
		<title>Films</title>
 | 
			
		||||
		<link
 | 
			
		||||
			rel="stylesheet"
 | 
			
		||||
			href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
 | 
			
		||||
		/>
 | 
			
		||||
 | 
			
		||||
		<link rel="stylesheet" href="./css/style.css">
 | 
			
		||||
	</head>
 | 
			
		||||
	<body>
 | 
			
		||||
		<main class="container">
 | 
			
		||||
							
								
								
									
										35
									
								
								TP3/code/vues/vueFiche.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								TP3/code/vues/vueFiche.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<!-- 
 | 
			
		||||
	Variables de la vue
 | 
			
		||||
	$film : données du film
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<h2>Fiche Film</h2>
 | 
			
		||||
 | 
			
		||||
<div style="max-width: 600px;">
 | 
			
		||||
	<h3><?= htmlspecialchars($film['titre']) ?></h3>
 | 
			
		||||
	
 | 
			
		||||
	<table style="width: 100%; border-collapse: collapse;">
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td style="font-weight: bold; padding: 8px; border: 1px solid #ddd; background-color: #f9f9f9;">Année :</td>
 | 
			
		||||
			<td style="padding: 8px; border: 1px solid #ddd;"><?= htmlspecialchars($film['annee']) ?></td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td style="font-weight: bold; padding: 8px; border: 1px solid #ddd; background-color: #f9f9f9;">Genre :</td>
 | 
			
		||||
			<td style="padding: 8px; border: 1px solid #ddd;"><?= htmlspecialchars($film['genre']) ?></td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td style="font-weight: bold; padding: 8px; border: 1px solid #ddd; background-color: #f9f9f9;">Réalisateur :</td>
 | 
			
		||||
			<td style="padding: 8px; border: 1px solid #ddd;"><?= htmlspecialchars($film['prenom'] . ' ' . $film['nom']) ?></td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<?php if (!empty($film['resume'])): ?>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td style="font-weight: bold; padding: 8px; border: 1px solid #ddd; background-color: #f9f9f9;">Résumé :</td>
 | 
			
		||||
			<td style="padding: 8px; border: 1px solid #ddd;"><?= nl2br(htmlspecialchars($film['resume'])) ?></td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<?php endif; ?>
 | 
			
		||||
	</table>
 | 
			
		||||
	
 | 
			
		||||
	<div style="margin-top: 20px;">
 | 
			
		||||
		<a href="films.php" style="text-decoration: none; color: #0066cc;">← Retour à la liste des films</a>
 | 
			
		||||
	</div>
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										92
									
								
								TP3/code/vues/vueFilms.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								TP3/code/vues/vueFilms.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
			
		||||
<!-- 
 | 
			
		||||
	Variables de la vue
 | 
			
		||||
	$films : les films de la page
 | 
			
		||||
	$realisateurs : liste des réalisateurs
 | 
			
		||||
	$realisateur_selectionne : ID du réalisateur sélectionné
 | 
			
		||||
	$tri_actuel : critère de tri actuel
 | 
			
		||||
	$nombreTotal : nombre total de films
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
<h2>Films</h2>
 | 
			
		||||
 | 
			
		||||
<!-- Formulaire de filtrage par réalisateur -->
 | 
			
		||||
<form method="GET" action="films.php" style="margin-bottom: 20px;">
 | 
			
		||||
	<label for="realisateur">Filtrer par réalisateur :</label>
 | 
			
		||||
	<select name="realisateur" id="realisateur" onchange="this.form.submit()">
 | 
			
		||||
		<option value="">-- Tous les réalisateurs --</option>
 | 
			
		||||
		<?php foreach($realisateurs as $realisateur): ?>
 | 
			
		||||
			<option value="<?= $realisateur['id'] ?>" 
 | 
			
		||||
					<?= ($realisateur_selectionne == $realisateur['id']) ? 'selected' : '' ?>>
 | 
			
		||||
				<?= htmlspecialchars($realisateur['prenom'] . ' ' . $realisateur['nom']) ?>
 | 
			
		||||
			</option>
 | 
			
		||||
		<?php endforeach; ?>
 | 
			
		||||
	</select>
 | 
			
		||||
	
 | 
			
		||||
	<!-- Maintenir les autres paramètres -->
 | 
			
		||||
	<input type="hidden" name="tri" value="<?= htmlspecialchars($tri_actuel) ?>">
 | 
			
		||||
</form>
 | 
			
		||||
 | 
			
		||||
<!-- Liens de tri -->
 | 
			
		||||
<div style="margin-bottom: 15px;">
 | 
			
		||||
	<strong>Trier par :</strong>
 | 
			
		||||
	<?php 
 | 
			
		||||
	$url_base = "films.php?";
 | 
			
		||||
	if ($realisateur_selectionne) {
 | 
			
		||||
		$url_base .= "realisateur=" . $realisateur_selectionne . "&";
 | 
			
		||||
	}
 | 
			
		||||
	?>
 | 
			
		||||
	<a href="<?= $url_base ?>tri=titre" <?= ($tri_actuel == 'titre') ? 'style="font-weight: bold;"' : '' ?>>Titre</a> |
 | 
			
		||||
	<a href="<?= $url_base ?>tri=annee" <?= ($tri_actuel == 'annee') ? 'style="font-weight: bold;"' : '' ?>>Année</a> |
 | 
			
		||||
	<a href="<?= $url_base ?>tri=genre" <?= ($tri_actuel == 'genre') ? 'style="font-weight: bold;"' : '' ?>>Genre</a> |
 | 
			
		||||
	<a href="<?= $url_base ?>tri=nom" <?= ($tri_actuel == 'nom') ? 'style="font-weight: bold;"' : '' ?>>Réalisateur</a>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<!-- Affichage du nombre de résultats -->
 | 
			
		||||
<p><em><?= count($films) ?> film(s) affiché(s) sur <?= $nombreTotal ?> au total</em></p>
 | 
			
		||||
 | 
			
		||||
<!-- Tableau des films -->
 | 
			
		||||
<table border="1" cellpadding="8" cellspacing="0" style="border-collapse: collapse; width: 100%;">
 | 
			
		||||
	<thead>
 | 
			
		||||
		<tr style="background-color: #f0f0f0;">
 | 
			
		||||
			<th>Titre</th>
 | 
			
		||||
			<th>Année</th>
 | 
			
		||||
			<th>Genre</th>
 | 
			
		||||
			<th>Réalisateur</th>
 | 
			
		||||
		</tr>
 | 
			
		||||
	</thead>
 | 
			
		||||
	<tbody>
 | 
			
		||||
<?php if (empty($films)): ?>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td colspan="4" style="text-align: center; font-style: italic;">Aucun film trouvé</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
<?php else: ?>
 | 
			
		||||
	<?php foreach($films as $film): ?>
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td>
 | 
			
		||||
				<a href="./fiche.php?film=<?= $film['idFilm'] ?>" style="text-decoration: none; color: #0066cc;">
 | 
			
		||||
					<?= htmlspecialchars($film['titre']) ?>
 | 
			
		||||
				</a>
 | 
			
		||||
			</td>
 | 
			
		||||
			<td><?= htmlspecialchars($film['annee']) ?></td>
 | 
			
		||||
			<td><?= htmlspecialchars($film['genre']) ?></td>
 | 
			
		||||
			<td><?= htmlspecialchars($film['prenom'] . ' ' . $film['nom']) ?></td>
 | 
			
		||||
		</tr>
 | 
			
		||||
	<?php endforeach; ?>
 | 
			
		||||
<?php endif; ?>
 | 
			
		||||
	</tbody>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
<!-- Exemple de limitation avec LIMIT -->
 | 
			
		||||
<div style="margin-top: 20px;">
 | 
			
		||||
	<strong>Affichage limité :</strong>
 | 
			
		||||
	<?php 
 | 
			
		||||
	$url_limit = "films.php?";
 | 
			
		||||
	if ($realisateur_selectionne) {
 | 
			
		||||
		$url_limit .= "realisateur=" . $realisateur_selectionne . "&";
 | 
			
		||||
	}
 | 
			
		||||
	$url_limit .= "tri=" . $tri_actuel . "&";
 | 
			
		||||
	?>
 | 
			
		||||
	<a href="<?= $url_limit ?>limit=5">5 premiers</a> |
 | 
			
		||||
	<a href="<?= $url_limit ?>limit=10">10 premiers</a> |
 | 
			
		||||
	<a href="<?= $url_limit ?>">Tous</a>
 | 
			
		||||
</div>
 | 
			
		||||
		Reference in New Issue
	
	Block a user