Completed
Push — master ( 871d94...af939e )
by Michael
03:14
created

tools.php ➔ userfields()   D

Complexity

Conditions 55
Paths > 20000

Size

Total Lines 6
Code Lines 183

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 55
eloc 183
nc 76744
nop 0
dl 0
loc 6
rs 4.923
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 112 and the first side effect is on line 4.

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
require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
5
xoops_loadLanguage('main', basename(dirname(dirname(__DIR__))));
6
7
// Include any common code for this module.
8
require_once dirname(__DIR__) . '/include/common.php';
9
10
$xoopsOption['template_main'] = 'pedigree_tools.tpl';
11
12
include XOOPS_ROOT_PATH . '/header.php';
13
$xoopsTpl->assign('page_title', 'Pedigree database - Add owner/breeder');
14
15
//check for access
16
$xoopsModule = XoopsModule::getByDirname('pedigree');
17 View Code Duplication
if (empty($GLOBALS['xoopsUser'])) {
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...
18
    redirect_header('index.php', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
19
}
20
21
//add JS routines
22
echo '<script language="JavaScript" src="picker.js"></script>';
23
24
//set form to be empty
25
$form = '';
26
27
//get module configuration
28
$moduleHandler = xoops_getHandler('module');
29
$module        = $moduleHandler->getByDirname('pedigree');
30
$configHandler = xoops_getHandler('config');
31
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
32
33
switch ($_GET['op']) {
34
    case 'lang':
35
        lang();
36
        break;
37
    case 'langsave':
38
        langsave();
39
        break;
40
    case 'colours':
41
        colours();
42
        break;
43
    case 'settings':
44
        settings();
45
        break;
46
    case 'settingssave':
47
        settingssave();
48
        break;
49
    case 'pro':
50
        pro();
51
        break;
52
    case 'userfields':
53
        userfields();
54
        break;
55
    case 'deleted':
56
        deleted();
57
        break;
58
    case 'delperm':
59
        delperm($_GET['id']);
60
        break;
61
    case 'delall':
62
        delall();
63
        break;
64
    case 'restore':
65
        restore($_GET['id']);
66
        break;
67
    case 'database':
68
        database();
69
        $db = true;
70
        break;
71
    case 'dbanc':
72
        database_oa();
73
        $db = true;
74
        break;
75
    case 'fltypar':
76
        database_fp();
77
        $db = true;
78
        break;
79
    case 'credits':
80
        credits();
81
        break;
82
    default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
83
        index();
0 ignored issues
show
Unused Code introduced by
The call to the function index() seems unnecessary as the function has no side-effects.
Loading history...
84
        break;
85
}
86
87
//create tools array
88
$tools[] = array('title' => 'General settings', 'link' => 'tools.php?op=settings', 'main' => '1');
89
if ($moduleConfig['proversion'] == '1') {
90
    $tools[] = array('title' => 'Pro-version settings', 'link' => 'tools.php?op=pro', 'main' => '1');
91
}
92
$tools[] = array('title' => 'Language options', 'link' => 'tools.php?op=lang', 'main' => '1');
93
$tools[] = array('title' => 'Create user fields', 'link' => 'tools.php?op=userfields', 'main' => '1');
94
$tools[] = array('title' => 'Create colours', 'link' => 'tools.php?op=colours', 'main' => '1');
95
$tools[] = array('title' => "Deleted pedigree's", 'link' => 'tools.php?op=deleted', 'main' => '1');
96
$tools[] = array('title' => 'Database tools', 'link' => 'tools.php?op=database', 'main' => '1');
97
if (isset($db)) {
98
    //create database submenu
99
    $tools[] = array('title' => 'Own ancestors', 'link' => 'tools.php?op=dbanc', 'main' => '0');
100
    $tools[] = array('title' => 'Incorrect gender', 'link' => 'tools.php?op=fltypar', 'main' => '0');
101
    $tools[] = array('title' => 'User Queries', 'link' => 'tools.php?op=userq', 'main' => '0');
102
}
103
$tools[] = array('title' => 'Credits', 'link' => 'tools.php?op=credits', 'main' => '1');
104
$tools[] = array('title' => 'Logout', 'link' => '../../user.php?op=logout', 'main' => '1');
105
//add data (form) to smarty template
106
107
$xoopsTpl->assign('tools', $tools);
108
109
//footer
110
include XOOPS_ROOT_PATH . '/footer.php';
111
112
function index()
113
{
114
    $form = '';
0 ignored issues
show
Unused Code introduced by
$form 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...
115
}
116
117
function colours()
118
{
119
    global $xoopsTpl, $femaleTextColour;
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...
120
    $form = 'This will be the wizard to create and modify the website colourscheme.<hr>';
121
    $form .= '<FORM NAME="myForm" action=\'savecolors.php\' method=\'POST\'>';
122
    $form .= '<INPUT TYPE="text" id="ftxtcolor" name="ftxtcolor" value="#' . $femaleTextColour . '" size="11" maxlength="7">';
123
    $form .= '<a href="javascript:TCP.popup(document.forms[\'myForm\'].elements[\'ftxtcolor\'])">';
124
    $form .= '<img width="15" height="13" border="0" alt="Click Here to Pick up the color" src="img/sel.gif"></a>';
125
    $form .= '</form>';
126
    $xoopsTpl->assign('form', $form);
127
}
128
129
function userfields()
130
{
131
    global $xoopsTpl;
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...
132
    $form = 'This will be the wizard to create and modify the custom userfields.<hr>';
133
    $xoopsTpl->assign('form', $form);
134
}
135
136
function credits()
137
{
138
    global $xoopsTpl;
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...
139
    $form = "Pedigree database module<br /><br /><li>Programming : James Cotton<br/><li>Design & Layout : Ton van der Hagen<br /><br />Technical support :<br /><li><a href=\"mailto:[email protected]\">[email protected]<br /><li><a href=\"http://www.animalpedigree.com\">www.animalpedigree.com</a><hr>";
140
    $xoopsTpl->assign('form', $form);
141
}
142
143
function database()
144
{
145
    global $xoopsTpl;
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...
146
    $form = _MA_PEDIGREE_QUERY_EXPLAN;
147
    $xoopsTpl->assign('form', $form);
148
}
149
150
function database_oa()
0 ignored issues
show
Coding Style introduced by
database_oa uses the super-global variable $GLOBALS 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...
151
{
152
    global $xoopsTpl;
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...
153
    $form   = _AM_PEDIGREE_DATABASE_CHECK_ANCESTORS;
154
    $sql    = 'SELECT d.id AS d_id, d.naam AS d_naam
155
            FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d
156
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON m.id = d.mother
157
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON f.id = d.father
158
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mm ON mm.id = m.mother
159
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mf ON mf.id = m.father
160
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fm ON fm.id = f.mother
161
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ff ON ff.id = f.father
162
            WHERE
163
            d.mother = d.id
164
            OR d.father = d.id
165
            OR m.mother = d.id
166
            OR m.father = d.id
167
            OR f.mother = d.id
168
            OR f.father = d.id
169
            OR mm.mother = d.id
170
            OR mm.father = d.id
171
            OR mf.mother = d.id
172
            OR mf.father = d.id
173
            OR fm.mother = d.id
174
            OR fm.father = d.id
175
            OR ff.mother = d.id
176
            OR ff.father = d.id
177
            ';
178
    $result = $GLOBALS['xoopsDB']->query($sql);
179 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
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...
180
        $form .= "<li><a href=\"pedigree.php?pedid=" . $row['d_id'] . "\">" . $row['d_naam'] . '</a> [own parent or grandparent]<br />';
181
    }
182
    $xoopsTpl->assign('form', $form);
183
}
184
185
function database_fp()
0 ignored issues
show
Coding Style introduced by
database_fp uses the super-global variable $GLOBALS 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...
186
{
187
    global $xoopsTpl;
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...
188
    $form   = _AM_PEDIGREE_DATABASE_CHECK_GENDER;
189
    $sql    = 'SELECT d.id AS d_id, d.naam AS d_naam, m.roft as m_roft
190
            FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d
191
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " m ON m.id = d.mother
192
            WHERE
193
            d.mother = m.id
194
            AND m.roft = '0' ";
195
    $result = $GLOBALS['xoopsDB']->query($sql);
196 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
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...
197
        $form .= "<li><a href=\"dog.php?id=" . $row['d_id'] . "\">" . $row['d_naam'] . '</a> [mother seems to be male]<br />';
198
    }
199
    $sql    = 'SELECT d.id AS d_id, d.naam AS d_naam, f.roft as f_roft
200
            FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d
201
            LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " f ON f.id = d.father
202
            WHERE
203
            d.father = f.id
204
            AND f.roft = '1' ";
205
    $result = $GLOBALS['xoopsDB']->query($sql);
206 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
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...
207
        $form .= "<li><a href=\"dog.php?id=" . $row['d_id'] . "\">" . $row['d_naam'] . '</a> [father seems to be female]<br />';
208
    }
209
    $xoopsTpl->assign('form', $form);
210
}
211
212
function pro()
213
{
214
    global $xoopsTpl;
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...
215
    $form = 'Pro version settings go here.<hr>';
216
    $xoopsTpl->assign('form', $form);
217
}
218
219
function deleted()
0 ignored issues
show
Coding Style introduced by
deleted uses the super-global variable $GLOBALS 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...
220
{
221
    global $xoopsTpl, $moduleConfig;
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...
222
    $form   = "Below the line are the animals which have been deleted from your database.<br /><br />By clicking on the name you can reinsert them into the database.<br />By clicking on the 'X' in front of the name you can permanently delete the animal.<hr>";
223
    $sql    = 'SELECT ID, NAAM  FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash');
224
    $result = $GLOBALS['xoopsDB']->query($sql);
225
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
226
        $form .= "<a href=\"tools.php?op=delperm&id=" . $row['Id'] . "\"><img src=\"assets/images/delete.gif\" /></a>&nbsp;<a href=\"tools.php?op=restore&id=" . $row['Id'] . "\">" . $row['NAAM'] . '</a><br />';
227
    }
228 View Code Duplication
    if ($GLOBALS['xoopsDB']->getRowsNum($result) > 0) {
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...
229
        $form .= "<hr><a href=\"tools.php?op=delall\">Click here</a> to remove all these " . $moduleConfig['animalTypes'] . ' permenantly ';
230
    }
231
    $xoopsTpl->assign('form', $form);
232
}
233
234
/**
235
 * @param $id
236
 */
237 View Code Duplication
function delperm($id)
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...
Coding Style introduced by
delperm uses the super-global variable $GLOBALS 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...
238
{
239
    global $xoopsTpl;
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...
240
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash') . ' WHERE ID = ' . $id;
241
    $GLOBALS['xoopsDB']->queryF($sql);
242
    deleted();
243
}
244
245 View Code Duplication
function delall()
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...
Coding Style introduced by
delall uses the super-global variable $GLOBALS 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...
246
{
247
    global $xoopsTpl;
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...
248
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash');
249
    $GLOBALS['xoopsDB']->queryF($sql);
250
    deleted();
251
}
252
253
/**
254
 * @param $id
255
 */
256
function restore($id)
0 ignored issues
show
Coding Style introduced by
restore uses the super-global variable $GLOBALS 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...
257
{
258
    global $xoopsTpl;
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...
259
    $sql    = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash') . ' WHERE ID = ' . $id;
260
    $result = $GLOBALS['xoopsDB']->query($sql);
261 View Code Duplication
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
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...
262
        foreach ($row as $key => $values) {
263
            //          $queryvalues .= "'" . $values . "',";
264
            $queryvalues .= "'" . $GLOBALS['xoopsDB']->escape($values) . "',";
0 ignored issues
show
Bug introduced by
The variable $queryvalues 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...
265
        }
266
        $outgoing = substr_replace($queryvalues, '', -1);
267
        $query    = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' VALUES (' . $outgoing . ')';
268
        $GLOBALS['xoopsDB']->queryF($query);
269
        $delquery = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash') . ' WHERE ID = ' . $id;
270
        $GLOBALS['xoopsDB']->queryF($delquery);
271
        $form .= "<li><a href=\"pedigree.php?pedid=" . $row['Id'] . "\">" . $row['NAAM'] . '</a> has been restored into the database.<hr>';
0 ignored issues
show
Bug introduced by
The variable $form 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...
272
    }
273
    $xoopsTpl->assign('form', $form);
