Completed
Push — master ( 3a683c...464735 )
by Laurent
01:31
created

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/class/bbcvols.class.php');
47
dol_include_once('/flightlog/class/bbctypes.class.php');
48
dol_include_once('/flightlog/lib/flightLog.lib.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
// Load traductions files requiredby by page
57
$langs->load("mymodule@flightlog");
58
$langs->load("other");
59
60
// Get parameters
61
$id = GETPOST('id', 'int') ?: GETPOST('idBBC_vols', 'int');
62
$action = GETPOST('action', 'alpha');
63
$cancel = GETPOST('cancel');
64
$backtopage = GETPOST('backtopage');
65
$myparam = GETPOST('myparam', 'alpha');
66
67
$isAllowedEdit = ($user->rights->flightlog->vol->edit || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id));
68
$isAllowedDelete = ($user->rights->flightlog->vol->delete || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id && !$object->is_facture));
69
$permissiondellink=$user->rights->flightlog->vol->financial;
70
71
$search_idBBC_vols = GETPOST('search_idBBC_vols', 'int');
72
$search_lieuD = GETPOST('search_lieuD', 'alpha');
73
$search_lieuA = GETPOST('search_lieuA', 'alpha');
74
$search_heureD = GETPOST('search_heureD', 'alpha');
75
$search_heureA = GETPOST('search_heureA', 'alpha');
76
$search_BBC_ballons_idBBC_ballons = GETPOST('search_BBC_ballons_idBBC_ballons', 'int');
77
$search_nbrPax = GETPOST('search_nbrPax', 'int');
78
$search_remarque = GETPOST('search_remarque', 'alpha');
79
$search_incidents = GETPOST('search_incidents', 'alpha');
80
$search_fk_type = GETPOST('search_fk_type', 'int');
81
$search_fk_pilot = GETPOST('search_fk_pilot', 'int');
82
$search_fk_organisateur = GETPOST('search_fk_organisateur', 'int');
83
$search_is_facture = GETPOST('search_is_facture', 'int');
84
$search_kilometers = GETPOST('search_kilometers', 'int');
85
$search_cost = GETPOST('search_cost', 'alpha');
86
$search_fk_receiver = GETPOST('search_fk_receiver', 'int');
87
$search_justif_kilometers = GETPOST('search_justif_kilometers', 'alpha');
88
89
$pageTitle = "Fiche vol " . $id;
90
91
if (!$user->rights->flightlog->vol->access) {
92
    accessforbidden($langs->trans("Tu n'as pas accès au vol"));
93
}
94
95
if (empty($action) && empty($id) && empty($ref)) {
96
    $action = 'view';
97
}
98
99
$object = new Bbcvols($db);
100
$extrafields = new ExtraFields($db);
101
102
$receiver = new User($db);
103
104
$pilotService = new PilotService($db);
105
$pilot = new User($db);
106
107
$organisator = new User($db);
108
109
$flightType = new Bbctypes($db);
110
$balloon = new Bbc_ballons($db);
111
112
// fetch optionals attributes and labels
113
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
114
115
// Load object
116
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php';  // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
117
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
118
119
// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
120
$hookmanager->initHooks(array('bbcvols'));
121
$object->ref = $object->idBBC_vols;
122
$receiver->fetch($object->fk_receiver);
123
$pilot->fetch($object->fk_pilot);
124
$organisator->fetch($object->fk_organisateur);
125
$flightType->fetch($object->fk_type);
126
$balloon->fetch($object->BBC_ballons_idBBC_ballons);
127
128
129
if (($action == "update" || $action == "edit") && !($user->rights->flightlog->vol->edit || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id))) {
130
    setEventMessage("Ceci n'est pas un de tes vols tu ne peux l'editer ! ", 'errors');
131
    $action = 'view';
132
}
133
134
/*******************************************************************
135
 * ACTIONS
136
 *
137
 * Put here all code to do according to value of "action" parameter
138
 ********************************************************************/
