Commit e1d98ab8 authored by Raulin's avatar Raulin

journal (read create)

parent e6108cfa
...@@ -14,13 +14,13 @@ require_once("template.php"); ...@@ -14,13 +14,13 @@ require_once("template.php");
// } // }
// else{ //sinon il s'agit d'un ajout // else{ //sinon il s'agit d'un ajout
if(isset($_POST["date"]) && isset($_POST["quantite"]) && isset($_POST["select_aliment"])){ if(isset($_POST["date"]) && isset($_POST["quantite"]) && isset($_POST["select_aliment"])){
$idprovisoire=1; $id=$_SESSION['id'];
$a='SELECT `id_aliment` FROM `aliments` WHERE `aliment` ="'.$_POST["select_aliment"].'"'; $a='SELECT `id_aliment` FROM `aliments` WHERE `aliment` ="'.$_POST["select_aliment"].'"';
$b = $mysqli->query($a); $b = $mysqli->query($a);
$c=$b->fetch_all(); $c=$b->fetch_all();
$idaliment= $c[0][0]; $idaliment= $c[0][0];
$requete="INSERT INTO `journal` (`date`,`id`, `id_aliment`,`quantite`) VALUES ( '" .$_POST['date'] . "', '" .$idprovisoire . "', '" .$idaliment . "', '" . $_POST['quantite'] . "')"; $requete="INSERT INTO `journal` (`date`,`id`, `id_aliment`,`quantite`) VALUES ( '" .$_POST['date'] . "', '" .$id . "', '" .$idaliment . "', '" . $_POST['quantite'] . "')";
$mysqli->query($requete); $mysqli->query($requete);
$msg="L'élément a bien été ajouté au journal"; $msg="L'élément a bien été ajouté au journal";
} else{ } else{
......
<?php <?php
require_once("template.php"); require_once("template.php");
$requete="DELETE FROM `journal` WHERE `journal`.`id_aliment` = ".$_POST['varIdAliment']."AND `journal`.`id` = ".$_POST['varIdUser']; $id=$_SESSION['id'];
$requete="DELETE FROM `journal` WHERE `journal`.`id_aliment` = ".$_POST['varIdAliment']."AND `journal`.`id` = ".$id;
$result = $mysqli->query($requete); $result = $mysqli->query($requete);
<?php <?php
require_once("template.php"); require_once("template.php");
$requete="SELECT `date`, `aliment`,`type`,`calories`,`quantite`, `journal`.`id_aliment`,`journal`.`id` FROM `journal` JOIN `aliments` ON `journal`.`id_aliment`=`aliments`.`id_aliment`"; $id=$_SESSION['id'];
$requete="SELECT `date`, `aliment`,`type`,`calories`,`quantite`, `journal`.`id_aliment`,`journal`.`id` FROM `journal` JOIN `aliments` ON `journal`.`id_aliment`=`aliments`.`id_aliment` WHERE `journal`.`id`=".$id;
$result = $mysqli->query($requete); $result = $mysqli->query($requete);
$journal=$result->fetch_all(); $journal=$result->fetch_all();
......
<?php <?php
session_start();
header('Content-Type: application/json'); //pour que le navigateur l'affiche dans le format json header('Content-Type: application/json'); //pour que le navigateur l'affiche dans le format json
include('bdd.php'); include('bdd.php');
......
...@@ -9,19 +9,21 @@ ...@@ -9,19 +9,21 @@
$(document).ready(function() { $(document).ready(function() {
$('#table_aliments').DataTable(); $('#table_aliments').DataTable();
resetForm(); resetForm();
} ); } );
function resetForm() { function resetForm() {
document.getElementById("submit_button").value="Ajouter"; document.getElementById("submit_button").value="Ajouter";
document.getElementById("quantite").value = ""; document.getElementById("quantite").value = "";
document.getElementById("date").value = ""; document.getElementById("date").value = "";
document.getElementById("mode").value = ""; // document.getElementById("mode").value = "";
}; };
};
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready( function() { $(document).ready( function() {
$.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/read_aliments.php', $.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/read_aliments.php',
function(json){ function(json){
...@@ -39,7 +41,7 @@ ...@@ -39,7 +41,7 @@
}); });
$(document).ready( function() { $(document).ready( function() {
// getId();
$.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/read_journal.php', $.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/read_journal.php',
function(json){ function(json){
table = $('#tbody_journal'); table = $('#tbody_journal');
...@@ -48,13 +50,26 @@ ...@@ -48,13 +50,26 @@
// cf. https://api.jquery.com/jQuery.getJSON/ // cf. https://api.jquery.com/jQuery.getJSON/
$.each( json, function( key, val ) { $.each( json, function( key, val ) {
table.append('<tr><td>'+val[0]+'</td><td>'+val[1]+'</td><td>'+val[2]+'</td><td>'+val[3]+'</td><td>'+val[4]+'</td><td><button '+ table.append('<tr><td>'+val[0]+'</td><td>'+val[1]+'</td><td>'+val[2]+'</td><td>'+val[3]*val[4]+'</td><td>'+val[4]+'</td><td><button '+
'onclick="onEdit(\''+val[0]+'\',\''+val[1]+'\',\''+val[4]+'\')">Modifier</button></td><td><button '+ 'onclick="onEdit(\''+val[0]+'\',\''+val[1]+'\',\''+val[4]+'\')">Modifier</button></td><td><button '+
'onclick="onDelete('+val[5]+','+val[6]+')">Supprimer</button></td></tr>'); 'onclick="onDelete('+val[5]+','+val[6]+')">Supprimer</button></td></tr>');
}); });
} }
); );
}); });
// function getId(){
// var varlogin= sessionStorage.getItem('para');
// $.ajax({
// url: 'api/read_journal.php',
// type: 'POST',
// data: {'varlogin' : varlogin},
// success: function(varlogin){
// alert(varlogin);// reponse contient l'affichage du fichier PHP (soit echo)
// }
// })
// };
function onEdit(date, aliment, quantite) { function onEdit(date, aliment, quantite) {
document.getElementById("date").value = date; document.getElementById("date").value = date;
...@@ -64,7 +79,7 @@ ...@@ -64,7 +79,7 @@
document.getElementById("submit_button").value='Modifier'; document.getElementById("submit_button").value='Modifier';
}; };
function onDelete(varIdUser, id_user){ function onDelete(id_aliment, id_user){
var varIdAliment= id_aliment; var varIdAliment= id_aliment;
var varIdUser= id_user; var varIdUser= id_user;
$.ajax({ $.ajax({
...@@ -133,7 +148,7 @@ ...@@ -133,7 +148,7 @@
<input type="number" id="quantite" name="quantite" required> <input type="number" id="quantite" name="quantite" required>
</div> </div>
<div> <div>
<input type="text" id="mode" name="mode" style="display : none" > <input type="text" id="mdifier" name="modifier" >
</div> </div>
<div class="form-action-buttons"> <div class="form-action-buttons">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment