1
|
|
|
<?php |
2
|
|
|
// $Id: navegacao.php,v 1.6 2007/03/24 17:50:52 marcellobrandao Exp $ |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// XOOPS - PHP Content Management System // |
5
|
|
|
// Copyright (c) 2000 XOOPS.org // |
6
|
|
|
// <http://www.xoops.org/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
// // |
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// // |
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21
|
|
|
// GNU General Public License for more details. // |
22
|
|
|
// // |
23
|
|
|
// You should have received a copy of the GNU General Public License // |
24
|
|
|
// along with this program; if not, write to the Free Software // |
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class NavegadorProva |
31
|
|
|
*/ |
32
|
|
|
class NavegadorProva extends XoopsPageNav |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Create navigation with images |
36
|
|
|
* |
37
|
|
|
* @param int $cod_perguntas |
38
|
|
|
* @param $cod_perguntas_respondidas |
39
|
|
|
* @param integer $offset |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function renderImageNav($cod_perguntas = null, $cod_perguntas_respondidas = null, $offset = 1) |
44
|
|
|
{ |
45
|
|
|
global $xoopsModule; |
46
|
|
|
$vazio = array(); |
47
|
|
|
$largura = 50 * $offset; |
48
|
|
|
$perguntas = @array_merge($perguntas, $vazio); |
|
|
|
|
49
|
|
|
if ($this->total < $this->perpage) { |
50
|
|
|
return null; |
51
|
|
|
} |
52
|
|
|
$total_pages = ceil($this->total / $this->perpage); |
53
|
|
|
|
54
|
|
|
if ($total_pages > 1) { |
55
|
|
|
$ret = '<table align="center" style="width:' . $largura . 'px;"><tr>'; |
56
|
|
|
|
57
|
|
|
$prev = $this->current - $this->perpage; |
58
|
|
|
if ($prev >= 0) { |
59
|
|
|
$ret .= '<td align="right"><a href="' . $this->url . $prev . $this->extra . '"> |
60
|
|
|
<img src="assets/images/anterior.gif" border="0" alt="' . _MA_ASSESSMENT_ANTERIOR . '" title="' . _MA_ASSESSMENT_ANTERIOR . '"></a></td> '; |
61
|
|
|
} |
62
|
|
|
$ret .= '<td align="center"><table><tr>'; |
63
|
|
|
$next = $this->current + $this->perpage; |
64
|
|
|
|
65
|
|
|
$counter = 1; |
66
|
|
|
$current_page = (int)floor(($this->current + $this->perpage) / $this->perpage); |
67
|
|
|
while ($counter <= $total_pages) { |
68
|
|
|
$cod_pergunta_atual = $cod_perguntas[$counter - 1]; |
69
|
|
|
|
70
|
|
|
if (in_array($cod_pergunta_atual, $cod_perguntas_respondidas)) { |
71
|
|
|
$ret .= '<td valign="center" style="height=20px; text-align:center; background:url(assets/images/feita.jpg); background-repeat:no-repeat;background-position:center;"> |
72
|
|
|
<a rel="sad" href="' |
73
|
|
|
. $this->url |
74
|
|
|
. (($counter - 1) * $this->perpage) |
75
|
|
|
. $this->extra |
76
|
|
|
. '">' |
77
|
|
|
. $counter |
78
|
|
|
. '</a></td>'; |
79
|
|
|
} else { |
80
|
|
|
$ret .= '<td valign="center" style="height=20px; text-align:center; background:url(assets/images/naofeita.jpg); background-repeat:no-repeat;background-position:center;"> |
81
|
|
|
<a href="' |
82
|
|
|
. $this->url |
83
|
|
|
. (($counter - 1) * $this->perpage) |
84
|
|
|
. $this->extra |
85
|
|
|
. '">' |
86
|
|
|
. $counter |
87
|
|
|
. '</a></td>'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ((($counter % $offset) == 0) & $counter != $total_pages - 1) { |
91
|
|
|
$ret .= '</tr><tr>'; |
92
|
|
|
} |
93
|
|
|
++$counter; |
94
|
|
|
} |
95
|
|
|
$ret .= '</tr></table></td>'; |
96
|
|
|
if ($this->total > $next) { |
97
|
|
|
$ret .= '<td valign="middle"><a href="' . $this->url . $next . $this->extra . '"><img src="assets/images/proximo.gif" border="0" alt="' . _MA_ASSESSMENT_PROXIMO . '" title="' . _MA_ASSESSMENT_PROXIMO . '"></a></td>'; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$ret .= '</tr></table>'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $ret; |
|
|
|
|
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
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.