274
}
275
276
function settings()
277
{
278
    global $xoopsTpl, $moduleConfig;
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...
279
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
280
    $form = new XoopsThemeForm('General settings', 'settings', 'tools.php?op=settingssave', 'POST', 1);
281
    $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
282
    $select  = new XoopsFormSelect('<b>Number of results per page</b>', 'perpage', $value = $moduleConfig['perpage'], $size = 1, $multiple = false);
283
    $options = array('50' => 50, '100' => 100, '250' => 250, '500' => 500, '1000' => 1000, '2000' => 2000, '5000' => 5000, '10000' => 10000);
284
    foreach ($options as $key => $values) {
285
        $select->addOption($key, $name = $values);
286
    }
287
    unset($options);
288
    $form->addElement($select);
289
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'This field is used to set the number of results a page will return from a search. If more results are returned extra pages will be created for easy browsing.<br />Set this number higher as your database grows and the number of pages increase.'));
290
    $radio = new XoopsFormRadio('<b>Use owner/breeder fields</b>', 'ownerbreeder', $value = $moduleConfig['ownerbreeder']);
291
    $radio->addOption(1, $name = 'yes');
292
    $radio->addOption(0, $name = 'no');
293
    $form->addElement($radio);
294
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set if you would like to use the owner/breeder fields of the database.<br />As the name suggests the owner/breeder fields let you record and display information about the owner and or breeder.<br />The owner/breeder menu items will also be affected by this setting.'));
295
    $radiobr = new XoopsFormRadio('<b>Show brother & sister field</b>', 'brothers', $value = $moduleConfig['brothers']);
296
    $radiobr->addOption(1, $name = 'yes');
297
    $radiobr->addOption(0, $name = 'no');
298
    $form->addElement($radiobr);
299
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set if you would like to use the add a ' . $moduleConfig['litter'] . 'feature.<br />If your chosen animal only has one offspring at a time this feature will not be useful to you.'));
300
    $radiolit = new XoopsFormRadio('<b>Use add a ' . $moduleConfig['litter'] . ' feature</b>', 'uselitter', $value = $moduleConfig['uselitter']);
301
    $radiolit->addOption(1, $name = 'yes');
302
    $radiolit->addOption(0, $name = 'no');
303
    $form->addElement($radiolit);
304
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set if you would like to display the brothers & sisters field on the detailed ' . $moduleConfig['animalType'] . ' information page.'));
305
    $radioch = new XoopsFormRadio('<b>Show ' . $moduleConfig['children'] . ' field</b>', 'pups', $value = $moduleConfig['pups']);
306
    $radioch->addOption(1, $name = 'yes');
307
    $radioch->addOption(0, $name = 'no');
308
    $form->addElement($radioch);
309
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set if you would like to display the ' . $moduleConfig['children'] . ' field on the detailed ' . $moduleConfig['animalType'] . ' information page.'));
310
    $form->addElement(new XoopsFormButton('', 'button_id', 'Submit', 'submit'));
311
    $xoopsTpl->assign('form', $form->render());
