playlist aléatoire

This commit is contained in:
Wilfried BRIGITTE 2024-06-12 19:08:54 +02:00
parent 4638bc989c
commit 02cc61a468
15 changed files with 383 additions and 36 deletions

View File

@ -9,6 +9,7 @@ class Deconnexion extends CI_Controller {
public function index() { public function index() {
$this->session->unset_userdata('logged'); $this->session->unset_userdata('logged');
$this->session->unset_userdata('mail');
$this->session->sess_destroy(); $this->session->sess_destroy();
redirect('welcome'); redirect('welcome');
} }

View File

@ -25,6 +25,7 @@ class Enregistrer extends CI_Controller{
} }
$this->model_music->SignUp($pseudo,$login,$password); $this->model_music->SignUp($pseudo,$login,$password);
$this->session->set_userdata('logged', true); $this->session->set_userdata('logged', true);
$this->session->set_userdata('mail', $login);
$this->load->view('layout/header'); $this->load->view('layout/header');
redirect('albums'); redirect('albums');
} }

View File

@ -50,12 +50,6 @@ class Playlist extends CI_Controller {
redirect("playlist/SongPlaylist/$id_playlist"); redirect("playlist/SongPlaylist/$id_playlist");
} }
public function MenuCreate() {
$this->load->view('layout/header');
$this->load->view('create_playlist');
$this->load->view('layout/footer');
}
public function createPlaylistController() { public function createPlaylistController() {
$mail = $this->session->userdata('mail'); $mail = $this->session->userdata('mail');
@ -64,6 +58,17 @@ class Playlist extends CI_Controller {
redirect('playlist'); redirect('playlist');
} }
public function createRandomPlaylist() {
$mail = $this->session->userdata('mail');
$name_playlist = $this->input->post('name_playlist_random');
$num_songs = (int) $this->input->post('num_songs');
if ($num_songs < 1 || $num_songs > 2000) {
return;
}
$this->model_music->createPlaylistRandom($name_playlist, $num_songs, $mail);
redirect('playlist');
}
public function addSongToPlaylist(){ public function addSongToPlaylist(){
$songName = $this->input->post('song'); $songName = $this->input->post('song');
$playlistId = $this->input->post('playlist'); $playlistId = $this->input->post('playlist');

View File

@ -244,4 +244,20 @@ class Model_music extends CI_Model {
array($new_playlist_id, $playlist_id)); array($new_playlist_id, $playlist_id));
} }
public function createPlaylistRandom($name_playlist, $num_songs, $mail) {
$data = array(
'name' => $name_playlist,
'mail' => $mail
);
$this->db->insert('playlist', $data);
$new_playlist_id = $this->db->insert_id();
// Sélectionner le nombre de chansons aléatoires spécifié
$query = $this->db->query("SELECT id, name FROM song ORDER BY RAND() LIMIT ?", array($num_songs));
$songs = $query->result();
foreach ($songs as $song) {
$this->db->query("INSERT INTO SongPlaylist (id, name) VALUES (?, ?)", array($new_playlist_id, $song->name));
}
}
} }

View File

@ -0,0 +1,8 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
echo "\nERROR: ",
$heading,
"\n\n",
$message,
"\n\n";

View File

@ -0,0 +1,8 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
echo "\nDatabase error: ",
$heading,
"\n\n",
$message,
"\n\n";

View File

@ -0,0 +1,21 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
An uncaught Exception was encountered
Type: <?php echo get_class($exception), "\n"; ?>
Message: <?php echo $message, "\n"; ?>
Filename: <?php echo $exception->getFile(), "\n"; ?>
Line Number: <?php echo $exception->getLine(); ?>
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
Backtrace:
<?php foreach ($exception->getTrace() as $error): ?>
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
File: <?php echo $error['file'], "\n"; ?>
Line: <?php echo $error['line'], "\n"; ?>
Function: <?php echo $error['function'], "\n\n"; ?>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>

View File

@ -0,0 +1,8 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
echo "\nERROR: ",
$heading,
"\n\n",
$message,
"\n\n";

View File

@ -0,0 +1,21 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
A PHP Error was encountered
Severity: <?php echo $severity, "\n"; ?>
Message: <?php echo $message, "\n"; ?>
Filename: <?php echo $filepath, "\n"; ?>
Line Number: <?php echo $line; ?>
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
Backtrace:
<?php foreach (debug_backtrace() as $error): ?>
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
File: <?php echo $error['file'], "\n"; ?>
Line: <?php echo $error['line'], "\n"; ?>
Function: <?php echo $error['function'], "\n\n"; ?>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>

View File

@ -0,0 +1,64 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>404 Page Not Found</title>
<style type="text/css">
::selection { background-color: #E13300; color: white; }
::-moz-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
}
p {
margin: 12px 15px 12px 15px;
}
</style>
</head>
<body>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
</body>
</html>

