Completed
Push — feature/date-in-table ( cb2ddb )
by Laurent
01:55
created

addFlight.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
// Load Dolibarr environment
4
if (false === (@include '../main.inc.php')) {  // From htdocs directory
5
    require '../../documents/custom/main.inc.php'; // From "custom" directory
6
}
7
8
global $db, $langs, $user, $conf;
9
10
dol_include_once('/commande/class/commande.class.php');
11
dol_include_once('/flightlog/class/bbcvols.class.php');
12
dol_include_once('/flightlog/class/bbctypes.class.php');
13
dol_include_once("/flightlog/lib/flightLog.lib.php");
14
dol_include_once("/flightlog/validators/FlightValidator.php");
15
dol_include_once("/flightlog/command/CommandInterface.php");
16
dol_include_once("/flightlog/command/CommandHandlerInterface.php");
17
dol_include_once("/flightlog/command/CreateFlightCommand.php");
18
dol_include_once("/flightlog/command/CreateFlightCommandHandler.php");
19
20
// Load translation files required by the page
21
$langs->load("mymodule@flightlog");
22
23
$validator = new FlightValidator($langs, $db, $conf->global->BBC_FLIGHT_TYPE_CUSTOMER);
24
$createFlightHandler = new CreateFlightCommandHandler($db, $conf, $user, $langs, $validator);
25
26
if (!$user->rights->flightlog->vol->add) {
27
    accessforbidden();
28
}
29
30
/* * *****************************************************************
31
 * ACTIONS
32
 *
33
 * Put here all code to do according to value of "action" parameter
34
 * ****************************************************************** */
35
$msg = '';
36
if (GETPOST("action") == 'add') {
37
    if (!$_POST["cancel"]) {
38
        $dated = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
39
        $isGroupedFlight = (int) GETPOST('grouped_flight', 'int', 2) === 1;
40
        $orderId = (int) GETPOST('order_id', 'int', 2);
41
42
        $volCommand = new CreateFlightCommand();
43
        $volCommand->setDate($dated)
44
            ->setLieuD($_POST['lieuD'])
45
            ->setLieuA($_POST['lieuA'])
46
            ->setHeureD($_POST['heureD'])
47
            ->setHeureA($_POST['heureA'])
48
            ->setBBCBallonsIdBBCBallons($_POST['ballon'])
49
            ->setNbrPax($_POST['nbrPax'])
50
            ->setRemarque($_POST['comm'])
51
            ->setIncidents($_POST['inci'])
52
            ->setFkType($_POST['type'])
53
            ->setFkPilot($_POST['pilot'])
54
            ->setFkOrganisateur($_POST['orga'])
55
            ->setKilometers($_POST['kilometers'])
56
            ->setCost($_POST['cost'])
57
            ->setFkReceiver($_POST['fk_receiver'])
58
            ->setJustifKilometers($_POST['justif_kilometers'])
59
            ->setPassengerNames($_POST['passenger_names'])
60
            ->setGroupedFlight($isGroupedFlight)
61
            ->setOrderId($orderId);
62
63
        try{
64
            $vol = $createFlightHandler->handle($volCommand);
65
66
            include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
67
            $interface = new Interfaces($db);
68
            $triggerResult = $interface->run_triggers('BBC_FLIGHT_LOG_ADD_FLIGHT', $vol, $user, $langs, $conf);
69
70
            $msg = '<div class="ok">L\'ajout du vol du : ' . $_POST["reday"] . '/' . $_POST["remonth"] . '/' . $_POST["reyear"] . ' s\'est correctement effectue ! </div>';
71
            Header("Location: card.php?id=" . $vol->id);
72
        }catch (\Exception $e){
73
            $msg = '<div class="error">Erreur lors de l\'ajout du vol : ' . $vol->error . '! </div>';
74
        }
75
76
    }
77
}
78
79
80
/* * *************************************************
81
 * PAGE
82
 *
83
 * Put here all code to build page
84
 * ************************************************** */
85
86
llxHeader('', 'Carnet de vol', '');
87
88
$html = new Form($db);
89
$commande = new Commande($db);
90
$datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
91
if ($msg) {
92
    print $msg;
93
}
94
95
?>
96
97
    <div class="errors error-messages">
