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 (GETPOST("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. Loading history...
|
|||
| 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 | ?> |
||
| 131 | <form class="flight-form" name='add' action="addFlight.php" method="post"> |
||
| 132 | <input type="hidden" name="action" value="add"/> |
||
| 133 | |||
| 134 | <section class="form-section"> |
||
| 135 | <h1 class="form-section-title"><?php echo $langs->trans('Date & heures'); ?></h1> |
||
| 136 | <table class="border" width="100%"> |
||
| 137 | <?php |
||
| 138 | //type du vol |
||
| 139 | print "<tr>"; |
||
| 140 | print '<td class="fieldrequired"> Type du vol</td><td colspan="3">'; |
||
| 141 | select_flight_type($_POST['type']); |
||
| 142 | print '</td></tr>'; |
||
| 143 | |||
| 144 | //date du vol |
||
| 145 | print "<tr>"; |
||
| 146 | print '<td class="fieldrequired"> Date du vol</td><td>'; |
||
| 147 | print $html->select_date($datec ? $datec : -1, '', '', '', '', 'add', 1, 1); |
||
| 148 | print '</td></tr>'; |
||
| 149 | |||
| 150 | //Hour start |
||
| 151 | print '<tr><td class="fieldrequired">Heure de départ (format autorise XXXX)</td><td width="25%" >'; |
||
| 152 | print '<input type="text" name="heureD" class="flat" value="' . $_POST['heureD'] . '"/>'; |
||
| 153 | print '</td>'; |
||
| 154 | |||
| 155 | //Hour end |
||
| 156 | print '<td class="fieldrequired">Heure d\'arrivée (format autorise XXXX)</td><td>'; |
||
| 157 | print '<input type="text" name="heureA" class="flat" value="' . $_POST['heureA'] . '"/>'; |
||
| 158 | print '</td></tr>'; |
||
| 159 | |||
| 160 | ?> |
||
| 161 | </table> |
||
| 162 | </section> |
||
| 163 | |||
| 164 | <section class="form-section"> |
||
| 165 | <h1 class="form-section-title"><?php echo $langs->trans('Pilote & ballon') ?></h1> |
||
| 166 | <table class="border" width="50%"> |
||
| 167 | <?php |
||
| 168 | //Pilote |
||
| 169 | print "<tr>"; |
||
| 170 | print '<td class="fieldrequired"> Pilote </td><td >'; |
||
| 171 | print $html->select_dolusers($_POST["pilot"] ? $_POST["pilot"] : $_GET["pilot"], 'pilot', $user->id); |
||
| 172 | print '</td></tr>'; |
||
| 173 | |||
| 174 | //Ballon |
||
| 175 | print "<tr>"; |
||
| 176 | print '<td width="25%" class="fieldrequired">Ballon</td><td>'; |
||
| 177 | select_balloons($_POST['ballon'], 'ballon', 0, 0); |
||
| 178 | print '</td></tr>'; |
||
| 179 | ?> |
||
| 180 | |||
| 181 | <tr> |
||
| 182 | <td>Il y'avait-il plusieurs ballons ?</td> |
||
| 183 | <td colspan="3"><input type="checkbox" value="1" name="grouped_flight"/> - Oui</td> |
||
| 184 | </tr> |
||
| 185 | </table> |
||
| 186 | </section> |
||
| 187 | |||
| 188 | <section class="form-section"> |
||
| 189 | <h1 class="form-section-title"><?php echo $langs->trans('Lieux') ?></h1> |
||
| 190 | <table class="border" width="100%"> |
||
| 191 | <?php |
||
| 192 | |||
| 193 | //place start |
||
| 194 | print "<tr>"; |
||
| 195 | print '<td class="fieldrequired">Lieu de départ </td><td width="25%" >'; |
||
| 196 | print '<input type="text" name="lieuD" class="flat" value="' . $_POST['lieuD'] . '"/>'; |
||
| 197 | print '</td>'; |
||
| 198 | |||
| 199 | //place end |
||
| 200 | print '<td class="fieldrequired">Lieu d\'arrivée </td><td>'; |
||
| 201 | print '<input type="text" name="lieuA" class="flat" value="' . $_POST['lieuA'] . '"/>'; |
||
| 202 | print '</td></tr>'; |
||
| 203 | |||
| 204 | ?> |
||
| 205 | |||
| 206 | </table> |
||
| 207 | </section> |
||
| 208 | |||
| 209 | <section class="form-section"> |
||
| 210 | <h1 class="form-section-title"><?php echo $langs->trans('Fieldfk_organisateur') ?></h1> |
||
| 211 | <table class="border" width="50%"> |
||
| 212 | |||
| 213 | <?php |
||
| 214 | |||
| 215 | |||
| 216 | //organisateur |
||
| 217 | print "<tr>"; |
||
| 218 | print '<td class="fieldrequired">' . $langs->trans('Fieldfk_organisateur') . ' </td><td>'; |
||
| 219 | print $html->select_dolusers($_POST["orga"] ? $_POST["orga"] : $_GET["orga"], 'orga', 1); |
||
| 220 | print '</td></tr>'; |
||
| 221 | ?> |
||
| 222 | |||
| 223 | </table> |
||
| 224 | </section> |
||
| 225 | |||
| 226 | |||
| 227 | <section class="form-section"> |
||
| 228 | <h1 class="form-section-title"><?php echo $langs->trans('Déplacements') ?></h1> |
||
| 229 | <table class="border" width="50%"> |
||
| 230 | <?php |
||
| 231 | |||
| 232 | //Numbe rof kilometrs done for the flight |
||
| 233 | print "<tr>"; |
||
| 234 | print '<td class="fieldrequired">Nombre de kilometres effectués pour le vol</td><td>'; |
||
| 235 | print '<input type="number" name="kilometers" class="flat" value="' . $_POST['kilometers'] . '"/>'; |
||
| 236 | print '</td></tr>'; |
||
| 237 | |||
| 238 | //Justif Kilometers |
||
| 239 | print "<tr>"; |
||
| 240 | print '<td width="25%" class="fieldrequired">Justificatif des KM</td><td>'; |
||
| 241 | print '<textarea rows="2" cols="60" class="flat" name="justif_kilometers" >' . $_POST['justif_kilometers'] . '</textarea> '; |
||
| 242 | print '</td></tr>'; |
||
| 243 | |||
| 244 | |||
| 245 | ?> |
||
| 246 | </table> |
||
| 247 | </section> |
||
| 248 | |||
| 249 | <section class="form-section"> |
||
| 250 | <h1 class="form-section-title"><?php echo $langs->trans('Passager') ?></h1> |
||
| 251 | <table class="border" width="50%"> |
||
| 252 | <?php |
||
| 253 | //NBR pax |
||
| 254 | print "<tr>"; |
||
| 255 | print '<td class="fieldrequired">Nombre de passagers</td><td>'; |
||
| 256 | print '<input type="number" name="nbrPax" class="flat" value="' . $_POST['nbrPax'] . '"/>'; |
||
| 257 | print '</td></tr>'; |
||
| 258 | |||
| 259 | //Flight cost |
||
| 260 | print "<tr>"; |
||
| 261 | print '<td class="fieldrequired">Montant perçu</td><td>'; |
||
| 262 | print '<input type="text" name="cost" class="flat" value="' . $_POST['cost'] . '"/>'; |
||
| 263 | print "€"; |
||
| 264 | print '</td></tr>'; |
||
| 265 | |||
| 266 | //Money receiver |
||
| 267 | print "<tr>"; |
||
| 268 | print '<td class="fieldrequired">Qui a perçu l\'argent</td><td>'; |
||
| 269 | print $html->select_dolusers($_POST["fk_receiver"] ? $_POST["fk_receiver"] : $_GET["fk_receiver"], |
||
| 270 | 'fk_receiver', 1); |
||
| 271 | print '</td></tr>'; |
||
| 272 | |||
| 273 | //commentaires |
||
| 274 | print "<tr>"; |
||
| 275 | print '<td class="fieldrequired"> Commentaire </td><td>'; |
||
| 276 | print '<textarea rows="2" cols="60" class="flat" name="comm" placeholder="RAS">' . $_POST['comm'] . '</textarea> '; |
||
| 277 | print '</td></tr>'; |
||
| 278 | |||
| 279 | //incidents |
||
| 280 | print "<tr>"; |
||
| 281 | print '<td class="fieldrequired"> incidents </td><td>'; |
||
| 282 | print '<textarea rows="2" cols="60" class="flat" name="inci" placeholder="RAS">' . $_POST['inci'] . '</textarea> '; |
||
| 283 | print '</td></tr>'; |
||
| 284 | ?> |
||
| 285 | </table> |
||
| 286 | </section> |
||
| 287 | <?php |
||
| 288 | |||
| 289 | print '<br><input class="button" type="submit" value="' . $langs->trans("Save") . '"> '; |
||
| 290 | print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">'; |
||
| 291 | |||
| 292 | print '</form>'; |
||
| 293 | |||
| 294 | $db->close(); |
||
| 295 |
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.