312
}
313
314
function settingssave()
0 ignored issues
show
Coding Style introduced by
settingssave 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...
Coding Style introduced by
settingssave uses the super-global variable $GLOBALS 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...
315
{
316
    global $xoopsTpl;
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...
317
    $form     = '';
318
    $settings = array('perpage', 'ownerbreeder', 'brothers', 'uselitter', 'pups');
319 View Code Duplication
    foreach ($_POST as $key => $values) {
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...
320
        if (in_array($key, $settings)) {
321
            //          $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('config') . " SET conf_value = '" . $values . "' WHERE conf_name = '" . $key . "'";
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
322
            $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('config') . " SET conf_value = '" . $GLOBALS['xoopsDB']->escape($values) . "' WHERE conf_name = '" . $GLOBALS['xoopsDB']->escape($key) . "'";
323
            $GLOBALS['xoopsDB']->query($query);
324
        }
325
    }
326
    $form .= 'Your settings have been saved.<hr>';
327
    $xoopsTpl->assign('form', $form);
328
}
329
330
function lang()
331
{
332
    global $xoopsTpl, $moduleConfig;
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...
333
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
334
    $form = new XoopsThemeForm('Language options', 'language', 'tools.php?op=langsave', 'POST');
335
    $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
336
    $form->addElement(new XoopsFormText('<b>type of animal</b>', 'animalType', $size = 50, $maxsize = 255, $value = $moduleConfig['animalType']));
337
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the animal type which will be used in the application.<br /><i>example : </i>snake, pigeon, dog, owl<br /><br />The value should fit in the sentences below.<br />Please add optional information for this <b>' . $moduleConfig['animalType'] . '</b>.<br />Select the first letter of the <b>' . $moduleConfig['animalType'] . '</b>.'));
338
    $form->addElement(new XoopsFormText('<b>type of animal</b>', 'animalTypes', $size = 50, $maxsize = 255, $value = $value = $moduleConfig['animalTypes']));
339
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the animal type which will be used in the application.<br />This field is the plural of the previous field<br /><i>example : </i>snakes, pigeons, dogs, owls<br /><br />The value should fit in the sentence below.<br />No <b>' . $moduleConfig['animalTypes'] . '</b> meeting your query have been found.'));
340
    $form->addElement(new XoopsFormText('<b>male</b>', 'male', $size = 50, $maxsize = 255, $value = $moduleConfig['male']));
341
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for the male animal.<br /><i>example : </i>male, buck, sire etc.'));
342
    $form->addElement(new XoopsFormText('<b>female</b>', 'female', $size = 50, $maxsize = 255, $value = $moduleConfig['female']));
343
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for the female animal.<br /><i>example : </i>female, vixen, dam etc.'));
344
    $form->addElement(new XoopsFormText('<b>children</b>', 'children', $size = 50, $maxsize = 255, $value = $moduleConfig['children']));
345
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for children of this type of animal (' . $moduleConfig['animalTypes'] . ').<br /><i>example : </i>pups, cubs, kittens etc.'));
346
    $form->addElement(new XoopsFormText('<b>mother</b>', 'mother', $size = 50, $maxsize = 255, $value = $moduleConfig['mother']));
347
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for mother of this type of animal (' . $moduleConfig['animalTypes'] . ').<br /><i>example : </i>dam, mare etc.'));
348
    $form->addElement(new XoopsFormText('<b>father</b>', 'father', $size = 50, $maxsize = 255, $value = $moduleConfig['father']));
349
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for father of this type of animal (' . $moduleConfig['animalTypes'] . ').<br /><i>example : </i>sire, stallion etc.'));
350
    $form->addElement(new XoopsFormText('<b>litter</b>', 'litter', $size = 50, $maxsize = 255, $value = $moduleConfig['litter']));
351
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for a collection of newborn animals.<br /><i>example : </i>litter, nest etc.'));
352
    $form->addElement(new XoopsFormTextArea('<b>Welcome text</b>', 'welcome', $value = $moduleConfig['welcome'], $rows = 15, $cols = 50));
353
354
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the text you would like to display for the welcome page.<br /><br />You may use the follwing variables :<br />[animalType] = ' . $moduleConfig['animalType'] . '<br />[animalTypes] =' . $moduleConfig['animalTypes'] . '<br />[numanimals] = number of animals in the database.'));
355
    $form->addElement(new XoopsFormButton('', 'button_id', 'Submit', 'submit'));
356
    $xoopsTpl->assign('form', $form->render());
357
}
358
359
function langsave()
0 ignored issues
show
Coding Style introduced by
langsave 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...
Coding Style introduced by
langsave uses the super-global variable $GLOBALS 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...
360
{
361
    global $xoopsTpl;
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...
362
    $form     = '';
363
    $settings = array('animalType', 'animalTypes', 'male', 'female', 'children', 'mother', 'father', 'litter', 'welcome');
364 View Code Duplication
    foreach ($_POST as $key => $values) {
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...
365
        if (in_array($key, $settings)) {
366
            //          $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('config') . " SET conf_value = '" . $values . "' WHERE conf_name = '" . $key . "'";
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
367
            $query = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('config') . " SET conf_value = '" . $GLOBALS['xoopsDB']->escape($values) . "' WHERE conf_name = '" . $GLOBALS['xoopsDB']->escape($key) . "'";
368
            $GLOBALS['xoopsDB']->query($query);
369
        }
370
    }
371
    $form .= 'Your settings have been saved.<hr>';
372
    $xoopsTpl->assign('form', $form);
373
}
374