diff --git a/CodeIgniter-3.1.13/application/config/autoload.php b/CodeIgniter-3.1.13/application/config/autoload.php index 47a3ba2..743fde9 100644 --- a/CodeIgniter-3.1.13/application/config/autoload.php +++ b/CodeIgniter-3.1.13/application/config/autoload.php @@ -58,7 +58,7 @@ $autoload['packages'] = array(); | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('session'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ $autoload['drivers'] = array(); | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url'); +$autoload['helper'] = array('url', 'form', 'html'); /* | ------------------------------------------------------------------- diff --git a/CodeIgniter-3.1.13/application/config/config.php b/CodeIgniter-3.1.13/application/config/config.php index 65af822..f0eca6a 100644 --- a/CodeIgniter-3.1.13/application/config/config.php +++ b/CodeIgniter-3.1.13/application/config/config.php @@ -383,14 +383,14 @@ $config['encryption_key'] = ''; | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here. | */ -$config['sess_driver'] = 'files'; +$config['sess_driver'] = 'database'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_samesite'] = 'Lax'; $config['sess_expiration'] = 7200; -$config['sess_save_path'] = NULL; +$config['sess_save_path'] = 'sessions'; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; -$config['sess_regenerate_destroy'] = FALSE; +$config['sess_regenerate_destroy'] = TRUE; /* |-------------------------------------------------------------------------- diff --git a/CodeIgniter-3.1.13/application/controllers/Albums.php b/CodeIgniter-3.1.13/application/controllers/Albums.php index f735525..91a8aea 100644 --- a/CodeIgniter-3.1.13/application/controllers/Albums.php +++ b/CodeIgniter-3.1.13/application/controllers/Albums.php @@ -6,23 +6,35 @@ class Albums extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->model('model_music'); - $this->load->helper('html'); - $this->load->helper('url'); } public function index(){ + $genre = $this->input->get('genre'); + $artist = $this->input->get('artist'); + $year = $this->input->get('year'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); + if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){ - $albums = $this->model_music->getAlbums(); + $albums = $this->model_music->get_filtered_albums($genre, $artist, $year, $sort, $order); + $data['albums'] = $albums; }else{ $recherche=filter_input(INPUT_GET,'recherche'); $albums = $this->model_music->getSearchAlbums($recherche); + $data['albums'] = $albums; } $this->load->view('layout/header'); if ($albums == false){ - //$page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']); - //$this->load->view('error',['page'=>$page[count($page)-1]]); - $albums = $this->model_music->getAlbums(); + $page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']); + $this->load->view('error',['page'=>$page[count($page)-1]]); + $albums = $this->model_music->get_filtered_albums($genre, $artist, $year, $sort, $order); + $data['albums'] = $albums; } - $this->load->view('albums_list',['albums'=>$albums]); + + $data['genres'] = $this->model_music->get_all_genres(); + $data['artists'] = $this->model_music->get_all_artists(); + $data['years'] = $this->model_music->get_all_years(); + + $this->load->view('albums_list',$data); $this->load->view('layout/footer'); } diff --git a/CodeIgniter-3.1.13/application/controllers/Artistes.php b/CodeIgniter-3.1.13/application/controllers/Artistes.php index 04fef29..03e7d68 100644 --- a/CodeIgniter-3.1.13/application/controllers/Artistes.php +++ b/CodeIgniter-3.1.13/application/controllers/Artistes.php @@ -6,8 +6,6 @@ class Artistes extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->model('model_music'); - $this->load->helper('html'); - $this->load->helper('url'); } public function index(){ if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){ @@ -18,7 +16,7 @@ class Artistes extends CI_Controller { } $this->load->view('layout/header'); if ($artistes == false){ - $page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']); + $page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']); $this->load->view('error',['page'=>$page[count($page)-1]]); $artistes = $this->model_music->getArtistes(); } diff --git a/CodeIgniter-3.1.13/application/controllers/Chansons.php b/CodeIgniter-3.1.13/application/controllers/Chansons.php index a2b37ba..e358c59 100644 --- a/CodeIgniter-3.1.13/application/controllers/Chansons.php +++ b/CodeIgniter-3.1.13/application/controllers/Chansons.php @@ -6,25 +6,53 @@ class Chansons extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->model('model_music'); - $this->load->helper('html'); - $this->load->helper('url'); + $this->load->library('form_validation'); } public function index(){ + $genre = $this->input->get('genre'); + $artist = $this->input->get('artist'); + $year = $this->input->get('year'); + $album = $this->input->get('albums'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); + if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){ - $chansons = $this->model_music->getChansons(); + $chansons = $this->model_music->get_filtered_chansons($genre, $artist, $year, $album, $sort, $order); + $data['chansons'] = $chansons; }else{ $recherche=filter_input(INPUT_GET,'recherche'); $chansons = $this->model_music->getSearchChansons($recherche); + $data['chansons'] = $chansons; } $this->load->view('layout/header'); if ($chansons == false){ - $page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']); + $page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']); $this->load->view('error',['page'=>$page[count($page)-1]]); - $chansons = $this->model_music->getChansons(); + $chansons = $this->model_music->get_filtered_chansons($genre, $artist, $year, $album, $sort, $order); + $data['chansons'] = $chansons; } - $this->load->view('chansons_list',['chansons'=>$chansons]); + $data['genres'] = $this->model_music->get_all_genres_chansons(); + $data['artists'] = $this->model_music->get_all_artists_chansons(); + $data['years'] = $this->model_music->get_all_years_chansons(); + $data['albums'] = $this->model_music->get_all_albums_chansons(); + + $this->load->view('chansons_list',$data); $this->load->view('layout/footer'); } + public function addSongtoPlaylist($id){ + $playlists = $this->model_music->getPlaylist(); + + $this->form_validation->set_rules('playlist_id', 'playlist_id', 'required'); + + if ($this->form_validation->run() == FALSE){ + $this->load->view('layout/header'); + $this->load->view('addSongtoplaylist', ["playlists" => $playlists]); + $this->load->view('layout/footer'); + }else{ + $playlistId = $this->input->post('playlist_id'); + $this->model_music->AddSongtoPlaylist($playlistId,$id); + } + } } diff --git a/CodeIgniter-3.1.13/application/controllers/Playlist.php b/CodeIgniter-3.1.13/application/controllers/Playlist.php new file mode 100644 index 0000000..73e543e --- /dev/null +++ b/CodeIgniter-3.1.13/application/controllers/Playlist.php @@ -0,0 +1,51 @@ +load->model('model_music'); + $this->load->library('form_validation'); + } + public function index(){ + if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){ + $playlists = $this->model_music->getPlaylist(); + }else{ + $recherche=filter_input(INPUT_GET,'recherche'); + $playlists = $this->model_music->getSearchPlaylist($recherche); + } + $this->load->view('layout/header'); + if ($playlists == false){ + $page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']); + $this->load->view('error',['page'=>$page[count($page)-1]]); + $playlists = $this->model_music->getPlaylist(); + } + $this->load->view('playlist_list',['playlists'=>$playlists]); + $this->load->view('layout/footer'); + } + + public function addplaylist(){ + + + $this->form_validation->set_rules('name', 'name', 'required'); + + if ($this->form_validation->run() == FALSE){ + $this->load->view('layout/header'); + $this->load->view('create_playlist'); + $this->load->view('layout/footer'); + }else{ + $nom = $this->input->post('name'); + $description = $this->input->post('Description'); + $userId = $this->session->userdata('userId'); + $playlist = array( + 'name'=>$nom, + 'description'=>$description, + 'userId'=>$userId, + ); + $this->model_music->addPlayliste($playlist); + redirect('playlist'); + } + } + +} \ No newline at end of file diff --git a/CodeIgniter-3.1.13/application/controllers/User.php b/CodeIgniter-3.1.13/application/controllers/User.php new file mode 100644 index 0000000..799e8c6 --- /dev/null +++ b/CodeIgniter-3.1.13/application/controllers/User.php @@ -0,0 +1,76 @@ +load->model('model_music'); + } + + public function create(){ + $this->load->library('form_validation'); + + $this->form_validation->set_rules('nom', 'Nom', 'required'); + $this->form_validation->set_rules('prenom', 'Prénom', 'required'); + $this->form_validation->set_rules('email', 'Adresse mail', 'valid_email'); + $this->form_validation->set_rules('password', 'current password', 'min_length[5]|required'); + $this->form_validation->set_rules('cpassword', 'confirm password', 'required|matches[password]'); + + if ($this->form_validation->run() == FALSE){ + $this->load->view('layout/header'); + $this->load->view('create_user'); + $this->load->view('layout/footer'); + }else{ + + $user=array( + "usernom" => $this->input->post("nom"), + "userprenom" => $this->input->post("prenom"), + "usermail" => $this->input->post("email"), + "userpassword" => password_hash(($this->input->post("password")), PASSWORD_DEFAULT), + ); + + $this->model_music->create_user($user); + redirect("user/auth"); + } + } + + public function auth() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('email', 'Adresse mail', 'valid_email'); + $this->form_validation->set_rules('password', 'current password', 'min_length[5]|required'); + + if ($this->form_validation->run() == FALSE){ + $this->load->view('layout/header'); + $this->load->view('connexion_user'); + $this->load->view('layout/footer'); + }else{ + $email = $this->input->post('email'); + $MDP = $this->input->post('password'); + + $dataUtilisateur = $this->model_music->get_user_by_email($email); + + if(password_verify($MDP, $dataUtilisateur->userpassword)){ + $dataUser = array( + "userId" => $dataUtilisateur->userId, + "userprenom" => $dataUtilisateur->userprenom, + "usermail" => $dataUtilisateur->usermail, + "userpassword" => $dataUtilisateur->userpassword, + "logged_in" => TRUE + ); + $this->session->set_userdata($dataUser); + redirect("albums"); + }else{ + redirect("user/create"); + } + + } + } + + public function logout(){ + $this->session->sess_destroy(); + redirect("albums"); + } +} \ No newline at end of file diff --git a/CodeIgniter-3.1.13/application/models/Model_music.php b/CodeIgniter-3.1.13/application/models/Model_music.php index 5fcbfc7..25d4ca6 100644 --- a/CodeIgniter-3.1.13/application/models/Model_music.php +++ b/CodeIgniter-3.1.13/application/models/Model_music.php @@ -4,19 +4,54 @@ class Model_music extends CI_Model { public function __construct(){ $this->load->database(); } + + public function get_filtered_albums($genre = [], $artist = [], $year = [], $sort = null, $order = null) { + $this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg '); + $this->db->from('album'); + $this->db->join('genre', 'album.genreId = genre.Id'); + $this->db->join('artist', 'album.artistId = artist.Id'); + $this->db->join('cover', 'album.coverId = cover.Id'); - public function getAlbums(){ - $query = $this->db->query( - "SELECT album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg - FROM album - JOIN artist ON album.artistid = artist.id - JOIN genre ON genre.id = album.genreid - JOIN cover ON cover.id = album.coverid - ORDER BY year - " - ); - return $query->result(); - } + if (!empty($genre)) { + $this->db->where_in('genre.name', $genre); + } + if (!empty($artist)) { + $this->db->where_in('artist.name', $artist); + } + if (!empty($year)) { + $this->db->where_in('album.year', $year); + } + if ($sort && in_array($sort, ['year', 'artistName', 'name', 'genreName'])) { + $this->db->order_by($sort, $order); + } + $query = $this->db->get(); + return $query->result(); + } + + public function get_all_genres() { + $this->db->distinct(); + $this->db->select('genreId,genre.name as genreName'); + $this->db->from('album'); + $this->db->join('genre', 'album.genreId = genre.Id'); + $query = $this->db->get(); + return $query->result(); + } + + public function get_all_artists() { + $this->db->distinct(); + $this->db->select('artistId,artist.name as artistName'); + $this->db->from('album'); + $this->db->join('artist', 'album.artistId = artist.Id'); + $query = $this->db->get(); + return $query->result(); + } + + public function get_all_years() { + $this->db->distinct(); + $this->db->select('year'); + $query = $this->db->get('album'); + return $query->result(); + } public function getArtistes(){ $query = $this->db->query( @@ -28,19 +63,74 @@ class Model_music extends CI_Model { return $query->result(); } - public function getChansons(){ - $query = $this->db->query( - "SELECT song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName - FROM song - JOIN track ON track.songId = song.id - JOIN album ON album.id = track.albumId - JOIN artist ON album.artistid = artist.id - JOIN genre ON genre.id = album.genreid - ORDER BY album.year - " - ); - return $query->result(); - } + public function get_filtered_chansons($genre = [], $artist = [], $year = [], $album = [], $sort = null, $order = null) { + $this->db->select('track.id as trackId, song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName'); + $this->db->from('song'); + $this->db->join('track', 'track.songId = song.id'); + $this->db->join('album', 'album.id = track.albumId'); + $this->db->join('artist', 'album.artistId = artist.Id'); + $this->db->join('genre', 'genre.id = album.genreid'); + + if (!empty($genre)) { + $this->db->where_in('genre.name', $genre); + } + if (!empty($artist)) { + $this->db->where_in('artist.name', $artist); + } + if (!empty($year)) { + $this->db->where_in('album.year', $year); + } + if (!empty($album)) { + $this->db->where_in('album.name', $album); + } + if ($sort && in_array($sort, ['year', 'artistName', 'name', 'genreName'])) { + $this->db->order_by($sort, $order); + } + $query = $this->db->get(); + return $query->result(); + } + + public function get_all_genres_chansons() { + $this->db->distinct(); + $this->db->select('genreId,genre.name as genreName'); + $this->db->from('song'); + $this->db->join('track', 'track.songId = song.id'); + $this->db->join('album', 'album.id = track.albumId'); + $this->db->join('genre', 'album.genreId = genre.Id'); + $query = $this->db->get(); + return $query->result(); + } + + public function get_all_artists_chansons() { + $this->db->distinct(); + $this->db->select('artistId,artist.name as artistName'); + $this->db->from('song'); + $this->db->join('track', 'track.songId = song.id'); + $this->db->join('album', 'album.id = track.albumId'); + $this->db->join('artist', 'album.artistId = artist.Id'); + $query = $this->db->get(); + return $query->result(); + } + + public function get_all_years_chansons() { + $this->db->distinct(); + $this->db->select('year'); + $this->db->from('song'); + $this->db->join('track', 'track.songId = song.id'); + $this->db->join('album', 'album.id = track.albumId'); + $query = $this->db->get(); + return $query->result(); + } + + public function get_all_albums_chansons() { + $this->db->distinct(); + $this->db->select('album.Id,album.name as albumName'); + $this->db->from('song'); + $this->db->join('track', 'track.songId = song.id'); + $this->db->join('album', 'album.id = track.albumId'); + $query = $this->db->get(); + return $query->result(); + } public function getSearchAlbums($nom){ $query = $this->db->query( @@ -75,7 +165,7 @@ class Model_music extends CI_Model { public function getSearchChansons($nom){ $query = $this->db->query( - "SELECT song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName + "SELECT track.id as trackId,song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName FROM song JOIN track ON track.songId = song.id JOIN album ON album.id = track.albumId @@ -157,4 +247,54 @@ class Model_music extends CI_Model { ); return $query->result(); } + + public function create_user($user){ + $this->db->insert("User",$user); + return $this->db->insert_id(); + } + + public function get_user_by_email($email){ + $this->db->select("userId,usernom,userprenom,usermail,userpassword"); + $this->db->from("User"); + $this->db->where("usermail",$email); + + $query = $this->db->get(); + return $query->row(); + } + + public function getPlaylist(){ + $query = $this->db->query( + "SELECT Playlist.name, Playlist.playlistid + FROM Playlist + ORDER BY Playlist.name + " + ); + return $query->result(); + } + + public function getSearchPlaylist($nom){ + $query = $this->db->query( + "SELECT Playlist.name, Playlist.playlistid + FROM Playlist + WHERE Playlist.name LIKE '$nom' + " + ); + $query->result(); + if ($query->num_rows() > 0){ + return $query->result(); + } + return $query = false; + } + + public function addPlayliste($playlist){ + $this->db->insert("Playlist",$playlist); + return $this->db->insert_id(); + } + + public function AddSongtoPlaylist($idplaylist, $trackId){ + $tupple = array( + "playlistId"=> $idplaylist, + "trackId"=> $trackId); + $this->db->insert("PlaylistSong",$tupple); + } } diff --git a/CodeIgniter-3.1.13/application/views/addSongtoplaylist.php b/CodeIgniter-3.1.13/application/views/addSongtoplaylist.php new file mode 100644 index 0000000..e4093ca --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/addSongtoplaylist.php @@ -0,0 +1,25 @@ +Ajouter une chanson à une playlist + +
+
Playlists
+
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+ + + diff --git a/CodeIgniter-3.1.13/application/views/albums_list.php b/CodeIgniter-3.1.13/application/views/albums_list.php index 4b5eec6..69bb1e3 100644 --- a/CodeIgniter-3.1.13/application/views/albums_list.php +++ b/CodeIgniter-3.1.13/application/views/albums_list.php @@ -1,3 +1,134 @@ + + + +
Filter Albums
+ + +
+
+
+ + + +
+ + + + + + + + +
+
+ +
Sort Albums
+ +
+ + + + + + + + +
+ +
Albums list
+ .filter-options { + display: none; + margin-top: 10px; + } + .filter-buttons { + display: none; + } + .filter-buttons.show { + display: inline-block; + } + .filter-checkboxes { + display: none; + } + .filter-checkboxes.show { + display: block; + } + .sort-buttons { + display: none; + } + .show-buttons .sort-buttons { + display: block; / Afficher les boutons de tri lorsque la classe show-buttons est appliquée */ + } + + + +
Filter Chansons
+ + +
+
+
+ + + + +
+ + + + + + + + + + +
+
+ +
Sort Chansons
+ +
+ + + + + + + + +
+
Chansons list
"; echo "
"; - echo anchor("albums/view/{$chansons->id}","{$chansons->name}"); + echo anchor("chansons/view/{$chanson->id}","{$chanson->name}"); + echo anchor("chansons/addSongtoPlaylist/{$chanson->trackId}",""); echo "
"; - echo ""; - echo ""; - echo "
{$chansons->year} - {$chansons->artistName}
+ echo ""; + echo ""; + echo "
{$chanson->year} - {$chanson->artistName}
"; } ?> diff --git a/CodeIgniter-3.1.13/application/views/connexion_user.php b/CodeIgniter-3.1.13/application/views/connexion_user.php new file mode 100644 index 0000000..0e7255a --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/connexion_user.php @@ -0,0 +1,16 @@ + + +
+ + + +
+ +
+ + + +
+ diff --git a/CodeIgniter-3.1.13/application/views/create_playlist.php b/CodeIgniter-3.1.13/application/views/create_playlist.php new file mode 100644 index 0000000..5d5d5b7 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/create_playlist.php @@ -0,0 +1,14 @@ + +
+ + + +
+ +
+ + +
+ diff --git a/CodeIgniter-3.1.13/application/views/create_user.php b/CodeIgniter-3.1.13/application/views/create_user.php new file mode 100644 index 0000000..7534225 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/create_user.php @@ -0,0 +1,32 @@ + +
+ +
+ + + + + +
+ + + +
+ + + +
+ + + +
diff --git a/CodeIgniter-3.1.13/application/views/layout/header.php b/CodeIgniter-3.1.13/application/views/layout/header.php index 630b2d3..dc02eb5 100644 --- a/CodeIgniter-3.1.13/application/views/layout/header.php +++ b/CodeIgniter-3.1.13/application/views/layout/header.php @@ -16,15 +16,24 @@ diff --git a/CodeIgniter-3.1.13/application/views/playlist_list.php b/CodeIgniter-3.1.13/application/views/playlist_list.php new file mode 100644 index 0000000..2cc7d1e --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/playlist_list.php @@ -0,0 +1,15 @@ +
Playlist list
+
+"; +echo anchor("playlist/addplaylist",""); +echo""; +foreach($playlists as $playlist){ + echo "
"; + echo "
"; + echo anchor("playlist/view/{$playlist->playlistid}","{$playlist->name}"); + echo "
"; + echo "
"; +} +?> +
\ No newline at end of file diff --git a/CodeIgniter-3.1.13/assets/style.css b/CodeIgniter-3.1.13/assets/style.css index 9fb6083..7e2b2d8 100644 --- a/CodeIgniter-3.1.13/assets/style.css +++ b/CodeIgniter-3.1.13/assets/style.css @@ -23,14 +23,15 @@ section.list img { height : 24px; } +.short-text{ + display: flex; + justify-content: space-between; + align-items: center; +} + .apliiiiiii{ width : 75px; height : 24px; color: red; } -.testtt{ - width : 75px; - height : 24px; - color: red; -} \ No newline at end of file