diff --git a/CodeIgniter-3.1.13/application/controllers/Albums.php b/CodeIgniter-3.1.13/application/controllers/Albums.php index cc6b8d8..290f9ce 100644 --- a/CodeIgniter-3.1.13/application/controllers/Albums.php +++ b/CodeIgniter-3.1.13/application/controllers/Albums.php @@ -6,8 +6,10 @@ class Albums extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->model('model_music'); + $this->load->model('model_playlist'); $this->load->helper('url'); $this->load->helper('html'); + $this->load->library('session'); } public function index($page = 1){ @@ -44,13 +46,23 @@ class Albums extends CI_Controller { $album = $this->model_music->get_album_by_id($id); $data['album'] = $album; - $data['title'] = $album->name." - Details"; - $data['css']='assets/css/album_view'; - + // Récupérer les playlists de l'utilisateur connecté + $data['playlist'] = $this->model_playlist->get_user_playlists($this->session->userdata('user_id')); + + // Définir le playlist_id si la playlist est définie + if(isset($data['playlist']) && !empty($data['playlist'])){ + $data['playlist_id'] = isset($data['playlist']->id) ? $data['playlist']->id : null; + } else { + $data['playlist_id'] = null; // Gérer le cas où aucune playlist n'est disponible + } + + $data['title'] = $album->name . " - Details"; + $data['css'] = 'assets/css/album_view'; + $this->load->view('layout/header_dark', $data); - $this->load->view('album_view'); + $this->load->view('album_view', $data); // Transmettre les données à la vue $this->load->view('layout/footer_dark'); } - + } ?> diff --git a/CodeIgniter-3.1.13/application/controllers/Playlists.php b/CodeIgniter-3.1.13/application/controllers/Playlists.php index c88f0c9..34ea4d0 100644 --- a/CodeIgniter-3.1.13/application/controllers/Playlists.php +++ b/CodeIgniter-3.1.13/application/controllers/Playlists.php @@ -9,7 +9,7 @@ class Playlists extends CI_Controller { $this->load->model('Model_music'); $this->load->helper('url'); $this->load->helper('html'); - $this->load->library('session'); // Charger la bibliothèque de sessions + $this->load->library('session'); } public function index(){ @@ -269,6 +269,10 @@ class Playlists extends CI_Controller { // Charger les chansons de la playlist spécifique $data['songs'] = $this->Model_playlist->get_songs_by_playlist($playlist_id); + // Charger la liste des playlists de l'utilisateur + $user_id = $this->session->userdata('user_id'); + $data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id); + $data['title'] = "Détails de la Playlist - Onzeur"; $data['css'] = "assets/css/playlist_view"; @@ -276,7 +280,7 @@ class Playlists extends CI_Controller { $this->load->view('layout/header_dark', $data); $this->load->view('playlist_view', $data); $this->load->view('layout/footer_dark'); - } + } private function verify_playlist_accessibility($playlist_id) { // Récupérer l'ID de l'utilisateur connecté diff --git a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php index 52c6db7..6f61946 100644 --- a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php +++ b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php @@ -471,11 +471,8 @@ class Utilisateur extends CI_Controller { $this->load->view('layout/footer_dark'); } - - - - public function modifier(){ - if(!$this->session->userdata('user_id')){ + public function modifier() { + if (!$this->session->userdata('user_id')) { redirect('utilisateur/connexion'); } @@ -487,8 +484,25 @@ class Utilisateur extends CI_Controller { $this->dashboard(); } else { $user_id = $this->session->userdata('user_id'); + $new_email = $this->input->post('email'); + + // Vérifie si l'email est déjà utilisé par un autre utilisateur + $existing_user = $this->Utilisateur_model->get_user_by_email($new_email); + if ($existing_user && $existing_user->id != $user_id) { + $data['error'] = 'Cet email est déjà utilisé par un autre utilisateur.'; + $data['user'] = $this->Utilisateur_model->get_user_by_id($user_id); + $data['avis'] = $this->Utilisateur_model->get_avis_by_user($user_id); + $data['title'] = "Dashboard - Onzeur"; + $data['css'] = "assets/css/dashboard"; + + $this->load->view('layout/header_dark', $data); + $this->load->view('dashboard', $data); + $this->load->view('layout/footer_dark'); + return; // Sortie de la méthode + } + $data = array( - 'email' => $this->input->post('email'), + 'email' => $new_email, 'nom' => $this->input->post('nom'), 'prenom' => $this->input->post('prenom') ); @@ -503,15 +517,16 @@ class Utilisateur extends CI_Controller { // Récupérer à nouveau les données d'avis pour cet utilisateur $data['user'] = $this->Utilisateur_model->get_user_by_id($user_id); $data['avis'] = $this->Utilisateur_model->get_avis_by_user($user_id); - - $data['title']="Dashboard - Onzeur"; - $data['css']="assets/css/dashboard"; - $this->load->view('layout/header_dark',$data); + $data['title'] = "Dashboard - Onzeur"; + $data['css'] = "assets/css/dashboard"; + + $this->load->view('layout/header_dark', $data); $this->load->view('dashboard', $data); $this->load->view('layout/footer_dark'); } - } + } + public function modifier_mot_de_passe() { if (!$this->session->userdata('user_id')) { diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index 9e6cbf9..508d6f4 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -150,8 +150,6 @@ class Model_music extends CI_Model { return $query->result(); } - - public function get_all_songs() { return $this->db->get('song')->result(); } diff --git a/CodeIgniter-3.1.13/application/models/Utilisateur_model.php b/CodeIgniter-3.1.13/application/models/Utilisateur_model.php index c1c7332..f355dea 100644 --- a/CodeIgniter-3.1.13/application/models/Utilisateur_model.php +++ b/CodeIgniter-3.1.13/application/models/Utilisateur_model.php @@ -17,6 +17,12 @@ class Utilisateur_model extends CI_Model { return $query->row(); } + public function get_user_by_email($email) { + $this->db->where('email', $email); + $query = $this->db->get('utilisateur'); // Assurez-vous que 'utilisateurs' est le nom de votre table d'utilisateurs + return $query->row(); // Retourne le premier résultat + } + public function get_user_by_id($id) { $query = $this->db->get_where('utilisateur', array('id' => $id)); return $query->row(); diff --git a/CodeIgniter-3.1.13/application/views/accueil.php b/CodeIgniter-3.1.13/application/views/accueil.php index c705ef1..4c5cf78 100644 --- a/CodeIgniter-3.1.13/application/views/accueil.php +++ b/CodeIgniter-3.1.13/application/views/accueil.php @@ -10,7 +10,7 @@