Completed
Push — master ( f9e566...747eba )
by Laurent
03:05
created

readFlightsPilot.php (8 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
 * \file    mypage.php
4
 * \ingroup mymodule
5
 * \brief   Example PHP page.
6
 *
7
 * read flights
8
 */
9
10
// Load Dolibarr environment
11
if (false === (@include '../main.inc.php')) {  // From htdocs directory
12
    require '../../documents/custom/main.inc.php'; // From "custom" directory
13
}
14
15
global $db, $langs, $user;
16
17
dol_include_once('/flightLog/class/bbcvols.class.php');
18
dol_include_once("/flightBalloon/bbc_ballons.class.php");
19
dol_include_once('/flightLog/class/bbctypes.class.php');
20
dol_include_once("/flightLog/lib/flightLog.lib.php");
21
22
// Load translation files required by the page
23
$langs->load("mymodule@mymodule");
24
25
// Get parameters
26
$myparam = isset($_GET["myparam"]) ? $_GET["myparam"] : '';
27
28
// Protection if external user
29
if ($user->societe_id > 0) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
30
    //accessforbidden();
31
}
32
// Protection if the user can't acces to the module
33
if (!$user->rights->flightLog->vol->access) {
34
    accessforbidden();
35
}
36
37
/*******************************************************************
38
 * ACTIONS
39
 *
40
 * Put here all code to do according to value of "action" parameter
41
 ********************************************************************/
42 View Code Duplication
if ($_POST["mode"] == 'SELECT') {
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...
43
    $userid = $_POST['userid'];
44
} else {
45
    $userid = $user->id;
46
}
47
48
//balloon with ID
49
$bbcUser = New User($db);
50
51
if ($bbcUser->fetch($userid) == -1) {
52
    print "ERROR<br/>";
53
}
54
55
//date
56
$datep = dol_mktime(-1, -1, -1, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]);
57
$datef = dol_mktime(-1, -1, -1, $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]);
58
59
//flight with balloon ID
60
$query = 'SELECT *,TIMEDIFF(heureA,heureD) AS time  FROM llx_bbc_vols WHERE 1=1';
61
62
if ($datep) {
63
    $query .= ' AND date >= \'' . dol_print_date($datep, 'dayrfc'). '\'';
64
}
65
if ($datef) {
66
    $query .= ' AND date <= \'' . dol_print_date($datef, 'dayrfc'). '\'';
67
}
68
69
$query .= ' AND `fk_pilot` = ' . $bbcUser->id;
70
$query .= ' ORDER BY date DESC';
71
72
$resql = $db->query($query);
73
74
75
$sqlByType = "SELECT USR.name AS nom , USR.firstname AS prenom ,COUNT(`idBBC_vols`) AS nbr,fk_pilot as pilot, TT.numero as type,SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(heureA,heureD)))) AS time ";
76
$sqlByType .= " FROM llx_bbc_vols, llx_user AS USR,llx_bbc_types AS TT WHERE `fk_pilot`= USR.rowid AND fk_type = TT.idType AND USR.rowid = " . $bbcUser->id;
77
78
if ($datep) {
79
    $sqlByType .= ' AND date >= \'' . dol_print_date($datep, 'dayrfc') . '\'';
80
}
81
if ($datef) {
82
    $sqlByType .= ' AND date <= \'' . dol_print_date($datef, 'dayrfc') . '\'';
83
}
84
85
$sqlByType .= " GROUP BY fk_pilot,`fk_type`";
86
87
88
$resqlByType = $db->query($sqlByType);
89
90
91
/***************************************************
92
 * PAGE
93
 *
94
 * Put here all code to build page
95
 ****************************************************/