98
        <?php
99
        foreach ($validator->getErrors() as $errorMessage) {
100
            print sprintf('<div class="error"><span>%s</span></div>', $errorMessage);
101
        }
102
        ?>
103
    </div>
104
    <form class="flight-form js-form" name='add' action="addFlight.php" method="post">
105
    <input type="hidden" name="action" value="add"/>
106
107
    <!-- Date et heures -->
108
    <section class="form-section">
109
        <h1 class="form-section-title"><?php echo $langs->trans('Date & heures'); ?></h1>
110
        <table class="border" width="100%">
111
            <?php
112
            //type du vol
113
            print "<tr>";
114
            print '<td class="fieldrequired"> Type du vol</td><td colspan="3">';
115
            select_flight_type($_POST['type']);
0 ignored issues
show
Deprecated Code introduced by
The function select_flight_type() has been deprecated with message: should use the form instead. Return list of flight type

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
116
            print '</td></tr>';
117
118
            //date du vol
119
            print "<tr>";
120
            print '<td class="fieldrequired"> Date du vol</td><td>';
121
            print $html->select_date($datec ? $datec : -1, '', '', '', '', 'add', 1, 1);
122
            print '</td></tr>';
123
124
            //Hour start
125
            print '<tr><td class="fieldrequired">Heure de d&#233;part (format autorise XXXX)</td><td width="25%" >'; ?>
126
            <input type="text"
127
                   name="heureD"
128
                   class="flat <?php echo($validator->hasError('heureD') ? 'error' : '') ?>"
129
                   value="<?php echo $_POST['heureD'] ?>"/>
130
            </td>
131
132
            <?php
133
            //Hour end
134
            print '<td class="fieldrequired">Heure d\'arriv&#233;e (format autorise XXXX)</td><td>'; ?>
135
            <input type="text"
136
                   name="heureA"
137
                   class="flat <?php echo($validator->hasError('heureA') ? 'error' : '') ?>"
138
                   value="<?php echo $_POST['heureA'] ?>"/>
139
            </td>
140
            </tr>
141
142
        </table>
143
    </section>
144
145
    <section class="form-section">
146
        <h1 class="form-section-title"><?php echo $langs->trans('Pilote & ballon') ?></h1>
147
        <table class="border" width="50%">
148
            <?php
149
            //Pilote
150
            print "<tr>";
151
            print '<td class="fieldrequired"> Pilote </td><td >';
152
            print $html->select_dolusers($_POST["pilot"] ? $_POST["pilot"] : $user->id, 'pilot', 0, null, 0, '', '', 0,0,0,'',0,'','', true);
153
            print '</td></tr>';
154
155
            //Ballon
156
            print "<tr>";
157
            print '<td width="25%" class="fieldrequired">Ballon</td><td>';
158
            select_balloons($_POST['ballon'], 'ballon', 0, 0);
159
            print '</td></tr>';
160
            ?>
161
162
            <tr>
163
                <td>Il y'avait-il plusieurs ballons ?</td>
164
                <td colspan="3"><input type="checkbox" value="1" name="grouped_flight"/> - Oui</td>
165
            </tr>
166
        </table>
167
    </section>
168
169
    <section class="form-section">
170
        <h1 class="form-section-title"><?php echo $langs->trans('Lieux') ?></h1>
171
        <table class="border" width="100%">
172
            <?php
173
174
            //place start
175
            print "<tr>";
176
            print '<td class="fieldrequired">Lieu de d&#233;part </td><td width="25%" >';
177
            print '<input type="text" name="lieuD" class="flat" value="' . $_POST['lieuD'] . '"/>';
178
            print '</td>';
179
180
            //place end
181
            print '<td class="fieldrequired">Lieu d\'arriv&#233;e </td><td>';
182
            print '<input type="text" name="lieuA" class="flat" value="' . $_POST['lieuA'] . '"/>';
183
            print '</td></tr>';
184
185
            ?>
186
187
        </table>
188
    </section>
189
190
    <section class="form-section">
191
        <h1 class="form-section-title"><span class="js-organisator-field">Organisateur</span><span class="js-instructor-field">Instructeur</span></h1>
