-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
262 lines (246 loc) · 8.91 KB
/
index.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
$csv_file = "booked_test.csv";
$to_email = "mon-email@foodcoop.org";
$max_3h = "Laisses donc des creneaux pour les autres, c'est 3h max par mois :)";
$max_5p = "Oups, 5 c'est bien assez, essaie un autre creneau !";
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
return $line_of_text;
}
function writeCSV($csvFile,$list){
$fp = fopen($csvFile, 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
}
if( isset($_COOKIE["booked"]) ){
$cookie_val = floatval($_COOKIE["booked"]);
}
else{
$cookie_val = 0;
}
$messages = array();
$messages["success"] = array();
$messages["error"] = array();
$messages["warning"] = array();
//list all shift
$creneaux = array();
$creneaux[0] = '6h-7h30';
$creneaux[1] = '7h30-10h30';
$creneaux[2] = '10h30-13h30';
$creneaux[3] = '13h30-16h30';
$creneaux[4] = '16h30-19h30';
$creneaux[5] = '19h30-21h';
//list all days
$jours = array();
$jours[0] = 'vendredi 6 octobre';
$jours[1] = 'Samedi 7 octobre';
$jours[2] = 'vendredi 13 octobre';
$jours[3] = 'Samedi 14 octobre';
$jours[4] = 'vendredi 20 octobre';
$jours[5] = 'Samedi 21 octobre';
$jours[6] = 'vendredi 27 octobre';
$jours[7] = 'Samedi 28 octobre';
if ($_POST && isset($_POST["ok"]) && $_POST["ok"]){
if (isset($_POST["lastname"])&&$_POST["lastname"]&&isset($_POST["firstname"])&&$_POST["firstname"]){
if (isset($_POST["email"])&&$_POST["email"]){
if (isset($_POST["raison"])){
$subject = '[ONLINE FORM] Impossible de reserver un creneau';
$message = $_POST["lastname"].' '.$_POST["firstname"].' '.$_POST["email"].' '.$_POST["raison"].' '.$_POST["message"];
$headers = 'From: creneaux@lelefan.org' . "\r\n" .
'Reply-To: '. $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to_email, $subject, $message, $headers);
header('Location: '.$_SERVER['PHP_SELF']."?success=true");
exit;
}else{
if (intval($_COOKIE["booked"])<3){
if (isset($_POST['creneau'])&&isset($_POST['jour'])){
$booked = readCSV($csv_file);
if ($booked[$_POST['creneau']][$_POST['jour']]<5){
$booked[$_POST['creneau']][$_POST['jour']] += 1;
writeCSV($csv_file,$booked);
$subject = '[ONLINE FORM] nouveau creneau reservé';
$message = $_POST["lastname"].' '.$_POST["firstname"].' '.$_POST["email"].' '.$_POST['ok'];
$headers = 'From: creneaux@lelefan.org' . "\r\n" .
'Reply-To: '. $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to_email, $subject, $message, $headers);
if ($_POST['creneau']==0 || $_POST['creneau']==5)
$cookie_val += 1.5;
else
$cookie_val += 3;
setcookie("booked",$cookie_val);
//success, redirect same file
header('Location: '.$_SERVER['PHP_SELF']."?success=true");
exit;
}else{
$messages['error'][] = $max_5p;
}
}else{
$messages['error'][] = "formulaire incomplet";
}
}else{
$messages['warning'][] = $max_3h;
}
}
}else{
$messages['error'][] = "Ton email est necessaire pour pouvoir te recontacter ;)";
}
}else{
$messages['error'][] = "Merci de bien spécifier ton nom et prénom :)";
}
}
if (isset($_GET['success'])&&$_GET['success']){
$messages['success'][] = "Merci, ta demande a bien été prise en compte. <br/>A bientôt dans ton épicerie";
}
//colors / nb of booking
$colors = array();
$colors[0] = 'red';
$colors[1] = 'amber';
$colors[2] = 'yellow';
$colors[3] = 'lime lighten-2';
$colors[4] = 'light-green lighten-3';
$colors[5] = 'green lighten-4';
$booked = readCSV($csv_file);
?><!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<title>L'éléfàn Creneaux Oct</title>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<?php foreach ($messages["success"] as $value) { ?>
<div class="card-panel green lighten-2"><?php echo $value ?></div>
<?php } ?>
<?php foreach ($messages["error"] as $value) { ?>
<div class="card-panel red lighten-2"><?php echo $value ?></div>
<?php } ?>
<?php foreach ($messages["warning"] as $value) { ?>
<div class="card-panel orange lighten-2"><?php echo $value ?></div>
<?php } ?>
<div class="container">
<div class="section">
<div class="row">
<h2>
Gestion du bénévolat mois d'octobre
</h2>
<p>
Clique sur une case pour t'inscrire sur le creneau associé.
</p>
<table class="responsive-table" id="tab">
<thead>
<tr>
<td>
</td>
<?php foreach ($jours as $indexj => $jour) { ?>
<td><?php echo $jour; ?></td>
<?php } ?>
</tr>
</thead>
<tbody>
<?php foreach ($creneaux as $index => $creneau) { ?>
<tr>
<td class="right-align"><b><?php echo $creneau; ?></b></td>
<?php foreach ($jours as $indexj => $jour) {
$nb = $booked[$index][$indexj];
?>
<td class="creneau <?php echo $colors[$nb]; ?>"
data-nb="<?php echo $nb; ?>"
data-lig="<?php echo $index; ?>"
data-col="<?php echo $indexj; ?>"
data-fr="je m'inscrit pour le <?php echo $jour; ?> de <?php echo $creneau; ?>"><?php echo $nb; ?> bénévole<?php echo ($nb)? 's' :'';?> inscrit<?php echo ($nb)? 's' :'';?></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
<br>
<br>
<a class="btn waves-effect waves-light red modal-trigger" href="#impossible">Oups, je ne peux pas m'inscrire :(</a>
</div>
</div>
</div>
<div id="inscription" class="modal">
<form action="" method="POST">
<div class="modal-content">
<input type="text" name="lastname" placeholder="Nom" />
<input type="text" name="firstname" placeholder="Prenom" />
<input type="email" name="email" placeholder="mon@email.fr" />
<input type="hidden" name="creneau" />
<input type="hidden" name="jour" />
</div>
<div class="modal-footer">
<input type="submit" name="ok" value="M'inscrire" class="btn" />
</div>
</form>
</div>
<div id="impossible" class="modal">
<form action="" method="POST">
<div class="modal-content">
<p>
<input name="raison" type="radio" id="raison1" value="pas disponible sur les créneaux" />
<label for="raison1">Je ne suis pas disponible sur les créneaux qui restent à pourvoir</label>
</p>
<p>
<input name="raison" type="radio" id="raison2" value="aucun créneau disponible" />
<label for="raison2">Il ne reste aucun créneau disponible</label>
</p>
<p>
<input name="raison" type="radio" id="raison3" checked="checked" value="problème technique" />
<label for="raison3">J'ai un problème technique</label>
</p>
<input type="text" name="lastname" placeholder="Nom" />
<input type="text" name="firstname" placeholder="Prenom" />
<input type="email" name="email" placeholder="mon@email.fr" />
<div class="input-field col s12">
<textarea id="message" class="materialize-textarea" name="message"></textarea>
<label for="message">Un message facultatif</label>
</div>
</div>
<div class="modal-footer">
<input type="submit" name="ok" value="Prévenir" class="btn" />
</div>
</form>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<?php if ($cookie_val < 3 ){?>
<script type="text/javascript">
jQuery(function(){
$('.modal').modal();
$("#tab").on("click","tbody td.creneau",function(){
if (parseInt($(this).attr("data-nb"))<5){
$("#inscription").find("input[name=ok]").val($(this).attr("data-fr"));
$("#inscription").find("input[name=creneau]").val($(this).attr("data-lig"));
$("#inscription").find("input[name=jour]").val($(this).attr("data-col"));
$("#inscription").modal('open');
}else{
Materialize.toast('<?php echo addslashes($max_5p); ?>', 3000, 'rounded');
}
});
});
</script>
<?php }else{ ?>
<script type="text/javascript">
jQuery(function(){
$('.modal').modal();
$("#tab").on("click","tbody td.creneau",function(){
Materialize.toast('<?php echo addslashes($max_3h); ?>', 3000, 'rounded');
});
});
</script>
<?php } ?>
</body>
</html>