Completed
Pull Request — master (#10)
by Michael
03:18
created

index.php ➔ xfgb_genderlist()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
c 0
b 0
f 0
nc 4
nop 0
dl 0
loc 25
rs 8.5806
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 53 and the first side effect is on line 26.

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
//
3
//  ------------------------------------------------------------------------ //
4
//             XF Guestbook                                                  //
5
// ------------------------------------------------------------------------- //
6
//  This program is free software; you can redistribute it and/or modify     //
7
//  it under the terms of the GNU General Public License as published by     //
8
//  the Free Software Foundation; either version 2 of the License, or        //
9
//  (at your option) any later version.                                      //
10
//                                                                           //
11
//  You may not change or alter any portion of this comment or credits       //
12
//  of supporting developers from this source code or any supporting         //
13
//  source code which is considered copyrighted (c) material of the          //
14
//  original comment or credit authors.                                      //
15
//                                                                           //
16
//  This program is distributed in the hope that it will be useful,          //
17
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
18
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
19
//  GNU General Public License for more details.                             //
20
//                                                                           //
21
//  You should have received a copy of the GNU General Public License        //
22
//  along with this program; if not, write metalslugto the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//  ------------------------------------------------------------------------ //
25
26
include __DIR__ . '/../../mainfile.php';
27
//include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/msg.php");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/functions.php';
29 View Code Duplication
if (isset($_GET['msg_id'])) {
0 ignored issues
show
Duplication introduced by
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...
30
    $msg_id = (int)$_GET['msg_id'];
31
} elseif (isset($_POST['msg_id'])) {
32
    $msg_id = (int)$_POST['msg_id'];
33
} else {
34
    $msg_id = 0;
35
}
36
37 View Code Duplication
if (isset($_GET['op'])) {
0 ignored issues
show
Duplication introduced by
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...
38
    $op = $_GET['op'];
39
} elseif (isset($_POST['op'])) {
40
    $op = $_POST['op'];
41
} else {
42
    $op = 'show_all';
43
}
44
45
$msgHandler = xoops_getModuleHandler('msg');
46
47
//Admin or not
48
$xoopsUser ? $adminview = $xoopsUser->isAdmin() : $adminview = 0;
49
50
/**
51
 * @param $msg_id
52
 */
53
function delete($msg_id)
0 ignored issues
show
Best Practice introduced by
The function delete() has been defined more than once; this definition is ignored, only the first definition in admin/main.php (L55-77) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Coding Style introduced by
delete uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
54
{
55
    global $msgHandler, $xoopsModule;
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...
56
    $ok = isset($_POST['ok']) ? (int)$_POST['ok'] : 0;
57
    if ($ok == 1) {
58
        $msg        = $msgHandler->get($msg_id);
59
        $del_msg_ok = $msgHandler->delete($msg);
60
        $filename   = $msg->getVar('photo');
61 View Code Duplication
        if ($filename !== '') {
0 ignored issues
show
Duplication introduced by
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
            $filename = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname') . '/' . $filename;
63
            unlink($filename);
64
        }
65
        if ($del_msg_ok) {
66
            $messagesent = _MD_XFGB_MSGDELETED;
67
        } else {
68
            $messagesent = _MD_XFGB_ERRORDEL;
69
        }
70
        redirect_header('index.php', 2, $messagesent);
71
    } else {
72
        xoops_confirm(array('op' => 'delete', 'msg_id' => $msg_id, 'ok' => 1), 'index.php', _DELETE);
73
    }
74
}
75
76
/**
77
 * @param $msg_id
78
 */
79
function approve($msg_id)
0 ignored issues
show
Best Practice introduced by
The function approve() has been defined more than once; this definition is ignored, only the first definition in admin/main.php (L79-96) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
80
{
81
    global $msgHandler;
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...
82
83
    $msg = $msgHandler->get($msg_id);
84
    $msg->setVar('moderate', 0);
85
    if (!$msgHandler->insert($msg)) {
86
        $messagesent = _MD_XFGB_ERRORVALID;
87
    } else {
88
        $messagesent = _MD_XFGB_VALIDATE;
89
    }
90
    redirect_header('index.php?op=show_waiting', 2, $messagesent);
91
}
92
93
/**
94
 * @param $msg
95
 */
96
function xfgb_getmsg($msg)
97
{
98
    global $nbmsg, $xoopsModule, $xoopsUser, $xoopsModuleConfig, $xoopsTpl, $xoopsConfig, $options, $opt, $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...
99
100
    $arr_country = xfgb_getAllCountry();
101
    $xoopsTpl->assign('display_msg', true);
102
    foreach ($msg as $onemsg) {
103
        if ($poster = xfgb_get_user_data($onemsg->getVar('user_id'))) {
104
            $a_msg = &$poster;
105
        } else {
106
            $a_msg             = array();
107
            $a_msg['poster']   = $onemsg->getVar('uname');
108
            $a_msg['rank']     = '';
109
            $a_msg['rank_img'] = '';
110
            $a_msg['avatar']   = '';
111
        }
112
        $memberHandler = xoops_getHandler('member');
113
        $user          = $memberHandler->getUser($onemsg->getVar('user_id'));
114
        // email
115
        if ($xoopsModuleConfig['showemail']
116
            || ($onemsg->getVar('email')
117
                && (($user->getVar('user_viewemail') == 1
118
                     || $onemsg->getVar('user_id') == 0)
119
                    && is_object($xoopsUser)))
120
        ) {
121
            $a_msg['email'] = "<a href=\"javascript:openWithSelfMain('"
122
                              . XOOPS_URL
123
                              . '/modules/xfguestbook/contact.php?msg_id='
124
                              . $onemsg->getVar('msg_id')
125
                              . "', 'contact', 600, 450);\"><img src=\""
126
                              . XOOPS_URL
127
                              . "/images/icons/email.gif\" alt=\""
128
                              . _SENDEMAILTO
129
                              . "\" /></a>";
130
        }
131
        // url
132
        if ($onemsg->getVar('url')) {
133
            $a_msg['url'] = '<a href="'
134
                            . $onemsg->getVar('url')
135
                            . '" target="_blank"><img src="'
136
                            . XOOPS_URL
137
                            . '/images/icons/www.gif" alt="'
138
                            . _VISITWEBSITE
139
                            . '"></a>';
140
        }
141
        // gender
142
        if ($onemsg->getVar('gender') !== '') {
143
            $a_msg['gender'] = '<a href="index.php?op=show_gender&param='
144
                               . $onemsg->getVar('gender')
145
                               . '"><img src="assets/images/'
146
                               . $onemsg->getVar('gender')
147
                               . '.gif"</a>';
148
        }
149
        // flag
150
        if ($onemsg->getVar('country') !== '') {
151
            if ($onemsg->getVar('country') != 'other') {
152
                $flag = XOOPS_ROOT_PATH
153
                        . '/modules/'
154
                        . $xoopsModule->dirname()
155
                        . '/assets/images/flags/'
156
                        . $onemsg->getVar('flagdir')
157
                        . '/'
158
                        . $onemsg->getVar('country')
159
                        . '.gif';
160
                if (array_key_exists($onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country'), $arr_country)) {
161
                    $country_name = $arr_country[$onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country')];
162
                } else {
163
                    $country_name = '';
164
                }
165 View Code Duplication
                if (file_exists($flag)) {
0 ignored issues
show
Duplication introduced by
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...
166
                    $a_msg['country'] = "<img src=\""
167
                                        . XOOPS_URL
168
                                        . '/modules/xfguestbook/assets/images/flags/'
169
                                        . $onemsg->getVar('flagdir')
170
                                        . '/'
171
                                        . $onemsg->getVar('country')
172
                                        . ".gif\" alt=\""
173
                                        . $country_name
174
                                        . "\">";
175
                } else {
176
                    $a_msg['country'] = $country_name;
177
                }
178
                $a_msg['country'] = "<a href=\"index.php?op=show_country&param="
179
                                    . $onemsg->getVar('flagdir')
180
                                    . '/'
181
                                    . $onemsg->getVar('country')
182
                                    . "\">"
183
                                    . $a_msg['country']
184
                                    . '</a>';
185
            } else {
186
                $a_msg['country'] = $onemsg->getVar('other');
187
            }
188
        }
189
        $a_msg['msg_id']  = $onemsg->getVar('msg_id');
190
        $a_msg['i']       = $nbmsg;
191
        $a_msg['title']   = $onemsg->getVar('title');
192
        $a_msg['date']    = formatTimestamp($onemsg->getVar('post_time'), 's');
193
        $a_msg['message'] = $onemsg->getVar('message');
194
        if ($options['opt_url'] == 1) {
195
            $a_msg['message'] = str_replace('target="_blank"', 'target="_blank" rel="nofollow"', $a_msg['message']);
196
        }
197
        $a_msg['note_msg']  = $onemsg->getVar('note');
198
        $a_msg['poster_ip'] = $onemsg->getVar('poster_ip');
199
        $a_msg['moderate']  = $onemsg->getVar('moderate');
200
        if (isset($country_name)) {
201
            $a_msg['local'] = "<a href=\"index.php?op=show_country&param="
202
                              . $onemsg->getVar('flagdir')
203
                              . '/'
204
                              . $onemsg->getVar('country')
205
                              . "\">"
206
                              . $country_name
207
                              . '</a>';
208
        }
209
        $a_msg['photo'] = $onemsg->getVar('photo');
210
        $xoopsTpl->append('msg', $a_msg);
211
        $nbmsg--;
212
    }
213
}
214
215
function xfgb_genderlist()
216
{
217
    global $options, $xoopsTpl, $xoopsModuleConfig, $xoopsModule, $msgHandler;
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...
218
    $criteria = new Criteria('moderate', 0);
219
    $arr_msg  = $msgHandler->countMsgByGender($criteria);
220
    $i        = 0;
221
    foreach ($arr_msg as $k => $v) {
222
        if ($k === 'M') {
223
            $gender[$i] = _MD_XFGB_MALES . '<br>';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$gender was never initialized. Although not strictly required by PHP, it is generally a good practice to add $gender = 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...
224
            $gender[$i] .= '<img src="assets/images/M.gif" alt="' . _MD_XFGB_MALES . '"><br><br>';
0 ignored issues
show
Bug introduced by
The variable $gender 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...
225
            $gender[$i] .= '<a href="index.php?op=show_gender&param=M">' . $v . _MD_XFGB_MESSAGES . '</a>';
226
        } elseif ($k === 'F') {
227
            $gender[$i] = _MD_XFGB_FEMALES . '<br>';
228
            $gender[$i] .= '<img src="assets/images/F.gif" alt="' . _MD_XFGB_FEMALES . '"><br><br>';
229
            $gender[$i] .= '<a href="index.php?op=show_gender&param=F">' . $v . _MD_XFGB_MESSAGES . '</a>';
230
        } else {
231
            $gender[$i] = _MD_XFGB_UNKNOW2 . '<br>';
232
            $gender[$i] .= '<img src="assets/images/U.gif"><br><br>';
233
            $gender[$i] .= $v . _MD_XFGB_MESSAGES;
234
        }
235
        $i++;
236
    }
237
    $xoopsTpl->assign('gender', $gender);
238
    $xoopsTpl->assign('display_gender', $options['opt_gender']);
239
}
240
241
// end functions
242
243
// if op = show_***, functions needed
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
244
//if (substr($op, 0, 4) == 'show') {
245
if (0 === strpos($op, 'show')) {
246
    $debut = isset($_GET['debut']) ? (int)$_GET['debut'] : 0;
247
    $param = isset($_GET['param']) ? $_GET['param'] : '';
248
249
    include_once __DIR__ . '/include/functions.php';
250
    $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_index.tpl';
251
    include_once XOOPS_ROOT_PATH . '/header.php';
252
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
253
    include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/config.inc.php';
254
    $options = getOptions();
255
256
    $criteria = new Criteria('moderate', 0);
257
    $nbmsg    = $msgHandler->countMsg($criteria);
258
259
    $xoopsTpl->assign('msg_message_count', sprintf(_MD_XFGB_THEREIS, '<b>' . $nbmsg . '</b>'));
260
    $xoopsTpl->assign('msg_moderated', $xoopsModuleConfig['moderate']);
261
    $xoopsTpl->assign('msg_lang_name', $xoopsConfig['language']);
262
    $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name() . ' -messages');
263
    if ($adminview) {
264
        $nbwait = $msgHandler->countMsg(new Criteria('moderate', '1'));
265
        $xoopsTpl->assign('msg_moderate_text', sprintf(_MD_XFGB_MODERATING, "<font class='fg2'><a href='"
266
                                                                            . XOOPS_URL
267
                                                                            . "/modules/xfguestbook/index.php?op=show_waiting'>"
268
                                                                            . $nbwait
269
                                                                            . '</a></font>'));
270
    }
271
}
272
273
switch ($op) {
274 View Code Duplication
    case 'delete':
0 ignored issues
show
Duplication introduced by
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...
275
        if ($adminview) {
276
            include_once XOOPS_ROOT_PATH . '/header.php';
277
            delete($msg_id);
0 ignored issues
show
Unused Code introduced by
The call to delete() has too many arguments starting with $msg_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
278
        } else {
279
            redirect_header('index.php', 1, '');
280
        }
281
        break;
282
283 View Code Duplication
    case 'approve':
0 ignored issues
show
Duplication introduced by
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...
284
        if ($adminview) {
285
            include_once XOOPS_ROOT_PATH . '/header.php';
286
            approve($msg_id);
0 ignored issues
show
Unused Code introduced by
The call to approve() has too many arguments starting with $msg_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
287
        } else {
288
            redirect_header('index.php', 1, '');
289
        }
290
        break;
291
292
    case 'show_stat':
293
        if ($options['opt_gender'] > 0) {
294
            xfgb_genderlist();
295
        }
296
        break;
297
298 View Code Duplication
    case 'show_waiting':
0 ignored issues
show
Duplication introduced by
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...
299
        $pagenav = new XoopsPageNav($nbwait, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_waiting');
300
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
301
        $criteria = new Criteria('moderate', 1);
302
        $criteria->setOrder('DESC');
303
        $criteria->setLimit($xoopsModuleConfig['perpage']);
304
        $criteria->setStart($debut);
305
        $msg =& $msgHandler->getObjects($criteria);
306
        $nbwait -= $debut;
307
        $nbmsg = $nbwait;
308
        xfgb_getmsg($msg);
309
        break;
310
311
    case 'show_one':
312
        if ($adminview) {
313
            $criteria = new Criteria('msg_id', $msg_id);
314
        } else {
315
            $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
316
            $criteria->add(new Criteria('msg_id', $msg_id));
317
        }
318
        $msg =& $msgHandler->getObjects($criteria);
319
        xfgb_getmsg($msg);
320
        if ($options['opt_gender'] > 0) {
321
            xfgb_genderlist();
322
        }
323
        break;
324
325
    case 'show_country':
326
        list($flagdir, $country) = explode('/', $param);
327
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
328
        if ($flagdir == $xoopsModuleConfig['flagdir']) {
329
            $criteria->add(new Criteria('flagdir', $flagdir));
330
        }
331
        $criteria->add(new Criteria('country', $country));
332
        $nbmsg   = $msgHandler->countMsg($criteria);
333
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_country&param=' . $param);
334
        $criteria->setOrder('DESC');
335
        $criteria->setLimit($xoopsModuleConfig['perpage']);
336
        $criteria->setStart($debut);
337
        $msg =& $msgHandler->getObjects($criteria);
338
        $nbmsg -= $debut;
339
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
340
        xfgb_getmsg($msg);
341
        break;
342
343
    case 'show_gender':
344
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
345
        $criteria->add(new Criteria('gender', $param));
346
        $nbmsg   = $msgHandler->countMsg($criteria);
347
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_gender&param=' . $param);
348
        $criteria->setOrder('DESC');
349
        $criteria->setLimit($xoopsModuleConfig['perpage']);
350
        $criteria->setStart($debut);
351
        $msg =& $msgHandler->getObjects($criteria);
352
        $nbmsg -= $debut;
353
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
354
        xfgb_getmsg($msg);
355
        if ($options['opt_gender'] > 0) {
356
            xfgb_genderlist();
357
        }
358
        break;
359
360
    case 'show_all':
361 View Code Duplication
    default:
0 ignored issues
show
Duplication introduced by
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...
362
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', '');
363
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
364
        $criteria = new Criteria('moderate', 0);
365
        $criteria->setOrder('DESC');
366
        $criteria->setLimit($xoopsModuleConfig['perpage']);
367
        $criteria->setStart($debut);
368
        $msg =& $msgHandler->getObjects($criteria);
369
        $nbmsg -= $debut;
370
        xfgb_getmsg($msg);
371
        if ($options['opt_gender'] > 0) {
372
            xfgb_genderlist();
373
        }
374
        break;
375
376 View Code Duplication
    case 'cancel':
0 ignored issues
show
Duplication introduced by
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...
377
        $photos_dir     = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
378
        $nb_removed_tmp = xfgb_clear_tmp_files($photos_dir);
379
        redirect_header('index.php', 0);
380
        break;
381
}
382
$sql = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country') . ' ORDER BY country_name ASC');
383
384
while ($coun = $xoopsDB->fetchArray($sql)) {
385
    $sql2 = $xoopsDB->query('SELECT COUNT(country) tot FROM '
386
                            . $xoopsDB->prefix('xfguestbook_msg')
387
                            . " WHERE country='"
388
                            . $coun['country_code']
389
                            . "'");
390
    list($tlocal) = $xoopsDB->fetchRow($sql2);
391
    $tlocal = $tlocal ?: '0';
392
    if ($tlocal > 0) {
393
        $opt["<a href=\"index.php?op=show_country&param="
394
             . $xoopsModuleConfig['flagdir']
395
             . '/'
396
             . $coun['country_code']
397
             . "\">"
398
             . $coun['country_name']
399
             . '</a>'] = $tlocal;
400
    } else {
401
        $opt[$coun['country_name']] = $tlocal;
402
    }
403
}
404
$xoopsTpl->assign('country_l', $opt);
405
406
include XOOPS_ROOT_PATH . '/footer.php';
407