-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprofil.php
160 lines (152 loc) · 4.81 KB
/
profil.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
session_start();
require('inc/pdo.php');
require('inc/function.php');
if (empty($_SESSION)) {
header('Location: index.php');
exit();
}
// Récupération des données du user depuis la session //
$nom = $_SESSION['user']['nom'];
$prenom = $_SESSION['user']['prenom'];
$email = $_SESSION['user']['email'];
$userID = $_SESSION['user']['id'];
$status = 'actif';
// Sélection des vaccins lié à l'utilisateur par son ID //
$sql = "SELECT * FROM user_vaccin WHERE id_user = :userID";
$query = $pdo->prepare($sql);
$query->bindValue(':userID', $userID,PDO::PARAM_INT);
$query->execute();
$vaccinsUser = $query->fetchAll();
// Selection des vaccins actif //
$sql = "SELECT * FROM vaccins WHERE status = :status";
$query = $pdo->prepare($sql);
$query->bindValue(':status', $status,PDO::PARAM_STR);
$query->execute();
$vaccinsAll = $query->fetchAll();
// Sélection des vaccins liés au user //
$n = -1;
$vaccinsOfUser = array();
if (!empty($vaccinsUser)) {
foreach ($vaccinsUser as $vaccinUser) {
$n++;
$idVaccin = $vaccinUser['id_vaccin'];
$sql = "SELECT * FROM vaccins WHERE id = :id AND status = :status";
$query = $pdo->prepare($sql);
$query->bindValue(':id',$idVaccin,PDO::PARAM_INT);
$query->bindValue(':status', $status,PDO::PARAM_STR);
$query->execute();
$vaccinsOfUser[$n] = $query->fetch();
}
}
// Sélection des autres vaccins, non liés au user //
if (!empty($vaccinsOfUser)) {
foreach($vaccinsAll as $vaccinAllID => $vaccinAll) {
foreach($vaccinsOfUser as $vaccinOfUser) {
if($vaccinAll['id'] == $vaccinOfUser['id']) {
unset($vaccinsAll[$vaccinAllID]);
break;
}
}
}
} else {
}
// Ajout date vaccin //
$errors = array();
$temps = time();
if(!empty($_POST['submitvaccin'])){
// Faille xss
$name = cleanXss($_POST['name']);
$date_vaccin = cleanXss($_POST['date_vaccin']);
$errors = ValidationText($errors,$name,'name',2,50);
if(!empty($date_vaccin)){
} else {
$errors['date_vaccin'] = 'Veuillez renseigner ce champ';
}
if (count($errors)==0) {
$sql = "SELECT id FROM vaccins WHERE name = :name && status = :status";
$query = $pdo->prepare($sql);
$query->bindValue(':name',$name,PDO::PARAM_STR);
$query->bindValue(':status', $status,PDO::PARAM_STR);
$query->execute();
$idOfUseresVaccin = $query->fetch();
if (!empty($idOfUseresVaccin)) {
$sql = "UPDATE user_vaccin SET date_vaccin = :date_vaccin WHERE id_vaccin = :id_vaccin && id_user = :userID";
$query = $pdo->prepare($sql);
$query->bindValue(':date_vaccin',$date_vaccin,PDO::PARAM_STR);
$query->bindValue(':userID',$userID,PDO::PARAM_INT);
$query->bindValue(':id_vaccin',$idOfUseresVaccin,PDO::PARAM_INT);
$query->execute();
} else {
$errors['name'] = 'Mauvais nom de vaccin entré OU vaccin non disponible';
}
}
}
// Récup date des vaccins pour puis afficher temps restant //
require('inc/header-front.php');
?>
<div class="bodyprofil">
<div class="avatarname">
<img src="asset/img/avatar.png" alt="avatar" width="100">
<h4><?php echo $prenom . ' ' . $nom; ?></h4>
</div>
<div class="bienvenue">
<p>Bienvenue, <?php echo $prenom . ' ' . $nom; ?><p>
</div>
<br>
<?php
$idTemp = -1;
if (!empty($vaccinUser)) {
foreach ($vaccinsOfUser as $vaccinOfUser) {
$idTemp++;
echo $vaccinOfUser['name'];
echo '</br>';
echo $vaccinOfUser['description'];
echo '</br>';
if(!empty($vaccinsUser[$idTemp]['date_vaccin'])){
$tmpRest = $vaccinsUser[$idTemp]['date_vaccin'];
} else {
$tmpRest = 'Non renseigné';
}
echo $tmpRest;
echo '</br>';
echo '<a href="vaccins.php?id=' . $vaccinOfUser['id'] . '&&type=supp">Supprimer de mes vaccins</a>';
echo '</br>';
}
}else {
echo '<p>Vous n\'avez ajouté aucun vaccin</p>';
}
?>
<!-- Ajout date de vaccin -->
<div class="vaccinform">
<form action="" method="post">
<label for="name">Nom du Vaccin</label>
<span class="error"><?php if(!empty($errors['name'])) { echo $errors['name']; } ?></span>
<input type="text" name="name" value="<?php if(!empty($_POST['name'])) { echo $_POST['name']; } ?>">
<label for="date_vaccin"></label>
<span class="error"><?php if(!empty($errors['date_vaccin'])) { echo $errors['date_vaccin']; } ?></span>
<input type="date" name="date_vaccin" value="">
<input type="submit" name="submitvaccin" value="Valider">
</form>
</div>
<?php
if (!empty($vaccinsAll)) {
foreach ($vaccinsAll as $vaccinAll) {
if(!empty($vaccinAll)){
echo '<div class="vaccin">';
echo $vaccinAll['name'];
echo '</br>';
echo $vaccinAll['description'];
echo '</br>';
echo '<a href="vaccins.php?id=' . $vaccinAll['id'] . '&&type=add">Ajouter à mes vaccins</a></br>';
echo '</div>';
}
}
} else {
echo '<div> <p>Plus de vaccins à ajouter</p> </div>';
}
?>
<a class="logout" href="logout.php">Déconnexion</a>
</div>
<?php
require('inc/footer-front.php');