139
140
$parameters = array();
141
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object,
142
    $action);    // Note that $action and $object may have been modified by some hooks
143
if ($reshook < 0) {
144
    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
145
}
146
147
if (empty($reshook)) {
148
149
    // Action to update record
150
    if ($action == 'update') {
151
        $error = 0;
152
153
        $object->idBBC_vols = GETPOST('idBBC_vols', 'int');
154
        $object->id = $object->idBBC_vols;
155
156
        $object->lieuD = GETPOST('lieuD', 'alpha');
157
        $object->lieuA = GETPOST('lieuA', 'alpha');
158
        $object->heureD = GETPOST('heureD_h', 'int') . ":" . GETPOST('heureD_m', 'int') . ":00";
159
        $object->heureA = GETPOST('heureA_h', 'int') . ":" . GETPOST('heureA_m', 'int') . ":00";
160
        $object->BBC_ballons_idBBC_ballons = GETPOST('BBC_ballons_idBBC_ballons', 'int');
161
162
        $object->remarque = GETPOST('remarque', 'alpha');
163
        $object->incidents = GETPOST('incidents', 'alpha');
164
        $object->kilometers = GETPOST('kilometers', 'int') ?: $object->kilometers;
165
        $object->justif_kilometers = GETPOST('justif_kilometers', 'alpha') ?: $object->justif_kilometers;
166
167
168
        //validation
169
        if (empty($object->idBBC_vols)) {
170
            $error++;
171
            setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",
172
                $langs->transnoentitiesnoconv("idBBC_vols")),
173
                null, 'errors');
174
        }
175
176
        if (!dol_validElement($object->lieuD)) {
177
            $error++;
178
            setEventMessage("Erreur le champ : lieu de décollage", 'errors');
179
        }
180
181
        if (!dol_validElement($object->lieuA)) {
182
            $error++;
183
            setEventMessage("Erreur le champ : lieu d'atterissage", 'errors');
184
        }
185
186
        $dateD = date_create_from_format("H:i:s", $object->heureD);
187
        $dateA = date_create_from_format("H:i:s", $object->heureA);
188
        if ($dateA <= $dateD) {
189
            $error++;
190
            setEventMessage("Erreur avec les heures de vol", 'errors');
191
        }
192
193
        if (!is_numeric($object->nbrPax) || $object->nbrPax < 0) {
194
            $error++;
195
            setEventMessage("Erreur le champ : nombre de passagers", 'errors');
196
        }
197
198
        // action : edit
199
        if (!$error) {
200
            $result = $object->update($user);
201
            if ($result > 0) {
202
                $action = 'view';
203
204
                $object->id = $object->idBBC_vols;
205
                $receiver->fetch($object->fk_receiver);
206
                $pilot->fetch($object->fk_pilot);
207
                $organisator->fetch($object->fk_organisateur);
208
                $flightType->fetch($object->fk_type);
209
                $balloon->fetch($object->BBC_ballons_idBBC_ballons);
210
211 View Code Duplication
            } else {
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...
212
                // Creation KO
213
                if (!empty($object->errors)) {
214
                    setEventMessages(null, $object->errors, 'errors');
215
                } else {
216
                    setEventMessages($object->error, null, 'errors');
217
                }
218
                $action = 'edit';
219
            }
220
        } else {
221
            $action = 'edit';
222
        }
223
    }
224
225
    // Action to delete
226
    if ($action == 'confirm_delete') {
227
        $result = $object->delete($user);
228
        if ($result > 0) {
229
            // Delete OK
230
            setEventMessages("RecordDeleted", null, 'mesgs');
231
            header("Location: " . dol_buildpath('/flightlog/list.php', 1));
232
            exit;
233 View Code Duplication
        } else {
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...
234
            if (!empty($object->errors)) {
235
                setEventMessages(null, $object->errors, 'errors');
236
            } else {
237
                setEventMessages($object->error, null, 'errors');
238
            }
239
        }
240
    }
