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; |
||
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 | |||
52 | //verification des heures |
||
53 | $patern = '#[0-9]{4}#'; |
||
54 | $error = 0; |
||
55 | View Code Duplication | if (preg_match($patern, $vol->heureD) == 0 || strlen($vol->heureD) != 4) { |
|
0 ignored issues
–
show
|
|||
56 | $msg = '<div class="error">L\'heure depart n\'est pas correcte</div>'; |
||
57 | $error++; |
||
58 | } else { |
||
59 | $vol->heureD = $vol->heureD . '00'; |
||
60 | } |
||
61 | 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. ![]() |
|||
62 | $msg = '<div class="error">L\'heure d\'arrivee n\'est pas correcte</div>'; |
||
63 | $error++; |
||
64 | } else { |
||
65 | $vol->heureA = $vol->heureA . '00'; |
||
66 | } |
||
67 | |||
68 | if ($error == 0 && ($vol->heureA - $vol->heureD) <= 0) { |
||
69 | $msg = '<div class="error">L\'heure de depart est plus grande que l\'heure d\'arrivee</div>'; |
||
70 | $error++; |
||
71 | } |
||
72 | |||
73 | // verification du nombre de pax |
||
74 | if ($vol->nbrPax < 0) { |
||
75 | $msg = '<div class="error">Erreur le nombre de passager est �gale � 0 ou est un nombre n�gatif.</div>'; |
||
76 | $error++; |
||
77 | } |
||
78 | if ($error == 0) { |
||
79 | $result = $vol->create($user); |
||
80 | if ($result > 0) { |
||
81 | //creation OK |
||
82 | $msg = '<div class="ok">L\'ajout du vol du : ' . $_POST["reday"] . '/' . $_POST["remonth"] . '/' . $_POST["reyear"] . ' s\'est correctement effectue ! </div>'; |
||
83 | Header("Location: card.php?id=" . $result); |
||
84 | } else { |
||
85 | // Creation KO |
||
86 | $msg = '<div class="error">Erreur lors de l\'ajout du vol : ' . $vol->error . '! </div>'; |
||
87 | $error++; |
||
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 | |||
102 | $html = new Form($db); |
||
103 | $datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); |
||
104 | if ($msg) { |
||
105 | print $msg; |
||
106 | } |
||
107 | |||
108 | // Put here content of your page |
||
109 | print "<form name='add' action=\"addFlight.php\" method=\"post\">\n"; |
||
110 | print '<input type="hidden" name="action" value="add"/>'; |
||
111 | print '<table class="border" width="100%">'; |
||
112 | //date du vol |
||
113 | print "<tr>"; |
||
114 | print '<td class="fieldrequired"> Date du vol</td><td>'; |
||
115 | print $html->select_date($datec ? $datec : -1, '', '', '', '', 'add', 1, 1); |
||
116 | print '</td></tr>'; |
||
117 | //type du vol |
||
118 | print "<tr>"; |
||
119 | print '<td class="fieldrequired"> Type du vol</td><td>'; |
||
120 | select_flight_type($_POST['type']); |
||
121 | print '</td></tr>'; |
||
122 | //Pilote |
||
123 | print "<tr>"; |
||
124 | print '<td class="fieldrequired"> Pilote </td><td>'; |
||
125 | print $html->select_dolusers($_POST["pilot"] ? $_POST["pilot"] : $_GET["pilot"], 'pilot', $user->id); |
||
126 | print '</td></tr>'; |
||
127 | //organisateur |
||
128 | print "<tr>"; |
||
129 | print '<td class="fieldrequired"> Organisateur </td><td>'; |
||
130 | print $html->select_dolusers($_POST["orga"] ? $_POST["orga"] : $_GET["orga"], 'orga', 1); |
||
131 | print '</td></tr>'; |
||
132 | //Ballon |
||
133 | print "<tr>"; |
||
134 | print '<td width="25%" class="fieldrequired">Ballon</td><td>'; |
||
135 | select_balloons($_POST['ballon'], 'ballon', 0, 0); |
||
136 | print '</td></tr>'; |
||
137 | //lieu d�part |
||
138 | print "<tr>"; |
||
139 | print '<td width="25%" class="fieldrequired">Lieu de départ </td><td>'; |
||
140 | print '<input type="text" name="lieuD" class="flat" value="' . $_POST['lieuD'] . '"/>'; |
||
141 | print '</td></tr>'; |
||
142 | //lieu arriv�e |
||
143 | print "<tr>"; |
||
144 | print '<td width="25%" class="fieldrequired">Lieu d\'arrivée </td><td>'; |
||
145 | print '<input type="text" name="lieuA" class="flat" value="' . $_POST['lieuA'] . '"/>'; |
||
146 | print '</td></tr>'; |
||
147 | //heure d�part |
||
148 | print "<tr>"; |
||
149 | print '<td width="25%" class="fieldrequired">Heure de départ <br/>(format autorise XXXX)</td><td>'; |
||
150 | print '<input type="text" name="heureD" class="flat" value="' . $_POST['heureD'] . '"/>'; |
||
151 | print '</td></tr>'; |
||
152 | //heure arriv�e |
||
153 | print "<tr>"; |
||
154 | print '<td width="25%" class="fieldrequired">Heure d\'arrivée <br/>(format autorise XXXX)</td><td>'; |
||
155 | print '<input type="text" name="heureA" class="flat" value="' . $_POST['heureA'] . '"/>'; |
||
156 | print '</td></tr>'; |
||
157 | //Numbe rof kilometrs done for the flight |
||
158 | print "<tr>"; |
||
159 | print '<td width="25%" class="fieldrequired">Nombre de kilometres effectués pour le vol</td><td>'; |
||
160 | print '<input type="number" name="kilometers" class="flat" value="' . $_POST['kilometers'] . '"/>'; |
||
161 | print '</td></tr>'; |
||
162 | |||
163 | //Justif KIlometers |
||
164 | print "<tr>"; |
||
165 | print '<td width="25%" class="fieldrequired">Justificatif des KM</td><td>'; |
||
166 | print '<textarea rows="2" cols="60" class="flat" name="justif_kilometers" >' . $_POST['justif_kilometers'] . '</textarea> '; |
||
167 | print '</td></tr>'; |
||
168 | //NBR pax |
||
169 | print "<tr>"; |
||
170 | print '<td width="25%" class="fieldrequired">Nombre de passagers</td><td>'; |
||
171 | print '<input type="number" name="nbrPax" class="flat" value="' . $_POST['nbrPax'] . '"/>'; |
||
172 | print '</td></tr>'; |
||
173 | //Flight cost |
||
174 | print "<tr>"; |
||
175 | print '<td width="25%" class="fieldrequired">Montant perçu</td><td>'; |
||
176 | print '<input type="text" name="cost" class="flat" value="' . $_POST['cost'] . '"/>'; |
||
177 | print "€"; |
||
178 | print '</td></tr>'; |
||
179 | //Money receiver |
||
180 | print "<tr>"; |
||
181 | print '<td width="25%" class="fieldrequired">Qui a perçu l\'argent</td><td>'; |
||
182 | print $html->select_dolusers($_POST["fk_receiver"] ? $_POST["fk_receiver"] : $_GET["fk_receiver"], 'fk_receiver', 1); |
||
183 | print '</td></tr>'; |
||
184 | //commentaires |
||
185 | print "<tr>"; |
||
186 | print '<td class="fieldrequired"> Commentaire </td><td>'; |
||
187 | print '<textarea rows="2" cols="60" class="flat" name="comm" placeholder="RAS">' . $_POST['comm'] . '</textarea> '; |
||
188 | print '</td></tr>'; |
||
189 | //incidents |
||
190 | print "<tr>"; |
||
191 | print '<td class="fieldrequired"> incidents </td><td>'; |
||
192 | print '<textarea rows="2" cols="60" class="flat" name="inci" placeholder="RAS">' . $_POST['inci'] . '</textarea> '; |
||
193 | print '</td></tr>'; |
||
194 | |||
195 | print '</table>'; |
||
196 | |||
197 | print '<br><input class="button" type="submit" value="' . $langs->trans("Save") . '"> '; |
||
198 | print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">'; |
||
199 | |||
200 | print '</form>'; |
||
201 | |||
202 | /* * ************************************************* |
||
203 | * LINKED OBJECT BLOCK |
||
204 | * |
||
205 | * Put here code to view linked object |
||
206 | * ************************************************** */ |
||
207 | // End of page |
||
208 | $db->close(); |
||
209 | llxFooter('$Date: 2011/07/31 22:21:57 $ - $Revision: 1.19 $'); |
||
210 |
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.