-
Notifications
You must be signed in to change notification settings - Fork 1
/
janvier.php
728 lines (686 loc) · 31.1 KB
/
janvier.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
<?php
$ADMIN = false;
if (md5($_COOKIE["babar"]) == 'd82d5af0d6f21d63ecac7799d88ea864')
$ADMIN = true;
if ($ADMIN){
$_SESSION['messages']['warning'][] = 'YOU ARE ADMIN';
}
$NB_MAX_OF_VOLUNTEER = array(7,2);
$NB_OF_BOOKABLE_ROOM = array(4,1);
if ($ADMIN) //admin can fill everithing
$NB_OF_BOOKABLE_ROOM = $NB_MAX_OF_VOLUNTEER;
$NB_MAX_OF_WORKED_HOURS = 3;
$NB_OF_VOLUNTEER_FIELDS = 3;
$HAS_HEADER = true;
$HAS_LABEL = true;
$FRAMAURL = "https://framadate.org/WEav6oUGRwKoL7I7"; //pour les ressources
//$FRAMAURL = "#"; //pour les ressources
$PERIOD_NAME = "mois de janvier 2017";
$csv_file = "csv/janvier.csv";
$csv_file_ressources = "csv/ressources.csv";
$to_email = "creneaux@lelefan.org";
$max_h = "Laisses donc des creneaux pour les autres, c'est ".$NB_MAX_OF_WORKED_HOURS."h max par mois :)";
$max_p = "Oups, il y bien assez de monde, essaie un autre creneau !";
$messages = array();
$messages["succes"] = array();
$messages["error"] = array();
$messages["warning"] = array();
$JOB_TYPES = array();
$JOB_TYPES[0] = "Epicerie";
$JOB_TYPES[1] = "Accueil - Bureau des membres";
$NB_OF_JOB_TYPE = count($JOB_TYPES);
//list all shift
$SHIFTS = array();
$SHIFTS[0] = array();
$SHIFTS[0][0] = '06h00-07h30';
$SHIFTS[0][1] = '07h30-10h30';
$SHIFTS[0][2] = '10h30-13h30';
$SHIFTS[0][3] = '13h30-16h30';
$SHIFTS[0][4] = '16h30-19h30';
$SHIFTS[0][5] = '19h30-21h00';
$SHIFTS[1] = array();
$SHIFTS[1][0] = '09h00-10h30';
$SHIFTS[1][1] = '10h30-12h00';
$SHIFTS[1][2] = '12h00-13h30';
$SHIFTS[1][3] = '13h30-15h00';
$SHIFTS[1][4] = '15h00-16h30';
$SHIFTS[1][5] = '16h30-18h00';
$SHIFTS[1][6] = '18h00-19h30';
//list all days
$DAYS = array();
$DAYS[0] = 'Jeu 4 jan'; //week 1
$DAYS[1] = 'Ven 5 jan';
$DAYS[2] = 'Sam 6 jan';
$DAYS[3] = 'Mer 10 jan'; // week 2
$DAYS[4] = 'Jeu 11 jan';
$DAYS[5] = 'Ven 12 jan';
$DAYS[6] = 'Sam 13 jan';
$DAYS[7] = 'Mer 17 jan'; // week 3
$DAYS[8] = 'Jeu 18 jan';
$DAYS[9] = 'Ven 19 jan';
$DAYS[10] = 'Sam 20 jan';
$DAYS[11] = 'Mer 24 jan'; // week 4
$DAYS[12] = 'Jeu 25 jan';
$DAYS[13] = 'Ven 26 jan';
$DAYS[14] = 'Sam 27 jan';
//list all shift
$SHIFTS_VALUES = array();
$SHIFTS_VALUES[0] = array();
$SHIFTS_VALUES[0][0] = 1.5;
$SHIFTS_VALUES[0][1] = 3;
$SHIFTS_VALUES[0][2] = 3;
$SHIFTS_VALUES[0][3] = 3;
$SHIFTS_VALUES[0][4] = 3;
$SHIFTS_VALUES[0][5] = 1.5;
$SHIFTS_VALUES[1] = array();
$SHIFTS_VALUES[1][0] = 1.5;
$SHIFTS_VALUES[1][1] = 1.5;
$SHIFTS_VALUES[1][2] = 1.5;
$SHIFTS_VALUES[1][3] = 1.5;
$SHIFTS_VALUES[1][4] = 1.5;
$SHIFTS_VALUES[1][5] = 1.5;
$SHIFTS_VALUES[1][6] = 1.5;
$SCHEDULED_HOURS=array();
//jeudi & mercredi
$BLOCKED = array();
$BLOCKED[0] = array();
$BLOCKED[0][0] = array();
$BLOCKED[0][0][0] = true;
$BLOCKED[0][0][1] = true;
$BLOCKED[0][3] = array();
$BLOCKED[0][3][0] = true;
$BLOCKED[0][3][1] = true;
$BLOCKED[0][4] = array();
$BLOCKED[0][4][0] = true;
$BLOCKED[0][4][1] = true;
$BLOCKED[0][7] = array();
$BLOCKED[0][7][0] = true;
$BLOCKED[0][7][1] = true;
$BLOCKED[0][8] = array();
$BLOCKED[0][8][0] = true;
$BLOCKED[0][8][1] = true;
$BLOCKED[0][11] = array();
$BLOCKED[0][11][0] = true;
$BLOCKED[0][11][1] = true;
$BLOCKED[0][12] = array();
$BLOCKED[0][12][0] = true;
$BLOCKED[0][12][1] = true;
$BLOCKED[1] = array();
$BLOCKED[1][0] = array();
$BLOCKED[1][0][0] = true;
$BLOCKED[1][0][1] = true;
$BLOCKED[1][3] = array();
$BLOCKED[1][3][0] = true;
$BLOCKED[1][3][1] = true;
$BLOCKED[1][4] = array();
$BLOCKED[1][4][0] = true;
$BLOCKED[1][4][1] = true;
$BLOCKED[1][7] = array();
$BLOCKED[1][7][0] = true;
$BLOCKED[1][7][1] = true;
$BLOCKED[1][8] = array();
$BLOCKED[1][8][0] = true;
$BLOCKED[1][8][1] = true;
$BLOCKED[1][11] = array();
$BLOCKED[1][11][0] = true;
$BLOCKED[1][11][1] = true;
$BLOCKED[1][12] = array();
$BLOCKED[1][12][0] = true;
$BLOCKED[1][12][1] = true;
//colors / nb of booking
$COLORS = array();
$COLORS[0] = array();
$COLORS[0][0] = 'free';
$COLORS[0][1] = 'amber lighten-3';
$COLORS[0][2] = 'yellow lighten-4';
$COLORS[0][3] = 'lime lighten-2';
$COLORS[0][4] = 'light-green lighten-3';
$COLORS[0][5] = 'green lighten-4';
$COLORS[1] = array();
$COLORS[1][0] = 'free';
$COLORS[1][1] = 'lime lighten-2';
$COLORS[1][2] = 'green lighten-4';
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
$line_of_text = array();
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);
}
function fixCSV(&$array){
// global $NB_OF_VOLUNTEER_FIELDS,$HAS_LABEL,$DAYS;
// $shifted_col = ($HAS_LABEL) ? 1 : 0;
// $max = count($DAYS)*$NB_OF_VOLUNTEER_FIELDS + $shifted_col;
// foreach ($array as $index => $line){
// for ($i=0;$i<$max;$i++){
// if (!isset($array[$index][$i]))
// $array[$index][$i] = '';
// }
// ksort($array[$index]);
// }
}
function singleLevelArray(&$element){
if (is_array($element) && count($element)==1)
$element = trim($element[0]);
}
$ressources = readCSV($csv_file_ressources);
array_walk($ressources,'singleLevelArray');
function isRessource($email){
global $ressources;
return in_array($email,$ressources);
}
class Volunteer {
protected $_firstname;
protected $_lastname;
protected $_email;
public function __construct($firstname,$lastname,$email)
{
$this->_firstname = strtolower($firstname);
$this->_lastname = strtolower($lastname);
$this->_email = strtolower(trim($email));
}
public function getFirstname(){
return $this->_firstname;
}
public function getLastname(){
return $this->_lastname;
}
public function getEmail(){
return $this->_email;
}
public function __toString()
{
if (!isRessource($this->getEmail()))
return $this->getFirstname() . ' ' . strtoupper(substr($this->getLastname(),0,1));
else
return '<i><b>'.$this->getFirstname() . ' ' . strtoupper(substr($this->getLastname(),0,1)).' (R)</b></i>';
}
}
function getIndexes($job_type,$index,$index_j){
global $HAS_HEADER,$HAS_LABEL,$SHIFTS,$NB_MAX_OF_VOLUNTEER,$NB_OF_VOLUNTEER_FIELDS;
$shifted_row = ($HAS_HEADER) ? 1 : 0;
$shifted_col = ($HAS_LABEL) ? 1 : 0;
$line_index = $shifted_row;
for ($job = 0; $job < $job_type; $job++) {
$line_index += count($SHIFTS[$job])*$NB_MAX_OF_VOLUNTEER[$job]+ $shifted_row;
}
$line_index += $index*$NB_MAX_OF_VOLUNTEER[$job_type];
$column_index = $index_j*$NB_OF_VOLUNTEER_FIELDS+$shifted_col;
return array($line_index,$column_index);
}
function countVolunteers($booked,$job_type,$index,$index_j){
global $NB_MAX_OF_VOLUNTEER;
$nb = 0;
list($line_index ,$column_index) = getIndexes($job_type,$index,$index_j);
for($i=0;$i<$NB_MAX_OF_VOLUNTEER[$job_type];$i++){ //for all lines in this shift
if (filter_var($booked[$line_index+$i][$column_index+2], FILTER_VALIDATE_EMAIL)) { // if email is valid
$nb++;
}
}
return $nb;
}
function getScheduledHours($booked,$email){
global $DAYS,$SHIFTS,$SHIFTS_VALUES;
global $NB_MAX_OF_VOLUNTEER,$NB_OF_JOB_TYPE,$HAS_HEADER,$HAS_LABEL;
if (!isset($_SESSION['scheduled_hours'][$email])){
foreach ($DAYS as $index_j => $day){
for ($j = 0; $j < $NB_OF_JOB_TYPE; $j++) {
foreach ($SHIFTS[$j] as $index => $shift) {
for ($i = 0; $i < $NB_MAX_OF_VOLUNTEER[$j]; $i++) {
list($line_index ,$column_index) = getIndexes($j,$index,$index_j);
if ((strtolower($booked[$line_index + $i ][$column_index + 2 ])) == strtolower($email)) {
$_SESSION['scheduled_hours'][$email] += $SHIFTS_VALUES[$j][$index];
}
}
}
}
}
}
return $_SESSION['scheduled_hours'][$email];
}
function getVolunteers($booked,$job_type,$index,$index_j){
global $NB_MAX_OF_VOLUNTEER;
$volunteers = array();
list($line_index ,$column_index) = getIndexes($job_type,$index,$index_j);
for($i=0;$i<$NB_MAX_OF_VOLUNTEER[$job_type];$i++){
if (filter_var($booked[$line_index+$i][$column_index+2], FILTER_VALIDATE_EMAIL)) {
$volunteers[] = new Volunteer(
strtolower($booked[$line_index+$i][$column_index]),
strtolower($booked[$line_index+$i][$column_index+1]),
strtolower($booked[$line_index+$i][$column_index+2])
);
}
}
return $volunteers;
}
function addVolunteer(&$booked,$job_type,$index,$index_j,$volunteer){
global $NB_MAX_OF_VOLUNTEER,$SHIFTS_VALUES,$SCHEDULED_HOURS;
list($line_index ,$column_index) = getIndexes($job_type,$index,$index_j);
for($i=0;$i<$NB_MAX_OF_VOLUNTEER[$job_type];$i++){
if (!filter_var($booked[$line_index+$i][$column_index+2], FILTER_VALIDATE_EMAIL)) { //email is not valid == room is available
$booked[$line_index+$i][$column_index+0] = $volunteer->getFirstname();
$booked[$line_index+$i][$column_index+1] = $volunteer->getLastname();
$booked[$line_index+$i][$column_index+2] = strtolower($volunteer->getEmail());
$_SESSION['scheduled_hours'][$volunteer->getEmail()] += $SHIFTS_VALUES[$job_type][$index];
return true;
}elseif ($booked[$line_index+$i][$column_index+2] == $volunteer->getEmail()){ //oups already subscribe here
$_SESSION['messages']['error'][] = "Oups, tu es déjà inscrit sur ce créneau ! Je sais que tu es super, mais de là à tenir deux postes en parallèle, quand même... :)";
return false;
}
}
return true;
}
function removeVolunteer(&$booked,$job_type,$index,$index_j,$email){
global $NB_MAX_OF_VOLUNTEER;
$returnValue = false;
list($line_index ,$column_index) = getIndexes($job_type,$index,$index_j);
for($i=0;$i<$NB_MAX_OF_VOLUNTEER[$job_type]&&!$returnValue;$i++){
$current_email = $booked[$line_index+$i][$column_index+2];
if ((filter_var($current_email, FILTER_VALIDATE_EMAIL)) //room is not empty and emails matche
&& (strtolower($email) == strtolower($current_email))){
$booked[$line_index+$i][$column_index+0] = '';
$booked[$line_index+$i][$column_index+1] = '';
$booked[$line_index+$i][$column_index+2] = '';
$returnValue = true; //exit
}
}
return $returnValue;
}
if (!file_exists($csv_file)) { //create empty
$fp = fopen($csv_file, 'w');
for ($job = 0; $job < $NB_OF_JOB_TYPE; $job++) {
$head = array();
$head[] = $JOB_TYPES[$job];
foreach ($DAYS as $day) {
$head[] = $day;
for ($d = 1; $d < $NB_OF_VOLUNTEER_FIELDS; $d++)
$head[] = '';
}
fputcsv($fp, $head); //head
foreach ($SHIFTS[$job] as $shift) {
$data = array();
$data[] = $shift; //first column
foreach ($DAYS as $day) {
for ($vf = 0; $vf < $NB_OF_VOLUNTEER_FIELDS; $vf++)
$data[] = '';
}
for ($i = 0; $i < $NB_MAX_OF_VOLUNTEER[$job]; $i++)
fputcsv($fp, $data);
}
}
fclose($fp);
}
if ($_POST && isset($_POST["remove"]) && $_POST["remove"]) {
if (isset($_POST["email"])&&$_POST["email"]){
$booked = readCSV($csv_file);
if (isset($_POST['creneau'])&&isset($_POST['jour'])){
if (!isRessource($_POST["email"]) || $ADMIN){
$remove = removeVolunteer($booked,$_POST['job_type'],$_POST['creneau'],$_POST['jour'],$_POST["email"]);
fixCSV($booked);
writeCSV($csv_file,$booked);
if ($remove){
$subject = '[ONLINE FORM] nouveau creneau supprimé';
$message = $_POST["lastname"].' '.$_POST["firstname"].' // '.$_POST["email"].' '.$_POST['remove'];
$headers = 'From: creneaux@lelefan.org' . "\r\n" .
'Reply-To: '. $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to_email, $subject, $message, $headers);
//todo mail the user too
//success, redirect same file
$_SESSION['messages']['success'][] = "Merci, la suppression a bien été prise en compte. <br/>Tu peux choisir un autre créneau. <br/>A bientôt dans ton épicerie";
}else{
$_SESSION['messages']['error'][] = "Oups, l'opération a mal tourné...";
}
}else{
$_SESSION['messages']['error'][] = "<i class=\"large material-icons\">warning</i> Tu es bénévole ressource ! Merci d'envoyer un mail à creneaux@lelefan.org pour te désincrire.</a> :)";
}
}else{
$_SESSION['messages']['error'][] = "formulaire incomplet";
}
}
}
elseif ($_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);
$_SESSION['messages']['success'][] = "Merci, ta demande a bien été prise en compte. <br/>A bientôt dans ton épicerie";
}else{
$booked = readCSV($csv_file);
if ((getScheduledHours($booked,$_POST["email"])<$NB_MAX_OF_WORKED_HOURS) || $ADMIN){
if (isset($_POST['creneau'])&&isset($_POST['jour'])){
if (!isRessource($_POST["email"]) || $ADMIN){
$countV = countVolunteers($booked,$_POST['job_type'],$_POST['creneau'],$_POST['jour']);
if ($countV<$NB_MAX_OF_VOLUNTEER[$_POST['job_type']]){
$volunteer = new Volunteer($_POST["firstname"],$_POST["lastname"],$_POST["email"]);
if (addVolunteer($booked,$_POST['job_type'],$_POST['creneau'],$_POST['jour'],$volunteer)){
fixCSV($booked);
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);
//success, redirect same file
$_SESSION['messages']['success'][] = "Merci, ta demande a bien été prise en compte. <br/>A bientôt dans ton épicerie";
if (getScheduledHours($booked,$_POST["email"])<$NB_MAX_OF_WORKED_HOURS) { // some more to do
$_SESSION['messages']['warning'][] = "Il te restera ".($NB_MAX_OF_WORKED_HOURS-getScheduledHours($booked,$_POST["email"]))."h à choisir pour combler ce cycle";
}
}
}else{
$_SESSION['messages']['error'][] = $max_p;
}
}else{
$_SESSION['messages']['warning'][] = "<i class=\"large material-icons\">favorite</i> Tu es bénévole ressource ! Afin de combler au mieux l'intégralité des creneaux avec au moins un volontaire comme toi, merci de remplir le <a href=\"".$FRAMAURL."\">framadate</a> :)";
}
}else{
$_SESSION['messages']['error'][] = "formulaire incomplet";
}
}else{
$_SESSION['messages']['error'][] = $max_h;
}
}
}else{
$_SESSION['messages']['error'][] = "Ton email est necessaire pour pouvoir te recontacter ;)";
}
}else{
$_SESSION['messages']['error'][] = "Merci de bien spécifier ton nom et prénom :)";
}
}
//$BORDER_COLOR = array('lightblue','lightgreen','yellow','Violet');
$BORDER_COLOR = array('#e3f2fd','#bbdefb','#90caf9','#64b5f6','#42a5f5','#2196f3','#1e88e5','#1976d2','#1565c0','#0d47a1','#1565c0','#1976d2','#1e88e5','#2196f3','#42a5f5','#64b5f6','#90caf9','#bbdefb');
$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 <?php echo $PERIOD_NAME; ?></title>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
td.free:before{
content: 'libre';
text-align: center;
width: 100%;
display: block;
font-style: italic;
color: lightblue;
height: 100%;
margin: auto;
}
.job{
display: none;
}
.card-panel{
color: white;
}
.table-container{
overflow-x: scroll;
margin-bottom: 20px;
}
.modal .title{
text-align: center;
text-transform: uppercase;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<div class="section">
<?php foreach ($_SESSION['messages']["success"] as $value) { ?>
<div class="card-panel green lighten-1"><?php echo $value ?></div>
<?php } ?>
<?php foreach ($_SESSION['messages']["error"] as $value) { ?>
<div class="card-panel red lighten-1"><?php echo $value ?></div>
<?php } ?>
<?php foreach ($_SESSION['messages']["warning"] as $value) { ?>
<div class="card-panel orange lighten-1"><?php echo $value ?></div>
<?php } ?>
<?php unset($_SESSION['messages']["success"]); ?>
<?php unset($_SESSION['messages']["error"]); ?>
<?php unset($_SESSION['messages']["warning"]); ?>
<div class="row">
<h2>
Créneaux <?php echo $PERIOD_NAME; ?>
</h2>
<div class="input-field col s12">
<select id="job_type">
<option value="" disabled selected>Choisir un poste</option>
<?php for($i=$NB_OF_JOB_TYPE-1;$i>=0;$i--): ?>
<option value="job<?php echo $i ?>"><?php echo $JOB_TYPES[$i]; ?></option>
<?php endfor; ?>
</select>
<label for="job_type">A quel poste souhaites tu participer ?</label>
</div>
<p class="job<?php for($i=0;$i<$NB_OF_JOB_TYPE;$i++): ?> job<?php echo $i; endfor; ?>">
Clique sur une case pour t'inscrire sur le créneau associé.
</p>
<p class="job job0">
Il y a <?php echo $NB_OF_BOOKABLE_ROOM[0]; ?> places réservables par créneau.
</p>
<p class="job job1">
Il y a <?php echo $NB_OF_BOOKABLE_ROOM[1]; ?> place réservable par créneau.
</p>
<?php for ($job=0;$job<$NB_OF_JOB_TYPE;$job++) : ?>
<div class="col s12 table-container job job<?php echo $job ?>">
<table class="bordered">
<thead>
<tr>
<td>
</td>
<?php foreach ($DAYS as $index_j => $day) { ?>
<td class="center-align"
style="border-left:2px solid <?php echo $BORDER_COLOR[$index_j%count($BORDER_COLOR)] ?>" width="<?php echo intval(100/count($DAYS))?>%"><?php echo $day; ?></td>
<?php } ?>
</tr>
</thead>
<tbody>
<?php foreach ($SHIFTS[$job] as $index => $shift) { ?>
<tr>
<td class="right-align"><b><?php echo $shift; ?></b></td>
<?php foreach ($DAYS as $index_j => $day) :
if (isset($BLOCKED[$job][$index_j])&&isset($BLOCKED[$job][$index_j][$index])) { ?>
<td class="creneau blocked"
style="border-left:2px solid <?php echo $BORDER_COLOR[$index_j%count($BORDER_COLOR)] ?>;background: lightgray;text-align: center;color: gray;">
Créneau fermé
</td>
<?php } else {
$nb = countVolunteers($booked,$job,$index,$index_j);
$volunteers = getVolunteers($booked,$job,$index,$index_j);
$r = array();
$v = array();
foreach ($volunteers as $volunteer){
if (isRessource($volunteer->getEmail()))
$r[] = $volunteer;
else
$v[] = $volunteer;
}
?>
<td class="creneau <?php echo $COLORS[$job][$nb]; ?>"
style="border-left:2px solid <?php echo $BORDER_COLOR[$index_j%count($BORDER_COLOR)] ?>;cursor:<?php echo (count($v) >= $NB_OF_BOOKABLE_ROOM[$job]) ? "not-allowed" : "pointer"; ?>;"
data-nb="<?php echo count($v); ?>"
data-nb-r="<?php echo count($r); ?>"
data-lig="<?php echo $index; ?>"
data-col="<?php echo $index_j; ?>"
data-job="<?php echo $job; ?>"
data-fr="je m'inscris pour le <?php echo $day; ?> de <?php echo $shift; ?>"
data-fr-nok="je me désinscris du <?php echo $day; ?> de <?php echo $shift; ?>"
>
<small>
<?php echo implode('<br>',$r) ?><br>
<?php echo implode('<br>',$v) ?>
</small>
</td>
<?php } ?>
<?php endforeach; ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php endfor; ?>
<a class="btn waves-effect waves-light deep-purple modal-trigger" href="#impossible"><i class="material-icons left">mood_bad</i>Oups, je ne peux pas m'inscrire</a>
<a class="btn waves-effect waves-light red modal-trigger" href="#desinscription"><i class="material-icons left">warning</i>Désinscription</a>
</div>
</div>
</div>
<div id="inscription" class="modal">
<form action="" method="POST">
<div class="modal-content">
<div class="title"></div>
<div class="row">
<div class="input-field col s6 m12">
<input id="firstname" type="text" name="firstname" class="validate">
<label for="firstname">Ton prénom</label>
</div>
<div class="input-field col s6 m12">
<input id="lastname" type="text" name="lastname" class="validate">
<label for="lastname">Ton nom</label>
</div>
<div class="input-field col s12">
<input id="email" type="email" name="email" class="validate">
<label for="email" data-error="Mauvais format" data-success="">Ton courriel</label>
</div>
</div>
<button type="submit" class="btn ok show-on-small hide-on-med-and-up">Je m'inscris</button>
<input type="hidden" name="creneau" />
<input type="hidden" name="jour" />
<input type="hidden" name="job_type" />
<input type="hidden" name="ok" />
</div>
<div class="modal-footer">
<button type="submit" class="btn ok hide-on-small-only">Je m'inscris</button>
</div>
</form>
</div>
<div id="remove" class="modal">
<form action="" method="POST">
<div class="modal-content">
<div class="title"></div>
<input type="email" name="email" placeholder="mon@email.fr" />
<input type="hidden" name="creneau" />
<input type="hidden" name="jour" />
<input type="hidden" name="job_type" />
<input type="hidden" name="remove" />
<p><i>Hum... est-ce que quelqu'un va pouvoir prendre ta place ? ... pas sûr ! <br/> N'abuses pas de cette fonction ...</i></p>
</div>
<div class="modal-footer">
<button type="submit" class="remove btn red">Je me désinscris</button>
</div>
</form>
</div>
<div id="desinscription" class="modal">
<div class="modal-content">
<div class="show-touch">
Reste appuyé une seconde sur le créneau où tu souhaites te désinscrire puis entre ton courriel.
</div>
<div class="hide-touch">
Clique avec le botton droit de la souris sur le créneau où tu souhaites te désinscrire puis entre ton courriel.
</div>
</div>
</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 (true ){?>
<script type="text/javascript">
function is_touch_device() {
return !!('ontouchstart' in window);
}
$(document).ready(function() {
$('select').material_select();
});
jQuery(function(){
if (is_touch_device()){
$(".show-touch").show();
$(".hide-touch").hide();
// $(".modal").addClass("bottom-sheet").modal();
$(".modal").modal();
console.log("touch_device detected");
}else{
$(".show-touch").hide();
$(".hide-touch").show();
$('.modal').modal();
}
$("#job_type").change(function () {
$(".job").hide();
$("."+$(this).val()).show();
});
var max_nb_of_volunteer = <?php echo json_encode($NB_OF_BOOKABLE_ROOM); ?>;
$(".job").on("click","tbody td.creneau:not(.blocked)",function(){
// if ((parseInt($(this).attr("data-nb"))+parseInt($(this).attr("data-nb-r")))<max_nb_of_volunteer[$(this).attr("data-job")]){
if (parseInt($(this).attr("data-nb"))<max_nb_of_volunteer[$(this).attr("data-job")]){
$("#inscription").find(".title").html($(this).attr("data-fr"));
$("#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").find("input[name=job_type]").val($(this).attr("data-job"));
$("#inscription").modal('open');
}else{
Materialize.toast('<?php echo addslashes($max_p); ?>', 3000, 'rounded');
}
});
$(".job").on("contextmenu","tbody td.creneau:not(.blocked)",function(event){
event.preventDefault();
$("#remove").find(".title").html($(this).attr("data-fr-nok"));
$("#remove").find("input[name=remove]").val($(this).attr("data-fr-nok"));
$("#remove").find("input[name=creneau]").val($(this).attr("data-lig"));
$("#remove").find("input[name=jour]").val($(this).attr("data-col"));
$("#remove").find("input[name=job_type]").val($(this).attr("data-job"));
$("#remove").modal('open');
});
$(".job").on("click","tbody td.creneau.blocked",function(){
Materialize.toast('Ce créneau est fermé :)', 3000, 'rounded');
});
});
</script>
<?php } ?>
</body>
</html>