Issues (379)

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.

class/assessment_provas.php (50 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 36 and the first side effect is on line 29.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
// assessment_provas.php,v 1
3
// $Id: assessment_provas.php,v 1.11 2007/03/24 20:08:53 marcellobrandao Exp $
4
//  ------------------------------------------------------------------------ //
5
//                XOOPS - PHP Content Management System                      //
6
//                    Copyright (c) 2000 XOOPS.org                           //
7
//                       <http://www.xoops.org/>                             //
8
//  ------------------------------------------------------------------------ //
9
//  This program is free software; you can redistribute it and/or modify     //
10
//  it under the terms of the GNU General Public License as published by     //
11
//  the Free Software Foundation; either version 2 of the License, or        //
12
//  (at your option) any later version.                                      //
13
//                                                                           //
14
//  You may not change or alter any portion of this comment or credits       //
15
//  of supporting developers from this source code or any supporting         //
16
//  source code which is considered copyrighted (c) material of the          //
17
//  original comment or credit authors.                                      //
18
//                                                                           //
19
//  This program is distributed in the hope that it will be useful,          //
20
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
21
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
22
//  GNU General Public License for more details.                             //
23
//                                                                           //
24
//  You should have received a copy of the GNU General Public License        //
25
//  along with this program; if not, write to the Free Software              //
26
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
27
//  ------------------------------------------------------------------------ //
28
29
include_once XOOPS_ROOT_PATH . '/kernel/object.php';
30
31
/**
32
 * assessment_provas class.
33
 * $this class is responsible for providing data access mechanisms to the data source
34
 * of XOOPS user class objects.
35
 */
36
class assessment_provas extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
37
{
38
    public $db;
39
40
    // constructor
41
42
    /**
43
     * @param null $id
44
     * @return assessment_provas
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
45
     */
46
    public function __construct($id = null)
47
    {
48
        $this->db = XoopsDatabaseFactory::getDatabaseConnection();
49
        $this->initVar('cod_prova', XOBJ_DTYPE_INT, null, false, 10);
50
        $this->initVar('data_criacao', XOBJ_DTYPE_TXTBOX, '2017-01-01', false);
51
        $this->initVar('data_update', XOBJ_DTYPE_TXTBOX, '2017-01-01', false);
52
        $this->initVar('titulo', XOBJ_DTYPE_TXTBOX, null, false);
53
        $this->initVar('descricao', XOBJ_DTYPE_TXTBOX, null, false);
54
        $this->initVar('instrucoes', XOBJ_DTYPE_TXTBOX, null, false);
55
        $this->initVar('acesso', XOBJ_DTYPE_TXTBOX, null, false);
56
        $this->initVar('tempo', XOBJ_DTYPE_TXTBOX, null, false);
57
        $this->initVar('uid_elaboradores', XOBJ_DTYPE_TXTBOX, null, false);
58
        $this->initVar('data_inicio', XOBJ_DTYPE_TXTBOX, null, false);
59
        $this->initVar('data_fim', XOBJ_DTYPE_TXTBOX, null, false);
60 View Code Duplication
        if (!empty($id)) {
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...
61
            if (is_array($id)) {
62
                $this->assignVars($id);
63
            } else {
64
                $this->load((int)$id);
65
            }
66
        } else {
67
            $this->setNew();
68
        }
69
    }
70
71
    /**
72
     * @param $id
73
     */
74 View Code Duplication
    public function load($id)
0 ignored issues
show
This method seems to be duplicated in 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...
75
    {
76
        $sql   = 'SELECT * FROM ' . $this->db->prefix('assessment_provas') . ' WHERE cod_prova=' . $id;
77
        $myrow = $this->db->fetchArray($this->db->query($sql));
78
        $this->assignVars($myrow);
79
        if (!$myrow) {
80
            $this->setNew();
81
        }
82
    }
83
84
    /**
85
     * @param array  $criteria
86
     * @param bool   $asobject
87
     * @param string $sort
88
     * @param string $order
89
     * @param int    $limit
90
     * @param int    $start
91
     *
92
     * @return array
93
     */
94 View Code Duplication
    public function getAllassessment_provass($criteria = array(), $asobject = false, $sort = 'cod_prova', $order = 'ASC', $limit = 0, $start = 0)
0 ignored issues
show
This method seems to be duplicated in 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...
95
    {
96
        $db          = XoopsDatabaseFactory::getDatabaseConnection();
97
        $ret         = array();
98
        $where_query = '';
99
        if (is_array($criteria) && count($criteria) > 0) {
100
            $where_query = ' WHERE';
101
            foreach ($criteria as $c) {
102
                $where_query .= " $c AND";
103
            }
104
            $where_query = substr($where_query, 0, -4);
105
        } elseif (!is_array($criteria) && $criteria) {
106
            $where_query = ' WHERE ' . $criteria;
107
        }
108
        if (!$asobject) {
109
            $sql    = 'SELECT cod_prova FROM ' . $db->prefix('assessment_provas') . "$where_query ORDER BY $sort $order";
110
            $result = $db->query($sql, $limit, $start);
111
            while ($myrow = $db->fetchArray($result)) {
112
                $ret[] = $myrow['assessment_provas_id'];
113
            }
114
        } else {
115
            $sql    = 'SELECT * FROM ' . $db->prefix('assessment_provas') . "$where_query ORDER BY $sort $order";
116
            $result = $db->query($sql, $limit, $start);
117
            while ($myrow = $db->fetchArray($result)) {
118
                $ret[] = new assessment_provas($myrow);
119
            }
120
        }
121
122
        return $ret;
123
    }
124
125
    /**
126
     * Verifica se aluno pode acessar esta prova
127
     *
128
     * @param object member $aluno
129
     *
130
     * @return bool true se autorizado e false se n�o autorizado
131
     */
132
    public function isAutorizado($aluno = null)
133
    {
134
        global $xoopsUser, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
135
        if ($aluno == null) {
136
            $aluno = $xoopsUser;
137
        }
138
        $acesso    = $this->getVar('acesso', 'n');
139
        $acesso    = explode(',', $acesso);
140
        $grupos    = $aluno->getGroups();
141
        $intersect = array_intersect($acesso, $grupos);
142
        if (!(count($intersect) > 0)) {
143
            return false;
144
        }
145
146
        $inicio            = $this->getVar('data_inicio', 'n');
147
        $fabrica_de_provas = new Xoopsassessment_provasHandler($xoopsDB);
148
        if ($fabrica_de_provas->dataMysql2dataUnix($inicio) > time()) {
149
            return false;
150
        }
151
152
        return true;
153
    }
154
155
    /**
156
     * Verifica se aluno pode acessar esta prova
157
     *
158
     * @param vetorgrupos
159
     *
160
     * @return bool true se autorizado e false se n�o autorizado
161
     */
162
    public function isAutorizado2($grupos)
163
    {
164
        global $xoopsUser, $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
165
166
        $acesso    = $this->getVar('acesso', 'n');
167
        $acesso    = explode(',', $acesso);
168
        $intersect = array_intersect($acesso, $grupos);
169
        if (!(count($intersect) > 0)) {
170
            return false;
171
        }
172
173
        $inicio            = $this->getVar('data_inicio', 'n');
174
        $fabrica_de_provas = new Xoopsassessment_provasHandler($xoopsDB);
175
        if ($fabrica_de_provas->dataMysql2dataUnix($inicio) > time()) {
176
            return false;
177
        }
178
179
        return true;
180
    }
181
}
182
183
// -------------------------------------------------------------------------
184
// ------------------assessment_provas user handler class -------------------
185
// -------------------------------------------------------------------------
186
187
/**
188
 * assessment_provashandler class.
189
 * This class provides simple mecanisme for assessment_provas object
190
 */
191
class Xoopsassessment_provasHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
192
{
193
    /**
194
     * create a new assessment_provas
195
     *
196
     * @param bool $isNew flag the new objects as "new"?
197
     *
198
     * @return object assessment_provas
199
     */
200
    public function &create($isNew = true)
201
    {
202
        $assessment_provas = new assessment_provas();
203
        if ($isNew) {
204
            $assessment_provas->setNew();
205
        } //hack consertando
206
        else {
207
            $assessment_provas->unsetNew();
208
        }
209
210
        //fim do hack para consertar
211
        return $assessment_provas;
212
    }
213
214
    /**
215
     * retrieve a assessment_provas
216
     *
217
     * @param  mixed $id     ID
218
     * @param  array $fields fields to fetch
0 ignored issues
show
Should the type for parameter $fields not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
219
     * @return XoopsObject {@link XoopsObject}
0 ignored issues
show
Should the return type not be false|assessment_provas?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
220
     */
221 View Code Duplication
    public function get($id = null, $fields = null)
0 ignored issues
show
This method seems to be duplicated in 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...
222
    {
223
        $sql = 'SELECT * FROM ' . $this->db->prefix('assessment_provas') . ' WHERE cod_prova=' . $id;
224
        if (!$result = $this->db->query($sql)) {
225
            return false;
226
        }
227
        $numrows = $this->db->getRowsNum($result);
228
        if ($numrows == 1) {
229
            $assessment_provas = new assessment_provas();
230
            $assessment_provas->assignVars($this->db->fetchArray($result));
231
232
            return $assessment_provas;
233
        }
234
235
        return false;
236
    }
237
238
    /**
239
     * insert a new assessment_provas in the database
240
     *
241
     * @param XoopsObject $assessment_provas reference to the {@link assessment_provas} object
242
     * @param bool        $force
243
     *
244
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
245
     */
246
    public function insert(XoopsObject $assessment_provas, $force = false)
247
    {
248
        global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
249
        if (get_class($assessment_provas) != 'assessment_provas') {
250
            return false;
251
        }
252
        if (!$assessment_provas->isDirty()) {
253
            return true;
254
        }
255
        if (!$assessment_provas->cleanVars()) {
256
            return false;
257
        }
258
        foreach ($assessment_provas->cleanVars as $k => $v) {
259
            ${$k} = $v;
260
        }
261
        $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)';
0 ignored issues
show
$now is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
262
        if ($assessment_provas->isNew()) {
263
            // ajout/modification d'un assessment_provas
264
            $assessment_provas = new assessment_provas();
265
            $format            = 'INSERT INTO %s (cod_prova, data_criacao, data_update, titulo, descricao, instrucoes, acesso, tempo, uid_elaboradores, data_inicio, data_fim)';
266
            $format            .= 'VALUES (%u, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)';
267
            $sql               = sprintf($format, $this->db->prefix('assessment_provas'), $cod_prova, $this->db->quoteString($data_criacao), $this->db->quoteString($data_update), $this->db->quoteString($titulo), $this->db->quoteString($descricao),
0 ignored issues
show
The variable $cod_prova seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
The variable $data_criacao does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $data_update does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $titulo does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $descricao does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
268
                                         $this->db->quoteString($instrucoes), $this->db->quoteString($acesso), $this->db->quoteString($tempo), $this->db->quoteString($uid_elaboradores), $this->db->quoteString($data_inicio),
0 ignored issues
show
The variable $instrucoes does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $acesso does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $tempo does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $uid_elaboradores does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $data_inicio does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
269
                                         $this->db->quoteString($data_fim));
0 ignored issues
show
The variable $data_fim does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
270
            $force             = true;
271
        } else {
272
            $format = 'UPDATE %s SET ';
273
            $format .= 'cod_prova=%u, data_criacao=%s, data_update=%s, titulo=%s, descricao=%s, instrucoes=%s, acesso=%s, tempo=%s, uid_elaboradores=%s, data_inicio=%s, data_fim=%s';
274
            $format .= ' WHERE cod_prova = %u';
275
            $sql    = sprintf($format, $this->db->prefix('assessment_provas'), $cod_prova, $this->db->quoteString($data_criacao), $this->db->quoteString($data_update), $this->db->quoteString($titulo), $this->db->quoteString($descricao),
0 ignored issues
show
The variable $cod_prova seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
276
                              $this->db->quoteString($instrucoes), $this->db->quoteString($acesso), $this->db->quoteString($tempo), $this->db->quoteString($uid_elaboradores), $this->db->quoteString($data_inicio), $this->db->quoteString($data_fim),
277
                              $cod_prova);
0 ignored issues
show
The variable $cod_prova seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
278
        }
279
        if (false != $force) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
280
            $result = $this->db->queryF($sql);
281
        } else {
282
            $result = $this->db->query($sql);
283
        }
284
        if (!$result) {
285
            return false;
286
        }
287
        if (empty($cod_prova)) {
0 ignored issues
show
The variable $cod_prova seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
288
            $cod_prova = $this->db->getInsertId();
289
        }
290
        $assessment_provas->assignVar('cod_prova', $cod_prova);
291
292
        return true;
293
    }
