Commit 9808c3bf authored by Raulin's avatar Raulin

journal

parent e1d98ab8
<?php <?php
require_once("template.php"); require_once("template.php");
// if($_POST['id']!=""){ //si l'id est renseigné il s'agit d'une modification $a='SELECT `id_aliment` FROM `aliments` WHERE `aliment` ="'.$_POST["select_aliment"].'"';
// if(isset($_POST["date"]) && isset($_POST["quantite"]) && isset($_POST["select_aliment"])){ $b = $mysqli->query($a);
// $requete= "UPDATE `journal` SET `aliment` = '".$_POST['aliment']."', `calories` = '".$_POST['calories']."', `type` = '".$_POST['cat']."' WHERE `aliments`.`id_aliment` = ".$_POST['id']; $c=$b->fetch_all();
// $mysqli->query($requete);
// $msg="L'aliment a bien été modifié";
// }
// else{
// $msg="Il manque des informations";
// }
// }
// else{ //sinon il s'agit d'un ajout
if(isset($_POST["date"]) && isset($_POST["quantite"]) && isset($_POST["select_aliment"])){
$id=$_SESSION['id'];
$a='SELECT `id_aliment` FROM `aliments` WHERE `aliment` ="'.$_POST["select_aliment"].'"';
$b = $mysqli->query($a);
$c=$b->fetch_all();
$idaliment= $c[0][0];
$idaliment= $c[0][0];
$id=$_SESSION['id'];
if(isset($_POST["date"]) && isset($_POST["quantite"]) && isset($_POST["select_aliment"])){
$requete="INSERT INTO `journal` (`date`,`id`, `id_aliment`,`quantite`) VALUES ( '" .$_POST['date'] . "', '" .$id . "', '" .$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{
$msg="Il manque des informations"; $msg="Il manque des informations";
} }
//
echo $msg; echo $msg;
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
require_once("template.php"); require_once("template.php");
$id=$_SESSION['id']; $id=$_SESSION['id'];
$requete="DELETE FROM `journal` WHERE `journal`.`id_aliment` = ".$_POST['varIdAliment']."AND `journal`.`id` = ".$id; $requete="DELETE FROM `journal` WHERE `journal`.`id_aliment` = ".$_POST['varIdAliment']." AND `journal`.`id` = ".$id;
$result = $mysqli->query($requete); $result = $mysqli->query($requete);
...@@ -12,10 +12,9 @@ ...@@ -12,10 +12,9 @@
} ); } );
function resetForm() { function resetForm() {
document.getElementById("submit_button").value="Ajouter"; document.getElementById("submit_button_journal").value="Ajouter";
document.getElementById("quantite").value = ""; document.getElementById("quantite").value = "";
document.getElementById("date").value = ""; document.getElementById("date").value = "";
// document.getElementById("mode").value = "";
}; };
...@@ -41,7 +40,6 @@ ...@@ -41,7 +40,6 @@
}); });
$(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');
...@@ -50,38 +48,28 @@ ...@@ -50,38 +48,28 @@
// 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]*val[4]+'</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[0]+'\','+val[5]+')">Supprimer</button></td></tr>');
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="onDelete(\''+val[0]+'\','+val[5]+')">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;
document.getElementById("aliment").value = aliment; // document.getElementById("select_aliment").value = aliment;
document.getElementById("quantite").value = quantite; // document.getElementById("quantite").value = quantite;
document.getElementById("mode").value = "modifier"; // document.getElementById("mode").value = "modifier";
document.getElementById("submit_button").value='Modifier'; // document.getElementById("submit_button_journal").value='Modifier';
}; // };
function onDelete(id_aliment, id_user){ function onDelete(date,ali){
var varIdAliment= id_aliment; var varIdAliment= ali;
var varIdUser= id_user;
$.ajax({ $.ajax({
url: 'api/delete_journal.php', url: 'api/delete_journal.php',
type: 'POST', type: 'POST',
...@@ -90,14 +78,6 @@ ...@@ -90,14 +78,6 @@
alert(varIdAliment); // reponse contient l'affichage du fichier PHP (soit echo) alert(varIdAliment); // reponse contient l'affichage du fichier PHP (soit echo)
} }
}); });
$.ajax({
url: 'api/delete_journal.php',
type: 'POST',
data: {'varIdUser' : varIdUser},
success: function(varIdUser) {
alert(varIdUser); // reponse contient l'affichage du fichier PHP (soit echo)
}
});
location.reload(); location.reload();
} }
...@@ -116,7 +96,6 @@ ...@@ -116,7 +96,6 @@
<th>Type</th> <th>Type</th>
<th>Calories (KCal)</th> <th>Calories (KCal)</th>
<th>Quantité</th> <th>Quantité</th>
<th>Modifier</th>
<th>Supprimer</th> <th>Supprimer</th>
</tr> </tr>
</thead> </thead>
...@@ -147,12 +126,9 @@ ...@@ -147,12 +126,9 @@
<label>Quantité</label> <label>Quantité</label>
<input type="number" id="quantite" name="quantite" required> <input type="number" id="quantite" name="quantite" required>
</div> </div>
<div>
<input type="text" id="mdifier" name="modifier" >
</div>
<div class="form-action-buttons"> <div class="form-action-buttons">
<input type="submit" value="Ajouter" id='submit_button'> <input type="submit" value="Ajouter" id='submit_button_journal'>
</div> </div>
</form> </form>
......
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