-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroCarnetVol.php
More file actions
1395 lines (1317 loc) · 65.2 KB
/
Copy pathIntroCarnetVol.php
File metadata and controls
1395 lines (1317 loc) · 65.2 KB
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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Copyright 2022-2026 Patrick Reginster (and Eric Vyncke)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
ob_start("ob_gzhandler"); // Enable gzip compression over HTTP
require_once 'dbi.php';
require_once 'dto.class.php';
require_once 'IntroCarnetVol_tools.php' ;
# HTTP/2 push of JS & CSS via header() to go faster
header('Link: </resa/js/script_carnetdevol.js>;rel=preload;as=script,</resa/data/members.js>;rel=preload;as=script,</resa/data/pilots.js>;rel=preload;as=script,' .
'</resa/data/instructors.js>;rel=preload;as=script,' .
'</resa/data/planes.js>;rel=preload;as=script,</resa/data/shareCodes.js>;rel=preload;as=script,</resa/data/prix.js>;rel=preload;as=script,</resa/css/IntroCarnetVol.css>;rel=preload;as=style') ;
if ($userIsAdmin or $userIsInstructor) { // Let' trust this browser for one year
// TODO only send it when not received
setcookie('trusted_booker', 1, time() + 365 * 24 * 60 * 60, '/', '', true, true) ;
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Introduction carnet de routes</title>
<link rel="stylesheet" type="text/css" href="css/IntroCarnetVol.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://<?= SITE_HOST ?>/favicon32x32.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
<script>
<?php
//---------------------------------------------------------------------------
// Initialiation of default variables
// Define all variables used by the javascript
//---------------------------------------------------------------------------
// Define all variables used by the javascript
print("var default_editflag=0;\n");
print("var default_segment=0;\n");
print("var default_logbookid=0;\n");
print("var default_plane=\"\";\n");
print("var default_pilot=0;\n");
print("var default_instructor=0;\n");
print("var default_isstudent=0;\n");
print("var default_date_heure_depart=\"\";\n");
print("var default_date_heure_arrivee=\"\";\n");
print("var default_day_landing=1;\n");
print("var default_crew_count=1;\n");
print("var default_pax_count=0;\n");
print("var default_flight_type=\"Local\";\n");
print("var default_from=\"EBSP\";\n");
print("var default_to=\"EBSP\";\n");
print("var default_is_pic=0;\n");
print("var default_instructor_paid=1;\n");
print("var default_share_type=\"NoCP\";\n");
print("var default_share_member=0;\n");
print("var default_remark=\"\";\n");
print("var default_compteur_moteur_start=\"\";\n");
print("var default_compteur_moteur_end=\"\";\n");
print("var default_compteur_flight_start=\"\";\n");
print("var default_compteur_flight_end=\"\";\n");
print("var default_flight_reference=\"\";\n");
print("var default_flight_id=0;\n");
print("var default_ATL_level=\"select\";\n");
print("var default_ATL_description=\"\";\n");
print("var default_huile_quantity=\"select\";\n");
print("var default_qrcode_communication_pilote=\"\";\n");
print("var default_fqrcode_montant_total_pilote=0;\n");
// Les instructeurs peuvent introduire des 1/2 litre d'huile + Patrick pour pouvoir tester!
if ($userId==66 or $userIsInstructor) {
print("var default_is_instructor=1;\n");
}
else {
print("var default_is_instructor=0;\n");
}
// bookingid is defined by the key "id" (coming from the booking) or by the key "cdv_booking" (coming from this page)
$auth="";
$logid="";
if (isset($_REQUEST['auth']) and $_REQUEST['auth'] != '') {
$auth=$_REQUEST['auth'];
print("var default_auth='$auth';\n");
if ($userId <= 0) journalise($userId, 'D', "IntroCarnetVol.php called with auth=$auth without being logged in") ;
}
if (isset($_REQUEST['id']) and $_REQUEST['id'] != '') {
$bookingid=$_REQUEST['id'];
if (isset($_REQUEST['auth']) and $_REQUEST['auth'] != '') {
$auth=$_REQUEST['auth'];
print("var default_auth='$auth';\n");
} else {
print("var default_auth='';\n");
}
}
else if (isset($_REQUEST['cdv_bookingid']) and $_REQUEST['cdv_bookingid'] != '') {
$bookingid=$_REQUEST['cdv_bookingid'];
print("var default_auth='';\n");
} else {
$bookingid = 0 ;
print("var default_auth='';\n");
}
// Prevent SQL injection
if (! is_numeric($bookingid)) journalise($userId, "F", "Paramètre bookingid ($bookingid) n'est pas numérique") ;
// Check whether user is logged in
if ($userId == 0) {
if (!isset($_REQUEST['auth']) or $_REQUEST['auth'] != md5($bookingid . $shared_secret)) {
print("</script><p style=\"color: red;\"><b>Impossible to proceed to this request.</br>You must be connected to the spa-aviation.be site or use a valid auth code and not \"$_REQUEST[auth]\"</b></p>") ;
journalise($userId, "F", "You must be connected or use a valid auth code and not \"$_REQUEST[auth]\" for bookingid $bookingid") ;
}
}
print("var default_bookingid=$bookingid;\n");
print("var default_pilot=$userId;\n");
$aircraft_techLog=GetJSONIncidentByPlanes();
print("var default_aircrafttechlog='$aircraft_techLog';\n");
?>
</script>
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['setUserId', '<?=$userName?>']);
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setDomains", ["*.spa-aviation.be","*.ebsp.be","*.m.ebsp.be","*.m.spa-aviation.be","*.resa.spa-aviation.be"]]);
_paq.push(['enableHeartBeatTimer']);
_paq.push(['setCustomVariable', 1, "userID", <?=$userId?>, "visit"]);
_paq.push(["setCookieDomain", "*.spa-aviation.be"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.vyncke.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '8']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body>
<h1 style="text-align: center;">Introduction vol</h1>
<?php
//---------------------------------------------------------------------------
// For FI (or when the trusted_booker cookie is set), display all existing reservations of today w/o any log entries
//---------------------------------------------------------------------------
$trustedBooker = (isset($_COOKIE['trusted_booker']) and $_COOKIE['trusted_booker'] == 1) ;
$trustedBookerMsg = ($trustedBooker) ? " Ce browser est trusted." : "" ;
if ($userIsAdmin or $userIsInstructor) {
$result = mysqli_query($mysqli_link, "SELECT r_plane, r_id, r_start, r_stop, r_comment, p.name AS pilot_name, i.name AS instructor_name
FROM $table_bookings r JOIN $table_planes pp on r_plane = pp.id JOIN $table_users AS p ON r_pilot = p.id LEFT JOIN $table_users AS i ON r_instructor = i.id
WHERE r_cancel_date IS NULL AND r_type != " . BOOKING_MAINTENANCE . " AND DATE(r_start) = CURRENT_DATE() AND pp.ressource = 0
ORDER BY r_start")
or journalise($userId, "F", "Cannot get all today bookings: " . mysqli_error($mysqli_link)) ;
if ($result->num_rows == 0) {
print("<p>Aucune réservation prévue ce jour.</p>\n") ;
} else {
// Table des reservations du jours
print("<center><h2>Choisir une réservation de ce jour</h2>
<p>Liste des réservations de ce jour (cliquez sur la date pour préremplir les champs ci-dessous).</br><em>Visible uniquement par les FIs et administrateurs.$trustedBookerMsg</em></p>
<table width=\"100%\">
<tr><th>Heure locale</th><th>Avion</th><th>Pilote</th><th>Remarque</th><th>Action</th></tr>\n") ;
while ($row = $result->fetch_assoc()) {
$pilot = db2web($row['pilot_name']) ;
$instructor = db2web($row['instructor_name']) ;
$crew = ($instructor == '') ? $pilot : "$pilot/$instructor" ;
$comment = db2web($row['r_comment']) ;
$auth = md5($row['r_id'] . $shared_secret) ;
print("<tr><td><a href=\"$_SERVER[PHP_SELF]?id=$row[r_id]&auth=$auth\">$row[r_start]</a></td><td>$row[r_plane]</td><td>$crew</td><td>$comment</td>
<td> <button type=\"button\" value=\"Fill\" onclick=\"window.location.href='$_SERVER[PHP_SELF]?id=$row[r_id]&auth=$auth';\">✎ Ajouter des segments</button>
<button style=\"background-color: salmon; color: white;\" value=\"Del\" onclick=\"window.location.href='$_SERVER[PHP_SELF]?id=$row[r_id]&auth=$auth&bookingtable=1';\">🗑 Annuler la réservation</button> </td>
</tr>\n") ;
}
print("</table></center><p></p>\n") ;
}
}
$compteurTypeByPlane= array();
$cars["color"] = "Red";
print("<script>\n");
print("var planes_properties=[\n");
$result=mysqli_query($mysqli_link,"SELECT upper(id) as name, cout, l_end_hour, l_end_minute, l_flight_end_hour, l_flight_end_minute, compteur_vol, compteur_type, model
FROM rapcs_planes p JOIN rapcs_logbook l ON p.id = l_plane
WHERE l_id = (SELECT MAX(ll.l_id) FROM rapcs_logbook ll WHERE ll.l_plane = l.l_plane)
and ressource = 0 and actif=1");
while($row=mysqli_fetch_array($result)) {
print("{ id: \"$row[name]\" , name: \"$row[name]\" , compteur_type: \"$row[compteur_type]\" ,
compteur: \"$row[l_end_hour].$row[l_end_minute]\",
compteur_vol: \"$row[compteur_vol]\", compteur_vol_valeur: \"$row[l_flight_end_hour].$row[l_flight_end_minute]\", prix: \"$row[cout]\" , model: \"$row[model]\"},\n");
$compteurTypeByPlane[$row["name"]]=$row["compteur_type"];
}
print("];\n");
print("</script>\n");
//---------------------------------------------------------------------------
// Management of previous and next booking
// Find the previous/next booking
//---------------------------------------------------------------------------
// Find the previous/next booking
// Retrieve the booking
$bookingidForPrevious=$bookingid;
if ($bookingidForPrevious) {
$result = mysqli_query($mysqli_link, "select username, r_id, r_plane, r_start, r_stop, r_type, r_pilot, r_instructor, r_who, r_date,
r_from, r_to, compteur_type, compteur_vol, model, compteur, compteur_date,
date_add(r_start, interval 15 minute) as r_takeoff, date(r_start) as r_day
from $table_bookings join $table_users as p on r_pilot = p.id, $table_planes as a
where r_id = $bookingidForPrevious and a.id = r_plane")
or journalise($userId, "F", "Cannot access the booking #$bookingidForPrevious: " . mysqli_error($mysqli_link)) ;
} else { // Retrieve the nearest one
if ($userId <= 0) journalise($userId, "F", "Vous devez être connecté") ;
$result = mysqli_query($mysqli_link, "select username, r_id, r_plane, r_start, r_stop, r_type, r_pilot, r_instructor, r_who, r_date,
r_from, r_to, compteur_type, compteur_vol, model, compteur, compteur_date,
date_add(r_start, interval 15 minute) as r_takeoff, date(r_start) as r_day
from $table_bookings join $table_users as p on r_pilot = p.id, $table_planes as a
where r_pilot = $userId and r_start < sysdate() and r_cancel_date is null and a.ressource = 0
order by r_start desc
limit 0,1")
or journalise($userId, "F", "Cannot access closest booking in the past: " . mysqli_error($mysqli_link)) ;
}
$booking = mysqli_fetch_array($result) ;
if ($bookingidForPrevious) {
$condition = "(r_pilot = $booking[r_pilot])" ;
} else {
$condition = "(r_pilot = $userId or r_instructor = $userId)" ;
$bookingidForPrevious = $booking['r_id'] ;
$auth = md5($bookingidForPrevious . $shared_secret) ;
}
$result = mysqli_query($mysqli_link, "select * from $table_bookings where r_cancel_date is null and r_stop < '$booking[r_start]' and r_start <= sysdate() and $condition order by r_start desc limit 0,1")
or journalise($userId, "F", "Cannot access previous booking: ".mysqli_error($mysqli_link)) ;
$row = mysqli_fetch_array($result) ;
$previous_id='';
if(!is_null($row ) && isset($row['r_id'])) {
$previous_id = $row['r_id'] ;
}
$previous_auth = md5($previous_id . $shared_secret) ;
$result = mysqli_query($mysqli_link, "select * from $table_bookings where r_cancel_date is null and r_start > '$booking[r_stop]' and r_start <= sysdate() and $condition order by r_start asc limit 0,1")
or journalise($userId, "F", "Cannot access next booking: ".mysqli_error($mysqli_link)) ;
$row = mysqli_fetch_array($result) ;
$next_id='';
if(!is_null($row )) {
$next_id = $row['r_id'] ;
}
else {
$next_id='';
}
$next_auth = md5($next_id . $shared_secret) ;
print('<table width="100%" border-spacing="0px">');
print('<tr><td width="33%" style="text-align: left;">');
if ($previous_id != '') {
print("<<< <a href=\"$_SERVER[PHP_SELF]?id=$previous_id&auth=$previous_auth\">Réservation précédente</a>\n") ;
}
print("</td><td width=\"33%\" style=\"text-align: center;\"><a href=\"$_SERVER[PHP_SELF]\">Vol sans réservation</a>");
print('</td><td style="text-align: right;">');
if ($next_id != '') {
print("<a href=\"$_SERVER[PHP_SELF]?id=$next_id&auth=$next_auth\">Réservation suivante</a> >>>\n") ;
}
else {
if(!$bookingid) {
$next_id = $bookingidForPrevious ;
$next_auth = md5($bookingidForPrevious . $shared_secret) ;
print("<a href=\"$_SERVER[PHP_SELF]?id=$next_id&auth=$next_auth\">Dernière Réservation</a>\n");
}
}
print('</td></tr>');
print('</table>');
//-----------------------------------------------------------------------------------------------------
// Do we need to delete a segment in the logbook?
//-----------------------------------------------------------------------------------------------------
if (isset($_REQUEST['audit_time']) and $_REQUEST['audit_time'] != '') {
$logid=$_REQUEST['logid'];
// Remove a DTO flight associated to this logid
//print("before RemoveDTOFlight: logid=$logid</br>");
RemoveDTOFlight($logid);
// Remove the entry in the LogBook
$audit_time = mysqli_real_escape_string($mysqli_link, $_REQUEST['audit_time']) ;
mysqli_query($mysqli_link, "delete from $table_logbook where l_id=$logid and l_audit_time='$audit_time'")
or journalise($userId, "F", "Cannot delete: " . mysqli_error($mysqli_link)) ;
if (mysqli_affected_rows($mysqli_link) > 0) {
$insert_message = "Carnet de routes mis à jour" ;
journalise($userId, 'I', "Logbook entry deleted for booking $bookingid (done at $audit_time).") ;
} else {
$insert_message = "Impossible d'effacer la ligne dans le carnet de routes" ;
journalise($userId, 'E', "Error (" . mysqli_error($mysqli_link). ") while deleting logbook entry for booking $bookingid (done at $audit_time).") ;
}
RemoveHuileQuantity($logid);
}
//-----------------------------------------------------------------------------------------------------
// Do we need to delete a reservation in booking table?
// 1. Delete all segments associated to this bookingid
// 2. Delete the entry in the bookings table
//-----------------------------------------------------------------------------------------------------
if (isset($_REQUEST['bookingtable']) and $_REQUEST['bookingtable'] == '1') {
// Delete all DTO flights associated to this bookingid
// All DTO flight associated to all segments behing this bookingid
RemoveAllDTOFlightBehindBooking($bookingid);
//All Oil quantity associated to a bookingID
RemoveAllHuileQuantityBooking($bookingid);
// Delete all already logged segments associated to this bookingid
mysqli_query($mysqli_link, "delete from $table_logbook where l_booking=$bookingid")
or journalise($userId, "F", "Cannot delete: " . mysqli_error($mysqli_link)) ;
if (mysqli_affected_rows($mysqli_link) > 0) {
$insert_message = "Carnet de routes mis à jour" ;
journalise($userId, 'I', mysqli_affected_rows($mysqli_link) . " logbook entri(es) deleted for booking $bookingid.") ;
}
// Delete the entry in the bookings table
$remote_address = getClientAddress() ;
mysqli_query($mysqli_link, "update $table_bookings set r_cancel_date=sysdate(), r_cancel_who=$userId, r_cancel_reason='IntroCarnetVol', r_cancel_address='$remote_address'
where r_id=$bookingid")
or journalise($userId, "F", "Cannot cancel booking: " . mysqli_error($mysqli_link)) ;
if (mysqli_affected_rows($mysqli_link) > 0) {
$insert_message = "Réservation mise à jour (annulée)" ;
journalise($userId, 'I', "Booking table entry cancelled for booking $bookingid.") ;
$bookingid=0;
$id=0;
print("<script>var default_bookingid=$bookingid;</script>\n");
} else {
$insert_message = "Impossible d'effacer la ligne dans les réservations" ;
journalise($userId, 'E', "Error (" . mysqli_error($mysqli_link). ") while cancelling booking entry for booking $bookingid.") ;
}
}
//-----------------------------------------------------------------------------------------------------
// Summary of the Reservation
//-----------------------------------------------------------------------------------------------------
print('<p></p>');
if($bookingid) {
$result=mysqli_query($mysqli_link,"SELECT r_id, r_plane, r_type, r_from, r_to, r_start, r_stop, r_pilot, p.last_name as pilotName, i.last_name as instructorName
FROM $table_bookings r join $table_person p on r.r_pilot = p.jom_id left join $table_person i on r.r_instructor = i.jom_id
WHERE r_id = $bookingid")
or journalise($userId, "F", "Impossible de retrouver le bookingid dans booking: " . mysqli_error($mysqli_link)) ;
$row=mysqli_fetch_array($result);
$start_UTC = gmdate('H:i', strtotime("$row[r_start] UTC")) ;
$end_UTC = gmdate('H:i', strtotime("$row[r_stop] UTC")) ;
$dateFlight=gmdate('l j-m-Y', strtotime("$row[r_start] UTC")) ;
if ($row['instructorName'] == '' )
$crew = db2web($row['pilotName']) ;
else
$crew = db2web($row['pilotName'] . '/' . $row['instructorName']) ;
if($row['r_type'] == BOOKING_MAINTENANCE) {
$crew= $crew." (Maintenance)";
}
$crew = db2web($crew) ; // As DB is latin and web is UTF-8
print('<p></p>');
//print(" 1. BookingId=$bookingid (r_id)</br>");
// Table Resume de la reservation selectionnee
print("<center><table width=\"100%\" border-spacing=\"0px\">
<thead>
<tr><th style=\"background-color: Gainsboro; text-align: center;\" colspan=\"8\">Résumé de la réservation (Heure locale)</th></tr>
<tr><th>Date</th><th>Avion</th><th>Pilote</th><th>De</th><th>Départ</th><th>À</th><th>Arrivée</th><th>Action</th></tr>
</thead>
<tbody>
<tr>
<td>$dateFlight</td>
<td>$row[r_plane]</td>
<td>$crew</td>
<td>$row[r_from]</td>
<td>$start_UTC</td>
<td>$row[r_to]</td>
<td>$end_UTC</td>
<td> <button type=\"button\" value=\"Del\" onclick=\"redirectBookingDelete('$_SERVER[PHP_SELF]',$bookingid,'$auth');\">🗑 Annuler la réservation</button>
</td>
</tr>
</tbody>
</table></center>");
// Select the default pilot
print("<script>var default_pilot=$row[r_pilot];</script>\n") ;
}
//---------------------------------------------------------------------------
// Manage l'enregistrement du vol introduit dans la form.
//---------------------------------------------------------------------------
$numeroVol="";
if (isset($_REQUEST['action']) and $_REQUEST['action'] != '') {
// TODO sanitize all fields to prevent SQL injection
$cdv_bookingid=$_REQUEST['cdv_bookingid'];
$cdv_logbookid=$_REQUEST['cdv_logbookid'];
$cdv_flightreferenceid=$_REQUEST['cdv_flightreferenceid'];
$cdv_segment=$_REQUEST['cdv_segment_count'];
$cdv_aircraft=$_REQUEST['cdv_aircraft'];
$cdv_aircraft_model=$_REQUEST['cdv_aircraft_model'];
$cdv_flight_date=$_REQUEST['cdv_flight_date'];
$cdv_pilot_name=$_REQUEST['cdv_pilot_name'];
$cdv_pilot_function=$_REQUEST['cdv_pilot_function'];
$cdv_flight_instructor="";
if(isset($_REQUEST['cdv_flight_instructor'])) {
$cdv_flight_instructor=$_REQUEST['cdv_flight_instructor'];
}
$cdv_departure_airport=$_REQUEST['cdv_departure_airport'];
$cdv_arrival_airport=$_REQUEST['cdv_arrival_airport'];
$cdv_heure_depart=$_REQUEST['cdv_heure_depart'];
$cdv_heure_arrivee=$_REQUEST['cdv_heure_arrivee'];
$cdv_duree=$_REQUEST['cdv_duree'];
$cdv_compteur_depart=$_REQUEST['cdv_compteur_depart'];
$cdv_compteur_arrivee=$_REQUEST['cdv_compteur_arrivee'];
$cdv_compteur_duree=$_REQUEST['cdv_compteur_duree'];
$cdv_compteur_vol_depart=$_REQUEST['cdv_compteur_vol_depart'];
$cdv_compteur_vol_arrivee=$_REQUEST['cdv_compteur_vol_arrivee'];
$cdv_compteur_vol_duree=$_REQUEST['cdv_compteur_vol_duree'];
$cdv_nombre_atterrissage=$_REQUEST['cdv_nombre_atterrissage'];
$cdv_nombre_crew=$_REQUEST['cdv_nombre_crew'];
$cdv_nombre_passager=$_REQUEST['cdv_nombre_passager'];
$cdv_nature_vol=$_REQUEST['cdv_nature_vol'];
$cdv_frais_CP=$_REQUEST['cdv_frais_CP'];
$cdv_frais_CP_type=$_REQUEST['cdv_frais_CP_type'];
$cdv_frais_numero_vol=$_REQUEST['cdv_frais_numero_vol'];
$cdv_frais_CP_PAX="";
if(isset($_REQUEST['cdv_frais_CP_PAX'])) {
$cdv_frais_CP_PAX=$_REQUEST['cdv_frais_CP_PAX'];
}
$cdv_frais_remarque=$_REQUEST['cdv_frais_remarque'];
$cdv_frais_DC=$_REQUEST['cdv_frais_DC'];
$cdv_ATL_level=$_REQUEST['cdv_ATL_level'];
$cdv_ATL_description=$_REQUEST['cdv_ATL_description'];
$cdv_huile_quantity=$_REQUEST['cdv_huile_quantity'];
$cdv_qrcode_montant_total_pilote=$_REQUEST['cdv_qrcode_montant_total_pilote'];
$cdv_qrcode_communication_pilote=$_REQUEST['cdv_qrcode_communication_pilote'];
print("<script>\n");
print("var default_qrcode_communication_pilote=\"$cdv_qrcode_communication_pilote\";\n");
print("var default_fqrcode_montant_total_pilote=$cdv_qrcode_montant_total_pilote;\n");
print("</script>\n");
$planeId=$cdv_aircraft;
$planeModel=$cdv_aircraft_model;
$bookingidPage=CheckVar($cdv_bookingid);
$fromAirport=$cdv_departure_airport;
$toAirport=$cdv_arrival_airport;
$engineStartHour=GetCompteurHour($cdv_compteur_depart);
$engineStartMinute=GetCompteurMinute($cdv_compteur_depart);
$engineEndHour=GetCompteurHour($cdv_compteur_arrivee);
$engineEndMinute=GetCompteurMinute($cdv_compteur_arrivee);
$flightStartHour=CheckVar(GetCompteurHour($cdv_compteur_vol_depart));
$flightStartMinute=CheckVar(GetCompteurMinute($cdv_compteur_vol_depart));
$flightEndHour=CheckVar(GetCompteurHour($cdv_compteur_vol_arrivee));
$flightEndMinute=CheckVar(GetCompteurMinute($cdv_compteur_vol_arrivee));
$startDayTime=GetDayTime($cdv_flight_date,$cdv_heure_depart);
$endDayTime= GetDayTime($cdv_flight_date,$cdv_heure_arrivee);
$flightType=CheckVar($cdv_nature_vol);
$isPICFunction=1;
if($cdv_pilot_function=="DC") {
$isPICFunction=0;
}
else if($cdv_pilot_function=="PIC") {
$isPICFunction=1;
$cdv_flight_instructor=0;
}
else if($cdv_pilot_function=="PICSupervise") {
$isPICFunction=2;
}
else {
// PICRecheck
$isPICFunction=1;
}
$remark=CheckVar($cdv_frais_remarque); // May return the string NULL
// Aircraft Technical Log
$ATLLevel=$cdv_ATL_level;
$ATLDescription=$cdv_ATL_description;
//print("PRE1 ATLLevel=$ATLLevel; ATLDescription=$ATLDescription<br>");
$huileQuantity=$cdv_huile_quantity;
// Vol IF or INIT
$numeroVol=CheckVar($cdv_frais_numero_vol); // May return the string NULL
//print("numeroVol1:$numeroVol</br>\n");
if ($numeroVol != 'NULL') {
$numeroVol = "$numeroVol" ; // As $remark is not quoted in the SQL statement
// Transform a ReferenceId into a Reference (String)
//print("SELECT f_id, f_reference FROM $table_flight WHERE f_id = '$numeroVol';</br>") ;
$flightResult=mysqli_query($mysqli_link,"SELECT f_id, f_reference FROM $table_flight WHERE f_id = '$numeroVol';")
or journalise($userId, "F", "Impossible de retrouver le f_id=$numeroVol dans table_flight: " . mysqli_error($mysqli_link)) ;
if ($flightResult->num_rows > 0) {
$flightRow=mysqli_fetch_array($flightResult);
$numeroVol=$flightRow['f_reference'];
}
//print("numeroVol2:$numeroVol</br>\n");
if ($remark != 'NULL') {
$remark="#$numeroVol $remark";
//print("remark1:$remark</br>\n");
}
else {
$remark="#$numeroVol";
//print("remark2:$remark</br>\n");
}
}
if ($remark != 'NULL') {
$remark = "'$remark'" ; // As $remark is not quoted in the SQL statement
}
//print("remark3:$remark</br>\n");
$paxCount=$cdv_nombre_passager;
$crewCount=$cdv_nombre_crew;
$pilotId=$cdv_pilot_name;
$instructorId=CheckVar($cdv_flight_instructor);
$dayLandings= $cdv_nombre_atterrissage;
$nightLandings=0;
$shareType=CheckVar($cdv_frais_CP);
$shareType=$cdv_frais_CP;
if(strcmp($shareType,"NoCP")==0) {
$shareType='';
}
$shareMember=$cdv_frais_CP_type;
$isInstructorPaid=1;
if($cdv_frais_DC == "No DC") {
$isInstructorPaid=0;
}
$flightStartHour = mysqli_real_escape_string($mysqli_link, $flightStartHour) ;
$instructorId = mysqli_real_escape_string($mysqli_link, $instructorId) ;
//if($planeId=="OO-APV") {
if (array_key_exists($planeId,$compteurTypeByPlane)) {
if($compteurTypeByPlane[$planeId]=="6") {
print("Compteur decimal<br>");
$engineStartMinute=strval(intval($engineStartMinute)*6);
$engineEndMinute=strval(intval($engineEndMinute)*6);
}
}
if($bookingid == 0){
// -----------------------------------------
// Vol sans reservation: Creation d'une entrée dans la table des bookings
// =====================
// -------------------------------------------
// Special time handling as bookings are in local time
$dt = new DateTime($startDayTime, new DateTimeZone('UTC'));
$dt->setTimezone(new DateTimeZone($default_timezone));
$rStart = $dt->format('Y-m-d H:i');
$dt = new DateTime($endDayTime, new DateTimeZone('UTC'));
$dt->setTimezone(new DateTimeZone($default_timezone));
$rStop = $dt->format('Y-m-d H:i');
$rType = ($instructorId != '' and $instructorId > 0) ? BOOKING_INSTRUCTOR : BOOKING_PILOT;
mysqli_query($mysqli_link, "insert into $table_bookings(r_plane, r_start, r_stop, r_pilot, r_instructor, r_type,
r_from, r_to, r_who, r_address, r_date)
values ('$planeId', '$rStart', '$rStop', $pilotId, $instructorId, $rType,
'$fromAirport', '$toAirport', $pilotId, '" . getClientAddress() . "',sysdate());")
or journalise($userId, "F", "Impossible d'ajouter dans mes reservations: " . mysqli_error($mysqli_link)) ;
$r_id = mysqli_insert_id($mysqli_link) ;
$bookingid=$r_id;
$id=$r_id;
$bookingidPage=$r_id;
print("<script>var default_bookingid=$bookingid;</script>\n");
journalise($userId, "I", "Synthetic booking entry added for $planeId, flight $rStart@$fromAirport to $rStop@$toAirport");
}
if($cdv_logbookid==0) {
// -----------------------------------------
// Insert a new segment
// =====================
// -------------------------------------------
//print("Insert a segment</br>");
//print("Insert a segment</br>");
if(IsSegmentAlreadyIntroduced($planeId,$startDayTime,$pilotId)) {
print("<script>alert('Ce vol semble déjà introduit. Un segment commencant à $startDayTime existe déjà. Vous devez l éditer s il n est pas correct.');</script>");
$logid=0;
$l_id=0;
}
else {
mysqli_query($mysqli_link, "insert into $table_logbook(l_plane, l_model, l_booking, l_from, l_to,
l_start_hour, l_start_minute, l_end_hour, l_end_minute, l_flight_start_hour, l_flight_start_minute, l_flight_end_hour, l_flight_end_minute,
l_start, l_end, l_flight_type, l_remark, l_pax_count, l_crew_count, l_pilot, l_is_pic, l_instructor, l_instructor_paid, l_day_landing, l_night_landing,
l_share_type, l_share_member, l_audit_who, l_audit_ip, l_audit_time)
values ('$planeId', '$planeModel', $bookingidPage, '$fromAirport', '$toAirport',
$engineStartHour, $engineStartMinute, $engineEndHour, $engineEndMinute, $flightStartHour, $flightStartMinute, $flightEndHour, $flightEndMinute,
'$startDayTime', '$endDayTime', '$flightType', $remark, $paxCount, $crewCount, $pilotId, $isPICFunction, $instructorId, $isInstructorPaid, $dayLandings, $nightLandings,
'$shareType', $shareMember, $userId, '" . getClientAddress() . "',sysdate());")
or journalise($userId, 'F', "<p style=\"color: red;\"><b>Impossible d'ajouter le segment dans le logbook:Vol déjà introduit.</br>Erreur SQL=" . mysqli_error($mysqli_link)."</br>9 fois sur 10, cela signifie que vous avez déjà introduit un vol ou un segment qui démarre au même moment $startDayTime.</br>Faite un Back avec votre Browser et corrigé l'heure de départ.</b></p>") ;
$l_id = mysqli_insert_id($mysqli_link) ;
$logid=$l_id;
journalise($userId, "I", "New Logbook entry added for $planeId, engine from $engineStartHour: $engineStartMinute to $engineEndHour:$engineEndMinute flight $startDayTime@$fromAirport to $endDayTime@$toAirport");
// Table resume ajoute
print('<p></p><center><table width=100%" border-spacing="0px"><tbody>
<tr><td style="background-color: LightSalmon; text-align: center;" colspan="8">Un vol enregistré: Résumé (Heure UTC)</td></tr>
<tr><td>Avion</td><td>Pilote</td><td>De</td><td>Heure</td><td>A</td><td>Heure</td><td>Durée</td></tr>') ;
}
}
else {
// -----------------------------------------
// Edit a segment
// ===============
// -------------------------------------------
//print("Edit a segment $cdv_logbookid </br>");
// mysqli_query($mysqli_link, "replace into $table_logbook(l_id, l_plane, l_model, l_booking, l_from, l_to,
// l_start_hour, l_start_minute, l_end_hour, l_end_minute, l_flight_start_hour, l_flight_start_minute, l_flight_end_hour, l_flight_end_minute,
// l_start, l_end, l_flight_type, l_remark, l_pax_count, l_crew_count, l_pilot, l_is_pic, l_instructor, l_instructor_paid, l_day_landing, l_night_landing,
// l_share_type, l_share_member, l_audit_who, l_audit_ip, l_audit_time)
// values ('$cdv_logbookid', '$planeId', '$planeModel', $bookingidPage, '$fromAirport', '$toAirport',
// $engineStartHour, $engineStartMinute, $engineEndHour, $engineEndMinute, $flightStartHour, $flightStartMinute, $flightEndHour, $flightEndMinute,'$startDayTime', '$endDayTime', '$flightType', $remark, $paxCount, $crewCount, $pilotId, $isPICFunction, $instructorId, $isInstructorPaid, $dayLandings, $nightLandings,
// '$shareType', $shareMember, $userId, '" . getClientAddress() . "',sysdate());")
// As l_id is a foreign key, let's use an UPDATE rather than a REPLACE
mysqli_query($mysqli_link, "UPDATE $table_logbook
SET l_plane='$planeId', l_model='$planeModel', l_booking=$bookingidPage, l_from='$fromAirport', l_to='$toAirport',
l_start_hour=$engineStartHour, l_start_minute=$engineStartMinute, l_end_hour=$engineEndHour, l_end_minute=$engineEndMinute,
l_flight_start_hour=$flightStartHour, l_flight_start_minute=$flightStartMinute, l_flight_end_hour=$flightEndHour, l_flight_end_minute=$flightEndMinute,
l_start='$startDayTime', l_end='$endDayTime', l_flight_type='$flightType', l_remark=$remark, l_pax_count=$paxCount, l_crew_count=$crewCount,
l_pilot=$pilotId, l_is_pic= $isPICFunction, l_instructor=$instructorId, l_instructor_paid=$isInstructorPaid, l_day_landing=$dayLandings, l_night_landing=$nightLandings,
l_share_type='$shareType', l_share_member= $shareMember, l_audit_who=$userId, l_audit_ip='" . getClientAddress() . "', l_audit_time=sysdate()
WHERE l_id=$cdv_logbookid")
or
journalise($userId, "F", "(2) l_audit_who=$userId, l_audit_ip='" . getClientAddress() . "', l_audit_time=sysdate() Impossible de mettre à jour le logbook: " . mysqli_error($mysqli_link)) ;
// $l_id = mysqli_insert_id($mysqli_link) ;
$l_id = $cdv_logbookid ;
journalise($userId, "I", "Logbook entry updated for $planeId, engine from $engineStartHour: $engineStartMinute to $engineEndHour:$engineEndMinute flight $startDayTime@$fromAirport to $endDayTime@$toAirport");
// Table resume du vol édité
print('<p></p><center><table width=100%" border-spacing="0px"><tbody>
<tr><td style="background-color: LightSalmon; text-align: center;" colspan="8">Un vol édité: Résumé (Heure UTC)</td></tr>
<tr><td>Avion</td><td>Pilote</td><td>De</td><td>Heure</td><td>A</td><td>Heure</td><td>Durée</td></tr>') ;
}
print("<tr>");
print("<td>$planeId</td>");
if($instructorId != 'NULL' && $instructorId != 0) {
print("<td>$pilotId/$instructorId</td>");
} else {
print("<td>$pilotId</td>");
}
print("<td>$fromAirport</td>");
print("<td>$cdv_heure_depart</td>");
print("<td>$toAirport</td>");
print("<td>$cdv_heure_arrivee</td>");
print("<td>$cdv_duree</td>");
print("</tbody></table></center>");
//----------------------------------------------------
//Manage Aircraft Technical Log
//----------------------------------------------------
if($ATLLevel!="" && $ATLLevel!="select") {
$ATLId=AddATLIncident($l_id, $planeId, $ATLLevel, $ATLDescription);
if($ATLId>0) {
print("<p style=\"color: red;\"><b>An entry $ATLId is introduced in the Technical Log: $ATLLevel </b></p>") ;
if(SentIncidentMail($ATLId, $planeId, $ATLLevel, $ATLDescription)) {
print("<p style=\"color: red;\"><b>A mail is send to FI and the fleet team</b></p>") ;
}
}
}
//----------------------------------------------------
//Manage Oil Log
//----------------------------------------------------
$topupId=ManageHuileQuantity($l_id, $planeId, $huileQuantity, $pilotId, $startDayTime, $engineStartHour,$engineStartMinute);
if($topupId>0) {
print("<p style=\"color: red;\"><b>$huileQuantity oil liter(s) added for the plane $planeId.</b></p>") ;
}
//----------------------------------------------------
// Associate the flight with a DTO fligth
// Only if pilot is a student
//----------------------------------------------------
//print("</br>Check if the pilot is a student pilotId=$pilotId </br>");
//print("SELECT user_id FROM $table_user_usergroup_map WHERE user_id = '$pilotId' and group_id='$joomla_student_group';</br>");
// Look in the $table_user_usergroup_map if the pilot is a student
$studentResult=mysqli_query($mysqli_link,"SELECT user_id FROM $table_user_usergroup_map WHERE user_id = '$pilotId' and group_id='$joomla_student_group';")
or journalise($userId, "F", "Impossible de retrouver le user_id=$pilotId dans table_user_usergroup_map: " . mysqli_error($mysqli_link)) ;
if ($studentResult->num_rows != 0) {
if($logid!="") {
$l_id=$logid;
}
if(!HasDTOFlight($l_id)) {
//print("C'est aussi un eleve logid=$logid</br>");
// Create a flight in the DTO table rapcs_dto_flight
$flight = new Flight() ;
$flight->flightLog = $l_id;
$flight->student= $pilotId;
if($isPICFunction>0) {
$flight->flightType="Solo";
//print("Creating Flight DTO flightType Solo</br>");
}
else {
$flight->flightType="DC";
//print("Creating Flight DTO flightType DC</br>");
}
$flight->save();
//print("FlightLog saved</br>");
}
}
else {
//print("Ce n'est pas un eleve</br");
}
}
// QRCode apres enregistrement
$epcString="";
print("<center><span id=\"id_payment_after\">");
print("<h3>Paiement du vol - Montant: <span id=\"id_payment_amount_after\"></span> €</br>");
print("Communication : \"<span id=\"id_payment_communication_after\"></span>\"</br>Compte : BE64 7320 3842 1852</h3>\n");
// evyncke: as the $epcString is still empty, no need to specify the src as it is invalid... was src=\"https://chart.googleapis.com/chart?cht=qr&chs=300x300&&chl=" . urlencode($epcString) . "\"
print("<img style=\"text-align: right;\" id=\"id_payment_qr_code_after\" width=\"150\" height=\"150\" ></center>");
print("</span>");
//----------------------------------------------------
// Associate the flight with an IF or an INIT flight
//----------------------------------------------------
//print("cdv_flightreferenceid=$cdv_flightreferenceid;numeroVol=$numeroVol;shareType=$shareType;shareMember=$shareMember</br>");
if($numeroVol!="" && $shareType=="CP1" && ($shareMember==-3 ||$shareMember==-4 || $shareMember==-6)) {
//print("Associate the flight with an IF or an INIT flight</br>");
$f_date_flown=$startDayTime;
$cdv_flightreferenceid=0;
if($cdv_flightreferenceid==0) {
//print("SELECT f_id, f_reference, f_type, f_date_flown , f_booking FROM $table_flight WHERE f_reference = '$numeroVol';</br>") ;
$flightResult=mysqli_query($mysqli_link,"SELECT f_id, f_reference, f_type, f_date_flown, f_booking FROM $table_flight WHERE f_reference = '$numeroVol';")
or journalise($userId, "F", "Impossible de retrouver le f_reference=$numeroVol dans table_flight: " . mysqli_error($mysqli_link)) ;
if ($flightResult->num_rows == 0) {
print("<script>alert('La reference du vol IF/INI $numeroVol n existe pas. Ce référence de vol IF/INI n\'est pas fermée.');</script>");
print("<p style=\"color: red;\"><b>The flight $numeroVol is NOT correctly closed</b></p>") ;
}
else {
$flightRow=mysqli_fetch_array($flightResult);
$cdv_flightreferenceid= $flightRow['f_id'];
$associatedBookingID=$flightRow['f_booking'];
if($associatedBookingID != $bookingid) {
print("<script>alert('La reference du vol IF/INI $numeroVol n est pas associé à cette réservation. Il faut corriger dans l outil de gestion des vols découvertes ou utiliser le numéro de vol correct. Cette référence de vol IF/INI n est pas fermée.');</script>");
$cdv_flightreferenceid=0;
print("<p style=\"color: red;\"><b>The flight $numeroVol is NOT correctly closed</b></p>") ;
}
}
}
if($cdv_flightreferenceid!=0) {
mysqli_query($mysqli_link,"update $table_flight set f_date_flown='$f_date_flown', f_pilot=$pilotId, f_booking=$bookingidPage where f_id=$cdv_flightreferenceid;")
or journalise($userId, "F", "Impossible d'ajouter dans le table_flight:" . mysqli_error($mysqli_link)) ;
//$flightRow=mysqli_fetch_array($flightResult);
//$f_id = mysqli_insert_id($mysqli_link) ;
print("<p style=\"color: red;\"><b>The flight $numeroVol is correctly closed</b></p>") ;
}
}
//-----------------------------------------------------------------------------------------------------
// display any previous entries related to this booking
//-----------------------------------------------------------------------------------------------------
print('<p></p>');
$end_Time='';
$toAirport='';
if($bookingid) {
//print(" 2. bookingid=$bookingid</br>");
// Now, display any previous entries related to this booking
$result = mysqli_query($mysqli_link, "select l_id, l_start, l_end, l_plane, l_from, l_to, l_flight_type,
l_start_hour, l_start_minute, l_end_hour, l_end_minute, l_day_landing,l_pax_count, l_crew_count, l_flight_type,l_is_pic, l_share_type, l_share_member, l_remark, l_instructor_paid,
l_audit_time, p.last_name as pilotName, i.last_name as instructorName
from $table_logbook l join $table_person p on l.l_pilot = p.jom_id left join $table_person i on l.l_instructor = i.jom_id
where l_booking = $bookingid order by l_start")
or journalise($userId, "F", "Impossible de lire les entrees pour réservation $bookingid: " . mysqli_error($mysqli_link)) ;
$this_segment_id = mysqli_num_rows($result) + 1 ;
if ($this_segment_id > 1) {
// Table Segments deja introduits
print('<center><table width="100%" border-spacing="0px"><tbody>
<tr><td style="background-color: GreenYellow; text-align: center;" colspan="13">Segments déjà introduits pour cette réservation. (Heure UTC)</td></tr>
<tr><th>#</th><th>Avion</th><th>Pilote</th><th>De</th><th>Départ</th><th>A</th><th>Arrivée</th><th>Type</th><th>Compteur</th><th>Atterr</th><th>Crew/Pass</th><th>Remarques</th><th>Action</th></tr>') ;
$aSegment=0;
while ($row = mysqli_fetch_array($result)) {
$logid=$row['l_id'];
// As the OVH MySQL server does not have the timezone support, needs to be done in PHP
$start_UTC = gmdate('H:i', strtotime("$row[l_start] UTC")) ;
$end_UTC = gmdate('H:i', strtotime("$row[l_end] UTC")) ;
$end_Time=$row['l_end'];
//$MOStart=$row['l_start_hour'].'.'.$row['l_start_minute'];
//$MOEnd=$row['l_end_hour'].'.'.$row['l_end_minute'];
$MO=$row['l_start_hour'].'.'.$row['l_start_minute'];
$MO=$MO.'->';
$MO=$MO.$row['l_end_hour'].'.'.$row['l_end_minute'];
$Min=$row['l_end_hour']*60+$row['l_end_minute']-$row['l_start_hour']*60-$row['l_start_minute'];
$MO=$MO." (".$Min."min)";
if (array_key_exists($row["l_plane"],$compteurTypeByPlane)) {
if($compteurTypeByPlane[$row["l_plane"]]=="6") {
$minValue= $row['l_start_minute']/6;
$MO=$row['l_start_hour'].'.'.$minValue;
$MO=$MO.'->';
$minValue= $row['l_end_minute']/6;
$MO=$MO.$row['l_end_hour'].'.'.$minValue;
$Min=$row['l_end_hour']*60+$row['l_end_minute']-$row['l_start_hour']*60-$row['l_start_minute'];
$MO=$MO." (".$Min."min)";
}
}
$aSegment+=1;
$instructorPaid="";
$crew_Count=$row['l_crew_count'];
if($crew_Count==0) $crew_Count=1;
if ($row['instructorName'] == '')
$crew = $row['pilotName'];
else {
$crew = $row['pilotName'] . '/' . $row['instructorName'] ;
if($row['l_instructor_paid']==0) {
$instructorPaid="No DC";
}
}
$crew=db2web($crew);
if ($row['l_is_pic']==1) {
if ($row['instructorName'] == '')
$crew=$crew.' (PIC)';
else {
$crew=$crew.' (PIC-Recheck)';
if($crew_Count==1) $crew_Count=2;
}
}
else {
$crew=$crew.' (DC)';
if($crew_Count==1) $crew_Count=2;
}
$remark="";
$remark=GetFullRemarks($row['l_share_type'],$row['l_share_member'], $row['l_remark'], $instructorPaid );
$toAirport=$row['l_to'];
// retrieve the Flight Id from the LogId
$dtoFlightId=GetDTOFlightIdFromLogId($logid);
//print("dtoFlightId=$dtoFlightId</br>");
print("<tr style='text-align: center;'>
<td>$aSegment ($logid)</td>
<td>$row[l_plane]</td>
<td>$crew</td>
<td>$row[l_from]</td>
<td>$start_UTC</td>
<td>$row[l_to]</td>
<td>$end_UTC</td>
<td>$row[l_flight_type]</td>
<td>$MO</td>
<td>$row[l_day_landing]</td>
<td>$crew_Count / $row[l_pax_count]</td>
<td>$remark</td>
<td><button type=\"button\" value=\"Del\" onclick=\"redirectLogbookDelete('$_SERVER[PHP_SELF]',$bookingid,$logid,'$auth','$row[l_audit_time]');\">🗑 Effacer</button>
<button type=\"button\" value=\"Edit\" onclick=\"window.location.href='$_SERVER[PHP_SELF]?edit=1&id=$bookingid&logid=$logid';\">✎ Editer</button> ");
//<button type=\"button\" value=\"QRCode\" onclick=\"displayQRCode();\"> QRCode</button>"
if($dtoFlightId>0) {
print(" <button type=\"button\" value=\"DTO\" onclick=\"window.location.href='" . SITE_URL . "dto.flight.php?flight=$dtoFlightId';\">DTO</button>");
}
print("
</td>
</tr>\n") ;
}
print('</tbody></table></center>');
}
else {
//print('xxxxx2this_segment_id=$this_segment_id</br>');
//print('<br/>Aucun Segment introduit pour cette réservation.</br>');
print('<center><table border-spacing="0px"><tbody>
<tr><td style="background-color: GreenYellow; text-align: center;" colspan="8">Aucun Segment introduit pour cette réservation</td></tr></tbody></table></center>');
}
}
else {
print('<center><table border-spacing="0px"><tbody>
<tr><td style="background-color: GreenYellow; text-align: center;" colspan="8">Introduction vol sans réservation</td></tr></tbody></table></center>');
}
$editFlag=0;
//---------------------------------------------------------------------------
// Edit a segment
if (isset($_REQUEST['edit']) and $_REQUEST['edit'] != '') {
$logid=$_REQUEST['logid'];
$editFlag=1;
//print("logid=$logid</br>\n");
// Load N entries related to this logid
$result = mysqli_query($mysqli_link, "select l_id, l_instructor, l_pilot, l_start, l_end, l_plane, l_from, l_to, l_flight_type,
l_start_hour, l_start_minute, l_end_hour, l_end_minute, l_flight_start_hour, l_flight_start_minute, l_flight_end_hour, l_flight_end_minute,
l_day_landing,l_pax_count, l_crew_count, l_flight_type,l_is_pic, l_share_type, l_share_member,
l_remark, l_instructor_paid,
l_audit_time, p.last_name as pilotName, i.last_name as instructorName
from $table_logbook l join $table_person p on l.l_pilot = p.jom_id left join $table_person i on l.l_instructor = i.jom_id
where l_booking = $bookingid order by l_start")
or journalise($userId, "F", "Impossible de lire les entrees pour segment $logid: " . mysqli_error($mysqli_link)) ;
$this_segment_id = mysqli_num_rows($result) + 1 ;
//print("this_segment_id=$this_segment_id</br>\n");
print("<script>\n");
if ($this_segment_id > 1) {
$aSegment=0;
while ($row = mysqli_fetch_array($result)) {
$aSegment=$aSegment+1;
if($logid==$row['l_id']) {
//print("Found Segment=$aSegment</br>\n");
print("var default_editflag=$editFlag;\n");
print("var default_segment=$aSegment;\n");
print("var default_logbookid=$logid;\n");
print("var default_plane=\"$row[l_plane]\";\n");
print("var default_pilot=$row[l_pilot];\n");
$anInstructor=0;
if($row['l_instructor']!= NULL){
$anInstructor=$row['l_instructor'];
}
print("var default_instructor=$anInstructor;\n");
$start_UTC = gmdate('Y-m-d H:i', strtotime("$row[l_start] UTC")) ;
print("var default_date_heure_depart=\"$start_UTC\";\n");
$end_UTC = gmdate('Y-m-d H:i', strtotime("$row[l_end] UTC")) ;
print("var default_date_heure_arrivee=\"$end_UTC\";\n");
print("var default_day_landing=$row[l_day_landing];\n");
print("var default_pax_count=$row[l_pax_count];\n");
print("var default_huile_quantity=1.0;\n");
if($row['l_crew_count'] != NULL){
print("var default_crew_count=$row[l_crew_count];\n");
}
else {
print("var default_crew_count=1;\n");
}
print("var default_flight_type=\"$row[l_flight_type]\";\n");
print("var default_from=\"$row[l_from]\";\n");
print("var default_to=\"$row[l_to]\";\n");
print("var default_is_pic=$row[l_is_pic];\n");
print("var default_instructor_paid=$row[l_instructor_paid];\n");
$shareType=$row['l_share_type'];
if($shareType=="") {
$shareType="NoCP";
}
print("var default_share_type=\"$shareType\";\n");
print("var default_share_member=$row[l_share_member];\n");
print("var default_remark=\"$row[l_remark]\";\n");
$compteurStart="$row[l_start_hour].";
if($row['l_start_minute']<10) {
$compteurStart=$compteurStart."0$row[l_start_minute]";
}
else {
$compteurStart=$compteurStart."$row[l_start_minute]";
}
print("var default_compteur_moteur_start=\"$compteurStart\";\n");
$compteurEnd="$row[l_end_hour].";
if($row['l_end_minute']<10) {
$compteurEnd=$compteurEnd."0$row[l_end_minute]";
}
else {
$compteurEnd=$compteurEnd."$row[l_end_minute]";
}
print("var default_compteur_moteur_end=\"$compteurEnd\";\n");
$compteurFlightStart="$row[l_flight_start_hour].";
if($row['l_flight_start_minute']<10) {
$compteurFlightStart=$compteurFlightStart."0$row[l_flight_start_minute]";
}
else {
$compteurFlightStart=$compteurFlightStart."$row[l_flight_start_minute]";
}
print("var default_compteur_flight_start=\"$compteurFlightStart\";\n");
$compteurFlightEnd="$row[l_flight_end_hour].";
if($row['l_flight_end_minute']<10) {
$compteurFlightEnd=$compteurFlightEnd."0$row[l_flight_end_minute]";
}
else {
$compteurFlightEnd=$compteurFlightEnd."$row[l_flight_end_minute]";
}
print("var default_compteur_flight_end=\"$compteurFlightEnd\";\n");
//Edit Aircraft Techical log
$ATLIncidentId=GetATLIncidentID($logid);
//print("(1) GetATLIncidentID($logid) ATLIncidentId=$ATLIncidentId<br>");
if( $ATLIncidentId != 0) {
// An incident was associated to the segment
$ATLSeverity=GetATLIncidentSeverity($ATLIncidentId);
$ATLDescription=GetATLIncidentDescription($ATLIncidentId);
print("var default_ATL_level=\"$ATLSeverity\";\n");
print("var default_ATL_description=\"$ATLDescription\";\n");
}
else {
// no incident associated to the segment
print("var default_ATL_level=\"nothing\";\n");
print("var default_ATL_description=\"\";\n");
}
$huileQuantity = GetHuileQuantity($logid);
print("var default_huile_quantity=\"$huileQuantity\";\n");
}
}
}
}
else {
print("<script>\n");
//---------------------------------------------------------------------------