294
295
    /**
296
     * delete a assessment_provas from the database
297
     *
298
     * @param XoopsObject $assessment_provas reference to the assessment_provas to delete
299
     * @param bool        $force
300
     *
301
     * @return bool FALSE if failed.
302
     */
303 View Code Duplication
    public function delete(XoopsObject $assessment_provas, $force = false)
0 ignored issues
show
This method seems to be duplicated in 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...
304
    {
305
        if (get_class($assessment_provas) != 'assessment_provas') {
306
            return false;
307
        }
308
        $sql = sprintf('DELETE FROM %s WHERE cod_prova = %u', $this->db->prefix('assessment_provas'), $assessment_provas->getVar('cod_prova'));
309
        if (false != $force) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
310
            $result = $this->db->queryF($sql);
311
        } else {
312
            $result = $this->db->query($sql);
313
        }
314
        if (!$result) {
315
            return false;
316
        }
317
318
        return true;
319
    }
320
321
    /**
322
     * @param $cod_prova
323
     */
324
    public function clonarProva($cod_prova)
325
    {
326
        $prova = $this->get($cod_prova);
327
328
        $prova->setVar('titulo', _AM_ASSESSMENT_CLONE . $prova->getVar('titulo'));
329
        $prova->setVar('cod_prova', 0);
330
        $prova->setNew();
331
        $this->insert($prova);
332
    }
