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('/flightlog/class/bbcvols.class.php'); |
||
11 | dol_include_once('/flightlog/class/bbctypes.class.php'); |
||
12 | dol_include_once("/flightlog/lib/flightLog.lib.php"); |
||
13 | |||
14 | // Load translation files required by the page |
||
15 | $langs->load("mymodule@flightlog"); |
||
16 | |||
17 | |||
18 | if (!$user->rights->flightlog->vol->add) { |
||
19 | accessforbidden(); |
||
20 | } |
||
21 | |||
22 | |||
23 | /* * ***************************************************************** |
||
24 | * ACTIONS |
||
25 | * |
||
26 | * Put here all code to do according to value of "action" parameter |
||
27 | * ****************************************************************** */ |
||
28 | $msg = ''; |
||
29 | if ($_GET["action"] == 'add' || $_POST["action"] == 'add') { |
||
30 | if (!$_POST["cancel"]) { |
||
31 | $dated = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); |
||
32 | |||
33 | $vol = new Bbcvols($db); |
||
34 | |||
35 | $vol->date = $dated; |
||
36 | $vol->lieuD = $_POST['lieuD']; |
||
37 | $vol->lieuA = $_POST['lieuA']; |
||
38 | $vol->heureD = $_POST['heureD']; |
||
39 | $vol->heureA = $_POST['heureA']; |
||
40 | $vol->BBC_ballons_idBBC_ballons = $_POST['ballon']; |
||
41 | $vol->nbrPax = $_POST['nbrPax']; |
||
42 | $vol->remarque = $_POST['comm']; |
||
43 | $vol->incidents = $_POST['inci']; |
||
44 | $vol->fk_type = $_POST['type']; |
||
45 | $vol->fk_pilot = $_POST['pilot']; |
||
46 | $vol->fk_organisateur = $_POST['orga']; |
||
47 | $vol->kilometers = $_POST['kilometers']; |
||
48 | $vol->cost = $_POST['cost']; |
||
49 | $vol->fk_receiver = $_POST['fk_receiver']; |
||
50 | $vol->justif_kilometers = $_POST['justif_kilometers']; |
||
51 | $isGroupedFlight = (int)GETPOST('grouped_flight', 'int',2) === 1; |
||
52 | |||
53 | //verification des heures |
||
54 | $patern = '#[0-9]{4}#'; |
||
55 | $error = 0; |
||
56 | View Code Duplication | if (preg_match($patern, $vol->heureD) == 0 || strlen($vol->heureD) != 4) { |
|
0 ignored issues
–
show
|
|||
57 | $msg = '<div class="error">L\'heure depart n\'est pas correcte</div>'; |
||
58 | $error++; |
||
59 | } else { |
||
60 | $vol->heureD = $vol->heureD . '00'; |
||
61 | } |
||
62 | View Code Duplication | if (preg_match($patern, $vol->heureA) == 0 || strlen($vol->heureA) != 4) { |
|
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. ![]() |
|||
63 | $msg = '<div class="error">L\'heure d\'arrivee n\'est pas correcte</div>'; |
||
64 | $error++; |
||
65 | } else { |
||
66 | $vol->heureA = $vol->heureA . '00'; |
||
67 | } |
||
68 | |||
69 | if ($error == 0 && ($vol->heureA - $vol->heureD) <= 0) { |
||
70 | $msg = '<div class="error">L\'heure de depart est plus grande que l\'heure d\'arrivee</div>'; |
||
71 | $error++; |
||
72 | } |
||
73 | |||
74 | // PAX |
||
75 | if ($vol->nbrPax < 0) { |
||
76 | $msg = '<div class="error">Erreur le nombre de passager est un nombre négatif.</div>'; |
||
77 | $error++; |
||
78 | } |
||
79 | |||
80 | if ($vol->mustHavePax() && !$vol->hasPax()) { |
||
81 | $msg = '<div class="error">Erreur ce type de vol doit etre fait avec des passagers.</div>'; |
||
82 | $error++; |
||
83 | } |
||
84 | |||
85 | // verification billing |
||
86 | if (!$isGroupedFlight && $vol->getFlightType()->isBillingRequired() && $vol->isFree()) { |
||
87 | $msg = '<div class="error">Erreur ce type de vol doit être payant.</div>'; |
||
88 | $error++; |
||
89 | } |
||
90 | if($vol->getFlightType()->isBillingRequired() && !$vol->hasReceiver()){ |
||
91 | $msg = '<div class="error">Erreur ce type de vol doit être payant, mais personne n\'a été signalé comme recepteur d\'argent.</div>'; |
||
92 | $error++; |
||
93 | } |
||
94 | |||
95 | if ($error == 0) { |
||
96 | $result = $vol->create($user); |
||
97 | if ($result > 0) { |
||
98 | //creation OK |
||
99 | |||
100 | include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
||
101 | $interface = new Interfaces($db); |
||
102 | $triggerResult = $interface->run_triggers('BBC_FLIGHT_LOG_ADD_FLIGHT', $vol, $user, $langs, $conf); |
||
103 | |||
104 | $msg = '<div class="ok">L\'ajout du vol du : ' . $_POST["reday"] . '/' . $_POST["remonth"] . '/' . $_POST["reyear"] . ' s\'est correctement effectue ! </div>'; |
||
105 | Header("Location: card.php?id=" . $result); |
||
106 | } else { |
||
107 | // Creation KO |
||
108 | $msg = '<div class="error">Erreur lors de l\'ajout du vol : ' . $vol->error . '! </div>'; |
||
109 | $error++; |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
115 | |||
116 | /* * ************************************************* |
||
117 | * PAGE |
||
118 | * |
||
119 | * Put here all code to build page |
||
120 | * ************************************************** */ |
||
121 | |||
122 | llxHeader('', 'Carnet de vol', ''); |
||
123 | |||
124 | $html = new Form($db); |
||
125 | $datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); |
||
126 | if ($msg) { |
||
127 | print $msg; |
||
128 | } |
||
129 | |||
130 | // Put here content of your page |
||
131 | print "<form name='add' action=\"addFlight.php\" method=\"post\">\n"; |
||
132 | print '<input type="hidden" name="action" value="add"/>'; |
||
133 | print '<table class="border" width="100%">'; |
||
134 | //date du vol |
||
135 | print "<tr>"; |
||
136 | print '<td class="fieldrequired"> Date du vol</td><td>'; |
||
137 | print $html->select_date($datec ? $datec : -1, '', '', '', '', 'add', 1, 1); |
||
138 | print '</td></tr>'; |
||
139 | //type du vol |
||
140 | print "<tr>"; |
||
141 | print '<td class="fieldrequired"> Type du vol</td><td>'; |
||
142 | select_flight_type($_POST['type']); |
||
143 | print '</td></tr>'; |
||
144 | ?> |
||
145 | <tr> |
||
146 | <td>Il y'avait-il plusieurs ballons ?</td> |
||
147 | <td><input type="checkbox" value="1" name="grouped_flight" /> - Oui </td> |
||
148 | </tr> |
||
149 | |||
150 | <?php |
||
151 | print '</td></tr>'; |
||
152 | //Pilote |
||
153 | print "<tr>"; |
||
154 | print '<td class="fieldrequired"> Pilote </td><td>'; |
||
155 | print $html->select_dolusers($_POST["pilot"] ? $_POST["pilot"] : $_GET["pilot"], 'pilot', $user->id); |
||
156 | print '</td></tr>'; |
||
157 | //organisateur |
||
158 | print "<tr>"; |
||
159 | print '<td class="fieldrequired"> Organisateur </td><td>'; |
||
160 | print $html->select_dolusers($_POST["orga"] ? $_POST["orga"] : $_GET["orga"], 'orga', 1); |
||
161 | print '</td></tr>'; |
||
162 | //Ballon |
||
163 | print "<tr>"; |
||
164 | print '<td width="25%" class="fieldrequired">Ballon</td><td>'; |
||
165 | select_balloons($_POST['ballon'], 'ballon', 0, 0); |
||
166 | print '</td></tr>'; |
||
167 | //lieu d�part |
||
168 | print "<tr>"; |
||
169 | print '<td width="25%" class="fieldrequired">Lieu de départ </td><td>'; |
||
170 | print '<input type="text" name="lieuD" class="flat" value="' . $_POST['lieuD'] . '"/>'; |
||
171 | print '</td></tr>'; |
||
172 | //lieu arriv�e |
||
173 | print "<tr>"; |
||
174 | print '<td width="25%" class="fieldrequired">Lieu d\'arrivée </td><td>'; |
||
175 | print '<input type="text" name="lieuA" class="flat" value="' . $_POST['lieuA'] . '"/>'; |
||
176 | print '</td></tr>'; |
||
177 | //heure d�part |
||
178 | print "<tr>"; |
||
179 | print '<td width="25%" class="fieldrequired">Heure de départ <br/>(format autorise XXXX)</td><td>'; |
||
180 | print '<input type="text" name="heureD" class="flat" value="' . $_POST['heureD'] . '"/>'; |
||
181 | print '</td></tr>'; |
||
182 | //heure arriv�e |
||
183 | print "<tr>"; |
||
184 | print '<td width="25%" class="fieldrequired">Heure d\'arrivée <br/>(format autorise XXXX)</td><td>'; |
||
185 | print '<input type="text" name="heureA" class="flat" value="' . $_POST['heureA'] . '"/>'; |
||
186 | print '</td></tr>'; |
||
187 | //Numbe rof kilometrs done for the flight |
||
188 | print "<tr>"; |
||
189 | print '<td width="25%" class="fieldrequired">Nombre de kilometres effectués pour le vol</td><td>'; |
||
190 | print '<input type="number" name="kilometers" class="flat" value="' . $_POST['kilometers'] . '"/>'; |
||
191 | print '</td></tr>'; |
||
192 | |||
193 | //Justif Kilometers |
||
194 | print "<tr>"; |
||
195 | print '<td width="25%" class="fieldrequired">Justificatif des KM</td><td>'; |
||
196 | print '<textarea rows="2" cols="60" class="flat" name="justif_kilometers" >' . $_POST['justif_kilometers'] . '</textarea> '; |
||
197 | print '</td></tr>'; |
||
198 | //NBR pax |
||
199 | print "<tr>"; |
||
200 | print '<td width="25%" class="fieldrequired">Nombre de passagers</td><td>'; |
||
201 | print '<input type="number" name="nbrPax" class="flat" value="' . $_POST['nbrPax'] . '"/>'; |
||
202 | print '</td></tr>'; |
||
203 | //Flight cost |
||
204 | print "<tr>"; |
||
205 | print '<td width="25%" class="fieldrequired">Montant perçu</td><td>'; |
||
206 | print '<input type="text" name="cost" class="flat" value="' . $_POST['cost'] . '"/>'; |
||
207 | print "€"; |
||
208 | print '</td></tr>'; |
||
209 | //Money receiver |
||
210 | print "<tr>"; |
||
211 | print '<td width="25%" class="fieldrequired">Qui a perçu l\'argent</td><td>'; |
||
212 | print $html->select_dolusers($_POST["fk_receiver"] ? $_POST["fk_receiver"] : $_GET["fk_receiver"], 'fk_receiver', 1); |
||
213 | print '</td></tr>'; |
||
214 | //commentaires |
||
215 | print "<tr>"; |
||
216 | print '<td class="fieldrequired"> Commentaire </td><td>'; |
||
217 | print '<textarea rows="2" cols="60" class="flat" name="comm" placeholder="RAS">' . $_POST['comm'] . '</textarea> '; |
||
218 | print '</td></tr>'; |
||
219 | //incidents |
||
220 | print "<tr>"; |
||
221 | print '<td class="fieldrequired"> incidents </td><td>'; |
||
222 | print '<textarea rows="2" cols="60" class="flat" name="inci" placeholder="RAS">' . $_POST['inci'] . '</textarea> '; |
||
223 | print '</td></tr>'; |
||
224 | |||
225 | print '</table>'; |
||
226 | |||
227 | print '<br><input class="button" type="submit" value="' . $langs->trans("Save") . '"> '; |
||
228 | print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">'; |
||
229 | |||
230 | print '</form>'; |
||
231 | |||
232 | $db->close(); |
||
233 |
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.