Issues (188)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

query/BillableFlightQueryHandler.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
require_once(DOL_DOCUMENT_ROOT . '/flightlog/class/flight/Pilot.php');
4
require_once(DOL_DOCUMENT_ROOT . '/flightlog/class/flight/FlightTypeCount.php');
5
require_once(DOL_DOCUMENT_ROOT . '/flightlog/query/BillableFlightQuery.php');
6
7
/**
8
 * @author Laurent De Coninck <[email protected]>
9
 */
10
class BillableFlightQueryHandler
11
{
12
13
    /**
14
     * @var DoliDb $db
15
     */
16
    private $db;
17
18
    /**
19
     * @var stdClass
20
     */
21
    private $conf;
22
23
    /**
24
     * @param DoliDb   $db
25
     * @param stdClass $conf
26
     */
27
    public function __construct(DoliDb $db, stdClass $conf)
28
    {
29
        $this->db = $db;
30
        $this->conf = $conf;
31
    }
32
33
    /**
34
     * @param BillableFlightQuery $query
35
     *
36
     * @return array
37
     */
38
    public function __invoke(BillableFlightQuery $query)
39
    {
40
        $sql = "SELECT USR.lastname 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";
41
        $sql .= " FROM llx_bbc_vols, llx_user AS USR,llx_bbc_types AS TT ";
42
        $sql .= " WHERE `fk_pilot`= USR.rowid AND fk_type = TT.idType AND YEAR(llx_bbc_vols.date) = " . ($query->hasYear() ? "'" . $query->getFiscalYear() . "'" : 'YEAR(NOW())');
43
        $sql .= " GROUP BY fk_pilot,`fk_type`";
44
45
        $resql = $this->db->query($sql);
46
        $array = array();
47
        if ($resql) {
48
            $num = $this->db->num_rows($resql);
49
            $i = 0;
50
            if ($num) {
51
                while ($i < $num) {
52
                    $obj = $this->db->fetch_object($resql); //vol
53
                    if ($obj) {
54
                        if (!isset($array[$obj->pilot])) {
55
                            $name = $obj->prenom . ' ' . $obj->nom;
56
                            $pilot = Pilot::create($name, $obj->pilot);
57
                            $array[$obj->pilot] = $pilot;
58
                        }
59
60
                        $array[$obj->pilot] = $array[$obj->pilot]->addCount(
61
                            new FlightTypeCount(
62
                                $obj->type,
63
                                $obj->nbr,
64
                                $this->getFactorByType($obj->type)
65
                            )
66
                        );
67
                    }
68
                    $i++;
69
                }
70
            }
71
        }
72
73
        if (!$query->isIncludeTotal()) {
74
            return $array;
75
        }
76
77
        //total orga
78
        $sql = 'SELECT llx_user.lastname as name , llx_user.firstname,llx_user.rowid, count(idBBC_vols) as total FROM llx_bbc_vols LEFT JOIN llx_user ON rowid = fk_organisateur WHERE YEAR(date) = \'' . $query->getFiscalYear() . '\' AND fk_type IN (1,2) GROUP BY fk_organisateur';
79
        $resql = $this->db->query($sql);
80 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...
81
            $num = $this->db->num_rows($resql);
82
            $i = 0;
83
            if ($num) {
84
                while ($i < $num) {
85
                    $obj = $this->db->fetch_object($resql); //vol
86
87
                    if ($obj) {
88
89
                        if (!isset($array[$obj->rowid])) {
90
                            $name = $obj->firstname . ' ' . $obj->name;
91
                            $pilot = Pilot::create($name, $obj->rowid);
92
                            $array[$obj->rowid] = $pilot;
93
                        }
94
95
                        $array[$obj->rowid] = $array[$obj->rowid]->addCount(
96
                            new FlightTypeCount(
97
                                'orga',
98
                                $obj->total,
99
                                $this->getFactorByType('orga')
100
                            )
101
                        );
102
                    }
103
                    $i++;
104
                }
105
            }
106
        }
107
108
        //total orga T6 - instructeur
109
        $sql = 'SELECT llx_user.lastname as name , llx_user.firstname,llx_user.rowid, count(idBBC_vols) as total FROM llx_bbc_vols LEFT JOIN llx_user ON rowid = fk_organisateur WHERE YEAR(date) = \'' . $query->getFiscalYear() . '\' AND fk_type = 6 GROUP BY fk_organisateur';
110
        $resql = $this->db->query($sql);
111 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...
112
            $num = $this->db->num_rows($resql);
113
            $i = 0;
114
            if ($num) {
115
                while ($i < $num) {
116
                    $obj = $this->db->fetch_object($resql); //vol
117
118
                    if ($obj) {
119
                        if (!isset($array[$obj->rowid])) {
120
                            $name = $obj->firstname . ' ' . $obj->name;
121
                            $pilot = Pilot::create($name, $obj->rowid);
122
                            $array[$obj->rowid] = $pilot;
123
                        }
124
125
                        $array[$obj->rowid] = $array[$obj->rowid]->addCount(
126
                            new FlightTypeCount(
127
                                'orga_T6',
128
                                $obj->total,
129
                                $this->getFactorByType('orga_T6')
130
                            )
131
                        );
132
                    }
133
                    $i++;
134
                }
135
            }
136
        }
137
138
        return $array;
139
    }
140
141
    /**
142
     * Returns the number of points if set in the config, if not return the price of the service.
143
     *
144
     * @param string $type
145
     *
146
     * @return int
147
     */
148
    private function getFactorByType($type)
149
    {
150
        switch ($type) {
151
            case 'orga':
152
                return $this->conf->BBC_POINTS_BONUS_ORGANISATOR;
153
            case 'orga_T6':
154
                return $this->conf->BBC_POINTS_BONUS_INSTRUCTOR;
155
        }
156
157
        $constVariableName = 'BBC_POINTS_BONUS_' . $type;
158
        if (!isset($this->conf->$constVariableName) || empty($this->conf->$constVariableName) || $this->conf->$constVariableName < 0) {
159
            return $this->getFactorForService($type);
160
        }
161
162
        return (int) $this->conf->$constVariableName;
163
164
    }
165
166
    /**
167
     * @param string $type
168
     *
169
     * @return float
170
     */
171
    private function getFactorForService($type)
172
    {
173
        $service = new Bbctypes($this->db);
174
        $fetchResult = $service->fetch($type);
175
176
        if ($fetchResult <= 0) {
177
            throw new \InvalidArgumentException('Service not found');
178
        }
179
180
        return $service->getService()->price_ttc;
181
    }
182
183
184
}