333
334
    /**
335
     * retrieve assessment_provass from the database
336
     *
337
     * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
0 ignored issues
show
Should the type for parameter $criteria not be null|CriteriaElement?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
338
     * @param bool            $id_as_key use the UID as key for the array?
339
     *
340
     * @param bool            $as_object
341
     * @return array array of <a href='psi_element://assessment_perguntas'>assessment_perguntas</a> objects
342
     *                                   objects
343
     */
344 View Code Duplication
    public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true)
0 ignored issues
show
This method seems to be duplicated in 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...
345
    {
346
        $ret   = array();
347
        $limit = $start = 0;
348
        $sql   = 'SELECT * FROM ' . $this->db->prefix('assessment_provas');
349
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
350
            $sql .= ' ' . $criteria->renderWhere();
351
            if ($criteria->getSort() != '') {
352
                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
353
            }
354
            $limit = $criteria->getLimit();
355
            $start = $criteria->getStart();
356
        }
357
        $result = $this->db->query($sql, $limit, $start);
358
        if (!$result) {
359
            return $ret;
360
        }
361
        while ($myrow = $this->db->fetchArray($result)) {
362
            $assessment_provas = new assessment_provas();
363
            $assessment_provas->assignVars($myrow);
364
            if (!$id_as_key) {
365
                $ret[] =& $assessment_provas;
366
            } else {
367
                $ret[$myrow['cod_prova']] = $assessment_provas;
368
            }
369
            unset($assessment_provas);
370
        }