View File

@ -0,0 +1,64 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Database Error</title>
<style type="text/css">
::selection { background-color: #E13300; color: white; }
::-moz-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
}
p {
margin: 12px 15px 12px 15px;
}
</style>
</head>
<body>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
</body>
</html>

View File

@ -0,0 +1,32 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>An uncaught Exception was encountered</h4>
<p>Type: <?php echo get_class($exception); ?></p>
<p>Message: <?php echo $message; ?></p>
<p>Filename: <?php echo $exception->getFile(); ?></p>
<p>Line Number: <?php echo $exception->getLine(); ?></p>
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
<p>Backtrace:</p>
<?php foreach ($exception->getTrace() as $error): ?>
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
<p style="margin-left:10px">
File: <?php echo $error['file']; ?><br />
Line: <?php echo $error['line']; ?><br />
Function: <?php echo $error['function']; ?>
</p>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
</div>

View File

@ -0,0 +1,64 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
<style type="text/css">
::selection { background-color: #E13300; color: white; }
::-moz-selection { background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
}
p {
margin: 12px 15px 12px 15px;
}
</style>
</head>
<body>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
</body>
</html>

View File

@ -0,0 +1,33 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: <?php echo $severity; ?></p>
<p>Message: <?php echo $message; ?></p>
<p>Filename: <?php echo $filepath; ?></p>
<p>Line Number: <?php echo $line; ?></p>
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
<p>Backtrace:</p>
<?php foreach (debug_backtrace() as $error): ?>
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
<p style="margin-left:10px">
File: <?php echo $error['file'] ?><br />
Line: <?php echo $error['line'] ?><br />
Function: <?php echo $error['function'] ?>
</p>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
</div>

View File

@ -1,35 +1,37 @@
<div id="Page"> <div id="Page">
<div class="content"> <div class="content">
<section id="about" class="box"> <section id="about" class="box">
<div class="box-content"> <div class="box-content">
<img src=<?= base_url('assets/img/alo.png') ?> alt="Description de l'image 2"> <img src="<?= base_url('assets/img/alo.png') ?>" alt="Description de l'image 2">
<div class="text-content"> <div class="text-content">
<h2>Créer une nouvelle Playlist</h2> <h2>Créer une nouvelle Playlist Vide</h2>
<form action="<?= base_url('index.php/playlist/createPlaylistController') ?>" method="post" class="playlist-form"> <form action="<?= base_url('index.php/playlist/createPlaylistController') ?>" method="post" class="playlist-form">
<label for="name_playlist" class="playlist-label">Nom de la Playlist:</label> <label for="name_playlist" class="playlist-label">Nom de la Playlist:</label>
<input type="text" name="name_playlist" id="name_playlist" class="playlist-input" required> <input type="text" name="name_playlist" id="name_playlist" class="playlist-input" required>
<button type="submit" name="submit" class="playlist-button">Créer</button> <button type="submit" name="submit" class="playlist-button">Créer</button>
</div> </form>
</div> </div>
</section> </div>
<section id="product" class="box"> </section>
<div class="box-img"> <section id="product" class="box">
<img src=<?= base_url('assets/img/musique2.png') ?> alt="Description de l'image 2"> <div class="box-img">
<div class="text-content"> <img src="<?= base_url('assets/img/musique2.png') ?>" alt="Description de l'image 2">
<h2>Créer une playlist aléatoire</h2> <div class="text-content">
<form action="<?= base_url('index.php/playlist/createPlaylistController') ?>" method="post" class="playlist-form"> <h2>Créer une Playlist Aléatoire</h2>
<label for="name_playlist" class="playlist-label">Nom de la Playlist:</label> <form action="<?= base_url('index.php/playlist/createRandomPlaylist') ?>" method="post" class="playlist-form">
<input type="text" name="name_playlist" id="name_playlist" class="playlist-input" required> <label for="name_playlist_random" class="playlist-label">Nom de la Playlist:</label>
<button type="submit" name="submit" class="playlist-button">Créer</button> <input type="text" name="name_playlist_random" id="name_playlist_random" class="playlist-input" required>
<label for="num_songs" class="playlist-label">Nombre de Chansons:</label>
<input type="number" name="num_songs" id="num_songs" class="playlist-input" min="1" max="2000" required>
<button type="submit" name="submit" class="playlist-button">Créer</button>
</form>
</div>
</div>
</section>
</div> </div>
</div>
</section>
</div>
</div> </div>
<div id="header"></div>
<div id="header"> </div>
</form>
<?php <?php
foreach($playlists as $playlist){ foreach($playlists as $playlist){
echo "<div class='playlist-item'>"; echo "<div class='playlist-item'>";
@ -44,5 +46,4 @@ foreach($playlists as $playlist){
echo "</header>"; echo "</header>";
echo "</div>"; echo "</div>";
} }
echo "</div>";
?> ?>