-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
57 lines (55 loc) · 2.1 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Vérifie si il y a un commentaire pour la désignation spécifiée dans les données utilisateur
* @param string $designation
* @return string $commentaire
*/
function commentaire($des) {
global $user;
foreach ($user as $d) {
if ($d->designation == $des && $d->commentaire != FALSE) {
return ($d->commentaire);
}
}
}
/**
* Vérifie si il y a une note pour la désignation spécifiée dans les données utilisateur
* @param string $designation
* @return string $note
*/
function note($des) {
global $user;
foreach ($user as $d) {
if ($d->designation == $des && $d->note != FALSE) {
return ($d->note);
}
}
}
/**
* Envoi des données utilisateur en base de données
* @param array $donnees
*/
function update_user($donnees) {
global $connexion;
foreach ($donnees as $d) {
$sql="SELECT COUNT(*) FROM `competences_users`
WHERE users_id=".$connexion->quote($d['user'], PDO::PARAM_INT)."
AND designation_id=".$connexion->quote($d['designation'], PDO::PARAM_INT);
$array=$connexion->query($sql)->fetch();
if ($array[0] > 0) {
if ($d['note'] == 0) {
$sql="DELETE FROM `competences_users` WHERE users_id=".$connexion->quote($d['user'], PDO::PARAM_INT)." AND designation_id=".$connexion->quote($d['designation'], PDO::PARAM_INT);
$connexion->exec($sql);
} else {
$sql="UPDATE `competences_users` SET note=".$connexion->quote($d['note'], PDO::PARAM_INT).", commentaire=".$connexion->quote($d['commentaire'], PDO::PARAM_STR)." WHERE users_id=".$connexion->quote($d['user'], PDO::PARAM_INT)." AND designation_id=".$connexion->quote($d['designation'], PDO::PARAM_INT);
$connexion->query($sql);
}
} else {
if ($d['note'] > 0) {
$sql="INSERT INTO `competences_users`(users_id, designation_id, note, commentaire) VALUES(".$connexion->quote($d['user'], PDO::PARAM_INT).", ".$connexion->quote($d['designation'], PDO::PARAM_INT).", ".$connexion->quote($d['note'], PDO::PARAM_INT).", ".$connexion->quote($d['commentaire'], PDO::PARAM_STR).")";
$connexion->exec($sql);
}
}
}
}
?>