371
372
        return $ret;
373
    }
374
375
    /**
376
     * count assessment_provass matching a condition
377
     *
378
     * @param CriteriaElement $criteria {@link CriteriaElement} to match
0 ignored issues
show
Should the type for parameter $criteria not be null|CriteriaElement?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
379
     *
380
     * @return int count of assessment_provass
381
     */
382 View Code Duplication
    public function getCount(CriteriaElement $criteria = null)
0 ignored issues
show
This method seems to be duplicated in 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...
383
    {
384
        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('assessment_provas');
385
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
386
            $sql .= ' ' . $criteria->renderWhere();
387
        }
388
        $result = $this->db->query($sql);
389
        if (!$result) {
390
            return 0;
391
        }
392
        list($count) = $this->db->fetchRow($result);
393
394
        return $count;
395
    }
396
397
    /**
398
     * delete assessment_provass matching a set of conditions
399
     *
400
     * @param CriteriaElement $criteria {@link CriteriaElement}
0 ignored issues
show
Should the type for parameter $criteria not be null|CriteriaElement?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
401
     *
402
     * @param bool            $force
403
     * @param bool            $asObject
404
     * @return bool FALSE if deletion failed
405
     */
406 View Code Duplication
    public function deleteAll(CriteriaElement $criteria = null, $force = true, $asObject = false)
