Completed
Pull Request — master (#10)
by Michael
01:59
created

index.php (23 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 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
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
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
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...
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
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(['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
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             = [];
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="' . $onemsg->getVar('url') . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" alt="' . _VISITWEBSITE . '"></a>';
134
        }
135
        // gender
136
        if ($onemsg->getVar('gender') !== '') {
137
            $a_msg['gender'] = '<a href="index.php?op=show_gender&param=' . $onemsg->getVar('gender') . '"><img src="assets/images/' . $onemsg->getVar('gender') . '.gif"</a>';
138
        }
139
        // flag
140
        if ($onemsg->getVar('country') !== '') {
141
            if ($onemsg->getVar('country') !== 'other') {
142
                $flag = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country') . '.gif';
143
                if (array_key_exists($onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country'), $arr_country)) {
144
                    $country_name = $arr_country[$onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country')];
145
                } else {
146
                    $country_name = '';
147
                }
148 View Code Duplication
                if (file_exists($flag)) {
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...
149
                    $a_msg['country'] = '<img src="'
150
                                        . XOOPS_URL
151
                                        . '/modules/xfguestbook/assets/images/flags/'
152
                                        . $onemsg->getVar('flagdir')
153
                                        . '/'
154
                                        . $onemsg->getVar('country')
155
                                        . '.gif" alt="'
156
                                        . $country_name
157
                                        . '">';
158
                } else {
159
                    $a_msg['country'] = $country_name;
160
                }
161
                $a_msg['country'] = '<a href="index.php?op=show_country&param=' . $onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country') . '">' . $a_msg['country'] . '</a>';
162
            } else {
163
                $a_msg['country'] = $onemsg->getVar('other');
164
            }
165
        }
166
        $a_msg['msg_id']  = $onemsg->getVar('msg_id');
167
        $a_msg['i']       = $nbmsg;
168
        $a_msg['title']   = $onemsg->getVar('title');
169
        $a_msg['date']    = formatTimestamp($onemsg->getVar('post_time'), 's');
170
        $a_msg['message'] = $onemsg->getVar('message');
171
        if ($options['opt_url'] == 1) {
172
            $a_msg['message'] = str_replace('target="_blank"', 'target="_blank" rel="nofollow"', $a_msg['message']);
173
        }
174
        $a_msg['note_msg']  = $onemsg->getVar('note');
175
        $a_msg['poster_ip'] = $onemsg->getVar('poster_ip');
176
        $a_msg['moderate']  = $onemsg->getVar('moderate');
177
        if (isset($country_name)) {
178
            $a_msg['local'] = '<a href="index.php?op=show_country&param=' . $onemsg->getVar('flagdir') . '/' . $onemsg->getVar('country') . '">' . $country_name . '</a>';
179
        }
180
        $a_msg['photo'] = $onemsg->getVar('photo');
181
        $xoopsTpl->append('msg', $a_msg);
182
        $nbmsg--;
183
    }
184
}
185
186
function xfgb_genderlist()
187
{
188
    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...
189
    $criteria = new Criteria('moderate', 0);
190
    $arr_msg  = $msgHandler->countMsgByGender($criteria);
191
    $i        = 0;
192
    foreach ($arr_msg as $k => $v) {
193
        if ($k === 'M') {
194
            $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...
195
            $gender[$i] .= '<img src="assets/images/M.gif" alt="' . MD_XFGB_MALES . '"><br><br>';
0 ignored issues
show
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...
196
            $gender[$i] .= '<a href="index.php?op=show_gender&param=M">' . $v . MD_XFGB_MESSAGES . '</a>';
197
        } elseif ($k === 'F') {
198
            $gender[$i] = MD_XFGB_FEMALES . '<br>';
199
            $gender[$i] .= '<img src="assets/images/F.gif" alt="' . MD_XFGB_FEMALES . '"><br><br>';
200
            $gender[$i] .= '<a href="index.php?op=show_gender&param=F">' . $v . MD_XFGB_MESSAGES . '</a>';
201
        } else {
202
            $gender[$i] = MD_XFGB_UNKNOW2 . '<br>';
203
            $gender[$i] .= '<img src="assets/images/U.gif"><br><br>';
204
            $gender[$i] .= $v . MD_XFGB_MESSAGES;
205
        }
206
        $i++;
207
    }
208
    $xoopsTpl->assign('gender', $gender);
209
    $xoopsTpl->assign('display_gender', $options['opt_gender']);
210
}
211
212
// end functions
213
214
// 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...
215
//if (substr($op, 0, 4) == 'show') {
216
if (0 === strpos($op, 'show')) {
217
    $debut = isset($_GET['debut']) ? (int)$_GET['debut'] : 0;
218
    $param = isset($_GET['param']) ? $_GET['param'] : '';
219
220
    include_once __DIR__ . '/include/functions.php';
221
    $GLOBALS['xoopsOption']['template_main'] = 'xfguestbook_index.tpl';
222
    include_once XOOPS_ROOT_PATH . '/header.php';
223
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
224
    include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/config.inc.php';
225
    $options = getOptions();
226
227
    $criteria = new Criteria('moderate', 0);
228
    $nbmsg    = $msgHandler->countMsg($criteria);
229
230
    $xoopsTpl->assign('msg_message_count', sprintf(MD_XFGB_THEREIS, '<b>' . $nbmsg . '</b>'));
231
    $xoopsTpl->assign('msg_moderated', $xoopsModuleConfig['moderate']);
232
    $xoopsTpl->assign('msg_lang_name', $xoopsConfig['language']);
233
    $xoopsTpl->assign('xoops_pagetitle', $xoopsModule->name() . ' -messages');
234
    if ($adminview) {
235
        $nbwait = $msgHandler->countMsg(new Criteria('moderate', '1'));
236
        $xoopsTpl->assign('msg_moderate_text', sprintf(MD_XFGB_MODERATING, "<font class='fg2'><a href='" . XOOPS_URL . "/modules/xfguestbook/index.php?op=show_waiting'>" . $nbwait . '</a></font>'));
237
    }
238
}
239
240
switch ($op) {
241 View Code Duplication
    case 'delete':
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...
242
        if ($adminview) {
243
            include_once XOOPS_ROOT_PATH . '/header.php';
244
            delete($msg_id);
0 ignored issues
show
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...
245
        } else {
246
            redirect_header('index.php', 1, '');
247
        }
248
        break;
249
250 View Code Duplication
    case 'approve':
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...
251
        if ($adminview) {
252
            include_once XOOPS_ROOT_PATH . '/header.php';
253
            approve($msg_id);
0 ignored issues
show
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...
254
        } else {
255
            redirect_header('index.php', 1, '');
256
        }
257
        break;
258
259
    case 'show_stat':
260
        if ($options['opt_gender'] > 0) {
261
            xfgb_genderlist();
262
        }
263
        break;
264
265 View Code Duplication
    case 'show_waiting':
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...
266
        $pagenav = new XoopsPageNav($nbwait, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_waiting');
267
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
268
        $criteria = new Criteria('moderate', 1);
269
        $criteria->setOrder('DESC');
270
        $criteria->setLimit($xoopsModuleConfig['perpage']);
271
        $criteria->setStart($debut);
272
        $msg    =& $msgHandler->getObjects($criteria);
273
        $nbwait -= $debut;
274
        $nbmsg  = $nbwait;
275
        xfgb_getmsg($msg);
276
        break;
277
278
    case 'show_one':
279
        if ($adminview) {
280
            $criteria = new Criteria('msg_id', $msg_id);
281
        } else {
282
            $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
283
            $criteria->add(new Criteria('msg_id', $msg_id));
284
        }
285
        $msg =& $msgHandler->getObjects($criteria);
286
        xfgb_getmsg($msg);
287
        if ($options['opt_gender'] > 0) {
288
            xfgb_genderlist();
289
        }
290
        break;
291
292
    case 'show_country':
293
        list($flagdir, $country) = explode('/', $param);
294
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
295
        if ($flagdir == $xoopsModuleConfig['flagdir']) {
296
            $criteria->add(new Criteria('flagdir', $flagdir));
297
        }
298
        $criteria->add(new Criteria('country', $country));
299
        $nbmsg   = $msgHandler->countMsg($criteria);
300
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_country&param=' . $param);
301
        $criteria->setOrder('DESC');
302
        $criteria->setLimit($xoopsModuleConfig['perpage']);
303
        $criteria->setStart($debut);
304
        $msg   =& $msgHandler->getObjects($criteria);
305
        $nbmsg -= $debut;
306
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
307
        xfgb_getmsg($msg);
308
        break;
309
310
    case 'show_gender':
311
        $criteria = new CriteriaCompo(new Criteria('moderate', '0'));
312
        $criteria->add(new Criteria('gender', $param));
313
        $nbmsg   = $msgHandler->countMsg($criteria);
314
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', 'op=show_gender&param=' . $param);
315
        $criteria->setOrder('DESC');
316
        $criteria->setLimit($xoopsModuleConfig['perpage']);
317
        $criteria->setStart($debut);
318
        $msg   =& $msgHandler->getObjects($criteria);
319
        $nbmsg -= $debut;
320
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
321
        xfgb_getmsg($msg);
322
        if ($options['opt_gender'] > 0) {
323
            xfgb_genderlist();
324
        }
325
        break;
326
327
    case 'show_all':
328 View Code Duplication
    default:
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...
329
        $pagenav = new XoopsPageNav($nbmsg, $xoopsModuleConfig['perpage'], $debut, 'debut', '');
330
        $xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
331
        $criteria = new Criteria('moderate', 0);
332
        $criteria->setOrder('DESC');
333
        $criteria->setLimit($xoopsModuleConfig['perpage']);
334
        $criteria->setStart($debut);
335
        $msg   =& $msgHandler->getObjects($criteria);
336
        $nbmsg -= $debut;
337
        xfgb_getmsg($msg);
338
        if ($options['opt_gender'] > 0) {
339
            xfgb_genderlist();
340
        }
341
        break;
342
343 View Code Duplication
    case 'cancel':
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...
344
        $photos_dir     = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
345
        $nb_removed_tmp = xfgb_clear_tmp_files($photos_dir);
346
        redirect_header('index.php', 0);
347
        break;
348
}
349
$sql = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country') . ' ORDER BY country_name ASC');
350
351
while ($coun = $xoopsDB->fetchArray($sql)) {
352
    $sql2 = $xoopsDB->query('SELECT COUNT(country) tot FROM ' . $xoopsDB->prefix('xfguestbook_msg') . " WHERE country='" . $coun['country_code'] . '\'');
353
    list($tlocal) = $xoopsDB->fetchRow($sql2);
354
    $tlocal = $tlocal ?: '0';
355
    if ($tlocal > 0) {
356
        $opt['<a href="index.php?op=show_country&param=' . $xoopsModuleConfig['flagdir'] . '/' . $coun['country_code'] . '">' . $coun['country_name'] . '</a>'] = $tlocal;
357
    } else {
358
        $opt[$coun['country_name']] = $tlocal;
359
    }
360
}
361
$xoopsTpl->assign('country_l', $opt);
362
363
include XOOPS_ROOT_PATH . '/footer.php';
364