Compare commits
No commits in common. "9c753ac70cd33e7e568a6d91e66e82afbd4cdce0" and "53e45aeb0df0956ebaa81c46f93c00de0d4452e9" have entirely different histories.
9c753ac70c
...
53e45aeb0d
4 changed files with 16 additions and 107 deletions
74
bdd.php
74
bdd.php
|
@ -52,7 +52,8 @@ function ajouter_doc($request){
|
||||||
die("Connection failed: " . $conn->connect_error);
|
die("Connection failed: " . $conn->connect_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO ensembles (commentaire_auteur) VALUES(\"".htmlspecialchars($request['commentaire_auteur'])."\")";
|
$sql = "INSERT INTO ensemble (commentaire_auteur) VALUES(\"".htmlspecialchars($request['commentaire_auteur'])."\")";
|
||||||
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$conn->execute_query($sql);
|
$conn->execute_query($sql);
|
||||||
|
@ -70,21 +71,15 @@ function saveFilesFromPost($postData,$id_ensemble) {
|
||||||
|
|
||||||
// Check if the $_POST variable is set and contains files
|
// Check if the $_POST variable is set and contains files
|
||||||
echo(print_r($_FILES,true));
|
echo(print_r($_FILES,true));
|
||||||
|
|
||||||
if (isset($_FILES) && is_array($_FILES)) {
|
if (isset($_FILES) && is_array($_FILES)) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Iterate through each file in the $_FILES array
|
// Iterate through each file in the $_FILES array
|
||||||
|
|
||||||
$safe_type = intval($postData['type']);
|
|
||||||
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
foreach ($_FILES as $file) {
|
foreach ($_FILES as $file) {
|
||||||
// Extract file information
|
// Extract file information
|
||||||
if (isset($file['name'])){
|
if (isset($file['name'])){
|
||||||
$fileName = htmlspecialchars($file['name']);
|
$fileName = $file['name'];
|
||||||
if(!check_ext($fileName)){
|
if(!check_ext($fileName)){
|
||||||
echo(json_encode(["status"=>"0","msg"=>"Error saving file '$uniqueFileName'"]));
|
echo(json_encode(["status"=>"0","msg"=>"Error saving file '$uniqueFileName'"]));
|
||||||
exit;
|
exit;
|
||||||
|
@ -96,7 +91,7 @@ function saveFilesFromPost($postData,$id_ensemble) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a unique filename to avoid overwriting existing files
|
// Create a unique filename to avoid overwriting existing files
|
||||||
$uniqueFileName = uniqid() . '_' . $fileName;
|
$uniqueFileName = uniqid() . '_' . htmlspecialchars($fileName);
|
||||||
|
|
||||||
// Define the path to save the file
|
// Define the path to save the file
|
||||||
$filePath = $GLOBALS['uploadDir'] . $uniqueFileName;
|
$filePath = $GLOBALS['uploadDir'] . $uniqueFileName;
|
||||||
|
@ -118,6 +113,7 @@ function saveFilesFromPost($postData,$id_ensemble) {
|
||||||
try{
|
try{
|
||||||
//update the database
|
//update the database
|
||||||
$safe_titre = htmlspecialchars($postData['titre']);
|
$safe_titre = htmlspecialchars($postData['titre']);
|
||||||
|
$safe_type = intval($postData['type']);
|
||||||
|
|
||||||
global $max_val_type;
|
global $max_val_type;
|
||||||
|
|
||||||
|
@ -128,72 +124,16 @@ function saveFilesFromPost($postData,$id_ensemble) {
|
||||||
|
|
||||||
// pour tester, pas implémenté les commentaires globaux ni les themes
|
// pour tester, pas implémenté les commentaires globaux ni les themes
|
||||||
$sql="INSERT INTO documents (titre,type,upload_path,commentaire_auteur,ensemble_id) VALUES(?,?,?,?,?)";
|
$sql="INSERT INTO documents (titre,type,upload_path,commentaire_auteur,ensemble_id) VALUES(?,?,?,?,?)";
|
||||||
$conn->execute_query($sql,array($safe_titre,$safe_type,$filePath,$postData['commentaire_doc_'.$i],$id_ensemble));
|
$conn->execute_query($sql,array($safe_titre,$safe_type,$filePath,"",$id_ensemble));
|
||||||
|
|
||||||
}catch(Exception $e){
|
}catch(Exception $e){
|
||||||
echo(json_encode(['status'=> '0','msg'=>$e->getMessage()]));
|
echo(json_encode(['status'=> '0','msg'=>$e->getMessage()]));
|
||||||
//exit;
|
//exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$i ++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// enregistrement des exercices dans le cas d'une annale
|
|
||||||
if($safe_type == 1){
|
|
||||||
|
|
||||||
$exercices = json_decode($postData['exercices'],true);
|
|
||||||
|
|
||||||
foreach ($exercices as $key => $ex) {
|
|
||||||
// premièrement, on enregistre l'exercice
|
|
||||||
$sql= 'INSERT INTO exercices (commentaire_auteur,ensemble_id,duree) VALUES(?,?,?)';
|
|
||||||
$conn->execute_query($sql,array($ex["commentaire_exo"],$id_ensemble,$ex["duree"]));
|
|
||||||
|
|
||||||
$id_exo = mysqli_insert_id($conn);
|
|
||||||
|
|
||||||
// on recherche pour chaque thème s'il n'existe pas déjà,
|
|
||||||
// si non, on en créer un nouveau
|
|
||||||
|
|
||||||
foreach($ex["themes"] as $theme){
|
|
||||||
|
|
||||||
// pour l'instant un match complet mais on va essayer d'ameliorer ça avec
|
|
||||||
// des regex
|
|
||||||
$sql= "SELECT id FROM themes WHERE name=\"".htmlspecialchars($theme)."\"";
|
|
||||||
$result = $conn->execute_query($sql);
|
|
||||||
if ($result){
|
|
||||||
if (mysqli_num_rows($result) > 0) {
|
|
||||||
$row = mysqli_fetch_assoc($result);
|
|
||||||
$id_theme = $row["id"];
|
|
||||||
}else{
|
|
||||||
echo("creation d'un theme");
|
|
||||||
$sql = "INSERT INTO themes (name) VALUES(?)";
|
|
||||||
$conn->execute_query($sql,array($theme));
|
|
||||||
|
|
||||||
$id_theme = mysqli_insert_id($conn);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensuite, on enregistre les qui lui sont associés
|
|
||||||
$sql= 'INSERT INTO exercices_themes (exercice_id,theme_id) VALUES(?,?)';
|
|
||||||
$result = $conn->execute_query($sql,array($id_exo,$id_theme));
|
|
||||||
echo("enregistrement d'un exercice");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo(json_encode(["status"=>"2","msg"=>"No files in the POST data."]));
|
echo(json_encode(["status"=>"2","msg"=>"No files in the POST data."]));
|
||||||
exit;
|
exit;
|
||||||
|
|
10
init_db.php
10
init_db.php
|
@ -17,7 +17,7 @@ $sql = "
|
||||||
name VARCHAR(255) NOT NULL
|
name VARCHAR(255) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS ensembles (
|
CREATE TABLE IF NOT EXISTS ensemble (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
commentaire_auteur TEXT,
|
commentaire_auteur TEXT,
|
||||||
valide BOOLEAN NOT NULL DEFAULT FALSE
|
valide BOOLEAN NOT NULL DEFAULT FALSE
|
||||||
|
@ -32,15 +32,15 @@ $sql = "
|
||||||
ensemble_id INT,
|
ensemble_id INT,
|
||||||
theme_id INT,
|
theme_id INT,
|
||||||
FOREIGN KEY (theme_id) REFERENCES themes(id),
|
FOREIGN KEY (theme_id) REFERENCES themes(id),
|
||||||
FOREIGN KEY (ensemble_id) REFERENCES ensembles(id)
|
FOREIGN KEY (ensemble_id) REFERENCES ensemble(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS exercices (
|
CREATE TABLE IF NOT EXISTS exercices (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
titre VARCHAR(255) NOT NULL,
|
||||||
commentaire_auteur TEXT,
|
commentaire_auteur TEXT,
|
||||||
ensemble_id INT,
|
document_id INT,
|
||||||
duree INT,
|
FOREIGN KEY (document_id) REFERENCES documents(id)
|
||||||
FOREIGN KEY (ensemble_id) REFERENCES ensembles(id)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
35
readme.md
35
readme.md
|
@ -17,29 +17,26 @@ D'autres fonctionnalités seront ajoutées petit à petit. (si vous avez des sug
|
||||||
|--------------|--------|-------------------------------------------|
|
|--------------|--------|-------------------------------------------|
|
||||||
| exercice_id | INT | FOREIGN KEY (exercice_id) REFERENCES exercises(id) |
|
| exercice_id | INT | FOREIGN KEY (exercice_id) REFERENCES exercises(id) |
|
||||||
| theme_id | INT | FOREIGN KEY (theme_id) REFERENCES themes(id) |
|
| theme_id | INT | FOREIGN KEY (theme_id) REFERENCES themes(id) |
|
||||||
| id | INT | AUTO_INCREMENT, PRIMARY KEY |
|
| PRIMARY KEY | | (exercice_id, theme_id) |
|
||||||
|
|
||||||
### Table: exercices
|
### Table: exercices
|
||||||
|
|
||||||
| Column | Type | Constraints |
|
| Column | Type | Constraints |
|
||||||
|--------------------|---------------|------------------------------------------|
|
|--------------------|---------------|------------------------------------------|
|
||||||
| id | INT | AUTO_INCREMENT, PRIMARY KEY |
|
| id | INT | AUTO_INCREMENT, PRIMARY KEY |
|
||||||
|
| titre | VARCHAR(255) | NOT NULL |
|
||||||
| commentaire_auteur | TEXT | |
|
| commentaire_auteur | TEXT | |
|
||||||
| ensemble_id | INT | FOREIGN KEY (ensemble_id) REFERENCES ensembles(id) |
|
| document_id | INT | FOREIGN KEY (document_id) REFERENCES documents(id) |
|
||||||
| duree | INT | |
|
| duree | INT | |
|
||||||
(la durée est en secondes)
|
(la durée est en secondes)
|
||||||
|
|
||||||
### Table: ensembles
|
### Table: ensemble
|
||||||
|
|
||||||
| Column | Type | Constraints |
|
| Column | Type | Constraints |
|
||||||
|--------------------|---------------|------------------------------------------|
|
|--------------------|---------------|------------------------------------------|
|
||||||
| id | INT | AUTO_INCREMENT |
|
| id | INT | AUTO_INCREMENT |
|
||||||
| commentaire_auteur | TEXT | |
|
| commentaire_auteur | TEXT | |
|
||||||
| valide | BOOLEAN | NOT NULL |
|
| valide | BOOLEAN | NOT NULL |
|
||||||
| corrige_inclu | BOOLEAN | |
|
|
||||||
|
|
||||||
> le champ "corrige_inclu" ne sera utilisé que pour des annales
|
|
||||||
|
|
||||||
### Table: documents
|
### Table: documents
|
||||||
|
|
||||||
| Column | Type | Constraints |
|
| Column | Type | Constraints |
|
||||||
|
@ -51,27 +48,3 @@ D'autres fonctionnalités seront ajoutées petit à petit. (si vous avez des sug
|
||||||
| commentaire_auteur | TEXT | |
|
| commentaire_auteur | TEXT | |
|
||||||
| ensemble_id | INT | FOREIGN KEY (ensemble_id) REFERENCES ensemble(id) |
|
| ensemble_id | INT | FOREIGN KEY (ensemble_id) REFERENCES ensemble(id) |
|
||||||
| theme_id | INT | FOREIGN KEY (theme_id) REFERENCES themes(id) |
|
| theme_id | INT | FOREIGN KEY (theme_id) REFERENCES themes(id) |
|
||||||
|
|
||||||
|
|
||||||
## TOUDOU :
|
|
||||||
|
|
||||||
### téléverser.php :
|
|
||||||
- ajouter un element "commentaire_doc_< i >" pour chaque document
|
|
||||||
|
|
||||||
- ssi le type est "annale" ajouter un element "commentaire_exo_< i >" pour chaque exercice déclaré dans chaque document
|
|
||||||
- Ajouter de même un champ "themes" qui porterons sur les thèmes abordés par l'exercice, possibilité d'en inscrire autant que l'on veut
|
|
||||||
- ajouter un champ "duree" pour chaque exercice
|
|
||||||
- tout pack dans un json à l'envoi :
|
|
||||||
``
|
|
||||||
let ex = [{duree:"10",themes:["algèbre","analyse"],commentaire_exo:"cci est un commenataire"},{duree:"15",themes:["elec analogique"],commentaire_exo:""}];
|
|
||||||
;
|
|
||||||
``
|
|
||||||
|
|
||||||
|
|
||||||
- ssi le type est "annale" Ajouter une checkbox pour spécifier si l'ensemble de documents comprend un corrigé ou non identifiant : "corrige_inclu"
|
|
||||||
|
|
||||||
- dans le cas d'une fiche de révisions, on ajouter seulement un champ "themes"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,6 @@ function uploadFiles() {
|
||||||
formData.append("titre",document.getElementById("titre").value);
|
formData.append("titre",document.getElementById("titre").value);
|
||||||
formData.append("commentaire_auteur",document.getElementById("commentaire_auteur").value);
|
formData.append("commentaire_auteur",document.getElementById("commentaire_auteur").value);
|
||||||
|
|
||||||
let ex = [{duree:"10",themes:["algèbre","analyse"],commentaire_exo:"cci est un commenataire"},{duree:"15",themes:["elec analogique"],commentaire_exo:""}];
|
|
||||||
formData.append("exercices",JSON.stringify(ex))
|
|
||||||
|
|
||||||
|
|
||||||
// Append each selected file to the FormData
|
// Append each selected file to the FormData
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const file of fileInput.files) {
|
for (const file of fileInput.files) {
|
||||||
|
|
Loading…
Reference in a new issue