0 ignored issues
show
This method seems to be duplicated in 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...
407
    {
408
        $sql = 'DELETE FROM ' . $this->db->prefix('assessment_provas');
409
        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of returns inconsistent results on some PHP versions for interfaces; you could instead use ReflectionClass::implementsInterface.
Loading history...
410
            $sql .= ' ' . $criteria->renderWhere();
411
        }
412
        if (!$result = $this->db->query($sql)) {
413
            return false;
414
        }
415
416
        return true;
417
    }
418
419
    /**
420
     * cria form de inser��o e edi��o de pergunta
421
     *
422
     * @param string $action caminho para arquivo que ...
423
     * @return bool FALSE if deletion failed
424
     * @internal param object $assessment_perguntas <a href='psi_element://assessment_perguntas'>assessment_perguntas</a>
425
     *
426
     */
427
    public function renderFormCadastrar($action)
428
    {
429
        $form             = new XoopsThemeForm(_AM_ASSESSMENT_CADASTRAR . ' ' . _AM_ASSESSMENT_PROVA, 'form_prova', $action, 'post', true);
430
        $campo_titulo     = new XoopsFormTextArea(_AM_ASSESSMENT_TITULO, 'campo_titulo', '', 2, 50);
431
        $campo_descricao  = new XoopsFormTextArea(_AM_ASSESSMENT_DESCRICAO, 'campo_descricao', '', 2, 50);
432
        $campo_instrucoes = new XoopsFormTextArea(_AM_ASSESSMENT_INSTRUCOES, 'campo_instrucoes', '', 2, 50);
433
        $campo_tempo      = new XoopsFormText(_AM_ASSESSMENT_TEMPO, 'campo_tempo', 10, 20);
434
435
        $campo_acesso      = new XoopsFormSelectGroup(_AM_ASSESSMENT_GRUPOSACESSO, 'campo_grupo', false, null, 4, true);
436
        $botao_enviar      = new XoopsFormButton(_AM_ASSESSMENT_CADASTRAR, 'botao_submit', _SUBMIT, 'submit');
437
        $campo_data_inicio = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_INICIO, 'campo_data_inicio');
438
        $campo_data_fim    = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_FIM, 'campo_data_fim');
439
        $form->addElement($campo_titulo, true);
440
        $form->addElement($campo_descricao, true);
441
        $form->addElement($campo_instrucoes, true);
442
        $form->addElement($campo_tempo, true);
443
444
        $form->addElement($campo_data_inicio, true);
445
        $form->addElement($campo_data_fim, true);
446
        $form->addElement($campo_acesso, true);
447
        $form->addElement($botao_enviar);
448
        $form->display();
449
450
        return true;
451
    }
452
453
    /**
454
     * cria form de inser��o e edi��o de pergunta
455
     *
456
     * @param string $action caminho para arquivo que ...
457
     * @param        $prova
458
     * @return bool FALSE if deletion failed
459
     * @internal param object $assessment_perguntas <a href='psi_element://assessment_perguntas'>assessment_perguntas</a>
460
     *
461
     */
462
    public function renderFormEditar($action, $prova)
463
    {
464
        $cod_prova  = $prova->getVar('cod_prova');
465
        $titulo     = $prova->getVar('titulo');
466
        $descricao  = $prova->getVar('descricao');
467
        $instrucoes = $prova->getVar('instrucoes');
468
        $acessos    = explode(',', $prova->getVar('acesso'));
469
        $tempo      = $prova->getVar('tempo');
470
        $inicio     = $this->dataMysql2dataUnix($prova->getVar('data_inicio'));
471
        $fim        = $this->dataMysql2dataUnix($prova->getVar('data_fim'));
472
473
        $form              = new XoopsThemeForm(_AM_ASSESSMENT_EDITAR . ' ' . _AM_ASSESSMENT_PROVA, 'form_prova', $action, 'post', true);
474
        $campo_titulo      = new XoopsFormTextArea(_AM_ASSESSMENT_TITULO, 'campo_titulo', $titulo, 2, 50);
475
        $campo_descricao   = new XoopsFormTextArea(_AM_ASSESSMENT_DESCRICAO, 'campo_descricao', $descricao, 2, 50);
476
        $campo_instrucoes  = new XoopsFormTextArea(_AM_ASSESSMENT_INSTRUCOES, 'campo_instrucoes', $instrucoes, 2, 50);
477
        $campo_tempo       = new XoopsFormText(_AM_ASSESSMENT_TEMPO, 'campo_tempo', 10, 20, $tempo);
478
        $campo_acesso      = new XoopsFormSelectGroup(_AM_ASSESSMENT_GRUPOSACESSO, 'campo_grupo', false, $acessos, 4, true);
479
        $campo_cod_prova   = new XoopsFormHidden('campo_cod_prova', $cod_prova);
480
        $campo_data_inicio = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_INICIO, 'campo_data_inicio', null, $inicio);
