Completed
Push — master ( 7bb44a...72105c )
by Laurent
02:19
created

fiche.php (2 issues)

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
//TODO refactor it by using the card layout
3
4
// Load Dolibarr environment
5
if (false === (@include '../main.inc.php')) {  // From htdocs directory
6
    require '../../documents/custom/main.inc.php'; // From "custom" directory
7
}
8
9
global $db, $langs, $user;
10
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("/flightBalloon/bbc_ballons.class.php");
15
16
// Load translation files required by the page
17
$langs->load("mymodule@mymodule");
18
19
// Protection if the user can't acces to the module
20
if (!$user->rights->flightLog->vol->access) {
21
    accessforbidden();
22
}
23
24
//TODO get all parameters here
25
26
/* * *****************************************************************
27
 * ACTIONS
28
 *
29
 * Put here all code to do according to value of "action" parameter
30
 * ****************************************************************** */
31
//To delete the flight
32
if (GETPOST('action') == 'deleteconfirm' && GETPOST('confirm') == 'yes') {
33
    if ($_GET['vol']) {
34
        $tmp = New Bbcvols($db);
35
        $tmp->fetch($_GET['vol']);
36
        if ($tmp->getId() && (($user->rights->flightLog->vol->delete && $user->id == $pilot->id ) || $user->admin)) {
37
            if ($tmp->delete($user) > 0) {
38
                dol_syslog("FLIGHT_DELETE : ".$tmp->toString().' BY : '.$user->id,LOG_WARNING);
39
                Header("Location: readFlights.php");
40
            }
41
        }
42
    }
43
}
44
45
//confirmation de la facturaion
46
if ($user->rights->flightLog->vol->status && $_POST['action'] == 'factconfirm' && $_POST['confirm'] == 'yes') {
47
    if ($_GET['vol']) {
48
        $tmp = New Bbcvols($db);
49
        $fetchResult = $tmp->fetch($_GET['vol']);
50
        if ($fetchResult > -1 && $user->rights->flightLog->vol->status) {
51
            $tmp->is_facture = 1;
52
            $tmp->update($user);
53
        }
54
    }
55
}
56
57
//Edit a flight
58
if ($_POST['action'] == 'edit') {
59
60
    $vol = New Bbcvols($db);
61
    $vol->fetch($_POST['vol']);
62
    $dated = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
63
64
    $vol->date = $dated;
65
    $vol->lieuD = $_POST['lieuD'];
66
    $vol->lieuA = $_POST['lieuA'];
67
    $vol->heureD = $_POST['heureD'];
68
    $vol->heureA = $_POST['heureA'];
69
    $vol->BBC_ballons_idBBC_ballons = $_POST['ballon'];
70
    $vol->nbrPax = $_POST['nbrPax'];
71
    $vol->remarque = $_POST['comm'];
72
    $vol->incidents = $_POST['inci'];
73
    $vol->fk_type = $_POST['type'];
74
    $vol->fk_pilot = $_POST['pilot'];
75
    $vol->fk_organisateur = $_POST['orga'];
76
    $vol->kilometers = $_POST['kilometers'];
77
    $vol->cost = $_POST['cost'];
78
    $vol->fk_receiver = $_POST['fk_receiver'];
79
    $vol->justif_kilometers = $_POST['justif_kilometers'];
80
81
    if ($vol->update($user) < 0) {
82
        dol_syslog("Error during update a flight ".$vol->error, LOG_ERR);
83
        $msg = '<div class="error">Erreur lors de la MAJ </div>';
84
        $error++;
85
    } else {
86
        Header("Location: fiche.php?vol=".$_POST['vol']);
87
    }
88
}
89
90
91
92
93
94
/* * *************************************************
95
 * PAGE
96
 *
97
 * Put here all code to build page
98
 * ************************************************** */
