Completed
Push — master ( 09623d...f9e566 )
by Laurent
03:33
created

addFlight.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
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@mymodule");
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
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...
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.

Loading history...
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: fiche.php?vol=" . $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
96
97
/* * *************************************************
98
 * PAGE
99
 *
100
 * Put here all code to build page
101
 * ************************************************** */
102
103
llxHeader('', 'Carnet de vol', '');
104
105
$html = new Form($db);
106
$datec = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
107
if ($msg) {
108
    print $msg;
109
}
110
111
// Put here content of your page
112
print "<form name='add' action=\"addFlight.php\" method=\"post\">\n";
113
print '<input type="hidden" name="action" value="add"/>';
114
print '<table class="border" width="100%">';
115
//date du vol
116
print "<tr>";
117
print '<td class="fieldrequired"> Date du vol</td><td>';
118
print $html->select_date($datec ? $datec : -1, '', '', '', '', 'add', 1, 1);
119
print '</td></tr>';
120
//type du vol
121
print "<tr>";
122
print '<td class="fieldrequired"> Type du vol</td><td>';
123
print select_flight_type($_POST['type']);
124
print '</td></tr>';
125
//Pilote
126
print "<tr>";
127
print '<td class="fieldrequired"> Pilote </td><td>';
128
print $html->select_dolusers($_POST["pilot"] ? $_POST["pilot"] : $_GET["pilot"], 'pilot', $user->id);
129
print '</td></tr>';
130
//organisateur
131
print "<tr>";
132
print '<td class="fieldrequired"> Organisateur </td><td>';
133
print $html->select_dolusers($_POST["orga"] ? $_POST["orga"] : $_GET["orga"], 'orga', 1);
134
print '</td></tr>';
135
//Ballon
136
print "<tr>";
137
print '<td width="25%" class="fieldrequired">Ballon</td><td>';
138
print select_balloons($_POST['ballon'], 'ballon', 0, 0);
139
print '</td></tr>';
140
//lieu d�part
141
print "<tr>";
142
print '<td width="25%" class="fieldrequired">Lieu de d&#233;part </td><td>';
143
print '<input type="text" name="lieuD" class="flat" value="' . $_POST['lieuD'] . '"/>';
144
print '</td></tr>';
145
//lieu arriv�e
146
print "<tr>";
147
print '<td width="25%" class="fieldrequired">Lieu d\'arriv&#233;e </td><td>';
148
print '<input type="text" name="lieuA" class="flat" value="' . $_POST['lieuA'] . '"/>';
149
print '</td></tr>';
150
//heure d�part
151
print "<tr>";
152
print '<td width="25%" class="fieldrequired">Heure de d&#233;part <br/>(format autorise XXXX)</td><td>';
153
print '<input type="text" name="heureD" class="flat" value="' . $_POST['heureD'] . '"/>';
154
print '</td></tr>';
155
//heure arriv�e
156
print "<tr>";
157
print '<td width="25%" class="fieldrequired">Heure d\'arriv&#233;e <br/>(format autorise XXXX)</td><td>';
158
print '<input type="text" name="heureA" class="flat" value="' . $_POST['heureA'] . '"/>';
159
print '</td></tr>';
160
//Numbe rof kilometrs done for the flight
161
print "<tr>";
162
print '<td width="25%" class="fieldrequired">Nombre de kilometres effectués pour le vol</td><td>';
163
print '<input type="number" name="kilometers" class="flat" value="' . $_POST['kilometers'] . '"/>';
164
print '</td></tr>';
165
166
//Justif KIlometers
167
print "<tr>";
168
print '<td width="25%" class="fieldrequired">Justificatif des KM</td><td>';
169
print '<textarea rows="2" cols="60" class="flat" name="justif_kilometers" >' . $_POST['justif_kilometers'] . '</textarea> ';
170
print '</td></tr>';
171
//NBR pax
172
print "<tr>";
173
print '<td width="25%" class="fieldrequired">Nombre de passagers</td><td>';
174
print '<input type="number" name="nbrPax" class="flat" value="' . $_POST['nbrPax'] . '"/>';
175
print '</td></tr>';
176
//Flight cost
177
print "<tr>";
178
print '<td width="25%" class="fieldrequired">Montant perçu</td><td>';
179
print '<input type="text" name="cost" class="flat" value="' . $_POST['cost'] . '"/>';
180
print "&euro;";
181
print '</td></tr>';
182
//Money receiver
183
print "<tr>";
184
print '<td width="25%" class="fieldrequired">Qui a perçu l\'argent</td><td>';
185
print $html->select_dolusers($_POST["fk_receiver"] ? $_POST["fk_receiver"] : $_GET["fk_receiver"], 'fk_receiver', 1);
186
print '</td></tr>';
187
//commentaires
188
print "<tr>";
189
print '<td class="fieldrequired"> Commentaire </td><td>';
190
print '<textarea rows="2" cols="60" class="flat" name="comm" placeholder="RAS">' . $_POST['comm'] . '</textarea> ';
191
print '</td></tr>';
192
//incidents
193
print "<tr>";
194
print '<td class="fieldrequired"> incidents </td><td>';
195
print '<textarea rows="2" cols="60" class="flat" name="inci" placeholder="RAS">' . $_POST['inci'] . '</textarea> ';
196
print '</td></tr>';
197
198
print '</table>';
199
200
print '<br><center><input class="button" type="submit" value="' . $langs->trans("Save") . '"> &nbsp; &nbsp; ';
201
print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '"></center';
202
203
print '</form>';
204
205
/* * *************************************************
206
 * LINKED OBJECT BLOCK
207
 *
208
 * Put here code to view linked object
209
 * ************************************************** */
210
// End of page
211
$db->close();
212
llxFooter('$Date: 2011/07/31 22:21:57 $ - $Revision: 1.19 $');
213