-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.php
209 lines (190 loc) · 8.69 KB
/
dashboard.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
require('src/inc/pdo.php');
require('src/inc/functions.php');
session_start();
if (isLogged()) {
$user = select($pdo, 'bn_users', '*', 'id', $_SESSION['user']['id']);
} else {
header('Location: ./error.php?e=403');
die();
}
if (!empty($_POST['logout'])) logout();
$errors = [];
if (!empty($_POST['save'])) {
$firstname = checkXss($_POST['firstname']);
$lastname = checkXss($_POST['lastname']);
$gender = checkXss($_POST['gender']);
$birthdate = checkXss($_POST['birthdate']);
$mail = checkXss($_POST['mail']);
$errors = checkField($errors, $firstname, 'firstname', 2, 80);
$errors = checkField($errors, $lastname, 'lastname', 2, 80);
$errors = checkField($errors, $gender, 'gender', 4, 20);
$errors = checkField($errors, $birthdate, 'birthdate', 7, 10);
$errors = checkEmail($errors, $mail, 'mail');
$errors = checkField($errors, $mail, 'mail', 6, 160);
if (count($errors) == 0) {
$_SESSION['user'] = [
'id' => $user['id'],
'mail' => $mail,
'firstname' => $firstname,
'lastname' => $lastname,
'birthdate' => $birthdate,
'gender' => $gender,
'role' => $user['role'],
'ip' => $_SERVER['REMOTE_ADDR']
];
update($pdo, 'bn_users', [
'mail = "' . $mail . '"',
'firstname = "' . $firstname . '"',
'lastname = "' . $lastname . '"',
'birthdate = "' . $birthdate . '"',
'gender = "' . $gender . '"',
'updated_at = "' . now() . '"',
], 'id', $user['id']);
$user = select($pdo, 'bn_users', '*', 'id', $_SESSION['user']['id']);
}
}
if (!empty($_POST['add'])) {
if (empty($_POST['vaccine'])) $_POST['vaccine'] = 1;
$vaccine = checkXss($_POST['vaccine']);
$lastInjection = checkXss($_POST['last_injection']);
$nextInjection = checkXss($_POST['next_injection']);
$errors = checkField($errors, $lastInjection, 'last_injection', 7, 10);
$errors = checkField($errors, $nextInjection, 'next_injection', 7, 10);
if (count($errors) == 0) {
insert(
$pdo,
'bn_reminders',
[
'user_id',
'vaccine_id',
'last_injection',
'reminder',
'created_at',
'updated_at'
],
[
$user['id'],
$vaccine,
$lastInjection,
$nextInjection,
now(),
now()
]
);
}
}
if (!empty($_GET['delete']) && is_numeric($_GET['delete']) && select($pdo, 'bn_reminders', '*', 'id', $_GET['delete'])) delete($pdo, 'bn_reminders', 'id', $_GET['delete']);
$vaccines = selectAll($pdo, 'bn_vaccines');
$reminders = selectAll($pdo, 'bn_reminders', '*', 'user_id', $user['id'], 'last_injection', 'DESC');
$title = 'Tableau de bord - Bookination';
include('src/template/header.php');
?>
<section id="dashboard">
<div class="wrap-fluid">
<div class="container">
<form action="" class="profile-card" method="POST">
<div class="profile">
<div class="profile-container">
<div class="profile-avatar">
<?php if ($user['gender'] == 'homme') : ?>
<img src="assets/img/man.png" alt="Photo ID">
<?php else : ?>
<img src="assets/img/woman.png" alt="Photo ID">
<?php endif; ?>
</div>
<div class="profile-details">
<input type="text" name="firstname" value="<?= $user['firstname'] ?>">
<input type="text" name="lastname" value="<?= $user['lastname'] ?>">
<p><?= calculateAge($user['birthdate']) ?> ans</p>
</div>
</div>
<div class="profile-container">
<div class="profile-item">
<h3>Rappels</h3>
<p><?= count($reminders) ?></p>
</div>
</div>
</div>
<div class="profile-tags">
<div class="profile-container">
<div class="profile-item">
<h3>Email</h3>
<input type="email" name="mail" value="<?= $user['mail'] ?>">
</div>
<div class="profile-item">
<h3>Date de naissance</h3>
<input type="date" name="birthdate" value="<?= $user['birthdate'] ?>">
</div>
<div class="profile-item">
<h3>Mot de passe</h3>
<a href="./recovery.php?mail=<?= $user['mail'] ?>&token=<?= $user['token'] ?>">Modifier</a>
</div>
</div>
<div class="profile-container">
<div class="profile-item">
<h3>Genre</h3>
<select name="gender">
<option value="femme" <?= ($user['gender'] == 'femme') ? 'selected' : '' ?>>Femme</option>
<option value="homme" <?= ($user['gender'] == 'homme') ? 'selected' : '' ?>>Homme</option>
<option value="non-binaire" <?= ($user['gender'] == 'non-binaire') ? 'selected' : '' ?>>Non-binaire</option>
<option value="non-specifie" <?= ($user['gender'] == 'non-specifie') ? 'selected' : '' ?>>Non-specifié</option>
</select>
</div>
<input type="submit" name="save" class="btn btn-purple" value="Sauvegarder">
</div>
</div>
</form>
<div class="reminders-card">
<table>
<tr>
<th>Vaccin</th>
<th>Fréquence</th>
<th style="padding: 0 15px">Obligatoire</th>
<th style="padding: 0 15px">Dernière injection</th>
<th>Prochaine injection</th>
</tr>
<?php foreach ($reminders as $r) : ?>
<tr>
<td><?= $vaccines[$r['vaccine_id']]['name'] ?></td>
<td><?= $vaccines[$r['vaccine_id']]['frequency'] ?></td>
<td><?= ($vaccines[$r['vaccine_id']]['mandatory']) ? 'Oui' : 'Non' ?></td>
<td><?= date("d/m/Y", strtotime($r['last_injection'])) ?></td>
<td><?= date("d/m/Y", strtotime($r['reminder'])) ?></td>
<td><a href="?delete=<?= $r['id'] ?>">Supprimer</a></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
<div class="sidebar">
<?php if (empty($_POST['new'])) : ?>
<div class="prescription">
<h3>Ajouter une injection</h3>
<form action="" method="POST">
<input type="submit" name="new" class="btn btn-purple" value="1"></input>
</form>
</div>
<?php else : ?>
<form action="" method="POST" class="add">
<label for="vaccine">Vaccin</label>
<select name="vaccine">
<option value="" disabled selected hidden>Types de vaccins</option>
<?php foreach ($vaccines as $v) : ?>
<option value="<?= $v['id'] ?>" style="color: #000"><?= $v['name'] ?></option>
<?php endforeach; ?>
</select>
<label for="last_injection">Dernière injection</label>
<input name="last_injection" type="date" value="<?= nowDate() ?>">
<label for="next_injection">Prochaine injection</label>
<input name="next_injection" type="date" value="<?= nowDate() ?>">
<input type="submit" name="add" class="btn btn-purple" value="1"></input>
</form>
<?php endif; ?>
<form action="" method="POST" class="logout">
<input type="submit" name="logout" class="btn btn-purple" value="1"></input>
</form>
</div>
</div>
</section>
<?php include('src/template/footer.php');