From e7ff8c541691dccfb412aa217e55503efe9704f8 Mon Sep 17 00:00:00 2001 From: Whykioh Date: Mon, 13 Apr 2026 02:50:24 +0200 Subject: [PATCH 1/3] aa --- watchgether/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watchgether/index.php b/watchgether/index.php index 0d9c6b7..aa6cb93 100644 --- a/watchgether/index.php +++ b/watchgether/index.php @@ -20,7 +20,7 @@
- + \ No newline at end of file From 81b39e856b0eb41f1eb5c116d7df967318e28d0d Mon Sep 17 00:00:00 2001 From: Whykioh Date: Mon, 13 Apr 2026 02:50:52 +0200 Subject: [PATCH 2/3] dd --- watchgether/index.php | 2 +- watchgether/ma-liste/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/watchgether/index.php b/watchgether/index.php index aa6cb93..073ef86 100644 --- a/watchgether/index.php +++ b/watchgether/index.php @@ -20,7 +20,7 @@
- + \ No newline at end of file diff --git a/watchgether/ma-liste/index.php b/watchgether/ma-liste/index.php index d17a2cc..53f82f5 100644 --- a/watchgether/ma-liste/index.php +++ b/watchgether/ma-liste/index.php @@ -50,7 +50,7 @@ - + From 5463a3220a605d9c99bda3e0f66ad1de07548f26 Mon Sep 17 00:00:00 2001 From: Whykioh Date: Mon, 27 Apr 2026 08:47:35 +0200 Subject: [PATCH 3/3] aa --- watchgether/RequestHandler.php | 97 ++++++++-- watchgether/index.php | 45 +++-- watchgether/js/list.js | 242 +++++++++++++++++++++++-- watchgether/js/{index.js => search.js} | 26 ++- watchgether/ma-liste/index.php | 27 ++- watchgether/modal-template.php | 22 ++- watchgether/search/index.php | 45 +++++ 7 files changed, 452 insertions(+), 52 deletions(-) rename watchgether/js/{index.js => search.js} (87%) create mode 100644 watchgether/search/index.php diff --git a/watchgether/RequestHandler.php b/watchgether/RequestHandler.php index 866b03c..0b3dd22 100644 --- a/watchgether/RequestHandler.php +++ b/watchgether/RequestHandler.php @@ -55,16 +55,24 @@ switch ($action) { // --- GESTION DES FILMS --- case 'addMovie': - $stmt = $pdo->prepare("INSERT INTO movies (tmdb_id, titre, affiche_path, type, user_id, vu) VALUES (?, ?, ?, ?, ?, 0)"); - $success = $stmt->execute([ - $params['tmdb_id'], - $params['titre'], - $params['affiche_path'], - $params['type'], // 'film' ou 'serie' - $current_user_id - ]); - echo json_encode(['success' => $success]); - exit; + // On cherche si le film existe déjà pour cet utilisateur + $stmt = $pdo->prepare("SELECT id FROM movies WHERE tmdb_id = ? AND user_id = ?"); + $stmt->execute([$params['tmdb_id'], $current_user_id]); + if ($stmt->fetch()) { + echo json_encode(['success' => false, 'error' => 'Film déjà dans la liste']); + exit; + } else { + $stmt = $pdo->prepare("INSERT INTO movies (tmdb_id, titre, affiche_path, type, user_id, vu) VALUES (?, ?, ?, ?, ?, 0)"); + $success = $stmt->execute([ + $params['tmdb_id'], + $params['titre'], + $params['affiche_path'], + $params['type'], // 'film' ou 'serie' + $current_user_id + ]); + echo json_encode(['success' => $success]); + exit; + } case 'getMyList': // Récupère les films ajoutés par l'utilisateur @@ -86,12 +94,19 @@ switch ($action) { $stmt->execute([$current_user_id, $partner_id]); echo json_encode(['success' => true, 'common_movies' => $stmt->fetchAll()]); exit; + + case 'getPartnerList': + $partner_id = ($current_user_id == 1) ? 2 : 1; + $stmt = $pdo->prepare("SELECT * FROM movies WHERE user_id = ? ORDER BY date_ajout DESC"); + $stmt->execute([$partner_id]); + echo json_encode(['success' => true, 'movies' => $stmt->fetchAll()]); + exit; // --- ACTIONS SUR LE FILM --- case 'toggleViewed': // Alterne entre vu (1) et non vu (0) - $stmt = $pdo->prepare("UPDATE movies SET vu = !vu WHERE id = ? AND user_id = ?"); - $success = $stmt->execute([(int)$params['movie_id'], $current_user_id]); + $stmt = $pdo->prepare("UPDATE movies SET vu = !vu WHERE id = ?"); + $success = $stmt->execute([(int)$params['movie_id']]); echo json_encode(['success' => $success]); exit; @@ -112,6 +127,16 @@ switch ($action) { echo json_encode(['success' => $success]); exit; + case 'getComments': + $stmt = $pdo->prepare(" + SELECT c.*, u.pseudo FROM commentaires c + JOIN users u ON c.user_id = u.id + WHERE c.movie_id = ? ORDER BY c.date_ajout DESC + "); + $stmt->execute([(int)$params['movie_id']]); + echo json_encode(['success' => true, 'comments' => $stmt->fetchAll()]); + exit; + case 'getMovieDetails': $id = $params['id']; $type = $params['type']; // 'movie' ou 'tv' @@ -121,6 +146,54 @@ switch ($action) { $response = file_get_contents($url); echo $response; exit; + + case 'setStarsRating': + $stmt = $pdo->prepare("INSERT INTO movies (rating) VALUES (?) WHERE id = ?"); + $success = $stmt->execute([ + (int)$params['movie_id'], + (int)$params['rating'] + ]); + echo json_encode(['success' => $success]); + exit; + + case 'getStarsRating': + $stmt = $pdo->prepare("SELECT rating FROM movies WHERE id = ?"); + $stmt->execute([(int)$params['movie_id']]); + $rating = $stmt->fetchColumn(); + echo json_encode(['success' => true, 'rating' => $rating]); + exit; + + case 'register': + $pseudo = $params['pseudo']; + $pass = password_hash($params['password'], PASSWORD_DEFAULT); + + $stmt = $pdo->prepare("INSERT INTO users (pseudo, password) VALUES (?, ?)"); + try { + $stmt->execute([$pseudo, $pass]); + echo json_encode(['success' => true]); + } catch (Exception $e) { + echo json_encode(['success' => false, 'error' => 'Pseudo déjà pris']); + } + exit; + + case 'login': + $stmt = $pdo->prepare("SELECT * FROM users WHERE pseudo = ?"); + $stmt->execute([$params['pseudo']]); + $user = $stmt->fetch(); + + if ($user && password_verify($params['password'], $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['pseudo'] = $user['pseudo']; + echo json_encode(['success' => true]); + } else { + echo json_encode(['success' => false, 'error' => 'Identifiants incorrects']); + } + exit; + + case 'logout': + session_destroy(); + echo json_encode(['success' => true]); + exit; default: echo json_encode(['success' => false, 'error' => 'Action inconnue']); diff --git a/watchgether/index.php b/watchgether/index.php index 073ef86..333d9a7 100644 --- a/watchgether/index.php +++ b/watchgether/index.php @@ -2,25 +2,42 @@ - WatchGether - Recherche + WatchGether - Connexion - + -
-

WatchGether

+
+

WATCHGETHER

-
- - +
+ + + + +
- -
- - + + \ No newline at end of file diff --git a/watchgether/js/list.js b/watchgether/js/list.js index c8bf981..0777454 100644 --- a/watchgether/js/list.js +++ b/watchgether/js/list.js @@ -1,7 +1,46 @@ let allMovies = []; // Stockage local de la liste entière +window.onload = () => { + loadList(); + document.getElementById('sortOrder').addEventListener('change', renderList); + document.getElementById('filterType').addEventListener('change', renderList); + document.getElementById('filterStatus').addEventListener('change', renderList); +} + +async function apiRequest(action, params = {}) { + try { + const response = await fetch('../RequestHandler.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ action, params }) + }); + return await response.json(); + } catch (error) { + console.error("Erreur API:", error); + return { success: false, error: "Erreur de connexion au serveur" }; + } +} + +async function addMovie(tmdbId, title, posterPath, type) { + const result = await apiRequest('addMovie', { + tmdb_id: tmdbId, + titre: title, + affiche_path: posterPath, + type: type + }); + + if (result.success) { + alert(`"${title}" a été ajouté à votre liste ! 🍿`); + closeModal(); + } else { + alert('Erreur lors de l\'ajout. Vérifie si le film n\'est pas déjà présent.'); + } +} + async function loadList() { - const response = await fetch('RequestHandler.php', { + const response = await fetch('../RequestHandler.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'getMyList' }) @@ -40,28 +79,74 @@ function renderList() { filtered.forEach(m => { const card = document.createElement('div'); - card.className = `relative group bg-slate-800 rounded-xl overflow-hidden border ${m.vu == 1 ? 'border-green-500/50' : 'border-slate-700'}`; - card.innerHTML = ` - -
-

${m.titre}

-
- - + // On ajoute 'flex flex-col' pour que le contenu s'empile proprement + card.className = `relative group bg-slate-800 rounded-xl overflow-hidden border ${m.vu == 1 ? 'border-green-500/50' : 'border-slate-700'} flex flex-col h-full`; + + if (currentView === 'partner') { + card.innerHTML = ` +
+
-
- `; + +
+

${m.titre}

+ +
+ +
+
+ `; + + } else if (currentView === 'common') { + + card.innerHTML = ` +
+ +
+ +
+

${m.titre}

+ +
+ +
+
+ `; + } else { + card.innerHTML = ` +
+ +
+ +
+

${m.titre}

+ +
+ + +
+
+ `; + } + grid.appendChild(card); }); } // Actions rapides async function toggleVu(id) { - const res = await fetch('RequestHandler.php', { + const res = await fetch('../RequestHandler.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'toggleViewed', params: { movie_id: id } }) @@ -77,7 +162,7 @@ async function toggleVu(id) { async function deleteMovie(id) { if(!confirm("Supprimer ce film de ta liste ?")) return; - const res = await fetch('RequestHandler.php', { + const res = await fetch('../RequestHandler.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'deleteMovie', params: { movie_id: id } }) @@ -89,4 +174,127 @@ async function deleteMovie(id) { } } +let currentView = 'my'; // 'my', 'common', ou 'partner' + +async function switchTab(view) { + currentView = view; + + // Mise à jour visuelle des boutons + const tabs = ['my', 'common', 'partner']; + tabs.forEach(t => { + const btn = document.getElementById(`tab-${t}`); + if (t === view) { + btn.classList.replace('bg-slate-700/50', 'bg-slate-800'); + btn.classList.replace('text-gray-400', 'text-white'); + btn.classList.replace('border-transparent', 'border-blue-500'); + } else { + btn.classList.replace('bg-slate-800', 'bg-slate-700/50'); + btn.classList.replace('text-white', 'text-gray-400'); + btn.classList.replace('border-blue-500', 'border-transparent'); + } + }); + + // On recharge les données selon la vue + let action = 'getMyList'; + if (view === 'common') action = 'getCommonList'; + if (view === 'partner') action = 'getPartnerList'; // Il faudra créer cette action dans RequestHandler + + const response = await apiRequest(action); + if (response.success) { + allMovies = response.movies || response.common_movies; + renderList(); + } +} + +async function showDetails(tmdbId, type, localId = null, isVu = 0) { + // 1. On récupère les détails complets via TMDB (comme dans search.js) + const mediaType = (type === 'serie') ? 'tv' : 'movie'; + + // On appelle ton RequestHandler pour avoir les détails + acteurs + const movie = await apiRequest('getMovieDetails', { id: tmdbId, type: mediaType }); + if (!movie) return; + + // 2. On remplit la modal avec les infos fraîches + document.getElementById('modalTitle').innerText = movie.title || movie.name; + + const year = (movie.release_date || movie.first_air_date || "").substring(0, 4); + const duration = movie.runtime ? `${movie.runtime} min` : (movie.number_of_seasons ? `${movie.number_of_seasons} Saison(s)` : ""); + const genres = movie.genres.map(g => g.name).join(', '); + document.getElementById('modalMeta').innerText = `${year} • ${genres} ${duration ? '• ' + duration : ''}`; + + document.getElementById('modalOverview').innerText = movie.overview || "Aucun synopsis disponible."; + document.getElementById('modalVote').innerText = movie.vote_average ? movie.vote_average.toFixed(1) : "N/A"; + + // Image de bannière + const bannerUrl = movie.backdrop_path ? `https://image.tmdb.org/t/p/original${movie.backdrop_path}` : ''; + document.getElementById('modalBanner').style.backgroundImage = `url(${bannerUrl})`; + + // Réalisateur + const director = movie.credits.crew.find(person => person.job === 'Director'); + document.getElementById('modalDirector').innerText = director ? director.name : "Non renseigné"; + + // Casting + const castContainer = document.getElementById('modalCast'); + castContainer.innerHTML = movie.credits.cast.slice(0, 8).map(actor => ` +
+ +

