Completed
Push — master ( 76b4a1...141e43 )
by Michael
06:17 queued 02:44
created

country_manager.php ➔ xfgb_getCountry()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 4
nop 3
dl 17
loc 17
rs 9.2
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 66 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
// $Id: admin/index.php,v 2.21 2005/11/09 C. Felix alias the Cat
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 to the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//  ------------------------------------------------------------------------ //
25
26
include dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
27
include_once dirname(__DIR__) . '/include/cp_functions.php';
28
include_once __DIR__ . '/admin_header.php';
29
30
// Flag
31
$maxsize   = 2000;
32
$maxheight = 50;
33
$maxwidth  = 80;
34
$format    = 'gif';
35
36 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...
37
    $op = $_GET['op'];
38
} elseif (isset($_POST['op'])) {
39
    $op = $_POST['op'];
40
} else {
41
    $op = 'countryShow';
42
}
43
44 View Code Duplication
if (isset($_GET['country_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...
45
    $country_id = (int)$_GET['country_id'];
46
} elseif (isset($_POST['country_id'])) {
47
    $country_id = (int)$_POST['country_id'];
48
} else {
49
    $country_id = 0;
50
}
51
52 View Code Duplication
if (isset($_GET['country_code'])) {
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...
53
    $country_code = $_GET['country_code'];
54
} elseif (isset($_POST['country_code'])) {
55
    $country_code = $_POST['country_code'];
56
} else {
57
    $country_code = '';
58
}
59
60
$start        = isset($_GET['start']) ? (int)$_GET['start'] : 0;
61
$country_name = isset($_POST['country_name']) ? $_POST['country_name'] : '';
62
63
/**
64
 * @param $country_code
65
 */
66
function flagUpload($country_code)
0 ignored issues
show
Coding Style introduced by
flagUpload uses the super-global variable $_FILES 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...
Coding Style introduced by
flagUpload 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...
67
{
68
    global $xoopsModule, $xoopsModuleConfig, $maxsize, $maxwidth, $maxheight, $format;
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...
69
    $array_allowed_mimetypes = array('image/' . $format);
70
    // photos
71
    if (!empty($_FILES['photo']['name'])) {
72
        $ext = preg_replace("/^.+\.([^.]+)$/sU", "\\1", $_FILES['photo']['name']);
0 ignored issues
show
Unused Code introduced by
$ext 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...
73
        include_once(XOOPS_ROOT_PATH . '/class/uploader.php');
74
        $field = $_POST['xoops_upload_file'][0];
75
        if (!empty($field) || $field !== '') {
76
            // Check if file uploaded
77
            if ($_FILES[$field]['tmp_name'] === '' || !is_readable($_FILES[$field]['tmp_name'])) {
78
                redirect_header('country_manager.php', 2, _MD_XFGB_FILEERROR);
79
                exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function flagUpload() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
80
            }
81
            $photos_dir = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'];
82
            $uploader   = new XoopsMediaUploader($photos_dir, $array_allowed_mimetypes, $maxsize, $maxwidth, $maxheight);
83
            $uploader->setPrefix('tmp');
84
            if ($uploader->fetchMedia($field) && $uploader->upload()) {
85
                $tmp_name = $uploader->getSavedFileName();
86
                $ext      = preg_replace("/^.+\.([^.]+)$/sU", "\\1", $tmp_name);
87
                $photo    = $country_code . '.' . $ext;
88
                if (file_exists($photos_dir . '/' . $photo)) {
89
                    unlink($photos_dir . '/' . $photo);
90
                }
91
                rename("$photos_dir/$tmp_name", "$photos_dir/$photo");
92
            } else {
93
                redirect_header('country_manager.php', 2, $uploader->getErrors());
94
                exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function flagUpload() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
95
            }
96
        }
97
        redirect_header('country_manager.php', 2, _AM_XFGB_FILEUPLOADED);
98
    } else {
99
        redirect_header('country_manager.php?op=flagForm&amp;country_code=' . $country_code, 2, _MD_XFGB_NOIMGSELECTED);
100
    }
101
    exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function flagUpload() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
102
}
103
104
/**
105
 * @param $country_code
106
 */
107
function flagForm($country_code)
108
{
109
    global $xoopsModule, $xoopsModuleConfig, $maxsize, $maxwidth, $maxheight, $format;
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...
110
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
111
112
    $flagform = new XoopsThemeForm(_AM_XFGB_SUBMITFLAG, 'op', xoops_getenv('PHP_SELF'));
113
    $flagform->setExtra("enctype='multipart/form-data'");
114
115
    $flag = '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $country_code . '.gif';
116
    if (file_exists(XOOPS_ROOT_PATH . $flag)) {
117
        $flag_img = "<img src='" . XOOPS_URL . $flag . "'>";
118
        $img_flag = new XoopsFormLabel('', '<br>' . $flag_img . '<br>');
119
        $flagform->addElement($img_flag);
120
    }
121
    $flag_desc = sprintf(_AM_XFGB_FLAGDSC, $maxsize, $maxwidth, $maxheight, $format);
122
    $flagform->addElement(new XoopsFormLabel('', $flag_desc));
123
124
    $img_text = new XoopsFormFile(_AM_XFGB_ADDIMG, 'photo', 30000);
125
    $img_text->setExtra("size ='60'");
126
    $flagform->addElement($img_text);
127
128
    $button_tray = new XoopsFormElementTray('', '');
129
    $button_tray->addElement(new XoopsFormButton('', 'post', _SEND, 'submit'));
130
    $button_tray->addElement(new XoopsFormHidden('country_code', $country_code));
131
    $button_tray->addElement(new XoopsFormHidden('op', 'flagUpload'));
132
    $flagform->addElement($button_tray);
133
134
    $flagform->display();
135
}
136
137
/**
138
 * @param $country_code
139
 */
140
function flagDel($country_code)
0 ignored issues
show
Coding Style introduced by
flagDel 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...
141
{
142
    global $xoopsModule, $xoopsModuleConfig;
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...
143
    $ok = isset($_POST['ok']) ? (int)$_POST['ok'] : 0;
144
    if ($ok == 1) {
145
        $flag = '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $country_code . '.gif';
146
        if (file_exists(XOOPS_ROOT_PATH . $flag)) {
147
            unlink(XOOPS_ROOT_PATH . $flag);
148
        }
149
        redirect_header('country_manager.php', 2, _AM_XFGB_FLAGDELETED);
150 View Code Duplication
    } else {
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...
151
        xoops_cp_header();
152
        $index_admin = new ModuleAdmin();
153
        echo $index_admin->addNavigation(basename(__FILE__));
154
        xoops_confirm(array('op' => 'flagDel', 'country_code' => $country_code, 'ok' => 1), 'country_manager.php', _AM_XFGB_CONFDELFLAG);
155
        include __DIR__ . '/admin_footer.php';
156
        //xoops_cp_footer();
157
    }
158
}
159
160
/**
161
 * @param null $country_id
162
 */
163
function countryForm($country_id = null)
164
{
165
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
166
167
    if ($country_id) {
168
        $sform        = new XoopsThemeForm(_AM_XFGB_MODCOUNTRY, 'op', xoops_getenv('PHP_SELF'));
169
        $arr_country  = xfgb_getCountry('country_id=' . $country_id, 0, 0);
170
        $country_code = $arr_country[0]['country_code'];
171
        $country_name = $arr_country[0]['country_name'];
172
    } else {
173
        $sform        = new XoopsThemeForm(_AM_XFGB_ADDCOUNTRY, 'op', xoops_getenv('PHP_SELF'));
174
        $country_code = '';
175
        $country_name = '';
176
    }
177
178
    $text_code = new XoopsFormText(_AM_XFGB_FLAGCODE, 'country_code', 5, 5, $country_code);
179
    if ($country_id) {
180
        $text_code->setExtra("readonly = 'readonly'");
181
    }
182
    $sform->addElement($text_code, true);
183
    $sform->addElement(new XoopsFormText(_AM_XFGB_FLAGNAME, 'country_name', 50, 50, $country_name), true);
184
185
    $button_tray = new XoopsFormElementTray('', '');
186
    $button_tray->addElement(new XoopsFormButton('', 'save', _SUBMIT, 'submit'));
187
    if ($country_id) {
188
        $button_tray->addElement(new XoopsFormHidden('country_id', $country_id));
189
    }
190
    $button_tray->addElement(new XoopsFormHidden('op', 'countrySave'));
191
    $sform->addElement($button_tray);
192
    $sform->display();
193
}
194
195
/**
196
 * @param null $criteria
197
 * @param int  $limit
198
 * @param int  $start
199
 * @return array
200
 */
201 View Code Duplication
function xfgb_getCountry($criteria = null, $limit = 0, $start = 0)
0 ignored issues
show
Duplication introduced by
This function 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...
202
{
203
    global $xoopsDB, $action;
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...
204
    $ret = array();
205
206
    $sql = 'SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country');
207
    if (isset($criteria) && $criteria !== '') {
208
        $sql .= ' WHERE ' . $criteria;
209
    }
210
    $sql .= ' ORDER BY country_name ASC';
211
    $result = $xoopsDB->query($sql, $limit, $start);
212
    while ($myrow = $xoopsDB->fetchArray($result)) {
213
        array_push($ret, $myrow);
214
    }
215
216
    return $ret;
217
}
218
219
/**
220
 * @param $country_id
221
 */
222
function countryDel($country_id)
0 ignored issues
show
Coding Style introduced by
countryDel 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...
223
{
224
    global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
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...
225
    $ok = isset($_POST['ok']) ? (int)$_POST['ok'] : 0;
226
    if ($ok == 1) {
227
        $arr_country = xfgb_getCountry('country_id=' . $country_id, 0, 0);
228
        $flag        = '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $arr_country[0]['country_code'] . '.gif';
229
        $sql         = 'DELETE FROM ' . $xoopsDB->prefix('xfguestbook_country') . " WHERE country_id=$country_id";
230
        $result      = $xoopsDB->query($sql);
0 ignored issues
show
Unused Code introduced by
$result 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...
231
        if (file_exists(XOOPS_ROOT_PATH . $flag)) {
232
            unlink(XOOPS_ROOT_PATH . $flag);
233
        }
234
        redirect_header('country_manager.php', 1, _AM_XFGB_COUNTRYDELETED);
235 View Code Duplication
    } else {
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...
236
        xoops_cp_header();
237
        $index_admin = new ModuleAdmin();
238
        echo $index_admin->addNavigation(basename(__FILE__));
239
        xoops_confirm(array('op' => 'countryDel', 'country_id' => $country_id, 'ok' => 1), 'country_manager.php', _AM_XFGB_CONFDELCOUNTRY);
240
        include __DIR__ . '/admin_footer.php';
241
        //xoops_cp_footer();
242
    }
243
}
244
245
/**
246
 * @param $country_id
247
 * @param $country_code
248
 * @param $country_name
249
 */
250 View Code Duplication
function countrySave($country_id, $country_code, $country_name)
0 ignored issues
show
Duplication introduced by
This function 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...
251
{
252
    global $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...
253
254
    $myts = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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...
255
    //$country_code=$myts->makeTboxData4Save::$country_code;
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
256
    //$country_name=$myts->makeTboxData4Save::$country_name;
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
257
    echo $country_code;
258
    if (!empty($country_id)) {
259
        $sql = 'UPDATE ' . $xoopsDB->prefix('xfguestbook_country') . " SET country_code='$country_code', country_name='$country_name'";
260
        $sql .= " WHERE country_id=$country_id";
261
        $xoopsDB->query($sql);
262
        $messagesent = _AM_XFGB_COUNTRY_UPDATED;
263
    } else {
264
        $sql = sprintf("SELECT COUNT(*) FROM  %s WHERE country_code = '%s'", $xoopsDB->prefix('xfguestbook_country'), $country_code);
265
        list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
266
        if ($count > 0) {
267
            $messagesent = '<font color="#FF0000">' . _AM_XFGB_COUNTRY_EXIST . '</font>';
268
        } else {
269
            $country_id = $xoopsDB->genId('country_id_seq');
270
            $sql        =
271
                sprintf("INSERT INTO %s (country_id, country_code, country_name) VALUES (%s, '%s', '%s')", $xoopsDB->prefix('xfguestbook_country'), $country_id, $country_code, $country_name);
272
            $xoopsDB->query($sql);
273
            $messagesent = _AM_XFGB_COUNTRY_ADDED;
274
        }
275
    }
276
    redirect_header('country_manager.php', 2, $messagesent);
277
    exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function countrySave() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
278
}
279
280
function countryShow()
281
{
282
    global $action, $start, $xoopsModule, $xoopsModuleConfig, $pathIcon16;
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...
283
    $myts        = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts 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...
284
    $limit       = 15;
285
    $arr_country = xfgb_getCountry('', $limit, $start);
286
    $scount      = count(xfgb_getCountry('', $limit, 0));
287
    $totalcount  = count(xfgb_getCountry('', 0, 0));
288
289
    echo "
290
    <table width='100%' cellspacing='1' cellpadding='2' border='0' style='border-left: 1px solid silver; border-top: 1px solid silver; border-right: 1px solid silver;'>
291
        <tr>
292
            <td><span style='font-weight: bold; font-size: 12px; font-variant: small-caps;'>" . _AM_XFGB_DISPCOUNTRY . ' : ' . $totalcount . "</span></td>
293
            <td align='right'>
294
            </td>
295
        </tr>
296
    </table>";
297
298
    echo "<table border='1' width='100%' cellpadding ='2' cellspacing='1'>";
299
    echo "<tr class='bg3'>";
300
    echo "<td align='center'><b>" . _AM_XFGB_FLAGIMG . '</td>';
301
    echo "<td align='center'><b>" . _AM_XFGB_FLAGCODE . '</td>';
302
    echo "<td align='center'><b>" . _AM_XFGB_FLAGNAME . '</td>';
303
    echo "<td align='center'><b>" . _AM_XFGB_COUNTRY . '</td></b>';
304
    echo "<td align='center'><b>" . _AM_XFGB_FLAGIMG . '</td></b>';
305
    echo '</tr>';
306
307
    if (count($arr_country) == '0') {
308
        echo "<tr ><td align='center' colspan ='10' class = 'head'><b>" . _AM_XFGB_NOFLAG . '</b></td></tr>';
309
    }
310
311
    for ($i = 0; $i < count($arr_country); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
312
        $all_country = array();
313
        $flag        = '/modules/' . $xoopsModule->dirname() . '/assets/images/flags/' . $xoopsModuleConfig['flagdir'] . '/' . $arr_country[$i]['country_code'] . '.gif';
314
        if (file_exists(XOOPS_ROOT_PATH . $flag)) {
315
            $all_country['flag_img'] = "<img src='" . XOOPS_URL . $flag . "'>";
316
        } else {
317
            $all_country['flag_img'] = "<img src='" . XOOPS_URL . "/images/blank.gif'>";
318
        }
319
320
        $all_country['country_id']   = $arr_country[$i]['country_id'];
321
        $all_country['country_code'] = $arr_country[$i]['country_code'];
322
        $all_country['country_name'] = $arr_country[$i]['country_name'];
323
        $all_country['msg_action']   = "<a href='country_manager.php?op=countryEdit&amp;country_id=" . $arr_country[$i]['country_id'] . "'><img src='" . $pathIcon16 . "/edit.png'></a>";
324
        $all_country['msg_action'] .= "&nbsp;<a href='country_manager.php?op=countryDel&amp;country_id=" . $arr_country[$i]['country_id'] . "'><img src='" . $pathIcon16 . "/delete.png'></a>";
325
        $all_country['flag_action'] = "<a href='country_manager.php?op=flagForm&amp;country_code=" . $arr_country[$i]['country_code'] . "'><img src='" . $pathIcon16 . "/add.png'></a>";
326
        $all_country['flag_action'] .= "&nbsp;<a href='country_manager.php?op=flagDel&amp;country_code=" . $arr_country[$i]['country_code'] . "'><img src='" . $pathIcon16 . "/delete.png'></a>";
327
        echo "<tr><td align='center' class = 'head'><b>" . $all_country['flag_img'] . '</b>';
328
        echo "</td><td class = 'even'>" . $all_country['country_code'] . '';
329
        echo "</td><td class = 'odd'>" . $all_country['country_name'] . '';
330
        echo "</td><td align='center' class='even'>" . $all_country['msg_action'] . '';
331
        echo "</td><td align='center' class='even'>" . $all_country['flag_action'] . '';
332
        echo '</td></tr>';
333
        unset($all_country);
334
    }
335
336
    echo '</table><br>';
337
338 View Code Duplication
    if ($totalcount > $scount) {
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...
339
        include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
340
        $pagenav = new XoopsPageNav($totalcount, $limit, $start, 'start', 'action=' . $action);
341
        echo "<div style='text-align: center;' class = 'head'>" . $pagenav->renderNav() . '</div><br>';
342
    } else {
343
        echo '';
344
    }
345
    echo '<br>';
346
}
347
348
switch ($op) {
349 View Code Duplication
    case 'flagForm':
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...
350
        xoops_cp_header();
351
        $index_admin = new ModuleAdmin();
352
        echo $index_admin->addNavigation(basename(__FILE__));
353
        //xfguestbook_admin_menu(2);
354
        flagForm($country_code);
355
        include __DIR__ . '/admin_footer.php';
356
        //xoops_cp_footer();
357
        break;
358
    case 'flagUpload':
359
        flagUpload($country_code);
360
        break;
361
    case 'flagDel':
362
        flagDel($country_code);
363
        break;
364
    case 'countryDel':
365
        countryDel($country_id);
366
        break;
367 View Code Duplication
    case 'countryEdit':
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...
368
        xoops_cp_header();
369
        $index_admin = new ModuleAdmin();
370
        echo $index_admin->addNavigation(basename(__FILE__));
371
        //xfguestbook_admin_menu(2);
372
        countryForm($country_id);
373
        include __DIR__ . '/admin_footer.php';
374
        //xoops_cp_footer();
375
        break;
376
    case 'countrySave':
377
        countrySave($country_id, $country_code, $country_name);
378
        break;
379 View Code Duplication
    case 'countryAdd':
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...
380
        xoops_cp_header();
381
        $index_admin = new ModuleAdmin();
382
        echo $index_admin->addNavigation(basename(__FILE__));
383
        //xfguestbook_admin_menu(2);
384
        countryForm();
385
        include __DIR__ . '/admin_footer.php';
386
        //xoops_cp_footer();
387
        break;
388
    case 'countryShow':
389 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...
390
        xoops_cp_header();
391
        $index_admin = new ModuleAdmin();
392
        echo $index_admin->addNavigation(basename(__FILE__));
393
        //xfguestbook_admin_menu(2);
394
        countryShow();
395
        countryForm();
396
        include __DIR__ . '/admin_footer.php';
397
        //xoops_cp_footer();
398
        break;
399
}
400