99
100
llxHeader('', 'Carnet de vol', '');
101
//delete
102
if ((($user->rights->flightLog->vol->delete && $user->id == $pilot->id ) || $user->admin) && $_GET["action"] == 'delete') {
103
    $html = New Form($db);
104
    print $html->formconfirm("fiche.php?vol=" . $_GET['vol'], "Delete vol", "Etes vous sure de vouloir supprimer ce vol?", 'deleteconfirm');
105
}
106
//facturation
107
if ($_GET["action"] == 'fact' && $user->rights->flightLog->vol->status) {
108
    $html = New Form($db);
109
    print $html->formconfirm("fiche.php?vol=" . $_GET['vol'], "Facturation du vol", "Etes vous sure de vouloir noter ce vol comme factur�?", 'factconfirm');
110
}
111
if ($msg) {
112
    print $msg;
113
}
114
115
116
// Put here content of your page
117
$vol = New Bbcvols($db);
118
$vol->fetch($_GET['vol']);
119
120
$pilot = New User($db);
121
$pilot->fetch($vol->fk_pilot);
122
123
$orga = New User($db);
124
$orga->fetch($vol->fk_organisateur);
125
126
$balloon = New Bbc_ballons($db);
127
$balloon->fetch($vol->BBC_ballons_idBBC_ballons);
128
129
$type = New Bbctypes($db);
130
$type->fetch($vol->fk_type);
131
132
133
//si l'action est edit et que l'utilisateur a le droit de modifier
134
if (isset($_GET['action']) && $_GET['action'] == 'edit' && ($user->rights->flightLog->vol->edit || $user->id == $pilot->id || $user->admin)) {
135
    $html = new Form($db);
136
    $datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
137
138
139
    // Put here content of your page
140
    print "<form name='add' action=\"fiche.php\" method=\"post\">\n";
141
    print '<input type="hidden" name="action" value="edit"/>';
142
    print '<input type="hidden" name="vol" value="' . $vol->idBbcvols . '"/>';
143
    print '<table class="border" width="100%">';
144
    print '<tr><td>identifiant</td><td>' . $vol->idBbcvols . '</td></tr>';
145
    //date du vol
146
    print "<tr>";
147
    print '<td class="fieldrequired"> Date du vol</td><td>';
148
    print $html->select_date($vol->date, '', '', '', '', 'add', 1, 1);
149
    print '</td></tr>';
150
    //type du vol
151
    print "<tr>";
152
    print '<td class="fieldrequired"> Type du vol</td><td>';
153
    select_flight_type($vol->fk_type);
154
    print '</td></tr>';
155
    //Pilote
156
    print "<tr>";
157
    print '<td class="fieldrequired"> Pilote</td><td>';
158
    print $html->select_dolusers($vol->fk_pilot,'pilot',0);
159
    print '</td></tr>';
160
    //organisateur
161
    print "<tr>";
162
    print '<td class="fieldrequired"> Organisateur </td><td>';
163
    print $html->select_dolusers($vol->fk_organisateur, 'orga', 1);
164
    print '</td></tr>';
165
    //Ballon
166
    print "<tr>";
167
    print '<td width="25%" class="fieldrequired">Ballon</td><td>';
168
    select_balloons($vol->BBC_ballons_idBBC_ballons, 'ballon', 0, 0);
169
    print '</td></tr>';
170
    //lieu d�part
171
    print "<tr>";
172
    print '<td width="25%" class="fieldrequired">Lieu de d&#233;part </td><td>';
173
    print '<input type="text" name="lieuD" calss="flat" value="' . $vol->lieuD . '"/>';
174
    print '</td></tr>';
175
    //lieu arriv�e
176
    print "<tr>";
177
    print '<td width="25%" class="fieldrequired">Lieu d\'arriv&#233;e </td><td>';
178
    print '<input type="text" name="lieuA" calss="flat" value="' . $vol->lieuA . '"/>';
179
    print '</td></tr>';
180
    //heure d�part
181
    print "<tr>";
182
    print '<td width="25%" class="fieldrequired">Heure de d&#233;part <br/>(format autorise XXXX)</td><td>';
183
    print '<input type="text" name="heureD" calss="flat" value="' . $vol->heureD . '"/>';
184
    print '</td></tr>';
185
    //heure arriv�e
186
    print "<tr>";
187
    print '<td width="25%" class="fieldrequired">Heure d\'arriv&#233;e <br/>(format autorise XXXX)</td><td>';
188
    print '<input type="text" name="heureA" calss="flat" value="' . $vol->heureA . '"/>';
189
    print '</td></tr>';
190
//Numbe rof kilometrs done for the flight
191
    print "<tr>";
192
    print '<td width="25%" class="fieldrequired">Nombre de kilometres effectués pour le vol</td><td>';
193
    print '<input type="number" name="kilometers" calss="flat" value="' . $vol->kilometers . '"/>';
194
    print '</td></tr>';
195
196
197
//Justif KIlometers
198
    print "<tr>";
199
    print '<td width="25%" class="fieldrequired">Justificatif des KM</td><td>';
200
    print '<textarea rows="2" cols="60" class="flat" name="justif_kilometers" >' . $vol->justif_kilometers. '</textarea> ';
201
    print '</td></tr>';
202
//NBR pax
203
    print "<tr>";
204
    print '<td width="25%" class="fieldrequired">Nombre de passagers</td><td>';
205
    print '<input type="number" name="nbrPax" calss="flat" value="' . $vol->nbrPax . '"/>';
206
    print '</td></tr>';
207
//Flight cost
208
    print "<tr>";
209
    print '<td width="25%" class="fieldrequired">Montant perçu</td><td>';
210
    print '<input type="text" name="cost" calss="flat" value="' .$vol->cost . '"/>';
211
    print "&euro;";
212
    print '</td></tr>';
213
//Money receiver
214
    print "<tr>";
215
    print '<td width="25%" class="fieldrequired">Qui a perçu l\'argent</td><td>';
216
    print $html->select_dolusers($vol->fk_receiver, 'fk_receiver', 1);
217
    print '</td></tr>';
218
//commentaires
219
    print "<tr>";
220
    print '<td class="fieldrequired"> Commentaire </td><td>';
221
    print '<textarea rows="2" cols="60" calss="flat" name="comm" placeholder="RAS">' . $vol->remarque . '</textarea> ';
222
    print '</td></tr>';
223
//incidents
224
    print "<tr>";
225
    print '<td class="fieldrequired"> incidents </td><td>';
226
    print '<textarea rows="2" cols="60" calss="flat" name="inci" placeholder="RAS">' . $vol->incidents . '</textarea> ';
227
    print '</td></tr>';
228
229
    print '</table>';
230
231
    print '<br><center><input class="button" type="submit" value="' . $langs->trans("Save") . '"> &nbsp; &nbsp; ';
232
    print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '"></center';
233
234
    print '</form>';
235
} else {
236
    print '<table class="border" width="100%">';
237
    print '<tr><td>identifiant</td><td>' . $vol->getIdBBCVols() . '</td></tr>';
238
    print '<tr><td>date </td><td>' . dol_print_date($vol->date) . '</td></tr>';
239
    print '<tr><td>Ballon </td><td>' . ($balloon->immat) . '</td></tr>';
240
    print '<tr><td>lieu de decollage</td><td>' . $vol->lieuD . '</td></tr>';
241
    print '<tr><td>lieu d\'aterissage</td><td>' . $vol->lieuA . '</td></tr>';
242
    print '<tr><td>Heure 1</td><td>' . $vol->heureD . '</td></tr>';
243
    print '<tr><td>Heure 2</td><td>' . $vol->heureA . '</td></tr>';
244
    print '<tr><td>type de vol</td><td>' . $type->idType . '-' . $type->nom . '</td></tr>';
245
    print '<tr><td>Pilote </td><td><a>' . $pilot->getNomUrl() . '</a></td></tr>';
246
    print '<tr><td>organisateur </td><td><a>' . $orga->getNomUrl() . '</a></td></tr>';
247
    print '<tr><td>Nombre de passagers</td><td>' . $vol->nbrPax . '</td></tr>';
248
    print '<tr><td>Incident </td><td>' . $vol->incidents . '</td></tr>';
249
250
    print '</table>';
251
}
252
253
254
print '<div class="tabsAction">';
255
256
if (!isset($_GET['action'])) {
257
    //delete - if user has right
258 View Code Duplication
    if (($user->rights->flightLog->vol->delete && $user->id == $pilot->id ) || $user->admin) {
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...
259
        print '<a class="butActionDelete" href="fiche.php?action=delete&vol=' . $vol->getId() . '">' . $langs->trans('Delete') . '</a>';
260
    } else {
261
        print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Delete') . '</a>';
262
    }
263
264
    //facturer
265
    if ($user->rights->flightLog->vol->status && !$vol->is_facture) {
266
        print '<a class="butAction" href="fiche.php?action=fact&vol=' . $vol->getId() . '">facturer</a>';
267
    } else {
268
        print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">facturer</a>';
269
    }
270
271
    //bouton modifier si on a le droit ou si c'est son vol
272 View Code Duplication
    if ($user->rights->flightLog->vol->edit || $user->id == $pilot->id || $user->admin) {
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...
273
        print '<a class="butAction" href="fiche.php?action=edit&vol=' . $vol->getId() . '">' . $langs->trans('Edit') . '</a>';
274
    } else {
275
        print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Edit') . '</a>';
276
    }
277
}
278
279
print '</div>';
280
281
llxFooter();