${actor.name}

+
+ `).join(''); + + // 3. LOGIQUE DU BOUTON (Vu / Pas Vu) + const btn = document.getElementById('modalMainBtn'); + const ratingZone = document.getElementById('ratingZone'); + + if (localId) { + ratingZone.classList.remove('hidden'); // On montre les étoiles + + if (isVu == 1) { + btn.innerText = "NE PLUS MARQUER COMME VU"; + btn.className = "w-full bg-slate-700 hover:bg-slate-600 text-white py-4 rounded-xl font-black transition-all"; + } else { + btn.innerText = "MARQUER COMME VU"; + btn.className = "w-full bg-green-600 hover:bg-green-500 text-white py-4 rounded-xl font-black transition-all"; + } + + btn.onclick = async () => { + await toggleVu(localId); // Ta fonction qui change le statut en BDD + closeModal(); + }; + } + + // 4. LOGIQYUE DES ÉTOILES + // On récupère la note actuelle pour ce film (si elle existe) + apiRequest('getStarsRating', { movie_id: localId }).then(res => { + if (res.success) { + const currentRating = res.rating || 0; + setRating(currentRating); // On affiche la note actuelle + } + }); + + // Affichage final + document.getElementById('movieModal').classList.remove('hidden'); + document.body.style.overflow = 'hidden'; +} + +// Fonction pour les étoiles +function setRating(note) { + const currentMovieId = document.getElementById('modalMainBtn').onclick.toString().match(/toggleVu\((\d+)\)/)[1]; // Extraction de l'ID du film + const stars = document.querySelectorAll('#starContainer span'); + stars.forEach((star, index) => { + if (index < note) { + star.classList.replace('text-gray-600', 'text-yellow-400'); + } else { + star.classList.replace('text-yellow-400', 'text-gray-600'); + } + }); + apiRequest('setStarsRating', { movie_id: currentMovieId, rating: note }); // currentMovieId doit être défini lors de l'ouverture de la modal +} + +function closeModal() { + document.getElementById('movieModal').classList.add('hidden'); + document.body.style.overflow = 'auto'; +} + loadList(); \ No newline at end of file diff --git a/watchgether/js/index.js b/watchgether/js/search.js similarity index 87% rename from watchgether/js/index.js rename to watchgether/js/search.js index 6640eac..825abda 100644 --- a/watchgether/js/index.js +++ b/watchgether/js/search.js @@ -7,7 +7,7 @@ */ async function apiRequest(action, params = {}) { try { - const response = await fetch('RequestHandler.php', { + const response = await fetch('../RequestHandler.php', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -21,6 +21,8 @@ async function apiRequest(action, params = {}) { } } +document.getElementById('ratingZone').classList.add('hidden'); + // --- RECHERCHE --- /** @@ -116,7 +118,13 @@ async function showDetails(id, type) { // 5. Bouton Ajouter (on passe les infos pour la BDD) const simplifiedType = (mediaType === 'tv') ? 'serie' : 'film'; - document.getElementById('modalAddBtn').onclick = () => addMovie(movie.id, movie.title || movie.name, movie.poster_path, simplifiedType); + const btn = document.getElementById('modalMainBtn'); + btn.innerText = "+ AJOUTER À LA LISTE"; + btn.className = "w-full bg-blue-600 hover:bg-blue-500 text-white py-4 rounded-xl font-black shadow-lg transition-all active:scale-95"; + btn.onclick = () => addMovie(movie.id, movie.title || movie.name, movie.poster_path, simplifiedType); + + // Cache les étoiles en mode recherche + document.getElementById('ratingZone').classList.add('hidden'); // Affichage modal.classList.remove('hidden'); @@ -157,4 +165,16 @@ document.getElementById('searchInput').addEventListener('keypress', function (e) if (e.key === 'Enter') { performSearch(); } -}); \ No newline at end of file +}); + +async function LogOut() { + const res = await fetch('../RequestHandler.php', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ action: 'logout' }) + }); + const data = await res.json(); + if (data.success) { + window.location.href = '../index.php'; + } +} \ No newline at end of file diff --git a/watchgether/ma-liste/index.php b/watchgether/ma-liste/index.php index 53f82f5..d0e1487 100644 --- a/watchgether/ma-liste/index.php +++ b/watchgether/ma-liste/index.php @@ -1,3 +1,11 @@ + + @@ -10,7 +18,24 @@
+ +
+ + + + +
diff --git a/watchgether/modal-template.php b/watchgether/modal-template.php index e8c80b2..2b4d5b2 100644 --- a/watchgether/modal-template.php +++ b/watchgether/modal-template.php @@ -1,4 +1,4 @@ -
diff --git a/watchgether/search/index.php b/watchgether/search/index.php new file mode 100644 index 0000000..3deed23 --- /dev/null +++ b/watchgether/search/index.php @@ -0,0 +1,45 @@ + + + + + + + WatchGether - Recherche + + + + +
+
+ + 🍿 Ma liste + + +

+ WATCHGETHER +

+ + +
+ +
+ + +
+
+
+ + + + \ No newline at end of file