192
        <table class="border" width="50%">
193
            <tr>
194
                <td class="fieldrequired"><span class="js-organisator-field">Organisateur</span><span class="js-instructor-field">Instructeur</span></td>
195
                <td>
196
                <?php
197
                    //organisateur
198
                    print $html->select_dolusers($_POST["orga"] ? $_POST["orga"] : $user->id, 'orga', 0, null, 0, '', '', 0,0,0,'',0,'','', true);
199
                ?>
200
                </td>
201
            </tr>
202
        </table>
203
    </section>
204
205
206
    <section class="form-section js-expensable-field">
207
        <h1 class="form-section-title"><?php echo $langs->trans('Déplacements') ?></h1>
208
        <table class="border" width="50%">
209
            <!-- number of kilometers done for the flight -->
210
            <tr>
211
                <td class="fieldrequired">Nombre de kilometres effectués pour le vol</td>
212
                <td>
213
                    <input type="number" name="kilometers" class="flat <?php echo($validator->hasError('kilometers') ? 'error' : '') ?>" value="<?php echo $_POST['kilometers'] ?>"/>
214
                </td>
215
            </tr>
216
217
            <!-- Justif Kilometers -->
218
            <tr>
219
220
                <td width="25%" class="fieldrequired">Justificatif des KM </td>
221
                <td>
222
                    <textarea name="justif_kilometers" rows="2" cols="60" class="flat <?php echo($validator->hasError('justif_kilometers') ? 'error' : '') ?>"><?php echo $_POST['justif_kilometers'] ?></textarea>
223
                </td>
224
            </tr>
225
        </table>
226
    </section>
227
228
    <!-- Passagers -->
229
    <section class="form-section">
230
        <h1 class="form-section-title"><?php echo $langs->trans('Passager') ?></h1>
231
        <table class="border" width="50%">
232
            <tr>
233
                <td class="fieldrequired"><?php echo $langs->trans('Nombre de passagers'); ?></td>
234
                <td>
235
                    <input type="number"
236
                           name="nbrPax"
237
                           class="flat <?php echo $validator->hasError('nbrPax') ? 'error' : '' ?>"
238
                           value="<?php echo $_POST['nbrPax']?: 0 ?>"/>
239
                </td>
240
            </tr>
241
242
            <!-- passenger names -->
243
            <tr>
244
                <td width="25%" class="fieldrequired"><?php echo $langs->trans('Noms des passagers'); ?><br/>(Séparé par des ; )</td>
245
                <td>
246
                    <textarea name="passenger_names" cols="60" rows="2" class="flat <?php echo $validator->hasError('passenger_names') ? 'error' : '' ?>"><?php echo $_POST['passenger_names'] ?></textarea>
247
                </td>
248
            </tr>
249
        </table>
250
    </section>
251
252
    <!-- billing information -->
253
    <section class="form-section">
254
        <h1 class="form-section-title js-billable-field"><?php echo $langs->trans('Facturation') ?></h1>
255
        <table class="border" width="50%">
256
257
            <!-- Order -->
258
            <tr class=" js-billable-field">
259
                <td class="fieldrequired"><?php echo $langs->trans('Commande du vol')?></td>
260
                <td class="js-order">
261
                    <?php
262
                     echo $html->selectarray('order_id',$commande->liste_array(2),$_POST['order_id'], 1,0,0,'',0,0,0,'','minwidth200',1);
263
                    ?>
264
                </td>
265
            </tr>
266
267
            <!-- Money receiver -->
268
            <tr class="js-hide-order js-billable-field">
269
                <td class="fieldrequired"><?php echo $langs->trans('Qui a perçu l\'argent')?></td><td>
270
                    <?php print $html->select_dolusers($_POST["fk_receiver"] ? $_POST["fk_receiver"] : $user->id,
271
                        'fk_receiver', true, null, 0, '', '', 0,0,0,'',0,'','', true); ?>
272
                </td>
273
            </tr>
274
275
            <!-- Flight cost -->
276
            <tr class="js-hide-order js-billable-field">
277
                <td class="fieldrequired">Montant perçu</td>
278
                <td>
279
                    <input type="text" name="cost" class="flat  <?php echo $validator->hasError('cost') ? 'error' : '' ?>" value="<?php echo $_POST['cost'] ?> "/>
280
                    &euro;
281
                </td>
282
            </tr>
283
        </table>
284
    </section>
285
286
    <!-- comments -->
287
    <section class="form-section">
288
        <h1 class="form-section-title"><?php echo $langs->trans('Commentaires') ?></h1>
289
        <table class="border" width="50%">
290
            <!-- commentaires -->
291
            <tr class="">
292
                <td class="fieldrequired"> Commentaire </td><td>
293
                    <textarea rows="2" cols="60" class="flat" name="comm" placeholder="RAS"><?php print $_POST['comm']; ?></textarea>
294
                </td>
295
            </tr>
296
297
            <!-- incidents -->
298
            <tr class="">
299
                <td class="fieldrequired"> incidents </td><td>
300
                    <textarea rows="2" cols="60" class="flat" name="inci" placeholder="RAS"><?php print $_POST['inci']; ?></textarea>
301
                </td>
302
            </tr>
303
        </table>
304
    </section>
305
<?php
306
307
print '<br><input class="button" type="submit" value="' . $langs->trans("Save") . '"> &nbsp; &nbsp; ';
308
print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
309
310
print '</form>';
311
312
$db->close();
313
?>
314
315
<script type="application/javascript">
316
317
    function hideOrderInformation (){
318
        var $this = $(this);
319
320
        if($this.val() > -1){
321
            $('input, select', '.js-hide-order').attr('disabled', 'disabled');
322
        }else{
323
            $('input, select', '.js-hide-order').removeAttr('disabled');
324
        }
325
    }
326
327
    /**
328
     * get the flight type object from an id.
329
     */
330
    function getFlightType(flightTypeId){
331
        var types = {
332
            1:{
333
                'billable' : 1,
334
                'expensable' : 1,
335
                'id' : 1
336
            },
337
            2:{
338
                'billable' : 1,
339
                'expensable' : 1,
340
                'id' : 2
341
            },
342
            3:{
343
                'billable' : 0,
344
                'expensable' : 0,
345
                'id' : 3
346
            },
347
            4:{
348
                'billable' : 0,
349
                'expensable' : 0,
350
                'id' : 4
351
            },
352
            5:{
353
                'billable' : 0,
354
                'expensable' : 0,
355
                'id' : 5
356
            },
357
            6:{
358
                'billable' : 0,
359
                'expensable' : 0,
360
                'id' : 6
361
            },
362
            7:{
363
                'billable' : 0,
364
                'expensable' : 0,
365
                'id' : 7
366
            }
367
        };
368
369
        var flightTypeNull = {
370
            'billable' : 0,
371
            'expensable' : 0,
372
            'id' : 0
373
        };
374
375
        return typeof types[flightTypeId] === 'undefined' ? flightTypeNull : types[flightTypeId];
376
    }
377
378
    function flightTypeChanged(){
379
        var $this = $(this);
380
        var typeId = $this.val();
381
        var flightType = getFlightType(typeId);
382
383
        if(flightType.billable === 1){
384
            $('.js-form .js-billable-field').removeClass('hidden');
385
        }else{
386
            $('.js-form .js-billable-field').addClass('hidden');
387
        }
388
389
        if(flightType.expensable === 1){
390
            $('.js-form .js-expensable-field').removeClass('hidden');
391
        }else{
392
            $('.js-form .js-expensable-field').addClass('hidden');
393
        }
394
395
        if(flightType.id === 6){
396
            //instruction flight
397
            $('.js-form .js-instructor-field').removeClass('hidden');
398
            $('.js-form .js-organisator-field').addClass('hidden');
399
        }else{
400
            $('.js-form .js-instructor-field').addClass('hidden');
401
            $('.js-form .js-organisator-field').removeClass('hidden');
402
        }
403
404
    }
405
406
    $(function(){
407
        $('.js-order select').on('change', hideOrderInformation);
408
        $('.js-order select').each(hideOrderInformation);
409
410
        $('.js-flight-type').on('change', flightTypeChanged);
411
        $('.js-flight-type').each(flightTypeChanged);
412
    });
413
</script>
414