96
llxHeader('', 'Carnet de vol', '');
97
98
$form = new Form($db);
99
100
print '<!-- debut cartouche rapport -->
101
<div class="tabs">
102
<a id="active" class="tab">Carnet de vol</a>
103
</div>';
104
print '<div class="tabBar">';
105
print "<form name='readBalloon' action=\"readFlightsPilot.php\" method=\"post\">\n";
106
print '<input type="hidden" name="mode" value="SELECT">';
107
print '<table width="100%" class="border">';
108
//Pilote
109
print '<tr><td>Pilote</td><td>';
110 View Code Duplication
if ($user->rights->flightLog->vol->detail) {
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...
111
    print $form->select_dolusers($userid);
112
} else {
113
    print $user->nom . ' ' . $user->prenom;
114
}
115
print'</td></tr>';
116
117
// Date start
118 View Code Duplication
if (GETPOST('datep', 'int', 1)) {
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...
119
    $datep = dol_stringtotime(GETPOST('datep', 'int', 1), 0);
120
}
121
print '<tr><td width="30%" nowrap="nowrap"><span>Debut</span></td><td>';
122
$form->select_date($datep, 'ap', 0, 0, 1, "readBalloon", 1, 1, 0, 0);
123
print '</td></tr>';
124
125
// Date end
126 View Code Duplication
if (GETPOST('datef', 'int', 1)) {
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...
127
    $datef = dol_stringtotime(GETPOST('datef', 'int', 1), 0);
128
}
129
print '<tr><td>Fin</span></td><td>';
130
$form->select_date($datef, 'p2', 0, 0, 1, "readBalloon", 1, 1, 0, 0);
131
print '</td></tr>';
132
133
134
$num = 0;
135 View Code Duplication
if ($resql) {
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...
136
    $num = $db->num_rows($resql);
137
    //Nbr de vols
138
    print '<tr>';
139
    print '<td>Nombre de vol(s) total (suivant filtre) </td>';
140
    print '<td>' . $num . '</td>';
141
    print '</tr>';
142
}
143
144
//Types
145 View Code Duplication
if ($resqlByType) {
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...
146
    $table = sqlToArray($db, $sqlByType, false);
147
    print '<td>Nombre de vols par type</td><td></td></tr>';
148
    print '<tr>';
149
    print '<td>Type 1 - Sponsor </td>';
150
    print '<td>' . $table[$userid]['1']['count'] . '</td>';
151
    print '</tr>';
152
    print '<tr>';
153
    print '<td>Type 2 - Baptême </td>';
154
    print '<td>' . $table[$userid]['2']['count'] . '</td>';
155
    print '</tr>';
156
    print '<tr>';
157
    print '<td>Type 3 - Privé </td>';
158
    print '<td>' . $table[$userid]['3']['count'] . '</td>';
159
    print '</tr>';
160
    print '<tr>';
161
    print '<td>Type 4 - Meeting </td>';
162
    print '<td>' . $table[$userid]['4']['count'] . '</td>';
163
    print '</tr>';
164
    print '<tr>';
165
    print '<td>Type 5  - Chambley </td>';
166
    print '<td>' . $table[$userid]['5']['count'] . '</td>';
167
    print '</tr>';
168
    print '<tr>';
169
    print '<td>Type 6 - Instruction </td>';
170
    print '<td>' . $table[$userid]['6']['count'] . '</td>';
171
    print '</tr>';
172
173
}
174
175
176
print '<tr><td colspan="2" align="center"><input type="submit" class="button" name="submit" value="Rafraichir"></td></tr></table>';
177
print '</form></div>';
178
179
180
if ($resql) {
181
    //fetch pilot
182
183
    print '<table class="border" width="100%">';
184
    $num = $db->num_rows($resql);
185
    $i = 0;
186 View Code Duplication
    if ($num) {
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...
187
        print '<tr class="liste_titre">';
188
        print '<td class="liste_titre"> identifiant </td>';
189
        print '<td class="liste_titre"> Type </td>';
190
        print '<td class="liste_titre"> Date </td>';
191
        print '<td class="liste_titre"> Ballon </td>';
192
        print '<td class="liste_titre"> Pilote </td>';
193
        print '<td class="liste_titre"> Lieu depart </td>';
194
        print '<td class="liste_titre"> Lieu arrivee </td>';
195
        print '<td class="liste_titre"> Heure depart</td>';
196
        print '<td class="liste_titre"> Heure Arrivee </td>';
197
        print '<td class="liste_titre"> Duree (min) </td>';
198
        print '<td class="liste_titre"> Nbr Pax </td>';
199
        print '<td class="liste_titre"> Rem </td>';
200
        print '<td class="liste_titre"> Incidents </td>';
201
        print '<td class="liste_titre"> KM </td>';
202
        print '<td class="liste_titre"> Justificatif KM </td>';
203
        if ($user->rights->flightLog->vol->status) {
204
            print '<td class="liste_titre"> Statut </td>';
205
        }
206
        print'</tr>';
207
        while ($i < $num) {
208
209
            $obj = $db->fetch_object($resql); //vol
210
            $ballon = New Bbc_ballons($db);
211
            $ballon->fetch($obj->BBC_ballons_idBBC_ballons);
212
            print '<tr>';
213
            if ($obj) {
214
                print '<td><a href="fiche.php?vol=' . $obj->idBBC_vols . '">' . $obj->idBBC_vols . '</a></td>';
215
                print '<td>' . $obj->fk_type . '</td>';
216
                print '<td>' . $obj->date . '</td>';
217
                print '<td>' . $ballon->immat . '</td>';
218
                print '<td>' . $bbcUser->getFullName($langs) . '</td>';
219
                print '<td>' . $obj->lieuD . '</td>';
220
                print '<td>' . $obj->lieuA . '</td>';
221
                print '<td>' . $obj->heureD . '</td>';
222
                print '<td>' . $obj->heureA . '</td>';
223
                print '<td>' . $obj->time . 'min </td>';
224
                print '<td>' . $obj->nbrPax . '</td>';
225
                print '<td>' . $obj->remarque . '</td>';
226
                print '<td>' . $obj->incidents . '</td>';
227
                print '<td>' . $obj->kilometers . '</td>';
228
                print '<td>' . $obj->justif_kilometers . '</td>';
229
                if ($user->rights->flightLog->vol->status) {
230
                    $vol = new Bbcvols($db);
231
                    $vol->fetch($obj->idBBC_vols);
232
                    print '<td>' . $vol->getStatus() . '</td>';
233
                }
234
            }
235
            print'</tr>';
236
            $i++;
237
        }
238
    }
239
    print'</table>';
240
}
241
242
llxFooter();
243