Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Projet_idaw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Liang Wu
Projet_idaw
Commits
9808c3bf
Commit
9808c3bf
authored
Apr 05, 2020
by
Raulin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
journal
parent
e1d98ab8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
68 deletions
+32
-68
create_journal.php
api/create_journal.php
+13
-25
delete_journal.php
api/delete_journal.php
+1
-1
journal.php
journal.php
+18
-42
No files found.
api/create_journal.php
View file @
9808c3bf
<?php
require_once
(
"template.php"
);
// if($_POST['id']!=""){ //si l'id est renseigné il s'agit d'une modification
// if(isset($_POST["date"]) && isset($_POST["quantite"]) && isset($_POST["select_aliment"])){
// $requete= "UPDATE `journal` SET `aliment` = '".$_POST['aliment']."', `calories` = '".$_POST['calories']."', `type` = '".$_POST['cat']."' WHERE `aliments`.`id_aliment` = ".$_POST['id'];
// $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
];
$requete
=
"INSERT INTO `journal` (`date`,`id`, `id_aliment`,`quantite`) VALUES ( '"
.
$_POST
[
'date'
]
.
"', '"
.
$id
.
"', '"
.
$idaliment
.
"', '"
.
$_POST
[
'quantite'
]
.
"')"
;
$mysqli
->
query
(
$requete
);
$msg
=
"L'élément a bien été ajouté au journal"
;
}
else
{
$msg
=
"Il manque des informations"
;
$a
=
'SELECT `id_aliment` FROM `aliments` WHERE `aliment` ="'
.
$_POST
[
"select_aliment"
]
.
'"'
;
$b
=
$mysqli
->
query
(
$a
);
$c
=
$b
->
fetch_all
();
$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'
]
.
"')"
;
$mysqli
->
query
(
$requete
);
$msg
=
"L'élément a bien été ajouté au journal"
;
}
else
{
$msg
=
"Il manque des informations"
;
}
//
echo
$msg
;
...
...
api/delete_journal.php
View file @
9808c3bf
...
...
@@ -2,6 +2,6 @@
require_once
(
"template.php"
);
$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
);
journal.php
View file @
9808c3bf
...
...
@@ -12,10 +12,9 @@
}
);
function
resetForm
()
{
document
.
getElementById
(
"submit_button"
).
value
=
"Ajouter"
;
document
.
getElementById
(
"submit_button
_journal
"
).
value
=
"Ajouter"
;
document
.
getElementById
(
"quantite"
).
value
=
""
;
document
.
getElementById
(
"date"
).
value
=
""
;
// document.getElementById("mode").value = "";
};
...
...
@@ -41,7 +40,6 @@
});
$
(
document
).
ready
(
function
()
{
// getId();
$
.
getJSON
(
'https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/read_journal.php'
,
function
(
json
){
table
=
$
(
'#tbody_journal'
);
...
...
@@ -50,38 +48,28 @@
// cf. https://api.jquery.com/jQuery.getJSON/
$
.
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 '
+
'onclick="onEdit(
\'
'
+
val
[
0
]
+
'
\'
,
\'
'
+
val
[
1
]
+
'
\'
,
\'
'
+
val
[
4
]
+
'
\'
)">Modifier</button></td><td><button '
+
'onclick="onDelete('
+
val
[
5
]
+
','
+
val
[
6
]
+
')">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="onEdit(\''+val[0]+'\',\''+val[1]+'\',\''+val[4]+'\')">Modifier
<
/button></
td
><
td
><
button
'+
// '
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
)
{
document
.
getElementById
(
"date"
).
value
=
date
;
document
.
getElementById
(
"aliment"
).
value
=
aliment
;
document
.
getElementById
(
"quantite"
).
value
=
quantite
;
document
.
getElementById
(
"mode"
).
value
=
"modifier"
;
document
.
getElementById
(
"submit_button"
).
value
=
'Modifier'
;
};
// function onEdit(date, aliment, quantite) {
// document.getElementById("date").value = date;
// document.getElementById("select_aliment").value = aliment;
// document.getElementById("quantite").value = quantite;
// document.getElementById("mode").value = "modifier";
// document.getElementById("submit_button_journal").value='Modifier';
// };
function
onDelete
(
id_aliment
,
id_user
){
var
varIdAliment
=
id_aliment
;
var
varIdUser
=
id_user
;
function
onDelete
(
date
,
ali
){
var
varIdAliment
=
ali
;
$
.
ajax
({
url
:
'api/delete_journal.php'
,
type
:
'POST'
,
...
...
@@ -90,14 +78,6 @@
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
();
}
...
...
@@ -116,7 +96,6 @@
<th>
Type
</th>
<th>
Calories (KCal)
</th>
<th>
Quantité
</th>
<th>
Modifier
</th>
<th>
Supprimer
</th>
</tr>
</thead>
...
...
@@ -147,12 +126,9 @@
<label>
Quantité
</label>
<input
type=
"number"
id=
"quantite"
name=
"quantite"
required
>
</div>
<div>
<input
type=
"text"
id=
"mdifier"
name=
"modifier"
>
</div>
<div
class=
"form-action-buttons"
>
<input
type=
"submit"
value=
"Ajouter"
id=
'submit_button'
>
<input
type=
"submit"
value=
"Ajouter"
id=
'submit_button
_journal
'
>
</div>
</form>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment