Completed
Push — feature/update_flight ( a5f5fd...6f8e65 )
by Laurent
01:47
created

card.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
/* Copyright (C) 2007-2015 Laurent Destailleur  <[email protected]>
3
 * Copyright (C) ---Put here your own copyright and developer email---
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
/**
20
 *    \file       flightlog/bbcvols_card.php
21
 *        \ingroup    flightlog
22
 *        \brief      This file is an example of a php page
23
 *                    Initialy built by build_class_from_table on 2017-02-09 11:10
24
 */
25
26
// Change this following line to use the correct relative path (../, ../../, etc)
27
$res = 0;
28
if (!$res && file_exists("../main.inc.php")) {
29
    $res = @include '../main.inc.php';
30
}                    // to work if your module directory is into dolibarr root htdocs directory
31
if (!$res && file_exists("../../main.inc.php")) {
32
    $res = @include '../../main.inc.php';
33
}            // to work if your module directory is into a subdir of root htdocs directory
34
if (!$res && file_exists("../../../dolibarr/htdocs/main.inc.php")) {
35
    $res = @include '../../../dolibarr/htdocs/main.inc.php';
36
}     // Used on dev env only
37
if (!$res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) {
38
    $res = @include '../../../../dolibarr/htdocs/main.inc.php';
39
}   // Used on dev env only
40
if (!$res) {
41
    die("Include of main fails");
42
}
43
// Change this following line to use the correct relative path from htdocs
44
include_once(DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php');
45
46
dol_include_once('/flightlog/flightLog.inc.php');
47
dol_include_once('/flightlog/class/bbcvols.class.php');
48
dol_include_once('/flightlog/class/bbctypes.class.php');
49
dol_include_once('/flightlog/lib/card.lib.php');
50
dol_include_once('/flightlog/lib/PilotService.php');
51
dol_include_once('/flightballoon/class/bbc_ballons.class.php');
52
dol_include_once('/user/class/usergroup.class.php');
53
54
global $langs, $user, $conf;
55
56
const ACTION_FLAG_BILLED = 'action_flag_bill';
57
const ACTION_CONFIRM_FLAG_BILLED = 'confirm_flag_bill';
58
59
// Load traductions files requiredby by page
60
$langs->load("mymodule@flightlog");
61
$langs->load("other");
62
63
// Get parameters
64
$id = GETPOST('id', 'int') ?: GETPOST('idBBC_vols', 'int');
65
$action = GETPOST('action', 'alpha');
66
$cancel = GETPOST('cancel');
67
$backtopage = GETPOST('backtopage');
68
$myparam = GETPOST('myparam', 'alpha');
69
70
$isAllowedEdit = ($user->rights->flightlog->vol->edit || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id));
71
$isAllowedDelete = ($user->rights->flightlog->vol->delete || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id && !$object->is_facture));
72
$permissiondellink = $user->rights->flightlog->vol->financial;
73
74
$search_idBBC_vols = GETPOST('search_idBBC_vols', 'int');
75
$search_lieuD = GETPOST('search_lieuD', 'alpha');
76
$search_lieuA = GETPOST('search_lieuA', 'alpha');
77
$search_heureD = GETPOST('search_heureD', 'alpha');
78
$search_heureA = GETPOST('search_heureA', 'alpha');
79
$search_BBC_ballons_idBBC_ballons = GETPOST('search_BBC_ballons_idBBC_ballons', 'int');
80
$search_nbrPax = GETPOST('search_nbrPax', 'int');
81
$search_remarque = GETPOST('search_remarque', 'alpha');
82
$search_incidents = GETPOST('search_incidents', 'alpha');
83
$search_fk_type = GETPOST('search_fk_type', 'int');
84
$search_fk_pilot = GETPOST('search_fk_pilot', 'int');
85
$search_fk_organisateur = GETPOST('search_fk_organisateur', 'int');
86
$search_is_facture = GETPOST('search_is_facture', 'int');
87
$search_kilometers = GETPOST('search_kilometers', 'int');
88
$search_cost = GETPOST('search_cost', 'alpha');
89
$search_fk_receiver = GETPOST('search_fk_receiver', 'int');
90
$search_justif_kilometers = GETPOST('search_justif_kilometers', 'alpha');
91
92
$pageTitle = "Fiche vol " . $id;
93
94
if (!$user->rights->flightlog->vol->access) {
95
    accessforbidden($langs->trans("Tu n'as pas accès au vol"));
96
}
97
98
if (empty($action) && empty($id) && empty($ref)) {
99
    $action = 'view';
100
}
101
102
$object = new Bbcvols($db);
103
$extrafields = new ExtraFields($db);
104
105
$receiver = new User($db);
106
107
$pilotService = new PilotService($db);
108
$pilot = new User($db);
109
110
$organisator = new User($db);
111
112
$flightType = new Bbctypes($db);
113
$balloon = new Bbc_ballons($db);
114
115
// fetch optionals attributes and labels
116
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
117
118
// Load object
119
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php';  // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
120
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
121
122
// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
123
$hookmanager->initHooks(array('bbcvols'));
124
$object->ref = $object->idBBC_vols;
125
$receiver->fetch($object->fk_receiver);
126
$pilot->fetch($object->fk_pilot);
127
$organisator->fetch($object->fk_organisateur);
128
$flightType->fetch($object->fk_type);
129
$balloon->fetch($object->BBC_ballons_idBBC_ballons);
130
131
$formFlight = new \flightlog\form\FlightForm(new FlightValidator($langs, $db, $conf->global->BBC_FLIGHT_TYPE_CUSTOMER), $object, $db, $conf->global);
132
$formFlight->bind($object);
133
134
135
if (($action == "update" || $action == "edit") && !($user->rights->flightlog->vol->edit || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id))) {
136
    setEventMessage("Ceci n'est pas un de tes vols tu ne peux l'editer ! ", 'errors');
137
    $action = 'view';
138
}
139
140
/*******************************************************************
141
 * ACTIONS
142
 *
143
 * Put here all code to do according to value of "action" parameter
144
 ********************************************************************/
145
146
$parameters = array();
147
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object,
148
    $action);    // Note that $action and $object may have been modified by some hooks
149
if ($reshook < 0) {
150
    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
151
}
152
153
if (empty($reshook)) {
154
155
    // Action to update record
156
    if ($action == 'update') {
157
158
        $formFlight->setData($_POST);
159
160
        // action : edit
161
        if ($formFlight->validate()) {
162
            /** @var Bbcvols $object */
163
            $object = $formFlight->getObject();
164
            $result = $object->update($user);
165
            if ($result > 0) {
166
                $action = 'view';
167
168
                $object->id = $object->idBBC_vols;
169
                $receiver->fetch($object->fk_receiver);
170
                $pilot->fetch($object->fk_pilot);
171
                $organisator->fetch($object->fk_organisateur);
172
                $flightType->fetch($object->fk_type);
173
                $balloon->fetch($object->BBC_ballons_idBBC_ballons);
174
175 View Code Duplication
            } else {
176
                // Creation KO
177
                if (!empty($object->errors)) {
178
                    setEventMessages(null, $object->errors, 'errors');
179
                } else {
180
                    setEventMessages($object->error, null, 'errors');
181
                }
182
                $action = 'edit';
183
            }
184
        } else {
185
            $action = 'edit';
186
        }
187
    }
188
189
    // Action to delete
190
    if ($action == 'confirm_delete') {
191
        $result = $object->delete($user);
192
        if ($result > 0) {
193
            // Delete OK
194
            setEventMessages("RecordDeleted", null, 'mesgs');
195
            header("Location: " . dol_buildpath('/flightlog/list.php', 1));
196
            exit;
197 View Code Duplication
        } else {
198
            if (!empty($object->errors)) {
199
                setEventMessages(null, $object->errors, 'errors');
200
            } else {
201
                setEventMessages($object->error, null, 'errors');
202
            }
203
        }
204
    }
205
206
    // Action to delete
207
    if ($user->rights->flightlog->vol->financial && !$object->isBilled() && $action === ACTION_CONFIRM_FLAG_BILLED) {
208
        $result = $object
209
            ->bill()
210
            ->update($user);
211
212
        if ($result > 0) {
213
            setEventMessages("Facturé", null, 'mesgs');
214
            $action = 'show';
215 View Code Duplication
        } else {
216
            if (!empty($object->errors)) {
217
                setEventMessages(null, $object->errors, 'errors');
218
            } else {
219
                setEventMessages($object->error, null, 'errors');
220
            }
221
        }
222
    }
223
}
224
225
226
/***************************************************
227
 * VIEW
228
 *
229
 * Put here all code to build page
230
 ****************************************************/
231
232
llxHeader('', $pageTitle, '');
233
234
$form = new Form($db);
235
236
// Put here content of your page
237
238
print '<script type="text/javascript" language="javascript">
239
jQuery(document).ready(function() {
240
	function init_myfunc()
241
	{
242
		jQuery("#myid").removeAttr(\'disabled\');
243
		jQuery("#myid").attr(\'disabled\',\'disabled\');
244
	}
245
	init_myfunc();
246
	jQuery("#mybutton").click(function() {
247
		init_myfunc();
248
	});
249
});
250
</script>';
251
252
253
// Part to edit record
254
if (($id || $ref) && $action == 'edit'): ?>
255
256
    <?php $renderer = new \flightlog\form\SimpleFormRenderer(); ?>
257
258
    <div class="errors error-messages">
259
        <?php
260
        foreach ($formFlight->getErrorMessages() as $errorMessage) {
261
            print sprintf('<div class="error"><span>%s</span></div>', $errorMessage);
262
        }
263
        ?>
264
    </div>
265
266
    <form class="flight-form js-form" name='add' action="card.php" method="POST">
267
        <input type="hidden" name="action" value="update"/>
268
269
        <?php echo $renderer->render($formFlight->getElement('idBBC_vols')); ?>
270
271
        <!-- Date et heures -->
272
        <section class="form-section">
273
            <h1 class="form-section-title"><?php echo $langs->trans('Date & heures'); ?></h1>
274
            <table class="border" width="50%">
275
276
                <tr>
277
                    <td class="fieldrequired" width="25%"> Type du vol</td>
278
                    <td ><?php echo $renderer->render($formFlight->getElement('fk_type')); ?></td>
279
                </tr>
280
            </table>
281
        </section>
282
283
        <section class="form-section">
284
            <h1 class="form-section-title"><?php echo $langs->trans('Pilote & ballon') ?></h1>
285
            <table class="border" width="50%">
286
287
                <tr>
288
                    <td class="fieldrequired"> Pilote </td>
289
                    <td><?php echo $renderer->render($formFlight->getElement('fk_pilot'),['ajax' => true]); ?></td>
290
                </tr>
291
292
                <tr>
293
                    <td width="25%" class="fieldrequired">Ballon</td>
294
                    <td><?php echo $renderer->render($formFlight->getElement('BBC_ballons_idBBC_ballons')); ?></td>
295
                </tr>
296
297
                <tr>
298
                    <td>Il y'avait-il plusieurs ballons ?</td>
299
                    <td colspan="3"><input type="checkbox" value="1" name="grouped_flight"/> - Oui</td>
300
                </tr>
301
            </table>
302
        </section>
303
304
        <section class="form-section">
305
            <h1 class="form-section-title"><?php echo $langs->trans('Lieux') ?></h1>
306
            <table class="border" width="100%">
307
                <?php
308
309
                //place start
310
                print "<tr>";
311
                print '<td class="fieldrequired">Lieu de d&#233;part </td><td width="25%" >';
312
                print $renderer->render($formFlight->getElement('lieuD'));
313
                print '</td>';
314
315
                //place end
316
                print '<td class="fieldrequired">Lieu d\'arriv&#233;e </td><td>';
317
                print $renderer->render($formFlight->getElement('lieuA'));
318
                print '</td></tr>';
319
320
                ?>
321
322
            </table>
323
        </section>
324
325
        <section class="form-section">
326
            <h1 class="form-section-title"><span class="js-organisator-field">Organisateur</span><span
327
                        class="js-instructor-field">Instructeur</span></h1>
328
            <table class="border" width="50%">
329
                <tr>
330
                    <td class="fieldrequired"><span class="js-organisator-field">Organisateur</span><span
331
                                class="js-instructor-field">Instructeur</span></td>
332
                    <td>
333
                        <?php
334
                        //organisateur
335
                        print $renderer->render($formFlight->getElement('fk_organisateur'),['ajax' => true]);
336
                        ?>
337
                    </td>
338
                </tr>
339
            </table>
340
        </section>
341
342
343
        <section class="form-section js-expensable-field">
344
            <h1 class="form-section-title"><?php echo $langs->trans('Déplacements') ?></h1>
345
            <table class="border" width="50%">
346
                <!-- number of kilometers done for the flight -->
347
                <tr>
348
                    <td class="fieldrequired">Nombre de kilometres effectués pour le vol</td>
349
                    <td>
350
                        <?php print $renderer->render($formFlight->getElement('kilometers')); ?>
351
                    </td>
352
                </tr>
353
354
                <!-- Justif Kilometers -->
355
                <tr>
356
357
                    <td width="25%" class="fieldrequired">Justificatif des KM</td>
358
                    <td>
359
                        <?php print $renderer->render($formFlight->getElement('justif_kilometers')); ?>
360
                    </textarea>
361
                    </td>
362
                </tr>
363
            </table>
364
        </section>
365
366
        <!-- Passagers -->
367
        <section class="form-section">
368
            <h1 class="form-section-title"><?php echo $langs->trans('Passager') ?></h1>
369
            <table class="border" width="50%">
370
                <tr>
371
                    <td class="fieldrequired"><?php echo $langs->trans('Nombre de passagers'); ?></td>
372
                    <td>
373
                        <?php print $renderer->render($formFlight->getElement('nbrPax')); ?>
374
                    </td>
375
                </tr>
376
377
                <!-- passenger names -->
378
                <tr>
379
                    <td width="25%" class="fieldrequired"><?php echo $langs->trans('Noms des passagers'); ?><br/>(Séparé
380
                        par des ; )
381
                    </td>
382
                    <td>
383
                        <?php print $renderer->render($formFlight->getElement('passengerNames')); ?>
384
                    </td>
385
                </tr>
386
            </table>
387
        </section>
388
389
        <!-- billing information -->
390
        <section class="form-section">
391
            <h1 class="form-section-title js-billable-field"><?php echo $langs->trans('Facturation') ?></h1>
392
            <table class="border" width="50%">
393
394
                <!-- Money receiver -->
395
                <tr class="js-hide-order js-billable-field">
396
                    <td class="fieldrequired"><?php echo $langs->trans('Qui a perçu l\'argent') ?></td>
397
                    <td>
398
                        <?php print $renderer->render($formFlight->getElement('fk_receiver'),['ajax' => true]); ?>
399
                    </td>
400
                </tr>
401
402
                <!-- Flight cost -->
403
                <tr class="js-hide-order js-billable-field">
404
                    <td class="fieldrequired">Montant perçu</td>
405
                    <td>
406
                        <?php print $renderer->render($formFlight->getElement('cost')); ?>
407
                        &euro;
408
                    </td>
409
                </tr>
410
            </table>
411
        </section>
412
413
        <!-- comments -->
414
        <section class="form-section">
415
            <h1 class="form-section-title"><?php echo $langs->trans('Commentaires') ?></h1>
416
            <table class="border" width="50%">
417
                <!-- commentaires -->
418
                <tr class="">
419
                    <td class="fieldrequired"> Commentaire</td>
420
                    <td>
421
                        <?php print $renderer->render($formFlight->getElement('remarque')); ?>
422
                    </td>
423
                </tr>
424
425
                <!-- incidents -->
426
                <tr class="">
427
                    <td class="fieldrequired"> incidents</td>
428
                    <td>
429
                        <?php print $renderer->render($formFlight->getElement('incidents')); ?>
430
                    </td>
431
                </tr>
432
            </table>
433
        </section>
434
435
        <button class="button" type="submit">Modifier</button>
436
    </form>
437
438
<?php endif;
439
440
441
// Part to show record
442
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
443
    $res = $object->fetch_optionals($object->id, $extralabels);
444
445
    $head = prepareFlightTabs($object);
446
447
    dol_fiche_head($head, 'general', $langs->trans("Vol"));
448
449
    $linkback = '<a href="' . DOL_URL_ROOT . '/flightlog/list.php">' . $langs->trans("BackToList") . '</a>';
450
    print $form->showrefnav($object, "idBBC_vols", $linkback, true, "idBBC_vols");
451
452
    if ($action == 'delete') {
453
        $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteMyOjbect'),
454
            $langs->trans('êtes-vous sure de vouloir supprimer ce vol ?'), 'confirm_delete', '', 0, 1);
455
        print $formconfirm;
456
    } elseif ($user->rights->flightlog->vol->financial && !$object->isBilled() && $action == ACTION_FLAG_BILLED) {
457
        $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id,
458
            $langs->trans('Marque comme facturé'),
459
            $langs->trans('Ce vol va être marqué comme facturé, est-ce bien le cas ?'), ACTION_CONFIRM_FLAG_BILLED, '',
460
            0, 1);
461
        print $formconfirm;
462
    }
463
464
    print '<table class="border centpercent">' . "\n";
465
466
467
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldidBBC_vols") . '</td><td>' . $object->idBBC_vols . '</td></tr>';
468
    print '<tr><td class="fieldrequired">' . $langs->trans("Fielddate") . '</td><td>' . dol_print_date($object->date) . '</td></tr>';
469
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldlieuD") . '</td><td>' . $object->lieuD . '</td></tr>';
470
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldlieuA") . '</td><td>' . $object->lieuA . '</td></tr>';
471
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldheureD") . '</td><td>' . $object->heureD . '</td></tr>';
472
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldheureA") . '</td><td>' . $object->heureA . '</td></tr>';
473
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldBBC_ballons_idBBC_ballons") . '</td><td>' . $balloon->immat . '</td></tr>';
474
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldnbrPax") . '</td><td>' . $object->nbrPax . '</td></tr>';
475
    print '<tr><td class="fieldrequired">' . $langs->trans("Noms des passagers") . '</td><td>' . $object->getPassengerNames() . '</td></tr>';
476
    print '<tr><td class="fieldrequired">' . $langs->trans("Fieldfk_type") . '</td><td>' . $object->fk_type . '</td></tr>';
477
    print '<tr><td class="fieldrequired">' . $langs->trans("Fieldfk_pilot") . '</td><td>' . $pilot->getNomUrl(1) . '</td></tr>';
478
    print '<tr><td class="fieldrequired">' . $langs->trans("Fieldfk_organisateur") . '</td><td>' . $organisator->getNomUrl(1) . '</td></tr>';
479
480
    print '</table>';
481
482
    dol_fiche_end();
483
484
    // Buttons
485
    print '<div class="tabsAction">' . "\n";
486
    $parameters = array();
487
    $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object,
488
        $action);    // Note that $action and $object may have been modified by hook
489
    if ($reshook < 0) {
490
        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
491
    }
492
493 View Code Duplication
    if ($user->rights->flightlog->vol->edit || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id && !$object->isBilled())) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
494
        print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=edit">' . $langs->trans("Modify") . '</a></div>' . "\n";
495
    }
496
497 View Code Duplication
    if ($user->rights->flightlog->vol->delete || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id && !$object->isBilled())) {
498
        print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=delete">' . $langs->trans('Delete') . '</a></div>' . "\n";
499
    }
500
501 View Code Duplication
    if ($user->rights->flightlog->vol->financial && $object->fk_type == 2 && !$object->hasFacture() && $object->hasReceiver()) {
502
        print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/flightlog/facture.php?id=' . $object->id . '">' . $langs->trans("Facturer") . '</a></div>' . "\n";
503
    }
504
    ?>
505
506
    <?php if ($user->rights->flightlog->vol->financial && !$object->isBilled()): ?>
507
        <div class="inline-block divButAction">
508
            <a class="butAction" href="<?php echo sprintf('%s?id=%s&action=%s', $_SERVER["PHP_SELF"], $object->id,
509
                ACTION_FLAG_BILLED); ?>">
510
                <?php echo $langs->trans("Marqué comme facturé ") ?>
511
            </a>
512
        </div>
513
    <?php endif; ?>
514
515
    </div>
516
    <?php
517
    if ($user->rights->flightlog->vol->financial) {
518
        print '<div class="fichecenter"><div class="fichehalfleft">';
519
        $form->showLinkedObjectBlock($object);
520
        print '</div></div>';
521
    }
522
523
}
524
525
526
// End of page
527
llxFooter();
528
$db->close();
529