481
        $campo_data_fim    = new XoopsFormDateTime(_AM_ASSESSMENT_DATA_FIM, 'campo_data_fim', null, $fim);
482
        $botao_enviar      = new XoopsFormButton('', 'botao_submit', _AM_ASSESSMENT_SALVARALTERACOES, 'submit');
483
        $form->addElement($campo_titulo, true);
484
        $form->addElement($campo_descricao, true);
485
        $form->addElement($campo_instrucoes, true);
486
        $form->addElement($campo_cod_prova, true);
487
488
        $form->addElement($campo_tempo, true);
489
        $form->addElement($campo_data_inicio, true);
490
        $form->addElement($campo_data_fim, true);
491
        $form->addElement($campo_acesso, true);
492
        $form->addElement($botao_enviar);
493
        $form->display();
494
495
        return true;
496
    }
497
498
    /**
499
     * @param $db
500
     *
501
     * @return mixed
502
     */
503
    public function pegarultimocodigo(&$db)
504
    {
505
        return $db->getInsertId();
506
    }
507
508
    /**
509
     * @param $dataMYSQL
510
     *
511
     * @return int
512
     */
513
    public function dataMysql2dataUnix($dataMYSQL)
514
    {
515
        $d  = @explode(' ', $dataMYSQL, 2);
516
        $t  = @explode(':', $d[1], 3);
517
        $d  = @explode('-', $d[0], 3);
518
        $ts = @mktime($t[0], $t[1], $t[2], $d[1], $d[2], $d[0]);
519
520
        return $ts;
521
    }
522
523
    /**
524
     * @param        $total_segundos
525
     * @param string $inicio
526
     *
527
     * @return mixed
528
     */
529
    public function converte_segundos($total_segundos, $inicio = 'Y')
530
    {
531
        /**
532
         * @autor: Carlos H. Reche
533
         * @data : 11/08/2004
534
         */
535
536
        $comecou = false;
537
538
        if ($inicio == 'Y') {
539
            $array['anos']  = floor($total_segundos / (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH * 12));
0 ignored issues
show
Coding Style Comprehensibility introduced by
$array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $array = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
540
            $total_segundos = ($total_segundos % (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH * 12));
541
            $comecou        = true;
542
        }
543
        if (($inicio == 'm') || ($comecou == true)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
544
            $array['meses'] = floor($total_segundos / (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH));
0 ignored issues
show
The variable $array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
545
            $total_segundos = ($total_segundos % (60 * 60 * 24 * _AM_ASSESSMENT_DAYS_PER_MONTH));
546
            $comecou        = true;
547
        }
548 View Code Duplication
        if (($inicio == 'd') || ($comecou == true)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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...
549
            $array['dias']  = floor($total_segundos / (60 * 60 * 24));
550
            $total_segundos = ($total_segundos % (60 * 60 * 24));
551
            $comecou        = true;
552
        }
553 View Code Duplication
        if (($inicio == 'H') || ($comecou == true)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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...
554
            $array['horas'] = floor($total_segundos / (60 * 60));
555
            $total_segundos = ($total_segundos % (60 * 60));
556
            $comecou        = true;
557
        }
558
        if (($inicio == 'i') || ($comecou == true)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
559
            $array['minutos'] = floor($total_segundos / 60);
560
            $total_segundos   = ($total_segundos % 60);
561
            $comecou          = true;
0 ignored issues
show
$comecou is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
562
        }
563
        $array['segundos'] = $total_segundos;
564
565
        return $array;
566
    }
567
}
568