241
}
242
243
244
/***************************************************
245
 * VIEW
246
 *
247
 * Put here all code to build page
248
 ****************************************************/
249
250
llxHeader('', $pageTitle, '');
251
252
$form = new Form($db);
253
254
// Put here content of your page
255
256
print '<script type="text/javascript" language="javascript">
257
jQuery(document).ready(function() {
258
	function init_myfunc()
259
	{
260
		jQuery("#myid").removeAttr(\'disabled\');
261
		jQuery("#myid").attr(\'disabled\',\'disabled\');
262
	}
263
	init_myfunc();
264
	jQuery("#mybutton").click(function() {
265
		init_myfunc();
266
	});
267
});
268
</script>';
269
270
271
// Part to edit record
272
if (($id || $ref) && $action == 'edit') {
273
    print load_fiche_titre($langs->trans("MyModule"));
274
275
    print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
276
    print '<input type="hidden" name="action" value="update">';
277
    print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
278
    print '<input type="hidden" name="idBBC_vols" value="' . $object->id . '">';
279
280
    dol_fiche_head();
281
282
    print '<table class="border centpercent">' . "\n";
283
284
    print "<tr><td class=\"fieldrequired\">" . $langs->trans("FieldlieuD") . "</td><td><input class=\"flat\" type=\"text\" name=\"lieuD\" value=\"" . $object->lieuD . "\"></td></tr>";
285
    print "<tr><td class=\"fieldrequired\">" . $langs->trans("FieldlieuA") . "</td><td><input class=\"flat\" type=\"text\" name=\"lieuA\" value=\"" . $object->lieuA . "\"></td></tr>";
286
    print "<tr><td class=\"fieldrequired\">" . $langs->trans("FieldheureD") . "</td><td><input class=\"flat\" min=\"0\" max=\"23\" type=\"number\" name=\"heureD_h\" value=\"" . explode(":",
287
            $object->heureD)[0] . "\">h<input class=\"flat\" type=\"number\" min=\"0\" max=\"59\" name=\"heureD_m\" value=\"" . explode(":",
288
            $object->heureD)[1] . "\"></td></tr>";
289
    print "<tr><td class=\"fieldrequired\">" . $langs->trans("FieldheureA") . "</td><td><input class=\"flat\" type=\"number\" min=\"0\" max=\"23\" name=\"heureA_h\" value=\"" . explode(":",
290
            $object->heureA)[0] . "\">h<input class=\"flat\" type=\"number\" min=\"0\" max=\"59\" name=\"heureA_m\" value=\"" . explode(":",
291
            $object->heureA)[1] . "\"></td></tr>";
292
    print "<tr><td class=\"fieldrequired\">" . $langs->trans("FieldBBC_ballons_idBBC_ballons") . "</td><td>";
293
    select_balloons($object->BBC_ballons_idBBC_ballons, "BBC_ballons_idBBC_ballons");
294
    print "</td></tr>";
295
    print "<tr><td class=\"fieldrequired\">" . $langs->trans("Fieldremarque") . "</td><td><textarea class=\"flat\" name=\"remarque\">" . $object->remarque . "</textarea></td></tr>";
296
    print "<tr><td class=\"fieldrequired\">" . $langs->trans("Fieldincidents") . "</td><td><textarea class=\"flat\" name=\"incidents\">" . $object->incidents . "</textarea></td></tr>";
297
298
    if ($user->rights->flightlog->vol->financial || $user->id == $object->fk_pilot) {
299
        print "<tr><td class=\"fieldrequired\">" . $langs->trans("Fieldkilometers") . "</td><td><input class=\"flat\" type=\"number\" name=\"kilometers\" value=\"" . $object->kilometers . "\"></td></tr>";
300
        print "<tr><td class=\"fieldrequired\">" . $langs->trans("Fieldjustif_kilometers") . "</td><td><textarea class=\"flat\" name=\"justif_kilometers\">" . $object->justif_kilometers . "</textarea></td></tr>";
301
    }
302
    print '</table>';
303
304
    dol_fiche_end();
305
306
    print '<div class="center"><input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
307
    print ' &nbsp; <input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
308
    print '</div>';
309
310
    print '</form>';
311
}
312
313
314
// Part to show record
315
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
316
    $res = $object->fetch_optionals($object->id, $extralabels);
317
318
    /*
319
             * Show tabs
320
             */
321
    $head = prepareFlightTabs($object);
322
323
    dol_fiche_head($head, 'general', $langs->trans("Vol"));
324
325
    $linkback = '<a href="' . DOL_URL_ROOT . '/flightlog/list.php">' . $langs->trans("BackToList") . '</a>';
326
    print $form->showrefnav($object, "idBBC_vols", $linkback, true, "idBBC_vols");
327
328
    if ($action == 'delete') {
329
        $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteMyOjbect'),
330
            $langs->trans('ConfirmDeleteMyObject'), 'confirm_delete', '', 0, 1);
331
        print $formconfirm;
332
    }
333
334
    print '<table class="border centpercent">' . "\n";
335
336
337
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldidBBC_vols") . '</td><td>' . $object->idBBC_vols . '</td></tr>';
338
    print '<tr><td class="fieldrequired">' . $langs->trans("Fielddate") . '</td><td>' . dol_print_date($object->date) . '</td></tr>';
339
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldlieuD") . '</td><td>' . $object->lieuD . '</td></tr>';
340
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldlieuA") . '</td><td>' . $object->lieuA . '</td></tr>';
341
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldheureD") . '</td><td>' . $object->heureD . '</td></tr>';
342
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldheureA") . '</td><td>' . $object->heureA . '</td></tr>';
343
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldBBC_ballons_idBBC_ballons") . '</td><td>' . $balloon->immat . '</td></tr>';
344
    print '<tr><td class="fieldrequired">' . $langs->trans("FieldnbrPax") . '</td><td>' . $object->nbrPax . '</td></tr>';
345
    print '<tr><td class="fieldrequired">' . $langs->trans("Fieldfk_type") . '</td><td>' . $object->fk_type . '</td></tr>';
346
    print '<tr><td class="fieldrequired">' . $langs->trans("Fieldfk_pilot") . '</td><td>' . $pilot->getNomUrl(1) . '</td></tr>';
347
    print '<tr><td class="fieldrequired">' . $langs->trans("Fieldfk_organisateur") . '</td><td>' . $organisator->getNomUrl(1) . '</td></tr>';
348
349
    print '</table>';
350
351
    dol_fiche_end();
352
353
    // Buttons
354
    print '<div class="tabsAction">' . "\n";
355
    $parameters = array();
356
    $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object,
357
        $action);    // Note that $action and $object may have been modified by hook
358
    if ($reshook < 0) {
359
        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
360
    }
361
362 View Code Duplication
    if ($user->rights->flightlog->vol->edit || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id)) {
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...
363
        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";
364
    }
365
366 View Code Duplication
    if ($user->rights->flightlog->vol->delete || ($user->rights->flightlog->vol->add && $object->fk_pilot == $user->id && !$object->is_facture)) {
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...
367
        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";
368
    }
369
370 View Code Duplication
    if($user->rights->flightlog->vol->financial && $object->fk_type == 2 && !$object->hasFacture()){
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...
371
        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";
372
    }
373
374
    print '</div>' . "\n";
375
376
    if($user->rights->flightlog->vol->financial){
377
        print '<div class="fichecenter"><div class="fichehalfleft">';
378
        $form->showLinkedObjectBlock($object);
379
        print '</div></div>';
380
    }
381
382
}
383
384
385
// End of page
386
llxFooter();
387
$db->close();
388